Skip to content

Commit

Permalink
[Sketcher] Local settings are correctly restored ; fixes #3952,#4058
Browse files Browse the repository at this point in the history
  • Loading branch information
0penBrain authored and abdullahtahiriyo committed May 27, 2020
1 parent 9d9aaf6 commit 811a446
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/Mod/Sketcher/Gui/CommandCreateGeo.cpp
Expand Up @@ -362,7 +362,7 @@ class DrawSketchHandlerLine: public DrawSketchHandler
}

ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher");
bool avoidredundant = hGrp->GetGroup("General")->GetBool("AvoidRedundantAutoconstraints",true) && sketchgui->Autoconstraints.getValue();
bool avoidredundant = sketchgui->AvoidRedundant.getValue() && sketchgui->Autoconstraints.getValue();

if(avoidredundant)
removeRedundantHorizontalVertical(static_cast<Sketcher::SketchObject *>(sketchgui->getObject()),sugConstr1,sugConstr2);
Expand Down Expand Up @@ -1167,7 +1167,7 @@ class DrawSketchHandlerLineSet: public DrawSketchHandler
}

ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher");
bool avoidredundant = hGrp->GetGroup("General")->GetBool("AvoidRedundantAutoconstraints",true) && sketchgui->Autoconstraints.getValue();
bool avoidredundant = sketchgui->AvoidRedundant.getValue() && sketchgui->Autoconstraints.getValue();

if (Mode == STATUS_Close) {

Expand Down
41 changes: 40 additions & 1 deletion src/Mod/Sketcher/Gui/TaskSketcherGeneral.cpp
Expand Up @@ -60,6 +60,8 @@ SketcherGeneralWidget::SketcherGeneralWidget(QWidget *parent)
this, SIGNAL(emitSetGridSize(double)));
connect(ui->checkBoxAutoconstraints, SIGNAL(toggled(bool)),
this, SIGNAL(emitToggleAutoconstraints(bool)));
connect(ui->checkBoxRedundantAutoconstraints, SIGNAL(toggled(bool)),
this, SIGNAL(emitToggleAvoidRedundant(bool)));
ui->renderingOrder->installEventFilter(this);
}

Expand Down Expand Up @@ -103,6 +105,7 @@ void SketcherGeneralWidget::loadSettings()
{
ui->checkBoxShowGrid->onRestore();
ui->gridSize->onRestore();
if (ui->gridSize->rawValue() == 0) { ui->gridSize->setValue(10.0); }
ui->checkBoxGridSnap->onRestore();
ui->checkBoxAutoconstraints->onRestore();
ui->checkBoxRedundantAutoconstraints->onRestore();
Expand Down Expand Up @@ -160,6 +163,11 @@ void SketcherGeneralWidget::checkAutoconstraints(bool on)
ui->checkBoxAutoconstraints->setChecked(on);
}

void SketcherGeneralWidget::checkAvoidRedundant(bool on)
{
ui->checkBoxRedundantAutoconstraints->setChecked(on);
}

void SketcherGeneralWidget::enableGridSettings(bool on)
{
ui->label->setEnabled(on);
Expand Down Expand Up @@ -189,6 +197,22 @@ TaskSketcherGeneral::TaskSketcherGeneral(ViewProviderSketch *sketchView)
// we need a separate container widget to add all controls to
widget = new SketcherGeneralWidget(this);
this->groupLayout()->addWidget(widget);

{
//Blocker probably not needed as signals aren't connected yet
QSignalBlocker block(widget);
//Load default settings to get ordering order & avoid redundant values
widget->loadSettings();
widget->checkGridView(sketchView->ShowGrid.getValue());
if (sketchView->GridSize.getValue() > 0) {
widget->setGridSize(sketchView->GridSize.getValue());
}
widget->checkGridSnap(sketchView->GridSnap.getValue());
widget->enableGridSettings(sketchView->ShowGrid.getValue());
widget->checkAutoconstraints(sketchView->Autoconstraints.getValue());
widget->checkAvoidRedundant(sketchView->AvoidRedundant.getValue());
widget->enableAvoidRedundant(sketchView->Autoconstraints.getValue());
}

// connecting the needed signals
QObject::connect(
Expand All @@ -210,14 +234,18 @@ TaskSketcherGeneral::TaskSketcherGeneral(ViewProviderSketch *sketchView)
widget, SIGNAL(emitToggleAutoconstraints(bool)),
this , SLOT (onToggleAutoconstraints(bool))
);

QObject::connect(
widget, SIGNAL(emitToggleAvoidRedundant(bool)),
this , SLOT (onToggleAvoidRedundant(bool))
);

QObject::connect(
widget, SIGNAL(emitRenderOrderChanged()),
this , SLOT (onRenderOrderChanged())
);

Gui::Selection().Attach(this);
widget->loadSettings();

Gui::Application* app = Gui::Application::Instance;
changedSketchView = app->signalChangedObject.connect(boost::bind
Expand All @@ -239,6 +267,7 @@ void TaskSketcherGeneral::onChangedSketchView(const Gui::ViewProvider& vp,
widget->enableGridSettings(sketchView->ShowGrid.getValue());
if (sketchView->ShowGrid.getValue()) {
sketchView->createGrid();
}
}
else if (&sketchView->GridSize == &prop) {
QSignalBlocker block(widget);
Expand All @@ -253,6 +282,10 @@ void TaskSketcherGeneral::onChangedSketchView(const Gui::ViewProvider& vp,
widget->checkAutoconstraints(sketchView->Autoconstraints.getValue());
widget->enableAvoidRedundant(sketchView->Autoconstraints.getValue());
}
else if (&sketchView->AvoidRedundant == &prop) {
QSignalBlocker block(widget);
widget->checkAvoidRedundant(sketchView->AvoidRedundant.getValue());
}
}
}

Expand Down Expand Up @@ -283,6 +316,12 @@ void TaskSketcherGeneral::onToggleAutoconstraints(bool on)
widget->enableAvoidRedundant(on);
}

