-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File: PlaneGCSSolver_Storage.h
-// Created: 14 Dec 2015
-// Author: Artem ZHIDKOV
+// Copyright (C) 2014-2021 CEA/DEN, EDF R&D
+//
+// 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 PlaneGCSSolver_Storage_H_
#define PlaneGCSSolver_Storage_H_
#include <PlaneGCSSolver_Defs.h>
-
-#include <SketchSolver.h>
#include <SketchSolver_Storage.h>
-#include <SketchSolver_ISolver.h>
+
+class PlaneGCSSolver_EntityBuilder;
/** \class PlaneGCSSolver_Storage
* \ingroup Plugins
class PlaneGCSSolver_Storage : public SketchSolver_Storage
{
public:
- PlaneGCSSolver_Storage(const GroupID& theGroup);
+ PlaneGCSSolver_Storage(const SolverPtr& theSolver);
// ============= Inherited from SketchSolver_Storage =============
/// \brief Change mapping between constraint from SketchPlugin and
- /// the list of constraints applicable for corresponding solver.
- /// Derived here to update point-point coincidence.
- /// \param theConstraint [in] original SketchPlugin constraint
- /// \param theSolverConstraints [in] list of solver's constraints
- virtual void addConstraint(ConstraintPtr theConstraint,
- std::list<ConstraintWrapperPtr> theSolverConstraints);
-
- /// \brief Update constraint's data
- /// \return \c true if any value is updated
- virtual bool update(ConstraintWrapperPtr theConstraint);
- /// \brief Update entity's data
- /// \return \c true if any value is updated
- virtual bool update(EntityWrapperPtr theEntity);
- /// \brief Update parameter's data
- /// \return \c true if the value of parameter is updated
- virtual bool update(ParameterWrapperPtr theParameter);
-
- /// \brief Update SketchPlugin features after resolving constraints
- /// \param theFixedOnly [in] if \c true the fixed points will be updated only
- virtual void refresh(bool theFixedOnly = false) const;
-
- /// \brief Check if some parameters or entities are returned
- /// to the current group after removing temporary constraints
- virtual void verifyFixed();
+ /// 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);
+
+
+ /// \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);
+
+ /// \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);
+
+ /// \brief Make entity external
+ virtual void makeExternal(const EntityWrapperPtr& theEntity);
+ /// \brief Make entity non-external
+ virtual void makeNonExternal(const EntityWrapperPtr& theEntity);
+
+ /// \brief Removes constraint from the storage
+ /// \return \c true if the constraint and all its parameters are removed successfully
+ virtual bool removeConstraint(ConstraintPtr theConstraint);
- /// \brief Mark two points as coincident
- virtual void addCoincidentPoints(EntityWrapperPtr theMaster, EntityWrapperPtr theSlave);
+ /// \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;
- /// \brief Shows the storage has the same constraint twice
- virtual bool hasDuplicatedConstraint() const
- { return false; }
+ /// \brief Update SketchPlugin features after resolving constraints
+ virtual void refresh() const;
- /// \brief Calculate point on theBase entity. Value theCoeff is in [0.0 .. 1.0] and
- /// shows the distance from the start point.
- virtual EntityWrapperPtr calculateMiddlePoint(EntityWrapperPtr theBase, double theCoeff);
+ /// \brief Initialize memory for new solver's parameter
+ double* createParameter();
+ /// \brief Release memory occupied by parameters
+ void removeParameters(const GCS::SET_pD& theParams);
- /// \brief Initialize solver by constraints, entities and parameters
- virtual void initializeSolver(SolverPtr theSolver);
+ /// \brief Remove all features became invalid
+ virtual void removeInvalidEntities();
-protected:
- /// \brief Remove constraint
- /// \return \c true if the constraint and all its parameters are removed successfully
- virtual bool remove(ConstraintWrapperPtr theConstraint);
- /// \brief Remove entity
- /// \return \c true if the entity and all its parameters are removed successfully
- virtual bool remove(EntityWrapperPtr theEntity);
- /// \brief Remove parameter
- /// \return \c true if the parameter has been removed
- virtual bool remove(ParameterWrapperPtr theParameter);
+ /// \brief Check the storage has constraints
+ virtual bool isEmpty() const
+ { return SketchSolver_Storage::isEmpty() && myAuxConstraintMap.empty(); }
- /// \brief Update the group for the given entity, its sub-entities and parameters
- virtual void changeGroup(EntityWrapperPtr theEntity, const GroupID& theGroup);
- /// \brief Update the group for the given parameter
- virtual void changeGroup(ParameterWrapperPtr theParam, const GroupID& theGroup);
+ /// \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();
+ /// \brief Return list of features which are not fully constrained
+ virtual void getUnderconstrainedGeometry(std::set<ObjectPtr>& theFeatures) const;
-// ============= Own methods =============
+private:
+ /// \brief Convert feature using specified builder.
+ EntityWrapperPtr createFeature(const FeaturePtr& theFeature,
+ PlaneGCSSolver_EntityBuilder* theBuilder);
- /// \brief Move parameters of the entity to the constants
- void makeConstant(const EntityWrapperPtr& theEntity);
- /// \brief Move parameters of the entity to the variables
- void makeVariable(const EntityWrapperPtr& theEntity);
+ /// \brief Convert attribute using specified builder.
+ EntityWrapperPtr createAttribute(const AttributePtr& theAttribute,
+ PlaneGCSSolver_EntityBuilder* theBuilder);
-private:
- /// \brief Move parameters of the entity from the list of variables to the list of constants
- /// and vice versa
- /// \param theEntity [in] entity to be changed
- /// \param theFrom [out] source list
- /// \param theTo [out] destination list
- void toggleEntity(const EntityWrapperPtr& theEntity, GCS::VEC_pD& theFrom, GCS::VEC_pD& theTo);
-
- /// \brief Create additional constraints for correct processing of arcs
- /// \param theArc [in] updated arc
- void processArc(const EntityWrapperPtr& theArc);
-
- /// \brief Adjust parameters of points coincident with the given
- void updateCoincident(const EntityWrapperPtr& thePoint);
-
- /// \brief Verifies the constraint should not be added into the solver
- ///
- /// This is a workaround method to avoid some kinds of conflicting constraints:
- /// * symmetric of two points placed on the mirror line (do not add perpendicular constraint)
- bool isRedundant(GCSConstraintPtr theCheckedConstraint,
- ConstraintWrapperPtr theParentConstraint,
- std::list<std::set<double*> >& theCoincidentPoints = std::list<std::set<double*> >() ) const;
+ /// \brief Create additional constaints:
+ /// * for arc to fix extra parameters;
+ /// * for ellipse to keep auxiliary points on their places
+ void createAuxiliaryConstraints(const EntityWrapperPtr& theEntity);
+ void removeAuxiliaryConstraints(const EntityWrapperPtr& theEntity);
private:
- GCS::VEC_pD myParameters; ///< list of parameters
- GCS::VEC_pD myConst; ///< list of constants
- EntityID myEntityLastID; ///< identifier of last added entity
- ConstraintID myConstraintLastID; ///< identifier of last added constraint
+ ConstraintID myConstraintLastID; ///< identifier of last added constraint
- std::map<EntityWrapperPtr, std::vector<GCSConstraintPtr> >
- myArcConstraintMap; ///< additional constraints for correct processing of the arcs
+ /// additional constraints for correct processing of the arcs, ellipses, elliptic arcs
+ std::map<EntityWrapperPtr, ConstraintWrapperPtr> myAuxConstraintMap;
- std::list<GCSConstraintPtr> myRemovedConstraints; ///< list of removed constraints to notify solver
+ /// list of removed constraints to notify solver
+ std::list<GCSConstraintPtr> myRemovedConstraints;
};
#endif