]> 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>
Mon, 8 Aug 2016 14:35:30 +0000 (17:35 +0300)
committerdbv <dbv@opencascade.com>
Mon, 8 Aug 2016 14:35:30 +0000 (17:35 +0300)
Added dump for Construction features Axis and Plane.

src/ConstructionAPI/ConstructionAPI_Axis.cpp
src/ConstructionAPI/ConstructionAPI_Axis.h
src/ConstructionAPI/ConstructionAPI_Plane.cpp
src/ConstructionAPI/ConstructionAPI_Plane.h
src/GeomAPI/GeomAPI_Shape.cpp
src/ModelHighAPI/ModelHighAPI_Dumper.cpp
src/ModelHighAPI/ModelHighAPI_Tools.cpp
src/ModelHighAPI/ModelHighAPI_Tools.h
src/PythonAPI/model/services/__init__.py

index 132adba5124a93bf623cbb65a9f05b0913d46054..399017fea881a8992e3a3a6590b92ff302405d7c 100644 (file)
@@ -6,6 +6,7 @@
 
 #include "ConstructionAPI_Axis.h"
 
+#include <ModelHighAPI_Dumper.h>
 #include <ModelHighAPI_Tools.h>
 
 //==================================================================================================
@@ -196,14 +197,70 @@ void ConstructionAPI_Axis::setByTwoPlanes(const ModelHighAPI_Selection& thePlane
   execute();
 }
 
+//==================================================================================================
+void ConstructionAPI_Axis::dump(ModelHighAPI_Dumper& theDumper) const
+{
+  FeaturePtr aBase = feature();
+  const std::string& aDocName = theDumper.name(aBase->document());
+
+  theDumper << aBase << " = model.addAxis(" << aDocName;
+
+  std::string aCreationMethod = aBase->string(ConstructionPlugin_Axis::METHOD())->value();
+
+  if(aCreationMethod == ConstructionPlugin_Axis::CREATION_METHOD_BY_DIMENSIONS()) {
+    AttributeDoublePtr anAttrDX = aBase->real(ConstructionPlugin_Axis::DX());
+    AttributeDoublePtr anAttrDY = aBase->real(ConstructionPlugin_Axis::DY());
+    AttributeDoublePtr anAttrDZ = aBase->real(ConstructionPlugin_Axis::DZ());
+
+    theDumper << ", " << anAttrDX << ", " << anAttrDY << ", " << anAttrDZ;
+  } else if(aCreationMethod == ConstructionPlugin_Axis::CREATION_METHOD_BY_TWO_POINTS()) {
+    AttributeSelectionPtr anAttrFirstPnt = aBase->selection(ConstructionPlugin_Axis::POINT_FIRST());
+    AttributeSelectionPtr anAttrSecondPnt = aBase->selection(ConstructionPlugin_Axis::POINT_SECOND());
+
+    theDumper << ", " << anAttrFirstPnt << ", " << anAttrSecondPnt;
+  } else if(aCreationMethod == ConstructionPlugin_Axis::CREATION_METHOD_BY_LINE()) {
+    AttributeSelectionPtr anAttrLine = aBase->selection(ConstructionPlugin_Axis::LINE());
+
+    theDumper << ", " << anAttrLine;
+  } else if(aCreationMethod == ConstructionPlugin_Axis::CREATION_METHOD_BY_CYLINDRICAL_FACE()) {
+    AttributeSelectionPtr anAttrFace = aBase->selection(ConstructionPlugin_Axis::CYLINDRICAL_FACE());
+
+    theDumper << ", " << anAttrFace;
+  } else if(aCreationMethod == ConstructionPlugin_Axis::CREATION_METHOD_BY_PLANE_AND_POINT()) {
+    AttributeSelectionPtr anAttrPlane = aBase->selection(ConstructionPlugin_Axis::PLANE());
+    AttributeSelectionPtr anAttrPoint = aBase->selection(ConstructionPlugin_Axis::POINT());
+
+    theDumper << ", " << anAttrPlane << ", " << anAttrPoint;
+  } else if(aCreationMethod == ConstructionPlugin_Axis::CREATION_METHOD_BY_TWO_PLANES()) {
+    AttributeSelectionPtr anAttrPlane1 = aBase->selection(ConstructionPlugin_Axis::PLANE1());
+    AttributeDoublePtr anAttrOffset1 = aBase->real(ConstructionPlugin_Axis::OFFSET1());
+    AttributeBooleanPtr anAttrReverseOffset1 = aBase->boolean(ConstructionPlugin_Axis::REVERSE_OFFSET1());
+    AttributeSelectionPtr anAttrPlane2 = aBase->selection(ConstructionPlugin_Axis::PLANE2());
+    AttributeDoublePtr anAttrOffset2 = aBase->real(ConstructionPlugin_Axis::OFFSET2());
+    AttributeBooleanPtr anAttrReverseOffset2 = aBase->boolean(ConstructionPlugin_Axis::REVERSE_OFFSET2());
+
+    theDumper << ", " << anAttrPlane1 << ", " << anAttrOffset1 << ", " << anAttrReverseOffset1
+              << ", " << anAttrPlane2 << ", " << anAttrOffset2 << ", " << anAttrReverseOffset2;
+  } else if(aCreationMethod == ConstructionPlugin_Axis::CREATION_METHOD_BY_POINT_AND_DIRECTION()) {
+    AttributeSelectionPtr anAttrFirstPnt = aBase->selection(ConstructionPlugin_Axis::POINT_FIRST());
+    AttributeDoublePtr anAttrX = aBase->real(ConstructionPlugin_Axis::X_DIRECTION());
+    AttributeDoublePtr anAttrY = aBase->real(ConstructionPlugin_Axis::Y_DIRECTION());
+    AttributeDoublePtr anAttrZ = aBase->real(ConstructionPlugin_Axis::Z_DIRECTION());
+
+    theDumper << ", " << anAttrFirstPnt << ", " << anAttrX << ", " << anAttrY << ", " << anAttrZ;
+  }
+
+  theDumper << ")" << std::endl;
+}
+
 //==================================================================================================
 AxisPtr addAxis(const std::shared_ptr<ModelAPI_Document>& thePart,
-                const ModelHighAPI_Selection& thePoint1,
-                const ModelHighAPI_Selection& thePoint2)
+                const ModelHighAPI_Selection& theObject1,
+                const ModelHighAPI_Selection& theObject2)
 {
   // TODO(spo): check that thePart is not empty
   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Axis::ID());
