Lock constraint can be applied with better selection
Can't yet start without selection: the button on toolbar is not active without a selection yet
This commit is contained in:
parent
ecd1f465b0
commit
1230f493d5
|
@ -33,6 +33,7 @@
|
||||||
#include <Gui/Application.h>
|
#include <Gui/Application.h>
|
||||||
#include <Gui/Document.h>
|
#include <Gui/Document.h>
|
||||||
#include <Gui/Selection.h>
|
#include <Gui/Selection.h>
|
||||||
|
#include <Gui/SelectionFilter.h>
|
||||||
#include <Gui/Command.h>
|
#include <Gui/Command.h>
|
||||||
#include <Gui/MainWindow.h>
|
#include <Gui/MainWindow.h>
|
||||||
#include <Gui/DlgEditFileIncludeProptertyExternal.h>
|
#include <Gui/DlgEditFileIncludeProptertyExternal.h>
|
||||||
|
@ -932,6 +933,29 @@ bool CmdSketcherConstrainVertical::isActive(void)
|
||||||
|
|
||||||
// ======================================================================================
|
// ======================================================================================
|
||||||
|
|
||||||
|
namespace SketcherGui {
|
||||||
|
class LockSelection : public Gui::SelectionFilterGate
|
||||||
|
{
|
||||||
|
App::DocumentObject* object;
|
||||||
|
public:
|
||||||
|
LockSelection(App::DocumentObject* obj)
|
||||||
|
: Gui::SelectionFilterGate((Gui::SelectionFilter*)0), object(obj)
|
||||||
|
{}
|
||||||
|
|
||||||
|
bool allow(App::Document *pDoc, App::DocumentObject *pObj, const char *sSubName)
|
||||||
|
{
|
||||||
|
if (pObj != this->object)
|
||||||
|
return false;
|
||||||
|
if (!sSubName || sSubName[0] == '\0')
|
||||||
|
return false;
|
||||||
|
std::string element(sSubName);
|
||||||
|
if (element.substr(0,6) == "Vertex")
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/* XPM */
|
/* XPM */
|
||||||
static const char *cursor_createlock[]={
|
static const char *cursor_createlock[]={
|
||||||
"32 32 3 1",
|
"32 32 3 1",
|
||||||
|
@ -974,44 +998,102 @@ static const char *cursor_createlock[]={
|
||||||
/**
|
/**
|
||||||
* @brief The DrawSketchHandlerLock class
|
* @brief The DrawSketchHandlerLock class
|
||||||
*
|
*
|
||||||
* Hacking on the lines of the functions in CommandCreateGeo.cpp to make lock
|
* Hacking along the lines of the functions in CommandCreateGeo.cpp to make lock
|
||||||
* constraints on the fly.
|
* constraints on the fly.
|
||||||
*/
|
*/
|
||||||
class DrawSketchHandlerLock: public DrawSketchHandler
|
class DrawSketchHandlerLock: public DrawSketchHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DrawSketchHandlerLock() : selectionDone(false) {}
|
DrawSketchHandlerLock() : selectionDone(false) {}
|
||||||
virtual ~DrawSketchHandlerLock() {}
|
virtual ~DrawSketchHandlerLock()
|
||||||
|
{
|
||||||
|
Gui::Selection().rmvSelectionGate();
|
||||||
|
}
|
||||||
|
|
||||||
virtual void activated(ViewProviderSketch *)
|
virtual void activated(ViewProviderSketch *)
|
||||||
{
|
{
|
||||||
|
Gui::Selection().rmvSelectionGate();
|
||||||
|
Gui::Selection().addSelectionGate(new LockSelection(sketchgui->getObject()));
|
||||||
setCursor(QPixmap(cursor_createlock),7,7);
|
setCursor(QPixmap(cursor_createlock),7,7);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void mouseMove(Base::Vector2d onSketchPos)
|
virtual void mouseMove(Base::Vector2d onSketchPos)
|
||||||
{
|
{
|
||||||
|
// If preselection Point
|
||||||
|
//int preSelPnt = sketchgui->getPreselectPoint();
|
||||||
|
if (sketchgui->getPreselectPoint() != -1) {
|
||||||
setPositionText(onSketchPos);
|
setPositionText(onSketchPos);
|
||||||
if (seekAutoConstraint(sugConstr, onSketchPos, Base::Vector2d(0.f,0.f))) {
|
|
||||||
renderSuggestConstraintsCursor(sugConstr);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
resetPositionText();
|
||||||
applyCursor();
|
applyCursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool pressButton(Base::Vector2d onSketchPos)
|
virtual bool pressButton(Base::Vector2d onSketchPos)
|
||||||
{
|
{
|
||||||
EditPoint = onSketchPos;
|
Q_UNUSED(onSketchPos);
|
||||||
|
// Get Preselection Point
|
||||||
|
int preSelPnt = sketchgui->getPreselectPoint();
|
||||||
|
if (preSelPnt != -1) {
|
||||||
|
pointGeoId = Constraint::GeoUndef;
|
||||||
|
pointPosId = Sketcher::none;
|
||||||
|
sketchgui->getSketchObject()->getGeoVertexIndex(preSelPnt, pointGeoId, pointPosId);
|
||||||
selectionDone = true;
|
selectionDone = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
virtual bool releaseButton(Base::Vector2d onSketchPos) {
|
virtual bool releaseButton(Base::Vector2d onSketchPos) {
|
||||||
|
Q_UNUSED(onSketchPos);
|
||||||
|
if (selectionDone) {
|
||||||
|
unsetCursor();
|
||||||
|
resetPositionText();
|
||||||
|
|
||||||
|
Sketcher::SketchObject* Obj = static_cast<Sketcher::SketchObject*>(sketchgui->getObject());
|
||||||
|
|
||||||
|
Base::Vector3d pnt = Obj->getPoint(pointGeoId,pointPosId);
|
||||||
|
|
||||||
|
// undo command open
|
||||||
|
Gui::Command::openCommand("add fixed constraint");
|
||||||
|
Gui::Command::doCommand(
|
||||||
|
Gui::Command::Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('DistanceX',%d,%d,%f)) ",
|
||||||
|
sketchgui->getObject()->getNameInDocument(),pointGeoId,pointPosId,pnt.x);
|
||||||
|
Gui::Command::doCommand(
|
||||||
|
Gui::Command::Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('DistanceY',%d,%d,%f)) ",
|
||||||
|
sketchgui->getObject()->getNameInDocument(),pointGeoId,pointPosId,pnt.y);
|
||||||
|
|
||||||
|
if (pointGeoId <= Sketcher::GeoEnum::RefExt || constraintCreationMode==Reference) {
|
||||||
|
// it is a constraint on a external line, make it non-driving
|
||||||
|
const std::vector<Sketcher::Constraint *> &ConStr = Obj->Constraints.getValues();
|
||||||
|
|
||||||
|
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.setDriving(%i,%s)",
|
||||||
|
sketchgui->getObject()->getNameInDocument(),ConStr.size()-2,"False");
|
||||||
|
|
||||||
|
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.setDriving(%i,%s)",
|
||||||
|
sketchgui->getObject()->getNameInDocument(),ConStr.size()-1,"False");
|
||||||
|
}
|
||||||
|
|
||||||
|
// finish the transaction and update
|
||||||
|
Gui::Command::commitCommand();
|
||||||
|
|
||||||
|
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher");
|
||||||
|
bool autoRecompute = hGrp->GetBool("AutoRecompute",false);
|
||||||
|
|
||||||
|
if(autoRecompute)
|
||||||
|
Gui::Command::updateActive();
|
||||||
|
|
||||||
|
// clear the selection (convenience)
|
||||||
|
Gui::Selection().clearSelection();
|
||||||
|
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool selectionDone;
|
bool selectionDone;
|
||||||
Base::Vector2d EditPoint;
|
int pointGeoId;
|
||||||
|
Sketcher::PointPos pointPosId;
|
||||||
std::vector<AutoConstraint> sugConstr;
|
std::vector<AutoConstraint> sugConstr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -4729,7 +4729,6 @@ public:
|
||||||
else
|
else
|
||||||
static_cast<Sketcher::SketchObject *>(sketchgui->getObject())->solve();
|
static_cast<Sketcher::SketchObject *>(sketchgui->getObject())->solve();
|
||||||
|
|
||||||
//ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher");
|
|
||||||
bool continuousMode = hGrp->GetBool("ContinuousCreationMode",true);
|
bool continuousMode = hGrp->GetBool("ContinuousCreationMode",true);
|
||||||
|
|
||||||
if(continuousMode){
|
if(continuousMode){
|
||||||
|
@ -4878,7 +4877,7 @@ namespace SketcherGui {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
/* XPM */
|
/* XPM */
|
||||||
|
|
|
@ -61,16 +61,9 @@ using namespace Sketcher;
|
||||||
//**************************************************************************
|
//**************************************************************************
|
||||||
// Construction/Destruction
|
// Construction/Destruction
|
||||||
|
|
||||||
DrawSketchHandler::DrawSketchHandler()
|
DrawSketchHandler::DrawSketchHandler() : sketchgui(0) {}
|
||||||
: sketchgui(0)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
DrawSketchHandler::~DrawSketchHandler() {}
|
||||||
|
|
||||||
DrawSketchHandler::~DrawSketchHandler()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void DrawSketchHandler::quit(void)
|
void DrawSketchHandler::quit(void)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user