1 // Name : ModelHighAPI_Tools.cpp
5 // 07/06/16 - Sergey POKHODENKO - Creation of the file
7 //--------------------------------------------------------------------------------------
8 #include "ModelHighAPI_Tools.h"
9 //--------------------------------------------------------------------------------------
10 #include <GeomAPI_Dir.h>
11 #include <GeomAPI_Pnt.h>
12 #include <GeomAPI_Pnt2d.h>
13 //--------------------------------------------------------------------------------------
14 #include <GeomDataAPI_Dir.h>
15 #include <GeomDataAPI_Point.h>
16 #include <GeomDataAPI_Point2D.h>
17 //--------------------------------------------------------------------------------------
18 #include <ModelAPI_AttributeBoolean.h>
19 #include <ModelAPI_AttributeDocRef.h>
20 #include <ModelAPI_AttributeDouble.h>
21 #include <ModelAPI_AttributeIntArray.h>
22 #include <ModelAPI_AttributeInteger.h>
23 #include <ModelAPI_AttributeRefAttr.h>
24 #include <ModelAPI_AttributeRefAttrList.h>
25 #include <ModelAPI_AttributeReference.h>
26 #include <ModelAPI_AttributeRefList.h>
27 #include <ModelAPI_AttributeSelection.h>
28 #include <ModelAPI_AttributeSelectionList.h>
29 #include <ModelAPI_AttributeString.h>
30 //--------------------------------------------------------------------------------------
31 #include "ModelHighAPI_Double.h"
32 #include "ModelHighAPI_Integer.h"
33 #include "ModelHighAPI_RefAttr.h"
34 #include "ModelHighAPI_Selection.h"
38 //--------------------------------------------------------------------------------------
39 void fillAttribute(const std::shared_ptr<GeomAPI_Pnt2d> & theValue,
40 const std::shared_ptr<GeomDataAPI_Point2D> & theAttribute)
42 theAttribute->setValue(theValue);
45 void fillAttribute(const std::shared_ptr<GeomDataAPI_Point2D> & theAttribute,
46 double theX, double theY)
48 theAttribute->setValue(theX, theY);
51 //--------------------------------------------------------------------------------------
52 void fillAttribute(const std::shared_ptr<GeomAPI_Dir> & theValue,
53 const std::shared_ptr<GeomDataAPI_Dir> & theAttribute)
55 theAttribute->setValue(theValue);
58 //--------------------------------------------------------------------------------------
59 void fillAttribute(const std::shared_ptr<GeomAPI_Pnt> & theValue,
60 const std::shared_ptr<GeomDataAPI_Point> & theAttribute)
62 theAttribute->setValue(theValue);
65 //--------------------------------------------------------------------------------------
66 void fillAttribute(bool theValue,
67 const std::shared_ptr<ModelAPI_AttributeBoolean> & theAttribute)
69 theAttribute->setValue(theValue);
72 //--------------------------------------------------------------------------------------
73 void fillAttribute(const ModelHighAPI_Double & theValue,
74 const std::shared_ptr<ModelAPI_AttributeDouble> & theAttribute)
76 theValue.fillAttribute(theAttribute);
78 void fillAttribute(double theValue,
79 const std::shared_ptr<ModelAPI_AttributeDouble> & theAttribute)
81 theAttribute->setValue(theValue);
84 //--------------------------------------------------------------------------------------
85 void fillAttribute(const ModelHighAPI_Integer & theValue,
86 const std::shared_ptr<ModelAPI_AttributeInteger> & theAttribute)
88 theValue.fillAttribute(theAttribute);
91 //--------------------------------------------------------------------------------------
92 void fillAttribute(const ModelHighAPI_RefAttr & theValue,
93 const std::shared_ptr<ModelAPI_AttributeRefAttr> & theAttribute)
95 theValue.fillAttribute(theAttribute);
98 //--------------------------------------------------------------------------------------
99 void fillAttribute(const std::list<ModelHighAPI_RefAttr> & theValue,
100 const std::shared_ptr<ModelAPI_AttributeRefAttrList> & theAttribute)
102 theAttribute->clear();
103 for (auto it = theValue.begin(); it != theValue.end(); ++it)
104 it->appendToList(theAttribute);
107 //--------------------------------------------------------------------------------------
108 void fillAttribute(const std::shared_ptr<ModelAPI_Object> & theValue,
109 const std::shared_ptr<ModelAPI_AttributeReference> & theAttribute)
111 theAttribute->setValue(theValue);
114 //--------------------------------------------------------------------------------------
115 void fillAttribute(const std::list<std::shared_ptr<ModelAPI_Object> > & theValue,
116 const std::shared_ptr<ModelAPI_AttributeRefList> & theAttribute)
118 theAttribute->clear();
119 for (auto it = theValue.begin(); it != theValue.end(); ++it)
120 theAttribute->append(*it);
123 //--------------------------------------------------------------------------------------
124 void fillAttribute(const ModelHighAPI_Selection & theValue,
125 const std::shared_ptr<ModelAPI_AttributeSelection> & theAttribute)
127 theValue.fillAttribute(theAttribute);
130 //--------------------------------------------------------------------------------------
131 void fillAttribute(const std::list<ModelHighAPI_Selection> & theValue,
132 const std::shared_ptr<ModelAPI_AttributeSelectionList> & theAttribute)
134 theAttribute->clear();
135 for (auto it = theValue.begin(); it != theValue.end(); ++it)
136 it->appendToList(theAttribute);
139 //--------------------------------------------------------------------------------------
140 void fillAttribute(const std::string & theValue,
141 const std::shared_ptr<ModelAPI_AttributeString> & theAttribute)
143 theAttribute->setValue(theValue);
145 void fillAttribute(const char * theValue,
146 const std::shared_ptr<ModelAPI_AttributeString> & theAttribute)
148 theAttribute->setValue(theValue);
151 //==================================================================================================
152 GeomAPI_Shape::ShapeType shapeTypeByStr(const std::string& theShapeTypeStr)
154 GeomAPI_Shape::ShapeType aShapeType = GeomAPI_Shape::SHAPE;
156 std::string aShapeTypeStr = theShapeTypeStr;
157 std::transform(aShapeTypeStr.begin(), aShapeTypeStr.end(), aShapeTypeStr.begin(), ::tolower);
159 if(theShapeTypeStr == "compound") {
160 aShapeType = GeomAPI_Shape::COMPOUND;
161 } else if(theShapeTypeStr == "compsolid") {
162 aShapeType = GeomAPI_Shape::COMPSOLID;
163 } else if(theShapeTypeStr == "solid") {
164 aShapeType = GeomAPI_Shape::SOLID;
165 } else if(theShapeTypeStr == "shell") {
166 aShapeType = GeomAPI_Shape::SHELL;
167 } else if(theShapeTypeStr == "face") {
168 aShapeType = GeomAPI_Shape::FACE;
169 } else if(theShapeTypeStr == "wire") {
170 aShapeType = GeomAPI_Shape::WIRE;
171 } else if(theShapeTypeStr == "edge") {
172 aShapeType = GeomAPI_Shape::EDGE;
173 } else if(theShapeTypeStr == "vertex") {
174 aShapeType = GeomAPI_Shape::VERTEX;
175 } else if(theShapeTypeStr == "shape") {
176 aShapeType = GeomAPI_Shape::SHAPE;
182 //==================================================================================================
183 GeomAPI_Shape::ShapeType getShapeType(const ModelHighAPI_Selection& theSelection)
185 GeomAPI_Shape::ShapeType aShapeType = GeomAPI_Shape::SHAPE;
187 switch(theSelection.variantType()) {
188 case ModelHighAPI_Selection::VT_ResultSubShapePair: {
189 ResultSubShapePair aPair = theSelection.resultSubShapePair();
190 GeomShapePtr aShape = aPair.second;
192 aShape = aPair.first->shape();
197 aShapeType = aShape->shapeType();
200 case ModelHighAPI_Selection::VT_TypeSubShapeNamePair: {
201 TypeSubShapeNamePair aPair = theSelection.typeSubShapeNamePair();
202 std::string aType = aPair.first;
203 aShapeType = shapeTypeByStr(aType);
211 //--------------------------------------------------------------------------------------