From f7c9566f1ec3aeb7165a6560d581193cb71fe854 Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Wed, 20 May 2015 16:39:17 +0200 Subject: [PATCH] Sketcher bug fixes: Non-driving constraints editable on double click and color settings not working =================================================================================================== This fixes a bug in the original implementation, that a non-driving constraint value could be edited by double clicking on it in the 3D view. It also includes minimal documentation on some functions. It also includes: - Color setting for non-driving constraints was not working. - Settle UI terminology dispute: * Driving Constraint (normal red constraint) * Reference Constraint (non-driving constraint) --- src/Mod/Sketcher/App/Sketch.h | 126 ++++++++++++++++-- src/Mod/Sketcher/Gui/SketcherSettings.cpp | 2 + .../Sketcher/Gui/TaskSketcherConstrains.cpp | 2 +- src/Mod/Sketcher/Gui/ViewProviderSketch.cpp | 4 +- 4 files changed, 119 insertions(+), 15 deletions(-) diff --git a/src/Mod/Sketcher/App/Sketch.h b/src/Mod/Sketcher/App/Sketch.h index fff2e63dc24e..244db2d19953 100644 --- a/src/Mod/Sketcher/App/Sketch.h +++ b/src/Mod/Sketcher/App/Sketch.h @@ -134,26 +134,86 @@ class SketcherExport Sketch :public Base::Persistence int addConstraints(const std::vector &ConstraintList); /// add one constraint to the sketch int addConstraint(const Constraint *constraint); - /// add a fixed coordinate constraint to a point + + /** + * add a fixed X coordinate constraint to a point + * + * double * value is a pointer to double allocated in the heap, containing the + * constraint value and already inserted into either the FixParameters or + * Parameters array, as the case may be. + */ int addCoordinateXConstraint(int geoId, PointPos pos, double * value); + /** + * add a fixed Y coordinate constraint to a point + * + * double * value is a pointer to double allocated in the heap, containing the + * constraint value and already inserted into either the FixParameters or + * Parameters array, as the case may be. + */ int addCoordinateYConstraint(int geoId, PointPos pos, double * value); - /// add a horizontal distance constraint to two points or line ends + /** + * add a horizontal distance constraint to two points or line ends + * + * double * value is a pointer to double allocated in the heap, containing the + * constraint value and already inserted into either the FixParameters or + * Parameters array, as the case may be. + */ int addDistanceXConstraint(int geoId, double * value); + /** + * add a horizontal distance constraint to two points or line ends + * + * double * value is a pointer to double allocated in the heap, containing the + * constraint value and already inserted into either the FixParameters or + * Parameters array, as the case may be. + */ int addDistanceXConstraint(int geoId1, PointPos pos1, int geoId2, PointPos pos2, double * value); - /// add a vertical distance constraint to two points or line ends + /** + * add a vertical distance constraint to two points or line ends + * + * double * value is a pointer to double allocated in the heap, containing the + * constraint value and already inserted into either the FixParameters or + * Parameters array, as the case may be. + */ int addDistanceYConstraint(int geoId, double * value); + /** + * add a vertical distance constraint to two points or line ends + * + * double * value is a pointer to double allocated in the heap, containing the + * constraint value and already inserted into either the FixParameters or + * Parameters array, as the case may be. + */ int addDistanceYConstraint(int geoId1, PointPos pos1, int geoId2, PointPos pos2, double * value); /// add a horizontal constraint to a geometry int addHorizontalConstraint(int geoId); int addHorizontalConstraint(int geoId1, PointPos pos1, int geoId2, PointPos pos2); /// add a vertical constraint to a geometry - int addVerticalConstraint(int geoId); + int addVerticalConstraint(int geoId); int addVerticalConstraint(int geoId1, PointPos pos1, int geoId2, PointPos pos2); /// add a coincident constraint to two points of two geometries int addPointCoincidentConstraint(int geoId1, PointPos pos1, int geoId2, PointPos pos2); - /// add a length or distance constraint + /** + * add a length or distance constraint + * + * double * value is a pointer to double allocated in the heap, containing the + * constraint value and already inserted into either the FixParameters or + * Parameters array, as the case may be. + */ int addDistanceConstraint(int geoId1, double * value); + /** + * add a length or distance constraint + * + * double * value is a pointer to double allocated in the heap, containing the + * constraint value and already inserted into either the FixParameters or + * Parameters array, as the case may be. + */ int addDistanceConstraint(int geoId1, PointPos pos1, int geoId2, double * value); + /** + * add a length or distance constraint + * + * double * value is a pointer to double allocated in the heap, containing the + * constraint value and already inserted into either the FixParameters or + * Parameters array, as the case may be. + */ int addDistanceConstraint(int geoId1, PointPos pos1, int geoId2, PointPos pos2, double * value); /// add a parallel constraint between two lines int addParallelConstraint(int geoId1, int geoId2); @@ -167,23 +227,65 @@ class SketcherExport Sketch :public Base::Persistence int geoId3, PointPos pos3, double * value, ConstraintType cTyp); - /// add a radius constraint on a circle or an arc + /** + * add a radius constraint on a circle or an arc + * + * double * value is a pointer to double allocated in the heap, containing the + * constraint value and already inserted into either the FixParameters or + * Parameters array, as the case may be. + */ int addRadiusConstraint(int geoId, double * value); - /// add an angle constraint on a line or between two lines + /** + * add an angle constraint on a line or between two lines + * + * double * value is a pointer to double allocated in the heap, containing the + * constraint value and already inserted into either the FixParameters or + * Parameters array, as the case may be. + */ int addAngleConstraint(int geoId, double * value); + /** + * add an angle constraint on a line or between two lines + * + * double * value is a pointer to double allocated in the heap, containing the + * constraint value and already inserted into either the FixParameters or + * Parameters array, as the case may be. + */ int addAngleConstraint(int geoId1, int geoId2, double * value); + /** + * add an angle constraint on a line or between two lines + * + * double * value is a pointer to double allocated in the heap, containing the + * constraint value and already inserted into either the FixParameters or + * Parameters array, as the case may be. + */ int addAngleConstraint(int geoId1, PointPos pos1, int geoId2, PointPos pos2, double * value); - /// add angle-via-point constraint between any two curves + /** + * add angle-via-point constraint between any two curves + * + * double * value is a pointer to double allocated in the heap, containing the + * constraint value and already inserted into either the FixParameters or + * Parameters array, as the case may be. + */ int addAngleViaPointConstraint(int geoId1, int geoId2, int geoId3, PointPos pos3, double value); /// add an equal length or radius constraints between two lines or between circles and arcs - int addEqualConstraint(int geoId1, int geoId2); + int addEqualConstraint(int geoId1, int geoId2); /// add a point on line constraint int addPointOnObjectConstraint(int geoId1, PointPos pos1, int geoId2); /// add a symmetric constraint between two points with respect to a line int addSymmetricConstraint(int geoId1, PointPos pos1, int geoId2, PointPos pos2, int geoId3); /// add a symmetric constraint between three points, the last point is in the middle of the first two int addSymmetricConstraint(int geoId1, PointPos pos1, int geoId2, PointPos pos2, int geoId3, PointPos pos3); - /// add a snell's law constraint + /** + * add a snell's law constraint + * + * double * value and double * second are each a pointer to double + * allocated in the heap and already inserted into either the + * FixParameters or Parameters array, as the case may be. + * + * value must contain the constraint value (the ratio of n2/n1) + * second may be initialized to any value, however the solver will + * provide n1 in value and n2 in second. + */ int addSnellsLawConstraint(int geoIdRay1, PointPos posRay1, int geoIdRay2, PointPos posRay2, int geoIdBnd, @@ -199,7 +301,7 @@ class SketcherExport Sketch :public Base::Persistence int addInternalAlignmentEllipseFocus1(int geoId1, int geoId2); int addInternalAlignmentEllipseFocus2(int geoId1, int geoId2); //@} - +public: //This func is to be used during angle-via-point constraint creation. It calculates //the angle between geoId1,geoId2 at point px,py. The point should be on both curves, //otherwise the result will be systematically off (but smoothly approach the correct @@ -238,7 +340,7 @@ class SketcherExport Sketch :public Base::Persistence int midPointId; // index in Points of the start point of this geometry int endPointId; // index in Points of the end point of this geometry }; - + /// container element to store and work with the constraints of this sketch struct ConstrDef { ConstrDef() : driving(true) {} Constraint * constr; // pointer to the constraint diff --git a/src/Mod/Sketcher/Gui/SketcherSettings.cpp b/src/Mod/Sketcher/Gui/SketcherSettings.cpp index 844c85d2ff5a..3a3d7c3ca7b9 100644 --- a/src/Mod/Sketcher/Gui/SketcherSettings.cpp +++ b/src/Mod/Sketcher/Gui/SketcherSettings.cpp @@ -103,6 +103,7 @@ void SketcherSettings::saveSettings() ui->FullyConstrainedColor->onSave(); ui->ConstrainedColor->onSave(); + ui->NonDrivingConstraintColor->onSave(); ui->DatumColor->onSave(); ui->SketcherDatumWidth->onSave(); @@ -134,6 +135,7 @@ void SketcherSettings::loadSettings() ui->FullyConstrainedColor->onRestore(); ui->ConstrainedColor->onRestore(); + ui->NonDrivingConstraintColor->onRestore(); ui->DatumColor->onRestore(); ui->SketcherDatumWidth->onRestore(); diff --git a/src/Mod/Sketcher/Gui/TaskSketcherConstrains.cpp b/src/Mod/Sketcher/Gui/TaskSketcherConstrains.cpp index b4ff81ae2f0b..5ae5ad382b16 100644 --- a/src/Mod/Sketcher/Gui/TaskSketcherConstrains.cpp +++ b/src/Mod/Sketcher/Gui/TaskSketcherConstrains.cpp @@ -136,7 +136,7 @@ void ConstraintView::contextMenuEvent (QContextMenuEvent* event) { ConstraintItem *it = dynamic_cast(item); - QAction* driven = menu.addAction(it->isDriving?tr("Disable"):tr("Enable"), this, SLOT(updateDrivingStatus())); + QAction* driven = menu.addAction(it->isDriving?tr("Change to reference"):tr("Change to driving"), this, SLOT(updateDrivingStatus())); // if its the right constraint if ((it->Type == Sketcher::Distance || it->Type == Sketcher::DistanceX || diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp index 3303ee392fd2..e8a4f22b0582 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp @@ -929,12 +929,12 @@ void ViewProviderSketch::editDoubleClicked(void) Constraint *Constr = constrlist[*it]; // if its the right constraint - if (Constr->Type == Sketcher::Distance || + if ((Constr->Type == Sketcher::Distance || Constr->Type == Sketcher::DistanceX || Constr->Type == Sketcher::DistanceY || Constr->Type == Sketcher::Radius || Constr->Type == Sketcher::Angle || - Constr->Type == Sketcher::SnellsLaw ) { + Constr->Type == Sketcher::SnellsLaw) && Constr->isDriving ) { // Coin's SoIdleSensor causes problems on some platform while Qt seems to work properly (#0001517) EditDatumDialog *editDatumDialog = new EditDatumDialog(this, *it);