]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Constraint for distance start creation.
authornds <natalia.donis@opencascade.com>
Mon, 2 Jun 2014 09:55:05 +0000 (13:55 +0400)
committernds <natalia.donis@opencascade.com>
Mon, 2 Jun 2014 09:55:05 +0000 (13:55 +0400)
src/PartSet/CMakeLists.txt
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_OperationConstraint.cpp [new file with mode: 0644]
src/PartSet/PartSet_OperationConstraint.h [new file with mode: 0644]
src/PartSet/PartSet_OperationEditLine.h
src/PartSet/PartSet_OperationSketchBase.h
src/SketchPlugin/plugin-Sketch.xml

index 9ccf4e46b3b6ab0eb2153da3030e748e95045b95..a9f0973b20bc767a1b4e7b232ae220f9dfa727f0 100644 (file)
@@ -7,6 +7,7 @@ SET(PROJECT_HEADERS
        PartSet.h
        PartSet_Listener.h
        PartSet_Module.h
+       PartSet_OperationConstraint.h
        PartSet_OperationEditLine.h
        PartSet_OperationSketchBase.h
        PartSet_OperationSketch.h
@@ -18,6 +19,7 @@ SET(PROJECT_HEADERS
 SET(PROJECT_SOURCES
        PartSet_Listener.cpp
        PartSet_Module.cpp
+       PartSet_OperationConstraint.cpp
        PartSet_OperationEditLine.cpp
        PartSet_OperationSketchBase.cpp
        PartSet_OperationSketch.cpp
index abf5d270d184351d7647f298cbb4c648cd5d75b5..739edf06aa50094abdefee6a0e3fca18987e89d0 100644 (file)
@@ -2,6 +2,7 @@
 #include <PartSet_OperationSketch.h>
 #include <PartSet_OperationSketchLine.h>
 #include <PartSet_OperationEditLine.h>
+#include <PartSet_OperationConstraint.h>
 #include <ModuleBase_Operation.h>
 #include <ModuleBase_OperationDescription.h>
 #include <PartSet_Listener.h>
@@ -318,8 +319,7 @@ ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdI
   if (theCmdId == PartSet_OperationSketch::Type()) {
     anOperation = new PartSet_OperationSketch(theCmdId.c_str(), this);
   }
-  else if(theCmdId == PartSet_OperationSketchLine::Type() ||
-          theCmdId == PartSet_OperationEditLine::Type()) {
+  else {
     ModuleBase_Operation* aCurOperation = myWorkshop->operationMgr()->currentOperation();
     boost::shared_ptr<ModelAPI_Feature> aSketch;
     PartSet_OperationSketchBase* aPrevOp = dynamic_cast<PartSet_OperationSketchBase*>(aCurOperation);
@@ -327,10 +327,13 @@ ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdI
       aSketch = aPrevOp->sketch();
     if (theCmdId == PartSet_OperationSketchLine::Type())
       anOperation = new PartSet_OperationSketchLine(theCmdId.c_str(), this, aSketch);
-    else
+    else if (theCmdId == PartSet_OperationEditLine::Type())
       anOperation = new PartSet_OperationEditLine(theCmdId.c_str(), this, aSketch);
+    else if (theCmdId == PartSet_OperationConstraint::Type())
+      anOperation = new PartSet_OperationConstraint(theCmdId.c_str(), this, aSketch);
   }
-  else {
+
+  if (!anOperation) {
     anOperation = new ModuleBase_Operation(theCmdId.c_str(), this);
   }
   anOperation->getDescription()->setXmlRepresentation(QString::fromStdString(aXmlCfg));
diff --git a/src/PartSet/PartSet_OperationConstraint.cpp b/src/PartSet/PartSet_OperationConstraint.cpp
new file mode 100644 (file)
index 0000000..9f5e5b5
--- /dev/null
@@ -0,0 +1,245 @@
+// File:        PartSet_OperationConstraint.h
+// Created:     20 Apr 2014
+// Author:      Natalia ERMOLAEVA
+
+#include <PartSet_OperationConstraint.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>
+#include <ModelAPI_AttributeRefList.h>
+
+#include <SketchPlugin_Constraint.h>
+
+#include <Geom_Line.hxx>
+#include <gp_Lin.hxx>
+
+#include <XGUI_ViewerPrs.h>
+#include <XGUI_Constants.h>
+
+#include <SketchPlugin_Line.h>
+
+#include <V3d_View.hxx>
+#include <TopoDS_Vertex.hxx>
+#include <TopoDS.hxx>
+#include <BRep_Tool.hxx>
+
+#ifdef _DEBUG
+#include <QDebug>
+#endif
+
+#include <QMouseEvent>
+
+using namespace std;
+
+PartSet_OperationConstraint::PartSet_OperationConstraint(const QString& theId,
+                                                 QObject* theParent,
+                                              boost::shared_ptr<ModelAPI_Feature> theFeature)
+: PartSet_OperationSketchBase(theId, theParent), mySketch(theFeature)
+{
+}
+
+PartSet_OperationConstraint::~PartSet_OperationConstraint()
+{
+}
+
+bool PartSet_OperationConstraint::isGranted(ModuleBase_IOperation* theOperation) const
+{
+  return theOperation->getDescription()->operationId().toStdString() == PartSet_OperationSketch::Type();
+}
+
+void PartSet_OperationConstraint::init(boost::shared_ptr<ModelAPI_Feature> theFeature,
+                                       const std::list<XGUI_ViewerPrs>& /*theSelected*/,
+                                       const std::list<XGUI_ViewerPrs>& /*theHighlighted*/)
+{
+  //if (!theFeature || theFeature->getKind() != "SketchLine")
+  //  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));
+}
+
+boost::shared_ptr<ModelAPI_Feature> PartSet_OperationConstraint::sketch() const
+{
+  return mySketch;
+}
+
+void PartSet_OperationConstraint::mouseReleased(QMouseEvent* theEvent, Handle(V3d_View) theView,
+                                                const std::list<XGUI_ViewerPrs>& theSelected,
+                                                const std::list<XGUI_ViewerPrs>& /*theHighlighted*/)
+{
+  /*if (myPointSelectionMode == SM_DonePoint)
+  {
+    // if the point creation is finished, the next mouse release should commit the modification
+    // the next release can happens by double click in the viewer
+    commit();
+    restartOperation(PartSet_OperationConstraint::Type(), feature());
+    return;
+  }
+
+  double aX, anY;
+
+  bool isFoundPoint = false;
+  gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(theEvent->pos(), theView);
+  if (theSelected.empty()) {
+    PartSet_Tools::ConvertTo2D(aPoint, sketch(), theView, aX, anY);
+    isFoundPoint = true;
+  }
+  else {
+    XGUI_ViewerPrs aPrs = theSelected.front();
+    const TopoDS_Shape& aShape = aPrs.shape();
+    if (!aShape.IsNull()) // the point is selected
+    {
+      if (aShape.ShapeType() == TopAbs_VERTEX) {
+        const TopoDS_Vertex& aVertex = TopoDS::Vertex(aShape);
+        if (!aVertex.IsNull()) {
+          aPoint = BRep_Tool::Pnt(aVertex);
+          PartSet_Tools::ConvertTo2D(aPoint, sketch(), theView, aX, anY);
+          isFoundPoint = true;
+
+          setConstraints(aX, anY);
+        }
+      }
+      else if (aShape.ShapeType() == TopAbs_EDGE) // the line is selected
+      {
+        boost::shared_ptr<ModelAPI_Feature> aFeature = aPrs.feature();
+        if (aFeature) {
+          double X0, X1, X2, X3;
+          double Y0, Y1, Y2, Y3;
+          getLinePoint(aFeature, LINE_ATTR_START, X2, Y2);
+          getLinePoint(aFeature, LINE_ATTR_END, X3, Y3);
+          PartSet_Tools::ConvertTo2D(aPoint, sketch(), theView, X1, Y1);
+
+          switch (myPointSelectionMode) {
+            case SM_FirstPoint:
+              PartSet_Tools::ProjectPointOnLine(X2, Y2, X3, Y3, X1, Y1, aX, anY);
+            break;
+            case SM_SecondPoint: {
+              getLinePoint(feature(), LINE_ATTR_START, X0, Y0);
+              PartSet_Tools::IntersectLines(X0, Y0, X1, Y1, X2, Y2, X3, Y3, aX, anY);
+            }
+            break;
+            default:
+            break;
+          }
+          isFoundPoint = true;
+        }
+      }
+    }
+  }
+
+  switch (myPointSelectionMode)
+  {
+    case SM_FirstPoint: {
+      setLinePoint(feature(), aX, anY, LINE_ATTR_START);
+      setLinePoint(feature(), aX, anY, LINE_ATTR_END);
+      flushUpdated();
+
+      //setPointSelectionMode(SM_SecondPoint);
+    }
+    break;
+    case SM_SecondPoint: {
+      setLinePoint(feature(), aX, anY, LINE_ATTR_END);
+      flushUpdated();
+
+      //setPointSelectionMode(SM_DonePoint);
+   }
+    break;
+    default:
+      break;
+  }
+*/
+}
+
+void PartSet_OperationConstraint::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
+{
+/*  switch (myPointSelectionMode)
+  {
+    case SM_FirstPoint: {
+      double aX, anY;
+      gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(theEvent->pos(), theView);
+      PartSet_Tools::ConvertTo2D(aPoint, sketch(), theView, aX, anY);
+      setLinePoint(feature(), aX, anY, LINE_ATTR_START);
+      setLinePoint(feature(), aX, anY, LINE_ATTR_END);
+      flushUpdated();
+      emit focusActivated(LINE_ATTR_START);
+    }
+    break;
+    case SM_SecondPoint:
+    {
+      gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(theEvent->pos(), theView);
+      setLinePoint(aPoint, theView, LINE_ATTR_END);
+      flushUpdated();
+      emit focusActivated(LINE_ATTR_END);
+    }
+    break;
+    case SM_DonePoint:
+    {
+      commit();
+      restartOperation(PartSet_OperationConstraint::Type(), feature());
+    }
+    default:
+      break;
+  }*/
+}
+
+void PartSet_OperationConstraint::startOperation()
+{
+  PartSet_OperationSketchBase::startOperation();
+  //setPointSelectionMode(!myInitPoint ? SM_FirstPoint : SM_SecondPoint);
+
+  emit multiSelectionEnabled(false);
+}
+
+void PartSet_OperationConstraint::abortOperation()
+{
+  emit featureConstructed(feature(), FM_Hide);
+  PartSet_OperationSketchBase::abortOperation();
+}
+
+void PartSet_OperationConstraint::stopOperation()
+{
+  PartSet_OperationSketchBase::stopOperation();
+  emit multiSelectionEnabled(true);
+}
+
+void PartSet_OperationConstraint::afterCommitOperation()
+{
+  PartSet_OperationSketchBase::afterCommitOperation();  
+  emit featureConstructed(feature(), FM_Deactivation);
+}
+
+boost::shared_ptr<ModelAPI_Feature> PartSet_OperationConstraint::createFeature(const bool theFlushMessage)
+{
+  boost::shared_ptr<ModelAPI_Feature> aNewFeature = ModuleBase_Operation::createFeature(false);
+  if (sketch()) {
+    boost::shared_ptr<SketchPlugin_Feature> aFeature = 
+                           boost::dynamic_pointer_cast<SketchPlugin_Feature>(sketch());
+
+    aFeature->addSub(aNewFeature);
+  }
+  /*if (myInitPoint) {
+    setLinePoint(aNewFeature, myInitPoint->x(), myInitPoint->y(), LINE_ATTR_START);
+    setLinePoint(aNewFeature, myInitPoint->x(), myInitPoint->y(), LINE_ATTR_END);
+
+    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));
+    createConstraint(myInitPoint, aPoint);
+  }*/
+
+  emit featureConstructed(aNewFeature, FM_Activation);
+  if (theFlushMessage)
+    flushCreated();
+  return aNewFeature;
+}
diff --git a/src/PartSet/PartSet_OperationConstraint.h b/src/PartSet/PartSet_OperationConstraint.h
new file mode 100644 (file)
index 0000000..fe1ea19
--- /dev/null
@@ -0,0 +1,92 @@
+// File:        PartSet_OperationConstraint.h
+// Created:     20 Apr 2014
+// Author:      Natalia ERMOLAEVA
+
+#ifndef PartSet_OperationConstraint_H
+#define PartSet_OperationConstraint_H
+
+#include "PartSet.h"
+
+#include <PartSet_OperationSketchBase.h>
+#include <QObject>
+
+/*!
+ \class PartSet_OperationConstraint
+ * \brief The operation for the sketch constraint feature creation
+*/
+class PARTSET_EXPORT PartSet_OperationConstraint : public PartSet_OperationSketchBase
+{
+  Q_OBJECT
+
+public:
+  /// Returns the operation type key
+  static std::string Type() { return "SketchConstraintDistance"; }
+
+public:
+  /// Constructor
+  /// \param theId the feature identifier
+  /// \param theParent the operation parent
+  /// \param theFeature the parent feature
+  PartSet_OperationConstraint(const QString& theId, QObject* theParent,
+                              boost::shared_ptr<ModelAPI_Feature> theSketchFeature);
+  /// Destructor
+  virtual ~PartSet_OperationConstraint();
+
+  /// 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;
+
+  /// Initializes some fields accorging to the feature
+  /// \param theSelected the list of selected presentations
+  /// \param theHighlighted the list of highlighted presentations
+  virtual void init(boost::shared_ptr<ModelAPI_Feature> theFeature,
+                    const std::list<XGUI_ViewerPrs>& theSelected,
+                    const std::list<XGUI_ViewerPrs>& theHighlighted);
+
+  /// 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 theEvent the mouse event
+  /// \param theView a viewer to have the viewer the eye position
+  /// \param theSelected the list of selected presentations
+  /// \param theHighlighted the list of highlighted presentations
+ virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
+                            const std::list<XGUI_ViewerPrs>& theSelected,
+                            const std::list<XGUI_ViewerPrs>& theHighlighted);
+  /// Gives the current mouse point in the viewer
+  /// \param thePoint a point clicked in the viewer
+  /// \param theEvent the mouse event
+  virtual void mouseMoved(QMouseEvent* theEvent, Handle_V3d_View theView);
+
+protected:
+  /// \brief Virtual method called when operation is started
+  /// Virtual method called when operation started (see start() method for more description)
+  /// After the parent operation body perform, set sketch feature to the created line feature
+  virtual void startOperation();
+
+  /// 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();
+
+  /// Virtual method called when operation stopped - committed or aborted.
+  /// Restore the multi selection state
+  virtual void stopOperation();
+
+  /// Virtual method called after operation committed (see commit() method for more description)
+  virtual void afterCommitOperation();
+
+  /// Creates an operation new feature
+  /// In addition to the default realization it appends the created line feature to
+  /// the sketch feature
+  /// \param theFlushMessage the flag whether the create message should be flushed
+  /// \returns the created feature
+  virtual boost::shared_ptr<ModelAPI_Feature> createFeature(const bool theFlushMessage = true);
+
+private:
+  boost::shared_ptr<ModelAPI_Feature> mySketch; ///< the sketch feature
+};
+
+#endif
index d42d0e545fb38022f6f716bd69b77935b83425bc..fef4c95fcec527bfc4418e4aa060bba93b7a2da3 100644 (file)
@@ -141,7 +141,6 @@ private:
   boost::shared_ptr<ModelAPI_Feature> mySketch; ///< the sketch feature
   std::list<XGUI_ViewerPrs> myFeatures; ///< the features to apply the edit operation
   Point myCurPoint; ///< the current 3D point clicked or moved
-  gp_Pnt myCurPressed; ///< the current 3D point clicked or moved
   bool myIsBlockedSelection; ///< the state of the last state of selection blocked signal
 };
 
index 0c10c6c1a9fb3b4074138b9b43f62e72f5d168fa..697208c5a745d190ff12b4f35e588c00bcdd21b1 100644 (file)
@@ -52,7 +52,7 @@ public:
   /// Returns the operation local selection mode
   /// \param theFeature the feature object to get the selection mode
   /// \return the selection mode
-  virtual std::list<int> getSelectionModes(boost::shared_ptr<ModelAPI_Feature> theFeature) const = 0;
+  virtual std::list<int> getSelectionModes(boost::shared_ptr<ModelAPI_Feature> theFeature) const;
 
   /// Initializes some fields accorging to the feature
   /// \param theSelected the list of selected presentations
index d91e6066c9fd86126cf4a318f0d94d8f649a628e..be9b3f8799ba9425ce042767ffab89597fd725d3 100644 (file)
@@ -1,7 +1,7 @@
 <plugin>
   <workbench id="Sketch">
     <group id="Basic">
-      <feature id="Sketch" nested="SketchLine" title="Sketch" tooltip="Create a new sketch or edit an existing sketch" icon=":icons/sketch.png">
+      <feature id="Sketch" nested="SketchLine SketchConstraintDistance" title="Sketch" tooltip="Create a new sketch or edit an existing sketch" icon=":icons/sketch.png">
         <label title="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>
@@ -19,7 +19,7 @@
         <point_selector id="ArcEndPoint" title="End point" tooltip="End point of the arc"/>
       </feature>
       <feature id="SketchConstraintCoincidence" title="Points coincidence" tooltip="Create constraint for the coincidence of two points" internal="1"/>
-      <feature id="SketchConstraintDistance" title="Distance between objects" tooltip="Create constraint for the distance from a point to an object" internal="1"/>
+      <feature id="SketchConstraintDistance" title="Distance between objects" tooltip="Create constraint for the distance from a point to an object"/>
       <feature id="SketchConstraintLength" title="Length of a line" tooltip="Create constraint for the given length of a line segment" internal="1"/>
       <feature id="SketchConstraintRadius" title="Radius of a circle or an arc" tooltip="Create constraint for the given radius of a circle or an arc" internal="1"/>
       <feature id="SketchConstraintParallel" title="Parallelism of a lines" tooltip="Create constraint defining two parallel lines" internal="1"/>