void TaskSketcherGeneral::onToggleAvoidRedundant(bool on)
{
Base::ConnectionBlocker block(changedSketchView);
sketchView->AvoidRedundant.setValue(on);
}

/// @cond DOXERR
void TaskSketcherGeneral::OnChange(Gui::SelectionSingleton::SubjectType &rCaller,
Gui::SelectionSingleton::MessageType Reason)
Expand Down
3 changes: 3 additions & 0 deletions src/Mod/Sketcher/Gui/TaskSketcherGeneral.h
Expand Up @@ -60,6 +60,7 @@ class SketcherGeneralWidget : public QWidget
void checkGridView(bool);
void checkGridSnap(bool);
void checkAutoconstraints(bool);
void checkAvoidRedundant(bool);
void enableGridSettings(bool);
void enableAvoidRedundant(bool);

Expand All @@ -68,6 +69,7 @@ class SketcherGeneralWidget : public QWidget
void emitToggleGridSnap(bool);
void emitSetGridSize(double);
void emitToggleAutoconstraints(bool);
void emitToggleAvoidRedundant(bool);
void emitRenderOrderChanged();

protected:
Expand All @@ -94,6 +96,7 @@ public Q_SLOTS:
void onSetGridSize(double val);
void onToggleGridSnap(bool on);
void onToggleAutoconstraints(bool on);
void onToggleAvoidRedundant(bool);
void onRenderOrderChanged();

private:
Expand Down
5 changes: 5 additions & 0 deletions src/Mod/Sketcher/Gui/ViewProviderSketch.cpp
Expand Up @@ -291,6 +291,7 @@ ViewProviderSketch::ViewProviderSketch()
listener(0)
{
ADD_PROPERTY_TYPE(Autoconstraints,(true),"Auto Constraints",(App::PropertyType)(App::Prop_None),"Create auto constraints");
ADD_PROPERTY_TYPE(AvoidRedundant,(true),"Auto Constraints",(App::PropertyType)(App::Prop_None),"Avoid redundant autoconstraint");
ADD_PROPERTY_TYPE(TempoVis,(Py::None()),"Visibility automation",(App::PropertyType)(App::Prop_None),"Object that handles hiding and showing other objects when entering/leaving sketch.");
ADD_PROPERTY_TYPE(HideDependent,(true),"Visibility automation",(App::PropertyType)(App::Prop_None),"If true, all objects that depend on the sketch are hidden when opening editing.");
ADD_PROPERTY_TYPE(ShowLinks,(true),"Visibility automation",(App::PropertyType)(App::Prop_None),"If true, all objects used in links to external geometry are shown when opening sketch.");
Expand All @@ -306,7 +307,11 @@ ViewProviderSketch::ViewProviderSketch()
this->RestoreCamera.setValue(hGrp->GetBool("RestoreCamera", true));

// well it is not visibility automation but a good place nevertheless
this->ShowGrid.setValue(hGrp->GetBool("ShowGrid", false));
this->GridSize.setValue(Base::Quantity::parse(QString::fromLatin1(hGrp->GetGroup("GridSize")->GetASCII("Hist0", "10.0").c_str())).getValue());
this->GridSnap.setValue(hGrp->GetBool("GridSnap", false));
this->Autoconstraints.setValue(hGrp->GetBool("AutoConstraints", true));
this->AvoidRedundant.setValue(hGrp->GetBool("AvoidRedundantAutoconstraints", true));
}

sPixmap = "Sketcher_Sketch";
Expand Down
1 change: 1 addition & 0 deletions src/Mod/Sketcher/Gui/ViewProviderSketch.h
Expand Up @@ -100,6 +100,7 @@ class SketcherGuiExport ViewProviderSketch : public PartGui::ViewProvider2DObjec
virtual ~ViewProviderSketch();

App::PropertyBool Autoconstraints;
App::PropertyBool AvoidRedundant;
App::PropertyPythonObject TempoVis;
App::PropertyBool HideDependent;
App::PropertyBool ShowLinks;
Expand Down

0 comments on commit 811a446

Please sign in to comment.