From c3e2c6c8c96fbd5de5da96de5042e40cb3ab3d49 Mon Sep 17 00:00:00 2001 From: dbv Date: Mon, 8 Aug 2016 17:35:30 +0300 Subject: [PATCH] Issue #1648: Dump Python in the High Level Parameterized Geometry API Added dump for Construction features Axis and Plane. --- src/ConstructionAPI/ConstructionAPI_Axis.cpp | 63 ++++++++++++++++++- src/ConstructionAPI/ConstructionAPI_Axis.h | 4 ++ src/ConstructionAPI/ConstructionAPI_Plane.cpp | 60 ++++++++++++++++++ src/ConstructionAPI/ConstructionAPI_Plane.h | 3 + src/GeomAPI/GeomAPI_Shape.cpp | 18 +++--- src/ModelHighAPI/ModelHighAPI_Dumper.cpp | 13 +++- src/ModelHighAPI/ModelHighAPI_Tools.cpp | 5 +- src/ModelHighAPI/ModelHighAPI_Tools.h | 2 +- src/PythonAPI/model/services/__init__.py | 3 +- 9 files changed, 153 insertions(+), 18 deletions(-) diff --git a/src/ConstructionAPI/ConstructionAPI_Axis.cpp b/src/ConstructionAPI/ConstructionAPI_Axis.cpp index 132adba51..399017fea 100644 --- a/src/ConstructionAPI/ConstructionAPI_Axis.cpp +++ b/src/ConstructionAPI/ConstructionAPI_Axis.cpp @@ -6,6 +6,7 @@ #include "ConstructionAPI_Axis.h" +#include #include //================================================================================================== @@ -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& 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 aFeature = thePart->addFeature(ConstructionAPI_Axis::ID()); - return AxisPtr(new ConstructionAPI_Axis(aFeature, thePoint1, thePoint2)); + return AxisPtr(new ConstructionAPI_Axis(aFeature, theObject1, theObject2)); } //================================================================================================== diff --git a/src/ConstructionAPI/ConstructionAPI_Axis.h b/src/ConstructionAPI/ConstructionAPI_Axis.h index 0b62587a6..fc6bbbc19 100644 --- a/src/ConstructionAPI/ConstructionAPI_Axis.h +++ b/src/ConstructionAPI/ConstructionAPI_Axis.h @@ -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 diff --git a/src/ConstructionAPI/ConstructionAPI_Plane.cpp b/src/ConstructionAPI/ConstructionAPI_Plane.cpp index fdde03ebb..b7de5703c 100644 --- a/src/ConstructionAPI/ConstructionAPI_Plane.cpp +++ b/src/ConstructionAPI/ConstructionAPI_Plane.cpp @@ -6,6 +6,7 @@ #include "ConstructionAPI_Plane.h" +#include #include //================================================================================================== @@ -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& thePart, const ModelHighAPI_Selection& theFace, diff --git a/src/ConstructionAPI/ConstructionAPI_Plane.h b/src/ConstructionAPI/ConstructionAPI_Plane.h index 2aaac5229..48eef87db 100644 --- a/src/ConstructionAPI/ConstructionAPI_Plane.h +++ b/src/ConstructionAPI/ConstructionAPI_Plane.h @@ -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 diff --git a/src/GeomAPI/GeomAPI_Shape.cpp b/src/GeomAPI/GeomAPI_Shape.cpp index 43627a1dd..5a520fb7c 100644 --- a/src/GeomAPI/GeomAPI_Shape.cpp +++ b/src/GeomAPI/GeomAPI_Shape.cpp @@ -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; } } diff --git a/src/ModelHighAPI/ModelHighAPI_Dumper.cpp b/src/ModelHighAPI/ModelHighAPI_Dumper.cpp index bbf3be1d0..4b3138389 100644 --- a/src/ModelHighAPI/ModelHighAPI_Dumper.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Dumper.cpp @@ -367,7 +367,18 @@ ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<( ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<( const std::shared_ptr& 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; } diff --git a/src/ModelHighAPI/ModelHighAPI_Tools.cpp b/src/ModelHighAPI/ModelHighAPI_Tools.cpp index be4e0186f..438b2b145 100644 --- a/src/ModelHighAPI/ModelHighAPI_Tools.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Tools.cpp @@ -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; diff --git a/src/ModelHighAPI/ModelHighAPI_Tools.h b/src/ModelHighAPI/ModelHighAPI_Tools.h index f5467566d..e278e282f 100644 --- a/src/ModelHighAPI/ModelHighAPI_Tools.h +++ b/src/ModelHighAPI/ModelHighAPI_Tools.h @@ -121,7 +121,7 @@ void fillAttribute(const char * theValue, const std::shared_ptr & 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); diff --git a/src/PythonAPI/model/services/__init__.py b/src/PythonAPI/model/services/__init__.py index e33077b31..1fe15791f 100644 --- a/src/PythonAPI/model/services/__init__.py +++ b/src/PythonAPI/model/services/__init__.py @@ -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 -- 2.39.2