Salome HOME
Merge branch 'Dev_1.1.0' of newgeom:newgeom.git into Dev_1.1.0
[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
14 #include <GeomAPI_Edge.h>
15 #include <GeomAlgoAPI_EdgeBuilder.h>
16 #include <GeomAlgoAPI_PointBuilder.h>
17
18 using namespace std;
19
20 ConstructionPlugin_Axis::ConstructionPlugin_Axis()
21 {
22 }
23
24 void ConstructionPlugin_Axis::initAttributes()
25 {
26   data()->addAttribute(ConstructionPlugin_Axis::POINT_FIRST(),
27                        ModelAPI_AttributeSelection::type());
28   data()->addAttribute(ConstructionPlugin_Axis::POINT_SECOND(),
29                        ModelAPI_AttributeSelection::type());
30 }
31
32 void ConstructionPlugin_Axis::execute()
33 {
34   AttributeSelectionPtr aRef1 = data()->selection(ConstructionPlugin_Axis::POINT_FIRST());
35   AttributeSelectionPtr aRef2 = data()->selection(ConstructionPlugin_Axis::POINT_SECOND());
36   if ((aRef1.get() != NULL) && (aRef2.get() != NULL)) {
37     GeomShapePtr aShape1 = aRef1->value();
38     GeomShapePtr aShape2 = aRef2->value();
39     if (aShape1->isVertex() && aShape2->isVertex() && (!aShape1->isEqual(aShape2))) {
40       std::shared_ptr<GeomAPI_Pnt> aStart = GeomAlgoAPI_PointBuilder::point(aShape1);
41       std::shared_ptr<GeomAPI_Pnt> anEnd = GeomAlgoAPI_PointBuilder::point(aShape2);
42       if (aStart->distance(anEnd) > ConstructionPlugin_Axis::MINIMAL_LENGTH()) {
43         std::shared_ptr<GeomAPI_Edge> anEdge = GeomAlgoAPI_EdgeBuilder::line(aStart, anEnd);
44
45         ResultConstructionPtr aConstr = document()->createConstruction(data());
46         aConstr->setShape(anEdge);
47         setResult(aConstr);
48       }
49     }
50   }
51 }
52
53 void ConstructionPlugin_Axis::customisePresentation(AISObjectPtr thePrs)
54 {
55   std::vector<int> aRGB = Config_PropManager::color("Visualization", "construction_axis_color",
56                                                     ConstructionPlugin_Axis::DEFAULT_COLOR());
57   thePrs->setColor(aRGB[0], aRGB[1], aRGB[2]);
58   thePrs->setLineStyle(3);
59   thePrs->redisplay();
60 }