Salome HOME
Issue #1664: workaround to avoid conflicting constraints when tangent two smoothly...
[modules/shaper.git] / src / SketchSolver / PlaneGCSSolver / PlaneGCSSolver_Solver.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:    PlaneGCSSolver_Solver.h
4 // Created: 14 Dec 2014
5 // Author:  Artem ZHIDKOV
6
7 #ifndef PlaneGCSSolver_Solver_H_
8 #define PlaneGCSSolver_Solver_H_
9
10 #include <SketchSolver_ISolver.h>
11 #include <PlaneGCSSolver_Defs.h>
12
13 #include <GCS.h>
14
15 /**
16  * The main class that performs the high-level operations for connection to the PlaneGCS.
17  */
18 class PlaneGCSSolver_Solver : public SketchSolver_ISolver
19 {
20 public:
21   PlaneGCSSolver_Solver() {}
22   ~PlaneGCSSolver_Solver();
23
24   /// \brief Clear system of equations
25   void clear();
26
27   /// \brief Add constraint to the system of equations
28   void addConstraint(GCSConstraintPtr theConstraint);
29
30   /// \brief Remove constraint from the system of equations
31   void removeConstraint(GCSConstraintPtr theConstraint);
32
33   /// \brief Initialize list of unknowns
34   void setParameters(const GCS::VEC_pD& theParams)
35   { myParameters = theParams; }
36
37   /// \brief Set list of IDs of tangent constraints
38   ///
39   /// Workaround to avoid incorrect report about redundant constraints
40   /// if an arc is already smoothly connected to a line.
41   void setTangent(const GCS::SET_I& theTangentIDs)
42   { myTangent = theTangentIDs; }
43
44   /** \brief Solve the set of equations
45    *  \return identifier whether solution succeeded
46    */
47   virtual SketchSolver_SolveStatus solve();
48
49   /// \brief Prepare for solving. Store initial values of parameters for undo
50   virtual void prepare()
51   { /* do nothing */ }
52
53   /// \brief Revert solution to initial values
54   virtual void undo();
55
56   /// \brief Check the constraint is conflicted with others
57   virtual bool isConflicting(const ConstraintID& theConstraint) const;
58
59   /// \brief Degrees of freedom
60   virtual int dof() const;
61
62 private:
63   void collectConflicting();
64
65   /// \brief Remove constraint from the system of equations
66   void removeConstraint(GCS::Constraint* theConstraint);
67
68   /// \brief Remove redundant tangent constraints and try to solve the system again
69   SketchSolver_SolveStatus solveWithoutTangent();
70
71   /// \brief Check the entities under the tangent constraint are smoothly connected
72   bool isTangentTruth(int theTagID) const;
73
74 private:
75   GCS::VEC_pD                myParameters;     ///< list of unknowns
76   std::set<GCS::Constraint*> myConstraints;    ///< list of constraints already processed by the system
77   GCS::System                myEquationSystem; ///< set of equations for solving in FreeGCS
78
79   GCS::VEC_I                 myConflictingIDs; ///< list of IDs of conflicting constraints
80   bool                       myConfCollected;  ///< specifies the conflicting constraints are already collected
81
82   GCS::SET_I                 myTangent;        ///< list of tangent IDs to check incorrect redundant constraints
83 };
84
85 #endif