Salome HOME
Issue #2167: error when create circle
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_Trim.h
index 70bffe0a827a6d02a5e0aed7f4ce1d81157954ea..b6b6599cf0388fe2b4dc2e981644f4da0d5b252f 100644 (file)
@@ -8,12 +8,15 @@
 #define SketchPlugin_Trim_H_
 
 #include "SketchPlugin.h"
+
+#include "GeomAPI_IPresentable.h"
+#include <ModelAPI_IReentrant.h>
 #include <SketchPlugin_Sketch.h>
-#include "SketchPlugin_ConstraintBase.h"
 
 class GeomDataAPI_Point2D;
 class ModelAPI_Feature;
 class ModelAPI_Result;
+class ModelAPI_Object;
 
 typedef std::pair<std::string, std::shared_ptr<GeomDataAPI_Point2D> > IdToPointPair;
 
@@ -21,7 +24,8 @@ typedef std::pair<std::string, std::shared_ptr<GeomDataAPI_Point2D> > IdToPointP
  *  \ingroup Plugins
  *  \brief Feature for creation of a new constraint trimming object. Entities for split:
  */
-class SketchPlugin_Trim : public SketchPlugin_Feature, public GeomAPI_IPresentable
+class SketchPlugin_Trim : public SketchPlugin_Feature, public GeomAPI_IPresentable,
+                          public ModelAPI_IReentrant
 {
  public:
   /// Split constraint kind
@@ -38,17 +42,31 @@ class SketchPlugin_Trim : public SketchPlugin_Feature, public GeomAPI_IPresentab
   }
 
   /// The value parameter for the constraint
-  inline static const std::string& BASE_OBJECT()
+  inline static const std::string& SELECTED_OBJECT()
+  {
+    static const std::string MY_SELECTED_OBJECT("SelectedObject");
+    return MY_SELECTED_OBJECT;
+  }
+
+  /// Start 2D point of the split segment
+  inline static const std::string& SELECTED_POINT()
+  {
+    static const std::string MY_SELECTED_POINT("SelectedPoint");
+    return MY_SELECTED_POINT;
+  }
+
+  /// The value parameter for the preview object
+  inline static const std::string& PREVIEW_OBJECT()
   {
-    static const std::string MY_CONSTRAINT_BASE_OBJECT("BaseObject");
-    return MY_CONSTRAINT_BASE_OBJECT;
+    static const std::string MY_PREVIEW_OBJECT("PreviewObject");
+    return MY_PREVIEW_OBJECT;
   }
 
   /// Start 2D point of the split segment
-  inline static const std::string& ENTITY_POINT()
+  inline static const std::string& PREVIEW_POINT()
   {
-    static const std::string MY_ENTITY_POINT("ConstraintEntityPoint");
-    return MY_ENTITY_POINT;
+    static const std::string MY_PREVIEW_POINT("PreviewPoint");
+    return MY_PREVIEW_POINT;
   }
 
   /// \brief Creates a new part document if needed
@@ -59,16 +77,12 @@ class SketchPlugin_Trim : public SketchPlugin_Feature, public GeomAPI_IPresentab
 
   /// Reimplemented from ModelAPI_Feature::isMacro()
   /// \returns true
-  SKETCHPLUGIN_EXPORT virtual bool isMacro() const;
+  SKETCHPLUGIN_EXPORT virtual bool isMacro() const { return true; }
 
   /// Reimplemented from ModelAPI_Feature::isPreviewNeeded(). Returns false.
   /// This is necessary to perform execute only by apply the feature
   SKETCHPLUGIN_EXPORT virtual bool isPreviewNeeded() const { return false; }
 
-  /// Called on change of any argument-attribute of this object
-  /// \param theID identifier of changed attribute
-  SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
-
   /// \brief Use plugin manager for features creation
   SketchPlugin_Trim();
 
@@ -78,7 +92,29 @@ class SketchPlugin_Trim : public SketchPlugin_Feature, public GeomAPI_IPresentab
   /// Moves the feature : Empty
   SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY) {};
 
+  /// Apply information of the message to current object. It fills selected point and object
+  virtual std::string processEvent(const std::shared_ptr<Events_Message>& theMessage);
+
+  typedef std::map<std::shared_ptr<GeomAPI_Pnt>,
+                   std::pair<std::list<std::shared_ptr<GeomDataAPI_Point2D> >,
+                             std::list<std::shared_ptr<ModelAPI_Object> > > > PointToRefsMap;
+
+  static void fillObjectShapes(const std::shared_ptr<ModelAPI_Object>& theObject,
+    const std::shared_ptr<ModelAPI_Object>& theSketch,
+    std::map<std::shared_ptr<ModelAPI_Object>, std::set<GeomShapePtr> >& theCashedShapes,
+    std::map<std::shared_ptr<ModelAPI_Object>, PointToRefsMap>& theObjectToPoints);
+
 private:
