Salome HOME
Clean Property panel before starting of a new operation.
[modules/shaper.git] / src / SketchSolver / SketchSolver_ConstraintGroup.h
index 1d29742961444fb9d07b5be531644c85776c898e..69c1a7c04584e6894796a4ab1fcc4f85a1da8e8b 100644 (file)
@@ -9,6 +9,7 @@
 #include <SketchSolver_Solver.h>
 
 #include <SketchPlugin_Constraint.h>
+#include <ModelAPI_Data.h>
 
 #include <list>
 #include <map>
@@ -39,6 +40,10 @@ public:
   inline bool isEmpty() const
   {return myConstraints.empty();}
 
+  /// \brief Check for valid sketch data
+  inline bool isWorkplaneValid() const
+  {return mySketch->data()->isValid();}
+
   /** \brief Adds or updates a constraint in the group
    *  \param[in] theConstraint constraint to be changed
    *  \return \c true if the constraint added or updated successfully
@@ -71,7 +76,7 @@ public:
   void updateEntityIfPossible(boost::shared_ptr<ModelAPI_Attribute> theEntity);
 
   /** \brief Searches invalid features and constraints in the group and avoids them
-   *  \return \c true if the group's sketch is invalid and the group should be removed
+   *  \return \c true if the group several constraints were removed
    */
   bool updateGroup();
 
@@ -80,6 +85,11 @@ public:
    */
   void mergeGroups(const SketchSolver_ConstraintGroup& 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<SketchSolver_ConstraintGroup*>& theCuts);
+
   /** \brief Start solution procedure if necessary and update attributes of features
    */
   void resolveConstraints();
@@ -94,6 +104,7 @@ protected:
    *  \return identifier of changed entity or 0 if entity could not be changed
    */
   Slvs_hEntity changeEntity(boost::shared_ptr<ModelAPI_Attribute> theEntity);
+  Slvs_hEntity changeEntity(FeaturePtr   theEntity);
 
   /** \brief Adds or updates a normal in the group
    *
@@ -121,6 +132,11 @@ protected:
   Slvs_hParam changeParameter(const double& theParam,
                               std::vector<Slvs_Param>::const_iterator& thePrmIter);
 
+  /** \brief Removes constraints from the group
+   *  \param[in] theConstraint constraint to be removed
+   */
+  void removeConstraint(boost::shared_ptr<SketchPlugin_Constraint> 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
@@ -143,6 +159,14 @@ private:
    */
   bool addWorkplane(boost::shared_ptr<SketchPlugin_Feature> 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);
+
 private:
   // SolveSpace entities
   Slvs_hGroup                  myID;            ///< the index of the group
@@ -157,13 +181,26 @@ private:
 
   SketchSolver_Solver          myConstrSolver;  ///< Solver for set of equations obtained by constraints
 
+  std::vector<Slvs_hParam>     myTempPointWhereDragged; ///< Parameters of one of the points which is moved by user
+  Slvs_hEntity                 myTempPointWDrgdID;      ///< Identifier of such point
+  std::list<Slvs_hConstraint>  myTempConstraints;       ///< The list of identifiers of temporary constraints (SLVS_C_WHERE_DRAGGED) applied for all other points moved by user
+
   // SketchPlugin entities
-  boost::shared_ptr<SketchPlugin_Feature> mySketch; ///< Equivalent to workplane
+  boost::shared_ptr<SketchPlugin_Feature>
+                               mySketch;        ///< Equivalent to workplane
   std::map<boost::shared_ptr<SketchPlugin_Constraint>, Slvs_hConstraint>
-                                myConstraintMap;    ///< The map between SketchPlugin and SolveSpace constraints
-  std::list<Slvs_hConstraint> myTempConstraints;    ///< The list of identifiers of temporary constraints
+                               myConstraintMap; ///< The map between SketchPlugin and SolveSpace constraints
   std::map<boost::shared_ptr<ModelAPI_Attribute>, Slvs_hEntity>
-                                myEntityMap;        ///< The map between parameters of constraints and their equivalent SolveSpace entities
+                               myEntityAttrMap;     ///< The map between "attribute" parameters of constraints and their equivalent SolveSpace entities
+  std::map<FeaturePtr, Slvs_hEntity>
+                               myEntityFeatMap;     ///< The map between "feature" parameters of constraints and their equivalent SolveSpace entities
+
+  // Conincident items
+  std::vector< std::set<Slvs_hEntity> >
+                               myCoincidentPoints; ///< Stores the lists of identifiers of coincident points (to avoid unnecessary coincidence constraints)
+  std::set< boost::shared_ptr<SketchPlugin_Constraint> >
+                               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
 };
 
 #endif