0000437 Sketcher: ask for value immediately after creating a length constraint
This commit is contained in:
parent
f66c433e6c
commit
b328943698
|
@ -37,6 +37,7 @@
|
||||||
#include <Mod/Sketcher/App/SketchObject.h>
|
#include <Mod/Sketcher/App/SketchObject.h>
|
||||||
|
|
||||||
#include "ViewProviderSketch.h"
|
#include "ViewProviderSketch.h"
|
||||||
|
#include "EditDatumDialog.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace SketcherGui;
|
using namespace SketcherGui;
|
||||||
|
@ -54,8 +55,15 @@ bool isCreateConstraintActive(Gui::Document *doc)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateDatumDistance(Gui::Document *doc, Constraint *constr)
|
// Utility method to avoid repeating the same code over and over again
|
||||||
|
void finishDistanceConstraint(Gui::Command* cmd, Sketcher::SketchObject* sketch)
|
||||||
{
|
{
|
||||||
|
// Get the latest constraint
|
||||||
|
const std::vector<Sketcher::Constraint *> &ConStr = sketch->Constraints.getValues();
|
||||||
|
Sketcher::Constraint *constr = ConStr[ConStr.size() -1];
|
||||||
|
|
||||||
|
// Guess some reasonable distance for placing the datum text
|
||||||
|
Gui::Document *doc = cmd->getActiveGuiDocument();
|
||||||
float sf = 1.f;
|
float sf = 1.f;
|
||||||
if (doc && doc->getInEdit() && doc->getInEdit()->isDerivedFrom(SketcherGui::ViewProviderSketch::getClassTypeId())) {
|
if (doc && doc->getInEdit() && doc->getInEdit()->isDerivedFrom(SketcherGui::ViewProviderSketch::getClassTypeId())) {
|
||||||
SketcherGui::ViewProviderSketch *vp = dynamic_cast<SketcherGui::ViewProviderSketch*>(doc->getInEdit());
|
SketcherGui::ViewProviderSketch *vp = dynamic_cast<SketcherGui::ViewProviderSketch*>(doc->getInEdit());
|
||||||
|
@ -64,6 +72,14 @@ void updateDatumDistance(Gui::Document *doc, Constraint *constr)
|
||||||
constr->LabelDistance = 2. * sf;
|
constr->LabelDistance = 2. * sf;
|
||||||
vp->draw(); // Redraw
|
vp->draw(); // Redraw
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ask for the value of the distance immediately
|
||||||
|
EditDatumDialog *editDatumDialog = new EditDatumDialog(sketch, ConStr.size() - 1);
|
||||||
|
editDatumDialog->exec(false);
|
||||||
|
delete editDatumDialog;
|
||||||
|
|
||||||
|
//updateActive();
|
||||||
|
cmd->getSelection().clearSelection();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool checkBothExternal(int GeoId1, int GeoId2)
|
bool checkBothExternal(int GeoId1, int GeoId2)
|
||||||
|
@ -621,14 +637,8 @@ void CmdSketcherConstrainDistance::activated(int iMsg)
|
||||||
}
|
}
|
||||||
commitCommand();
|
commitCommand();
|
||||||
|
|
||||||
// Get the latest constraint
|
finishDistanceConstraint(this, Obj);
|
||||||
const std::vector<Sketcher::Constraint *> &ConStr = dynamic_cast<Sketcher::SketchObject*>(selection[0].getObject())->Constraints.getValues();
|
|
||||||
Sketcher::Constraint *constr = ConStr[ConStr.size() -1];
|
|
||||||
|
|
||||||
updateDatumDistance(getActiveGuiDocument(), constr);
|
|
||||||
|
|
||||||
//updateActive();
|
|
||||||
getSelection().clearSelection();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if ((isVertex(GeoId1,PosId1) && isEdge(GeoId2,PosId2)) ||
|
else if ((isVertex(GeoId1,PosId1) && isEdge(GeoId2,PosId2)) ||
|
||||||
|
@ -653,14 +663,7 @@ void CmdSketcherConstrainDistance::activated(int iMsg)
|
||||||
selection[0].getFeatName(),GeoId1,PosId1,GeoId2,ActDist);
|
selection[0].getFeatName(),GeoId1,PosId1,GeoId2,ActDist);
|
||||||
commitCommand();
|
commitCommand();
|
||||||
|
|
||||||
// Get the latest constraint
|
finishDistanceConstraint(this, Obj);
|
||||||
const std::vector<Sketcher::Constraint *> &ConStr = dynamic_cast<Sketcher::SketchObject*>(selection[0].getObject())->Constraints.getValues();
|
|
||||||
Sketcher::Constraint *constr = ConStr[ConStr.size() -1];
|
|
||||||
|
|
||||||
updateDatumDistance(getActiveGuiDocument(), constr);
|
|
||||||
|
|
||||||
//updateActive();
|
|
||||||
getSelection().clearSelection();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -684,14 +687,8 @@ void CmdSketcherConstrainDistance::activated(int iMsg)
|
||||||
selection[0].getFeatName(),GeoId1,ActLength);
|
selection[0].getFeatName(),GeoId1,ActLength);
|
||||||
commitCommand();
|
commitCommand();
|
||||||
|
|
||||||
// Get the latest created constraint
|
finishDistanceConstraint(this, Obj);
|
||||||
const std::vector<Sketcher::Constraint *> &ConStr = dynamic_cast<Sketcher::SketchObject*>(selection[0].getObject())->Constraints.getValues();
|
|
||||||
Sketcher::Constraint *constr = ConStr[ConStr.size() -1];
|
|
||||||
|
|
||||||
updateDatumDistance(getActiveGuiDocument(), constr);
|
|
||||||
|
|
||||||
//updateActive();
|
|
||||||
getSelection().clearSelection();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -859,14 +856,8 @@ void CmdSketcherConstrainDistanceX::activated(int iMsg)
|
||||||
selection[0].getFeatName(),GeoId1,PosId1,GeoId2,PosId2,ActLength);
|
selection[0].getFeatName(),GeoId1,PosId1,GeoId2,PosId2,ActLength);
|
||||||
commitCommand();
|
commitCommand();
|
||||||
|
|
||||||
// Get the latest created constraint
|
finishDistanceConstraint(this, Obj);
|
||||||
const std::vector<Sketcher::Constraint *> &ConStr = dynamic_cast<Sketcher::SketchObject*>(selection[0].getObject())->Constraints.getValues();
|
|
||||||
Sketcher::Constraint *constr = ConStr[ConStr.size() -1];
|
|
||||||
|
|
||||||
updateDatumDistance(getActiveGuiDocument(), constr);
|
|
||||||
|
|
||||||
//updateActive();
|
|
||||||
getSelection().clearSelection();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (isEdge(GeoId1,PosId1) && GeoId2 == Constraint::GeoUndef) { // horizontal length of a line
|
else if (isEdge(GeoId1,PosId1) && GeoId2 == Constraint::GeoUndef) { // horizontal length of a line
|
||||||
|
@ -890,14 +881,8 @@ void CmdSketcherConstrainDistanceX::activated(int iMsg)
|
||||||
selection[0].getFeatName(),GeoId1,ActLength);
|
selection[0].getFeatName(),GeoId1,ActLength);
|
||||||
commitCommand();
|
commitCommand();
|
||||||
|
|
||||||
// Get the latest created constraint
|
finishDistanceConstraint(this, Obj);
|
||||||
const std::vector<Sketcher::Constraint *> &ConStr = dynamic_cast<Sketcher::SketchObject*>(selection[0].getObject())->Constraints.getValues();
|
|
||||||
Sketcher::Constraint *constr = ConStr[ConStr.size() -1];
|
|
||||||
|
|
||||||
updateDatumDistance(getActiveGuiDocument(), constr);
|
|
||||||
|
|
||||||
//updateActive();
|
|
||||||
getSelection().clearSelection();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -919,14 +904,8 @@ void CmdSketcherConstrainDistanceX::activated(int iMsg)
|
||||||
selection[0].getFeatName(),GeoId1,PosId1,ActX);
|
selection[0].getFeatName(),GeoId1,PosId1,ActX);
|
||||||
commitCommand();
|
commitCommand();
|
||||||
|
|
||||||
// Get the latest created constraint
|
finishDistanceConstraint(this, Obj);
|
||||||
const std::vector<Sketcher::Constraint *> &ConStr = dynamic_cast<Sketcher::SketchObject*>(selection[0].getObject())->Constraints.getValues();
|
|
||||||
Sketcher::Constraint *constr = ConStr[ConStr.size() -1];
|
|
||||||
|
|
||||||
updateDatumDistance(getActiveGuiDocument(), constr);
|
|
||||||
|
|
||||||
//updateActive();
|
|
||||||
getSelection().clearSelection();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1009,14 +988,8 @@ void CmdSketcherConstrainDistanceY::activated(int iMsg)
|
||||||
selection[0].getFeatName(),GeoId1,PosId1,GeoId2,PosId2,ActLength);
|
selection[0].getFeatName(),GeoId1,PosId1,GeoId2,PosId2,ActLength);
|
||||||
commitCommand();
|
commitCommand();
|
||||||
|
|
||||||
// Get the latest created constraint
|
finishDistanceConstraint(this, Obj);
|
||||||
const std::vector<Sketcher::Constraint *> &ConStr = dynamic_cast<Sketcher::SketchObject*>(selection[0].getObject())->Constraints.getValues();
|
|
||||||
Sketcher::Constraint *constr = ConStr[ConStr.size() -1];
|
|
||||||
|
|
||||||
updateDatumDistance(getActiveGuiDocument(), constr);
|
|
||||||
|
|
||||||
//updateActive();
|
|
||||||
getSelection().clearSelection();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (isEdge(GeoId1,PosId1) && GeoId2 == Constraint::GeoUndef) { // vertical length of a line
|
else if (isEdge(GeoId1,PosId1) && GeoId2 == Constraint::GeoUndef) { // vertical length of a line
|
||||||
|
@ -1040,14 +1013,8 @@ void CmdSketcherConstrainDistanceY::activated(int iMsg)
|
||||||
selection[0].getFeatName(),GeoId1,ActLength);
|
selection[0].getFeatName(),GeoId1,ActLength);
|
||||||
commitCommand();
|
commitCommand();
|
||||||
|
|
||||||
// Get the latest created constraint
|
finishDistanceConstraint(this, Obj);
|
||||||
const std::vector<Sketcher::Constraint *> &ConStr = dynamic_cast<Sketcher::SketchObject*>(selection[0].getObject())->Constraints.getValues();
|
|
||||||
Sketcher::Constraint *constr = ConStr[ConStr.size() -1];
|
|
||||||
|
|
||||||
updateDatumDistance(getActiveGuiDocument(), constr);
|
|
||||||
|
|
||||||
//updateActive();
|
|
||||||
getSelection().clearSelection();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1069,14 +1036,8 @@ void CmdSketcherConstrainDistanceY::activated(int iMsg)
|
||||||
selection[0].getFeatName(),GeoId1,PosId1,ActY);
|
selection[0].getFeatName(),GeoId1,PosId1,ActY);
|
||||||
commitCommand();
|
commitCommand();
|
||||||
|
|
||||||
// Get the latest created constraint
|
finishDistanceConstraint(this, Obj);
|
||||||
const std::vector<Sketcher::Constraint *> &ConStr = dynamic_cast<Sketcher::SketchObject*>(selection[0].getObject())->Constraints.getValues();
|
|
||||||
Sketcher::Constraint *constr = ConStr[ConStr.size() -1];
|
|
||||||
|
|
||||||
updateDatumDistance(getActiveGuiDocument(), constr);
|
|
||||||
|
|
||||||
//updateActive();
|
|
||||||
getSelection().clearSelection();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1491,8 +1452,8 @@ void CmdSketcherConstrainRadius::activated(int iMsg)
|
||||||
Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Radius',%d,%f)) ",
|
Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Radius',%d,%f)) ",
|
||||||
selection[0].getFeatName(),GeoId,ActRadius);
|
selection[0].getFeatName(),GeoId,ActRadius);
|
||||||
commitCommand();
|
commitCommand();
|
||||||
//updateActive();
|
|
||||||
getSelection().clearSelection();
|
finishDistanceConstraint(this, Obj);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (geom->getTypeId() == Part::GeomCircle::getClassTypeId()) {
|
else if (geom->getTypeId() == Part::GeomCircle::getClassTypeId()) {
|
||||||
|
@ -1504,8 +1465,8 @@ void CmdSketcherConstrainRadius::activated(int iMsg)
|
||||||
Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Radius',%d,%f)) ",
|
Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('Radius',%d,%f)) ",
|
||||||
selection[0].getFeatName(),GeoId,ActRadius);
|
selection[0].getFeatName(),GeoId,ActRadius);
|
||||||
commitCommand();
|
commitCommand();
|
||||||
//updateActive();
|
|
||||||
getSelection().clearSelection();
|
finishDistanceConstraint(this, Obj);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1618,14 +1579,7 @@ void CmdSketcherConstrainAngle::activated(int iMsg)
|
||||||
selection[0].getFeatName(),GeoId1,PosId1,GeoId2,PosId2,ActAngle);
|
selection[0].getFeatName(),GeoId1,PosId1,GeoId2,PosId2,ActAngle);
|
||||||
commitCommand();
|
commitCommand();
|
||||||
|
|
||||||
// Get the latest created constraint
|
finishDistanceConstraint(this, Obj);
|
||||||
const std::vector<Sketcher::Constraint *> &ConStr = dynamic_cast<Sketcher::SketchObject*>(selection[0].getObject())->Constraints.getValues();
|
|
||||||
Sketcher::Constraint *constr = ConStr[ConStr.size() -1];
|
|
||||||
|
|
||||||
updateDatumDistance(getActiveGuiDocument(), constr);
|
|
||||||
|
|
||||||
//updateActive();
|
|
||||||
getSelection().clearSelection();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if (isEdge(GeoId1,PosId1)) { // line angle
|
} else if (isEdge(GeoId1,PosId1)) { // line angle
|
||||||
|
@ -1649,14 +1603,7 @@ void CmdSketcherConstrainAngle::activated(int iMsg)
|
||||||
selection[0].getFeatName(),GeoId1,ActAngle);
|
selection[0].getFeatName(),GeoId1,ActAngle);
|
||||||
commitCommand();
|
commitCommand();
|
||||||
|
|
||||||
// Get the latest constraint
|
finishDistanceConstraint(this, Obj);
|
||||||
const std::vector<Sketcher::Constraint *> &ConStr = dynamic_cast<Sketcher::SketchObject*>(selection[0].getObject())->Constraints.getValues();
|
|
||||||
Sketcher::Constraint *constr = ConStr[ConStr.size() -1];
|
|
||||||
|
|
||||||
updateDatumDistance(getActiveGuiDocument(), constr);
|
|
||||||
|
|
||||||
//updateActive();
|
|
||||||
getSelection().clearSelection();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,9 +45,16 @@
|
||||||
|
|
||||||
using namespace SketcherGui;
|
using namespace SketcherGui;
|
||||||
|
|
||||||
EditDatumDialog::EditDatumDialog(ViewProviderSketch* vp, int ConstrNbr) : vp(vp), ConstrNbr(ConstrNbr)
|
EditDatumDialog::EditDatumDialog(ViewProviderSketch* vp, int ConstrNbr) : ConstrNbr(ConstrNbr)
|
||||||
{
|
{
|
||||||
const std::vector<Sketcher::Constraint *> &Constraints = vp->getSketchObject()->Constraints.getValues();
|
sketch = vp->getSketchObject();
|
||||||
|
const std::vector<Sketcher::Constraint *> &Constraints = sketch->Constraints.getValues();
|
||||||
|
Constr = Constraints[ConstrNbr];
|
||||||
|
}
|
||||||
|
|
||||||
|
EditDatumDialog::EditDatumDialog(Sketcher::SketchObject* pcSketch, int ConstrNbr) : sketch(pcSketch), ConstrNbr(ConstrNbr)
|
||||||
|
{
|
||||||
|
const std::vector<Sketcher::Constraint *> &Constraints = sketch->Constraints.getValues();
|
||||||
Constr = Constraints[ConstrNbr];
|
Constr = Constraints[ConstrNbr];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,7 +75,7 @@ void EditDatumDialog::exec(bool atCursor)
|
||||||
Constr->Type == Sketcher::DistanceX || Constr->Type == Sketcher::DistanceY ||
|
Constr->Type == Sketcher::DistanceX || Constr->Type == Sketcher::DistanceY ||
|
||||||
Constr->Type == Sketcher::Radius || Constr->Type == Sketcher::Angle) {
|
Constr->Type == Sketcher::Radius || Constr->Type == Sketcher::Angle) {
|
||||||
|
|
||||||
if (vp->getSketchObject()->hasConflicts()) {
|
if (sketch->hasConflicts()) {
|
||||||
QMessageBox::critical(qApp->activeWindow(), QObject::tr("Distance constraint"),
|
QMessageBox::critical(qApp->activeWindow(), QObject::tr("Distance constraint"),
|
||||||
QObject::tr("Not allowed to edit the datum because the sketch contains conflicting constraints"));
|
QObject::tr("Not allowed to edit the datum because the sketch contains conflicting constraints"));
|
||||||
return;
|
return;
|
||||||
|
@ -121,7 +128,7 @@ void EditDatumDialog::exec(bool atCursor)
|
||||||
try {
|
try {
|
||||||
Gui::Command::openCommand("Modify sketch constraints");
|
Gui::Command::openCommand("Modify sketch constraints");
|
||||||
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.setDatum(%i,%f)",
|
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.setDatum(%i,%f)",
|
||||||
vp->getObject()->getNameInDocument(),
|
sketch->getNameInDocument(),
|
||||||
ConstrNbr, newDatum);
|
ConstrNbr, newDatum);
|
||||||
Gui::Command::commitCommand();
|
Gui::Command::commitCommand();
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ class SoSensor;
|
||||||
|
|
||||||
namespace Sketcher {
|
namespace Sketcher {
|
||||||
class Constraint;
|
class Constraint;
|
||||||
|
class SketchObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace SketcherGui {
|
namespace SketcherGui {
|
||||||
|
@ -34,13 +35,14 @@ class ViewProviderSketch;
|
||||||
class EditDatumDialog {
|
class EditDatumDialog {
|
||||||
public:
|
public:
|
||||||
EditDatumDialog(ViewProviderSketch* vp, int ConstrNbr);
|
EditDatumDialog(ViewProviderSketch* vp, int ConstrNbr);
|
||||||
|
EditDatumDialog(Sketcher::SketchObject* pcSketch, int ConstrNbr);
|
||||||
~EditDatumDialog();
|
~EditDatumDialog();
|
||||||
|
|
||||||
static void run(void * data, SoSensor * sensor);
|
static void run(void * data, SoSensor * sensor);
|
||||||
void exec(bool atCursor=true);
|
void exec(bool atCursor=true);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ViewProviderSketch* vp;
|
Sketcher::SketchObject* sketch;
|
||||||
Sketcher::Constraint* Constr;
|
Sketcher::Constraint* Constr;
|
||||||
int ConstrNbr;
|
int ConstrNbr;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user