]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
refs #30 - Sketch base GUI: create, draw lines
authornds <natalia.donis@opencascade.com>
Wed, 21 May 2014 09:21:18 +0000 (13:21 +0400)
committernds <natalia.donis@opencascade.com>
Wed, 21 May 2014 09:21:18 +0000 (13:21 +0400)
Hide preview by clicking "Apply" or "Abort" button in the sketch operation.

src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_Module.h
src/PartSet/PartSet_OperationSketch.cpp
src/PartSet/PartSet_OperationSketch.h
src/PartSet/PartSet_OperationSketchBase.cpp
src/PartSet/PartSet_OperationSketchBase.h
src/PartSet/PartSet_OperationSketchLine.cpp

index f3d1113353700fd328aec98a106fc1cf37ca771d..b54dc192afca8965a7bb3250fbbdc6222cd8b3b6 100644 (file)
@@ -164,15 +164,6 @@ void PartSet_Module::onKeyRelease(QKeyEvent* theEvent)
 void PartSet_Module::onPlaneSelected(double theX, double theY, double theZ)
 {
   myWorkshop->viewer()->setViewProjection(theX, theY, theZ);
-
-  ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
-  if (anOperation) {
-    PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
-    if (aPreviewOp) {
-      visualizePreview(aPreviewOp->feature(), false);
-    }
-  }
-
   myWorkshop->actionsMgr()->setNestedActionsEnabled(true);
 }
 
@@ -216,11 +207,36 @@ void PartSet_Module::onSetSelection(const std::list<XGUI_ViewerPrs>& theFeatures
   aDisplayer->UpdateViewer();
 }
 
+void PartSet_Module::onCloseLocalContext()
+{
+  XGUI_Displayer* aDisplayer = myWorkshop->displayer();
+  aDisplayer->CloseLocalContexts();
+}
+
 void PartSet_Module::onFeatureConstructed(boost::shared_ptr<ModelAPI_Feature> theFeature,
                                           int theMode)
 {
-  bool isDisplay = theMode != PartSet_OperationSketchBase::FM_Abort;
+  bool isDisplay = theMode != PartSet_OperationSketchBase::FM_Hide;
   visualizePreview(theFeature, isDisplay, false);
+  if (!isDisplay) {
+    ModuleBase_Operation* aCurOperation = myWorkshop->operationMgr()->currentOperation();
+    boost::shared_ptr<ModelAPI_Feature> aSketch;
+    PartSet_OperationSketchBase* aPrevOp = dynamic_cast<PartSet_OperationSketchBase*>(aCurOperation);
+    if (aPrevOp) {
+      std::map<boost::shared_ptr<ModelAPI_Feature>, boost::shared_ptr<GeomAPI_Shape> >
+                                                                         aList = aPrevOp->subPreview();
+      XGUI_Displayer* aDisplayer = myWorkshop->displayer();
+      std::list<int> aModes = aPrevOp->getSelectionModes(aPrevOp->feature());
+
+      std::map<boost::shared_ptr<ModelAPI_Feature>, boost::shared_ptr<GeomAPI_Shape> >::const_iterator
+                                                             anIt = aList.begin(), aLast = aList.end();
+      for (; anIt != aLast; anIt++) {
+        boost::shared_ptr<ModelAPI_Feature> aFeature = (*anIt).first;
+        visualizePreview(aFeature, false, false);
+      }
+      aDisplayer->UpdateViewer();
+    }
+  }
 
   if (theMode == PartSet_OperationSketchBase::FM_Activation ||
       theMode == PartSet_OperationSketchBase::FM_Deactivation)
@@ -279,6 +295,9 @@ ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdI
     connect(aPreviewOp, SIGNAL(setSelection(const std::list<XGUI_ViewerPrs>&)),
             this, SLOT(onSetSelection(const std::list<XGUI_ViewerPrs>&)));
 
+     connect(aPreviewOp, SIGNAL(closeLocalContext()),
+             this, SLOT(onCloseLocalContext()));
+
     PartSet_OperationSketch* aSketchOp = dynamic_cast<PartSet_OperationSketch*>(aPreviewOp);
     if (aSketchOp) {
       connect(aSketchOp, SIGNAL(planeSelected(double, double, double)),
@@ -316,7 +335,7 @@ void PartSet_Module::visualizePreview(boost::shared_ptr<ModelAPI_Feature> theFea
                           aPreview ? aPreview->impl<TopoDS_Shape>() : TopoDS_Shape(), false);
   }
   else
-    aDisplayer->Erase(anOperation->feature(), false);
+    aDisplayer->Erase(theFeature, false);
 
   if (isUpdateViewer)
     aDisplayer->UpdateViewer();
@@ -349,7 +368,7 @@ void PartSet_Module::updateCurrentPreview(const std::string& theCmdId)
     return;
 
   std::map<boost::shared_ptr<ModelAPI_Feature>, boost::shared_ptr<GeomAPI_Shape> >
-                                                                     aList = aPreviewOp->preview();
+                                                                     aList = aPreviewOp->subPreview();
   XGUI_Displayer* aDisplayer = myWorkshop->displayer();
   std::list<int> aModes = aPreviewOp->getSelectionModes(aPreviewOp->feature());
 
index acd5502572b839c9a9db9448fe6109b1aa7071fd..17dc2034820d6cdef49ddde5c1ae81ce6a548c00 100644 (file)
@@ -101,6 +101,9 @@ public slots:
   /// \param theFeatures a list of features to be selected
   void onSetSelection(const std::list<XGUI_ViewerPrs>& theFeatures);
 
+  /// SLOT, to close the viewer local context
+  void onCloseLocalContext();
+
   /// SLOT, to visualize the feature in another local context mode
   /// \param theFeature the feature to be put in another local context mode
   /// \param theMode the mode appeared on the feature
index 4c4aa241db6b01c3237c72cf9789ec955f7ed7ca..d527cd0f3f1aee9d07598e9a2b2c36c40f1cbf6f 100644 (file)
@@ -100,7 +100,7 @@ void PartSet_OperationSketch::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View)
 }
 
 std::map<boost::shared_ptr<ModelAPI_Feature>, boost::shared_ptr<GeomAPI_Shape> >
