X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchSolver%2FSketchSolver_Group.h;h=8422b32ffddabd7a359755df30d6a201853ceb61;hb=fc72d43b677baa05ae7fd317346fd8b723b799ed;hp=68317fd0a15db5819d55f311d595036ece11c737;hpb=bc06873747d5ea9bc0e8d6bd56641eebe33ac08d;p=modules%2Fshaper.git diff --git a/src/SketchSolver/SketchSolver_Group.h b/src/SketchSolver/SketchSolver_Group.h index 68317fd0a..8422b32ff 100644 --- a/src/SketchSolver/SketchSolver_Group.h +++ b/src/SketchSolver/SketchSolver_Group.h @@ -1,34 +1,44 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -// File: SketchSolver_Group.h -// Created: 27 May 2014 -// Author: Artem ZHIDKOV +// Copyright (C) 2014-2023 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 SketchSolver_Group_H_ #define SketchSolver_Group_H_ -#include "SketchSolver.h" #include #include -#include -#include -#include -#include -#include +#include +#include #include -#include #include -#include -#include + +class GeomAPI_Dir; +class GeomAPI_Pnt; +class GeomAPI_Pnt2d; typedef std::map ConstraintConstraintMap; /** \class SketchSolver_Group * \ingroup Plugins - * \brief Keeps the group of constraints which based on the same entities + * \brief Keeps the group of constraints which placed in the same sketch */ class SketchSolver_Group { @@ -37,31 +47,14 @@ class SketchSolver_Group * Throws an exception if theWorkplane is not an object of SketchPlugin_Sketch type * \remark Type of theSketch is not verified inside */ - SketchSolver_Group(std::shared_ptr theWorkplane); - - ~SketchSolver_Group(); + SketchSolver_Group(const CompositeFeaturePtr& theWorkplane); - /// \brief Returns group's unique identifier - inline const Slvs_hGroup& getId() const - { - return myID; - } - - /// \brief Returns identifier of the workplane - inline const Slvs_hEntity& getWorkplaneId() const - { - return myWorkplaneID; - } - - /// \brief Find the identifier of the feature, if it already exists in the group - Slvs_hEntity getFeatureId(FeaturePtr theFeature) const; - /// \brief Find the identifier of the attribute, if it already exists in the group - Slvs_hEntity getAttributeId(AttributePtr theAttribute) const; + virtual ~SketchSolver_Group(); /// \brief Returns true if the group has no constraints yet inline bool isEmpty() const { - return myConstraints.empty(); + return myConstraints.empty() && myTempConstraints.empty(); } /// \brief Check for valid sketch data @@ -75,235 +68,102 @@ class SketchSolver_Group * \return \c true if the constraint added or updated successfully */ bool changeConstraint(std::shared_ptr theConstraint); -//// /** \brief Adds or updates a rigid constraint in the group -//// * \param[in] theConstraint constraint to be changed -//// * \return \c true if the constraint added or updated successfully -//// */ -//// bool changeRigidConstraint(std::shared_ptr theConstraint); -//// /** \brief Adds or updates a mirror constraint in the group -//// * \param[in] theConstraint constraint to be changed -//// * \return \c true if the constraint added or updated successfully -//// */ -//// bool changeMirrorConstraint(std::shared_ptr theConstraint); -//// /** \brief Adds or updates a fillet constraint in the group -//// * \param[in] theConstraint constraint to be changed -//// * \return \c true if the constraint added or updated successfully -//// */ -//// bool changeFilletConstraint(std::shared_ptr theConstraint); - /** \brief Updates the data corresponding the specified feature moved in GUI. - * Additional Fixed constraints are created. - * \param[in] theFeature the feature to be updated + /** \brief Updates the sketch feature */ - void moveFeature(std::shared_ptr theFeature); + bool updateSketch(CompositeFeaturePtr theSketch); - /** \brief Verifies the feature attributes are used in this group - * \param[in] theFeature constraint or any other object for verification of interaction - * \return \c true if some of attributes are used in current group + /** \brief Updates the data corresponding the specified feature + * \param[in] theFeature the feature to be updated */ - bool isInteract(std::shared_ptr theFeature) const; + bool updateFeature(FeaturePtr theFeature); - /** \brief Verifies the specified feature is equal to the base workplane for this group - * \param[in] theWorkplane the feature to be compared with base workplane - * \return \c true if workplanes are the same + /** \brief Updates the data corresponding the specified feature moved in GUI. + * Special kind of Fixed constraints is created. + * \param[in] theFeature the feature to be updated + * \param[in] theFrom start point of the movement + * \param[in] theTo final point of the movement + * \return \c true, if the feature is really moved + */ + bool moveFeature(FeaturePtr theFeature, + const std::shared_ptr& theFrom, + const std::shared_ptr& theTo); + /** \brief Updates the data corresponding the specified point moved in GUI. + * Special kind of Fixed constraints is created. + * \param[in] thePointOrArray the attribute to be updated + * \param[in] thePointIndex index of moved point in array + * \param[in] theFrom start point of the movement + * \param[in] theTo destination point of the movement + * \return \c true, if the attribute is really moved */ - bool isBaseWorkplane(CompositeFeaturePtr theWorkplane) const; + bool movePoint(AttributePtr thePointOrArray, + const int thePointIndex, + const std::shared_ptr& theFrom, + const std::shared_ptr& theTo); /// Returns the current workplane - std::shared_ptr getWorkplane() const + inline const CompositeFeaturePtr& getWorkplane() const { return mySketch; } - /** \brief Update parameters of workplane. Should be called when Update event is coming. - * \return \c true if workplane updated successfully, \c false if workplane parameters are not consistent - */ - bool updateWorkplane(); -//// -//// /** \brief If the entity is in this group it will updated -//// * \param[in] theEntity attribute, which values should update SolveSpace entity -//// */ -//// void updateEntityIfPossible(std::shared_ptr theEntity); - /** \brief Searches invalid features and constraints in the group and removes them * \return \c false if the group several constraints were removed */ - bool isConsistent(); - - /** \brief Add specified group to this one - * \param[in] theGroup group of constraint to be added - */ - void mergeGroups(const SketchSolver_Group& theGroup); - - /** \brief Cut from the group several subgroups, which are not connected to the current one by any constraint - * \param[out] theCuts enlarge this list by newly created groups - */ - void splitGroup(std::vector& theCuts); + void repairConsistency(); /** \brief Start solution procedure if necessary and update attributes of features * \return \c false when no need to solve constraints */ bool resolveConstraints(); -//// -//// /** \brief Searches the constraints built on the entity and emit the signal to update them -//// * \param[in] theEntity attribute of the constraint -//// */ -//// void updateRelatedConstraints(std::shared_ptr theEntity) const; -//// /** \brief Searches the constraints built on the entity and emit the signal to update them -//// * \param[in] theFeature feature of the constraint -//// */ -//// void updateRelatedConstraintsFeature(std::shared_ptr theFeature) const; -//// -//// /** \brief Adds or updates an entity in the group -//// * -//// * The parameters of entity will be parsed and added to the list of SolveSpace parameters. -//// * Parameters of certain entity will be placed sequentially in the list. -//// * -//// * \param[in] theEntity the object of constraint -//// * \return identifier of changed entity or 0 if entity could not be changed -//// */ -//// Slvs_hEntity changeEntity(std::shared_ptr theEntity); -//// Slvs_hEntity changeEntityFeature(std::shared_ptr theEntity); - -protected: -//// /** \brief Adds or updates a normal in the group -//// * -//// * Normal is a special entity in SolveSpace, which defines a direction in 3D and -//// * a rotation about this direction. So, SolveSpace represents normals as unit quaternions. -//// * -//// * To define a normal there should be specified two coordinate axis -//// * on the plane transversed to created normal. -//// * -//// * \param[in] theDirX first coordinate axis of the plane -//// * \param[in] theNorm attribute for the normal (used to identify newly created entity) -//// * \return identifier of created or updated normal -//// */ -//// Slvs_hEntity changeNormal(std::shared_ptr theDirX, -//// std::shared_ptr theNorm); -//// -//// /** \brief Adds or updates a parameter in the group -//// * \param[in] theParam the value of parameter -//// * \param[in] thePrmIter the cell in the list of parameters which should be changed -//// * (the iterator will be increased if it does not reach the end of the list) -//// * \return identifier of changed parameter; when the parameter cannot be created, returned ID is 0 -//// */ -//// Slvs_hParam changeParameter(const double& theParam, -//// std::vector::const_iterator& thePrmIter); -//// -//// /** \brief Removes specified entities and their parameters -//// * \param[in] theEntities list of IDs of the entities to be removed -//// */ -//// void removeEntitiesById(const std::set& theEntities); + + /// \brief Find the list of features, which are not fully constrained. + void underconstrainedFeatures(std::set& theFeatures) const; + + /// \brief Block or unblock events sent by features in this group + void blockEvents(bool isBlocked); + +private: + /// \biref Verify constraints have not been removed + bool areConstraintsValid() const; /** \brief Removes constraints from the group * \param[in] theConstraint constraint to be removed */ void removeConstraint(ConstraintPtr theConstraint); -//// -//// /** \brief Change values of attribute by parameters received from SolveSpace solver -//// * \param[in,out] theAttribute pointer to the attribute to be changed -//// * \param[in] theEntityID identifier of SolveSpace entity, which contains updated data -//// * \return \c true if the attribute's value has changed -//// */ -//// bool updateAttribute(std::shared_ptr theAttribute, -//// const Slvs_hEntity& theEntityID); -//// -//// /// \brief Update arc of fillet to be less than 180 degree -//// void updateFilletConstraints(); -//// -//// /** \brief Adds a constraint for a point which should not be changed during computations -//// * \param[in] theEntity the base for the constraint -//// * \param[in] theAllowToFit this flag shows that the entity may be placed into -//// * the 'dragged' field of SolveSpace solver, so this entity -//// * may be changed a little during solution -//// */ -//// void addTemporaryConstraintWhereDragged(std::shared_ptr theEntity, -//// bool theAllowToFit = true); - - /** \brief Remove all temporary constraint after computation finished - * \param[in] theRemoved indexes of constraints to be removed. If empty, all temporary constraints should be deleted - */ + + /// \brief Remove all temporary constraints after the computation finished void removeTemporaryConstraints(); -private: - /** \brief Creates a workplane from the sketch parameters - * \param[in] theSketch parameters of workplane are the attributes of this sketch - * \return \c true if success, \c false if workplane parameters are not consistent - */ - bool addWorkplane(CompositeFeaturePtr theSketch); -//// -//// /** \brief Add the entities of constraint for points coincidence into the appropriate list -//// * \param[in] thePoint1 identifier of the first point -//// * \param[in] thePoint2 identifier of the second point -//// * \return \c true if the points are added successfully, and -//// * \c false if the constraint is the extra one (should not be created in SolveSpace) -//// */ -//// bool addCoincidentPoints(const Slvs_hEntity& thePoint1, const Slvs_hEntity& thePoint2); -//// -//// /** \brief Verifies and changes parameters of constriant, -//// * e.g. sign of the distance between line and point -//// * \param[in,out] theConstraint SolveSpace constraint to be verified -//// */ -//// void checkConstraintConsistence(Slvs_Constraint& theConstraint); -//// -//// /** \brief Change entities parameters to make them symmetric relating to the mirror line -//// * \param[in] theBase entity to be mirrored -//// * \param[in] theMirror a mirrored object -//// * \param[in] theMirrorLine a mirror line -//// */ -//// void makeMirrorEntity(const Slvs_hEntity& theBase, -//// const Slvs_hEntity& theMirror, -//// const Slvs_hEntity& theMirrorLine); -//// -//// /** \brief Calculates middle point on line or arc -//// * \param[in] theEntity identifier of line or arc -//// * \param[out] theX X value of middle point -//// * \param[out] theY Y value of middle point -//// */ -//// void calculateMiddlePoint(const Slvs_hEntity& theEntity, -//// double& theX, double& theY) const; -//// -//// private: -//// // SolveSpace entities -//// Slvs_hGroup myID; ///< the index of the group -//// Slvs_Entity myWorkplane; ///< Workplane for the current group -//// std::vector myParams; ///< List of parameters of the constraints -//// Slvs_hParam myParamMaxID; ///< Actual maximal ID of parameters (not equal to myParams size) -//// std::vector myEntities; ///< List of entities of the constaints -//// std::vector myEntOfConstr; ///< Flags show that certain entity used in constraints -//// Slvs_hEntity myEntityMaxID; ///< Actual maximal ID of entities (not equal to myEntities size) -//// std::vector myConstraints; ///< List of constraints in SolveSpace format -//// Slvs_hConstraint myConstrMaxID; ///< Actual maximal ID of constraints (not equal to myConstraints size) -//// bool myNeedToSolve; ///< Indicator that something changed in the group and constraint system need to be rebuilt -//// -//// SketchSolver_Solver myConstrSolver; ///< Solver for set of equations obtained by constraints -//// -//// std::vector myTempPointWhereDragged; ///< Parameters of one of the points which is moved by user -//// Slvs_hEntity myTempPointWDrgdID; ///< Identifier of such point -//// std::list myTempConstraints; ///< The list of identifiers of temporary constraints (SLVS_C_WHERE_DRAGGED) applied for all other points moved by user -//// -//// // SketchPlugin entities -//// std::shared_ptr mySketch; ///< Equivalent to workplane -//// ConstraintMap myConstraintMap; ///< The map between SketchPlugin and SolveSpace constraints -//// std::map, Slvs_hEntity> myEntityAttrMap; ///< The map between "attribute" parameters of constraints and their equivalent SolveSpace entities -//// std::map myEntityFeatMap; ///< The map between "feature" parameters of constraints and their equivalent SolveSpace entities -//// -//// // Conincident items -//// std::vector > myCoincidentPoints; ///< Stores the lists of identifiers of coincident points (to avoid unnecessary coincidence constraints) -//// std::set > myExtraCoincidence; ///< Additional coincidence constraints which are not necessary (coincidence between points already done -//// ///< by other constraints) but created by GUI tools. Useful when some coincidence constraints were removed + /// \brief Append given constraint to the group of temporary constraints + void setTemporary(SolverConstraintPtr theConstraint); + + /// \brief Compute DoF of the sketch and set corresponding field + void computeDoF(); private: - Slvs_hGroup myID; ///< Index of the group - Slvs_hEntity myWorkplaneID; ///< Index of workplane, the group is based on - CompositeFeaturePtr mySketch; ///< Sketch is equivalent to workplane + CompositeFeaturePtr mySketch; ///< Sketch for this group + std::shared_ptr mySketchOrigin; + std::shared_ptr mySketchNormal; + std::shared_ptr mySketchXDir; + ConstraintConstraintMap myConstraints; ///< List of constraints std::set myTempConstraints; ///< List of temporary constraints StoragePtr myStorage; ///< Container for the set of SolveSpace constraints and their entities - FeatureStoragePtr myFeatureStorage; ///< Container for the set of SketchPlugin features and their dependencies + SolverPtr mySketchSolver; ///< Solver for set of equations obtained by constraints - SketchSolver_Solver myConstrSolver; ///< Solver for set of equations obtained by constraints + /// Result of previous solution of the set of constraints + PlaneGCSSolver_Solver::SolveStatus myPrevResult; + std::set myConflictingConstraints; ///< List of conflicting constraints + + int myDOF; ///< degrees of freedom of the current sketch + + bool myIsEventsBlocked; ///< shows the events are blocked for this group + + int myMultiConstraintUpdateStack; ///< depth of the stack updating "Multi" constraints }; +typedef std::shared_ptr SketchGroupPtr; + #endif