+  bool setCoincidenceToAttribute(const AttributePtr& theAttribute,
+            const std::set<std::shared_ptr<GeomDataAPI_Point2D> >& theFurtherCoincidences);
+  /// Move tangency constraint to the feature if it is geometrically closely to it
+  /// \param theAttribute an attribute of a tangent constraint feature
+  /// \param theFeature a feature that can be set into the attribute
+  bool moveTangency(const AttributePtr& theAttribute, const FeaturePtr& theFeature);
+
+  GeomShapePtr getSubShape(const std::string& theObjectAttributeId,
+                           const std::string& thePointAttributeId);
+
   /// Returns geom point attribute of the feature bounds. It processes line or arc.
   /// For circle feature, the result attributes are null
   /// \param theFeature a source feature
@@ -93,7 +129,7 @@ private:
   /// \param theFeaturesToDelete [out] constrains that will be deleted after split
   /// \param theFeaturesToUpdate [out] constrains that will be updated after split
   void getConstraints(std::set<std::shared_ptr<ModelAPI_Feature>>& theFeaturesToDelete,
-              std::set<std::shared_ptr<ModelAPI_Feature>>& theFeaturesToUpdate);
+                      std::set<FeaturePtr>& theFeaturesToUpdate);
 
   /// Obtains references to feature point attributes and to feature,
   /// e.g. for feature line: 1st container is
@@ -106,12 +142,6 @@ private:
                         std::map<AttributePtr, std::list<AttributePtr> >& theRefs,
                         std::list<AttributePtr>& theRefsToFeature);
 
-  /// Move constraints from base feature to given feature
-  /// \param theFeature a base feature
-  /// \param theRefsToFeature list of attributes referenced to base feature
-  void updateRefFeatureConstraints(const std::shared_ptr<ModelAPI_Result>& theFeatureBaseResult,
-                                   const std::list<AttributePtr>& theRefsToFeature);
-
   /// Move constraints from attribute of base feature to attribute after modification
   /// \param theBaseRefAttributes container of references to the attributes of base feature
   /// \param theModifiedAttributes container of attributes placed instead of base attributes
@@ -121,42 +151,42 @@ private:
                const std::set<std::pair<AttributePtr, AttributePtr> >& theModifiedAttributes,
                std::set<std::shared_ptr<ModelAPI_Feature>>& theFeaturesToDelete);
 
