]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
refs #30 - Sketch base GUI: create, draw lines
authornds <natalia.donis@opencascade.com>
Wed, 30 Apr 2014 08:15:19 +0000 (12:15 +0400)
committernds <natalia.donis@opencascade.com>
Wed, 30 Apr 2014 08:15:19 +0000 (12:15 +0400)
Continuous line creation.

src/PartSet/PartSet_Listener.cpp
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
src/PartSet/PartSet_OperationSketchLine.h

index 580186b567b1d3cde612fe1802bb91aa9da2b11a..a9c1eb2cb68dbe3e401a5fe2a5e04c845200de14 100644 (file)
@@ -32,6 +32,8 @@ void PartSet_Listener::processEvent(const Events_Message* theMessage)
 {
   if (QString(theMessage->eventID().eventText()) == EVENT_FEATURE_UPDATED)
   {
-    myModule->visualizePreview(true);
+    const Model_FeatureUpdatedMessage* aUpdMsg = dynamic_cast<const Model_FeatureUpdatedMessage*>(theMessage);
+    boost::shared_ptr<ModelAPI_Feature> aFeature = aUpdMsg->feature();
+    myModule->visualizePreview(aFeature, true);
   }
 }
index 167d9f0ea1fc5f3902acc7958beb601377f7ce70..8bcafffef7f617994bc123ada88dd7912ce5192d 100644 (file)
@@ -138,7 +138,10 @@ void PartSet_Module::onOperationStarted()
 
   PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
   if (aPreviewOp) {
-    visualizePreview(true);
+    visualizePreview(aPreviewOp->feature(), true);
+
+    connect(aPreviewOp, SIGNAL(featureConstructed(boost::shared_ptr<ModelAPI_Feature>)),
+            this, SLOT(onFeatureConstructed(boost::shared_ptr<ModelAPI_Feature>)));
 
     PartSet_OperationSketch* aSketchOp = dynamic_cast<PartSet_OperationSketch*>(aPreviewOp);
     if (aSketchOp) {
@@ -224,14 +227,19 @@ void PartSet_Module::onPlaneSelected(double theX, double theY, double theZ)
     PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
     if (aPreviewOp) {
       aPreviewOp->setEditMode(true);
-      visualizePreview(false);
+      visualizePreview(aPreviewOp->feature(), false);
     }
   }
 
   myWorkshop->actionsMgr()->setNestedActionsEnabled(true);
 }
 
