]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
refs #30 - Sketch base GUI: create, draw lines
authornds <natalia.donis@opencascade.com>
Tue, 20 May 2014 05:50:26 +0000 (09:50 +0400)
committernds <natalia.donis@opencascade.com>
Tue, 20 May 2014 05:50:26 +0000 (09:50 +0400)
Start operation of line creation during the edit operation is active.

src/ModuleBase/ModuleBase_IOperation.cpp
src/ModuleBase/ModuleBase_IOperation.h
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_OperationEditLine.cpp
src/PartSet/PartSet_OperationEditLine.h
src/PartSet/PartSet_OperationSketch.cpp
src/PartSet/PartSet_OperationSketch.h
src/PartSet/PartSet_OperationSketchBase.h
src/PartSet/PartSet_OperationSketchLine.cpp
src/PartSet/PartSet_OperationSketchLine.h
src/XGUI/XGUI_OperationMgr.cpp

index 9a14779c65ab395f6e6d33ee6f6c36a86d03bacb..6853d0d70a27a9f3106c9423e98831c824e10ab7 100644 (file)
@@ -31,7 +31,7 @@ ModuleBase_OperationDescription* ModuleBase_IOperation::getDescription() const
   return myDescription;
 }
 
-bool ModuleBase_IOperation::isGranted() const
+bool ModuleBase_IOperation::isGranted(ModuleBase_IOperation* /*theOperation*/) const
 {
   return false;
 }
index 6b75e7eca17599ca16b3115e908d700572744d01..966d2668104c3d8f55f8602b20e01e36b3f67ce2 100644 (file)
@@ -61,7 +61,8 @@ public:
   /// must be always can start above any launched one. Default impl returns FALSE,
   /// so it is being checked for IsValid, but some operations may overload IsGranted()
   /// In this case they will always start, no matter what operation is running.
-  virtual bool isGranted() const;
+  /// \param theOperation the previous running operation
+  virtual bool isGranted(ModuleBase_IOperation* theOperation) const;
 
 signals:
   void started(); /// the operation is started
