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>
21 ConstructionPlugin_Axis::ConstructionPlugin_Axis()
25 void ConstructionPlugin_Axis::initAttributes()
27 data()->addAttribute(ConstructionPlugin_Axis::METHOD(),
28 ModelAPI_AttributeString::type());
29 data()->addAttribute(ConstructionPlugin_Axis::POINT_FIRST(),
30 ModelAPI_AttributeSelection::type());
31 data()->addAttribute(ConstructionPlugin_Axis::POINT_SECOND(),
32 ModelAPI_AttributeSelection::type());
33 data()->addAttribute(ConstructionPlugin_Axis::CYLINDRICAL_FACE(),
34 ModelAPI_AttributeSelection::type());
37 void ConstructionPlugin_Axis::execute()
39 AttributeSelectionPtr aRef1 = data()->selection(ConstructionPlugin_Axis::POINT_FIRST());
40 AttributeSelectionPtr aRef2 = data()->selection(ConstructionPlugin_Axis::POINT_SECOND());
41 if ((aRef1.get() != NULL) && (aRef2.get() != NULL)) {
42 GeomShapePtr aShape1 = aRef1->value();
43 GeomShapePtr aShape2 = aRef2->value();
44 if (aShape1->isVertex() && aShape2->isVertex() && (!aShape1->isEqual(aShape2))) {
45 std::shared_ptr<GeomAPI_Pnt> aStart = GeomAlgoAPI_PointBuilder::point(aShape1);
46 std::shared_ptr<GeomAPI_Pnt> anEnd = GeomAlgoAPI_PointBuilder::point(aShape2);
47 if (aStart->distance(anEnd) > ConstructionPlugin_Axis::MINIMAL_LENGTH()) {
48 std::shared_ptr<GeomAPI_Edge> anEdge = GeomAlgoAPI_EdgeBuilder::line(aStart, anEnd);
50 ResultConstructionPtr aConstr = document()->createConstruction(data());
51 aConstr->setShape(anEdge);
58 void ConstructionPlugin_Axis::customisePresentation(AISObjectPtr thePrs)
60 std::vector<int> aRGB = Config_PropManager::color("Visualization", "construction_axis_color",
61 ConstructionPlugin_Axis::DEFAULT_COLOR());
62 thePrs->setColor(aRGB[0], aRGB[1], aRGB[2]);
63 thePrs->setLineStyle(3);