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<GeomDataAPI_Point2D> anEndAttr = std::dynamic_pointer_cast<
/// 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);
/// 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();
{
}
-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());
/// 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)
/// Use plugin manager for features creation
SketchPlugin_Circle();
+
+protected:
+ /// \brief Initializes attributes of derived class.
+ virtual void initDerivedClassAttributes();
};
#endif
: 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());
/// 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
/// Use plugin manager for features creation
SketchPlugin_Line();
+
+protected:
+ /// \brief Initializes attributes of derived class.
+ virtual void initDerivedClassAttributes();
};
#endif
#include <ModelAPI_Session.h>
#include <ModelAPI_Validator.h>
+#include <SketchPlugin_SketchEntity.h>
+
#include <GeomAPI_Pnt2d.h>
#include <GeomAPI_XY.h>
return anAIS;
}
+void SketchPlugin_MultiRotation::erase()
+{
+ // Set copy attribute to false on all copied features.
+ AttributeRefListPtr aRefListOfRotated = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
+ 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<ObjectPtr> aTargetList = aRefListOfRotated->list();
+ for(std::list<ObjectPtr>::const_iterator aTargetIt = aTargetList.cbegin(); aTargetIt != aTargetList.cend(); aTargetIt++) {
+ if((*aTargetIt).get()) {
+ ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(*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)
{
/// 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();
#include <ModelAPI_Session.h>
#include <ModelAPI_Validator.h>
+#include <SketchPlugin_SketchEntity.h>
#include <SketcherPrs_Factory.h>
SketchPlugin_MultiTranslation::SketchPlugin_MultiTranslation()
return anAIS;
}
+void SketchPlugin_MultiTranslation::erase()
+{
+ // Set copy attribute to false on all copied features.
+ AttributeRefListPtr aRefListOfTranslated = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
+ 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<ObjectPtr> aTargetList = aRefListOfTranslated->list();
+ for(std::list<ObjectPtr>::const_iterator aTargetIt = aTargetList.cbegin(); aTargetIt != aTargetList.cend(); aTargetIt++) {
+ if((*aTargetIt).get()) {
+ ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(*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<ModelAPI_ResultConstruction>(theObject);
/// 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();
{
}
-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());
/// 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
/// Use plugin manager for features creation
SketchPlugin_Point();
+
+protected:
+ /// \brief Initializes attributes of derived class.
+ virtual void initDerivedClassAttributes();
};
#endif
// text expressions could block setValue of some attributes
SketchPlugin_Tools::clearExpressions(aNewFeature);
// Set copy attribute
- std::shared_ptr<ModelAPI_AttributeBoolean> 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;
}
{
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<ModelAPI_AttributeBoolean>(anAttr);
+ if(anAttr.get()) {
+ anAttrBool->setValue(false);
+ }
}
}
if(isCopy()) {
double aWidth = thePrs->width();
- thePrs->setWidth(aWidth / 2.5);
+ isCustomized = thePrs->setWidth(aWidth / 2.5) || isCustomized;
}
return isCustomized;
}
protected:
/// initializes mySketch
SketchPlugin_SketchEntity();
+
+ /// \brief Initializes attributes of derived class.
+ virtual void initDerivedClassAttributes(){};
+
};
#endif