From: nds Date: Fri, 18 Dec 2015 18:07:40 +0000 (+0300) Subject: 2D points selection in multi-translation/rotation : multi-translation: using ModelAPI... X-Git-Tag: V_2.1.0~135 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=d024d0b170de8d01684352397479835432076db6;p=modules%2Fshaper.git 2D points selection in multi-translation/rotation : multi-translation: using ModelAPI_AttributeRefAttr instead of GeomDataAPI_Point2D --- diff --git a/src/GeomDataAPI/GeomDataAPI_Point2D.cpp b/src/GeomDataAPI/GeomDataAPI_Point2D.cpp index dd8b39ec5..3a72ceacc 100644 --- a/src/GeomDataAPI/GeomDataAPI_Point2D.cpp +++ b/src/GeomDataAPI/GeomDataAPI_Point2D.cpp @@ -6,6 +6,7 @@ #include +#include void GeomDataAPI_Point2D::move(const double theDeltaX, const double theDeltaY) { @@ -17,6 +18,22 @@ std::string GeomDataAPI_Point2D::attributeType() return typeId(); } +std::shared_ptr GeomDataAPI_Point2D::getPoint2D( + const DataPtr& theData, const std::string& theAttribute) +{ + std::shared_ptr aPointAttr; + if (!theData) + return aPointAttr; + + std::shared_ptr anAttr = std::dynamic_pointer_cast< + ModelAPI_AttributeRefAttr>(theData->attribute(theAttribute)); + if (anAttr && anAttr->attr()) { + aPointAttr = std::dynamic_pointer_cast(anAttr->attr()); + } + return aPointAttr; +} + + GeomDataAPI_Point2D::GeomDataAPI_Point2D() { } diff --git a/src/GeomDataAPI/GeomDataAPI_Point2D.h b/src/GeomDataAPI/GeomDataAPI_Point2D.h index 7f67085e7..633ef8255 100644 --- a/src/GeomDataAPI/GeomDataAPI_Point2D.h +++ b/src/GeomDataAPI/GeomDataAPI_Point2D.h @@ -9,6 +9,7 @@ #include #include +#include #include @@ -82,6 +83,12 @@ class GeomDataAPI_Point2D : public ModelAPI_Attribute /// Returns the type of this class of attributes, not static method GEOMDATAAPI_EXPORT virtual std::string attributeType(); + /// Returns this attribute from the data if it is possible + /// \param theData a model data + /// \param theAttribute an attribute index + static GEOMDATAAPI_EXPORT std::shared_ptr getPoint2D(const DataPtr& theData, + const std::string& theAttribute); + protected: /// Objects are created for features automatically GEOMDATAAPI_EXPORT GeomDataAPI_Point2D(); diff --git a/src/SketchPlugin/SketchPlugin_MultiTranslation.cpp b/src/SketchPlugin/SketchPlugin_MultiTranslation.cpp index c94ae2dca..2be40aecb 100755 --- a/src/SketchPlugin/SketchPlugin_MultiTranslation.cpp +++ b/src/SketchPlugin/SketchPlugin_MultiTranslation.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -22,7 +23,6 @@ #include SketchPlugin_MultiTranslation::SketchPlugin_MultiTranslation() -: myBlockValue(false) { } @@ -30,10 +30,9 @@ void SketchPlugin_MultiTranslation::initAttributes() { data()->addAttribute(VALUE_TYPE(), ModelAPI_AttributeString::typeId()); - data()->addAttribute(START_POINT_ID(), GeomDataAPI_Point2D::typeId()); - data()->addAttribute(START_FULL_POINT_ID(), GeomDataAPI_Point2D::typeId()); - data()->addAttribute(END_POINT_ID(), GeomDataAPI_Point2D::typeId()); - data()->addAttribute(END_FULL_POINT_ID(), GeomDataAPI_Point2D::typeId()); + data()->addAttribute(START_POINT_ID(), ModelAPI_AttributeRefAttr::typeId()); + data()->addAttribute(END_POINT_ID(), ModelAPI_AttributeRefAttr::typeId()); + data()->addAttribute(NUMBER_OF_OBJECTS_ID(), ModelAPI_AttributeInteger::typeId()); data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefList::typeId()); data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefList::typeId()); @@ -56,30 +55,19 @@ void SketchPlugin_MultiTranslation::execute() return; // Calculate shift vector - std::shared_ptr aStart = std::dynamic_pointer_cast( - attribute(START_POINT_ID())); - std::shared_ptr aEnd = std::dynamic_pointer_cast( - attribute(END_POINT_ID())); - if (!aStart || !aEnd || !aStart->isInitialized() || !aEnd->isInitialized()) - return; - - if (attribute(END_POINT_ID())->isInitialized() && !attribute(END_FULL_POINT_ID())->isInitialized()) { - myBlockValue = true; - SketchPlugin_Tools::updateMultiAttribute(attribute(START_POINT_ID()), attribute(END_POINT_ID()), - attribute(END_FULL_POINT_ID()), aNbCopies, true); - myBlockValue = false; - } - + AttributeRefAttrPtr aStartAttr = data()->refattr(START_POINT_ID()); + AttributeRefAttrPtr anEndAttr = data()->refattr(END_POINT_ID()); - // make a visible points - SketchPlugin_Sketch::createPoint2DResult(this, sketch(), START_POINT_ID(), 0); + if (!aStartAttr || !anEndAttr || !aStartAttr->isInitialized() || !anEndAttr->isInitialized()) + return; - std::string aSecondPointAttributeID = END_POINT_ID(); - AttributeStringPtr aMethodTypeAttr = string(VALUE_TYPE()); - std::string aMethodType = aMethodTypeAttr->value(); - if (aMethodType != "SingleValue") - aSecondPointAttributeID = END_FULL_POINT_ID(); - SketchPlugin_Sketch::createPoint2DResult(this, sketch(), aSecondPointAttributeID, 1); + DataPtr aData = data(); + std::shared_ptr aStart = GeomDataAPI_Point2D::getPoint2D(aData, + START_POINT_ID()); + std::shared_ptr aEnd = GeomDataAPI_Point2D::getPoint2D(aData, + END_POINT_ID()); + if (!aStart || !aEnd) + return; std::shared_ptr aShiftVec(new GeomAPI_XY(aEnd->x() - aStart->x(), aEnd->y() - aStart->y())); @@ -89,7 +77,6 @@ void SketchPlugin_MultiTranslation::execute() if (isUpdateFlushed) Events_Loop::loop()->setFlushed(anUpdateEvent, false); - std::shared_ptr aData = data(); AttributeRefListPtr aRefListOfShapes = std::dynamic_pointer_cast( aData->attribute(SketchPlugin_Constraint::ENTITY_A())); AttributeRefListPtr aRefListOfTranslated = std::dynamic_pointer_cast( @@ -273,63 +260,4 @@ void SketchPlugin_MultiTranslation::attributeChanged(const std::string& theID) data()->attribute(SketchPlugin_Constraint::ENTITY_B()))->clear(); } } - else if (theID == START_POINT_ID() && !myBlockValue) { - myBlockValue = true; - std::shared_ptr aStartPoint = - std::dynamic_pointer_cast(attribute(START_POINT_ID())); - std::shared_ptr aStartFullPoint = - std::dynamic_pointer_cast(attribute(START_FULL_POINT_ID())); - aStartFullPoint->setValue(aStartPoint->pnt()); - myBlockValue = false; - } - else if (theID == START_FULL_POINT_ID() && !myBlockValue) { - myBlockValue = true; - std::shared_ptr aStartPoint = - std::dynamic_pointer_cast(attribute(START_POINT_ID())); - std::shared_ptr aStartFullPoint = - std::dynamic_pointer_cast(attribute(START_FULL_POINT_ID())); - aStartPoint->setValue(aStartFullPoint->pnt()); - myBlockValue = false; - } - else if (theID == END_POINT_ID() && !myBlockValue) { - int aNbCopies = integer(NUMBER_OF_OBJECTS_ID())->value() - 1; - if (aNbCopies > 0) { - myBlockValue = true; - SketchPlugin_Tools::updateMultiAttribute(attribute(START_POINT_ID()), attribute(END_POINT_ID()), - attribute(END_FULL_POINT_ID()), aNbCopies, true); - myBlockValue = false; - Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); - } - } - else if (theID == END_FULL_POINT_ID() && !myBlockValue) { - int aNbCopies = integer(NUMBER_OF_OBJECTS_ID())->value() - 1; - if (aNbCopies > 0) { - myBlockValue = true; - SketchPlugin_Tools::updateMultiAttribute(attribute(START_POINT_ID()), attribute(END_FULL_POINT_ID()), - attribute(END_POINT_ID()), aNbCopies, false); - myBlockValue = false; - Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); - } - } - else if (theID == NUMBER_OF_OBJECTS_ID()) { - if (attribute(NUMBER_OF_OBJECTS_ID())->isInitialized() && - attribute(END_POINT_ID())->isInitialized() && - attribute(VALUE_TYPE())->isInitialized()) { - AttributeStringPtr aMethodTypeAttr = string(VALUE_TYPE()); - std::string aMethodType = aMethodTypeAttr->value(); - int aNbCopies = integer(NUMBER_OF_OBJECTS_ID())->value() - 1; - if (aNbCopies > 0) { - myBlockValue = true; - if (aMethodType == "SingleValue") - SketchPlugin_Tools::updateMultiAttribute(attribute(START_POINT_ID()), attribute(END_POINT_ID()), - attribute(END_FULL_POINT_ID()), aNbCopies, true); - else { - SketchPlugin_Tools::updateMultiAttribute(attribute(START_POINT_ID()), attribute(END_FULL_POINT_ID()), - attribute(END_POINT_ID()), aNbCopies, false); - } - myBlockValue = false; - Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); - } - } - } } diff --git a/src/SketchPlugin/SketchPlugin_MultiTranslation.h b/src/SketchPlugin/SketchPlugin_MultiTranslation.h index b9d44214d..7a3a78bc8 100644 --- a/src/SketchPlugin/SketchPlugin_MultiTranslation.h +++ b/src/SketchPlugin/SketchPlugin_MultiTranslation.h @@ -59,12 +59,6 @@ class SketchPlugin_MultiTranslation : public SketchPlugin_ConstraintBase static const std::string MY_START_POINT_ID("MultiTranslationStartPoint"); return MY_START_POINT_ID; } - /// Start point of translation - inline static const std::string& START_FULL_POINT_ID() - { - static const std::string MY_START_FULL_POINT_ID("MultiTranslationFullStartPoint"); - return MY_START_FULL_POINT_ID; - } /// End point of translation inline static const std::string& END_POINT_ID() @@ -72,12 +66,6 @@ class SketchPlugin_MultiTranslation : public SketchPlugin_ConstraintBase static const std::string MY_END_POINT_ID("MultiTranslationEndPoint"); return MY_END_POINT_ID; } - /// End point of translation - inline static const std::string& END_FULL_POINT_ID() - { - static const std::string MY_END_FULL_POINT_ID("MultiTranslationFullEndPoint"); - return MY_END_FULL_POINT_ID; - } /// Total number of objects, initial and translated objects inline static const std::string& NUMBER_OF_OBJECTS_ID() @@ -105,8 +93,6 @@ class SketchPlugin_MultiTranslation : public SketchPlugin_ConstraintBase private: ObjectPtr copyFeature(ObjectPtr theObject); -private: - bool myBlockValue; /// a boolean state to avoid recusive value change in attributeChanged }; #endif diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index 110b00461..b38f14995 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -289,37 +289,57 @@ - - + + + + + + + + + + - - + + + + + + + + + + - + +#include + +#include void SketchSolver_ConstraintMultiTranslation::getAttributes( EntityWrapperPtr& theStartPoint, EntityWrapperPtr& theEndPoint, @@ -63,3 +66,66 @@ const std::string& SketchSolver_ConstraintMultiTranslation::nameNbObjects() { return SketchPlugin_MultiTranslation::NUMBER_OF_OBJECTS_ID(); } + +void SketchSolver_ConstraintMultiTranslation::updateLocal() +{ + DataPtr aData = myBaseConstraint->data(); + AttributePoint2DPtr aStartPointAttribute = GeomDataAPI_Point2D::getPoint2D(aData, + SketchPlugin_MultiTranslation::START_POINT_ID()); + AttributePoint2DPtr anEndPointAttribute = GeomDataAPI_Point2D::getPoint2D(aData, + SketchPlugin_MultiTranslation::END_POINT_ID()); + AttributeStringPtr aMethodTypeAttr = aData->string(SketchPlugin_MultiTranslation::VALUE_TYPE()); + bool aFullValue = aMethodTypeAttr->value() != "SingleValue"; + + bool aStartPointChanged = aStartPointAttribute != myStartPointAttribute; + bool anEndPointChanged = anEndPointAttribute != myEndPointAttribute; + bool isMethodChanged = aFullValue != myIsFullValue; + + if (aStartPointChanged) + myStartPointAttribute = aStartPointAttribute; + if (aStartPointChanged) + myEndPointAttribute = anEndPointAttribute; + if (isMethodChanged) + myIsFullValue = aFullValue; + + if (aStartPointChanged || anEndPointChanged || isMethodChanged) { + DataPtr aData = myBaseConstraint->data(); + std::list aConstraints = myStorage->constraint(myBaseConstraint); + std::list::const_iterator anIt = aConstraints.begin(), + aLast = aConstraints.end(); + std::list anEntities; + for (; anIt != aLast; anIt++) { + ConstraintWrapperPtr aConstraint = *anIt; + aConstraint->setIsFullValue(myIsFullValue); + anEntities.clear(); + + const std::list& aConstraintEntities = aConstraint->entities(); + std::list::const_iterator aSIt = aConstraintEntities.begin(), + aSLast = aConstraintEntities.end(); + EntityWrapperPtr aStartEntity = *aSIt++; + if (aStartPointChanged) { + AttributePtr aStartPointAttr = aData->attribute(SketchPlugin_MultiTranslation::START_POINT_ID()); + myStorage->update(aStartPointAttr); + aStartEntity = myStorage->entity(aStartPointAttr); + } + anEntities.push_back(aStartEntity); + + EntityWrapperPtr anEndEntity = *aSIt++; + if (anEndPointChanged) { + AttributePtr anEndPointAttr = aData->attribute(SketchPlugin_MultiTranslation::END_POINT_ID()); + myStorage->update(anEndPointAttr); + anEndEntity = myStorage->entity(anEndPointAttr); + } + anEntities.push_back(anEndEntity); + + for (; aSIt != aSLast; ++aSIt) + anEntities.push_back(*aSIt); + + aConstraint->setEntities(anEntities); + } + myStorage->addConstraint(myBaseConstraint, aConstraints); + + myAdjusted = false; + } +} + diff --git a/src/SketchSolver/SketchSolver_ConstraintMultiTranslation.h b/src/SketchSolver/SketchSolver_ConstraintMultiTranslation.h index 0e0c2faf1..a0f6ca525 100644 --- a/src/SketchSolver/SketchSolver_ConstraintMultiTranslation.h +++ b/src/SketchSolver/SketchSolver_ConstraintMultiTranslation.h @@ -10,6 +10,8 @@ #include "SketchSolver.h" #include +#include "GeomDataAPI_Point2D.h" + /** \class SketchSolver_ConstraintMultiTranslation * \ingroup Plugins * \brief Convert translated features to the list of SolveSpace constraints @@ -34,12 +36,16 @@ protected: std::list< std::list >& theEntities); /// \brief Update parameters (called from base class) - virtual void updateLocal() - {} + virtual void updateLocal(); private: /// \brief Returns name of NUMBER_OF_COPIES parameter for corresponding feature virtual const std::string& nameNbObjects(); + +private: + AttributePoint2DPtr myStartPointAttribute; + AttributePoint2DPtr myEndPointAttribute; + bool myIsFullValue; }; #endif diff --git a/src/SketchSolver/SketchSolver_IConstraintWrapper.h b/src/SketchSolver/SketchSolver_IConstraintWrapper.h index a0dd5261b..813e8dede 100644 --- a/src/SketchSolver/SketchSolver_IConstraintWrapper.h +++ b/src/SketchSolver/SketchSolver_IConstraintWrapper.h @@ -80,6 +80,13 @@ public: const double& value() const { return myValue; } + /// \brief Store a boolean flag for full value using + void setIsFullValue(const bool& theFullValue) + { myIsFullValue = theFullValue; } + /// \brief Return a flag of a full value using + const bool& isFullValue() const + { return myIsFullValue; } + /// \brief Verify the feature is used in the constraint virtual bool isUsed(FeaturePtr theFeature) const = 0; /// \brief Verify the attribute is used in the constraint @@ -96,6 +103,7 @@ protected: ConstraintPtr myBaseConstraint; std::list myConstrained; double myValue; + bool myIsFullValue; }; typedef std::shared_ptr ConstraintWrapperPtr; diff --git a/src/SketchSolver/SolveSpaceSolver/SolveSpaceSolver_Builder.cpp b/src/SketchSolver/SolveSpaceSolver/SolveSpaceSolver_Builder.cpp index 34101a991..2c47352ad 100644 --- a/src/SketchSolver/SolveSpaceSolver/SolveSpaceSolver_Builder.cpp +++ b/src/SketchSolver/SolveSpaceSolver/SolveSpaceSolver_Builder.cpp @@ -837,6 +837,13 @@ void adjustMultiTranslation(ConstraintWrapperPtr theConstraint) std::shared_ptr aEndPnt = aBuilder->point(*aSIt++); std::shared_ptr aDelta = aEndPnt->xy()->decreased(aStartPnt->xy()); + bool isFullValue = theConstraint->isFullValue(); + int aNbObjects = aSubs.size()-3; + if (isFullValue && aNbObjects > 0) { + aDelta->setX(aDelta->x()/aNbObjects); + aDelta->setY(aDelta->y()/aNbObjects); + } + std::list::const_iterator aPrevIt = aSIt++; for (; aSIt != aSubs.end(); ++aPrevIt, ++aSIt) translate(*aPrevIt, *aSIt, aDelta);