]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Debug of Box macro feature to the updated architecture
authormpv <mpv@opencascade.com>
Mon, 25 May 2015 16:27:57 +0000 (19:27 +0300)
committermpv <mpv@opencascade.com>
Mon, 25 May 2015 16:27:57 +0000 (19:27 +0300)
src/Model/Model_Data.cpp
src/Model/Model_Data.h
src/Model/Model_Objects.cpp
src/Model/Model_Update.cpp
src/ModelAPI/ModelAPI_Data.h
src/ModelAPI/ModelAPI_Object.cpp
src/PythonAPI/modeler/extrusion.py
src/PythonAPI/modeler/sketcher.py

index b6c27518e4fe1a9bc8c84d4bfc516a418d769c34..2c973fa3f881e1c170c5fcd8db69860d42101d98 100644 (file)
@@ -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<ModelAPI_Data> 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<ModelAPI_Data> Model_Data::invalidPtr()
+{
+  return kInvalid;
+}
index 10464cabdba9c7b620c0197f3c91a4186d1773cf..cf90469ba46acfc003a3bf602e8e9ad96767c4aa 100644 (file)
@@ -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<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();
index 98ead6c683a63cca7fdcce4127b58a5fdc24fdb1..9ebc1e4d8ae617241b5a107657cc1ed2af931804 100644 (file)
@@ -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<Model_Data> 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);
index 502930d93dc69e6b47e8a23bed95a9134f94e00b..6a2d435ff2ebad9f7e9da7e0d3888c16b4be39b2 100644 (file)
@@ -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);
index 5d952ebfad0e004b8228e7e99a5a0120b30fe3d7..e57aaec10a62c18ff9df8a474b44927b89ae5d28 100644 (file)
@@ -144,6 +144,9 @@ class MODELAPI_EXPORT ModelAPI_Data
   /// 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();
index 24a2b2d55c32740f5976a67d7bb7fc97c0f94b6b..bb3339f932430191a5dc7ccd3e8f6e955c1653b9 100644 (file)
@@ -68,8 +68,8 @@ void ModelAPI_Object::setDoc(std::shared_ptr<ModelAPI_Document> 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()
index 785fba6ab1848bc96a2d9fbec64a2aa4492345ba..3cea7291de1f2d123c6c38c58c785f7b58e1f50e 100644 (file)
@@ -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):
index 5aa7b54adfcb6800188f9afdad73c90e896f8163..b0b3376c53d571ca55763dc4dc5126c027cf7cb8 100644 (file)
@@ -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):