-  return AxisPtr(new ConstructionAPI_Axis(aFeature, thePoint1, thePoint2));
+  return AxisPtr(new ConstructionAPI_Axis(aFeature, theObject1, theObject2));
 }
 
 //==================================================================================================
index 0b62587a637ac2a0d3e85d80cd188877d2ab6ee9..fc6bbbc1936fbf96ee7a32b685bfc290039c05b4 100644 (file)
@@ -137,6 +137,10 @@ public:
                       const ModelHighAPI_Selection& thePlane2,
                       const ModelHighAPI_Double& theOffset2,
                       const bool theReverseOffset2);
+
+  /// Dump wrapped feature
+  CONSTRUCTIONAPI_EXPORT
+  virtual void dump(ModelHighAPI_Dumper& theDumper) const;
 };
 
 /// Pointer on Axis object
index fdde03ebb39359a00f0d148482e3a5e057e90fc8..b7de5703c0b882fc8e56067c416ce264c13914ab 100644 (file)
@@ -6,6 +6,7 @@
 
 #include "ConstructionAPI_Plane.h"
 
+#include <ModelHighAPI_Dumper.h>
 #include <ModelHighAPI_Tools.h>
 
 //==================================================================================================
@@ -190,6 +191,65 @@ void ConstructionAPI_Plane::setByRotation(const ModelHighAPI_Selection& thePlane
   execute();
 }
 
