]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
refs #30 - Sketch base GUI: create, draw lines
authornds <natalia.donis@opencascade.com>
Tue, 6 May 2014 11:58:35 +0000 (15:58 +0400)
committernds <natalia.donis@opencascade.com>
Tue, 6 May 2014 11:58:35 +0000 (15:58 +0400)
Restart for the line creation operation instead of the operation internal manipulation.

src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_OperationSketch.cpp
src/PartSet/PartSet_OperationSketchLine.cpp
src/PartSet/PartSet_OperationSketchLine.h
src/XGUI/XGUI_ActionsMgr.cpp
src/XGUI/XGUI_ActionsMgr.h

index 36a58e67e9e82b4f4c895c8c902705934bbb2cf8..d77c02df5a5fd8f0dd339123b9de6bf492ac3915 100644 (file)
@@ -212,6 +212,7 @@ void PartSet_Module::onLaunchOperation(std::string theName, boost::shared_ptr<Mo
   {
     aPreviewOp->init(theFeature);
   }
+  myWorkshop->actionsMgr()->setActionChecked(anOperation->getDescription()->operationId(), true);
   sendOperation(anOperation);
 }
 
index 0fb1833484e16268f3a6290f424cc6618c6892e7..46b0c4ca2a70d4da3dd3389c596dbea623b2762e 100644 (file)
@@ -37,6 +37,10 @@ std::list<int> PartSet_OperationSketch::getSelectionModes(boost::shared_ptr<Mode
   std::list<int> aModes;
   if (!myIsEditMode)
     aModes.push_back(TopAbs_FACE);
+  else {
+    aModes.push_back(TopAbs_VERTEX);
+    aModes.push_back(TopAbs_EDGE);
+  }
   return aModes;
 }
 
index 25bc7667366bf59dfe07ccc3fb285caee2ac82c3..cc4c02ede5a11459a634871571c04774dbadb17c 100644 (file)
@@ -38,12 +38,16 @@ bool PartSet_OperationSketchLine::isGranted() const
 
 std::list<int> PartSet_OperationSketchLine::getSelectionModes(boost::shared_ptr<ModelAPI_Feature> theFeature) const
 {
-  std::list<int> aModes;
-  if (theFeature != feature()) {
-    aModes.push_back(TopAbs_VERTEX);
-    aModes.push_back(TopAbs_EDGE);
-  }
-  return aModes;
+  return std::list<int>();
+}
+
+void PartSet_OperationSketchLine::init(boost::shared_ptr<ModelAPI_Feature> theFeature)
+{
+  if (!theFeature)
+    return;
+  // use the last point of the previous feature as the first of the new one
+  boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
+  myInitPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_END));
 }
 
 void PartSet_OperationSketchLine::mouseReleased(const gp_Pnt& thePoint, QMouseEvent* /*theEvent*/)
@@ -57,10 +61,9 @@ void PartSet_OperationSketchLine::mouseReleased(const gp_Pnt& thePoint, QMouseEv
     break;
     case SM_SecondPoint: {
       setLinePoint(thePoint, LINE_ATTR_END);
-      myPointSelectionMode = SM_None;
-    }
-    break;
-    case SM_None: {
+      commit();
+      emit featureConstructed(feature(), FM_Deactivation);
+      emit launchOperation(PartSet_OperationSketchLine::Type(), feature());
     }
     break;
     default:
@@ -75,22 +78,6 @@ void PartSet_OperationSketchLine::mouseMoved(const gp_Pnt& thePoint, QMouseEvent
     case SM_SecondPoint:
       setLinePoint(thePoint, LINE_ATTR_END);
       break;
-    case SM_None: {
-      boost::shared_ptr<ModelAPI_Feature> aPrevFeature = feature();
-      // stop the last operation
-      commitOperation();
-      document()->finishOperation();
-      //emit changeSelectionMode(aPrevFeature, TopAbs_VERTEX);
-      // start a new operation
-      document()->startOperation();
-      startOperation();
-      // use the last point of the previous feature as the first of the new one
-      setLinePoint(aPrevFeature, LINE_ATTR_END, LINE_ATTR_START);
-      myPointSelectionMode = SM_SecondPoint;
-
-      emit featureConstructed(aPrevFeature, FM_Deactivation);
-    }
-    break;
     default:
       break;
   }
@@ -100,19 +87,12 @@ void PartSet_OperationSketchLine::keyReleased(const int theKey)
 {
   switch (theKey) {
     case Qt::Key_Escape: {
-      if (myPointSelectionMode != SM_None)
-        emit featureConstructed(feature(), FM_Abort);
       abort();
     }
     break;
     case Qt::Key_Return: {
-      if (myPointSelectionMode != SM_None) {
-        emit featureConstructed(feature(), FM_Abort);
-        myPointSelectionMode = SM_FirstPoint;
-        document()->abortOperation();
-      }
-      else
-        myPointSelectionMode = SM_FirstPoint;
+      abort();
+      emit launchOperation(PartSet_OperationSketchLine::Type(), boost::shared_ptr<ModelAPI_Feature>());
     }
     break;
     default:
@@ -123,13 +103,13 @@ void PartSet_OperationSketchLine::keyReleased(const int theKey)
 void PartSet_OperationSketchLine::startOperation()
 {
   PartSet_OperationSketchBase::startOperation();
-  myPointSelectionMode = SM_FirstPoint;
+  myPointSelectionMode = !myInitPoint ? SM_FirstPoint : SM_SecondPoint;
 }
 
-void PartSet_OperationSketchLine::stopOperation()
+void PartSet_OperationSketchLine::abortOperation()
 {
-  PartSet_OperationSketchBase::stopOperation();
-  myPointSelectionMode = SM_None;
+  emit featureConstructed(feature(), FM_Abort);
+  PartSet_OperationSketchBase::abortOperation();
 }
 
 boost::shared_ptr<ModelAPI_Feature> PartSet_OperationSketchLine::createFeature()
@@ -141,6 +121,13 @@ boost::shared_ptr<ModelAPI_Feature> PartSet_OperationSketchLine::createFeature()
 
     aFeature->addSub(aNewFeature);
   }
+  if (myInitPoint) {
+    boost::shared_ptr<ModelAPI_Data> aData = aNewFeature->data();
+    boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
+                                                                (aData->attribute(LINE_ATTR_START));
+    aPoint->setValue(myInitPoint->x(), myInitPoint->y());
+  }
+
   emit featureConstructed(aNewFeature, FM_Activation);
   return aNewFeature;
 }
@@ -156,18 +143,3 @@ void PartSet_OperationSketchLine::setLinePoint(const gp_Pnt& thePoint,
   PartSet_Tools::ConvertTo2D(thePoint, mySketch, aX, anY);
   aPoint->setValue(aX, anY);
 }
-
-void PartSet_OperationSketchLine::setLinePoint(boost::shared_ptr<ModelAPI_Feature> theSourceFeature,
-                                               const std::string& theSourceAttribute,
-                                               const std::string& theAttribute)
-{
-  boost::shared_ptr<ModelAPI_Data> aData = theSourceFeature->data();
-  boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
-        boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(theSourceAttribute));
-  double aX = aPoint->x();
-  double anY = aPoint->y();
-
-  aData = feature()->data();
-  aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(theAttribute));
-  aPoint->setValue(aX, anY);
-}
index cab05194c55cdfd9ae468784929dbf361cd768bf..044e739ffd777c2c9b0e36df862780c35417ae06 100644 (file)
@@ -10,6 +10,7 @@
 #include <PartSet_OperationSketchBase.h>
 #include <QObject>
 
