Salome HOME
Issue #1648: Dump Python in the High Level Parameterized Geometry API
authordbv <dbv@opencascade.com>
Wed, 10 Aug 2016 14:23:14 +0000 (17:23 +0300)
committerdbv <dbv@opencascade.com>
Wed, 10 Aug 2016 14:23:33 +0000 (17:23 +0300)
Dump for FeaturesAPI_Extrusion with nested sketch

src/FeaturesAPI/FeaturesAPI_Extrusion.cpp
src/FeaturesAPI/FeaturesAPI_Extrusion.h
src/ModelHighAPI/ModelHighAPI_Reference.cpp
src/ModelHighAPI/ModelHighAPI_Reference.h

index f2dd6e6d793ee15de7bd5d0394d10c1573cd4c89..75635c73d8ef18bfbb314971921933c0b1bc7a67 100644 (file)
@@ -8,6 +8,7 @@
 
 #include <ModelHighAPI_Double.h>
 #include <ModelHighAPI_Dumper.h>
+#include <ModelHighAPI_Reference.h>
 #include <ModelHighAPI_Tools.h>
 
 //==================================================================================================
@@ -106,15 +107,26 @@ FeaturesAPI_Extrusion::FeaturesAPI_Extrusion(const std::shared_ptr<ModelAPI_Feat
 //==================================================================================================
 FeaturesAPI_Extrusion::~FeaturesAPI_Extrusion()
 {
+}
 
+//==================================================================================================
+void FeaturesAPI_Extrusion::setNestedSketch(const ModelHighAPI_Reference& theSketch)
+{
+  mysketch->setValue(theSketch.feature());
+  mybaseObjects->clear();
+  mybaseObjects->append(theSketch.feature()->firstResult(), GeomShapePtr());
+
+  execIfBaseNotEmpty();
 }
 
 //==================================================================================================
 void FeaturesAPI_Extrusion::setBase(const std::list<ModelHighAPI_Selection>& theBaseObjects)
 {
+  mysketch->setValue(ObjectPtr());
+  mybaseObjects->clear();
   fillAttribute(theBaseObjects, mybaseObjects);
 
-  execute();
+  execIfBaseNotEmpty();
 }
 
 //==================================================================================================
@@ -122,7 +134,7 @@ void FeaturesAPI_Extrusion::setDirection(const ModelHighAPI_Selection& theDirect
 {
   fillAttribute(theDirection, mydirection);
 
-  execute();
+  execIfBaseNotEmpty();
 }
 
 //==================================================================================================
@@ -133,7 +145,7 @@ void FeaturesAPI_Extrusion::setSizes(const ModelHighAPI_Double& theToSize,
   fillAttribute(theToSize, mytoSize);
   fillAttribute(theFromSize, myfromSize);
 
-  execute();
+  execIfBaseNotEmpty();
 }
 
 //==================================================================================================
@@ -143,7 +155,7 @@ void FeaturesAPI_Extrusion::setSize(const ModelHighAPI_Double& theSize)
   fillAttribute(theSize, mytoSize);
   fillAttribute(ModelHighAPI_Double(), myfromSize);
 
-  execute();
+  execIfBaseNotEmpty();
 }
 
 //==================================================================================================
@@ -158,7 +170,7 @@ void FeaturesAPI_Extrusion::setPlanesAndOffsets(const ModelHighAPI_Selection& th
   fillAttribute(theFromObject, myfromObject);
   fillAttribute(theFromOffset, myfromOffset);
 
-  execute();
+  execIfBaseNotEmpty();
 }
 
 //==================================================================================================
@@ -167,10 +179,10 @@ void FeaturesAPI_Extrusion::dump(ModelHighAPI_Dumper& theDumper) const
   FeaturePtr aBase = feature();
   const std::string& aDocName = theDumper.name(aBase->document());
 
-  AttributeSelectionListPtr anObjects = aBase->selectionList(FeaturesPlugin_Extrusion::BASE_OBJECTS_ID());
-  AttributeSelectionPtr aDirection = aBase->selection(FeaturesPlugin_Extrusion::DIRECTION_OBJECT_ID());
+  AttributeSelectionListPtr anAttrObjects = aBase->selectionList(FeaturesPlugin_Extrusion::BASE_OBJECTS_ID());
+  AttributeSelectionPtr anAttrDirection = aBase->selection(FeaturesPlugin_Extrusion::DIRECTION_OBJECT_ID());
 
-  theDumper << aBase << " = model.addExtrusion(" << aDocName << ", " << anObjects << ", " << aDirection;
+  theDumper << aBase << " = model.addExtrusion(" << aDocName << ", " << anAttrObjects << ", " << anAttrDirection;
 
   std::string aCreationMethod = aBase->string(FeaturesPlugin_Extrusion::CREATION_METHOD())->value();
 
@@ -189,6 +201,18 @@ void FeaturesAPI_Extrusion::dump(ModelHighAPI_Dumper& theDumper) const
   }
 
   theDumper << ")" << std::endl;
