From: nds Date: Sat, 21 Jun 2014 10:40:03 +0000 (+0400) Subject: refs #80 - Sketch base GUI: create/draw point, circle and arc X-Git-Tag: V_0.4.4~269 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=4d3e52c50c0ce7356508372fc5d40531d4d5a862;p=modules%2Fshaper.git refs #80 - Sketch base GUI: create/draw point, circle and arc 1. Introduce the Last kind of selection in order to realize second feature selection for the distance constraint --- diff --git a/src/PartSet/PartSet_Constants.h b/src/PartSet/PartSet_Constants.h index fd1fb9725..9f466ed55 100644 --- a/src/PartSet/PartSet_Constants.h +++ b/src/PartSet/PartSet_Constants.h @@ -15,6 +15,7 @@ enum PartSet_SelectionMode SM_FirstPoint, SM_SecondPoint, SM_ThirdPoint, + SM_LastPoint, SM_DonePoint }; diff --git a/src/PartSet/PartSet_ConstraintDistancePrs.cpp b/src/PartSet/PartSet_ConstraintDistancePrs.cpp index d63e98c26..8ad377696 100644 --- a/src/PartSet/PartSet_ConstraintDistancePrs.cpp +++ b/src/PartSet/PartSet_ConstraintDistancePrs.cpp @@ -37,9 +37,9 @@ std::string PartSet_ConstraintDistancePrs::getKind() return SKETCH_CONSTRAINT_DISTANCE_KIND; } -bool PartSet_ConstraintDistancePrs::setFeature(FeaturePtr theFeature, const PartSet_SelectionMode& theMode) +PartSet_SelectionMode PartSet_ConstraintDistancePrs::setFeature(FeaturePtr theFeature, const PartSet_SelectionMode& theMode) { - bool aResult = false; + PartSet_SelectionMode aMode = theMode; if (feature() && theFeature && theFeature->getKind() == SKETCH_LINE_KIND && theMode == SM_FirstPoint) { // set length feature @@ -57,9 +57,9 @@ bool PartSet_ConstraintDistancePrs::setFeature(FeaturePtr theFeature, const Part double aLenght = aPoint1->pnt()->distance(aPoint2->pnt()); PartSet_Tools::setFeatureValue(feature(), aLenght, CONSTRAINT_ATTR_VALUE); - aResult = true; + aMode = SM_SecondPoint; } - return aResult; + return aMode; } PartSet_SelectionMode PartSet_ConstraintDistancePrs::setPoint(double theX, double theY, @@ -68,7 +68,7 @@ PartSet_SelectionMode PartSet_ConstraintDistancePrs::setPoint(double theX, doubl PartSet_SelectionMode aMode = theMode; switch (theMode) { - case SM_SecondPoint: { + case SM_LastPoint: { boost::shared_ptr aData = feature()->data(); boost::shared_ptr anAttr = boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_ENTITY_A)); diff --git a/src/PartSet/PartSet_ConstraintDistancePrs.h b/src/PartSet/PartSet_ConstraintDistancePrs.h index a6fe31eac..89cfb9051 100644 --- a/src/PartSet/PartSet_ConstraintDistancePrs.h +++ b/src/PartSet/PartSet_ConstraintDistancePrs.h @@ -36,7 +36,7 @@ public: /// \param theFeature a feature instance /// \param theMode the selection mode /// \return whether the feature is set - virtual bool setFeature(FeaturePtr theFeature, const PartSet_SelectionMode& theMode); + virtual PartSet_SelectionMode setFeature(FeaturePtr theFeature, const PartSet_SelectionMode& theMode); /// Sets the point to the feature in an attribute depending on the selection mode /// \param theX the 2D point horizontal coordinate diff --git a/src/PartSet/PartSet_ConstraintLengthPrs.cpp b/src/PartSet/PartSet_ConstraintLengthPrs.cpp index 67df7c4c7..2f9c1d15c 100644 --- a/src/PartSet/PartSet_ConstraintLengthPrs.cpp +++ b/src/PartSet/PartSet_ConstraintLengthPrs.cpp @@ -46,9 +46,9 @@ std::string PartSet_ConstraintLengthPrs::getKind() return SKETCH_CONSTRAINT_LENGTH_KIND; } -bool PartSet_ConstraintLengthPrs::setFeature(FeaturePtr theFeature, const PartSet_SelectionMode& theMode) +PartSet_SelectionMode PartSet_ConstraintLengthPrs::setFeature(FeaturePtr theFeature, const PartSet_SelectionMode& theMode) { - bool aResult = false; + PartSet_SelectionMode aMode = theMode; if (feature() && theFeature && theFeature->getKind() == SKETCH_LINE_KIND && theMode == SM_FirstPoint) { // set length feature @@ -66,9 +66,9 @@ bool PartSet_ConstraintLengthPrs::setFeature(FeaturePtr theFeature, const PartSe double aLenght = aPoint1->pnt()->distance(aPoint2->pnt()); PartSet_Tools::setFeatureValue(feature(), aLenght, CONSTRAINT_ATTR_VALUE); - aResult = true; + aMode = SM_LastPoint; } - return aResult; + return aMode; } PartSet_SelectionMode PartSet_ConstraintLengthPrs::setPoint(double theX, double theY, @@ -77,7 +77,7 @@ PartSet_SelectionMode PartSet_ConstraintLengthPrs::setPoint(double theX, double PartSet_SelectionMode aMode = theMode; switch (theMode) { - case SM_SecondPoint: { + case SM_LastPoint: { boost::shared_ptr aData = feature()->data(); boost::shared_ptr anAttr = boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_ENTITY_A)); diff --git a/src/PartSet/PartSet_ConstraintLengthPrs.h b/src/PartSet/PartSet_ConstraintLengthPrs.h index 5c8f85d56..69fef7848 100644 --- a/src/PartSet/PartSet_ConstraintLengthPrs.h +++ b/src/PartSet/PartSet_ConstraintLengthPrs.h @@ -36,7 +36,7 @@ public: /// \param theFeature a feature instance /// \param theMode the selection mode /// \return whether the feature is set - virtual bool setFeature(FeaturePtr theFeature, const PartSet_SelectionMode& theMode); + virtual PartSet_SelectionMode setFeature(FeaturePtr theFeature, const PartSet_SelectionMode& theMode); /// Sets the point to the feature in an attribute depending on the selection mode /// \param theX the 2D point horizontal coordinate diff --git a/src/PartSet/PartSet_ConstraintRadiusPrs.cpp b/src/PartSet/PartSet_ConstraintRadiusPrs.cpp index 70e6ba7b2..394ae38dc 100644 --- a/src/PartSet/PartSet_ConstraintRadiusPrs.cpp +++ b/src/PartSet/PartSet_ConstraintRadiusPrs.cpp @@ -49,11 +49,11 @@ std::string PartSet_ConstraintRadiusPrs::getKind() return SKETCH_CONSTRAINT_RADIUS_KIND; } -bool PartSet_ConstraintRadiusPrs::setFeature(FeaturePtr theFeature, const PartSet_SelectionMode& theMode) +PartSet_SelectionMode PartSet_ConstraintRadiusPrs::setFeature(FeaturePtr theFeature, const PartSet_SelectionMode& theMode) { - bool aResult = false; + PartSet_SelectionMode aMode = theMode; if (!feature() || theMode != SM_FirstPoint || !theFeature) { - return aResult; + return aMode; } std::string aKind = theFeature->getKind(); if (aKind == SKETCH_CIRCLE_KIND || aKind == SKETCH_ARC_KIND) { @@ -73,9 +73,9 @@ bool PartSet_ConstraintRadiusPrs::setFeature(FeaturePtr theFeature, const PartSe } PartSet_Tools::setFeatureValue(feature(), aLength, CONSTRAINT_ATTR_VALUE); - aResult = true; + aMode = SM_LastPoint; } - return aResult; + return aMode; } PartSet_SelectionMode PartSet_ConstraintRadiusPrs::setPoint(double theX, double theY, @@ -84,7 +84,7 @@ PartSet_SelectionMode PartSet_ConstraintRadiusPrs::setPoint(double theX, double PartSet_SelectionMode aMode = theMode; switch (theMode) { - case SM_SecondPoint: { + case SM_LastPoint: { boost::shared_ptr aData = feature()->data(); boost::shared_ptr aPoint = boost::shared_ptr @@ -97,7 +97,7 @@ PartSet_SelectionMode PartSet_ConstraintRadiusPrs::setPoint(double theX, double // boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE)); //aFlyoutAttr->setValue(aDistance); - aMode = SM_DonePoint; + aMode = SM_LastPoint; } break; default: diff --git a/src/PartSet/PartSet_ConstraintRadiusPrs.h b/src/PartSet/PartSet_ConstraintRadiusPrs.h index 754f2dadf..9767c766f 100644 --- a/src/PartSet/PartSet_ConstraintRadiusPrs.h +++ b/src/PartSet/PartSet_ConstraintRadiusPrs.h @@ -39,7 +39,7 @@ public: /// \param theFeature a feature instance /// \param theMode the selection mode /// \return whether the feature is set - virtual bool setFeature(FeaturePtr theFeature, const PartSet_SelectionMode& theMode); + virtual PartSet_SelectionMode setFeature(FeaturePtr theFeature, const PartSet_SelectionMode& theMode); /// Sets the point to the feature in an attribute depending on the selection mode /// \param theX the 2D point horizontal coordinate diff --git a/src/PartSet/PartSet_FeatureLinePrs.cpp b/src/PartSet/PartSet_FeatureLinePrs.cpp index ef6e7c005..17c516701 100644 --- a/src/PartSet/PartSet_FeatureLinePrs.cpp +++ b/src/PartSet/PartSet_FeatureLinePrs.cpp @@ -58,9 +58,9 @@ PartSet_SelectionMode PartSet_FeatureLinePrs::setPoint(double theX, double theY, return aMode; } -bool PartSet_FeatureLinePrs::setFeature(FeaturePtr theFeature, const PartSet_SelectionMode& theMode) +PartSet_SelectionMode PartSet_FeatureLinePrs::setFeature(FeaturePtr theFeature, const PartSet_SelectionMode& theMode) { - bool aResult = false; + PartSet_SelectionMode aMode = theMode; if (feature() && theFeature && theMode == SM_FirstPoint) { // use the last point of the previous feature as the first of the new one @@ -74,9 +74,9 @@ bool PartSet_FeatureLinePrs::setFeature(FeaturePtr theFeature, const PartSet_Sel boost::shared_ptr aPoint = boost::dynamic_pointer_cast (aData->attribute(LINE_ATTR_START)); PartSet_Tools::createConstraint(sketch(), anInitPoint, aPoint); - aResult = true; + aMode = SM_SecondPoint; } - return aResult; + return aMode; } std::string PartSet_FeatureLinePrs::getAttribute(const PartSet_SelectionMode& theMode) const diff --git a/src/PartSet/PartSet_FeatureLinePrs.h b/src/PartSet/PartSet_FeatureLinePrs.h index 3ba436797..128c12745 100644 --- a/src/PartSet/PartSet_FeatureLinePrs.h +++ b/src/PartSet/PartSet_FeatureLinePrs.h @@ -47,7 +47,7 @@ public: /// \param theFeature a feature instance /// \param theMode the selection mode /// \return whether the feature is set - virtual bool setFeature(FeaturePtr theFeature, const PartSet_SelectionMode& theMode); + virtual PartSet_SelectionMode setFeature(FeaturePtr theFeature, const PartSet_SelectionMode& theMode); /// Returns the feature attribute name for the selection mode /// \param theMode the current operation selection mode. The feature attribute depends on the mode diff --git a/src/PartSet/PartSet_FeaturePrs.cpp b/src/PartSet/PartSet_FeaturePrs.cpp index 9f2184d86..7e9d12f02 100644 --- a/src/PartSet/PartSet_FeaturePrs.cpp +++ b/src/PartSet/PartSet_FeaturePrs.cpp @@ -43,6 +43,12 @@ FeaturePtr PartSet_FeaturePrs::feature() const return myFeature; } +PartSet_SelectionMode PartSet_FeaturePrs::setFeature(FeaturePtr theFeature, + const PartSet_SelectionMode& theMode) +{ + return SM_FirstPoint; +} + void PartSet_FeaturePrs::setConstraints(double theX, double theY, const PartSet_SelectionMode& theMode) { diff --git a/src/PartSet/PartSet_FeaturePrs.h b/src/PartSet/PartSet_FeaturePrs.h index 0acc2125d..609b16973 100644 --- a/src/PartSet/PartSet_FeaturePrs.h +++ b/src/PartSet/PartSet_FeaturePrs.h @@ -47,7 +47,8 @@ public: /// \param theFeature a feature instance /// \param theMode the selection mode /// \return whether the feature is set - virtual bool setFeature(FeaturePtr theFeature, const PartSet_SelectionMode& theMode) { return false; }; + /// \return the new selection mode + virtual PartSet_SelectionMode setFeature(FeaturePtr theFeature, const PartSet_SelectionMode& theMode); /// Returns the feature attribute name for the selection mode /// \param theMode the current operation selection mode. The feature attribute depends on the mode diff --git a/src/PartSet/PartSet_OperationCreateConstraint.cpp b/src/PartSet/PartSet_OperationCreateConstraint.cpp index a5f54997e..aff514a78 100644 --- a/src/PartSet/PartSet_OperationCreateConstraint.cpp +++ b/src/PartSet/PartSet_OperationCreateConstraint.cpp @@ -104,19 +104,21 @@ void PartSet_OperationCreateConstraint::mouseReleased(QMouseEvent* theEvent, Han { switch (myPointSelectionMode) { - case SM_FirstPoint: { + case SM_FirstPoint: + case SM_SecondPoint: { if (!theSelected.empty()) { XGUI_ViewerPrs aPrs = theSelected.front(); FeaturePtr aFeature = aPrs.feature(); - if (myFeaturePrs->setFeature(aFeature, myPointSelectionMode)) { + PartSet_SelectionMode aMode = myFeaturePrs->setFeature(aFeature, myPointSelectionMode); + if (aMode != myPointSelectionMode) { flushUpdated(); - setPointSelectionMode(SM_SecondPoint); + setPointSelectionMode(aMode); } } } break; - case SM_SecondPoint: { + case SM_LastPoint: { double aX, anY; gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView); PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY); @@ -127,7 +129,6 @@ void PartSet_OperationCreateConstraint::mouseReleased(QMouseEvent* theEvent, Han double aValue = PartSet_Tools::featureValue(feature(), CONSTRAINT_ATTR_VALUE, isValid); if (isValid) { showEditor(theEvent, aValue); - setPointSelectionMode(SM_ThirdPoint/*aMode*/); } } break; @@ -142,8 +143,8 @@ void PartSet_OperationCreateConstraint::mouseMoved(QMouseEvent* theEvent, Handle switch (myPointSelectionMode) { //case SM_FirstPoint: - case SM_SecondPoint: - //case SM_ThirdPoint: + //case SM_SecondPoint: + case SM_LastPoint: { double aX, anY; gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView); @@ -194,9 +195,8 @@ void PartSet_OperationCreateConstraint::keyReleased(const int theKey) } // changed // the modification is really need until the focus of editor do not accept the focus - if (myPointSelectionMode == SM_ThirdPoint) { - if (myEditor->isStarted()) - myEditor->stop(); + if (myPointSelectionMode == SM_LastPoint && myEditor->isStarted()) { + myEditor->stop(); commit(); // it start a new line creation at a free point restartOperation(feature()->getKind(), FeaturePtr()/*feature()*/); @@ -223,7 +223,7 @@ void PartSet_OperationCreateConstraint::keyReleased(const int theKey) void PartSet_OperationCreateConstraint::startOperation() { PartSet_OperationSketchBase::startOperation(); - setPointSelectionMode(!myInitFeature ? SM_FirstPoint : SM_SecondPoint); + //setPointSelectionMode(!myInitFeature ? SM_FirstPoint : SM_SecondPoint); emit multiSelectionEnabled(false); } @@ -256,8 +256,10 @@ FeaturePtr PartSet_OperationCreateConstraint::createFeature(const bool theFlushM aFeature->addSub(aNewFeature); } myFeaturePrs->init(aNewFeature); - if (myInitFeature) - myFeaturePrs->setFeature(myInitFeature, SM_FirstPoint); + if (myInitFeature) { + PartSet_SelectionMode aMode = myFeaturePrs->setFeature(myInitFeature, SM_FirstPoint); + //setPointSelectionMode(aMode); + } emit featureConstructed(aNewFeature, FM_Activation); if (theFlushMessage) diff --git a/src/PartSet/PartSet_OperationEditConstraint.cpp b/src/PartSet/PartSet_OperationEditConstraint.cpp index d617b365a..ee536279b 100644 --- a/src/PartSet/PartSet_OperationEditConstraint.cpp +++ b/src/PartSet/PartSet_OperationEditConstraint.cpp @@ -156,7 +156,7 @@ void PartSet_OperationEditConstraint::mouseMoved(QMouseEvent* theEvent, Handle(V anArcPrs->projectPointOnFeature(feature(), sketch(), aPoint, theView, aX, anY); } } - myFeaturePrs->setPoint(aX, anY, SM_SecondPoint); + myFeaturePrs->setPoint(aX, anY, SM_LastPoint); /*std::list::const_iterator anIt = myFeatures.begin(), aLast = myFeatures.end();