Skip to content

Commit

Permalink
Sketcher bug fixes: Non-driving constraints editable on double click …
Browse files Browse the repository at this point in the history
…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)
  • Loading branch information
abdullahtahiriyo authored and wwmayer committed May 30, 2015
1 parent ad180fb commit f7c9566
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 15 deletions.
126 changes: 114 additions & 12 deletions src/Mod/Sketcher/App/Sketch.h
Expand Up @@ -134,26 +134,86 @@ class SketcherExport Sketch :public Base::Persistence
int addConstraints(const std::vector<Constraint *> &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);
Expand All @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/Mod/Sketcher/Gui/SketcherSettings.cpp
Expand Up @@ -103,6 +103,7 @@ void SketcherSettings::saveSettings()
ui->FullyConstrainedColor->onSave();

ui->ConstrainedColor->onSave();
ui->NonDrivingConstraintColor->onSave();
ui->DatumColor->onSave();

ui->SketcherDatumWidth->onSave();
Expand Down Expand Up @@ -134,6 +135,7 @@ void SketcherSettings::loadSettings()
ui->FullyConstrainedColor->onRestore();

ui->ConstrainedColor->onRestore();
ui->NonDrivingConstraintColor->onRestore();
ui->DatumColor->onRestore();

ui->SketcherDatumWidth->onRestore();
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/Sketcher/Gui/TaskSketcherConstrains.cpp
Expand Up @@ -136,7 +136,7 @@ void ConstraintView::contextMenuEvent (QContextMenuEvent* event)
{
ConstraintItem *it = dynamic_cast<ConstraintItem*>(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 ||
Expand Down
4 changes: 2 additions & 2 deletions src/Mod/Sketcher/Gui/ViewProviderSketch.cpp
Expand Up @@ -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);
Expand Down

0 comments on commit f7c9566

Please sign in to comment.