+
+  AttributeReferencePtr anAttrSketch = aBase->reference(FeaturesPlugin_CompositeSketch::SKETCH_ID());
+  if(anAttrSketch->isInitialized()) {
+    theDumper << aBase << ".setNestedSketch(" << anAttrSketch << ")";
+  }
+}
+
+void FeaturesAPI_Extrusion::execIfBaseNotEmpty()
+{
+  if(mybaseObjects->size() > 0) {
+    execute();
+  }
 }
 
 //==================================================================================================
index 456da2c044457ea3fe4a4af850ae1358a0631f1f..e4a31b18c0bcdc65cc2be47b2a0ae62adc7f32e6 100644 (file)
@@ -15,6 +15,7 @@
 #include <ModelHighAPI_Macro.h>
 
 class ModelHighAPI_Double;
+class ModelHighAPI_Reference;
 class ModelHighAPI_Selection;
 
 /// \class FeaturesAPI_Extrusion
@@ -77,7 +78,8 @@ public:
   FEATURESAPI_EXPORT
   virtual ~FeaturesAPI_Extrusion();
 
-  INTERFACE_10(FeaturesPlugin_Extrusion::ID(),
+  INTERFACE_11(FeaturesPlugin_Extrusion::ID(),
+               sketch, FeaturesPlugin_Extrusion::SKETCH_ID(), ModelAPI_AttributeReference, /** Sketch object */,
                baseObjects, FeaturesPlugin_Extrusion::BASE_OBJECTS_ID(), ModelAPI_AttributeSelectionList, /** Base objects */,
                creationMethod, FeaturesPlugin_Extrusion::CREATION_METHOD(), ModelAPI_AttributeString, /** Creation method */,
                toSize, FeaturesPlugin_Extrusion::TO_SIZE_ID(), ModelAPI_AttributeDouble, /** To size */,
@@ -89,6 +91,10 @@ public:
                direction, FeaturesPlugin_Extrusion::DIRECTION_OBJECT_ID(), ModelAPI_AttributeSelection, /** Direction */,
                sketchLauncher, FeaturesPlugin_Extrusion::SKETCH_ID(), ModelAPI_AttributeReference, /** Sketch launcher */)
 
+  /// Modify base attribute of the feature.
+  FEATURESAPI_EXPORT
+  void setNestedSketch(const ModelHighAPI_Reference& theSketch);
+
   /// Modify base attribute of the feature.
   FEATURESAPI_EXPORT
   void setBase(const std::list<ModelHighAPI_Selection>& theBaseObjects);
@@ -115,6 +121,9 @@ public:
   /// Dump wrapped feature
   FEATURESAPI_EXPORT
   virtual void dump(ModelHighAPI_Dumper& theDumper) const;
+
+private:
+  void execIfBaseNotEmpty();
 };
 
 /// Pointer on Extrusion object.
index 3e13a0b463d95f32fef462b83c9500c287d0d2d8..20a07f53b12dc9323c034eaf8c4c430bab101590 100644 (file)
@@ -44,3 +44,9 @@ void ModelHighAPI_Reference::appendToList(
 {
   theAttribute->append(myObject);
 }
+
+//--------------------------------------------------------------------------------------
+std::shared_ptr<ModelAPI_Feature> ModelHighAPI_Reference::feature() const
+{
+  return ModelAPI_Feature::feature(myObject);
+}
index 71a6f2acaed2eb8394d06a258744c7325f416a5a..f960791ce14b8b8e6db7fd64de81e75a1218ec4b 100644 (file)
@@ -16,6 +16,7 @@
 class ModelAPI_Attribute;
 class ModelAPI_AttributeReference;
 class ModelAPI_AttributeRefList;
+class ModelAPI_Feature;
 class ModelAPI_Object;
 class ModelHighAPI_Interface;
 //--------------------------------------------------------------------------------------
@@ -47,6 +48,10 @@ public:
   MODELHIGHAPI_EXPORT
   virtual void appendToList(const std::shared_ptr<ModelAPI_AttributeRefList> & theAttribute) const;
 
+  /// Returns feature for this object.
+  MODELHIGHAPI_EXPORT
+  virtual std::shared_ptr<ModelAPI_Feature> feature() const;
+
 private:
   std::shared_ptr<ModelAPI_Object> myObject;
 };