-//  /// Make the base object is splitted by the point attributes
-//  /// \param theSplitFeature a result split feature
-//  /// \param theBeforeFeature a feature between start point and the 1st point of split feature
-//  /// \param theAfterFeature a feature between last point of split feature and the end point
-//  /// \param thePoints a list of points where coincidences will be build
-//  /// \param theCreatedFeatures a container of created features
-//  /// \param theModifiedAttributes a container of attribute on base
-//  /// feature to attribute on new feature
-  void trimLine(const std::shared_ptr<GeomAPI_Pnt2d>& theStartShapePoint,
+  /// Remove references constraints from attribute of base feature refer to the given attribute
+  /// \param theAttribute an attribute
+  /// \param theModifiedAttributes modifiable container of attributes
+  void removeReferencesToAttribute(const AttributePtr& theAttribute,
+                  std::map<AttributePtr, std::list<AttributePtr> >& theBaseRefAttributes);
+
+   /// Updates line length if it exist in the list
+  /// \param theFeaturesToUpdate a constraints container
+  void updateFeaturesAfterTrim(const std::set<FeaturePtr>& theFeaturesToUpdate);
+
+  /// Make the base object is splitted by the point attributes
+  /// \param theBaseRefAttributes container of references to the attributes of base feature
+  /// \param thePoints a list of points where coincidences will be build
+  /// \param theModifiedAttributes a container of attribute on base
+  /// feature to attribute on new feature
+  /// \return new line if it was created
+  FeaturePtr trimLine(const std::shared_ptr<GeomAPI_Pnt2d>& theStartShapePoint,
                 const std::shared_ptr<GeomAPI_Pnt2d>& theLastShapePoint,
+                std::map<AttributePtr, std::list<AttributePtr> >& theBaseRefAttributes,
                 std::set<std::shared_ptr<GeomDataAPI_Point2D> >& thePoints,
-                std::set<std::shared_ptr<ModelAPI_Feature>>& theCreatedFeatures,
                 std::set<std::pair<AttributePtr, AttributePtr>>& theModifiedAttributes);
 
   /// Make the base object is splitted by the point attributes
-  /// \param theSplitFeature a result split feature
-  /// \param theBeforeFeature a feature between start point and the 1st point of split feature
-  /// \param theAfterFeature a feature between last point of split feature and the end point
   /// \param thePoints a list of points where coincidences will be build
-  /// \param theCreatedFeatures a container of created features
-  void trimArc(const std::shared_ptr<GeomAPI_Pnt2d>& theStartShapePoint,
+  /// \return new line if it was created
+  FeaturePtr trimArc(const std::shared_ptr<GeomAPI_Pnt2d>& theStartShapePoint,
                const std::shared_ptr<GeomAPI_Pnt2d>& theLastShapePoint,
+               std::map<AttributePtr, std::list<AttributePtr> >& theBaseRefAttributes,
                std::set<std::shared_ptr<GeomDataAPI_Point2D> >& thePoints,
-               std::set<std::shared_ptr<ModelAPI_Feature>>& theCreatedFeatures,
                std::set<std::pair<AttributePtr, AttributePtr>>& theModifiedAttributes);
 
   /// Make the base object is splitted by the point attributes
-  /// \param theSplitFeature a result split feature
-  /// \param theBeforeFeature a feature between start point and the 1st point of split feature
-  /// \param theAfterFeature a feature between last point of split feature and the end point
   /// \param thePoints a list of points where coincidences will be build
-  /// \param theCreatedFeatures a container of created features
-  void trimCircle(const std::shared_ptr<GeomAPI_Pnt2d>& theStartShapePoint,
+  FeaturePtr trimCircle(const std::shared_ptr<GeomAPI_Pnt2d>& theStartShapePoint,
                   const std::shared_ptr<GeomAPI_Pnt2d>& theLastShapePoint,
                   std::set<std::shared_ptr<GeomDataAPI_Point2D> >& thePoints,
-                  std::set<std::shared_ptr<ModelAPI_Feature>>& theCreatedFeatures,
                   std::set<std::pair<AttributePtr, AttributePtr>>& theModifiedAttributes);
 
   /// Correct the first and the second point to provide condition that the first is closer to
@@ -225,7 +255,7 @@ private:
   /// \param theConstraintId a constraint index
   /// \param theFirstAttribute an attribute of further coincidence
   /// \param theSecondObject an object of further coincidence
-  std::shared_ptr<ModelAPI_Feature> createConstraint(const std::string& theConstraintId,
+  std::shared_ptr<ModelAPI_Feature> createConstraintToObject(const std::string& theConstraintId,
                         const std::shared_ptr<ModelAPI_Attribute>& theFirstAttribute,
                         const std::shared_ptr<ModelAPI_Object>& theSecondObject);
 
@@ -244,23 +274,16 @@ private:
                                     const std::shared_ptr<ModelAPI_Feature>& theFeature);
 
 private:
-  bool useGraphicIntersection() const;
-
-  void fillObjectShapes(const ObjectPtr& theObject);
-
-  void findShapePoints(std::shared_ptr<GeomAPI_Pnt>& aStartPoint,
+  void findShapePoints(const std::string& theObjectAttributeId,
+                       const std::string& thePointAttributeId,
+                       std::shared_ptr<GeomAPI_Pnt>& aStartPoint,
                        std::shared_ptr<GeomAPI_Pnt>& aLastPoint);
 
   std::shared_ptr<GeomAPI_Pnt2d> convertPoint(const std::shared_ptr<GeomAPI_Pnt>& thePoint);
 
 private:
-  std::map<ObjectPtr, std::set<GeomShapePtr> > myCashedShapes;
-
-  typedef std::map<std::shared_ptr<GeomAPI_Pnt>,
-                   std::pair<std::list<std::shared_ptr<GeomDataAPI_Point2D> >,
-                             std::list<std::shared_ptr<ModelAPI_Object> > > > PointToRefsMap;
-
-  std::map<ObjectPtr, PointToRefsMap> myObjectToPoints;
+  std::map<std::shared_ptr<ModelAPI_Object>, std::set<GeomShapePtr> > myCashedShapes;
+  std::map<std::shared_ptr<ModelAPI_Object>, PointToRefsMap> myObjectToPoints;
 };
 
 #endif