From: azv Date: Tue, 13 May 2014 05:55:43 +0000 (+0400) Subject: Changes according to the Feature ideology X-Git-Tag: V_0.2~64^2~12 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c46bbabbbdc3ca55df465836b1298e2228ac05cb;p=modules%2Fshaper.git Changes according to the Feature ideology --- diff --git a/src/SketchPlugin/CMakeLists.txt b/src/SketchPlugin/CMakeLists.txt index 6613ff57c..88638a26d 100644 --- a/src/SketchPlugin/CMakeLists.txt +++ b/src/SketchPlugin/CMakeLists.txt @@ -8,7 +8,7 @@ SET(PROJECT_HEADERS SketchPlugin_Line.h SketchPlugin_Point.h SketchPlugin_Constraint.h - SketchPlugin_ConstraintDistance.h + SketchPlugin_ConstraintPointsCoincident.h ) SET(PROJECT_SOURCES @@ -18,7 +18,7 @@ SET(PROJECT_SOURCES SketchPlugin_Line.cpp SketchPlugin_Point.cpp SketchPlugin_Constraint.cpp - SketchPlugin_ConstraintDistance.cpp + SketchPlugin_ConstraintPointsCoincident.cpp ) SET(PROJECT_LIBRARIES diff --git a/src/SketchPlugin/SketchPlugin_Constraint.cpp b/src/SketchPlugin/SketchPlugin_Constraint.cpp index 6269e3213..6d30aa06c 100644 --- a/src/SketchPlugin/SketchPlugin_Constraint.cpp +++ b/src/SketchPlugin/SketchPlugin_Constraint.cpp @@ -4,39 +4,3 @@ #include "SketchPlugin_Constraint.h" -#include -#include - -const boost::shared_ptr& SketchPlugin_Constraint::preview() -{ - return getPreview(); -} - -void SketchPlugin_Constraint::addConstrainedObject( - const std::string& theAttrID, - const boost::shared_ptr& theReference) -{ - if (!data()->attribute(theAttrID).get()) - data()->addAttribute(theAttrID, theReference->type()); - boost::dynamic_pointer_cast( - data()->attribute(theAttrID))->setValue(theReference->value()); -} - -void SketchPlugin_Constraint::addConstrainedObject( - const std::string& theAttrID, - const boost::shared_ptr& theReference) -{ - if (!data()->attribute(theAttrID).get()) - data()->addAttribute(theAttrID, theReference->type()); - boost::dynamic_pointer_cast( - data()->attribute(theAttrID))->setValue(theReference->value()); -} - -void SketchPlugin_Constraint::getSketchParameters( - std::list< boost::shared_ptr >& theParams) -{ - theParams.push_back(sketch()->data()->attribute(SKETCH_ATTR_ORIGIN)); - theParams.push_back(sketch()->data()->attribute(SKETCH_ATTR_DIRX)); - theParams.push_back(sketch()->data()->attribute(SKETCH_ATTR_DIRY)); - theParams.push_back(sketch()->data()->attribute(SKETCH_ATTR_NORM)); -} diff --git a/src/SketchPlugin/SketchPlugin_Constraint.h b/src/SketchPlugin/SketchPlugin_Constraint.h index 9a5e9e480..8c5e6dadb 100644 --- a/src/SketchPlugin/SketchPlugin_Constraint.h +++ b/src/SketchPlugin/SketchPlugin_Constraint.h @@ -37,6 +37,7 @@ const std::string CONSTRAINT_ATTR_ENTITY_B("ConstraintEntityB"); /** \class SketchPlugin_Constraint * \ingroup DataModel * \brief Feature for creation of a new constraint between other features. + * Base class for all constraints. */ class SketchPlugin_Constraint: public SketchPlugin_Feature { @@ -49,47 +50,14 @@ public: SKETCHPLUGIN_EXPORT virtual const std::string& getGroup() {static std::string MY_GROUP = "Sketch"; return MY_GROUP;} - /// Returns the sketch preview - /// \param theSketch the owner of this feature - /// \return the built preview - SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr& preview(); - /** \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[in] theAttrID identifier of the attribute - * \param[in] theReference reference to the feature, which will be constrained - */ - SKETCHPLUGIN_EXPORT virtual void addConstrainedObject( - const std::string& theAttrID, - const boost::shared_ptr& theReference); - - /** \brief Adds an object of the constraint. The object added by the reference to its attribute. - * \param[in] theAttrID identifier of the attribute - * \param[in] theReference reference to the attribute feature, which will be constrained - */ - SKETCHPLUGIN_EXPORT virtual void addConstrainedObject( - const std::string& theAttrID, - const boost::shared_ptr& theReference); - - /** \brief Prepares list of attributes of current sketch workplane - * \param[out] theParams list of attributes - */ - SKETCHPLUGIN_EXPORT void getSketchParameters( - std::list< boost::shared_ptr >& theParams); - /// \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 deleted file mode 100644 index 13ef22dd8..000000000 --- a/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp +++ /dev/null @@ -1,124 +0,0 @@ -// 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 deleted file mode 100644 index 48b59e1ed..000000000 --- a/src/SketchPlugin/SketchPlugin_ConstraintDistance.h +++ /dev/null @@ -1,132 +0,0 @@ -// 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_EXPORT 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_ConstraintPointsCoincident.cpp b/src/SketchPlugin/SketchPlugin_ConstraintPointsCoincident.cpp new file mode 100644 index 000000000..ebbb76373 --- /dev/null +++ b/src/SketchPlugin/SketchPlugin_ConstraintPointsCoincident.cpp @@ -0,0 +1,30 @@ +// File: SketchPlugin_ConstraintPointsCoincident.cpp +// Created: 08 May 2014 +// Author: Artem ZHIDKOV + +#include "SketchPlugin_ConstraintPointsCoincident.h" + +#include +#include +#include + +SketchPlugin_ConstraintPointsCoincident::SketchPlugin_ConstraintPointsCoincident() +{ +} + +void SketchPlugin_ConstraintPointsCoincident::initAttributes() +{ + data()->addAttribute(CONSTRAINT_ATTR_POINT_A, ModelAPI_AttributeRefAttr::type()); + data()->addAttribute(CONSTRAINT_ATTR_POINT_B, ModelAPI_AttributeRefAttr::type()); +} + +void SketchPlugin_ConstraintPointsCoincident::execute() +{ +} + +const boost::shared_ptr& SketchPlugin_ConstraintPointsCoincident::preview() +{ + /// \todo Preview for point coincidence + return getPreview(); +} + diff --git a/src/SketchPlugin/SketchPlugin_ConstraintPointsCoincident.h b/src/SketchPlugin/SketchPlugin_ConstraintPointsCoincident.h new file mode 100644 index 000000000..8130a43b9 --- /dev/null +++ b/src/SketchPlugin/SketchPlugin_ConstraintPointsCoincident.h @@ -0,0 +1,43 @@ +// File: SketchPlugin_ConstraintPointsCoincident.h +// Created: 08 May 2014 +// Author: Artem ZHIDKOV + +#ifndef SketchPlugin_ConstraintPointsCoincident_HeaderFile +#define SketchPlugin_ConstraintPointsCoincident_HeaderFile + +#include "SketchPlugin.h" +#include "SketchPlugin_Constraint.h" +#include + + +/** \class SketchPlugin_ConstraintPointsCoincident + * \ingroup DataModel + * \brief Feature for creation of a new constraint which defines equvalence of two points + * + * These constraint has two attributes: CONSTRAINT_ATTR_POINT_A and CONSTRAINT_ATTR_POINT_B + */ +class SketchPlugin_ConstraintPointsCoincident: public SketchPlugin_Constraint +{ +public: + /// \brief Returns the kind of a feature + SKETCHPLUGIN_EXPORT virtual const std::string& getKind() + {static std::string MY_KIND = "SketchConstraintPointsCoincident"; 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 + SKETCHPLUGIN_EXPORT virtual void initAttributes(); + + /// \brief Returns the sketch preview + SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr& preview(); + + /// \brief Use plugin manager for features creation + SketchPlugin_ConstraintPointsCoincident(); +}; + +#endif diff --git a/src/SketchSolver/SketchSolver_ConstraintManager.cpp b/src/SketchSolver/SketchSolver_ConstraintManager.cpp index 86cb8bacd..6872c82f6 100644 --- a/src/SketchSolver/SketchSolver_ConstraintManager.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintManager.cpp @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include @@ -92,11 +92,11 @@ bool SketchSolver_ConstraintManager::SketchSolver_ConstraintGroup::addConstraint { if (myWorkplane.h == 0) { - // Create workplane when first constraint is added - std::list< boost::shared_ptr > aWPAttr; - theConstraint->getSketchParameters(aWPAttr); - if (!addWorkplane(aWPAttr)) - return false; +// // Create workplane when first constraint is added +// std::list< boost::shared_ptr > aWPAttr; +// theConstraint->getSketchParameters(aWPAttr); +// if (!addWorkplane(aWPAttr)) +// return false; } // Create constraint parameters @@ -151,42 +151,42 @@ bool SketchSolver_ConstraintManager::SketchSolver_ConstraintGroup::addWorkplane( int SketchSolver_ConstraintManager::SketchSolver_ConstraintGroup::getConstraintType( const boost::shared_ptr& theConstraint) const { - if (theConstraint->getKind() == SketchPlugin_ConstraintDistance().getKind()) - { - boost::shared_ptr aPtA = theConstraint->data()->attribute(CONSTRAINT_ATTR_POINT_A); - boost::shared_ptr aPtB = theConstraint->data()->attribute(CONSTRAINT_ATTR_POINT_B); - boost::shared_ptr aEntA = theConstraint->data()->attribute(CONSTRAINT_ATTR_ENTITY_A); - boost::shared_ptr aEntB = theConstraint->data()->attribute(CONSTRAINT_ATTR_ENTITY_B); - boost::shared_ptr aDistance = - boost::shared_dynamic_cast(theConstraint->data()->attribute(CONSTRAINT_ATTR_VALUE)); - if (aPtA.get()) // ptA is an attribute of the constraint - { -// if (aEntA.get()) // entityA is an attribute of the constraint +// if (theConstraint->getKind() == SketchPlugin_ConstraintDistance().getKind()) +// { +// boost::shared_ptr aPtA = theConstraint->data()->attribute(CONSTRAINT_ATTR_POINT_A); +// boost::shared_ptr aPtB = theConstraint->data()->attribute(CONSTRAINT_ATTR_POINT_B); +// boost::shared_ptr aEntA = theConstraint->data()->attribute(CONSTRAINT_ATTR_ENTITY_A); +// boost::shared_ptr aEntB = theConstraint->data()->attribute(CONSTRAINT_ATTR_ENTITY_B); +// boost::shared_ptr aDistance = +// boost::shared_dynamic_cast(theConstraint->data()->attribute(CONSTRAINT_ATTR_VALUE)); +// if (aPtA.get()) // ptA is an attribute of the constraint +// { +//// if (aEntA.get()) // entityA is an attribute of the constraint +//// { +//// if (aEntA->feature()->getKind() == SketchPlugin_Line().getKind()) // entityA is a line +//// { +//// if (aEntB.get() && aEntB->feature()->getKind() == SketchPlugin_Line().getKind()) // entityB is a line too +//// return SLVS_C_ANGLE; +//// else if (aPtB.get()) // ptB is also an attribute of the constraint +//// return SLVS_C_PROJ_PT_DISTANCE; +//// else +//// return SLVS_C_PT_LINE_DISTANCE; +//// } +//// /// \todo Implement other point-entity distances +//// } +//// else +// if (aPtB.get()) // ptB is an attribute of the constrtaint => point-point distance // { -// if (aEntA->feature()->getKind() == SketchPlugin_Line().getKind()) // entityA is a line -// { -// if (aEntB.get() && aEntB->feature()->getKind() == SketchPlugin_Line().getKind()) // entityB is a line too -// return SLVS_C_ANGLE; -// else if (aPtB.get()) // ptB is also an attribute of the constraint -// return SLVS_C_PROJ_PT_DISTANCE; -// else -// return SLVS_C_PT_LINE_DISTANCE; -// } -// /// \todo Implement other point-entity distances +// if (aDistance->value() == 0.0) +// return SLVS_C_POINTS_COINCIDENT; +// else +// return SLVS_C_PT_PT_DISTANCE; // } -// else - if (aPtB.get()) // ptB is an attribute of the constrtaint => point-point distance - { - if (aDistance->value() == 0.0) - return SLVS_C_POINTS_COINCIDENT; - else - return SLVS_C_PT_PT_DISTANCE; - } - } - else if (aEntA.get() && !aEntB.get() && !aPtB.get()) - return SLVS_C_DIAMETER; - return SLVS_C_UNKNOWN; - } +// } +// else if (aEntA.get() && !aEntB.get() && !aPtB.get()) +// return SLVS_C_DIAMETER; +// return SLVS_C_UNKNOWN; +// } /// \todo Implement other kind of constrtaints return SLVS_C_UNKNOWN;