Salome HOME
SketchSolver Refactoring: Eliminate SolveSpace as a sketch solver.
[modules/shaper.git] / src / SketchSolver / PlaneGCSSolver / PlaneGCSSolver_Storage.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:    PlaneGCSSolver_Storage.h
4 // Created: 14 Dec 2015
5 // Author:  Artem ZHIDKOV
6
7 #ifndef PlaneGCSSolver_Storage_H_
8 #define PlaneGCSSolver_Storage_H_
9
10 #include <PlaneGCSSolver_Defs.h>
11
12 #include <SketchSolver.h>
13 #include <SketchSolver_Storage.h>
14 #include <SketchSolver_ISolver.h>
15
16 class PlaneGCSSolver_EntityBuilder;
17
18 /** \class   PlaneGCSSolver_Storage
19  *  \ingroup Plugins
20  *  \brief   Contains all necessary data in PlaneGCS format to solve a single group of constraints
21  */
22 class PlaneGCSSolver_Storage : public SketchSolver_Storage
23 {
24 public:
25   PlaneGCSSolver_Storage(const SolverPtr& theSolver);
26
27 // =============   Inherited from SketchSolver_Storage   =============
28
29   /// \brief Change mapping between constraint from SketchPlugin and
30   ///        a constraint applicable for corresponding solver.
31   /// \param theConstraint       [in]   original SketchPlugin constraint
32   /// \param theSolverConstraint [in]   solver's constraint
33   virtual void addConstraint(ConstraintPtr        theConstraint,
34                              ConstraintWrapperPtr theSolverConstraint) override;
35
36   /// \brief Add list of temporary constraints which will be destroyed
37   ///        after the next solving of the set of constraints.
38   /// \param theSolverConstraint [in]  solver's constraint
39   virtual void addTemporaryConstraint(const ConstraintWrapperPtr& theSolverConstraint) override;
40
41
42   /// \brief Convert feature to the form applicable for specific solver and map it
43   /// \param theFeature [in]  feature to convert
44   /// \param theForce   [in]  forced feature creation
45   /// \return \c true if the feature has been created or updated
46   virtual bool update(FeaturePtr theFeature, bool theForce = false) override;
47
48   /// \brief Convert attribute to the form applicable for specific solver and map it
49   /// \param theAttribute [in]  attribute to convert
50   /// \param theForce     [in]  forced feature creation
51   /// \return \c true if the attribute has been created or updated
52   virtual bool update(AttributePtr theAttribute, bool theForce = false) override;
53
54
55   /// \brief Removes constraint from the storage
56   /// \return \c true if the constraint and all its parameters are removed successfully
57   virtual bool removeConstraint(ConstraintPtr theConstraint) override;
58
59   /// \brief Update SketchPlugin features after resolving constraints
60   virtual void refresh() const override;
61
62   /// \brief Initialize solver by constraints, entities and parameters
63   virtual void initializeSolver();
64
65   /// \brief Initialize memory for new solver's parameter
66   double* createParameter();
67   /// \brief Release memory occupied by parameters
68   void removeParameters(const GCS::SET_pD& theParams);
69
70   /// \brief Remove all features became invalid
71   virtual void removeInvalidEntities() override;
72
73 private:
74   /// \brief Verifies the constraint should not be added into the solver
75   ///
76   /// This is a workaround method to avoid some kinds of conflicting constraints:
77   ///   * symmetric of two points placed on the mirror line (do not add perpendicular constraint)
78   bool isRedundant(GCSConstraintPtr theCheckedConstraint,
79                    ConstraintWrapperPtr theParentConstraint,
80                    std::list<std::set<double*> >& theCoincidentPoints) const;
81
82   /// \brief Convert feature using specified builder.
83   EntityWrapperPtr createFeature(const FeaturePtr&             theFeature,
84                                  PlaneGCSSolver_EntityBuilder* theBuilder);
85
86   /// \brief Convert attribute using specified builder.
87   EntityWrapperPtr createAttribute(const AttributePtr&           theAttribute,
88                                    PlaneGCSSolver_EntityBuilder* theBuilder);
89
90 private:
91   GCS::VEC_pD  myParameters;         ///< list of parameters
92   ConstraintID myConstraintLastID;   ///< identifier of last added constraint
93
94   /// additional constraints for correct processing of the arcs
95   std::map<EntityWrapperPtr, ConstraintWrapperPtr> myArcConstraintMap;
96
97   /// list of removed constraints to notify solver
98   std::list<GCSConstraintPtr> myRemovedConstraints;
99 };
100
101 #endif