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>
14 #include <ModelAPI_AttributeDouble.h>
16 #include <GeomAPI_Edge.h>
17 #include <GeomAPI_Vertex.h>
18 #include <GeomAlgoAPI_EdgeBuilder.h>
19 #include <GeomAlgoAPI_PointBuilder.h>
27 ConstructionPlugin_Axis::ConstructionPlugin_Axis()
31 void ConstructionPlugin_Axis::initAttributes()
33 data()->addAttribute(ConstructionPlugin_Axis::METHOD(),
34 ModelAPI_AttributeString::typeId());
35 data()->addAttribute(ConstructionPlugin_Axis::POINT_FIRST(),
36 ModelAPI_AttributeSelection::typeId());
37 data()->addAttribute(ConstructionPlugin_Axis::POINT_SECOND(),
38 ModelAPI_AttributeSelection::typeId());
39 data()->addAttribute(ConstructionPlugin_Axis::CYLINDRICAL_FACE(),
40 ModelAPI_AttributeSelection::typeId());
41 data()->addAttribute(ConstructionPlugin_Axis::X_DIRECTION(),
42 ModelAPI_AttributeDouble::typeId());
43 data()->addAttribute(ConstructionPlugin_Axis::Y_DIRECTION(),
44 ModelAPI_AttributeDouble::typeId());
45 data()->addAttribute(ConstructionPlugin_Axis::Z_DIRECTION(),
46 ModelAPI_AttributeDouble::typeId());
49 void ConstructionPlugin_Axis::createAxisByTwoPoints()
51 AttributeSelectionPtr aRef1 = data()->selection(ConstructionPlugin_Axis::POINT_FIRST());
52 AttributeSelectionPtr aRef2 = data()->selection(ConstructionPlugin_Axis::POINT_SECOND());
53 if ((aRef1.get() != NULL) && (aRef2.get() != NULL)) {
54 GeomShapePtr aShape1 = aRef1->value();
56 aShape1 = aRef1->context()->shape();
57 GeomShapePtr aShape2 = aRef2->value();
59 aShape2 = aRef2->context()->shape();
60 if (aShape1->isVertex() && aShape2->isVertex() && (!aShape1->isEqual(aShape2))) {
61 std::shared_ptr<GeomAPI_Pnt> aStart = GeomAlgoAPI_PointBuilder::point(aShape1);
62 std::shared_ptr<GeomAPI_Pnt> anEnd = GeomAlgoAPI_PointBuilder::point(aShape2);
63 if (aStart->distance(anEnd) > ConstructionPlugin_Axis::MINIMAL_LENGTH()) {
64 std::shared_ptr<GeomAPI_Edge> anEdge = GeomAlgoAPI_EdgeBuilder::line(aStart, anEnd);
66 ResultConstructionPtr aConstr = document()->createConstruction(data());
67 aConstr->setInfinite(true);
68 aConstr->setShape(anEdge);
76 void ConstructionPlugin_Axis::createAxisByPointAndDirection()
78 AttributeSelectionPtr aRef1 = data()->selection(ConstructionPlugin_Axis::POINT_FIRST());
79 AttributeDoublePtr aXAttr = data()->real(ConstructionPlugin_Axis::X_DIRECTION());
80 AttributeDoublePtr aYAttr = data()->real(ConstructionPlugin_Axis::Y_DIRECTION());
81 AttributeDoublePtr aZAttr = data()->real(ConstructionPlugin_Axis::Z_DIRECTION());
82 if ((aRef1.get() != NULL) && (aXAttr.get() != NULL) &&
83 (aYAttr.get() != NULL) && (aZAttr.get() != NULL)) {
84 GeomShapePtr aShape1 = aRef1->value();
86 aShape1 = aRef1->context()->shape();
88 std::shared_ptr<GeomAPI_Vertex> aVertex(new GeomAPI_Vertex(aXAttr->value(),
91 if (aShape1->isVertex() && (!aShape1->isEqual(aVertex))) {
92 std::shared_ptr<GeomAPI_Pnt> aStart = GeomAlgoAPI_PointBuilder::point(aShape1);
93 std::shared_ptr<GeomAPI_Pnt> anEnd = GeomAlgoAPI_PointBuilder::point(aVertex);
94 if (aStart->distance(anEnd) > ConstructionPlugin_Axis::MINIMAL_LENGTH()) {
95 std::shared_ptr<GeomAPI_Edge> anEdge = GeomAlgoAPI_EdgeBuilder::line(aStart, anEnd);
97 ResultConstructionPtr aConstr = document()->createConstruction(data());
98 aConstr->setInfinite(true);
99 aConstr->setShape(anEdge);
107 void ConstructionPlugin_Axis::createAxisByCylindricalFace()
109 std::shared_ptr<GeomAPI_Shape> aSelection = data()->selection(CYLINDRICAL_FACE())->value();
110 // update arguments due to the selection value
111 if (aSelection && !aSelection->isNull() && aSelection->isFace()) {
112 std::shared_ptr<GeomAPI_Edge> anEdge = GeomAlgoAPI_EdgeBuilder::cylinderAxis(aSelection);
114 ResultConstructionPtr aConstr = document()->createConstruction(data());
115 aConstr->setInfinite(true);
116 aConstr->setShape(anEdge);
123 void ConstructionPlugin_Axis::execute()
125 AttributeStringPtr aMethodTypeAttr = string(ConstructionPlugin_Axis::METHOD());
126 std::string aMethodType = aMethodTypeAttr->value();
127 if (aMethodType == "AxisByPointsCase") {
128 createAxisByTwoPoints();
129 } else if (aMethodType == "AxisByCylindricalFaceCase") {
130 createAxisByCylindricalFace();
131 } else if (aMethodType == "AxisByPointAndDirection") {
132 createAxisByPointAndDirection();
136 bool ConstructionPlugin_Axis::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
137 std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
139 bool isCustomized = theDefaultPrs.get() != NULL &&
140 theDefaultPrs->customisePresentation(theResult, thePrs, theDefaultPrs);
142 isCustomized = thePrs->setLineStyle(3) || isCustomized;
143 isCustomized = thePrs->setWidth(2) || isCustomized;