index 0074285dd53dace26418855a315ae13020ebae25..596ccf5be53557b5f9740bb280421a995bf430ca 100644 (file)
@@ -247,13 +247,14 @@ ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdI
   else if(theCmdId == PartSet_OperationSketchLine::Type() ||
           theCmdId == PartSet_OperationEditLine::Type()) {
     ModuleBase_Operation* aCurOperation = myWorkshop->operationMgr()->currentOperation();
-    boost::shared_ptr<ModelAPI_Feature> aSketchFeature;
-    if (aCurOperation)
-      aSketchFeature = aCurOperation->feature();
+    boost::shared_ptr<ModelAPI_Feature> aSketch;
+    PartSet_OperationSketchBase* aPrevOp = dynamic_cast<PartSet_OperationSketchBase*>(aCurOperation);
+    if (aPrevOp)
+      aSketch = aPrevOp->sketch();
     if (theCmdId == PartSet_OperationSketchLine::Type())
-      anOperation = new PartSet_OperationSketchLine(theCmdId.c_str(), this, aSketchFeature);
+      anOperation = new PartSet_OperationSketchLine(theCmdId.c_str(), this, aSketch);
     else
-      anOperation = new PartSet_OperationEditLine(theCmdId.c_str(), this, aSketchFeature);
+      anOperation = new PartSet_OperationEditLine(theCmdId.c_str(), this, aSketch);
   }
   else {
     anOperation = new ModuleBase_Operation(theCmdId.c_str(), this);
index f482cabefb0a75d11cdcb684bcedcfe3d4ac41c7..5383e0d493393863abec6cb728bed0cf49a156d6 100644 (file)
@@ -4,6 +4,9 @@
 
 #include <PartSet_OperationEditLine.h>
 #include <PartSet_Tools.h>
+#include <PartSet_OperationSketch.h>
+
+#include <ModuleBase_OperationDescription.h>
 
 #include <XGUI_ViewerPrs.h>
 
@@ -35,9 +38,9 @@ PartSet_OperationEditLine::~PartSet_OperationEditLine()
 {
 }
 
-bool PartSet_OperationEditLine::isGranted() const
+bool PartSet_OperationEditLine::isGranted(ModuleBase_IOperation* theOperation) const
 {
-  return true;
+  return theOperation->getDescription()->operationId().toStdString() == PartSet_OperationSketch::Type();
 }
 
 std::list<int> PartSet_OperationEditLine::getSelectionModes(boost::shared_ptr<ModelAPI_Feature> theFeature) const
@@ -52,6 +55,11 @@ void PartSet_OperationEditLine::init(boost::shared_ptr<ModelAPI_Feature> theFeat
   myFeatures = thePresentations;
 }
 
+boost::shared_ptr<ModelAPI_Feature> PartSet_OperationEditLine::sketch() const
+{
+  return mySketch;
+}
+
 void PartSet_OperationEditLine::mousePressed(QMouseEvent* theEvent, Handle(V3d_View) theView)
 {
   if (!(theEvent->buttons() &  Qt::LeftButton))
@@ -69,10 +77,10 @@ void PartSet_OperationEditLine::mouseMoved(QMouseEvent* theEvent, Handle(V3d_Vie
 
   if (myCurPoint.myIsInitialized) {
     double aCurX, aCurY;
-    PartSet_Tools::ConvertTo2D(myCurPoint.myPoint, mySketch, theView, aCurX, aCurY);
+    PartSet_Tools::ConvertTo2D(myCurPoint.myPoint, sketch(), theView, aCurX, aCurY);
 
     double aX, anY;
-    PartSet_Tools::ConvertTo2D(aPoint, mySketch, theView, aX, anY);
+    PartSet_Tools::ConvertTo2D(aPoint, sketch(), theView, aX, anY);
 
     double aDeltaX = aX - aCurX;
     double aDeltaY = anY - aCurY;
index 0c225f2f2b0fd2661e66aef6d94941c6d3a7833d..5f447c7305bcd7425703b13458c92b7c85453fdf 100644 (file)
@@ -60,9 +60,10 @@ public:
   /// Destructor
   virtual ~PartSet_OperationEditLine();
 
-   /// Returns that this operator can be started above already running one.
-   /// The runned operation should be the sketch feature modified operation
-  virtual bool isGranted() const;
+  /// Returns that this operator can be started above already running one.
+  /// The runned operation should be the sketch feature modified operation
+  /// \param theOperation the previous running operation
+  virtual bool isGranted(ModuleBase_IOperation* theOperation) const;
 
   /// Returns the operation local selection mode
   /// \param theFeature the feature object to get the selection mode
@@ -75,6 +76,10 @@ public:
   virtual void init(boost::shared_ptr<ModelAPI_Feature> theFeature,
                     const std::list<XGUI_ViewerPrs>& thePresentations);
 
+  /// Returns the operation sketch feature
+  /// \returns the sketch instance
+  virtual boost::shared_ptr<ModelAPI_Feature> sketch() const;
+
   /// Processes the mouse pressed in the point
   /// \param thePoint a point clicked in the viewer
   /// \param theEvent the mouse event
index 3bb916fab0926f66e023cdf65286d2bf88461962..4c4aa241db6b01c3237c72cf9789ec955f7ed7ca 100644 (file)
@@ -51,6 +51,11 @@ std::list<int> PartSet_OperationSketch::getSelectionModes(boost::shared_ptr<Mode
   return aModes;
 }
 
+boost::shared_ptr<ModelAPI_Feature> PartSet_OperationSketch::sketch() const
+{
+  return feature();
+}
+
 void PartSet_OperationSketch::mousePressed(QMouseEvent* theEvent, Handle_V3d_View theView,
                                            const std::list<XGUI_ViewerPrs>& theSelected)
 {
index 162627c5623a4e350585943c8873663f9f484849..e964939d4607c2b2c930fec8224a500fb949731c 100644 (file)
@@ -34,6 +34,10 @@ public:
   /// \return the selection mode
   virtual std::list<int> getSelectionModes(boost::shared_ptr<ModelAPI_Feature> theFeature) const;
 
+  /// Returns the operation sketch feature
+  /// \returns the sketch instance
+  virtual boost::shared_ptr<ModelAPI_Feature> sketch() const;
+
   /// Processes the mouse pressed in the point
   /// \param thePoint a point clicked in the viewer
   /// \param theEvent the mouse event
index 4fd20d5152a02ef583741d47382f5b06a121888e..b11406c2db1041b50c4d01ad5da7c04760d40618 100644 (file)
@@ -60,6 +60,10 @@ public:
   virtual void init(boost::shared_ptr<ModelAPI_Feature> theFeature,
                     const std::list<XGUI_ViewerPrs>& thePresentations) {}
 
+  /// Returns the operation sketch feature
+  /// \returns the sketch instance
+  virtual boost::shared_ptr<ModelAPI_Feature> sketch() const = 0;
+
   /// Processes the mouse pressed in the point
   /// \param thePoint a point clicked in the viewer
   /// \param theEvent the mouse event
index 0b05a8ef9a6393bbe7c800f1a6cf101298e5f6a3..c5ac31a6f277e4cb438cbaf290147ad0485ac639 100644 (file)
@@ -5,11 +5,15 @@
 #include <PartSet_OperationSketchLine.h>
 
 #include <PartSet_Tools.h>
+#include <PartSet_OperationSketch.h>
 
 #include <SketchPlugin_Feature.h>
 #include <SketchPlugin_Sketch.h>
 
 #include <GeomDataAPI_Point2D.h>
+
+#include <ModuleBase_OperationDescription.h>
+
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Document.h>
 #include <ModelAPI_AttributeRefAttr.h>
@@ -49,9 +53,9 @@ PartSet_OperationSketchLine::~PartSet_OperationSketchLine()
 {
 }
 
-bool PartSet_OperationSketchLine::isGranted() const
+bool PartSet_OperationSketchLine::isGranted(ModuleBase_IOperation* theOperation) const
 {
-  return true;
+  return theOperation->getDescription()->operationId().toStdString() == PartSet_OperationSketch::Type();
 }
 
 std::list<int> PartSet_OperationSketchLine::getSelectionModes(boost::shared_ptr<ModelAPI_Feature> theFeature) const
@@ -72,6 +76,11 @@ void PartSet_OperationSketchLine::init(boost::shared_ptr<ModelAPI_Feature> theFe
   myInitPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_END));
 }
 
+boost::shared_ptr<ModelAPI_Feature> PartSet_OperationSketchLine::sketch() const
+{
+  return mySketch;
+}
+
 void PartSet_OperationSketchLine::mouseReleased(QMouseEvent* theEvent, Handle(V3d_View) theView,
                                                 const std::list<XGUI_ViewerPrs>& theSelected)
 {
@@ -80,7 +89,7 @@ void PartSet_OperationSketchLine::mouseReleased(QMouseEvent* theEvent, Handle(V3
   bool isFoundPoint = false;
   gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(theEvent->pos(), theView);
   if (theSelected.empty()) {
-    PartSet_Tools::ConvertTo2D(aPoint, mySketch, theView, aX, anY);
+    PartSet_Tools::ConvertTo2D(aPoint, sketch(), theView, aX, anY);
     isFoundPoint = true;
   }
   else {
@@ -92,7 +101,7 @@ void PartSet_OperationSketchLine::mouseReleased(QMouseEvent* theEvent, Handle(V3
         const TopoDS_Vertex& aVertex = TopoDS::Vertex(aShape);
         if (!aVertex.IsNull()) {
           aPoint = BRep_Tool::Pnt(aVertex);
-          PartSet_Tools::ConvertTo2D(aPoint, mySketch, theView, aX, anY);
+          PartSet_Tools::ConvertTo2D(aPoint, sketch(), theView, aX, anY);
           isFoundPoint = true;
 
           setConstraints(aX, anY);
@@ -106,7 +115,7 @@ void PartSet_OperationSketchLine::mouseReleased(QMouseEvent* theEvent, Handle(V3
           double Y0, Y1, Y2, Y3;
           getLinePoint(aFeature, LINE_ATTR_START, X2, Y2);
           getLinePoint(aFeature, LINE_ATTR_END, X3, Y3);
-          PartSet_Tools::ConvertTo2D(aPoint, mySketch, theView, X1, Y1);
+          PartSet_Tools::ConvertTo2D(aPoint, sketch(), theView, X1, Y1);
 
           switch (myPointSelectionMode) {
             case SM_FirstPoint:
@@ -201,9 +210,9 @@ void PartSet_OperationSketchLine::stopOperation()
 boost::shared_ptr<ModelAPI_Feature> PartSet_OperationSketchLine::createFeature()
 {
   boost::shared_ptr<ModelAPI_Feature> aNewFeature = ModuleBase_Operation::createFeature();
-  if (mySketch) {
+  if (sketch()) {
     boost::shared_ptr<SketchPlugin_Feature> aFeature = 
-                           boost::dynamic_pointer_cast<SketchPlugin_Feature>(mySketch);
+                           boost::dynamic_pointer_cast<SketchPlugin_Feature>(sketch());
 
     aFeature->addSub(aNewFeature);
   }
@@ -226,9 +235,9 @@ void PartSet_OperationSketchLine::createConstraint(boost::shared_ptr<GeomDataAPI
   boost::shared_ptr<ModelAPI_Document> aDoc = document();
   boost::shared_ptr<ModelAPI_Feature> aFeature = aDoc->addFeature("SketchConstraintCoincidence");
 
-  if (mySketch) {
+  if (sketch()) {
     boost::shared_ptr<SketchPlugin_Feature> aSketch = 
-                           boost::dynamic_pointer_cast<SketchPlugin_Feature>(mySketch);
+                           boost::dynamic_pointer_cast<SketchPlugin_Feature>(sketch());
     aSketch->addSub(aFeature);
   }
 
@@ -262,7 +271,7 @@ void PartSet_OperationSketchLine::setConstraints(double theX, double theY)
   boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
   boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
                                                               (aData->attribute(aPointArg));
-  aData = mySketch->data();
+  aData = sketch()->data();
   boost::shared_ptr<ModelAPI_AttributeRefList> aRefList =
         boost::dynamic_pointer_cast<ModelAPI_AttributeRefList>(aData->attribute(SKETCH_ATTR_FEATURES));
 
@@ -325,7 +334,7 @@ void PartSet_OperationSketchLine::setLinePoint(const gp_Pnt& thePoint,
                                                const std::string& theAttribute)
 {
   double aX, anY;
-  PartSet_Tools::ConvertTo2D(thePoint, mySketch, theView, aX, anY);
+  PartSet_Tools::ConvertTo2D(thePoint, sketch(), theView, aX, anY);
   boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
   boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
         boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(theAttribute));
index cc5af926c2bbf2522397b2e38f2d667a9a9295a3..fa5f12938cc548f6eb9a32b3f37fa44d677312f4 100644 (file)
@@ -37,7 +37,8 @@ public:
 
    /// Returns that this operator can be started above already running one.
    /// The runned operation should be the sketch feature modified operation
-  virtual bool isGranted() const;
+  /// \param theOperation the previous running operation
+  virtual bool isGranted(ModuleBase_IOperation* theOperation) const;
 
   /// Returns the operation local selection mode
   /// \param theFeature the feature object to get the selection mode
@@ -50,6 +51,10 @@ public:
   virtual void init(boost::shared_ptr<ModelAPI_Feature> theFeature,
                     const std::list<XGUI_ViewerPrs>& thePresentations);
 
+  /// Returns the operation sketch feature
+  /// \returns the sketch instance
+  virtual boost::shared_ptr<ModelAPI_Feature> sketch() const;
+
   /// Gives the current selected objects to be processed by the operation
   /// \param thePoint a point clicked in the viewer
   /// \param theEvent the mouse event
index 792d5846777c786955ced5668b1878c2d9b34566..00aa7ecc5373c77116021faddf613bfabca4d4ae 100644 (file)
@@ -68,7 +68,7 @@ bool XGUI_OperationMgr::canStartOperation(ModuleBase_Operation* theOperation)
 {
   bool aCanStart = true;
   ModuleBase_Operation* aCurrentOp = currentOperation();
-  if (aCurrentOp && !theOperation->isGranted())
+  if (aCurrentOp && !theOperation->isGranted(aCurrentOp))
   {
     if (canStopOperation()) {
       aCurrentOp->abort();