Salome HOME
Issue #1648: Dump Python in the High Level Parameterized Geometry API
authordbv <dbv@opencascade.com>
Tue, 16 Aug 2016 07:40:14 +0000 (10:40 +0300)
committerdbv <dbv@opencascade.com>
Tue, 16 Aug 2016 07:54:52 +0000 (10:54 +0300)
Dump for FeaturesAPI_RevolutionCut and FeaturesAPI_RevolutionFuse

src/FeaturesAPI/FeaturesAPI_RevolutionBoolean.cpp
src/FeaturesAPI/FeaturesAPI_RevolutionBoolean.h

index 3ca6f2b7d55612da19c0cbd3bfe6816cd2c3e730..097fbfbdb5accf241bebb7141061c74fe77c42dd 100644 (file)
@@ -7,6 +7,8 @@
 #include "FeaturesAPI_RevolutionBoolean.h"
 
 #include <ModelHighAPI_Double.h>
+#include <ModelHighAPI_Dumper.h>
+#include <ModelHighAPI_Reference.h>
 #include <ModelHighAPI_Tools.h>
 
 //==================================================================================================
@@ -20,12 +22,24 @@ FeaturesAPI_RevolutionBoolean::~FeaturesAPI_RevolutionBoolean()
 {
 }
 
+//==================================================================================================
+void FeaturesAPI_RevolutionBoolean::setNestedSketch(const ModelHighAPI_Reference& theSketch)
+{
+  mysketch->setValue(theSketch.feature());
+  mybaseObjects->clear();
+  mybaseObjects->append(theSketch.feature()->firstResult(), GeomShapePtr());
+
+  execIfBaseNotEmpty();
+}
+
 //==================================================================================================
 void FeaturesAPI_RevolutionBoolean::setBase(const std::list<ModelHighAPI_Selection>& theBaseObjects)
 {
+  mysketch->setValue(ObjectPtr());
+  mybaseObjects->clear();
   fillAttribute(theBaseObjects, mybaseObjects);
 
-  execute();
+  execIfBaseNotEmpty();
 }
 
 //==================================================================================================
