X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FConstructionPlugin%2FConstructionPlugin_Axis.cpp;h=790c0d642bc1965f084072d977c094a97a5e9d2a;hb=10671023698288fff01b8717696d150419dc4475;hp=1dad21a9360dc5bb32b4ad7c52e35ac9804c6e1b;hpb=c1e8de73f772aef0a65200b94ee731fbf4cca507;p=modules%2Fshaper.git diff --git a/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp b/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp index 1dad21a93..790c0d642 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp @@ -4,12 +4,13 @@ // Created: 12 Dec 2014 // Author: Vitaly Smetannikov -// Modified by CEA (delegation to Alyotech) : 29 Mar 2016 +// Modified by Clarisse Genrault (CEA) : 29 Mar 2016 #include "ConstructionPlugin_Axis.h" #include +#include #include #include #include @@ -18,6 +19,7 @@ #include #include +#include #include #include #include @@ -29,7 +31,7 @@ #include #endif -using namespace std; +static const double defaultAxisSize = 100; ConstructionPlugin_Axis::ConstructionPlugin_Axis() { @@ -39,7 +41,7 @@ void ConstructionPlugin_Axis::initAttributes() { data()->addAttribute(ConstructionPlugin_Axis::METHOD(), ModelAPI_AttributeString::typeId()); - + // Attributes needed to build the axis using the "two points" method data()->addAttribute(ConstructionPlugin_Axis::POINT_FIRST(), ModelAPI_AttributeSelection::typeId()); @@ -55,11 +57,11 @@ void ConstructionPlugin_Axis::initAttributes() ModelAPI_AttributeDouble::typeId()); data()->addAttribute(ConstructionPlugin_Axis::Z_DIRECTION(), ModelAPI_AttributeDouble::typeId()); - ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), + ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), ConstructionPlugin_Axis::X_DIRECTION()); - ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), + ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), ConstructionPlugin_Axis::Y_DIRECTION()); - ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), + ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), ConstructionPlugin_Axis::Z_DIRECTION()); //Attributes needed to build the axis using the "three dimensions" method @@ -76,6 +78,16 @@ void ConstructionPlugin_Axis::initAttributes() /// Attributes for axis by plane and point. data()->addAttribute(PLANE(), ModelAPI_AttributeSelection::typeId()); data()->addAttribute(POINT(), ModelAPI_AttributeSelection::typeId()); + + /// Attributes for axis by two planes. + data()->addAttribute(PLANE1(), ModelAPI_AttributeSelection::typeId()); + data()->addAttribute(USE_OFFSET1(), ModelAPI_AttributeString::typeId()); + data()->addAttribute(OFFSET1(), ModelAPI_AttributeDouble::typeId()); + data()->addAttribute(REVERSE_OFFSET1(), ModelAPI_AttributeBoolean::typeId()); + data()->addAttribute(PLANE2(), ModelAPI_AttributeSelection::typeId()); + data()->addAttribute(USE_OFFSET2(), ModelAPI_AttributeString::typeId()); + data()->addAttribute(OFFSET2(), ModelAPI_AttributeDouble::typeId()); + data()->addAttribute(REVERSE_OFFSET2(), ModelAPI_AttributeBoolean::typeId()); } void ConstructionPlugin_Axis::createAxisByTwoPoints() @@ -111,13 +123,13 @@ void ConstructionPlugin_Axis::createAxisByPointAndDirection() AttributeDoublePtr aXAttr = data()->real(ConstructionPlugin_Axis::X_DIRECTION()); AttributeDoublePtr aYAttr = data()->real(ConstructionPlugin_Axis::Y_DIRECTION()); AttributeDoublePtr aZAttr = data()->real(ConstructionPlugin_Axis::Z_DIRECTION()); - if ((aRef1.get() != NULL) && (aXAttr.get() != NULL) && + if ((aRef1.get() != NULL) && (aXAttr.get() != NULL) && (aYAttr.get() != NULL) && (aZAttr.get() != NULL)) { GeomShapePtr aShape1 = aRef1->value(); if (!aShape1.get()) aShape1 = aRef1->context()->shape(); - std::shared_ptr aVertex(new GeomAPI_Vertex(aXAttr->value(), + std::shared_ptr aVertex(new GeomAPI_Vertex(aXAttr->value(), aYAttr->value(), aZAttr->value())); if (aShape1->isVertex() && (!aShape1->isEqual(aVertex))) { @@ -157,7 +169,8 @@ void ConstructionPlugin_Axis::createAxisByDimensions() double aDY = data()->real(DY())->value(); double aDZ = data()->real(DZ())->value(); - if (fabs(aDX) < MINIMAL_LENGTH() && fabs(aDY) < MINIMAL_LENGTH() && fabs(aDZ) < MINIMAL_LENGTH()){ + if (fabs(aDX) < MINIMAL_LENGTH() && fabs(aDY) < MINIMAL_LENGTH() && + fabs(aDZ) < MINIMAL_LENGTH()) { setError("Axis builder with dimensions :: all dimensions are null", false); return ; } @@ -167,7 +180,7 @@ void ConstructionPlugin_Axis::createAxisByDimensions() ResultConstructionPtr aConstr = document()->createConstruction(data()); aConstr->setInfinite(true); aConstr->setShape(anEdge); - setResult(aConstr); + setResult(aConstr); } void ConstructionPlugin_Axis::createAxisByLine() @@ -209,10 +222,63 @@ void ConstructionPlugin_Axis::createAxisByPlaneAndPoint() std::shared_ptr aProjPnt = aPln->project(aPnt); if(aProjPnt->isEqual(aPnt)) { - aPnt->translate(aPln->direction(), 10); + aPnt->translate(aPln->direction(), defaultAxisSize); + } + + std::shared_ptr anEdge = GeomAlgoAPI_EdgeBuilder::line(aPnt, aProjPnt); + + ResultConstructionPtr aConstr = document()->createConstruction(data()); + aConstr->setInfinite(true); + aConstr->setShape(anEdge); + setResult(aConstr); +} + +void ConstructionPlugin_Axis::createAxisByTwoPlanes() +{ + // Get face 1. + AttributeSelectionPtr aFaceSelection1 = selection(PLANE1()); + GeomShapePtr aFaceShape1 = aFaceSelection1->value(); + if(!aFaceShape1.get()) { + aFaceShape1 = aFaceSelection1->context()->shape(); + } + std::shared_ptr aFace1(new GeomAPI_Face(aFaceShape1)); + std::shared_ptr aPln1 = aFace1->getPlane(); + + std::string useOffset1 = string(USE_OFFSET1())->value(); + if(!useOffset1.empty()) { + double anOffset1 = real(OFFSET1())->value(); + bool reverseOffset1 = boolean(REVERSE_OFFSET1())->value(); + if(reverseOffset1) { + anOffset1 = -anOffset1; + } + aPln1->translate(aPln1->direction(), anOffset1); } - std::shared_ptr anEdge = GeomAlgoAPI_EdgeBuilder::line(aProjPnt, aPnt); + // Get face 2. + AttributeSelectionPtr aFaceSelection2 = selection(PLANE2()); + GeomShapePtr aFaceShape2 = aFaceSelection2->value(); + if(!aFaceShape2.get()) { + aFaceShape2 = aFaceSelection2->context()->shape(); + } + std::shared_ptr aFace2(new GeomAPI_Face(aFaceShape2)); + std::shared_ptr aPln2 = aFace2->getPlane(); + + std::string useOffset2 = string(USE_OFFSET2())->value(); + if(!useOffset2.empty()) { + double anOffset2 = real(OFFSET2())->value(); + bool reverseOffset2 = boolean(REVERSE_OFFSET2())->value(); + if(reverseOffset2) { + anOffset2 = -anOffset2; + } + aPln2->translate(aPln2->direction(), anOffset2); + } + + std::shared_ptr aLin = aPln1->intersect(aPln2); + std::shared_ptr aPnt1 = aLin->location(); + std::shared_ptr aPnt2 = aLin->location(); + aPnt2->translate(aLin->direction(), defaultAxisSize); + + std::shared_ptr anEdge = GeomAlgoAPI_EdgeBuilder::line(aPnt1, aPnt2); ResultConstructionPtr aConstr = document()->createConstruction(data()); aConstr->setInfinite(true); @@ -224,18 +290,20 @@ void ConstructionPlugin_Axis::execute() { AttributeStringPtr aMethodTypeAttr = string(ConstructionPlugin_Axis::METHOD()); std::string aMethodType = aMethodTypeAttr->value(); - if (aMethodType == "AxisByPointsCase") { + if (aMethodType == CREATION_METHOD_BY_TWO_POINTS()) { createAxisByTwoPoints(); - } else if (aMethodType == "AxisByCylindricalFaceCase") { + } else if (aMethodType == CREATION_METHOD_BY_CYLINDRICAL_FACE()) { createAxisByCylindricalFace(); - } else if (aMethodType == "AxisByPointAndDirection") { + } else if (aMethodType == CREATION_METHOD_BY_POINT_AND_DIRECTION()) { createAxisByPointAndDirection(); - } else if (aMethodType == "AxisByDimensionsCase") { + } else if (aMethodType == CREATION_METHOD_BY_DIMENSIONS()) { createAxisByDimensions(); } else if(aMethodType == CREATION_METHOD_BY_LINE()) { createAxisByLine(); } else if(aMethodType == CREATION_METHOD_BY_PLANE_AND_POINT()) { createAxisByPlaneAndPoint(); + } else if(aMethodType == CREATION_METHOD_BY_TWO_PLANES()) { + createAxisByTwoPlanes(); } }