+//==================================================================================================
+void ConstructionAPI_Plane::dump(ModelHighAPI_Dumper& theDumper) const
+{
+  FeaturePtr aBase = feature();
+  const std::string& aDocName = theDumper.name(aBase->document());
+
+  theDumper << aBase << " = model.addPlane(" << aDocName;
+
+  std::string aCreationMethod = aBase->string(ConstructionPlugin_Plane::CREATION_METHOD())->value();
+
+  if(aCreationMethod == ConstructionPlugin_Plane::CREATION_METHOD_BY_GENERAL_EQUATION()) {
+    AttributeDoublePtr anAttrA = aBase->real(ConstructionPlugin_Plane::A());
+    AttributeDoublePtr anAttrB = aBase->real(ConstructionPlugin_Plane::B());
+    AttributeDoublePtr anAttrC = aBase->real(ConstructionPlugin_Plane::C());
+    AttributeDoublePtr anAttrD = aBase->real(ConstructionPlugin_Plane::D());
+
+    theDumper << ", " << anAttrA << ", " << anAttrB << ", " << anAttrC << ", " << anAttrD;
+  } else if(aCreationMethod == ConstructionPlugin_Plane::CREATION_METHOD_BY_THREE_POINTS()) {
+    AttributeSelectionPtr anAttrPnt1 = aBase->selection(ConstructionPlugin_Plane::POINT1());
+    AttributeSelectionPtr anAttrPnt2 = aBase->selection(ConstructionPlugin_Plane::POINT2());
+    AttributeSelectionPtr anAttrPnt3 = aBase->selection(ConstructionPlugin_Plane::POINT3());
+
+    theDumper << ", " << anAttrPnt1 << ", " << anAttrPnt2 << ", " << anAttrPnt3;
+  } else if(aCreationMethod == ConstructionPlugin_Plane::CREATION_METHOD_BY_LINE_AND_POINT()) {
+    AttributeSelectionPtr anAttrLine = aBase->selection(ConstructionPlugin_Plane::LINE());
+    AttributeSelectionPtr anAttrPoint = aBase->selection(ConstructionPlugin_Plane::POINT());
+    AttributeBooleanPtr anAttrPerpendicular = aBase->boolean(ConstructionPlugin_Plane::PERPENDICULAR());
+
+    theDumper << ", " << anAttrLine << ", " << anAttrPoint << ", " << anAttrPerpendicular;
+  } else if(aCreationMethod == ConstructionPlugin_Plane::CREATION_METHOD_BY_OTHER_PLANE()) {
+    AttributeSelectionPtr anAttrPlane = aBase->selection(ConstructionPlugin_Plane::PLANE());
+
+    std::string aCreationMethodOption =
+        aBase->string(ConstructionPlugin_Plane::CREATION_METHOD_BY_OTHER_PLANE_OPTION())->value();
+    if(aCreationMethodOption == ConstructionPlugin_Plane::CREATION_METHOD_BY_DISTANCE_FROM_OTHER()) {
+      AttributeDoublePtr anAttrDistance = aBase->real(ConstructionPlugin_Plane::DISTANCE());
+      AttributeBooleanPtr anAttrReverse = aBase->boolean(ConstructionPlugin_Plane::REVERSE());
+
+      theDumper << ", " << anAttrPlane << ", " << anAttrDistance << ", " << anAttrReverse;
+    } else if(aCreationMethodOption == ConstructionPlugin_Plane::CREATION_METHOD_BY_COINCIDENT_TO_POINT()) {
+      AttributeSelectionPtr anAttrPoint = aBase->selection(ConstructionPlugin_Plane::COINCIDENT_POINT());
+
+      theDumper << ", " << anAttrPlane << ", " << anAttrPoint;
+    } else if(aCreationMethodOption == ConstructionPlugin_Plane::CREATION_METHOD_BY_ROTATION()) {
+      AttributeSelectionPtr anAttrAxis = aBase->selection(ConstructionPlugin_Plane::AXIS());
+      AttributeDoublePtr anAttrAngle = aBase->real(ConstructionPlugin_Plane::ANGLE());
+
+      theDumper << ", " << anAttrPlane << ", " << anAttrAxis << ", " << anAttrAngle;
+    }
+  } else if(aCreationMethod == ConstructionPlugin_Plane::CREATION_METHOD_BY_TWO_PARALLEL_PLANES()) {
+    AttributeSelectionPtr anAttrPlane1 = aBase->selection(ConstructionPlugin_Plane::PLANE1());
+    AttributeSelectionPtr anAttrPlane2 = aBase->selection(ConstructionPlugin_Plane::PLANE2());
+
+    theDumper << ", " << anAttrPlane1 << ", " << anAttrPlane2;
+  }
+
+  theDumper << ")" << std::endl;
+}
+
 //==================================================================================================
 PlanePtr addPlane(const std::shared_ptr<ModelAPI_Document>& thePart,
                   const ModelHighAPI_Selection& theFace,
index 2aaac52290ab71e0b6697cb4e421219d50537bcc..48eef87db38f27daea155b6e2c26ee2f5e10a268 100644 (file)
@@ -136,6 +136,9 @@ public:
                      const ModelHighAPI_Selection& theAxis,
                      const ModelHighAPI_Double& theAngle);
 
+  /// Dump wrapped feature
+  CONSTRUCTIONAPI_EXPORT
+  virtual void dump(ModelHighAPI_Dumper& theDumper) const;
 };
 
 /// Pointer on Plane object
