Salome HOME
Fix incorrect processing of the copied entities after the "Multi" constraint has...
[modules/shaper.git] / src / SketchSolver / PlaneGCSSolver / PlaneGCSSolver_Solver.h
index c3b4b61104516a39e0ca8b617285d0a87b7606f2..19faa221b7571eb92d5306897b3d23f385fc9283 100644 (file)
@@ -7,18 +7,24 @@
 #ifndef PlaneGCSSolver_Solver_H_
 #define PlaneGCSSolver_Solver_H_
 
-#include <SketchSolver_ISolver.h>
-#include <SketchSolver_IConstraintWrapper.h>
 #include <PlaneGCSSolver_Defs.h>
+#include <PlaneGCSSolver_ConstraintWrapper.h>
 
 #include <GCS.h>
 
-/**
- * The main class that performs the high-level operations for connection to the PlaneGCS.
- */
-class PlaneGCSSolver_Solver : public SketchSolver_ISolver
+/// \brief The main class that performs the high-level operations for connection to the PlaneGCS.
+class PlaneGCSSolver_Solver
 {
 public:
+  /// The result of constraints solution
+  enum SolveStatus {
+    STATUS_OK,
+    STATUS_INCONSISTENT,
+    STATUS_EMPTYSET,
+    STATUS_FAILED, // set if no one other status is applicable
+    STATUS_UNKNOWN // set for newly created groups
+  };
+
   PlaneGCSSolver_Solver();
   ~PlaneGCSSolver_Solver();
 
@@ -26,66 +32,58 @@ public:
   void clear();
 
   /// \brief Add constraint to the system of equations
-  void addConstraint(GCSConstraintPtr theConstraint,
-                     const SketchSolver_ConstraintType theType);
+  void addConstraint(GCSConstraintPtr theConstraint);
 
   /// \brief Remove constraint from the system of equations
-  void removeConstraint(GCSConstraintPtr theConstraint);
-
-  /// \brief Initialize list of unknowns
-  void setParameters(const GCS::VEC_pD& theParams)
-  { myParameters = theParams; }
+  void removeConstraint(ConstraintID theID);
 
-  /// \brief Set list of IDs of tangent constraints
-  ///
-  /// Workaround to avoid incorrect report about redundant constraints
-  /// if an arc is already smoothly connected to a line.
-  void setTangent(const GCS::SET_I& theTangentIDs)
-  { myTangent = theTangentIDs; }
+  /// \brief Initialize memory for new solver's parameter
+  double* createParameter();
+  /// \brief Add parameters created elsewhere
+  void addParameters(const GCS::SET_pD& theParams);
+  /// \brief Release memory occupied by parameters
+  void removeParameters(const GCS::SET_pD& theParams);
 
-  /** \brief Solve the set of equations
-   *  \return identifier whether solution succeeded
-   */
-  virtual SketchSolver_SolveStatus solve();
+  /// \brief Preliminary initialization of solver (useful for moving a feature).
+  ///        When called, the solve() method does not reinitialize a set of constraints.
+  void initialize();
 
-  /// \brief Prepare for solving. Store initial values of parameters for undo
-  virtual void prepare()
-  { /* do nothing */ }
+  /// \brief Solve the set of equations
+  /// \return identifier whether solution succeeded
+  SolveStatus solve();
 
   /// \brief Revert solution to initial values
-  virtual void undo();
+  void undo();
 
   /// \brief Check the constraint is conflicted with others
-  virtual bool isConflicting(const ConstraintID& theConstraint) const;
+  bool isConflicting(const ConstraintID& theConstraint) const;
+
+  /// \brief Check conflicting/redundant constraints and DoF
+  void diagnose();
 
   /// \brief Degrees of freedom
-  virtual int dof() const;
+  int dof();
 
 private:
   void collectConflicting();
 
-  /// \brief Remove constraint from the system of equations
-  void removeConstraint(GCS::Constraint* theConstraint);
-
-  /// \brief Remove redundant tangent constraints and try to solve the system again
-  GCS::SolveStatus solveWithoutTangent();
-
-  /// \brief Check the entities under the tangent constraint are smoothly connected
-  bool isTangentTruth(int theTagID) const;
-  /// \brief Check the entities under the tangent constraint are smoothly connected
-  bool isTangentTruth(GCS::Constraint* theTangent) const;
-
 private:
-  typedef std::map<GCS::Constraint*, SketchSolver_ConstraintType> ConstraintMap;
+  typedef std::map<ConstraintID, std::set<GCSConstraintPtr> > ConstraintMap;
 
   GCS::VEC_pD                  myParameters;     ///< list of unknowns
-  ConstraintMap                myConstraints;    ///< list of constraints already processed by the system
+  ConstraintMap                myConstraints;    ///< list of constraints
+
   std::shared_ptr<GCS::System> myEquationSystem; ///< set of equations for solving in FreeGCS
+  bool                         myDiagnoseBeforeSolve; ///< is the diagnostic necessary
+  bool                         myInitilized;     ///< is the system already initialized
 
   GCS::SET_I                   myConflictingIDs; ///< list of IDs of conflicting constraints
-  bool                         myConfCollected;  ///< specifies the conflicting constraints are already collected
+  /// specifies the conflicting constraints are already collected
+  bool                         myConfCollected;
 
-  GCS::SET_I                   myTangent;        ///< list of tangent IDs to check incorrect redundant constraints
+  int                          myDOF;            ///< degrees of freedom
 };
 
+typedef std::shared_ptr<PlaneGCSSolver_Solver> SolverPtr;
+
 #endif