From 46cd5e094f9b9eabde66e3a4848ee885933149b6 Mon Sep 17 00:00:00 2001 From: dbv Date: Thu, 8 Sep 2016 12:42:30 +0300 Subject: [PATCH] Fix for Axis dump --- src/BuildPlugin/Test/TestSubShapes.py | 18 +++ src/BuildPlugin/Test/TestWire.py | 23 ++++ src/ConstructionAPI/ConstructionAPI_Axis.cpp | 107 +++++++++++++++++- src/ConstructionAPI/ConstructionAPI_Axis.h | 48 ++++++++ .../Test/TestAxisCreation.py | 4 +- 5 files changed, 192 insertions(+), 8 deletions(-) diff --git a/src/BuildPlugin/Test/TestSubShapes.py b/src/BuildPlugin/Test/TestSubShapes.py index e943f66b3..dbe6d695d 100644 --- a/src/BuildPlugin/Test/TestSubShapes.py +++ b/src/BuildPlugin/Test/TestSubShapes.py @@ -128,4 +128,22 @@ aSession.finishOperation() assert (len(aSubShapesFeature.results()) > 0) import model + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY")) +SketchCircle_1 = Sketch_1.addCircle(-454.545454545455, 50.600343053173, 137.95899463189) +SketchCircle_2 = Sketch_1.addCircle(-454.545454545455, 50.600343053173, 62.129572131303) +SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchCircle_1.center(), SketchCircle_2.center()) +SketchPoint_1 = Sketch_1.addPoint(-490.566037735849, 50.600343053173) +SketchPoint_2 = Sketch_1.addPoint(-423.670668953688, 50.600343053173) +model.do() +Face_1 = model.addFace(Part_1_doc, [model.selection("WIRE", "Sketch_1/Wire-SketchCircle_1_2f")]) +Face_2 = model.addFace(Part_1_doc, [model.selection("WIRE", "Sketch_1/Wire-SketchCircle_2_2r")]) +SubShapes_1 = model.addSubShapes(Part_1_doc, model.selection("FACE", "Face_1_1"), [model.selection("VERTEX", "Sketch_1/Vertex-SketchPoint_1"), model.selection("VERTEX", "Sketch_1/Vertex-SketchPoint_2")]) +SubShapes_1.setBaseShape(model.selection("FACE", "Face_2_1")) +model.end() + assert(model.checkPythonDump()) diff --git a/src/BuildPlugin/Test/TestWire.py b/src/BuildPlugin/Test/TestWire.py index 545c5ffa6..0d3bb1618 100644 --- a/src/BuildPlugin/Test/TestWire.py +++ b/src/BuildPlugin/Test/TestWire.py @@ -64,4 +64,27 @@ aSession.finishOperation() assert (len(aWireFeature.results()) > 0) import model + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY")) +SketchLine_1 = Sketch_1.addLine(-68.61063464837, 232.418524871355, -488.85077186964, 232.418524871355) +SketchLine_2 = Sketch_1.addLine(-488.85077186964, 232.418524871355, -488.85077186964, -153.516295025729) +SketchLine_3 = Sketch_1.addLine(-488.85077186964, -153.516295025729, -68.61063464837, -153.516295025729) +SketchLine_4 = Sketch_1.addLine(-68.61063464837, -153.516295025729, -68.61063464837, 232.418524871355) +SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_1.startPoint()) +SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint()) +SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint()) +SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint()) +SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_1.result()[0]) +SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_2.result()[0]) +SketchConstraintHorizontal_2 = Sketch_1.setHorizontal(SketchLine_3.result()[0]) +SketchConstraintVertical_2 = Sketch_1.setVertical(SketchLine_4.result()[0]) +model.do() +Wire_1 = model.addWire(Part_1_doc, [model.selection("EDGE", "Sketch_1/Edge-SketchLine_1")]) +Wire_1.addContour() +model.end() + assert(model.checkPythonDump()) diff --git a/src/ConstructionAPI/ConstructionAPI_Axis.cpp b/src/ConstructionAPI/ConstructionAPI_Axis.cpp index 399017fea..7f1debcfa 100644 --- a/src/ConstructionAPI/ConstructionAPI_Axis.cpp +++ b/src/ConstructionAPI/ConstructionAPI_Axis.cpp @@ -90,6 +90,32 @@ ConstructionAPI_Axis::ConstructionAPI_Axis(const std::shared_ptr& theFeature, + const ModelHighAPI_Selection& thePlane1, + const ModelHighAPI_Selection& thePlane2, + const ModelHighAPI_Double& theOffset2, + const bool theReverseOffset2) +: ModelHighAPI_Interface(theFeature) +{ + if(initialize()) { + setByTwoPlanes(thePlane1, thePlane2, theOffset2, theReverseOffset2); + } +} + +//================================================================================================== +ConstructionAPI_Axis::ConstructionAPI_Axis(const std::shared_ptr& theFeature, + const ModelHighAPI_Selection& thePlane1, + const ModelHighAPI_Double& theOffset1, + const bool theReverseOffset1, + const ModelHighAPI_Selection& thePlane2) +: ModelHighAPI_Interface(theFeature) +{ + if(initialize()) { + setByTwoPlanes(thePlane1, theOffset1, theReverseOffset1, thePlane2); + } +} + //================================================================================================== ConstructionAPI_Axis::~ConstructionAPI_Axis() { @@ -197,6 +223,40 @@ void ConstructionAPI_Axis::setByTwoPlanes(const ModelHighAPI_Selection& thePlane execute(); } +//================================================================================================== +void ConstructionAPI_Axis::setByTwoPlanes(const ModelHighAPI_Selection& thePlane1, + const ModelHighAPI_Selection& thePlane2, + const ModelHighAPI_Double& theOffset2, + const bool theReverseOffset2) +{ + fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_TWO_PLANES(), creationMethod()); + fillAttribute(thePlane1, plane1()); + fillAttribute("", useOffset1()); + fillAttribute(thePlane2, plane2()); + fillAttribute(ConstructionPlugin_Axis::USE_OFFSET2(), useOffset2()); + fillAttribute(theOffset2, offset2()); + fillAttribute(theReverseOffset2, reverseOffset2()); + + execute(); +} + +//================================================================================================== +void ConstructionAPI_Axis::setByTwoPlanes(const ModelHighAPI_Selection& thePlane1, + const ModelHighAPI_Double& theOffset1, + const bool theReverseOffset1, + const ModelHighAPI_Selection& thePlane2) +{ + fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_TWO_PLANES(), creationMethod()); + fillAttribute(thePlane1, plane1()); + fillAttribute(ConstructionPlugin_Axis::USE_OFFSET1(), useOffset1()); + fillAttribute(theOffset1, offset1()); + fillAttribute(theReverseOffset1, reverseOffset1()); + fillAttribute(thePlane2, plane2()); + fillAttribute("", useOffset2()); + + execute(); +} + //================================================================================================== void ConstructionAPI_Axis::dump(ModelHighAPI_Dumper& theDumper) const { @@ -233,14 +293,23 @@ void ConstructionAPI_Axis::dump(ModelHighAPI_Dumper& theDumper) const 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; + theDumper << ", " << anAttrPlane1; + if(aBase->string(ConstructionPlugin_Axis::USE_OFFSET1())->isInitialized() + && !aBase->string(ConstructionPlugin_Axis::USE_OFFSET1())->value().empty()) { + AttributeDoublePtr anAttrOffset1 = aBase->real(ConstructionPlugin_Axis::OFFSET1()); + AttributeBooleanPtr anAttrReverseOffset1 = aBase->boolean(ConstructionPlugin_Axis::REVERSE_OFFSET1()); + theDumper << ", " << anAttrOffset1 << ", " << anAttrReverseOffset1; + } + + theDumper << ", " << anAttrPlane2; + if(aBase->string(ConstructionPlugin_Axis::USE_OFFSET2())->isInitialized() + && !aBase->string(ConstructionPlugin_Axis::USE_OFFSET2())->value().empty()) { + AttributeDoublePtr anAttrOffset2 = aBase->real(ConstructionPlugin_Axis::OFFSET2()); + AttributeBooleanPtr anAttrReverseOffset2 = aBase->boolean(ConstructionPlugin_Axis::REVERSE_OFFSET2()); + theDumper << ", " << 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()); @@ -309,3 +378,29 @@ AxisPtr addAxis(const std::shared_ptr& thePart, return AxisPtr(new ConstructionAPI_Axis(aFeature, thePlane1, theOffset1, theReverseOffset1, thePlane2, theOffset2, theReverseOffset2)); } + +//================================================================================================== +AxisPtr addAxis(const std::shared_ptr& thePart, + const ModelHighAPI_Selection& thePlane1, + const ModelHighAPI_Selection& thePlane2, + const ModelHighAPI_Double& theOffset2, + const bool theReverseOffset2) +{ + // TODO(spo): check that thePart is not empty + std::shared_ptr aFeature = thePart->addFeature(ConstructionAPI_Axis::ID()); + return AxisPtr(new ConstructionAPI_Axis(aFeature, thePlane1, + thePlane2, theOffset2, theReverseOffset2)); +} + +//================================================================================================== +AxisPtr addAxis(const std::shared_ptr& thePart, + const ModelHighAPI_Selection& thePlane1, + const ModelHighAPI_Double& theOffset1, + const bool theReverseOffset1, + const ModelHighAPI_Selection& thePlane2) +{ + // TODO(spo): check that thePart is not empty + std::shared_ptr aFeature = thePart->addFeature(ConstructionAPI_Axis::ID()); + return AxisPtr(new ConstructionAPI_Axis(aFeature, thePlane1, theOffset1, theReverseOffset1, + thePlane2)); +} diff --git a/src/ConstructionAPI/ConstructionAPI_Axis.h b/src/ConstructionAPI/ConstructionAPI_Axis.h index fc6bbbc19..e9bdb6bfc 100644 --- a/src/ConstructionAPI/ConstructionAPI_Axis.h +++ b/src/ConstructionAPI/ConstructionAPI_Axis.h @@ -66,6 +66,22 @@ public: const ModelHighAPI_Double& theOffset2, const bool theReverseOffset2); + /// Constructor with values + CONSTRUCTIONAPI_EXPORT + ConstructionAPI_Axis(const std::shared_ptr& theFeature, + const ModelHighAPI_Selection& thePlane1, + const ModelHighAPI_Selection& thePlane2, + const ModelHighAPI_Double& theOffset2, + const bool theReverseOffset2); + + /// Constructor with values + CONSTRUCTIONAPI_EXPORT + ConstructionAPI_Axis(const std::shared_ptr& theFeature, + const ModelHighAPI_Selection& thePlane1, + const ModelHighAPI_Double& theOffset1, + const bool theReverseOffset1, + const ModelHighAPI_Selection& thePlane2); + /// Destructor CONSTRUCTIONAPI_EXPORT virtual ~ConstructionAPI_Axis(); @@ -138,6 +154,20 @@ public: const ModelHighAPI_Double& theOffset2, const bool theReverseOffset2); + /// Set by two planes + CONSTRUCTIONAPI_EXPORT + void setByTwoPlanes(const ModelHighAPI_Selection& thePlane1, + const ModelHighAPI_Selection& thePlane2, + const ModelHighAPI_Double& theOffset2, + const bool theReverseOffset2); + + /// Set by two planes + CONSTRUCTIONAPI_EXPORT + void setByTwoPlanes(const ModelHighAPI_Selection& thePlane1, + const ModelHighAPI_Double& theOffset1, + const bool theReverseOffset1, + const ModelHighAPI_Selection& thePlane2); + /// Dump wrapped feature CONSTRUCTIONAPI_EXPORT virtual void dump(ModelHighAPI_Dumper& theDumper) const; @@ -187,4 +217,22 @@ AxisPtr addAxis(const std::shared_ptr& thePart, const ModelHighAPI_Double& theOffset2, const bool theReverseOffset2); +/// \ingroup CPPHighAPI +/// \brief Create Axis feature +CONSTRUCTIONAPI_EXPORT +AxisPtr addAxis(const std::shared_ptr& thePart, + const ModelHighAPI_Selection& thePlane1, + const ModelHighAPI_Selection& thePlane2, + const ModelHighAPI_Double& theOffset2, + const bool theReverseOffset2); + +/// \ingroup CPPHighAPI +/// \brief Create Axis feature +CONSTRUCTIONAPI_EXPORT +AxisPtr addAxis(const std::shared_ptr& thePart, + const ModelHighAPI_Selection& thePlane1, + const ModelHighAPI_Double& theOffset1, + const bool theReverseOffset1, + const ModelHighAPI_Selection& thePlane2); + #endif /* SRC_CONSTRUCTIONAPI_CONSTRUCTIONAPI_AXIS_H_ */ diff --git a/src/ConstructionPlugin/Test/TestAxisCreation.py b/src/ConstructionPlugin/Test/TestAxisCreation.py index 77be60ef1..2c0dabfb6 100644 --- a/src/ConstructionPlugin/Test/TestAxisCreation.py +++ b/src/ConstructionPlugin/Test/TestAxisCreation.py @@ -189,5 +189,5 @@ anAxis = model.addAxis(aPart, aPlane1.result()[0], 50, False, aPlane2.result()[0 aSession.finishOperation() assert (len(anAxis.result()) > 0) -#import model -#assert(model.checkPythonDump()) +import model +assert(model.checkPythonDump()) -- 2.39.2