Salome HOME
updated copyright message
[modules/shaper.git] / src / SketchSolver / SketchSolver_Group.h
index e75accd08dd53a53b0c370b13ec4dd804c0e9ec2..8422b32ffddabd7a359755df30d6a201853ceb61 100644 (file)
@@ -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 <SketchSolver_Constraint.h>
 #include <SketchSolver_Storage.h>
-#include <SketchSolver_FeatureStorage.h>
-#include <SketchSolver_Solver.h>
+
+#include <PlaneGCSSolver_Solver.h>
 
 #include <SketchPlugin_Constraint.h>
-#include <ModelAPI_Data.h>
-#include <ModelAPI_Feature.h>
-#include <ModelAPI_AttributeRefList.h>
 
 #include <memory>
-#include <list>
 #include <map>
-#include <vector>
-#include <set>
+
+class GeomAPI_Dir;
+class GeomAPI_Pnt;
+class GeomAPI_Pnt2d;
 
 typedef std::map<ConstraintPtr, SolverConstraintPtr> 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<ModelAPI_CompositeFeature> theWorkplane);
-
-  ~SketchSolver_Group();
-
-  /// \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;
-  }
+  SketchSolver_Group(const CompositeFeaturePtr& theWorkplane);
 
-  /// \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
@@ -70,109 +63,107 @@ class SketchSolver_Group
     return mySketch->data() && mySketch->data()->isValid();
   }
 
-  /// \brief Verifies the constraint is complex, i.e. it needs another constraints to be created before
-  static bool isComplexConstraint(FeaturePtr theConstraint);
-
   /** \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
    */
   bool changeConstraint(std::shared_ptr<SketchPlugin_Constraint> theConstraint);
 
+  /** \brief Updates the sketch feature
+   */
+  bool updateSketch(CompositeFeaturePtr theSketch);
+
   /** \brief Updates the data corresponding the specified feature
    *  \param[in] theFeature the feature to be updated
    */
-  bool updateFeature(std::shared_ptr<SketchPlugin_Feature> theFeature);
+  bool updateFeature(FeaturePtr theFeature);
 
   /** \brief Updates the data corresponding the specified feature moved in GUI.
-   *         Additional Fixed constraints are created.
+   *         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
    */
-  void moveFeature(std::shared_ptr<SketchPlugin_Feature> theFeature);
-
-  /** \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
+  bool moveFeature(FeaturePtr theFeature,
+                   const std::shared_ptr<GeomAPI_Pnt2d>& theFrom,
+                   const std::shared_ptr<GeomAPI_Pnt2d>& 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 isInteract(std::shared_ptr<SketchPlugin_Feature> theFeature) const;
-
-  /** \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
-   */
-  bool isBaseWorkplane(CompositeFeaturePtr theWorkplane) const;
+  bool movePoint(AttributePtr thePointOrArray,
+                 const int thePointIndex,
+                 const std::shared_ptr<GeomAPI_Pnt2d>& theFrom,
+                 const std::shared_ptr<GeomAPI_Pnt2d>& theTo);
 
   /// Returns the current workplane
-  std::shared_ptr<ModelAPI_CompositeFeature> 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 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<SketchSolver_Group*>& 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();
 
-protected:
+  /// \brief Find the list of features, which are not fully constrained.
+  void underconstrainedFeatures(std::set<ObjectPtr>& 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 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 Apply temporary rigid constraints for the list of features
-  void fixFeaturesList(AttributeRefListPtr theList);
-
-  /// \brief Append given constraint to th group of temporary constraints
+  /// \brief Append given constraint to the group of temporary constraints
   void setTemporary(SolverConstraintPtr theConstraint);
 
-  /// \brief Verifies is the feature valid
-  bool checkFeatureValidity(FeaturePtr theFeature);
+  /// \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<GeomAPI_Pnt> mySketchOrigin;
+  std::shared_ptr<GeomAPI_Dir> mySketchNormal;
+  std::shared_ptr<GeomAPI_Dir> mySketchXDir;
+
   ConstraintConstraintMap myConstraints; ///< List of constraints
   std::set<SolverConstraintPtr> 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
+
+  /// Result of previous solution of the set of constraints
+  PlaneGCSSolver_Solver::SolveStatus myPrevResult;
+  std::set<ObjectPtr>      myConflictingConstraints; ///< List of conflicting constraints
 
-  SketchSolver_Solver myConstrSolver;  ///< Solver for set of equations obtained by constraints
+  int  myDOF; ///< degrees of freedom of the current sketch
 
-  bool myPrevSolved; ///< Indicates that previous solving was done correctly
+  bool myIsEventsBlocked; ///< shows the events are blocked for this group
+
+  int myMultiConstraintUpdateStack; ///< depth of the stack updating "Multi" constraints
 };
 
+typedef std::shared_ptr<SketchSolver_Group> SketchGroupPtr;
+
 #endif