]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #1648: Dump Python in the High Level Parameterized Geometry API
authordbv <dbv@opencascade.com>
Tue, 9 Aug 2016 14:01:40 +0000 (17:01 +0300)
committerdbv <dbv@opencascade.com>
Tue, 9 Aug 2016 14:01:58 +0000 (17:01 +0300)
1. Empty constructor for ModelHighAPI_Selection (for not obligatory attributes);
2. Overloaded operator<< for ModelHighAPI_Dumper which takes ModelAPI_AttributeSelectionList;
3. Dump for FeaturesAPI_Extrusion.

src/FeaturesAPI/FeaturesAPI_Extrusion.cpp
src/FeaturesAPI/FeaturesAPI_Extrusion.h
src/ModelHighAPI/ModelHighAPI_Dumper.cpp
src/ModelHighAPI/ModelHighAPI_Dumper.h
src/ModelHighAPI/ModelHighAPI_Selection.cpp
src/ModelHighAPI/ModelHighAPI_Selection.h

index d79749b5f28389b1114568008bcb158d71327588..f2dd6e6d793ee15de7bd5d0394d10c1573cd4c89 100644 (file)
@@ -7,6 +7,7 @@
 #include "FeaturesAPI_Extrusion.h"
 
 #include <ModelHighAPI_Double.h>
+#include <ModelHighAPI_Dumper.h>
 #include <ModelHighAPI_Tools.h>
 
 //==================================================================================================
@@ -160,6 +161,36 @@ void FeaturesAPI_Extrusion::setPlanesAndOffsets(const ModelHighAPI_Selection& th
   execute();
 }
 
+//==================================================================================================
+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());
+
+  theDumper << aBase << " = model.addExtrusion(" << aDocName << ", " << anObjects << ", " << aDirection;
+
+  std::string aCreationMethod = aBase->string(FeaturesPlugin_Extrusion::CREATION_METHOD())->value();
+
+  if(aCreationMethod == FeaturesPlugin_Extrusion::CREATION_METHOD_BY_SIZES()) {
+    AttributeDoublePtr anAttrToSize = aBase->real(FeaturesPlugin_Extrusion::TO_SIZE_ID());
+    AttributeDoublePtr anAttrFromSize = aBase->real(FeaturesPlugin_Extrusion::FROM_SIZE_ID());
+
+    theDumper << ", " << anAttrToSize << ", " << anAttrFromSize;
+  } else if(aCreationMethod == FeaturesPlugin_Extrusion::CREATION_METHOD_BY_PLANES()) {
+    AttributeSelectionPtr anAttrToObject = aBase->selection(FeaturesPlugin_Extrusion::TO_OBJECT_ID());
+    AttributeDoublePtr anAttrToOffset = aBase->real(FeaturesPlugin_Extrusion::TO_OFFSET_ID());
+    AttributeSelectionPtr anAttrFromObject = aBase->selection(FeaturesPlugin_Extrusion::FROM_OBJECT_ID());
+    AttributeDoublePtr anAttrFromOffset = aBase->real(FeaturesPlugin_Extrusion::FROM_OFFSET_ID());
+
+    theDumper << ", " << anAttrToObject << ", " << anAttrToOffset << ", " << anAttrFromObject << ", " << anAttrFromOffset;
+  }
+
+  theDumper << ")" << std::endl;
+}
+
 //==================================================================================================
 ExtrusionPtr addExtrusion(const std::shared_ptr<ModelAPI_Document>& thePart,
                           const std::list<ModelHighAPI_Selection>& theBaseObjects,
index 2c569802f942c7a48db6e82bd913c0b68c0d8a65..f2ca23485e8176a367fcafef9b3b207a2054a1a9 100644 (file)
@@ -111,6 +111,10 @@ public:
                            const ModelHighAPI_Double& theToOffset,
                            const ModelHighAPI_Selection& theFromObject,
                            const ModelHighAPI_Double& theFromOffset);
+
+    /// Dump wrapped feature
+  FEATURESAPI_EXPORT
+  virtual void dump(ModelHighAPI_Dumper& theDumper) const;
 };
 
 /// Pointer on Extrusion object.
index ee7894f50975a0bea84cf67e59c065ed187fd39e..72d4623cc8f85345e737b76ab8b49454af458ebf 100644 (file)
@@ -19,6 +19,7 @@
 #include <ModelAPI_AttributeInteger.h>
 #include <ModelAPI_AttributeRefAttr.h>
 #include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_AttributeString.h>
 #include <ModelAPI_CompositeFeature.h>
 #include <ModelAPI_Document.h>
