1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: ConstructionPlugin_Axis.cpp
4 // Created: 12 Dec 2014
5 // Author: Vitaly Smetannikov
7 #include "ConstructionPlugin_Axis.h"
9 #include <Config_PropManager.h>
11 #include <ModelAPI_AttributeSelection.h>
12 #include <ModelAPI_ResultConstruction.h>
13 #include <ModelAPI_AttributeString.h>
15 #include <GeomAPI_Edge.h>
16 #include <GeomAlgoAPI_EdgeBuilder.h>
17 #include <GeomAlgoAPI_PointBuilder.h>
25 ConstructionPlugin_Axis::ConstructionPlugin_Axis()
29 void ConstructionPlugin_Axis::initAttributes()
31 data()->addAttribute(ConstructionPlugin_Axis::METHOD(),
32 ModelAPI_AttributeString::typeId());
33 data()->addAttribute(ConstructionPlugin_Axis::POINT_FIRST(),
34 ModelAPI_AttributeSelection::typeId());
35 data()->addAttribute(ConstructionPlugin_Axis::POINT_SECOND(),
36 ModelAPI_AttributeSelection::typeId());
37 data()->addAttribute(ConstructionPlugin_Axis::CYLINDRICAL_FACE(),
38 ModelAPI_AttributeSelection::typeId());
41 void ConstructionPlugin_Axis::createAxisByTwoPoints()
43 AttributeSelectionPtr aRef1 = data()->selection(ConstructionPlugin_Axis::POINT_FIRST());
44 AttributeSelectionPtr aRef2 = data()->selection(ConstructionPlugin_Axis::POINT_SECOND());
45 if ((aRef1.get() != NULL) && (aRef2.get() != NULL)) {
46 GeomShapePtr aShape1 = aRef1->value();
48 aShape1 = aRef1->context()->shape();
49 GeomShapePtr aShape2 = aRef2->value();
51 aShape2 = aRef2->context()->shape();
52 if (aShape1->isVertex() && aShape2->isVertex() && (!aShape1->isEqual(aShape2))) {
53 std::shared_ptr<GeomAPI_Pnt> aStart = GeomAlgoAPI_PointBuilder::point(aShape1);
54 std::shared_ptr<GeomAPI_Pnt> anEnd = GeomAlgoAPI_PointBuilder::point(aShape2);
55 if (aStart->distance(anEnd) > ConstructionPlugin_Axis::MINIMAL_LENGTH()) {
56 std::shared_ptr<GeomAPI_Edge> anEdge = GeomAlgoAPI_EdgeBuilder::line(aStart, anEnd);
58 ResultConstructionPtr aConstr = document()->createConstruction(data());
59 aConstr->setInfinite(true);
60 aConstr->setShape(anEdge);
67 void ConstructionPlugin_Axis::createAxisByCylindricalFace()
69 std::shared_ptr<GeomAPI_Shape> aSelection = data()->selection(CYLINDRICAL_FACE())->value();
70 // update arguments due to the selection value
71 if (aSelection && !aSelection->isNull() && aSelection->isFace()) {
72 std::shared_ptr<GeomAPI_Edge> anEdge = GeomAlgoAPI_EdgeBuilder::cylinderAxis(aSelection);
74 ResultConstructionPtr aConstr = document()->createConstruction(data());
75 aConstr->setInfinite(true);
76 aConstr->setShape(anEdge);
81 void ConstructionPlugin_Axis::execute()
83 AttributeStringPtr aMethodTypeAttr = string(ConstructionPlugin_Axis::METHOD());
84 std::string aMethodType = aMethodTypeAttr->value();
85 if (aMethodType == "AxisByPointsCase") {
86 createAxisByTwoPoints();
87 } else if (aMethodType == "AxisByCylindricalFaceCase") {
88 createAxisByCylindricalFace();
92 bool ConstructionPlugin_Axis::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
93 std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
95 bool isCustomized = theDefaultPrs.get() != NULL &&
96 theDefaultPrs->customisePresentation(theResult, thePrs, theDefaultPrs);
98 isCustomized = thePrs->setLineStyle(3) || isCustomized;
99 isCustomized = thePrs->setWidth(2) || isCustomized;