Salome HOME
Fix ConstructionPlugin_Plane created by Rotation
[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 = createByXYZ();
61
62   /*GeomShapePtr aShape;
63
64   std::string aCreationMethod = string(CREATION_METHOD())->value();
65   if(aCreationMethod == CREATION_METHOD_BY_XYZ()) {
66     aShape = createByXYZ();
67   } else if(aCreationMethod == CREATION_METHOD_BY_DISTANCE_ON_EDGE()) {
68     aShape = createByDistanceOnEdge();
69   } else if(aCreationMethod == CREATION_METHOD_BY_PROJECTION()) {
70     aShape = createByProjection();
71   } else if(aCreationMethod == CREATION_METHOD_BY_LINES_INTERSECTION()) {
72     aShape = createByLinesIntersection();
73   } else if(aCreationMethod == CREATION_METHOD_BY_LINE_AND_PLANE_INTERSECTION()) {
74     aShape = createByLineAndPlaneIntersection();
75   }*/
76
77   if(!aShape.get()) {
78     return;
79   }
80
81   std::shared_ptr<ModelAPI_ResultConstruction> aConstr = document()->createConstruction(data());
82   aConstr->setShape(aShape);
83   setResult(aConstr);
84 }
85
86 //==================================================================================================
87 bool ConstructionPlugin_Point::customisePresentation(ResultPtr theResult,
88                                                      AISObjectPtr thePrs,
89                                                 std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
90 {
91   bool isCustomized = theDefaultPrs.get() != NULL &&
92                       theDefaultPrs->customisePresentation(theResult, thePrs, theDefaultPrs);
93   //thePrs->setPointMarker(1, 1.); // Set point as a '+' symbol
94   return true;
95 }
96
97 //==================================================================================================
98 std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByXYZ()
99 {
100   return GeomAlgoAPI_PointBuilder::vertex(real(X())->value(),
101                                           real(Y())->value(),
102                                           real(Z())->value());
103 }
104
105 /*//==================================================================================================
106 std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByDistanceOnEdge()
107 {
108   // Get edge.
109   AttributeSelectionPtr anEdgeSelection = selection(EDGE());
110   GeomShapePtr aShape = anEdgeSelection->value();
111   if(!aShape.get()) {
112     aShape = anEdgeSelection->context()->shape();
113   }
114   std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(aShape));
115
116   // Get distance value and percent flag.
117   double aValue = real(DISTANCE_VALUE())->value();
118   bool anIsPercent = boolean(DISTANCE_PERCENT())->value();
119
120   // Get reverse flag.
121   bool anIsReverse = boolean(REVERSE())->value();
122
123   return GeomAlgoAPI_PointBuilder::vertexOnEdge(anEdge, aValue, anIsPercent, anIsReverse);
124 }
125
126 //==================================================================================================
127 std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByProjection()
128 {
129   // Get point.
130   AttributeSelectionPtr aPointSelection = selection(POINT());
131   GeomShapePtr aPointShape = aPointSelection->value();
132   if(!aPointShape.get()) {
133     aPointShape = aPointSelection->context()->shape();
134   }
135   std::shared_ptr<GeomAPI_Vertex> aVertex(new GeomAPI_Vertex(aPointShape));
136
137   // Get plane.
138   AttributeSelectionPtr aPlaneSelection = selection(PLANE());
139   GeomShapePtr aPlaneShape = aPlaneSelection->value();
140   if(!aPlaneShape.get()) {
141     aPlaneShape = aPlaneSelection->context()->shape();
142   }
143   std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(aPlaneShape));
144
145   return GeomAlgoAPI_PointBuilder::vertexByProjection(aVertex, aFace);
146 }
147
148 //==================================================================================================
149 std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByLinesIntersection()
150 {
151   // Get first line.
152   AttributeSelectionPtr aFirstLineSelection= selection(FIRST_LINE());
153   GeomShapePtr aFirstLineShape = aFirstLineSelection->value();
154   if(!aFirstLineShape.get()) {
155     aFirstLineShape = aFirstLineSelection->context()->shape();
156   }
157   std::shared_ptr<GeomAPI_Edge> aFirstEdge(new GeomAPI_Edge(aFirstLineShape));
158
159   // Get second line.
160   AttributeSelectionPtr aSecondLineSelection= selection(SECOND_LINE());
161   GeomShapePtr aSecondLineShape = aSecondLineSelection->value();
162   if(!aSecondLineShape.get()) {
163     aSecondLineShape = aSecondLineSelection->context()->shape();
164   }
165   std::shared_ptr<GeomAPI_Edge> aSecondEdge(new GeomAPI_Edge(aSecondLineShape));
166
167   return GeomAlgoAPI_PointBuilder::vertexByIntersection(aFirstEdge, aSecondEdge);
168 }
169
170 //==================================================================================================
171 std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByLineAndPlaneIntersection()
172 {
173   // Get line.
174   AttributeSelectionPtr aLineSelection= selection(INTERSECTION_LINE());
175   GeomShapePtr aLineShape = aLineSelection->value();
176   if(!aLineShape.get()) {
177     aLineShape = aLineSelection->context()->shape();
178   }
179   std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(aLineShape));
180
181   // Get plane.
182   AttributeSelectionPtr aPlaneSelection= selection(INTERSECTION_PLANE());
183   GeomShapePtr aPlaneShape = aPlaneSelection->value();
184   if(!aPlaneShape.get()) {
185     aPlaneShape = aPlaneSelection->context()->shape();
186   }
187   std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(aPlaneShape));
188
189   return GeomAlgoAPI_PointBuilder::vertexByIntersection(anEdge, aFace);
190 }*/