index 43627a1dd56a1281fadcec7db90295ec647be12c..5a520fb7cc6b1c43681cd04eac5b33979a2a5c49 100644 (file)
@@ -287,39 +287,39 @@ std::string GeomAPI_Shape::shapeTypeStr() const
 
   switch(aShapeType) {
     case COMPOUND: {
-      aShapeTypeStr = "Compound";
+      aShapeTypeStr = "COMPOUND";
       break;
     }
     case COMPSOLID: {
-      aShapeTypeStr = "CompSolid";
+      aShapeTypeStr = "COMPSOLID";
       break;
     }
     case SOLID: {
-      aShapeTypeStr = "Solid";
+      aShapeTypeStr = "SOLID";
       break;
     }
     case SHELL: {
-      aShapeTypeStr = "Shell";
+      aShapeTypeStr = "SHELL";
       break;
     }
     case FACE: {
-      aShapeTypeStr = "Face";
+      aShapeTypeStr = "FACE";
       break;
     }
     case WIRE: {
-      aShapeTypeStr = "Wire";
+      aShapeTypeStr = "WIRE";
       break;
     }
     case EDGE: {
-      aShapeTypeStr = "Edge";
+      aShapeTypeStr = "EDGE";
       break;
     }
     case VERTEX: {
-      aShapeTypeStr = "Vertex";
+      aShapeTypeStr = "VERTEX";
       break;
     }
     case SHAPE: {
-      aShapeTypeStr = "Shape";
+      aShapeTypeStr = "SHAPE";
       break;
     }
   }
index bbf3be1d0b188845e951282ebeeee317539c8107..4b3138389b9dfd266954f346a476530b257a9ec1 100644 (file)
@@ -367,7 +367,18 @@ ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(
 ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(
     const std::shared_ptr<ModelAPI_AttributeSelection>& theAttrSelect)
 {
-  myDumpBuffer << "\"" << theAttrSelect->namingName() << "\"";
+  GeomShapePtr aShape = theAttrSelect->value();
+  if(!aShape.get()) {
+    aShape = theAttrSelect->context()->shape();
+  }
+
+  if(!aShape.get()) {
+    return *this;
+  }
+
+  std::string aShapeTypeStr = aShape->shapeTypeStr();
+
+  myDumpBuffer << "model.selection(\"" << aShapeTypeStr << "\", \"" << theAttrSelect->namingName() << "\")";
   return *this;
 }
 
index be4e0186f020be400cbafd5d67dee676583dcb72..438b2b145b62093c1dffda876c4a271a0d56a75f 100644 (file)
@@ -175,12 +175,11 @@ void fillAttribute(const char * theValue,
 }
 
 //==================================================================================================
-GeomAPI_Shape::ShapeType shapeTypeByStr(const std::string& theShapeTypeStr)
+GeomAPI_Shape::ShapeType shapeTypeByStr(std::string theShapeTypeStr)
 {
   GeomAPI_Shape::ShapeType aShapeType = GeomAPI_Shape::SHAPE;
 
-  std::string aShapeTypeStr = theShapeTypeStr;
-  std::transform(aShapeTypeStr.begin(), aShapeTypeStr.end(), aShapeTypeStr.begin(), ::tolower);
+  std::transform(theShapeTypeStr.begin(), theShapeTypeStr.end(), theShapeTypeStr.begin(), ::tolower);
 
   if(theShapeTypeStr == "compound") {
     aShapeType = GeomAPI_Shape::COMPOUND;
index f5467566d61bc31c1ee3bcb845d86c8f91574c25..e278e282ffaea348315cb646804d5aee9551c9a8 100644 (file)
@@ -121,7 +121,7 @@ void fillAttribute(const char * theValue,
                    const std::shared_ptr<ModelAPI_AttributeString> & theAttribute);
 
 MODELHIGHAPI_EXPORT
-GeomAPI_Shape::ShapeType shapeTypeByStr(const std::string& theShapeTypeStr);
+GeomAPI_Shape::ShapeType shapeTypeByStr(std::string theShapeTypeStr);
 
 MODELHIGHAPI_EXPORT
 GeomAPI_Shape::ShapeType getShapeType(const ModelHighAPI_Selection& theSelection);
index e33077b31af8856afe171b1e159ff670c06d2359..1fe15791f9ab9e0eac1ff8f971f4c52194c36987 100644 (file)
@@ -6,4 +6,5 @@ from ModelHighAPI import defaultPlane
 from ModelHighAPI import begin, end
 from ModelHighAPI import apply as do
 from ModelHighAPI import undo, redo
-from ModelHighAPI import reset
\ No newline at end of file
+from ModelHighAPI import reset
+from ModelHighAPI import ModelHighAPI_Selection as selection