From ba5a8fe87c40f69786fb99e82d987ebd23994c27 Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Thu, 21 May 2015 14:54:55 +0200 Subject: [PATCH] Sketcher: New Feature: Continuous creation mode =============================================== When creating a type of geometric element, the user can create as many elements of that type he wishes without having to click the button before each insertion. The insertion of that type of elements ends by pressing ESC or clicking the right button of the mouse. This mode is by default disabled and can be enabled in Preferences->Display->Sketch->Geometry Creation "Continue Mode". --- src/Mod/Sketcher/Gui/CommandCreateGeo.cpp | 311 +++++++++++++++++++--- src/Mod/Sketcher/Gui/SketcherSettings.cpp | 2 + src/Mod/Sketcher/Gui/SketcherSettings.ui | 15 +- 3 files changed, 288 insertions(+), 40 deletions(-) diff --git a/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp b/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp index 85f1cc9b8b75..1bc2540ef45a 100644 --- a/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp +++ b/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp @@ -252,7 +252,23 @@ class DrawSketchHandlerLine: public DrawSketchHandler EditCurve.clear(); sketchgui->drawEdit(EditCurve); - sketchgui->purgeHandler(); // no code after this line, Handler get deleted in ViewProvider + + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool continuousMode = hGrp->GetBool("ContinuousCreationMode", false); + + if(continuousMode){ + // This code enables the continuous creation mode. + Mode=STATUS_SEEK_First; + EditCurve.resize(2); + applyCursor(); + /* It is ok not to call to purgeHandler + * in continuous creation mode because the + * handler is destroyed by the quit() method on pressing the + * right button of the mouse */ + } + else{ + sketchgui->purgeHandler(); // no code after this line, Handler get deleted in ViewProvider + } } return true; } @@ -456,9 +472,26 @@ class DrawSketchHandlerBox: public DrawSketchHandler sugConstr2.clear(); } - EditCurve.clear(); - sketchgui->drawEdit(EditCurve); - sketchgui->purgeHandler(); // no code after this line, Handler get deleted in ViewProvider + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool continuousMode = hGrp->GetBool("ContinuousCreationMode", false); + + if(continuousMode){ + // This code enables the continuous creation mode. + Mode=STATUS_SEEK_First; + EditCurve.clear(); + sketchgui->drawEdit(EditCurve); + EditCurve.resize(5); + applyCursor(); + /* this is ok not to call to purgeHandler + * in continuous creation mode because the + * handler is destroyed by the quit() method on pressing the + * right button of the mouse */ + } + else{ + sketchgui->purgeHandler(); // no code after this line, Handler get deleted in ViewProvider + } + + } return true; } @@ -803,11 +836,35 @@ class DrawSketchHandlerLineSet: public DrawSketchHandler // exit on clicking exactly at the same position (e.g. double click) if (onSketchPos == EditCurve[0]) { unsetCursor(); - EditCurve.clear(); resetPositionText(); + EditCurve.clear(); sketchgui->drawEdit(EditCurve); - sketchgui->purgeHandler(); // no code after this line, Handler get deleted in ViewProvider - return true; // 'this' instance is destroyed now! + + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool continuousMode = hGrp->GetBool("ContinuousCreationMode", false); + + if(continuousMode){ + // This code enables the continuous creation mode. + Mode=STATUS_SEEK_First; + SegmentMode=SEGMENT_MODE_Line; + TransitionMode=TRANSITION_MODE_Free; + suppressTransition=false; + firstCurve=-1; + previousCurve=-1; + firstPosId=Sketcher::none; + previousPosId=Sketcher::none; + EditCurve.resize(2); + applyCursor(); + /* this is ok not to call to purgeHandler + * in continuous creation mode because the + * handler is destroyed by the quit() method on pressing the + * right button of the mouse */ + return true; + } + else{ + sketchgui->purgeHandler(); // no code after this line, Handler get deleted in ViewProvider + return true; + } } Mode = STATUS_Do; @@ -911,10 +968,34 @@ class DrawSketchHandlerLineSet: public DrawSketchHandler } unsetCursor(); - EditCurve.clear(); + resetPositionText(); - sketchgui->drawEdit(EditCurve); - sketchgui->purgeHandler(); // no code after this line, Handler get deleted in ViewProvider + EditCurve.clear(); + sketchgui->drawEdit(EditCurve); + + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool continuousMode = hGrp->GetBool("ContinuousCreationMode", false); + + if(continuousMode){ + // This code enables the continuous creation mode. + Mode=STATUS_SEEK_First; + SegmentMode=SEGMENT_MODE_Line; + TransitionMode=TRANSITION_MODE_Free; + suppressTransition=false; + firstCurve=-1; + previousCurve=-1; + firstPosId=Sketcher::none; + previousPosId=Sketcher::none; + EditCurve.resize(2); + applyCursor(); + /* this is ok not to call to purgeHandler + * in continuous creation mode because the + * handler is destroyed by the quit() method on pressing the + * right button of the mouse */ + } + else{ + sketchgui->purgeHandler(); // no code after this line, Handler get deleted in ViewProvider + } } else { Gui::Command::commitCommand(); @@ -1230,9 +1311,24 @@ class DrawSketchHandlerArc : public DrawSketchHandler sugConstr3.clear(); } - EditCurve.clear(); - sketchgui->drawEdit(EditCurve); - sketchgui->purgeHandler(); // no code after this line, Handler get deleted in ViewProvider + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool continuousMode = hGrp->GetBool("ContinuousCreationMode", false); + + if(continuousMode){ + // This code enables the continuous creation mode. + Mode=STATUS_SEEK_First; + EditCurve.clear(); + sketchgui->drawEdit(EditCurve); + EditCurve.resize(2); + applyCursor(); + /* this is ok not to call to purgeHandler + * in continuous creation mode because the + * handler is destroyed by the quit() method on pressing the + * right button of the mouse */ + } + else{ + sketchgui->purgeHandler(); // no code after this line, Handler get deleted in ViewProvider + } } return true; } @@ -1503,9 +1599,24 @@ class DrawSketchHandler3PointArc : public DrawSketchHandler sugConstr3.clear(); } - EditCurve.clear(); - sketchgui->drawEdit(EditCurve); - sketchgui->purgeHandler(); // no code after this line, Handler get deleted in ViewProvider + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool continuousMode = hGrp->GetBool("ContinuousCreationMode", false); + + if(continuousMode){ + // This code enables the continuous creation mode. + Mode=STATUS_SEEK_First; + EditCurve.clear(); + sketchgui->drawEdit(EditCurve); + EditCurve.resize(2); + applyCursor(); + /* this is ok not to call to purgeHandler + * in continuous creation mode because the + * handler is destroyed by the quit() method on pressing the + * right button of the mouse */ + } + else{ + sketchgui->purgeHandler(); // no code after this line, Handler get deleted in ViewProvider + } } return true; } @@ -1760,9 +1871,24 @@ class DrawSketchHandlerCircle : public DrawSketchHandler sugConstr2.clear(); } - EditCurve.clear(); - sketchgui->drawEdit(EditCurve); - sketchgui->purgeHandler(); // no code after this line, Handler get deleted in ViewProvider + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool continuousMode = hGrp->GetBool("ContinuousCreationMode", false); + + if(continuousMode){ + // This code enables the continuous creation mode. + Mode=STATUS_SEEK_First; + EditCurve.clear(); + sketchgui->drawEdit(EditCurve); + EditCurve.resize(34); + applyCursor(); + /* this is ok not to call to purgeHandler + * in continuous creation mode because the + * handler is destroyed by the quit() method on pressing the + * right button of the mouse */ + } + else{ + sketchgui->purgeHandler(); // no code after this line, Handler get deleted in ViewProvider + } } return true; } @@ -2054,6 +2180,18 @@ class DrawSketchHandlerEllipse : public DrawSketchHandler { if (mode == STATUS_Close) { saveEllipse(); + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool continuousMode = hGrp->GetBool("ContinuousCreationMode", false); + + if(continuousMode){ + if (constrMethod == 0) { + method = CENTER_PERIAPSIS_B; + mode = STATUS_SEEK_CENTROID; + } else { + method = PERIAPSIS_APOAPSIS_B; + mode = STATUS_SEEK_PERIAPSIS; + } + } } return true; } @@ -2556,10 +2694,34 @@ class DrawSketchHandlerEllipse : public DrawSketchHandler } } - // delete the temp construction curve from the sketch - editCurve.clear(); - sketchgui->drawEdit(editCurve); - sketchgui->purgeHandler(); // no code after this line, Handler gets deleted in ViewProvider + // This code enables the continuous creation mode. + if (constrMethod == 0) { + method = CENTER_PERIAPSIS_B; + mode = STATUS_SEEK_CENTROID; + } else { + method = PERIAPSIS_APOAPSIS_B; + mode = STATUS_SEEK_PERIAPSIS; + } + editCurve.clear(); + sketchgui->drawEdit(editCurve); + + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool continuousMode = hGrp->GetBool("ContinuousCreationMode", false); + + + if(continuousMode){ + // This code enables the continuous creation mode. + editCurve.resize(33); + applyCursor(); + /* It is ok not to call to purgeHandler + * in continuous creation mode because the + * handler is destroyed by the quit() method on pressing the + * right button of the mouse */ + } + else{ + sketchgui->purgeHandler(); // no code after this line, Handler get deleted in ViewProvider + } + } }; @@ -2929,9 +3091,24 @@ class DrawSketchHandlerArcOfEllipse : public DrawSketchHandler sugConstr4.clear(); } - EditCurve.clear(); - sketchgui->drawEdit(EditCurve); - sketchgui->purgeHandler(); // no code after this line, Handler get deleted in ViewProvider + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool continuousMode = hGrp->GetBool("ContinuousCreationMode", false); + + if(continuousMode){ + // This code enables the continuous creation mode. + Mode=STATUS_SEEK_First; + EditCurve.clear(); + sketchgui->drawEdit(EditCurve); + EditCurve.resize(34); + applyCursor(); + /* this is ok not to call to purgeHandler + * in continuous creation mode because the + * handler is destroyed by the quit() method on pressing the + * right button of the mouse */ + } + else{ + sketchgui->purgeHandler(); // no code after this line, Handler get deleted in ViewProvider + } } return true; } @@ -3246,10 +3423,25 @@ class DrawSketchHandler3PointCircle : public DrawSketchHandler createAutoConstraints(sugConstr3, getHighestCurveIndex(), Sketcher::none); sugConstr3.clear(); } - - EditCurve.clear(); - sketchgui->drawEdit(EditCurve); - sketchgui->purgeHandler(); // no code after this line, Handler get deleted in ViewProvider + + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool continuousMode = hGrp->GetBool("ContinuousCreationMode", false); + + if(continuousMode){ + // This code enables the continuous creation mode. + Mode=STATUS_SEEK_First; + EditCurve.clear(); + sketchgui->drawEdit(EditCurve); + EditCurve.resize(2); + applyCursor(); + /* this is ok not to call to purgeHandler + * in continuous creation mode because the + * handler is destroyed by the quit() method on pressing the + * right button of the mouse */ + } + else{ + sketchgui->purgeHandler(); // no code after this line, Handler get deleted in ViewProvider + } } return true; } @@ -3453,7 +3645,20 @@ class DrawSketchHandlerPoint: public DrawSketchHandler sugConstr.clear(); } - sketchgui->purgeHandler(); // no code after this line, Handler get deleted in ViewProvider + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool continuousMode = hGrp->GetBool("ContinuousCreationMode", false); + + if(continuousMode){ + // This code enables the continuous creation mode. + applyCursor(); + /* It is ok not to call to purgeHandler + * in continuous creation mode because the + * handler is destroyed by the quit() method on pressing the + * right button of the mouse */ + } + else{ + sketchgui->purgeHandler(); // no code after this line, Handler get deleted in ViewProvider + } } return true; } @@ -4332,10 +4537,24 @@ class DrawSketchHandlerSlot: public DrawSketchHandler Gui::Command::abortCommand(); Gui::Command::updateActive(); } - - EditCurve.clear(); - sketchgui->drawEdit(EditCurve); - sketchgui->purgeHandler(); // no code after this line, Handler get deleted in ViewProvider + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool continuousMode = hGrp->GetBool("ContinuousCreationMode", false); + + if(continuousMode){ + // This code enables the continuous creation mode. + Mode=STATUS_SEEK_First; + EditCurve.clear(); + sketchgui->drawEdit(EditCurve); + EditCurve.resize(36); + applyCursor(); + /* this is ok not to call to purgeHandler + * in continuous creation mode because the + * handler is destroyed by the quit() method on pressing the + * right button of the mouse */ + } + else{ + sketchgui->purgeHandler(); // no code after this line, Handler get deleted in ViewProvider + } } return true; } @@ -4529,10 +4748,24 @@ class DrawSketchHandlerRegularPolygon: public DrawSketchHandler Gui::Command::abortCommand(); Gui::Command::updateActive(); } - - EditCurve.clear(); - sketchgui->drawEdit(EditCurve); - sketchgui->purgeHandler(); // no code after this line, Handler get deleted in ViewProvider + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool continuousMode = hGrp->GetBool("ContinuousCreationMode", false); + + if(continuousMode){ + // This code enables the continuous creation mode. + Mode=STATUS_SEEK_First; + EditCurve.clear(); + sketchgui->drawEdit(EditCurve); + EditCurve.resize(Corners+1); + applyCursor(); + /* this is ok not to call to purgeHandler + * in continuous creation mode because the + * handler is destroyed by the quit() method on pressing the + * right button of the mouse */ + } + else{ + sketchgui->purgeHandler(); // no code after this line, Handler get deleted in ViewProvider + } } return true; } diff --git a/src/Mod/Sketcher/Gui/SketcherSettings.cpp b/src/Mod/Sketcher/Gui/SketcherSettings.cpp index 3a3d7c3ca7b9..7d8176d55c4c 100644 --- a/src/Mod/Sketcher/Gui/SketcherSettings.cpp +++ b/src/Mod/Sketcher/Gui/SketcherSettings.cpp @@ -115,6 +115,7 @@ void SketcherSettings::saveSettings() // Sketch editing ui->EditSketcherFontSize->onSave(); ui->dialogOnDistanceConstraint->onSave(); + ui->continueMode->onSave(); form->saveSettings(); ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Part"); @@ -147,6 +148,7 @@ void SketcherSettings::loadSettings() // Sketch editing ui->EditSketcherFontSize->onRestore(); ui->dialogOnDistanceConstraint->onRestore(); + ui->continueMode->onRestore(); form->loadSettings(); ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Part"); diff --git a/src/Mod/Sketcher/Gui/SketcherSettings.ui b/src/Mod/Sketcher/Gui/SketcherSettings.ui index 9bc8607c1bd9..c67d4a90906e 100644 --- a/src/Mod/Sketcher/Gui/SketcherSettings.ui +++ b/src/Mod/Sketcher/Gui/SketcherSettings.ui @@ -7,7 +7,7 @@ 0 0 404 - 652 + 680 @@ -565,6 +565,19 @@ + + + + Geometry Creation "Continue Mode" + + + ContinuousCreationMode + + + Mod/Sketcher + + +