Salome HOME
Fix for the issue #2753 : error when dump/load script
[modules/shaper.git] / src / SketchSolver / PlaneGCSSolver / PlaneGCSSolver_Storage.h
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #ifndef PlaneGCSSolver_Storage_H_
22 #define PlaneGCSSolver_Storage_H_
23
24 #include <PlaneGCSSolver_Defs.h>
25 #include <SketchSolver_Storage.h>
26
27 class PlaneGCSSolver_EntityBuilder;
28
29 /** \class   PlaneGCSSolver_Storage
30  *  \ingroup Plugins
31  *  \brief   Contains all necessary data in PlaneGCS format to solve a single group of constraints
32  */
33 class PlaneGCSSolver_Storage : public SketchSolver_Storage
34 {
35 public:
36   PlaneGCSSolver_Storage(const SolverPtr& theSolver);
37
38 // =============   Inherited from SketchSolver_Storage   =============
39
40   /// \brief Change mapping between constraint from SketchPlugin and
41   ///        a constraint applicable for corresponding solver.
42   /// \param theConstraint       [in]   original SketchPlugin constraint
43   /// \param theSolverConstraint [in]   solver's constraint
44   virtual void addConstraint(ConstraintPtr        theConstraint,
45                              ConstraintWrapperPtr theSolverConstraint);
46
47   /// \brief Add a movement constraint which will be destroyed
48   ///        after the next solving of the set of constraints.
49   /// \param theSolverConstraint [in]  solver's constraint
50   virtual void addMovementConstraint(const ConstraintWrapperPtr& theSolverConstraint);
51
52
53   /// \brief Convert feature to the form applicable for specific solver and map it
54   /// \param theFeature [in]  feature to convert
55   /// \param theForce   [in]  forced feature creation
56   /// \return \c true if the feature has been created or updated
57   virtual bool update(FeaturePtr theFeature, bool theForce = false);
58
59   /// \brief Convert attribute to the form applicable for specific solver and map it
60   /// \param theAttribute [in]  attribute to convert
61   /// \param theForce     [in]  forced feature creation
62   /// \return \c true if the attribute has been created or updated
63   virtual bool update(AttributePtr theAttribute, bool theForce = false);
64
65   /// \brief Make entity external
66   virtual void makeExternal(const EntityWrapperPtr& theEntity);
67   /// \brief Make entity non-external
68   virtual void makeNonExternal(const EntityWrapperPtr& theEntity);
69
70   /// \brief Removes constraint from the storage
71   /// \return \c true if the constraint and all its parameters are removed successfully
72   virtual bool removeConstraint(ConstraintPtr theConstraint);
73
74   /// \brief Verify, the sketch contains degenerated geometry
75   ///        after resolving the set of constraints
76   /// \return STATUS_OK if the geometry is valid, STATUS_DEGENERATED otherwise.
77   virtual PlaneGCSSolver_Solver::SolveStatus checkDegeneratedGeometry() const;
78
79   /// \brief Update SketchPlugin features after resolving constraints
80   virtual void refresh() const;
81
82   /// \brief Initialize memory for new solver's parameter
83   double* createParameter();
84   /// \brief Release memory occupied by parameters
85   void removeParameters(const GCS::SET_pD& theParams);
86
87   /// \brief Remove all features became invalid
88   virtual void removeInvalidEntities();
89
90   /// \brief Check the storage has constraints
91   virtual bool isEmpty() const
92   { return SketchSolver_Storage::isEmpty() && myArcConstraintMap.empty(); }
93
94 private:
95   /// \brief Convert feature using specified builder.
96   EntityWrapperPtr createFeature(const FeaturePtr&             theFeature,
97                                  PlaneGCSSolver_EntityBuilder* theBuilder);
98
99   /// \brief Convert attribute using specified builder.
100   EntityWrapperPtr createAttribute(const AttributePtr&           theAttribute,
101                                    PlaneGCSSolver_EntityBuilder* theBuilder);
102
103   void createArcConstraints(const EntityWrapperPtr& theArc);
104   void removeArcConstraints(const EntityWrapperPtr& theArc);
105
106 private:
107   ConstraintID myConstraintLastID;   ///< identifier of last added constraint
108
109   /// additional constraints for correct processing of the arcs
110   std::map<EntityWrapperPtr, ConstraintWrapperPtr> myArcConstraintMap;
111
112   /// list of removed constraints to notify solver
113   std::list<GCSConstraintPtr> myRemovedConstraints;
114 };
115
116 #endif