Salome HOME
Implementatation of Toolbox as ModelWidget
[modules/shaper.git] / src / ConstructionPlugin / ConstructionPlugin_Axis.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        ConstructionPlugin_Axis.cpp
4 // Created:     12 Dec 2014
5 // Author:      Vitaly Smetannikov
6
7 #include "ConstructionPlugin_Axis.h"
8
9 #include <Config_PropManager.h>
10
11 #include <ModelAPI_AttributeSelection.h>
12 #include <ModelAPI_ResultConstruction.h>
13 #include <ModelAPI_AttributeString.h>
14
15 #include <GeomAPI_Edge.h>
16 #include <GeomAlgoAPI_EdgeBuilder.h>
17 #include <GeomAlgoAPI_PointBuilder.h>
18
19 using namespace std;
20
21 ConstructionPlugin_Axis::ConstructionPlugin_Axis()
22 {
23 }
24
25 void ConstructionPlugin_Axis::initAttributes()
26 {
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());
35 }
36
37 void ConstructionPlugin_Axis::execute()
38 {
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);
49
50         ResultConstructionPtr aConstr = document()->createConstruction(data());
51         aConstr->setShape(anEdge);
52         setResult(aConstr);
53       }
54     }
55   }
56 }
57
58 void ConstructionPlugin_Axis::customisePresentation(AISObjectPtr thePrs)
59 {
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);
64   thePrs->redisplay();
65 }