-                                                        PartSet_OperationSketch::preview() const
+                                                        PartSet_OperationSketch::subPreview() const
 {
   std::map<boost::shared_ptr<ModelAPI_Feature>, boost::shared_ptr<GeomAPI_Shape> > aPreviewMap;
 
@@ -122,6 +122,13 @@ std::map<boost::shared_ptr<ModelAPI_Feature>, boost::shared_ptr<GeomAPI_Shape> >
   return aPreviewMap;
 }
 
+void PartSet_OperationSketch::stopOperation()
+{
+  PartSet_OperationSketchBase::stopOperation();
+  emit featureConstructed(feature(), FM_Hide);
+  emit closeLocalContext();
+}
+
 void PartSet_OperationSketch::setSketchPlane(const TopoDS_Shape& theShape)
 {
   if (theShape.IsNull())
@@ -160,5 +167,7 @@ void PartSet_OperationSketch::setSketchPlane(const TopoDS_Shape& theShape)
     boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_DIRY));
   aDirY->setValue(aC, anA, aB);
   boost::shared_ptr<GeomAPI_Dir> aDir = aPlane->direction();
+  emit featureConstructed(feature(), FM_Hide);
+  emit closeLocalContext();
   emit planeSelected(aDir->x(), aDir->y(), aDir->z());
 }
index e964939d4607c2b2c930fec8224a500fb949731c..fbb0eb376afba999656a2a675bb42d6e37a76f15 100644 (file)
@@ -58,7 +58,12 @@ public:
   /// Returns the map of the operation previews including the nested feature previews
   /// \return the map of feature to the feature preview
   virtual std::map<boost::shared_ptr<ModelAPI_Feature>, boost::shared_ptr<GeomAPI_Shape> >
-                                                                           preview() const;
+                                                                           subPreview() const;
+
+  /// Virtual method called when operation stopped - committed or aborted.
+  /// Emits a signal to hide the preview of the operation
+  virtual void stopOperation();
+
 signals:
   /// signal about the sketch plane is selected
   /// \param theX the value in the X direction of the plane
index 3a02de8b88ccba22a22ab639a4e29e927f35916f..18fdea1fd16c5ce20a82d1ea53232f032e0e5b32 100644 (file)
@@ -40,7 +40,7 @@ boost::shared_ptr<GeomAPI_Shape> PartSet_OperationSketchBase::preview(
 }
 
 std::map<boost::shared_ptr<ModelAPI_Feature>, boost::shared_ptr<GeomAPI_Shape> >
-                                                     PartSet_OperationSketchBase::preview() const
+                                                     PartSet_OperationSketchBase::subPreview() const
 {
   return std::map<boost::shared_ptr<ModelAPI_Feature>, boost::shared_ptr<GeomAPI_Shape> >();
 }
index 33b9e1d04ee38bc4236255ebf9128be49bb5696d..0045a8e87b1a6c19b2cf227188974d3ea7099387 100644 (file)
@@ -31,7 +31,7 @@ class PARTSET_EXPORT PartSet_OperationSketchBase : public ModuleBase_Operation
 {
   Q_OBJECT
 public:
-  enum FeatureActionMode { FM_Activation, FM_Deactivation, FM_Abort };
+  enum FeatureActionMode { FM_Activation, FM_Deactivation, FM_Hide };
 
 public:
   /// Constructor
@@ -47,7 +47,7 @@ public:
 
   /// Returns the map of the operation previews including the nested feature previews
   /// \return the map of feature to the feature preview
-  virtual std::map<boost::shared_ptr<ModelAPI_Feature>, boost::shared_ptr<GeomAPI_Shape> > preview() const;
+  virtual std::map<boost::shared_ptr<ModelAPI_Feature>, boost::shared_ptr<GeomAPI_Shape> > subPreview() const;
 
   /// Returns the operation local selection mode
   /// \param theFeature the feature object to get the selection mode
@@ -112,9 +112,8 @@ signals:
   /// \param theFeatures a list of features to be disabled
   void setSelection(const std::list<XGUI_ViewerPrs>& theFeatures);
 
-  /// signal to enable/disable usual selection in the viewer
-  /// \param theEnabled the boolean state
-  void selectionEnabled(bool theEnabled);
+  /// signal to close the operation local context if it is opened
+  void closeLocalContext();
 
 protected:
   /// Creates an operation new feature
index 36c969305b60f69ecbb67385904e4b44cd379514..6b64cd2759cff1930c142411f11a40d44ab5d1bc 100644 (file)
@@ -213,7 +213,7 @@ void PartSet_OperationSketchLine::startOperation()
 
 void PartSet_OperationSketchLine::abortOperation()
 {
-  emit featureConstructed(feature(), FM_Abort);
+  emit featureConstructed(feature(), FM_Hide);
   PartSet_OperationSketchBase::abortOperation();
 }