1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #ifndef SketchSolver_Constraint_H_
22 #define SketchSolver_Constraint_H_
24 #include <SketchSolver_Storage.h>
25 #include <PlaneGCSSolver_Update.h>
27 #include <SketchPlugin_Constraint.h>
29 #include <ModelAPI_AttributeDouble.h>
30 #include <ModelAPI_AttributeRefAttr.h>
35 /** \class SketchSolver_Constraint
37 * \brief Converts SketchPlugin constraint to the constraint applicable for solver
39 class SketchSolver_Constraint
42 /// Default constructor
43 SketchSolver_Constraint()
44 : myType(CONSTRAINT_UNKNOWN)
48 /// Constructor based on SketchPlugin constraint
49 SketchSolver_Constraint(ConstraintPtr theConstraint);
51 virtual ~SketchSolver_Constraint() {}
53 /// \brief Initializes parameters and start constraint creation
54 /// \param theStorage [in] storage where to place new constraint
55 /// \param theEventsBlocked [in] all events from this constraint should be blocked
56 void process(StoragePtr theStorage, bool theEvensBlocked);
58 /// \brief Notify this object about the feature is changed somewhere
59 virtual void notify(const FeaturePtr& theFeature, PlaneGCSSolver_Update* theUpdater) {}
61 /// \brief Update constraint
62 virtual void update();
64 /// \brief Tries to remove constraint
65 /// \return \c false, if current constraint contains another SketchPlugin constraints
66 /// (like for multiple coincidence)
67 virtual bool remove();
69 /// \brief Block or unblock events from this constraint
70 virtual void blockEvents(bool isBlocked);
72 /// \brief Obtain a type of SketchPlugin constraint
73 static SketchSolver_ConstraintType TYPE(ConstraintPtr theConstraint);
75 /// \brief Returns the type of constraint
76 virtual SketchSolver_ConstraintType getType() const
79 /// \brief Shows error message
80 const std::string& error() const
81 { return myErrorMsg; }
84 /// \brief Converts SketchPlugin constraint to a list of solver's constraints
85 virtual void process();
87 /// \brief Generate list of attributes of constraint in order useful for constraints
88 /// \param[out] theValue numerical characteristic of constraint (e.g. distance)
89 /// \param[out] theAttributes list of attributes to be filled
90 virtual void getAttributes(EntityWrapperPtr& theValue,
91 std::vector<EntityWrapperPtr>& theAttributes);
93 /// \brief This method is used in derived objects to check consistency of constraint.
94 /// E.g. the distance between line and point may be signed.
95 virtual void adjustConstraint()
98 /// \brief Removes last error
100 { myErrorMsg.clear(); }
103 ConstraintPtr myBaseConstraint; ///< base SketchPlugin constraint
104 ConstraintWrapperPtr mySolverConstraint; ///< wrapper for PlaneGCS constraint
106 /// storage, which contains all information about entities and constraints
107 StoragePtr myStorage;
108 SketchSolver_ConstraintType myType; ///< type of constraint
109 std::list<EntityWrapperPtr> myAttributes; ///< attributes of constraint
111 std::string myErrorMsg; ///< error message
114 typedef std::shared_ptr<SketchSolver_Constraint> SolverConstraintPtr;