@@ -33,7 +47,7 @@ void FeaturesAPI_RevolutionBoolean::setAxis(const ModelHighAPI_Selection& theAxi
 {
   fillAttribute(theAxis, myaxis);
 
-  execute();
+  execIfBaseNotEmpty();
 }
 
 //==================================================================================================
@@ -44,7 +58,7 @@ void FeaturesAPI_RevolutionBoolean::setAngles(const ModelHighAPI_Double& theToAn
   fillAttribute(theToAngle, mytoAngle);
   fillAttribute(theFromAngle, myfromAngle);
 
-  execute();
+  execIfBaseNotEmpty();
 }
 
 //==================================================================================================
@@ -54,7 +68,7 @@ void FeaturesAPI_RevolutionBoolean::setAngle(const ModelHighAPI_Double& theAngle
   fillAttribute(theAngle, mytoAngle);
   fillAttribute(ModelHighAPI_Double(), myfromAngle);
 
-  execute();
+  execIfBaseNotEmpty();
 }
 
 //==================================================================================================
@@ -69,7 +83,7 @@ void FeaturesAPI_RevolutionBoolean::setPlanesAndOffsets(const ModelHighAPI_Selec
   fillAttribute(theFromObject, myfromObject);
   fillAttribute(theFromOffset, myfromOffset);
 
-  execute();
+  execIfBaseNotEmpty();
 }
 
 //==================================================================================================
@@ -77,7 +91,59 @@ void FeaturesAPI_RevolutionBoolean::setBooleanObjects(const std::list<ModelHighA
 {
   fillAttribute(theBooleanObjects, mybooleanObjects);
 
-  execute();
+  execIfBaseNotEmpty();
+}
+
+//==================================================================================================
+void FeaturesAPI_RevolutionBoolean::dump(ModelHighAPI_Dumper& theDumper) const
+{
+  FeaturePtr aBase = feature();
+  const std::string& aDocName = theDumper.name(aBase->document());
+
+  AttributeReferencePtr anAttrSketch = aBase->reference(FeaturesPlugin_Revolution::SKETCH_ID());
+  AttributeSelectionListPtr anAttrObjects = aBase->selectionList(FeaturesPlugin_Revolution::BASE_OBJECTS_ID());
+  AttributeSelectionPtr anAttrAxis = aBase->selection(FeaturesPlugin_Revolution::AXIS_OBJECT_ID());
+
+  theDumper << aBase << " = model.addRevolution";
+  if(aBase->getKind() == FeaturesPlugin_RevolutionCut::ID()) {
+    theDumper << "Cut";
+  } else if(aBase->getKind() == FeaturesPlugin_RevolutionFuse::ID()) {
+    theDumper << "Fuse";
+  }
+  theDumper << "(" << aDocName << ", ";
+  anAttrSketch->isInitialized() ? theDumper << "[]" : theDumper << anAttrObjects;
+  theDumper << ", " << anAttrAxis;
+
+  std::string aCreationMethod = aBase->string(FeaturesPlugin_Revolution::CREATION_METHOD())->value();
+
+  if(aCreationMethod == FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES()) {
+    AttributeDoublePtr anAttrToAngle = aBase->real(FeaturesPlugin_Revolution::TO_ANGLE_ID());
+    AttributeDoublePtr anAttrFromAngle = aBase->real(FeaturesPlugin_Revolution::FROM_ANGLE_ID());
+
+    theDumper << ", " << anAttrToAngle << ", " << anAttrFromAngle;
+  } else if(aCreationMethod == FeaturesPlugin_Revolution::CREATION_METHOD_BY_PLANES()) {
+    AttributeSelectionPtr anAttrToObject = aBase->selection(FeaturesPlugin_Revolution::TO_OBJECT_ID());
+    AttributeDoublePtr anAttrToOffset = aBase->real(FeaturesPlugin_Revolution::TO_OFFSET_ID());
+    AttributeSelectionPtr anAttrFromObject = aBase->selection(FeaturesPlugin_Revolution::FROM_OBJECT_ID());
+    AttributeDoublePtr anAttrFromOffset = aBase->real(FeaturesPlugin_Revolution::FROM_OFFSET_ID());
+
+    theDumper << ", " << anAttrToObject << ", " << anAttrToOffset << ", " << anAttrFromObject << ", " << anAttrFromOffset;
+  }
+
+  AttributeSelectionListPtr anAttrBoolObjects = aBase->selectionList(FeaturesPlugin_CompositeBoolean::OBJECTS_ID());
+  theDumper << ", " << anAttrBoolObjects << ")" << std::endl;
+
+  if(anAttrSketch->isInitialized()) {
+    theDumper << aBase << ".setNestedSketch(" << anAttrSketch << ")" << std::endl;
+  }
+}
+
+//==================================================================================================
+void FeaturesAPI_RevolutionBoolean::execIfBaseNotEmpty()
+{
+  if(mybaseObjects->size() > 0) {
+    execute();
+  }
 }
 
 //==================================================================================================
@@ -98,6 +164,7 @@ FeaturesAPI_RevolutionCut::FeaturesAPI_RevolutionCut(const std::shared_ptr<Model
   if(initialize()) {
     fillAttribute(theBaseObjects, mybaseObjects);
     fillAttribute(theAxis, myaxis);
+    fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
     fillAttribute(theSize, mytoAngle);
     fillAttribute(ModelHighAPI_Double(), myfromAngle);
     setBooleanObjects(theBooleanObjects);
@@ -116,6 +183,7 @@ FeaturesAPI_RevolutionCut::FeaturesAPI_RevolutionCut(const std::shared_ptr<Model
   if(initialize()) {
     fillAttribute(theBaseObjects, mybaseObjects);
     fillAttribute(theAxis, myaxis);
+    fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
     fillAttribute(theToAngle, mytoAngle);
     fillAttribute(theFromAngle, myfromAngle);
     setBooleanObjects(theBooleanObjects);
@@ -136,6 +204,7 @@ FeaturesAPI_RevolutionCut::FeaturesAPI_RevolutionCut(const std::shared_ptr<Model
   if(initialize()) {
     fillAttribute(theBaseObjects, mybaseObjects);
     fillAttribute(theAxis, myaxis);
+    fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_PLANES(), mycreationMethod);
     fillAttribute(theToObject, mytoObject);
     fillAttribute(theToOffset, mytoOffset);
     fillAttribute(theFromObject, myfromObject);
@@ -212,6 +281,7 @@ FeaturesAPI_RevolutionFuse::FeaturesAPI_RevolutionFuse(const std::shared_ptr<Mod
   if(initialize()) {
     fillAttribute(theBaseObjects, mybaseObjects);
     fillAttribute(theAxis, myaxis);
+    fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
     fillAttribute(theSize, mytoAngle);
     fillAttribute(ModelHighAPI_Double(), myfromAngle);
     setBooleanObjects(theBooleanObjects);
@@ -230,6 +300,7 @@ FeaturesAPI_RevolutionFuse::FeaturesAPI_RevolutionFuse(const std::shared_ptr<Mod
   if(initialize()) {
     fillAttribute(theBaseObjects, mybaseObjects);
     fillAttribute(theAxis, myaxis);
+    fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES(), mycreationMethod);
     fillAttribute(theToAngle, mytoAngle);
     fillAttribute(theFromAngle, myfromAngle);
     setBooleanObjects(theBooleanObjects);
@@ -250,6 +321,7 @@ FeaturesAPI_RevolutionFuse::FeaturesAPI_RevolutionFuse(const std::shared_ptr<Mod
   if(initialize()) {
     fillAttribute(theBaseObjects, mybaseObjects);
     fillAttribute(theAxis, myaxis);
+    fillAttribute(FeaturesPlugin_Revolution::CREATION_METHOD_BY_PLANES(), mycreationMethod);
     fillAttribute(theToObject, mytoObject);
     fillAttribute(theToOffset, mytoOffset);
     fillAttribute(theFromObject, myfromObject);
index 679eb58317eddf25f7ce06a3ccf6d9784ff0ec33..bc5942242d9bb78ee22e54bf69cf63e1291edcf1 100644 (file)
@@ -17,6 +17,8 @@
 #include <ModelHighAPI_Macro.h>
 
 class ModelHighAPI_Double;
+class ModelHighAPI_Dumper;
+class ModelHighAPI_Reference;
 class ModelHighAPI_Selection;
 
 /// \class FeaturesAPI_RevolutionBoolean
@@ -30,7 +32,7 @@ public:
   virtual ~FeaturesAPI_RevolutionBoolean();
 
   INTERFACE_11("",
-               sketchLauncher, FeaturesPlugin_Revolution::SKETCH_ID(), ModelAPI_AttributeReference, /** Sketch launcher */,
+               sketch, FeaturesPlugin_Revolution::SKETCH_ID(), ModelAPI_AttributeReference, /** Sketch launcher */,
                baseObjects, FeaturesPlugin_Revolution::BASE_OBJECTS_ID(), ModelAPI_AttributeSelectionList, /** Base objects */,
                axis, FeaturesPlugin_Revolution::AXIS_OBJECT_ID(), ModelAPI_AttributeSelection, /** Axis */,
                creationMethod, FeaturesPlugin_Revolution::CREATION_METHOD(), ModelAPI_AttributeString, /** Creation method */,
@@ -42,6 +44,10 @@ public:
                fromOffset, FeaturesPlugin_Revolution::FROM_OFFSET_ID(), ModelAPI_AttributeDouble, /** From offset */,
                booleanObjects, FeaturesPlugin_CompositeBoolean::OBJECTS_ID(), ModelAPI_AttributeSelectionList, /** Boolean objects */)
 
+  /// 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);
@@ -69,19 +75,25 @@ public:
   FEATURESAPI_EXPORT
   void setBooleanObjects(const std::list<ModelHighAPI_Selection>& theBooleanObjects);
 
+  /// Dump wrapped feature
+  FEATURESAPI_EXPORT
+  virtual void dump(ModelHighAPI_Dumper& theDumper) const;
+
 protected:
   /// Constructor without values.
   FEATURESAPI_EXPORT
   explicit FeaturesAPI_RevolutionBoolean(const std::shared_ptr<ModelAPI_Feature>& theFeature);
+
+private:
+  void execIfBaseNotEmpty();
 };
 
 class FeaturesAPI_RevolutionCut: public FeaturesAPI_RevolutionBoolean
 {
 public:
-  FEATURESAPI_EXPORT
-  virtual std::string getID() {
-    return FeaturesPlugin_RevolutionCut::ID();
-  }
+
+  static std::string ID() { return FeaturesPlugin_RevolutionCut::ID(); }
+  virtual std::string getID() { return ID(); }
 
   /// Constructor without values.
   FEATURESAPI_EXPORT
@@ -153,10 +165,9 @@ RevolutionCutPtr addRevolutionCut(const std::shared_ptr<ModelAPI_Document>& theP
 class FeaturesAPI_RevolutionFuse: public FeaturesAPI_RevolutionBoolean
 {
 public:
-  FEATURESAPI_EXPORT
-  virtual std::string getID() {
-    return FeaturesPlugin_RevolutionFuse::ID();
-  }
+
+  static std::string ID() { return FeaturesPlugin_RevolutionFuse::ID(); }
+  virtual std::string getID() { return ID(); }
 
   /// Constructor without values.
   FEATURESAPI_EXPORT