// 1 - is displayed or not
static const int kFlagDisplayed = 1;
+// invalid data
+const static std::shared_ptr<ModelAPI_Data> kInvalid(new Model_Data());
+
Model_Data::Model_Data() : mySendAttributeUpdated(true)
{
}
aECreator->sendUpdated(myObject, EVENT_DISP);
}
}
+
+std::shared_ptr<ModelAPI_Data> Model_Data::invalidPtr()
+{
+ return kInvalid;
+}
/// flag that may block the "attribute updated" sending
bool mySendAttributeUpdated;
- Model_Data();
-
/// Returns label of this feature
TDF_Label label()
{
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
/// Copies all atributes content into theTarget data
MODEL_EXPORT virtual void copyTo(std::shared_ptr<ModelAPI_Data> theTarget);
+ /// Returns the invalid data pointer (to avoid working with NULL shared ptrs in swig)
+ MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Data> invalidPtr();
+
protected:
/// Returns true if "is in history" custom behaviors is defined for the feature
MODEL_EXPORT virtual bool isInHistory();
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<Model_Data> aPrevData =
}
}
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);
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);
/// Copies all atributes content into theTarget data
virtual void copyTo(std::shared_ptr<ModelAPI_Data> theTarget) = 0;
+ /// Returns the invalid data pointer (to avoid working with NULL shared ptrs in swig)
+ virtual std::shared_ptr<ModelAPI_Data> invalidPtr() = 0;
+
protected:
/// Objects are created for features automatically
ModelAPI_Data();
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()
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()
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):
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):