-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File: SketchSolver_Storage.h
-// Created: 18 Mar 2015
-// Author: Artem ZHIDKOV
+// 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 SketchSolver_Storage_H_
#define SketchSolver_Storage_H_
-#include "SketchSolver.h"
-#include <SketchSolver_Solver.h>
+#include <PlaneGCSSolver_ConstraintWrapper.h>
+#include <PlaneGCSSolver_EntityWrapper.h>
+
+#include <PlaneGCSSolver_Solver.h>
+#include <PlaneGCSSolver_UpdateFeature.h>
+
+#include <ModelAPI_Attribute.h>
+#include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_Feature.h>
+#include <SketchPlugin_Constraint.h>
+
+class SketchSolver_ConstraintDistance;
+class SketchSolver_ConstraintFixedArcRadius;
+typedef std::map<EntityWrapperPtr, std::set<EntityWrapperPtr> > CoincidentPointsMap;
-#include <list>
-#include <memory>
-#include <set>
-#include <vector>
/** \class SketchSolver_Storage
* \ingroup Plugins
- * \brief Contains all necessary data in SolveSpace format to solve a single group of constraints
+ * \brief Interface to map SketchPlugin features to the entities of corresponding solver.
*/
class SketchSolver_Storage
{
+private:
+ SketchSolver_Storage(const SketchSolver_Storage&);
+ SketchSolver_Storage& operator=(const SketchSolver_Storage&);
+
public:
- SketchSolver_Storage();
-
- /** \brief Add new parameter to the current group
- * \param[in] theParam SolveSpace parameter
- * \return the ID of added parameter
- */
- Slvs_hParam addParameter(const Slvs_Param& theParam);
- /** \brief Updates parameter in the current group. If the ID of parameter is zero, the new item will be added
- * \param[in] theParam SolveSpace parameter
- * \return the ID of updated/added parameter
- */
- Slvs_hParam updateParameter(const Slvs_Param& theParam);
- /** \brief Removes the parameter by its ID
- * \param[in] theParamID index of parameter to be removed
- * \return \c true if the parameter was successfully removed
- */
- bool removeParameter(const Slvs_hParam& theParamID);
- /// \brief Returns the parameter by its ID
- const Slvs_Param& getParameter(const Slvs_hParam& theParamID) const;
-
- /** \brief Add new entity to the current group
- * \param[in] theEntity SolveSpace entity
- * \return the ID of added entity
- */
- Slvs_hEntity addEntity(const Slvs_Entity& theEntity);
- /** \brief Updates entity in the current group. If the ID of entity is zero, the new item will be added
- * \param[in] theEntity SolveSpace entity
- * \return the ID of updated/added entity
- */
- Slvs_hEntity updateEntity(const Slvs_Entity& theEntity);
- /** \brief Removes the entity by its ID. All parameters used in this entity,
- * and not used in other constraints, will be removed too.
- * \param[in] theEntityID index of entity to be removed
- * \return \c true if the entity was successfully removed
- */
- bool removeEntity(const Slvs_hEntity& theEntityID);
- /// \brief Returns the entity by its ID
- const Slvs_Entity& getEntity(const Slvs_hEntity& theEntityID) const;
-
- /// \brief Verifies the current point or another coincident one is fixed
- /// \return the ID of the Fixed constraint or SLVS_E_UNKNOWN
- Slvs_hConstraint isPointFixed(const Slvs_hEntity& thePointID) const;
-
- /** \brief Add new constraint to the current group
- * \param[in] theConstraint SolveSpace's constraint
- * \return the ID of added constraint
- */
- Slvs_hConstraint addConstraint(const Slvs_Constraint& theConstraint);
- /** \brief Updates constraint in the current group.
- * If the ID of constraint is zero, the new item will be added
- * \param[in] theConstraint SolveSpace constraint
- * \return the ID of updated/added constraint
- */
- Slvs_hConstraint updateConstraint(const Slvs_Constraint& theConstraint);
- /** \brief Removes the constraint by its ID. All entities and parameters depending on this
- * constraint, which are not used in other constraints, will be removed too.
- * \param[in] theConstraintID index of constraint to be removed
- * \return \c true if the constraint was successfully removed
- */
- bool removeConstraint(const Slvs_hConstraint& theConstraintID);
- /// \brief Returns the constraint by its ID
- const Slvs_Constraint& getConstraint(const Slvs_hConstraint& theConstraintID) const;
- /// \brief Returns list of constraints of specified type
- std::list<Slvs_Constraint> getConstraintsByType(int theConstraintType) const;
-
- /// \brief Attach temporary constraint to this storage. It need to make precise calculations
- void addTemporaryConstraint(const Slvs_hConstraint& theConstraintID);
+ SketchSolver_Storage(SolverPtr theSolver);
+
+ /// \brief Change mapping between constraint from SketchPlugin and
+ /// a constraint applicable for corresponding solver.
+ /// \param theConstraint [in] original SketchPlugin constraint
+ /// \param theSolverConstraint [in] solver's constraint
+ virtual void addConstraint(ConstraintPtr theConstraint,
+ ConstraintWrapperPtr theSolverConstraint);
+
+ /// \brief Add a movement constraint which will be destroyed
+ /// after the next solving of the set of constraints.
+ /// \param theSolverConstraint [in] solver's constraint
+ virtual void addMovementConstraint(const ConstraintWrapperPtr& theSolverConstraint) = 0;
+
+ /// \brief Change mapping feature from SketchPlugin and
+ /// the entity applicable for corresponding solver.
+ /// \param theFeature [in] original SketchPlugin feature
+ /// \param theSolverEntity [in] solver's entity, created outside
+ void addEntity(FeaturePtr theFeature,
+ EntityWrapperPtr theSolverEntity);
+
+ /// \brief Change mapping attribute of a feature and the entity
+ /// applicable for corresponding solver.
+ /// \param theAttribute [in] original attribute
+ /// \param theSolverEntity [in] solver's entity, created outside
+ void addEntity(AttributePtr theAttribute,
+ EntityWrapperPtr theSolverEntity);
+
+ /// \brief Convert feature to the form applicable for specific solver and map it
+ /// \param theFeature [in] feature to convert
+ /// \param theForce [in] forced feature creation
+ /// \return \c true if the feature has been created or updated
+ virtual bool update(FeaturePtr theFeature, bool theForce = false) = 0;
+
+ /// \brief Convert attribute to the form applicable for specific solver and map it
+ /// \param theAttribute [in] attribute to convert
+ /// \param theForce [in] forced feature creation
+ /// \return \c true if the attribute has been created or updated
+ virtual bool update(AttributePtr theAttribute, bool theForce = false) = 0;
+
+ /// \brief Returns constraint related to corresponding constraint
+ const ConstraintWrapperPtr& constraint(const ConstraintPtr& theConstraint) const;
+
+ /// \brief Returns entity related to corresponding feature
+ const EntityWrapperPtr& entity(const FeaturePtr& theFeature) const;
+ /// \brief Returns entity related to corresponding attribute
+ const EntityWrapperPtr& entity(const AttributePtr& theAttribute) const;
+
+ /// \brief Make entity external
+ virtual void makeExternal(const EntityWrapperPtr& theEntity) = 0;
+ /// \brief Make entity non-external
+ virtual void makeNonExternal(const EntityWrapperPtr& theEntity) = 0;
+
+ /// \brief Removes constraint from the storage
+ /// \return \c true if the constraint and all its parameters are removed successfully
+ virtual bool removeConstraint(ConstraintPtr theConstraint) = 0;
+ /// \brief Removes feature from the storage
+ void removeFeature(FeaturePtr theFeature);
+ /// \brief Removes attribute from the storage
+ void removeAttribute(AttributePtr theAttribute);
+
+ /// \brief Remove all features became invalid
+ virtual void removeInvalidEntities() = 0;
+
+ /// \brief Check the features have not been removed
+ bool areFeaturesValid() const;
+
+ /// \brief Check the storage has constraints
+ virtual bool isEmpty() const
+ { return myConstraintMap.empty(); }
/// \brief Shows the sketch should be resolved
- bool isNeedToResolve() const
+ virtual bool isNeedToResolve()
{ return myNeedToResolve; }
-
/// \brief Changes the flag of group to be resolved
void setNeedToResolve(bool theFlag)
{ myNeedToResolve = theFlag; }
- /// \brief Returns lists of removed elements
- void getRemoved(std::set<Slvs_hParam>& theParameters,
- std::set<Slvs_hEntity>& theEntities,
- std::set<Slvs_hConstraint>& theConstraints);
-
- /// \brief Initialize constraint solver by the entities collected by current storage
- void initializeSolver(SketchSolver_Solver& theSolver);
-
-private:
- /// \brief Store coincident points
- void addCoincidentPoints(const Slvs_hEntity& thePoint1, const Slvs_hEntity& thePoint2);
- /// \brief Remove point from lists of coincidence
- void removeCoincidentPoint(const Slvs_hEntity& thePoint);
-
-public:
- /// \brief Check two points are coincident
- bool isCoincident(const Slvs_hEntity& thePoint1, const Slvs_hEntity& thePoint2) const;
-
-private:
- Slvs_hParam myParamMaxID; ///< current parameter index (may differs with the number of parameters)
- std::vector<Slvs_Param> myParameters; ///< list of parameters used in the current group of constraints (sorted by the identifier)
- Slvs_hEntity myEntityMaxID; ///< current entity index (may differs with the number of entities)
- std::vector<Slvs_Entity> myEntities; ///< list of entities used in the current group of constraints (sorted by the identifier)
- Slvs_hConstraint myConstrMaxID; ///< current constraint index (may differs with the number of constraints)
- std::vector<Slvs_Constraint> myConstraints; ///< list of constraints used in the current group (sorted by the identifier)
-
- std::vector< std::set<Slvs_hEntity> > myCoincidentPoints; ///< lists of coincident points
- Slvs_hConstraint myFixed; ///< identifier of one of temporary constraints to fix separate point
-
- bool myNeedToResolve; ///< parameters are changed and group needs to be resolved
-
- std::set<Slvs_hParam> myRemovedParameters; ///< list of just removed parameters (cleared when returning to applicant)
- std::set<Slvs_hEntity> myRemovedEntities; ///< list of just removed entities (cleared when returning to applicant)
- std::set<Slvs_hConstraint> myRemovedConstraints; ///< list of just removed constraints (cleared when returning to applicant)
+ /// \brief Return list of conflicting constraints
+ std::set<ObjectPtr> getConflictingConstraints(SolverPtr theSolver) const;
+
+ /// \brief Return list of features which are not fully constrained
+ virtual void getUnderconstrainedGeometry(std::set<ObjectPtr>& theFeatures) const = 0;
+
+ /// \brief Verify, the sketch contains degenerated geometry
+ /// after resolving the set of constraints
+ /// \return STATUS_OK if the geometry is valid, STATUS_DEGENERATED otherwise.
+ virtual PlaneGCSSolver_Solver::SolveStatus checkDegeneratedGeometry() const = 0;
+
+ /// \brief Update SketchPlugin features after resolving constraints
+ virtual void refresh() const = 0;
+
+ /// \brief Block or unblock events when refreshing features
+ void blockEvents(bool isBlocked);
+
+ /// \brief Subscribe for updates of features
+ /// \param theSubscriber [in] object which wants to revceive notifications
+ /// \param theGroup [in] group of updates features to be send
+ void subscribeUpdates(SketchSolver_Constraint* theSubscriber, const std::string& theGroup) const;
+ /// \brief Unsubscribe for updates of features
+ /// \param theSubscriber [in] object which does not want to revceive notifications anymore
+ void unsubscribeUpdates(SketchSolver_Constraint* theSubscriber) const;
+
+ /// \brief Notify all subscribers about update of the feature
+ void notify(const FeaturePtr& theFeature) const;
+
+ /// \brief Make parametrization of arcs consistent.
+ /// Forward arcs should have the last parameter greater than the first parameter.
+ /// Reversed arcs should have the last parameter lesser than the first parameter.
+ virtual void adjustParametrizationOfArcs() = 0;
+
+protected:
+ /// \brief Convert result to feature or attribute if theResult is linked to center of circle/arc
+ static void resultToFeatureOrAttribute(const ObjectPtr& theResult,
+ FeaturePtr& theFeature,
+ AttributePtr& theAttribute);
+
+protected:
+ SolverPtr mySketchSolver; ///< Sketch solver, prepared in corresponding group
+ bool myNeedToResolve; ///< parameters are changed and group needs to be resolved
+ bool myEventsBlocked; ///< indicates that features do not send events
+
+ /// map SketchPlugin constraint to a list of solver's constraints
+ std::map<ConstraintPtr, ConstraintWrapperPtr> myConstraintMap;
+ /// map SketchPlugin feature to solver's entity
+ std::map<FeaturePtr, EntityWrapperPtr> myFeatureMap;
+ /// map attribute to solver's entity
+ std::map<AttributePtr, EntityWrapperPtr> myAttributeMap;
+
+ UpdaterPtr myUpdaters;
};
typedef std::shared_ptr<SketchSolver_Storage> StoragePtr;