Salome HOME
Added option to create Construction Point by distance on edge. Fixed tests.
[modules/shaper.git] / src / ConstructionAPI / ConstructionAPI_Point.cpp
1 // Name   : ConstructionAPI_Point.cpp
2 // Purpose: 
3 //
4 // History:
5 // 29/03/16 - Sergey POKHODENKO - Creation of the file
6
7 #include "ConstructionAPI_Point.h"
8
9 #include <ModelHighAPI_Tools.h>
10
11 //==================================================================================================
12 ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature)
13 : ModelHighAPI_Interface(theFeature)
14 {
15   initialize();
16 }
17
18 //==================================================================================================
19 ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature,
20                                              const ModelHighAPI_Double& theX,
21                                              const ModelHighAPI_Double& theY,
22                                              const ModelHighAPI_Double& theZ)
23 : ModelHighAPI_Interface(theFeature)
24 {
25   if(initialize()) {
26     setByXYZ(theX, theY, theZ);
27   }
28 }
29
30 //==================================================================================================
31 ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature,
32                                              const ModelHighAPI_Selection& theEdge,
33                                              const ModelHighAPI_Double& theDistanceValue,
34                                              const bool theDistancePercent,
35                                              const bool theReverse)
36 : ModelHighAPI_Interface(theFeature)
37 {
38   if(initialize()) {
39     setByDistanceOnEdge(theEdge, theDistanceValue, theDistancePercent, theReverse);
40   }
41 }
42
43 //==================================================================================================
44 ConstructionAPI_Point::~ConstructionAPI_Point()
45 {
46
47 }
48
49 //==================================================================================================
50 void ConstructionAPI_Point::setByXYZ(const ModelHighAPI_Double& theX,
51                                      const ModelHighAPI_Double& theY,
52                                      const ModelHighAPI_Double& theZ)
53 {
54   fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_XYZ(), mycreationMethod);
55   fillAttribute(theX, myx);
56   fillAttribute(theY, myy);
57   fillAttribute(theZ, myz);
58
59   execute();
60 }
61
62 //==================================================================================================
63 void ConstructionAPI_Point::setByDistanceOnEdge(const ModelHighAPI_Selection& theEdge,
64                                                 const ModelHighAPI_Double& theDistanceValue,
65                                                 const bool theDistancePercent,
66                                                 const bool theReverse)
67 {
68   fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_DISTANCE_ON_EDGE(), mycreationMethod);
69   fillAttribute(theEdge, myedge);
70   fillAttribute(theDistanceValue, mydistanceValue);
71   fillAttribute(theDistancePercent, mydistancePercent);
72   fillAttribute(theReverse, myreverse);
73
74   execute();
75 }
76
77 //==================================================================================================
78 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document>& thePart,
79                   const ModelHighAPI_Double& theX,
80                   const ModelHighAPI_Double& theY,
81                   const ModelHighAPI_Double& theZ)
82 {
83   // TODO(spo): check that thePart is not empty
84   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
85   return PointPtr(new ConstructionAPI_Point(aFeature, theX, theY, theZ));
86 }
87
88 //==================================================================================================
89 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
90                   const ModelHighAPI_Selection& theEdge,
91                   const ModelHighAPI_Double& theDistanceValue,
92                   const bool theDistancePercent,
93                   const bool theReverse)
94 {
95   // TODO(spo): check that thePart is not empty
96   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
97   return PointPtr(new ConstructionAPI_Point(aFeature, theEdge, theDistanceValue, theDistancePercent, theReverse));
98 }