]> SALOME platform Git repositories - modules/shaper.git/blob - src/ConstructionPlugin/ConstructionPlugin_Point.cpp
Salome HOME
Issue #1649: Added options to create plane by three points;
[modules/shaper.git] / src / ConstructionPlugin / ConstructionPlugin_Point.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        ConstructionPlugin_Point.cxx
4 // Created:     27 Mar 2014
5 // Author:      Mikhail PONIKAROV
6
7 #include "ConstructionPlugin_Point.h"
8
9 #include <ModelAPI_AttributeBoolean.h>
10 #include <ModelAPI_AttributeDouble.h>
11 #include <ModelAPI_AttributeSelection.h>
12 #include <ModelAPI_AttributeString.h>
13 #include <ModelAPI_ResultConstruction.h>
14
15 #include <GeomAlgoAPI_PointBuilder.h>
16
17 #include <GeomAPI_Edge.h>
18 #include <GeomAPI_Pnt.h>
19 #include <GeomAPI_Vertex.h>
20
21 //==================================================================================================
22 ConstructionPlugin_Point::ConstructionPlugin_Point()
23 {
24 }
25
26 //==================================================================================================
27 const std::string& ConstructionPlugin_Point::getKind()
28 {
29   static std::string MY_KIND = ConstructionPlugin_Point::ID();
30   return MY_KIND;
31 }
32
33 //==================================================================================================
34 void ConstructionPlugin_Point::initAttributes()
35 {
36   data()->addAttribute(CREATION_METHOD(), ModelAPI_AttributeString::typeId());
37
38   data()->addAttribute(X(), ModelAPI_AttributeDouble::typeId());
39   data()->addAttribute(Y(), ModelAPI_AttributeDouble::typeId());
40   data()->addAttribute(Z(), ModelAPI_AttributeDouble::typeId());
41
42   data()->addAttribute(EDGE(), ModelAPI_AttributeSelection::typeId());
43   data()->addAttribute(DISTANCE_VALUE(), ModelAPI_AttributeDouble::typeId());
44   data()->addAttribute(DISTANCE_PERCENT(), ModelAPI_AttributeBoolean::typeId());
45   data()->addAttribute(REVERSE(), ModelAPI_AttributeBoolean::typeId());
46
47   data()->addAttribute(POINT(), ModelAPI_AttributeSelection::typeId());
48   data()->addAttribute(PLANE(), ModelAPI_AttributeSelection::typeId());
49
50   data()->addAttribute(FIRST_LINE(), ModelAPI_AttributeSelection::typeId());
51   data()->addAttribute(SECOND_LINE(), ModelAPI_AttributeSelection::typeId());
52
53   data()->addAttribute(INTERSECTION_LINE(), ModelAPI_AttributeSelection::typeId());
54   data()->addAttribute(INTERSECTION_PLANE(), ModelAPI_AttributeSelection::typeId());
55 }
56
57 //==================================================================================================
58 void ConstructionPlugin_Point::execute()
59 {
60   GeomShapePtr aShape;
61
62   std::string aCreationMethod = string(CREATION_METHOD())->value();
63   if(aCreationMethod == CREATION_METHOD_BY_XYZ()) {
64     aShape = createByXYZ();
65   } else if(aCreationMethod == CREATION_METHOD_BY_DISTANCE_ON_EDGE()) {
66     aShape = createByDistanceOnEdge();
67   } else if(aCreationMethod == CREATION_METHOD_BY_PROJECTION()) {
68     aShape = createByProjection();
69   } else if(aCreationMethod == CREATION_METHOD_BY_LINES_INTERSECTION()) {
70     aShape = createByLinesIntersection();
71   } else if(aCreationMethod == CREATION_METHOD_BY_LINE_AND_PLANE_INTERSECTION()) {
72     aShape = createByLineAndPlaneIntersection();
73   }
74
75   if(!aShape.get()) {
76     return;
77   }
78
79   std::shared_ptr<ModelAPI_ResultConstruction> aConstr = document()->createConstruction(data());
80   aConstr->setShape(aShape);
81   setResult(aConstr);
82 }
83
84 //==================================================================================================
85 bool ConstructionPlugin_Point::customisePresentation(ResultPtr theResult,
86                                                      AISObjectPtr thePrs,
87                                                      std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
88 {
89   bool isCustomized = theDefaultPrs.get() != NULL &&
90                       theDefaultPrs->customisePresentation(theResult, thePrs, theDefaultPrs);
91   //thePrs->setPointMarker(1, 1.); // Set point as a '+' symbol
92   return true;
93 }
94
95 //==================================================================================================
96 std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByXYZ()
97 {
98   return GeomAlgoAPI_PointBuilder::vertex(real(X())->value(),
99                                           real(Y())->value(),
100                                           real(Z())->value());
101 }
102
103 //==================================================================================================
104 std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByDistanceOnEdge()
105 {
106   // Get edge.
107   AttributeSelectionPtr anEdgeSelection = selection(EDGE());
108   GeomShapePtr aShape = anEdgeSelection->value();
109   if(!aShape.get()) {
110     aShape = anEdgeSelection->context()->shape();
111   }
112   std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(aShape));
113
114   // Get distance value and percent flag.
115   double aValue = real(DISTANCE_VALUE())->value();
116   bool anIsPercent = boolean(DISTANCE_PERCENT())->value();
117
118   // Get reverse flag.
119   bool anIsReverse = boolean(REVERSE())->value();
120
121   return GeomAlgoAPI_PointBuilder::vertexOnEdge(anEdge, aValue, anIsPercent, anIsReverse);
122 }
123
124 //==================================================================================================
125 std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByProjection()
126 {
127   // Get point.
128   AttributeSelectionPtr aPointSelection = selection(POINT());
129   GeomShapePtr aPointShape = aPointSelection->value();
130   if(!aPointShape.get()) {
131     aPointShape = aPointSelection->context()->shape();
132   }
133   std::shared_ptr<GeomAPI_Vertex> aVertex(new GeomAPI_Vertex(aPointShape));
134
135   // Get plane.
136   AttributeSelectionPtr aPlaneSelection = selection(PLANE());
137   GeomShapePtr aPlaneShape = aPlaneSelection->value();
138   if(!aPlaneShape.get()) {
139     aPlaneShape = aPlaneSelection->context()->shape();
140   }
141   std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(aPlaneShape));
142
143   return GeomAlgoAPI_PointBuilder::vertexByProjection(aVertex, aFace);
144 }
145
146 //==================================================================================================
147 std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByLinesIntersection()
148 {
149   // Get first line.
150   AttributeSelectionPtr aFirstLineSelection= selection(FIRST_LINE());
151   GeomShapePtr aFirstLineShape = aFirstLineSelection->value();
152   if(!aFirstLineShape.get()) {
153     aFirstLineShape = aFirstLineSelection->context()->shape();
154   }
155   std::shared_ptr<GeomAPI_Edge> aFirstEdge(new GeomAPI_Edge(aFirstLineShape));
156
157   // Get second line.
158   AttributeSelectionPtr aSecondLineSelection= selection(SECOND_LINE());
159   GeomShapePtr aSecondLineShape = aSecondLineSelection->value();
160   if(!aSecondLineShape.get()) {
161     aSecondLineShape = aSecondLineSelection->context()->shape();
162   }
163   std::shared_ptr<GeomAPI_Edge> aSecondEdge(new GeomAPI_Edge(aSecondLineShape));
164
165   return GeomAlgoAPI_PointBuilder::vertexByIntersection(aFirstEdge, aSecondEdge);
166 }
167
168 //==================================================================================================
169 std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByLineAndPlaneIntersection()
170 {
171   // Get line.
172   AttributeSelectionPtr aLineSelection= selection(INTERSECTION_LINE());
173   GeomShapePtr aLineShape = aLineSelection->value();
174   if(!aLineShape.get()) {
175     aLineShape = aLineSelection->context()->shape();
176   }
177   std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(aLineShape));
178
179   // Get plane.
180   AttributeSelectionPtr aPlaneSelection= selection(INTERSECTION_PLANE());
181   GeomShapePtr aPlaneShape = aPlaneSelection->value();
182   if(!aPlaneShape.get()) {
183     aPlaneShape = aPlaneSelection->context()->shape();
184   }
185   std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(aPlaneShape));
186
187   return GeomAlgoAPI_PointBuilder::vertexByIntersection(anEdge, aFace);
188 }