]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
refs #80 - Sketch base GUI: create/draw point, circle and arc
authornds <natalia.donis@opencascade.com>
Sat, 21 Jun 2014 10:40:03 +0000 (14:40 +0400)
committernds <natalia.donis@opencascade.com>
Sat, 21 Jun 2014 10:40:03 +0000 (14:40 +0400)
1. Introduce the Last kind of selection in order to realize second feature selection for the distance constraint

13 files changed:
src/PartSet/PartSet_Constants.h
src/PartSet/PartSet_ConstraintDistancePrs.cpp
src/PartSet/PartSet_ConstraintDistancePrs.h
src/PartSet/PartSet_ConstraintLengthPrs.cpp
src/PartSet/PartSet_ConstraintLengthPrs.h
src/PartSet/PartSet_ConstraintRadiusPrs.cpp
src/PartSet/PartSet_ConstraintRadiusPrs.h
src/PartSet/PartSet_FeatureLinePrs.cpp
src/PartSet/PartSet_FeatureLinePrs.h
src/PartSet/PartSet_FeaturePrs.cpp
src/PartSet/PartSet_FeaturePrs.h
src/PartSet/PartSet_OperationCreateConstraint.cpp
src/PartSet/PartSet_OperationEditConstraint.cpp

index fd1fb97256844dae23f1702318564f88f434e3dc..9f466ed55c88c6e9ca13700bd27fc49a187e7f1f 100644 (file)
@@ -15,6 +15,7 @@ enum PartSet_SelectionMode
   SM_FirstPoint,
   SM_SecondPoint,
   SM_ThirdPoint,
+  SM_LastPoint,
   SM_DonePoint
 };
 
index d63e98c26f90ad2df3ba9fd6638b45792e243f4f..8ad377696cb400522742782eb0d34d1e4b508b8b 100644 (file)
@@ -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<ModelAPI_Data> aData = feature()->data();
       boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = 
               boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_A));
index a6fe31eac95d58eacc3f531ab87257bbca5132c1..89cfb9051d7f3b791dadd0719bdfcddbfb68259d 100644 (file)
@@ -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
index 67df7c4c729ac62de750244ed0c061e9d5e288fe..2f9c1d15ca4dc3130b3bd3f92bc07f15e4fa7247 100644 (file)
@@ -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<ModelAPI_Data> aData = feature()->data();
       boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = 
               boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_A));
index 5c8f85d562e36396786b46a048e74d8d3781abaf..69fef784858b40247e71cc6687d985945463b88a 100644 (file)
@@ -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
index 70e6ba7b2e9a9f4430b3c9de61a0b18ce14d7367..394ae38dc9ba80e0d622bedd081510efca66c3e3 100644 (file)
@@ -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<ModelAPI_Data> aData = feature()->data();
 
       boost::shared_ptr<GeomAPI_Pnt2d> aPoint = boost::shared_ptr<GeomAPI_Pnt2d>
@@ -97,7 +97,7 @@ PartSet_SelectionMode PartSet_ConstraintRadiusPrs::setPoint(double theX, double
       //    boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE));
       //aFlyoutAttr->setValue(aDistance);
 
-      aMode = SM_DonePoint;
+      aMode = SM_LastPoint;
     }
     break;
     default:
index 754f2dadf0fe49a3b7fcc9c142b6da1e40a2247a..9767c766f26f9492ac83a072903edf024ce0ed97 100644 (file)
@@ -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
index ef6e7c0059c4a3bfdbc974aafc197a62016b18a7..17c51670171d1fe0b45755f5cda62442fa2bea6e 100644 (file)
@@ -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<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
                                                                  (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
index 3ba4367974a95957c06546148b5e570a1fa7b6c3..128c127459ad765bef44836b14ccf9f24ae7445e 100644 (file)
@@ -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
index 9f2184d862da2f7998434b32eff26a6a9e3c6e06..7e9d12f020aab2d827d7a4f75cc4a2cb4a966773 100644 (file)
@@ -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)
 {
index 0acc2125d2b3c3929071f1445ff48c084b6c6d42..609b16973ce31db4f8c3355424635def31ad157c 100644 (file)
@@ -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
index a5f54997e252171af91fd78de1d0d90930497737..aff514a7836ef167ea164f8f49ad9b8b90dd0499 100644 (file)
@@ -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)
index d617b365aa4f6efbb4be8ca54a7fdc818c9a7356..ee536279b5e2b3035f9704fe79c6df0cbded2a30 100644 (file)
@@ -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<XGUI_ViewerPrs>::const_iterator anIt = myFeatures.begin(), aLast = myFeatures.end();