@@ -395,18 +396,57 @@ ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(
 ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(
     const std::shared_ptr<ModelAPI_AttributeSelection>& theAttrSelect)
 {
+  myDumpBuffer << "model.selection(";
+
+  if(!theAttrSelect->isInitialized()) {
+    myDumpBuffer << ")";
+    return *this;
+  }
+
   GeomShapePtr aShape = theAttrSelect->value();
   if(!aShape.get()) {
     aShape = theAttrSelect->context()->shape();
   }
 
   if(!aShape.get()) {
+    myDumpBuffer << ")";
     return *this;
   }
 
-  std::string aShapeTypeStr = aShape->shapeTypeStr();
+  myDumpBuffer << "\"" << aShape->shapeTypeStr() << "\", \"" << theAttrSelect->namingName() << "\")";
+  return *this;
+}
+
+ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(
+    const std::shared_ptr<ModelAPI_AttributeSelectionList>& theAttrSelList)
+{
+  myDumpBuffer << "[";
+
+  GeomShapePtr aShape;
+  std::string aShapeTypeStr;
+
+  bool isAdded = false;
+
+  for(int anIndex = 0; anIndex < theAttrSelList->size(); ++anIndex) {
+    AttributeSelectionPtr anAttribute = theAttrSelList->value(anIndex);
+    aShape = anAttribute->value();
+    if(!aShape.get()) {
+      aShape = anAttribute->context()->shape();
+    }
+
+    if(!aShape.get()) {
+      continue;
+    }
+
+    if(isAdded) {
+      myDumpBuffer << ", ";
+    } else {
+      isAdded = true;
+    }
+    myDumpBuffer << "model.selection(\"" << aShape->shapeTypeStr() << "\", \"" << anAttribute->namingName() << "\")";
+  }
 
-  myDumpBuffer << "model.selection(\"" << aShapeTypeStr << "\", \"" << theAttrSelect->namingName() << "\")";
+  myDumpBuffer << "]";
   return *this;
 }
 
index 200262fdb5c85d7417dd327fd29efd6a2dc2cf7f..30cdce0883d38bcda70ec674527973e5d149690d 100644 (file)
@@ -27,6 +27,7 @@ class ModelAPI_AttributeDouble;
 class ModelAPI_AttributeInteger;
 class ModelAPI_AttributeRefAttr;
 class ModelAPI_AttributeSelection;
+class ModelAPI_AttributeSelectionList;
 class ModelAPI_AttributeString;
 class ModelAPI_CompositeFeature;
 class ModelAPI_Document;
@@ -154,6 +155,9 @@ public:
   /// Dump AttributeSelection
   MODELHIGHAPI_EXPORT
   ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeSelection>& theAttrSelect);
+  /// Dump AttributeSelectionList
+  MODELHIGHAPI_EXPORT
+  ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeSelectionList>& theAttrSelList);
 
   /// Clear dump buffer
   MODELHIGHAPI_EXPORT
index 1a7e90cc0391f88be5ce50a3cb4bd60c77f85eda..c2540b8f51a30d29cf1512265e661e9f292addfd 100644 (file)
 //--------------------------------------------------------------------------------------
 
 //--------------------------------------------------------------------------------------
+ModelHighAPI_Selection::ModelHighAPI_Selection()
+: myVariantType(VT_Empty)
+{
+}
+
 ModelHighAPI_Selection::ModelHighAPI_Selection(const std::shared_ptr<ModelAPI_Result>& theContext,
                                                const std::shared_ptr<GeomAPI_Shape>& theSubShape)
 : myVariantType(VT_ResultSubShapePair)
@@ -35,6 +40,7 @@ void ModelHighAPI_Selection::fillAttribute(
     const std::shared_ptr<ModelAPI_AttributeSelection> & theAttribute) const
 {
   switch(myVariantType) {
+    case VT_Empty: return;
     case VT_ResultSubShapePair: theAttribute->setValue(myResultSubShapePair.first, myResultSubShapePair.second); return;
     case VT_TypeSubShapeNamePair: theAttribute->selectSubShape(myTypeSubShapeNamePair.first, myTypeSubShapeNamePair.second); return;
   }
@@ -45,6 +51,7 @@ void ModelHighAPI_Selection::appendToList(
     const std::shared_ptr<ModelAPI_AttributeSelectionList> & theAttribute) const
 {
   switch(myVariantType) {
+    case VT_Empty: return;
     case VT_ResultSubShapePair: theAttribute->append(myResultSubShapePair.first, myResultSubShapePair.second); return;
     case VT_TypeSubShapeNamePair:
       // Note: the reverse order (first - type, second - sub-shape name)
index 2a72733197c78190291cd789f8c0827845a054fe..e559228b6fe206cf4410abdc43b678f95b31bafa 100644 (file)
@@ -30,14 +30,19 @@ class ModelHighAPI_Selection
 {
 public:
   enum VariantType {
+    VT_Empty,
     VT_ResultSubShapePair,
     VT_TypeSubShapeNamePair
   };
 
 public:
+  /// Default constructor with empty selection.
+  MODELHIGHAPI_EXPORT
+  ModelHighAPI_Selection();
+
   /// Constructor for result and sub-shape
   MODELHIGHAPI_EXPORT
-  ModelHighAPI_Selection(const std::shared_ptr<ModelAPI_Result>& theContext = std::shared_ptr<ModelAPI_Result>(),
+  ModelHighAPI_Selection(const std::shared_ptr<ModelAPI_Result>& theContext,
                          const std::shared_ptr<GeomAPI_Shape>& theSubShape = std::shared_ptr<GeomAPI_Shape>());
   /// Constructor for sub-shape by the textual Name
   MODELHIGHAPI_EXPORT