-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
-
-// File: SketchPlugin_Trim.h
-// Created: 22 Feb 2017
-// Author: Natalia ERMOLAEVA
+// Copyright (C) 2014-2023 CEA, EDF
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
#ifndef SketchPlugin_Trim_H_
#define SketchPlugin_Trim_H_
#include "SketchPlugin.h"
+#include <SketchPlugin_Tools.h>
+
+#include <GeomAPI_IPresentable.h>
+#include <ModelAPI_IReentrant.h>
#include <SketchPlugin_Sketch.h>
-#include "SketchPlugin_ConstraintBase.h"
class GeomDataAPI_Point2D;
class ModelAPI_Feature;
* \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
/// 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
/// Returns the AIS preview
SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
- /// Moves the feature : Empty
- SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY) {};
-
- 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);
+ /// 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);
private:
- 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
- /// \param theStartPointAttr an out attribute to start point
- /// \param theStartPointAttr an out attribute to end point
- void getFeaturePoints(const FeaturePtr& theFeature,
- std::shared_ptr<GeomDataAPI_Point2D>& theStartPointAttr,
- std::shared_ptr<GeomDataAPI_Point2D>& theEndPointAttr);
+ bool setCoincidenceToAttribute(const AttributePtr& theAttribute,
+ const std::set<std::shared_ptr<GeomDataAPI_Point2D> >& theFurtherCoincidences,
+ std::set<std::shared_ptr<ModelAPI_Feature>>& theFeaturesToDelete);
+ /// 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);
/// Obtains those constraints of the feature that should be modified. output maps contain
/// point of coincidence and attribute id to be modified after split
/// \param theFeaturesToDelete [out] constrains that will be deleted after split
- void getConstraints(std::set<std::shared_ptr<ModelAPI_Feature>>& theFeaturesToDelete);
-
- /// Obtains references to feature point attributes and to feature,
- /// e.g. for feature line: 1st container is
- /// <1st line point, list<entity_a in distance, entity_b in parallel> >
- /// <2nd line point, list<> >
- /// for feature circle 2nd container is <entity_a in Radius, entity_b in equal, ...>
- /// \param theFeature an investigated feature
- /// \param theRefs a container of list of referenced attributes
- void getRefAttributes(const FeaturePtr& theFeature,
- std::map<AttributePtr, std::list<AttributePtr> >& theRefs,
- std::list<AttributePtr>& theRefsToFeature);
-
- /// Obtains coincident features to the given object. It is collected in a container
- /// by the coincident attribute
- /// \param theObject an investigated object
- /// \param theCoincidencesToBaseFeature a container of list of referenced attributes
- void getCoincidencesToObject(const std::shared_ptr<ModelAPI_Object>& theObject,
- std::map<AttributePtr, FeaturePtr>& theCoincidencesToBaseFeature);
-
- /// 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
- /// at the same place
- void updateRefAttConstraints(
- const std::map<AttributePtr, std::list<AttributePtr> >& theBaseRefAttributes,
- const std::set<std::pair<AttributePtr, AttributePtr> >& theModifiedAttributes,
- std::set<std::shared_ptr<ModelAPI_Feature>>& theFeaturesToDelete);
+ /// \param theFeaturesToUpdate [out] constrains that will be updated after split
+ void getConstraints(std::set<std::shared_ptr<ModelAPI_Feature>>& theFeaturesToDelete,
+ std::set<FeaturePtr>& theFeaturesToUpdate);
+
+ /// 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);
/// 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 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
- void trimLine(const std::shared_ptr<GeomAPI_Pnt2d>& theStartShapePoint,
+ /// \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::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
- 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::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
- 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::pair<AttributePtr, AttributePtr>>& theModifiedAttributes);
+ /// \return new elliptic arc if it was created
+ FeaturePtr trimEllipticArc(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::pair<AttributePtr, AttributePtr>>& theModifiedAttributes);
+
+ /// Make the base object is splitted by the point attributes
+ /// \param thePoints a list of points where coincidences will be build
+ FeaturePtr trimClosed(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::pair<AttributePtr, AttributePtr>>& theModifiedAttributes);
/// Correct the first and the second point to provide condition that the first is closer to
/// the start point and the second point - to the last end of current segment. To rearrange
void fillPointAttribute(const AttributePtr& theModifiedAttribute,
const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
- /// Creates a line feature filled by center of base feature and given points
- /// \param theBaseFeature another arc feature
- /// \param theFirstAttribute an attribute with coordinates for the start point
- /// \param theSecondAttribute an attribute with coordinates for the end point
- FeaturePtr createLineFeature(const FeaturePtr& theBaseFeature,
- const std::shared_ptr<GeomAPI_Pnt2d>& theFirstPoint,
- const std::shared_ptr<GeomAPI_Pnt2d>& theSecondPoint);
-
- /// Creates an arc feature filled by center of base feature and given points
- /// \param theBaseFeature another arc feature
- /// \param theFirstAttribute an attribute with coordinates for the start point
- /// \param theSecondAttribute an attribute with coordinates for the end point
- FeaturePtr createArcFeature(const FeaturePtr& theBaseFeature,
- const std::shared_ptr<GeomAPI_Pnt2d>& theFirstPoint,
- const std::shared_ptr<GeomAPI_Pnt2d>& theSecondPoint);
-
- /// Add feature coincidence constraint between given attributes
- /// \param theConstraintId a constraint index
- /// \param theFirstAttribute an attribute of further coincidence
- /// \param theSecondAttribute an attribute of further coincidence
- std::shared_ptr<ModelAPI_Feature> createConstraint(const std::string& theConstraintId,
- const std::shared_ptr<ModelAPI_Attribute>& theFirstAttribute,
- const std::shared_ptr<ModelAPI_Attribute>& theSecondAttribute);
-
- /// Add feature coincidence constraint between given attributes
- /// \param theConstraintId a constraint index
- /// \param theFirstAttribute an attribute of further coincidence
- /// \param theSecondObject an object of further coincidence
- std::shared_ptr<ModelAPI_Feature> createConstraintToObject(const std::string& theConstraintId,
- const std::shared_ptr<ModelAPI_Attribute>& theFirstAttribute,
- const std::shared_ptr<ModelAPI_Object>& theSecondObject);
-
- /// Add feature coincidence constraint between given attributes
- /// \param theConstraintId a constraint index
- /// \param theFirstAttribute an attribute of further coincidence
- /// \param theFirstAttribute an attribute of further coincidence
- std::shared_ptr<ModelAPI_Feature> createConstraintForObjects(const std::string& theConstraintId,
- const std::shared_ptr<ModelAPI_Object>& theFirstObject,
- const std::shared_ptr<ModelAPI_Object>& theSecondObject);
-
- /// Result result of the feature to build constraint with. For arc, circle it is an edge result.
- /// \param theFeature a feature
- /// \return result object
- std::shared_ptr<ModelAPI_Result> getFeatureResult(
- const std::shared_ptr<ModelAPI_Feature>& theFeature);
-
private:
void findShapePoints(const std::string& theObjectAttributeId,
const std::string& thePointAttributeId,
private:
std::map<std::shared_ptr<ModelAPI_Object>, std::set<GeomShapePtr> > myCashedShapes;
- std::map<std::shared_ptr<ModelAPI_Object>, PointToRefsMap> myObjectToPoints;
+ std::map<std::shared_ptr<ModelAPI_Object>,
+ GeomAlgoAPI_ShapeTools::PointToRefsMap> myObjectToPoints;
};
#endif