Salome HOME
refs #30 - Sketch base GUI: create, draw lines
authornds <natalia.donis@opencascade.com>
Tue, 29 Apr 2014 15:17:29 +0000 (19:17 +0400)
committernds <natalia.donis@opencascade.com>
Tue, 29 Apr 2014 15:17:29 +0000 (19:17 +0400)
Resume operation for sketch after a line operation finish

src/ModuleBase/ModuleBase_Operation.cpp
src/ModuleBase/ModuleBase_Operation.h
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_OperationSketch.cpp
src/PartSet/PartSet_OperationSketchBase.cpp
src/PartSet/PartSet_OperationSketchBase.h
src/PartSet/PartSet_OperationSketchLine.cpp
src/SketchPlugin/plugin-Sketch.xml
src/XGUI/XGUI_OperationMgr.cpp
src/XGUI/XGUI_OperationMgr.h

index f31a292e0c4ef4c8d6a494a29dfcc22b0b081833..d5a0ce993ebb9c9e6bd49deeb7a00da8c59ba640 100644 (file)
@@ -196,6 +196,19 @@ void ModuleBase_Operation::start()
   emit started();
 }
 
+/*!
+ * \brief Resumes operation
+ *
+ * Public slot. Verifies whether operation can be started and starts operation.
+ * This slot is not virtual and cannot be redefined. Redefine startOperation method
+ * to change behavior of operation. There is no point in using this method. It would
+ * be better to inherit own operator from base one and redefine startOperation method
+ * instead.
+ */
+void ModuleBase_Operation::resume()
+{
+}
+
 /*!
  * \brief Aborts operation
  *
index 818476d6faf073a3eafc05bd01a95373f7600482..14978bee3d6be644328c0a155979b5d600eb354a 100644 (file)
@@ -101,6 +101,7 @@ signals:
 
 public slots:
   void start();
+  void resume();
   void abort();
   void commit();
 
index 54472ed0a6ecda456a16ad56b7defaaefc68f48a..0724e6de1fa8e9e92ea5b87cfd001b222135c4a7 100644 (file)
@@ -154,8 +154,8 @@ void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation)
   if (!anOperation)
     return;
   PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
-  if (aPreviewOp)
-    visualizePreview(false);
+  //if (aPreviewOp)
+  //  visualizePreview(false);
 }
 
 void PartSet_Module::onSelectionChanged()
@@ -218,6 +218,18 @@ void PartSet_Module::onPlaneSelected(double theX, double theY, double theZ)
   if (aViewer) {
     aViewer->setViewProjection(theX, theY, theZ);
   }
+
+  ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
+  if (anOperation) {
+    PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
+    if (aPreviewOp) {
+      aPreviewOp->setEditMode(true);
+      // the preview should be shown in another local context
+      visualizePreview(false);
+      visualizePreview(true);
+    }
+  }
+
   myWorkshop->actionsMgr()->setNestedActionsEnabled(true);
 }
 
index cc5fad46cb8f74a7493bd2580a35c23135ff36c1..9a3a5c716cfb7c69bb580ce999dc10a043ba8ca2 100644 (file)
@@ -32,7 +32,10 @@ PartSet_OperationSketch::~PartSet_OperationSketch()
 
 int PartSet_OperationSketch::getSelectionMode() const
 {
-  return TopAbs_FACE;
+  int aMode = TopAbs_FACE;
+  if (isEditMode())
+    aMode = TopAbs_VERTEX;
+  return aMode;
 }
 
 void PartSet_OperationSketch::setSelectedShapes(const NCollection_List<TopoDS_Shape>& theList)
@@ -40,6 +43,9 @@ void PartSet_OperationSketch::setSelectedShapes(const NCollection_List<TopoDS_Sh
   if (theList.IsEmpty())
     return;
 
+  if (isEditMode())
+    return;
+
   // get selected shape
   const TopoDS_Shape& aShape = theList.First();
   boost::shared_ptr<GeomAPI_Shape> aGShape(new GeomAPI_Shape);
index 864f77dda90f447729947fe20f8f97eb660ca097..a9f861fbbbac67b1f02167350d01b8358de1cc64 100644 (file)
@@ -16,6 +16,7 @@ PartSet_OperationSketchBase::PartSet_OperationSketchBase(const QString& theId,
                                                             QObject* theParent)
 : ModuleBase_PropPanelOperation(theId, theParent)
 {
+  setEditMode(false);
 }
 
 PartSet_OperationSketchBase::~PartSet_OperationSketchBase()
index bcc3f3aa1a5e9f110ef679735ed8348e5a919074..c578796a5a0d7c929bcc0d0015a8fa3079b7500f 100644 (file)
@@ -50,6 +50,13 @@ public:
   /// Processes the mouse move in the point
   /// \param thePoint a 3D point clicked in the viewer
   virtual void mouseMoved(const gp_Pnt& thePoint) {};
+
+  /// temporary code to provide edition mode
+  void setEditMode(const bool isEditMode) { myIsEditMode = isEditMode; };
+protected:
+  bool isEditMode() const { return myIsEditMode; }
+private:
+  bool myIsEditMode;
 };
 
 #endif
index 6da4b71f5d25eb55a06da55d251f2cb08247635b..45121e28572def4a10d6d9e359799b8ca74d58f5 100644 (file)
@@ -49,7 +49,7 @@ void PartSet_OperationSketchLine::mouseReleased(const gp_Pnt& thePoint)
     break;
     case SM_SecondPoint: {
       setLinePoint(thePoint, LINE_ATTR_END);
-      commit();
+      myPointSelectionMode = SM_None;
     }
     break;
     case SM_None: {
@@ -83,7 +83,6 @@ void PartSet_OperationSketchLine::startOperation()
 void PartSet_OperationSketchLine::stopOperation()
 {
   PartSet_OperationSketchBase::stopOperation();
-
   myPointSelectionMode = SM_None;
 }
 
index 489bf53e63972674f8dd8ee6996a7a8c623496fa..2feedd6d7372fbe64d3e6094a55d30616ae332d5 100644 (file)
@@ -1,7 +1,7 @@
 <plugin>
   <workbench id="Sketch">
     <group id="Basic">
-      <feature id="Sketch" text="New sketch" tooltip="Create a new sketch or edit an existing sketch" icon=":icons/sketch.png">
+      <feature id="Sketch" nested="SketchLine" text="New sketch" tooltip="Create a new sketch or edit an existing sketch" icon=":icons/sketch.png">
         <label text="Select a plane on which to create a sketch" tooltip="Select a plane on which to create a sketch"/> 
       <!--icon=":pictures/x_point.png"-->
       </feature>
index aeb0ed3c06533a771a44873994117795ae04193f..5661727c2cf8e14d3aa75c069b1d319b02701ac3 100644 (file)
@@ -36,6 +36,14 @@ bool XGUI_OperationMgr::startOperation(ModuleBase_Operation* theOperation)
   return true;
 }
 
+void XGUI_OperationMgr::resumeOperation(ModuleBase_Operation* theOperation)
+{
+  connect(theOperation, SIGNAL(stopped()), this, SLOT(onOperationStopped()));
+  connect(theOperation, SIGNAL(started()), this, SIGNAL(operationStarted()));
+
+  theOperation->resume();
+}
+
 bool XGUI_OperationMgr::canStartOperation(ModuleBase_Operation* theOperation)
 {
   bool aCanStart = true;
@@ -78,5 +86,5 @@ void XGUI_OperationMgr::onOperationStopped()
     }
   }
   if (aResultOp)
-    startOperation(aResultOp);
+    resumeOperation(aResultOp);
 }
index ef06d7da70ecb43514771aded8985b5825d71edb..2e74ab0b1d045c300b820b0a6259d6e4ba85d443 100644 (file)
@@ -34,8 +34,9 @@ public:
   /// Returns the current operation or NULL
   /// \return the current operation
   ModuleBase_Operation* currentOperation() const;
-  /// Sets the current operation or NULL
-  /// \return the current operation
+  /// Start the operation and append it to the stack of operations
+  /// \param theOperation the started operation
+  /// \return the state whether the current operation is started
   bool startOperation(ModuleBase_Operation* theOperation);
 
 signals:
@@ -46,6 +47,12 @@ signals:
   void operationStopped(ModuleBase_Operation* theOperation);
 
 protected:
+  /// Sets the current operation or NULL
+  /// \param theOperation the started operation
+  /// \param isCheckBeforeStart the flag whether to check whether the operation can be started
+  /// \return the state whether the operation is resumed
+  void resumeOperation(ModuleBase_Operation* theOperation);
+
   /// Returns whether the operation can be started. Check if there is already started operation and
   /// the granted parameter of the launched operation
   /// \param theOperation an operation to check