From: azv Date: Mon, 12 May 2014 07:02:51 +0000 (+0400) Subject: Added class for the distance constraint X-Git-Tag: V_0.2~64^2~13^2~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=7ee1eff7098db3bd08f072034d4926524950f230;p=modules%2Fshaper.git Added class for the distance constraint --- diff --git a/src/SketchPlugin/CMakeLists.txt b/src/SketchPlugin/CMakeLists.txt index 15ec42e10..6613ff57c 100644 --- a/src/SketchPlugin/CMakeLists.txt +++ b/src/SketchPlugin/CMakeLists.txt @@ -7,6 +7,8 @@ SET(PROJECT_HEADERS SketchPlugin_Sketch.h SketchPlugin_Line.h SketchPlugin_Point.h + SketchPlugin_Constraint.h + SketchPlugin_ConstraintDistance.h ) SET(PROJECT_SOURCES @@ -15,6 +17,8 @@ SET(PROJECT_SOURCES SketchPlugin_Sketch.cpp SketchPlugin_Line.cpp SketchPlugin_Point.cpp + SketchPlugin_Constraint.cpp + SketchPlugin_ConstraintDistance.cpp ) SET(PROJECT_LIBRARIES diff --git a/src/SketchPlugin/SketchPlugin_Constraint.cpp b/src/SketchPlugin/SketchPlugin_Constraint.cpp new file mode 100644 index 000000000..810f0c9ec --- /dev/null +++ b/src/SketchPlugin/SketchPlugin_Constraint.cpp @@ -0,0 +1,15 @@ +// File: SketchPlugin_Constraint.cpp +// Created: 08 May 2014 +// Author: Artem ZHIDKOV + +#include "SketchPlugin_Constraint.h" + +void SketchPlugin_Constraint::addConstrainedObject( + const boost::shared_ptr& theReference) +{ +} + +void SketchPlugin_Constraint::addConstrainedObject( + const boost::shared_ptr& theReference) +{ +} diff --git a/src/SketchPlugin/SketchPlugin_Constraint.h b/src/SketchPlugin/SketchPlugin_Constraint.h new file mode 100644 index 000000000..031587be0 --- /dev/null +++ b/src/SketchPlugin/SketchPlugin_Constraint.h @@ -0,0 +1,80 @@ +// File: SketchPlugin_Constraint.h +// Created: 08 May 2014 +// Author: Artem ZHIDKOV + +#ifndef SketchPlugin_Constraint_HeaderFile +#define SketchPlugin_Constraint_HeaderFile + +#include "SketchPlugin.h" +#include "SketchPlugin_Feature.h" +#include +#include +#include + +/* Description: + * Each constraint uses a set of parameters. In the SolveSpace library + * these parameters are named "valA", "ptA", "ptB", "entityA", "entityB". + * The "ptA" and "ptB" parameters represents a point in the constraint. + * The "entityA" and "entityB" represents any other object (and a point too). + * And the "valA" represents a real value. + * + * The attributes below are named corresponding to the SolveSpace, + * some of them may be unused. The list of used attributes is defined + * inside the certain constraint. + */ +/// The value parameter for the constraint +const std::string CONSTRAINT_ATTR_VALUE("ConstraintValueA"); +/// First point for the constraint +const std::string CONSTRAINT_ATTR_POINT_A("ConstraintPointA"); +/// Second point for the constraint +const std::string CONSTRAINT_ATTR_POINT_B("ConstraintPointB"); +/// First entity for the constraint +const std::string CONSTRAINT_ATTR_ENTITY_A("ConstraintEntityA"); +/// Second entity for the constraint +const std::string CONSTRAINT_ATTR_ENTITY_B("ConstraintEntityB"); + + +/** \class SketchPlugin_Constraint + * \ingroup DataModel + * \brief Feature for creation of a new constraint between other features. + */ +class SketchPlugin_Constraint: public SketchPlugin_Feature +{ +public: + /// \brief Returns the kind of a feature + SKETCHPLUGIN_EXPORT virtual const std::string& getKind() + {static std::string MY_KIND = "SketchConstraint"; return MY_KIND;} + + /// \brief Returns to which group in the document must be added feature + SKETCHPLUGIN_EXPORT virtual const std::string& getGroup() + {static std::string MY_GROUP = "Sketch"; return MY_GROUP;} + + /** \brief Adds sub-feature of the higher level feature (sub-element of the sketch) + * \param theFeature sub-feature + */ + SKETCHPLUGIN_EXPORT virtual const void addSub( + const boost::shared_ptr& theFeature) {} + + /** \brief Adds an object of the constraint. The object added by the reference. + * \param theReference reference to the feature, which will be constrained + */ + SKETCHPLUGIN_EXPORT virtual void addConstrainedObject( + const boost::shared_ptr& theReference); + + /** \brief Adds an object of the constraint. The object added by the reference to its attribute. + * \param theReference reference to the attribute feature, which will be constrained + */ + SKETCHPLUGIN_EXPORT virtual void addConstrainedObject( + const boost::shared_ptr& theReference); + + /// \brief Use plugin manager for features creation + SketchPlugin_Constraint() {} + +protected: + /** \brief Returns the list of attributes for the certain type of constraint. + * \return names of attributes + */ + virtual const std::list& getAttributesList() const = 0; +}; + +#endif diff --git a/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp b/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp new file mode 100644 index 000000000..13ef22dd8 --- /dev/null +++ b/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp @@ -0,0 +1,124 @@ +// File: SketchPlugin_ConstraintDistance.cpp +// Created: 08 May 2014 +// Author: Artem ZHIDKOV + +#include "SketchPlugin_ConstraintDistance.h" + +#include +#include +#include + +SketchPlugin_ConstraintDistance::SketchPlugin_ConstraintDistance() +{ + myAttrList.push_back(CONSTRAINT_ATTR_DISTANCE); +} + +void SketchPlugin_ConstraintDistance::execute() +{ +} + + +void SketchPlugin_ConstraintDistance::setAttributes( + const double theDistance, + const boost::shared_ptr theEntityA, + const boost::shared_ptr theEntityB) +{ + // Assign the value of the distance + data()->addAttribute(CONSTRAINT_ATTR_DISTANCE, ModelAPI_AttributeDouble::type()); + boost::dynamic_pointer_cast( + data()->attribute(CONSTRAINT_ATTR_DISTANCE))->setValue(theDistance); + + // Assign parameters of the constraint + std::string aPoints[2] = {CONSTRAINT_ATTR_POINT_A, CONSTRAINT_ATTR_POINT_B}; + std::string anEntities[2] = {CONSTRAINT_ATTR_ENTITY_A, CONSTRAINT_ATTR_ENTITY_B}; + int aCurPt = 0; + int aCurEnt = 0; + std::string aCurAttr; + // add entityA depending on its type + if (theEntityA->getKind() == SketchPlugin_Point().getKind()) + aCurAttr = aPoints[aCurPt++]; + else + aCurAttr = anEntities[aCurEnt++]; + myAttrList.push_back(aCurAttr); + data()->addAttribute(aCurAttr, ModelAPI_AttributeReference::type()); + boost::dynamic_pointer_cast( + data()->attribute(aCurAttr))->setValue(theEntityA); + // add entityB depending on its type + if (theEntityB->getKind() == SketchPlugin_Point().getKind()) + aCurAttr = aPoints[aCurPt++]; + else + aCurAttr = anEntities[aCurEnt++]; + myAttrList.push_back(aCurAttr); + data()->addAttribute(aCurAttr, ModelAPI_AttributeReference::type()); + boost::dynamic_pointer_cast( + data()->attribute(aCurAttr))->setValue(theEntityB); +} + +void SketchPlugin_ConstraintDistance::setAttributes( + const double theDistance, + const boost::shared_ptr thePoint, + const boost::shared_ptr theEntity) +{ + // Assign the value of the distance + data()->addAttribute(CONSTRAINT_ATTR_DISTANCE, ModelAPI_AttributeDouble::type()); + boost::dynamic_pointer_cast( + data()->attribute(CONSTRAINT_ATTR_DISTANCE))->setValue(theDistance); + + // Assign reference to the first point + myAttrList.push_back(CONSTRAINT_ATTR_POINT_A); + data()->addAttribute(CONSTRAINT_ATTR_POINT_A, ModelAPI_AttributeRefAttr::type()); + boost::dynamic_pointer_cast( + data()->attribute(CONSTRAINT_ATTR_POINT_A))->setValue(thePoint); + + // Assign reference to the entity + std::string aCurAttr; + if (theEntity->getKind() == SketchPlugin_Point().getKind()) + aCurAttr = CONSTRAINT_ATTR_POINT_B; + else + aCurAttr = CONSTRAINT_ATTR_ENTITY_A; + myAttrList.push_back(aCurAttr); + data()->addAttribute(aCurAttr, ModelAPI_AttributeReference::type()); + boost::dynamic_pointer_cast( + data()->attribute(aCurAttr))->setValue(theEntity); +} + +void SketchPlugin_ConstraintDistance::setAttributes( + const double theDistance, + const boost::shared_ptr thePointA, + const boost::shared_ptr thePointB) +{ + // Assign the value of the distance + data()->addAttribute(CONSTRAINT_ATTR_DISTANCE, ModelAPI_AttributeDouble::type()); + boost::dynamic_pointer_cast( + data()->attribute(CONSTRAINT_ATTR_DISTANCE))->setValue(theDistance); + + // Assign reference to the first point + myAttrList.push_back(CONSTRAINT_ATTR_POINT_A); + data()->addAttribute(CONSTRAINT_ATTR_POINT_A, ModelAPI_AttributeRefAttr::type()); + boost::dynamic_pointer_cast( + data()->attribute(CONSTRAINT_ATTR_POINT_A))->setValue(thePointA); + + // Assign reference to the second point + myAttrList.push_back(CONSTRAINT_ATTR_POINT_B); + data()->addAttribute(CONSTRAINT_ATTR_POINT_B, ModelAPI_AttributeRefAttr::type()); + boost::dynamic_pointer_cast( + data()->attribute(CONSTRAINT_ATTR_POINT_B))->setValue(thePointB); +} + +void SketchPlugin_ConstraintDistance::setAttributes( + const double theRadius, + const boost::shared_ptr theCircle) +{ + /// \todo Need to be implemented +} + +void SketchPlugin_ConstraintDistance::setAttributes( + const double theDistance, + const boost::shared_ptr thePointA, + const boost::shared_ptr thePointB, + const boost::shared_ptr theEntity) +{ + /// \todo Need to be implemented. Possibly need to add points by their attributes +} + + diff --git a/src/SketchPlugin/SketchPlugin_ConstraintDistance.h b/src/SketchPlugin/SketchPlugin_ConstraintDistance.h new file mode 100644 index 000000000..0199e4ef3 --- /dev/null +++ b/src/SketchPlugin/SketchPlugin_ConstraintDistance.h @@ -0,0 +1,132 @@ +// File: SketchPlugin_ConstraintDistance.h +// Created: 08 May 2014 +// Author: Artem ZHIDKOV + +#ifndef SketchPlugin_ConstraintDistance_HeaderFile +#define SketchPlugin_ConstraintDistance_HeaderFile + +#include "SketchPlugin.h" +#include "SketchPlugin_Constraint.h" +#include + +/// The distance value +const std::string CONSTRAINT_ATTR_DISTANCE(CONSTRAINT_ATTR_VALUE); + + +/** \class SketchPlugin_ConstraintDistance + * \ingroup DataModel + * \brief Feature for creation of a new constraint which fixes the distance + * between two other features. + * + * There are allowed several kinds of distances: + * \li The next constraints use "valA", "ptA" and "entityA" parameters: + * point-point, point-line, point-plane, point-face; + * \li The distance between two points projected on a line (or vector) + * uses "valA", "ptA", "ptB", "entityA"; + * \li The diameter of a circle is defined by "valA" and "entityA"; + * \li The angle between two lines (or vectors) uses "valA", "entityA", "entityB". + * + * The default list of attributes contains only CONSTRAINT_ATTR_DISTANCE. + * + * \remark As far as the constraint may have different attributes, + * it is strongly recommended to use setAttibutes() methods + * instead of direct intialization of the attributes + */ +class SketchPlugin_ConstraintDistance: public SketchPlugin_Constraint +{ +public: + /// \brief Returns the kind of a feature + SKETCHPLUGIN_EXPORT virtual const std::string& getKind() + {static std::string MY_KIND = "SketchConstraintDistance"; return MY_KIND;} + + /// \brief Returns to which group in the document must be added feature + SKETCHPLUGIN_EXPORT virtual const std::string& getGroup() + {static std::string MY_GROUP = "Sketch"; return MY_GROUP;} + + /// \brief Creates a new part document if needed + SKETCHPLUGIN_EXPORT virtual void execute(); + + /** \brief Request for initialization of data model of the feature: adding all attributes + * + * The setAttributes() methods should be used instead. + */ + SKETCHPLUGIN_EXPORT virtual void initAttributes() + { /* do nothing */ } + + /// \brief Use plugin manager for features creation + SketchPlugin_ConstraintDistance(); + + /** \brief Initializes the attributes of the constraint + * + * Defines the distance between a point and another entity, + * or defines the angle between two vectors. + * + * \param[in] theDistance distance (or angle) between two entities + * \param[in] theEntityA first parameter of the constraint + * \param[in] theEntityB second parameter of the constraint + */ + SKETCHPLUGIN_EXPORT void setAttributes( + const double theDistance, + const boost::shared_ptr theEntityA, + const boost::shared_ptr theEntityB); + /** \brief Initializes the attributes of the constraint + * + * Defines the distance between a point defined by reference and another entity. + * + * \param[in] theDistance distance between the point and other entity + * \param[in] thePoint reference to the point attribute + * \param[in] theEntity other parameter of the constraint + */ + SKETCHPLUGIN_EXPORT void setAttributes( + const double theDistance, + const boost::shared_ptr thePoint, + const boost::shared_ptr theEntity); + /** \brief Initializes the attributes of the constraint + * + * Defines the distance between two points which defined by references. + * + * \param[in] theDistance distance between the points + * \param[in] thePointA reference to the first point attribute + * \param[in] thePointB reference to the second point attribute + */ + SKETCHPLUGIN_EXPORT void setAttributes( + const double theDistance, + const boost::shared_ptr thePointA, + const boost::shared_ptr thePointB); + /** \brief Initializes the attributes of the constraint + * + * Defines radius of a circle. + * + * \param[in] theRadius radius of the circle + * \param[in] theCircle the circle which has specified radius + */ + SKETCHPLUGIN_EXPORT void setAttributes( + const double theRadius, + const boost::shared_ptr theCircle); + /** \brief Initializes the attributes of the constraint + * + * Defines the distance between two points projected on specified vector (or line). + * + * \param[in] theDistance distance between projected points + * \param[in] thePointA first point for the projection + * \param[in] thePointB second point for the projection + * \param[in] theEntity direction of the line which the points projected on + */ + SKETCHPLUGIN_EXPORT void setAttributes( + const double theDistance, + const boost::shared_ptr thePointA, + const boost::shared_ptr thePointB, + const boost::shared_ptr theEntity); + +private: + /** \brief Returns the list of attributes for the certain type of constraint. + * \return names of attributes + */ + const std::list& getAttributesList() const + { return myAttrList; } + +private: + std::list myAttrList; ///< List of attributes for current constraint +}; + +#endif diff --git a/src/SketchPlugin/SketchPlugin_Point.cpp b/src/SketchPlugin/SketchPlugin_Point.cpp index fa77d2494..1d9601a83 100644 --- a/src/SketchPlugin/SketchPlugin_Point.cpp +++ b/src/SketchPlugin/SketchPlugin_Point.cpp @@ -5,15 +5,10 @@ #include "SketchPlugin_Point.h" #include "SketchPlugin_Sketch.h" #include -////#include -////#include #include using namespace std; -////// face of the square-face displayed for selection of general plane -////const double PLANE_SIZE = 200; - SketchPlugin_Point::SketchPlugin_Point() { } diff --git a/src/SketchSolver/CMakeLists.txt b/src/SketchSolver/CMakeLists.txt index 4ac9b2fdb..c26ddc829 100644 --- a/src/SketchSolver/CMakeLists.txt +++ b/src/SketchSolver/CMakeLists.txt @@ -4,10 +4,12 @@ INCLUDE(FindSolveSpace) SET(PROJECT_HEADERS SketchSolver.h SketchSolver_Solver.h + SketchSolver_ConstraintManager.h ) SET(PROJECT_SOURCES SketchSolver_Solver.cpp + SketchSolver_ConstraintManager.cpp ) SET(PROJECT_LIBRARIES diff --git a/src/SketchSolver/SketchSolver_ConstraintManager.cpp b/src/SketchSolver/SketchSolver_ConstraintManager.cpp new file mode 100644 index 000000000..d8d3b5f98 --- /dev/null +++ b/src/SketchSolver/SketchSolver_ConstraintManager.cpp @@ -0,0 +1,5 @@ +// File: SketchSolver_ConstraintManager.cpp +// Created: 08 May 2014 +// Author: Artem ZHIDKOV + +#include "SketchSolver_ConstraintManager.h" diff --git a/src/SketchSolver/SketchSolver_ConstraintManager.h b/src/SketchSolver/SketchSolver_ConstraintManager.h new file mode 100644 index 000000000..376fd2029 --- /dev/null +++ b/src/SketchSolver/SketchSolver_ConstraintManager.h @@ -0,0 +1,28 @@ +// File: SketchSolver_ConstraintManager.h +// Created: 08 May 2014 +// Author: Artem ZHIDKOV + +#ifndef SketchSolver_ConstraintManager_Headerfile +#define SketchSolver_ConstraintManager_Headerfile + +#include "SketchSolver.h" + +/** \class SketchSolver_ConstraintManager + * \ingroup DataModel + * \brief Transforms the Constraint feature into the format understandable by SolveSpace library. + * + * Constraints created for SolveSpace library will be divided into the groups. + * The division order based on connectedness of the features by the constraints. + * The groups may be fused or separated according to the new constraints. + */ +class SketchSolver_ConstraintManager +{ +private: + class SketchSolver_ConstraintGroup; +}; + +class SketchSolver_ConstraintManager::SketchSolver_ConstraintGroup +{ +}; + +#endif