From: mpv Date: Mon, 25 May 2015 16:27:57 +0000 (+0300) Subject: Debug of Box macro feature to the updated architecture X-Git-Tag: V_1.2.0~91 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=96e85a57787c129a73586c195661284e01beb81a;p=modules%2Fshaper.git Debug of Box macro feature to the updated architecture --- diff --git a/src/Model/Model_Data.cpp b/src/Model/Model_Data.cpp index b6c27518e..2c973fa3f 100644 --- a/src/Model/Model_Data.cpp +++ b/src/Model/Model_Data.cpp @@ -45,6 +45,9 @@ static const int kFlagInHistory = 0; // 1 - is displayed or not static const int kFlagDisplayed = 1; +// invalid data +const static std::shared_ptr kInvalid(new Model_Data()); + Model_Data::Model_Data() : mySendAttributeUpdated(true) { } @@ -407,3 +410,8 @@ void Model_Data::setDisplayed(const bool theDisplay) aECreator->sendUpdated(myObject, EVENT_DISP); } } + +std::shared_ptr Model_Data::invalidPtr() +{ + return kInvalid; +} diff --git a/src/Model/Model_Data.h b/src/Model/Model_Data.h index 10464cabd..cf90469ba 100644 --- a/src/Model/Model_Data.h +++ b/src/Model/Model_Data.h @@ -56,8 +56,6 @@ class Model_Data : public ModelAPI_Data /// flag that may block the "attribute updated" sending bool mySendAttributeUpdated; - Model_Data(); - /// Returns label of this feature TDF_Label label() { @@ -73,6 +71,8 @@ class Model_Data : public ModelAPI_Data friend class Model_AttributeSelection; public: + /// The simplest constructor. "setLabel" must be called just after to initialize correctly. + Model_Data(); /// Returns the name of the feature visible by the user in the object browser MODEL_EXPORT virtual std::string name(); /// Defines the name of the feature visible by the user in the object browser @@ -186,6 +186,9 @@ class Model_Data : public ModelAPI_Data /// Copies all atributes content into theTarget data MODEL_EXPORT virtual void copyTo(std::shared_ptr theTarget); + /// Returns the invalid data pointer (to avoid working with NULL shared ptrs in swig) + MODEL_EXPORT virtual std::shared_ptr invalidPtr(); + protected: /// Returns true if "is in history" custom behaviors is defined for the feature MODEL_EXPORT virtual bool isInHistory(); diff --git a/src/Model/Model_Objects.cpp b/src/Model/Model_Objects.cpp index 98ead6c68..9ebc1e4d8 100644 --- a/src/Model/Model_Objects.cpp +++ b/src/Model/Model_Objects.cpp @@ -105,11 +105,8 @@ void Model_Objects::addFeature(FeaturePtr theFeature, const FeaturePtr theAfterT if (!theFeature->isAction()) { // do not add action to the data model TDF_Label aFeaturesLab = featuresLabel(); TDF_Label aFeatureLab = aFeaturesLab.NewChild(); - initData(theFeature, aFeatureLab, TAG_FEATURE_ARGUMENTS); - // keep the feature ID to restore document later correctly - TDataStd_Comment::Set(aFeatureLab, theFeature->getKind().c_str()); - myFeatures.Bind(aFeatureLab, theFeature); - // store feature in the features array + // store feature in the features array: before "initData" because in macro features + // in initData it creates new features, appeared later than this TDF_Label aPrevFeateureLab; if (theAfterThis.get()) { // searching for the previous feature label std::shared_ptr aPrevData = @@ -119,6 +116,11 @@ void Model_Objects::addFeature(FeaturePtr theFeature, const FeaturePtr theAfterT } } AddToRefArray(aFeaturesLab, aFeatureLab, aPrevFeateureLab); + + initData(theFeature, aFeatureLab, TAG_FEATURE_ARGUMENTS); + // keep the feature ID to restore document later correctly + TDataStd_Comment::Set(aFeatureLab, theFeature->getKind().c_str()); + myFeatures.Bind(aFeatureLab, theFeature); // event: feature is added static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_CREATED); ModelAPI_EventCreator::get()->sendUpdated(theFeature, anEvent); diff --git a/src/Model/Model_Update.cpp b/src/Model/Model_Update.cpp index 502930d93..6a2d435ff 100644 --- a/src/Model/Model_Update.cpp +++ b/src/Model/Model_Update.cpp @@ -381,7 +381,8 @@ void Model_Update::updateFeature(FeaturePtr theFeature) if (aFactory->validate(theFeature)) { if (myIsAutomatic || !theFeature->isPersistentResult() /* execute quick, not persistent results */ || (isUpdated(theFeature) && - theFeature == theFeature->document()->currentFeature(false))) // currently edited + (theFeature == theFeature->document()->currentFeature(false) || + theFeature->document()->currentFeature(false)->isMacro()))) // currently edited { if (aState == ModelAPI_StateDone || aState == ModelAPI_StateMustBeUpdated) { executeFeature(theFeature); diff --git a/src/ModelAPI/ModelAPI_Data.h b/src/ModelAPI/ModelAPI_Data.h index 5d952ebfa..e57aaec10 100644 --- a/src/ModelAPI/ModelAPI_Data.h +++ b/src/ModelAPI/ModelAPI_Data.h @@ -144,6 +144,9 @@ class MODELAPI_EXPORT ModelAPI_Data /// Copies all atributes content into theTarget data virtual void copyTo(std::shared_ptr theTarget) = 0; + /// Returns the invalid data pointer (to avoid working with NULL shared ptrs in swig) + virtual std::shared_ptr invalidPtr() = 0; + protected: /// Objects are created for features automatically ModelAPI_Data(); diff --git a/src/ModelAPI/ModelAPI_Object.cpp b/src/ModelAPI/ModelAPI_Object.cpp index 24a2b2d55..bb3339f93 100644 --- a/src/ModelAPI/ModelAPI_Object.cpp +++ b/src/ModelAPI/ModelAPI_Object.cpp @@ -68,8 +68,8 @@ void ModelAPI_Object::setDoc(std::shared_ptr theDoc) void ModelAPI_Object::erase() { - if (myData) myData->erase(); - setData(DataPtr()); + if (myData.get() && myData != myData->invalidPtr()) myData->erase(); + setData(myData->invalidPtr()); } bool ModelAPI_Object::isDisplayed() diff --git a/src/PythonAPI/modeler/extrusion.py b/src/PythonAPI/modeler/extrusion.py index 785fba6ab..3cea7291d 100644 --- a/src/PythonAPI/modeler/extrusion.py +++ b/src/PythonAPI/modeler/extrusion.py @@ -13,12 +13,12 @@ class Extrusion(): self.my = part.addFeature("Extrusion") self.my.data().selectionList("base").append(sketch.result(), sketch.buildShape()) if size < 0: - self.my.data().boolean("reverse").setValue(True) - size = -size + self.my.data().real("from_size").setValue(-size) + self.my.data().real("to_size").setValue(0) else: - self.my.data().boolean("reverse").setValue(False) + self.my.data().real("to_size").setValue(size) + self.my.data().real("from_size").setValue(0) - self.my.data().real("to_size").setValue(size) if ModelAPI_Session.get().validators().validate(self.my): self.my.execute() @@ -29,12 +29,12 @@ class Extrusion(): def setSize (self, size): """Modifies the size of this extrusion according to the given size.""" if size < 0: - self.my.data().boolean("reverse").setValue(True) - size = -size + self.my.data().real("from_size").setValue(-size) + self.my.data().real("to_size").setValue(0) else: - self.my.data().boolean("reverse").setValue(False) + self.my.data().real("to_size").setValue(size) + self.my.data().real("from_size").setValue(0) - self.my.data().real("to_size").setValue(size) self.my.execute() def result (self): diff --git a/src/PythonAPI/modeler/sketcher.py b/src/PythonAPI/modeler/sketcher.py index 5aa7b54ad..b0b3376c5 100644 --- a/src/PythonAPI/modeler/sketcher.py +++ b/src/PythonAPI/modeler/sketcher.py @@ -122,6 +122,7 @@ class Sketch(): constraint = self.my.addFeature("SketchConstraintLength") constraint.data().refattr("ConstraintEntityA").setObject(line) constraint.data().real("ConstraintValue").setValue(length) + self.my.execute() return constraint def setRadius (self, circle, radius):