+class GeomDataAPI_Point2D;
 class QMouseEvent;
 
 /*!
@@ -43,6 +44,10 @@ public:
   /// \return the selection mode
   virtual std::list<int> getSelectionModes(boost::shared_ptr<ModelAPI_Feature> theFeature) const;
 
+  /// Initializes some fields accorging to the feature
+  /// \param theFeature the feature
+  virtual void init(boost::shared_ptr<ModelAPI_Feature> theFeature);
+
   /// Gives the current selected objects to be processed by the operation
   /// \param thePoint a point clicked in the viewer
   /// \param theEvent the mouse event
@@ -61,10 +66,9 @@ protected:
   /// After the parent operation body perform, set sketch feature to the created line feature
   virtual void startOperation();
 
-  /// \brief Virtual method called when operation is started
-  /// Virtual method called when operation stopped - committed or aborted.
-  /// After the parent operation body perform, reset selection point mode of the operation
-  virtual void stopOperation();
+  /// Virtual method called when operation aborted (see abort() method for more description)
+  /// Before the feature is aborted, it should be hidden from the viewer
+  virtual void abortOperation();
 
   /// Creates an operation new feature
   /// In addition to the default realization it appends the created line feature to
@@ -78,20 +82,13 @@ protected:
   /// \param theAttribute the start or end attribute of the line
   void setLinePoint(const gp_Pnt& thePoint, const std::string& theAttribute);
 
-  /// \brief Set the point to the line by the point of the source line.
-  /// \param theSourceFeature the feature, where the point is obtained
-  /// \param theSourceAttribute the start or end attribute of the source line
-  /// \param theAttribute the start or end attribute of the line
-  void setLinePoint(boost::shared_ptr<ModelAPI_Feature> theSourceFeature,
-                                               const std::string& theSourceAttribute,
-                                               const std::string& theAttribute);
-
 protected:
   ///< Structure to lists the possible types of point selection modes
-  enum PointSelectionMode {SM_FirstPoint, SM_SecondPoint, SM_None};
+  enum PointSelectionMode {SM_FirstPoint, SM_SecondPoint};
 
 private:
   boost::shared_ptr<ModelAPI_Feature> mySketch; ///< the sketch feature
+  boost::shared_ptr<GeomDataAPI_Point2D> myInitPoint; ///< the first line point
   PointSelectionMode myPointSelectionMode; ///< point selection mode
 };
 
index 46b15993acda2bb84d885ceb361dfed832cab112..a496899708f9375fd8fa60fde53a89de2044a6f3 100644 (file)
@@ -88,6 +88,13 @@ void XGUI_ActionsMgr::restoreCommandState()
   }
 }
 
+void XGUI_ActionsMgr::setActionChecked(const QString& theId, const bool theChecked)
+{
+  if(myActions.contains(theId)) {
+    myActions[theId]->setChecked(theChecked);
+  }
+}
+
 void XGUI_ActionsMgr::updateAction(const QString& theId)
 {
   if(myActions.contains(theId)){
index fe80fa21e04bf89ea00e378f7865cd484fb49c20..965f2289f05e884d451e2c32450a68ad7aea7f3d 100644 (file)
@@ -34,6 +34,11 @@ public:
   void saveCommandsState();
   void restoreCommandState();
 
+  /// Set the action is checked
+  /// \param theId - string ID of the command
+  /// \praram theChecked - the new checked state
+  void setActionChecked(const QString& theId, const bool theChecked);
+
   void updateAction(const QString&);
   void setNestedActionsEnabled(bool);