X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FConstructionPlugin%2FConstructionPlugin_Axis.cpp;h=8a6c2a5d0c23fb8ea0dad5ad7b35404771e1c90c;hb=5dfebcc3a72f75f043de9880419b39f073af6819;hp=69b31a9f0feed35170699c0e04d0606a090ebd16;hpb=3efd29f07fa128246690fd24a3439048b5e95878;p=modules%2Fshaper.git diff --git a/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp b/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp index 69b31a9f0..8a6c2a5d0 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp @@ -6,16 +6,21 @@ #include "ConstructionPlugin_Axis.h" -#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,37 +28,75 @@ ConstructionPlugin_Axis::ConstructionPlugin_Axis() void ConstructionPlugin_Axis::initAttributes() { - data()->addAttribute(POINT_ATTR_FIRST, ModelAPI_AttributeReference::type()); - data()->addAttribute(POINT_ATTR_SECOND, ModelAPI_AttributeReference::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()); } -void ConstructionPlugin_Axis::execute() +void ConstructionPlugin_Axis::createAxisByTwoPoints() { - AttributeReferencePtr aRef1 = data()->reference(POINT_ATTR_FIRST); - AttributeReferencePtr aRef2 = data()->reference(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)) { - ResultConstructionPtr aPntObj1 = std::dynamic_pointer_cast(aRef1->value()); - ResultConstructionPtr aPntObj2 = std::dynamic_pointer_cast(aRef2->value()); - if ((aPntObj1.get() != NULL) && (aPntObj2.get() != NULL)) { - GeomShapePtr aShape1 = aPntObj1->shape(); - GeomShapePtr aShape2 = aPntObj2->shape(); - if (aShape1->isVertex() && aShape2->isVertex()) { - std::shared_ptr aStart = GeomAlgoAPI_PointBuilder::point(aShape1); - std::shared_ptr anEnd = GeomAlgoAPI_PointBuilder::point(aShape2); - if (aStart->distance(anEnd) > MINIMAL_LENGTH) { - std::shared_ptr anEdge = GeomAlgoAPI_EdgeBuilder::line(aStart, anEnd); - - ResultConstructionPtr aConstr = document()->createConstruction(data()); - aConstr->setShape(anEdge); - setResult(aConstr); - } + 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) > 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::customisePresentation(AISObjectPtr thePrs) +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(); + } +} + +bool ConstructionPlugin_Axis::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs, + std::shared_ptr theDefaultPrs) { - thePrs->setColor(0, 0, 0); - thePrs->setLineStyle(3); -} \ No newline at end of file + bool isCustomized = theDefaultPrs.get() != NULL && + theDefaultPrs->customisePresentation(theResult, thePrs, theDefaultPrs); + + isCustomized = thePrs->setLineStyle(3) || isCustomized; + isCustomized = thePrs->setWidth(2) || isCustomized; + + return isCustomized; +}