-void PartSet_Module::visualizePreview(bool isDisplay)
+void PartSet_Module::onFeatureConstructed(boost::shared_ptr<ModelAPI_Feature> theFeature)
+{
+  visualizePreview(theFeature, true);
+}
+
+void PartSet_Module::visualizePreview(boost::shared_ptr<ModelAPI_Feature> theFeature, bool isDisplay)
 {
   ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
   if (!anOperation)
@@ -243,10 +251,10 @@ void PartSet_Module::visualizePreview(bool isDisplay)
 
   XGUI_Displayer* aDisplayer = myWorkshop->displayer();
   if (isDisplay) {
-    boost::shared_ptr<GeomAPI_Shape> aPreview = aPreviewOp->preview();
+    boost::shared_ptr<GeomAPI_Shape> aPreview = aPreviewOp->preview(theFeature);
     if (aPreview) {
-      aDisplayer->DisplayInLocalContext(anOperation->feature(), aPreview->impl<TopoDS_Shape>(),
-                                        aPreviewOp->getSelectionMode());
+      aDisplayer->DisplayInLocalContext(theFeature, aPreview->impl<TopoDS_Shape>(),
+                                        aPreviewOp->getSelectionMode(theFeature));
     }
   }
   else {
index ba120ea0940d858fc4f0210e96c93b685fd21a48..ea7d30e4dac0997544fc34b33fece681e758cb6a 100644 (file)
 
 #include <string>
 
+#include <boost/shared_ptr.hpp>
+
 class XGUI_ViewWindow;
 class QMouseEvent;
 class PartSet_Listener;
+class ModelAPI_Feature;
 
 class PARTSET_EXPORT PartSet_Module: public QObject, public XGUI_Module
 {
@@ -31,8 +34,9 @@ public:
   virtual void launchOperation(const QString& theCmdId);
 
   /// Displays or erase the current operation preview, if it has it.
+  /// \param theF
   /// \param isDisplay the state whether the presentation should be displayed or erased
-  void visualizePreview(bool isDisplay);
+  void visualizePreview(boost::shared_ptr<ModelAPI_Feature> theFeature, bool isDisplay);
 
 public slots:
   void onFeatureTriggered();
@@ -63,6 +67,10 @@ public slots:
   /// \param theZ the Z projection value
   void onPlaneSelected(double theX, double theY, double theZ);
 
+  /// SLOT, to visualize the feature in another local context mode
+  /// \param theFeature the feature to be put in another local context mode
+  void onFeatureConstructed(boost::shared_ptr<ModelAPI_Feature> theFeature);
+
 private:
   XGUI_Workshop* myWorkshop;
   PartSet_Listener* myListener;
index 9a3a5c716cfb7c69bb580ce999dc10a043ba8ca2..b583c1e808eabb794953ee6385b88525504316fe 100644 (file)
@@ -30,7 +30,7 @@ PartSet_OperationSketch::~PartSet_OperationSketch()
 {
 }
 
-int PartSet_OperationSketch::getSelectionMode() const
+int PartSet_OperationSketch::getSelectionMode(boost::shared_ptr<ModelAPI_Feature> theFeature) const
 {
   int aMode = TopAbs_FACE;
   if (isEditMode())
index 5eb45b17e7318cb8d67e2934ff44063bc1a44299..7818a67cd185fda6787a82d374e60f017c469c1d 100644 (file)
@@ -26,8 +26,9 @@ public:
   virtual ~PartSet_OperationSketch();
 
   /// Returns the operation local selection mode
+  /// \param theFeature the feature object to get the selection mode
   /// \return the selection mode
-  virtual int getSelectionMode() const;
+  virtual int getSelectionMode(boost::shared_ptr<ModelAPI_Feature> theFeature) const;
 
   /// Gives the current selected objects to be processed by the operation
   /// \param theList a list of interactive selected shapes
index a9f861fbbbac67b1f02167350d01b8358de1cc64..c372bc72f96a4a174434649131e6c24e09691f2e 100644 (file)
@@ -23,9 +23,10 @@ PartSet_OperationSketchBase::~PartSet_OperationSketchBase()
 {
 }
 
-boost::shared_ptr<GeomAPI_Shape> PartSet_OperationSketchBase::preview() const
+boost::shared_ptr<GeomAPI_Shape> PartSet_OperationSketchBase::preview(
+                                      boost::shared_ptr<ModelAPI_Feature> theFeature) const
 {
   boost::shared_ptr<SketchPlugin_Feature> aFeature = 
-    boost::dynamic_pointer_cast<SketchPlugin_Feature>(feature());
+                              boost::dynamic_pointer_cast<SketchPlugin_Feature>(theFeature);
   return aFeature->preview();
 }
index c578796a5a0d7c929bcc0d0015a8fa3079b7500f..e5aa868a398f1afb38bf98482998d0ba68d0ca2c 100644 (file)
@@ -33,11 +33,13 @@ public:
   virtual ~PartSet_OperationSketchBase();
 
   /// Returns the feature preview shape
-  boost::shared_ptr<GeomAPI_Shape> preview() const;
+  /// \param theFeature the feature object to obtain the preview
+  boost::shared_ptr<GeomAPI_Shape> preview(boost::shared_ptr<ModelAPI_Feature> theFeature) const;
 
   /// Returns the operation local selection mode
+  /// \param theFeature the feature object to get the selection mode
   /// \return the selection mode
-  virtual int getSelectionMode() const = 0;
+  virtual int getSelectionMode(boost::shared_ptr<ModelAPI_Feature> theFeature) const = 0;
 
   /// Gives the current selected objects to be processed by the operation
   /// \param theList a list of interactive selected shapes
@@ -51,6 +53,12 @@ public:
   /// \param thePoint a 3D point clicked in the viewer
   virtual void mouseMoved(const gp_Pnt& thePoint) {};
 
+signals:
+  /// Signal about the feature construing is finished
+  /// \param theFeature the result feature
+  void featureConstructed(boost::shared_ptr<ModelAPI_Feature> theFeature);
+
+public:
   /// temporary code to provide edition mode
   void setEditMode(const bool isEditMode) { myIsEditMode = isEditMode; };
 protected:
index 366d650e8427a1220cafbe6208c8ebdc54de4916..b76a73084afa3fa30c2534209415203dc7f374eb 100644 (file)
@@ -9,6 +9,7 @@
 #include <GeomDataAPI_Point.h>
 #include <GeomDataAPI_Dir.h>
 #include <ModelAPI_Data.h>
+#include <ModelAPI_Document.h>
 
 #include <SketchPlugin_Sketch.h>
 #include <SketchPlugin_Line.h>
@@ -36,9 +37,12 @@ bool PartSet_OperationSketchLine::isGranted() const
   return true;
 }
 
-int PartSet_OperationSketchLine::getSelectionMode() const
+int PartSet_OperationSketchLine::getSelectionMode(boost::shared_ptr<ModelAPI_Feature> theFeature) const
 {
-  return 0;//TopAbs_FACE;
+  int aMode = 0;
+  if (theFeature != feature())
+    aMode = TopAbs_VERTEX;
+  return aMode;
 }
 
 void PartSet_OperationSketchLine::mouseReleased(const gp_Pnt& thePoint)
@@ -66,8 +70,30 @@ void PartSet_OperationSketchLine::mouseReleased(const gp_Pnt& thePoint)
 
 void PartSet_OperationSketchLine::mouseMoved(const gp_Pnt& thePoint)
 {
-  if (myPointSelectionMode == SM_SecondPoint)
-    setLinePoint(thePoint, LINE_ATTR_END);
+  switch (myPointSelectionMode)
+  {
+    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);
+    }
+    break;
+    default:
+      break;
+  }
 }
 
 void PartSet_OperationSketchLine::startOperation()
@@ -102,6 +128,21 @@ void PartSet_OperationSketchLine::setLinePoint(const gp_Pnt& thePoint,
   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);
+}
+
 void PartSet_OperationSketchLine::convertTo2D(const gp_Pnt& thePoint, double& theX, double& theY)
 {
   if (!mySketch)
index 456bcf01343daa3f0ac93bda7992d9faf1432837..3e07b82b8a510b0663c6c2f0d5591360e092c8d7 100644 (file)
@@ -32,8 +32,9 @@ public:
   virtual bool isGranted() const;
 
   /// Returns the operation local selection mode
+  /// \param theFeature the feature object to get the selection mode
   /// \return the selection mode
-  virtual int getSelectionMode() const;
+  virtual int getSelectionMode(boost::shared_ptr<ModelAPI_Feature> theFeature) const;
 
   /// Gives the current selected objects to be processed by the operation
   /// \param thePoint a point clicked in the viewer
@@ -42,6 +43,14 @@ public:
   /// \param thePoint a point clicked in the viewer
   virtual void mouseMoved(const gp_Pnt& thePoint);
 
+signals:
+  /// signal about the sketch plane is selected
+  /// \param theX the value in the X direction of the plane
+  /// \param theX the value in the Y direction value of the plane
+  /// \param theX the value in the Z direction of the plane
+  void localContextChanged(boost::shared_ptr<ModelAPI_Feature> theFeature,
+                           int theMode);
+
 protected:
   /// \brief Virtual method called when operation is started
   /// Virtual method called when operation started (see start() method for more description)
@@ -59,6 +68,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);
   /// \brief Converts the 3D point to the projected coodinates on the sketch plane.
   /// \param thePoint the 3D point in the viewer
   /// \param theX the X coordinate