Salome HOME
Add copyright header according to request of CEA from 06.06.2017
[modules/shaper.git] / src / ConstructionPlugin / ConstructionPlugin_Point.cpp
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #include "ConstructionPlugin_Point.h"
22
23 #include <ModelAPI_AttributeBoolean.h>
24 #include <ModelAPI_AttributeDouble.h>
25 #include <ModelAPI_AttributeSelection.h>
26 #include <ModelAPI_AttributeString.h>
27 #include <ModelAPI_ResultConstruction.h>
28
29 #include <GeomAlgoAPI_PointBuilder.h>
30
31 #include <GeomAPI_Edge.h>
32 #include <GeomAPI_Pnt.h>
33 #include <GeomAPI_Vertex.h>
34
35 //==================================================================================================
36 ConstructionPlugin_Point::ConstructionPlugin_Point()
37 {
38 }
39
40 //==================================================================================================
41 const std::string& ConstructionPlugin_Point::getKind()
42 {
43   static std::string MY_KIND = ConstructionPlugin_Point::ID();
44   return MY_KIND;
45 }
46
47 //==================================================================================================
48 void ConstructionPlugin_Point::initAttributes()
49 {
50   //data()->addAttribute(CREATION_METHOD(), ModelAPI_AttributeString::typeId());
51
52   data()->addAttribute(X(), ModelAPI_AttributeDouble::typeId());
53   data()->addAttribute(Y(), ModelAPI_AttributeDouble::typeId());
54   data()->addAttribute(Z(), ModelAPI_AttributeDouble::typeId());
55
56   /*data()->addAttribute(EDGE(), ModelAPI_AttributeSelection::typeId());
57   data()->addAttribute(DISTANCE_VALUE(), ModelAPI_AttributeDouble::typeId());
58   data()->addAttribute(DISTANCE_PERCENT(), ModelAPI_AttributeBoolean::typeId());
59   data()->addAttribute(REVERSE(), ModelAPI_AttributeBoolean::typeId());
60
61   data()->addAttribute(POINT(), ModelAPI_AttributeSelection::typeId());
62   data()->addAttribute(PLANE(), ModelAPI_AttributeSelection::typeId());
63
64   data()->addAttribute(FIRST_LINE(), ModelAPI_AttributeSelection::typeId());
65   data()->addAttribute(SECOND_LINE(), ModelAPI_AttributeSelection::typeId());
66
67   data()->addAttribute(INTERSECTION_LINE(), ModelAPI_AttributeSelection::typeId());
68   data()->addAttribute(INTERSECTION_PLANE(), ModelAPI_AttributeSelection::typeId());*/
69 }
70
71 //==================================================================================================
72 void ConstructionPlugin_Point::execute()
73 {
74   GeomShapePtr aShape = createByXYZ();
75
76   /*GeomShapePtr aShape;
77
78   std::string aCreationMethod = string(CREATION_METHOD())->value();
79   if(aCreationMethod == CREATION_METHOD_BY_XYZ()) {
80     aShape = createByXYZ();
81   } else if(aCreationMethod == CREATION_METHOD_BY_DISTANCE_ON_EDGE()) {
82     aShape = createByDistanceOnEdge();
83   } else if(aCreationMethod == CREATION_METHOD_BY_PROJECTION()) {
84     aShape = createByProjection();
85   } else if(aCreationMethod == CREATION_METHOD_BY_LINES_INTERSECTION()) {
86     aShape = createByLinesIntersection();
87   } else if(aCreationMethod == CREATION_METHOD_BY_LINE_AND_PLANE_INTERSECTION()) {
88     aShape = createByLineAndPlaneIntersection();
89   }*/
90
91   if(!aShape.get()) {
92     return;
93   }
94
95   std::shared_ptr<ModelAPI_ResultConstruction> aConstr = document()->createConstruction(data());
96   aConstr->setShape(aShape);
97   setResult(aConstr);
98 }
99
100 //==================================================================================================
101 bool ConstructionPlugin_Point::customisePresentation(ResultPtr theResult,
102                                                      AISObjectPtr thePrs,
103                                                 std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
104 {
105   bool isCustomized = theDefaultPrs.get() != NULL &&
106                       theDefaultPrs->customisePresentation(theResult, thePrs, theDefaultPrs);
107   //thePrs->setPointMarker(1, 1.); // Set point as a '+' symbol
108   return true;
109 }
110
111 //==================================================================================================
112 std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByXYZ()
113 {
114   return GeomAlgoAPI_PointBuilder::vertex(real(X())->value(),
115                                           real(Y())->value(),
116                                           real(Z())->value());
117 }
118
119 /*//==================================================================================================
120 std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByDistanceOnEdge()
121 {
122   // Get edge.
123   AttributeSelectionPtr anEdgeSelection = selection(EDGE());
124   GeomShapePtr aShape = anEdgeSelection->value();
125   if(!aShape.get()) {
126     aShape = anEdgeSelection->context()->shape();
127   }
128   std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(aShape));
129
130   // Get distance value and percent flag.
131   double aValue = real(DISTANCE_VALUE())->value();
132   bool anIsPercent = boolean(DISTANCE_PERCENT())->value();
133
134   // Get reverse flag.
135   bool anIsReverse = boolean(REVERSE())->value();
136
137   return GeomAlgoAPI_PointBuilder::vertexOnEdge(anEdge, aValue, anIsPercent, anIsReverse);
138 }
139
140 //==================================================================================================
141 std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByProjection()
142 {
143   // Get point.
144   AttributeSelectionPtr aPointSelection = selection(POINT());
145   GeomShapePtr aPointShape = aPointSelection->value();
146   if(!aPointShape.get()) {
147     aPointShape = aPointSelection->context()->shape();
148   }
149   std::shared_ptr<GeomAPI_Vertex> aVertex(new GeomAPI_Vertex(aPointShape));
150
151   // Get plane.
152   AttributeSelectionPtr aPlaneSelection = selection(PLANE());
153   GeomShapePtr aPlaneShape = aPlaneSelection->value();
154   if(!aPlaneShape.get()) {
155     aPlaneShape = aPlaneSelection->context()->shape();
156   }
157   std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(aPlaneShape));
158
159   return GeomAlgoAPI_PointBuilder::vertexByProjection(aVertex, aFace);
160 }
161
162 //==================================================================================================
163 std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByLinesIntersection()
164 {
165   // Get first line.
166   AttributeSelectionPtr aFirstLineSelection= selection(FIRST_LINE());
167   GeomShapePtr aFirstLineShape = aFirstLineSelection->value();
168   if(!aFirstLineShape.get()) {
169     aFirstLineShape = aFirstLineSelection->context()->shape();
170   }
171   std::shared_ptr<GeomAPI_Edge> aFirstEdge(new GeomAPI_Edge(aFirstLineShape));
172
173   // Get second line.
174   AttributeSelectionPtr aSecondLineSelection= selection(SECOND_LINE());
175   GeomShapePtr aSecondLineShape = aSecondLineSelection->value();
176   if(!aSecondLineShape.get()) {
177     aSecondLineShape = aSecondLineSelection->context()->shape();
178   }
179   std::shared_ptr<GeomAPI_Edge> aSecondEdge(new GeomAPI_Edge(aSecondLineShape));
180
181   return GeomAlgoAPI_PointBuilder::vertexByIntersection(aFirstEdge, aSecondEdge);
182 }
183
184 //==================================================================================================
185 std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByLineAndPlaneIntersection()
186 {
187   // Get line.
188   AttributeSelectionPtr aLineSelection= selection(INTERSECTION_LINE());
189   GeomShapePtr aLineShape = aLineSelection->value();
190   if(!aLineShape.get()) {
191     aLineShape = aLineSelection->context()->shape();
192   }
193   std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(aLineShape));
194
195   // Get plane.
196   AttributeSelectionPtr aPlaneSelection= selection(INTERSECTION_PLANE());
197   GeomShapePtr aPlaneShape = aPlaneSelection->value();
198   if(!aPlaneShape.get()) {
199     aPlaneShape = aPlaneSelection->context()->shape();
200   }
201   std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(aPlaneShape));
202
203   return GeomAlgoAPI_PointBuilder::vertexByIntersection(anEdge, aFace);
204 }*/