From 86469f18d7a0d509914e1fc9ffac53a2393c7776 Mon Sep 17 00:00:00 2001 From: dbv Date: Thu, 24 Dec 2015 17:04:49 +0300 Subject: [PATCH] COPY attribute in SketchEntity now persistent --- src/SketchPlugin/SketchPlugin_Arc.cpp | 4 +-- src/SketchPlugin/SketchPlugin_Arc.h | 7 ++-- src/SketchPlugin/SketchPlugin_Circle.cpp | 4 +-- src/SketchPlugin/SketchPlugin_Circle.h | 7 ++-- src/SketchPlugin/SketchPlugin_Line.cpp | 4 +-- src/SketchPlugin/SketchPlugin_Line.h | 7 ++-- .../SketchPlugin_MultiRotation.cpp | 33 +++++++++++++++++++ src/SketchPlugin/SketchPlugin_MultiRotation.h | 3 ++ .../SketchPlugin_MultiTranslation.cpp | 33 +++++++++++++++++++ .../SketchPlugin_MultiTranslation.h | 3 ++ src/SketchPlugin/SketchPlugin_Point.cpp | 4 +-- src/SketchPlugin/SketchPlugin_Point.h | 7 ++-- src/SketchPlugin/SketchPlugin_Sketch.cpp | 8 ++--- .../SketchPlugin_SketchEntity.cpp | 10 ++++++ src/SketchPlugin/SketchPlugin_SketchEntity.h | 6 +++- 15 files changed, 110 insertions(+), 30 deletions(-) diff --git a/src/SketchPlugin/SketchPlugin_Arc.cpp b/src/SketchPlugin/SketchPlugin_Arc.cpp index 7d285d079..261e70b95 100644 --- a/src/SketchPlugin/SketchPlugin_Arc.cpp +++ b/src/SketchPlugin/SketchPlugin_Arc.cpp @@ -41,10 +41,8 @@ SketchPlugin_Arc::SketchPlugin_Arc() myParamBefore = 0; } -void SketchPlugin_Arc::initAttributes() +void SketchPlugin_Arc::initDerivedClassAttributes() { - SketchPlugin_SketchEntity::initAttributes(); - data()->addAttribute(CENTER_ID(), GeomDataAPI_Point2D::typeId()); data()->addAttribute(START_ID(), GeomDataAPI_Point2D::typeId()); std::shared_ptr anEndAttr = std::dynamic_pointer_cast< diff --git a/src/SketchPlugin/SketchPlugin_Arc.h b/src/SketchPlugin/SketchPlugin_Arc.h index 0464ebead..296b849bc 100644 --- a/src/SketchPlugin/SketchPlugin_Arc.h +++ b/src/SketchPlugin/SketchPlugin_Arc.h @@ -77,9 +77,6 @@ class SketchPlugin_Arc : public SketchPlugin_SketchEntity, public GeomAPI_IPrese /// Creates an arc-shape SKETCHPLUGIN_EXPORT virtual void execute(); - /// Request for initialization of data model of the feature: adding all attributes - SKETCHPLUGIN_EXPORT virtual void initAttributes(); - /// Called on change of any argument-attribute of this object /// \param theID identifier of changed attribute SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID); @@ -101,6 +98,10 @@ class SketchPlugin_Arc : public SketchPlugin_SketchEntity, public GeomAPI_IPrese /// Use plugin manager for features creation SketchPlugin_Arc(); +protected: + /// \brief Initializes attributes of derived class. + virtual void initDerivedClassAttributes(); + private: /// Returns true if all obligatory attributes are initialized bool isFeatureValid(); diff --git a/src/SketchPlugin/SketchPlugin_Circle.cpp b/src/SketchPlugin/SketchPlugin_Circle.cpp index bf8a7d8d0..5dd78c10c 100644 --- a/src/SketchPlugin/SketchPlugin_Circle.cpp +++ b/src/SketchPlugin/SketchPlugin_Circle.cpp @@ -26,10 +26,8 @@ SketchPlugin_Circle::SketchPlugin_Circle() { } -void SketchPlugin_Circle::initAttributes() +void SketchPlugin_Circle::initDerivedClassAttributes() { - SketchPlugin_SketchEntity::initAttributes(); - data()->addAttribute(CENTER_ID(), GeomDataAPI_Point2D::typeId()); data()->addAttribute(RADIUS_ID(), ModelAPI_AttributeDouble::typeId()); data()->addAttribute(EXTERNAL_ID(), ModelAPI_AttributeSelection::typeId()); diff --git a/src/SketchPlugin/SketchPlugin_Circle.h b/src/SketchPlugin/SketchPlugin_Circle.h index 2edff8e39..941d90f22 100644 --- a/src/SketchPlugin/SketchPlugin_Circle.h +++ b/src/SketchPlugin/SketchPlugin_Circle.h @@ -53,9 +53,6 @@ class SketchPlugin_Circle : public SketchPlugin_SketchEntity /// Creates a new part document if needed SKETCHPLUGIN_EXPORT virtual void execute(); - /// Request for initialization of data model of the feature: adding all attributes - SKETCHPLUGIN_EXPORT virtual void initAttributes(); - /// Adds sub-feature of the higher level feature (sub-element of the sketch) /// \param theFeature sub-feature SKETCHPLUGIN_EXPORT virtual const void addSub(const FeaturePtr& theFeature) @@ -73,6 +70,10 @@ class SketchPlugin_Circle : public SketchPlugin_SketchEntity /// Use plugin manager for features creation SketchPlugin_Circle(); + +protected: + /// \brief Initializes attributes of derived class. + virtual void initDerivedClassAttributes(); }; #endif diff --git a/src/SketchPlugin/SketchPlugin_Line.cpp b/src/SketchPlugin/SketchPlugin_Line.cpp index f4382e431..33d087d2c 100644 --- a/src/SketchPlugin/SketchPlugin_Line.cpp +++ b/src/SketchPlugin/SketchPlugin_Line.cpp @@ -26,10 +26,8 @@ SketchPlugin_Line::SketchPlugin_Line() : SketchPlugin_SketchEntity() {} -void SketchPlugin_Line::initAttributes() +void SketchPlugin_Line::initDerivedClassAttributes() { - SketchPlugin_SketchEntity::initAttributes(); - data()->addAttribute(START_ID(), GeomDataAPI_Point2D::typeId()); data()->addAttribute(END_ID(), GeomDataAPI_Point2D::typeId()); data()->addAttribute(EXTERNAL_ID(), ModelAPI_AttributeSelection::typeId()); diff --git a/src/SketchPlugin/SketchPlugin_Line.h b/src/SketchPlugin/SketchPlugin_Line.h index eaa3330f3..57363add5 100644 --- a/src/SketchPlugin/SketchPlugin_Line.h +++ b/src/SketchPlugin/SketchPlugin_Line.h @@ -49,9 +49,6 @@ class SketchPlugin_Line : public SketchPlugin_SketchEntity /// Creates a new part document if needed SKETCHPLUGIN_EXPORT virtual void execute(); - /// Request for initialization of data model of the feature: adding all attributes - SKETCHPLUGIN_EXPORT virtual void initAttributes(); - /// Moves the feature /// \param theDeltaX the delta for X coordinate is moved /// \param theDeltaY the delta for Y coordinate is moved @@ -66,6 +63,10 @@ class SketchPlugin_Line : public SketchPlugin_SketchEntity /// Use plugin manager for features creation SketchPlugin_Line(); + +protected: + /// \brief Initializes attributes of derived class. + virtual void initDerivedClassAttributes(); }; #endif diff --git a/src/SketchPlugin/SketchPlugin_MultiRotation.cpp b/src/SketchPlugin/SketchPlugin_MultiRotation.cpp index e878ea50d..68e0eab6d 100755 --- a/src/SketchPlugin/SketchPlugin_MultiRotation.cpp +++ b/src/SketchPlugin/SketchPlugin_MultiRotation.cpp @@ -19,6 +19,8 @@ #include #include +#include + #include #include @@ -209,6 +211,37 @@ AISObjectPtr SketchPlugin_MultiRotation::getAISObject(AISObjectPtr thePrevious) return anAIS; } +void SketchPlugin_MultiRotation::erase() +{ + // Set copy attribute to false on all copied features. + AttributeRefListPtr aRefListOfRotated = std::dynamic_pointer_cast( + data()->attribute(SketchPlugin_Constraint::ENTITY_B())); + + if(aRefListOfRotated.get()) { + static Events_Loop* aLoop = Events_Loop::loop(); + static Events_ID aRedispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY); + + std::list aTargetList = aRefListOfRotated->list(); + for(std::list::const_iterator aTargetIt = aTargetList.cbegin(); aTargetIt != aTargetList.cend(); aTargetIt++) { + if((*aTargetIt).get()) { + ResultPtr aRes = std::dynamic_pointer_cast(*aTargetIt); + if(aRes.get()) { + FeaturePtr aFeature = aRes->document()->feature(aRes); + if(aFeature.get()) { + AttributeBooleanPtr aBooleanAttr = aFeature->boolean(SketchPlugin_SketchEntity::COPY_ID()); + if(aBooleanAttr.get()) { + aBooleanAttr->setValue(false); + // Redisplay object as it is not copy anymore. + ModelAPI_EventCreator::get()->sendUpdated(aRes, aRedispEvent); + } + } + } + } + } + } + + SketchPlugin_ConstraintBase::erase(); +} ObjectPtr SketchPlugin_MultiRotation::copyFeature(ObjectPtr theObject) { diff --git a/src/SketchPlugin/SketchPlugin_MultiRotation.h b/src/SketchPlugin/SketchPlugin_MultiRotation.h index 97528ebc0..3a1be2088 100644 --- a/src/SketchPlugin/SketchPlugin_MultiRotation.h +++ b/src/SketchPlugin/SketchPlugin_MultiRotation.h @@ -86,6 +86,9 @@ class SketchPlugin_MultiRotation : public SketchPlugin_ConstraintBase /// Returns the AIS preview SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious); + /// removes all fields from this feature: results, data, etc + SKETCHPLUGIN_EXPORT virtual void erase(); + /// \brief Use plugin manager for features creation SketchPlugin_MultiRotation(); diff --git a/src/SketchPlugin/SketchPlugin_MultiTranslation.cpp b/src/SketchPlugin/SketchPlugin_MultiTranslation.cpp index df1643454..df58c765d 100755 --- a/src/SketchPlugin/SketchPlugin_MultiTranslation.cpp +++ b/src/SketchPlugin/SketchPlugin_MultiTranslation.cpp @@ -20,6 +20,7 @@ #include #include +#include #include SketchPlugin_MultiTranslation::SketchPlugin_MultiTranslation() @@ -197,6 +198,38 @@ AISObjectPtr SketchPlugin_MultiTranslation::getAISObject(AISObjectPtr thePreviou return anAIS; } +void SketchPlugin_MultiTranslation::erase() +{ + // Set copy attribute to false on all copied features. + AttributeRefListPtr aRefListOfTranslated = std::dynamic_pointer_cast( + data()->attribute(SketchPlugin_Constraint::ENTITY_B())); + + if(aRefListOfTranslated.get()) { + static Events_Loop* aLoop = Events_Loop::loop(); + static Events_ID aRedispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY); + + std::list aTargetList = aRefListOfTranslated->list(); + for(std::list::const_iterator aTargetIt = aTargetList.cbegin(); aTargetIt != aTargetList.cend(); aTargetIt++) { + if((*aTargetIt).get()) { + ResultPtr aRes = std::dynamic_pointer_cast(*aTargetIt); + if(aRes.get()) { + FeaturePtr aFeature = aRes->document()->feature(aRes); + if(aFeature.get()) { + AttributeBooleanPtr aBooleanAttr = aFeature->boolean(SketchPlugin_SketchEntity::COPY_ID()); + if(aBooleanAttr.get()) { + aBooleanAttr->setValue(false); + // Redisplay object as it is not copy anymore. + ModelAPI_EventCreator::get()->sendUpdated(aRes, aRedispEvent); + } + } + } + } + } + } + + SketchPlugin_ConstraintBase::erase(); +} + ObjectPtr SketchPlugin_MultiTranslation::copyFeature(ObjectPtr theObject) { ResultPtr aResult = std::dynamic_pointer_cast(theObject); diff --git a/src/SketchPlugin/SketchPlugin_MultiTranslation.h b/src/SketchPlugin/SketchPlugin_MultiTranslation.h index 7a3a78bc8..cdf08a5a5 100644 --- a/src/SketchPlugin/SketchPlugin_MultiTranslation.h +++ b/src/SketchPlugin/SketchPlugin_MultiTranslation.h @@ -87,6 +87,9 @@ class SketchPlugin_MultiTranslation : public SketchPlugin_ConstraintBase /// Returns the AIS preview SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious); + /// removes all fields from this feature: results, data, etc + SKETCHPLUGIN_EXPORT virtual void erase(); + /// \brief Use plugin manager for features creation SketchPlugin_MultiTranslation(); diff --git a/src/SketchPlugin/SketchPlugin_Point.cpp b/src/SketchPlugin/SketchPlugin_Point.cpp index cf718db76..17dbb0a3f 100644 --- a/src/SketchPlugin/SketchPlugin_Point.cpp +++ b/src/SketchPlugin/SketchPlugin_Point.cpp @@ -25,10 +25,8 @@ SketchPlugin_Point::SketchPlugin_Point() { } -void SketchPlugin_Point::initAttributes() +void SketchPlugin_Point::initDerivedClassAttributes() { - SketchPlugin_SketchEntity::initAttributes(); - data()->addAttribute(SketchPlugin_Point::COORD_ID(), GeomDataAPI_Point2D::typeId()); data()->addAttribute(EXTERNAL_ID(), ModelAPI_AttributeSelection::typeId()); ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), EXTERNAL_ID()); diff --git a/src/SketchPlugin/SketchPlugin_Point.h b/src/SketchPlugin/SketchPlugin_Point.h index 59995ff43..142d0915a 100644 --- a/src/SketchPlugin/SketchPlugin_Point.h +++ b/src/SketchPlugin/SketchPlugin_Point.h @@ -44,9 +44,6 @@ class SketchPlugin_Point : public SketchPlugin_SketchEntity /// Creates a new part document if needed SKETCHPLUGIN_EXPORT virtual void execute(); - /// Request for initialization of data model of the feature: adding all attributes - SKETCHPLUGIN_EXPORT virtual void initAttributes(); - /// Moves the feature /// \param theDeltaX the delta for X coordinate is moved /// \param theDeltaY the delta for Y coordinate is moved @@ -57,6 +54,10 @@ class SketchPlugin_Point : public SketchPlugin_SketchEntity /// Use plugin manager for features creation SketchPlugin_Point(); + +protected: + /// \brief Initializes attributes of derived class. + virtual void initDerivedClassAttributes(); }; #endif diff --git a/src/SketchPlugin/SketchPlugin_Sketch.cpp b/src/SketchPlugin/SketchPlugin_Sketch.cpp index bc71a6445..739f347bf 100644 --- a/src/SketchPlugin/SketchPlugin_Sketch.cpp +++ b/src/SketchPlugin/SketchPlugin_Sketch.cpp @@ -310,12 +310,10 @@ FeaturePtr SketchPlugin_Sketch::addUniqueNamedCopiedFeature(FeaturePtr theFeatur // text expressions could block setValue of some attributes SketchPlugin_Tools::clearExpressions(aNewFeature); // Set copy attribute - std::shared_ptr anAttr = aNewFeature->data()->boolean(SketchPlugin_SketchEntity::COPY_ID()); - if(!anAttr.get()) { - aNewFeature->data()->addAttribute(SketchPlugin_SketchEntity::COPY_ID(), ModelAPI_AttributeBoolean::typeId()); - ModelAPI_Session::get()->validators()->registerNotObligatory(aNewFeature->getKind(), SketchPlugin_SketchEntity::COPY_ID()); + AttributeBooleanPtr anAttr = aNewFeature->data()->boolean(SketchPlugin_SketchEntity::COPY_ID()); + if(anAttr.get()) { + anAttr->setValue(theIsCopy); } - aNewFeature->data()->boolean(SketchPlugin_SketchEntity::COPY_ID())->setValue(theIsCopy); return aNewFeature; } diff --git a/src/SketchPlugin/SketchPlugin_SketchEntity.cpp b/src/SketchPlugin/SketchPlugin_SketchEntity.cpp index 9e95496ef..f29dfc139 100644 --- a/src/SketchPlugin/SketchPlugin_SketchEntity.cpp +++ b/src/SketchPlugin/SketchPlugin_SketchEntity.cpp @@ -15,4 +15,14 @@ void SketchPlugin_SketchEntity::initAttributes() { data()->addAttribute(AUXILIARY_ID(), ModelAPI_AttributeBoolean::typeId()); ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), AUXILIARY_ID()); + + initDerivedClassAttributes(); + + AttributePtr anAttr = data()->addAttribute(SketchPlugin_SketchEntity::COPY_ID(), ModelAPI_AttributeBoolean::typeId()); + anAttr->setIsArgument(false); + ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), SketchPlugin_SketchEntity::COPY_ID()); + AttributeBooleanPtr anAttrBool = std::dynamic_pointer_cast(anAttr); + if(anAttr.get()) { + anAttrBool->setValue(false); + } } diff --git a/src/SketchPlugin/SketchPlugin_SketchEntity.h b/src/SketchPlugin/SketchPlugin_SketchEntity.h index 3148b0c57..16101d186 100644 --- a/src/SketchPlugin/SketchPlugin_SketchEntity.h +++ b/src/SketchPlugin/SketchPlugin_SketchEntity.h @@ -123,7 +123,7 @@ class SketchPlugin_SketchEntity : public SketchPlugin_Feature, public GeomAPI_IC } if(isCopy()) { double aWidth = thePrs->width(); - thePrs->setWidth(aWidth / 2.5); + isCustomized = thePrs->setWidth(aWidth / 2.5) || isCustomized; } return isCustomized; } @@ -131,6 +131,10 @@ class SketchPlugin_SketchEntity : public SketchPlugin_Feature, public GeomAPI_IC protected: /// initializes mySketch SketchPlugin_SketchEntity(); + + /// \brief Initializes attributes of derived class. + virtual void initDerivedClassAttributes(){}; + }; #endif -- 2.39.2