X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchSolver%2FSketchSolver_Constraint.h;h=e4081174610fa7843e0bb87da9f2487a7cbf4cf6;hb=c02fae5493cc6d56c9a1db3bdcf6d872f88fea07;hp=3f547d8d8a8a2ccd294f80bd8b1e74f65085d060;hpb=2c4f7de06341fa7af89f47ba405fe188f13e3600;p=modules%2Fshaper.git diff --git a/src/SketchSolver/SketchSolver_Constraint.h b/src/SketchSolver/SketchSolver_Constraint.h index 3f547d8d8..e40811746 100644 --- a/src/SketchSolver/SketchSolver_Constraint.h +++ b/src/SketchSolver/SketchSolver_Constraint.h @@ -1,45 +1,115 @@ -// File: SketchSolver_Constraint.h -// Created: 27 May 2014 -// Author: Artem ZHIDKOV +// Copyright (C) 2014-2019 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// #ifndef SketchSolver_Constraint_H_ #define SketchSolver_Constraint_H_ -#include "SketchSolver.h" +#include +#include #include +#include +#include + #include #include /** \class SketchSolver_Constraint - * \ingroup DataModel - * \brief Obtain information about SketchPlugin's constraint + * \ingroup Plugins + * \brief Converts SketchPlugin constraint to the constraint applicable for solver */ class SketchSolver_Constraint { +protected: + /// Default constructor + SketchSolver_Constraint() + : myType(CONSTRAINT_UNKNOWN) + {} + public: - SketchSolver_Constraint(); - SketchSolver_Constraint(boost::shared_ptr theConstraint); - - /** \brief Compute constraint type according to SolveSpace identifiers - * and verify that constraint parameters are correct - * \param[in] theConstraint constraint which type should be determined - * \return identifier of constraint type or SLVS_C_UNKNOWN if the type is wrong - */ - const int& getType(boost::shared_ptr theConstraint); - /// \brief Returns the type of myConstraint member - inline const int& getType() const + /// Constructor based on SketchPlugin constraint + SketchSolver_Constraint(ConstraintPtr theConstraint); + + virtual ~SketchSolver_Constraint() {} + + /// \brief Initializes parameters and start constraint creation + /// \param theStorage [in] storage where to place new constraint + /// \param theEventsBlocked [in] all events from this constraint should be blocked + void process(StoragePtr theStorage, bool theEvensBlocked); + + /// \brief Notify this object about the feature is changed somewhere + virtual void notify(const FeaturePtr& theFeature, PlaneGCSSolver_Update* theUpdater) {} + + /// \brief Update constraint + virtual void update(); + + /// \brief Tries to remove constraint + /// \return \c false, if current constraint contains another SketchPlugin constraints + /// (like for multiple coincidence) + virtual bool remove(); + + /// \brief Block or unblock events from this constraint + virtual void blockEvents(bool isBlocked); + + /// \brief Obtain a type of SketchPlugin constraint + static SketchSolver_ConstraintType TYPE(ConstraintPtr theConstraint); + + /// \brief Returns the type of constraint + virtual SketchSolver_ConstraintType getType() const { return myType; } - /// \brief Returns list of attributes names in the correct order required by SolveSpace - inline const std::vector& getAttributes() const - { return myAttributesList; } + /// \brief Shows error message + const std::string& error() const + { return myErrorMsg; } + +protected: + /// \brief Converts SketchPlugin constraint to a list of solver's constraints + virtual void process(); + + /// \brief Generate list of attributes of constraint in order useful for constraints + /// \param[out] theValue numerical characteristic of constraint (e.g. distance) + /// \param[out] theAttributes list of attributes to be filled + virtual void getAttributes(EntityWrapperPtr& theValue, + std::vector& theAttributes); + + /// \brief This method is used in derived objects to check consistency of constraint. + /// E.g. the distance between line and point may be signed. + virtual void adjustConstraint() + {} -private: - boost::shared_ptr myConstraint; - int myType; - std::vector myAttributesList; + /// \brief Removes last error + void cleanErrorMsg() + { myErrorMsg.clear(); } + +protected: + ConstraintPtr myBaseConstraint; ///< base SketchPlugin constraint + ConstraintWrapperPtr mySolverConstraint; ///< wrapper for PlaneGCS constraint + + /// storage, which contains all information about entities and constraints + StoragePtr myStorage; + SketchSolver_ConstraintType myType; ///< type of constraint + std::list myAttributes; ///< attributes of constraint + + std::string myErrorMsg; ///< error message }; +typedef std::shared_ptr SolverConstraintPtr; + #endif