X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FConstructionPlugin%2FConstructionPlugin_Axis.cpp;h=b25cc9c2d4c0b3568fa89ddbf1f7e06e5caa1f6b;hb=383021cb51c4720904096ca851db5ee79255b402;hp=7315289b3c52227ee9495b438debb8b4041f2b5a;hpb=5119a6154d1737e3a46eda810bedb9436d80ee52;p=modules%2Fshaper.git diff --git a/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp b/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp index 7315289b3..b25cc9c2d 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp @@ -6,16 +6,25 @@ #include "ConstructionPlugin_Axis.h" +#include + #include #include +#include +#include +#include +#include #include +#include #include #include -using namespace std; +#ifdef _DEBUG +#include +#endif -static const double MINIMAL_LENGTH = 1.e-5; +using namespace std; ConstructionPlugin_Axis::ConstructionPlugin_Axis() { @@ -23,24 +32,47 @@ ConstructionPlugin_Axis::ConstructionPlugin_Axis() void ConstructionPlugin_Axis::initAttributes() { - data()->addAttribute(POINT_ATTR_FIRST, ModelAPI_AttributeSelection::type()); - data()->addAttribute(POINT_ATTR_SECOND, ModelAPI_AttributeSelection::type()); + data()->addAttribute(ConstructionPlugin_Axis::METHOD(), + ModelAPI_AttributeString::typeId()); + data()->addAttribute(ConstructionPlugin_Axis::POINT_FIRST(), + ModelAPI_AttributeSelection::typeId()); + data()->addAttribute(ConstructionPlugin_Axis::POINT_SECOND(), + ModelAPI_AttributeSelection::typeId()); + data()->addAttribute(ConstructionPlugin_Axis::CYLINDRICAL_FACE(), + ModelAPI_AttributeSelection::typeId()); + data()->addAttribute(ConstructionPlugin_Axis::X_DIRECTION(), + ModelAPI_AttributeDouble::typeId()); + data()->addAttribute(ConstructionPlugin_Axis::Y_DIRECTION(), + ModelAPI_AttributeDouble::typeId()); + data()->addAttribute(ConstructionPlugin_Axis::Z_DIRECTION(), + ModelAPI_AttributeDouble::typeId()); + ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), + ConstructionPlugin_Axis::X_DIRECTION()); + ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), + ConstructionPlugin_Axis::Y_DIRECTION()); + ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), + ConstructionPlugin_Axis::Z_DIRECTION()); } -void ConstructionPlugin_Axis::execute() +void ConstructionPlugin_Axis::createAxisByTwoPoints() { - AttributeSelectionPtr aRef1 = data()->selection(POINT_ATTR_FIRST); - AttributeSelectionPtr aRef2 = data()->selection(POINT_ATTR_SECOND); + AttributeSelectionPtr aRef1 = data()->selection(ConstructionPlugin_Axis::POINT_FIRST()); + AttributeSelectionPtr aRef2 = data()->selection(ConstructionPlugin_Axis::POINT_SECOND()); if ((aRef1.get() != NULL) && (aRef2.get() != NULL)) { GeomShapePtr aShape1 = aRef1->value(); + if (!aShape1.get()) + aShape1 = aRef1->context()->shape(); GeomShapePtr aShape2 = aRef2->value(); + if (!aShape2.get()) + aShape2 = aRef2->context()->shape(); if (aShape1->isVertex() && aShape2->isVertex() && (!aShape1->isEqual(aShape2))) { std::shared_ptr aStart = GeomAlgoAPI_PointBuilder::point(aShape1); std::shared_ptr anEnd = GeomAlgoAPI_PointBuilder::point(aShape2); - if (aStart->distance(anEnd) > MINIMAL_LENGTH) { + if (aStart->distance(anEnd) > ConstructionPlugin_Axis::MINIMAL_LENGTH()) { std::shared_ptr anEdge = GeomAlgoAPI_EdgeBuilder::line(aStart, anEnd); ResultConstructionPtr aConstr = document()->createConstruction(data()); + aConstr->setInfinite(true); aConstr->setShape(anEdge); setResult(aConstr); } @@ -48,8 +80,75 @@ void ConstructionPlugin_Axis::execute() } } -void ConstructionPlugin_Axis::customisePresentation(AISObjectPtr thePrs) + +void ConstructionPlugin_Axis::createAxisByPointAndDirection() { - thePrs->setColor(0, 0, 0); - thePrs->setLineStyle(3); -} \ No newline at end of file + AttributeSelectionPtr aRef1 = data()->selection(ConstructionPlugin_Axis::POINT_FIRST()); + 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) && + (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(), + aYAttr->value(), + aZAttr->value())); + if (aShape1->isVertex() && (!aShape1->isEqual(aVertex))) { + std::shared_ptr aStart = GeomAlgoAPI_PointBuilder::point(aShape1); + std::shared_ptr anEnd = aVertex->point(); + if (aStart->distance(anEnd) > ConstructionPlugin_Axis::MINIMAL_LENGTH()) { + std::shared_ptr anEdge = GeomAlgoAPI_EdgeBuilder::line(aStart, anEnd); + + ResultConstructionPtr aConstr = document()->createConstruction(data()); + aConstr->setInfinite(true); + aConstr->setShape(anEdge); + setResult(aConstr); + } + } + } +} + + +void ConstructionPlugin_Axis::createAxisByCylindricalFace() +{ + std::shared_ptr aSelection = data()->selection(CYLINDRICAL_FACE())->value(); + // update arguments due to the selection value + if (aSelection && !aSelection->isNull() && aSelection->isFace()) { + std::shared_ptr anEdge = GeomAlgoAPI_EdgeBuilder::cylinderAxis(aSelection); + + ResultConstructionPtr aConstr = document()->createConstruction(data()); + aConstr->setInfinite(true); + aConstr->setShape(anEdge); + setResult(aConstr); + } +} + + + +void ConstructionPlugin_Axis::execute() +{ + AttributeStringPtr aMethodTypeAttr = string(ConstructionPlugin_Axis::METHOD()); + std::string aMethodType = aMethodTypeAttr->value(); + if (aMethodType == "AxisByPointsCase") { + createAxisByTwoPoints(); + } else if (aMethodType == "AxisByCylindricalFaceCase") { + createAxisByCylindricalFace(); + } else if (aMethodType == "AxisByPointAndDirection") { + createAxisByPointAndDirection(); + } +} + +bool ConstructionPlugin_Axis::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs, + std::shared_ptr theDefaultPrs) +{ + bool isCustomized = theDefaultPrs.get() != NULL && + theDefaultPrs->customisePresentation(theResult, thePrs, theDefaultPrs); + + isCustomized = thePrs->setLineStyle(3) || isCustomized; + isCustomized = thePrs->setWidth(2) || isCustomized; + + return isCustomized; +}