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 <ModelAPI_AttributeSelection.h>
10 #include <ModelAPI_ResultConstruction.h>
12 #include <GeomAPI_Edge.h>
13 #include <GeomAlgoAPI_EdgeBuilder.h>
14 #include <GeomAlgoAPI_PointBuilder.h>
18 ConstructionPlugin_Axis::ConstructionPlugin_Axis()
22 void ConstructionPlugin_Axis::initAttributes()
24 data()->addAttribute(ConstructionPlugin_Axis::POINT_FIRST(),
25 ModelAPI_AttributeSelection::type());
26 data()->addAttribute(ConstructionPlugin_Axis::POINT_SECOND(),
27 ModelAPI_AttributeSelection::type());
30 void ConstructionPlugin_Axis::execute()
32 AttributeSelectionPtr aRef1 = data()->selection(ConstructionPlugin_Axis::POINT_FIRST());
33 AttributeSelectionPtr aRef2 = data()->selection(ConstructionPlugin_Axis::POINT_SECOND());
34 if ((aRef1.get() != NULL) && (aRef2.get() != NULL)) {
35 GeomShapePtr aShape1 = aRef1->value();
36 GeomShapePtr aShape2 = aRef2->value();
37 if (aShape1->isVertex() && aShape2->isVertex() && (!aShape1->isEqual(aShape2))) {
38 std::shared_ptr<GeomAPI_Pnt> aStart = GeomAlgoAPI_PointBuilder::point(aShape1);
39 std::shared_ptr<GeomAPI_Pnt> anEnd = GeomAlgoAPI_PointBuilder::point(aShape2);
40 if (aStart->distance(anEnd) > ConstructionPlugin_Axis::MINIMAL_LENGTH()) {
41 std::shared_ptr<GeomAPI_Edge> anEdge = GeomAlgoAPI_EdgeBuilder::line(aStart, anEnd);
43 ResultConstructionPtr aConstr = document()->createConstruction(data());
44 aConstr->setShape(anEdge);
51 void ConstructionPlugin_Axis::customisePresentation(AISObjectPtr thePrs)
53 thePrs->setColor(0, 0, 0);
54 thePrs->setLineStyle(3);