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_Reference.h"
35 #include "ModelHighAPI_Selection.h"
39 //--------------------------------------------------------------------------------------
40 void fillAttribute(const std::shared_ptr<GeomAPI_Pnt2d> & theValue,
41 const std::shared_ptr<GeomDataAPI_Point2D> & theAttribute)
43 theAttribute->setValue(theValue);
46 void fillAttribute(const std::shared_ptr<GeomDataAPI_Point2D> & theAttribute,
47 double theX, double theY)
49 theAttribute->setValue(theX, theY);
52 //--------------------------------------------------------------------------------------
53 void fillAttribute(const std::shared_ptr<GeomAPI_Dir> & theValue,
54 const std::shared_ptr<GeomDataAPI_Dir> & theAttribute)
56 theAttribute->setValue(theValue);
59 //--------------------------------------------------------------------------------------
60 void fillAttribute(const std::shared_ptr<GeomAPI_Pnt> & theValue,
61 const std::shared_ptr<GeomDataAPI_Point> & theAttribute)
63 theAttribute->setValue(theValue);
66 //--------------------------------------------------------------------------------------
67 void fillAttribute(bool theValue,
68 const std::shared_ptr<ModelAPI_AttributeBoolean> & theAttribute)
70 theAttribute->setValue(theValue);
73 //--------------------------------------------------------------------------------------
74 void fillAttribute(const ModelHighAPI_Double & theValue,
75 const std::shared_ptr<ModelAPI_AttributeDouble> & theAttribute)
77 theValue.fillAttribute(theAttribute);
79 void fillAttribute(double theValue,
80 const std::shared_ptr<ModelAPI_AttributeDouble> & theAttribute)
82 theAttribute->setValue(theValue);
85 //--------------------------------------------------------------------------------------
86 void fillAttribute(const ModelHighAPI_Integer & theValue,
87 const std::shared_ptr<ModelAPI_AttributeInteger> & theAttribute)
89 theValue.fillAttribute(theAttribute);
91 void fillAttribute(int theValue,
92 const std::shared_ptr<ModelAPI_AttributeInteger> & theAttribute)
94 theAttribute->setValue(theValue);
97 //--------------------------------------------------------------------------------------
98 void fillAttribute(const ModelHighAPI_RefAttr & theValue,
99 const std::shared_ptr<ModelAPI_AttributeRefAttr> & theAttribute)
101 theValue.fillAttribute(theAttribute);
104 //--------------------------------------------------------------------------------------
105 void fillAttribute(const std::list<ModelHighAPI_RefAttr> & theValue,
106 const std::shared_ptr<ModelAPI_AttributeRefAttrList> & theAttribute)
108 theAttribute->clear();
109 for (auto it = theValue.begin(); it != theValue.end(); ++it)
110 it->appendToList(theAttribute);
113 //--------------------------------------------------------------------------------------
114 void fillAttribute(const ModelHighAPI_Reference & theValue,
115 const std::shared_ptr<ModelAPI_AttributeReference> & theAttribute)
117 theValue.fillAttribute(theAttribute);
120 //--------------------------------------------------------------------------------------
121 void fillAttribute(const std::list<ModelHighAPI_Reference> & theValue,
122 const std::shared_ptr<ModelAPI_AttributeRefList> & theAttribute)
124 theAttribute->clear();
125 for (auto it = theValue.begin(); it != theValue.end(); ++it)
126 it->appendToList(theAttribute);
129 //--------------------------------------------------------------------------------------
130 void fillAttribute(const std::shared_ptr<ModelAPI_Object> & theValue,
131 const std::shared_ptr<ModelAPI_AttributeReference> & theAttribute)
133 theAttribute->setValue(theValue);
136 //--------------------------------------------------------------------------------------
137 void fillAttribute(const std::list<std::shared_ptr<ModelAPI_Object> > & theValue,
138 const std::shared_ptr<ModelAPI_AttributeRefList> & theAttribute)
140 theAttribute->clear();
141 for (auto it = theValue.begin(); it != theValue.end(); ++it)
142 theAttribute->append(*it);
146 void fillAttribute(const std::list<ModelHighAPI_Selection> & theValue,
147 const std::shared_ptr<ModelAPI_AttributeRefList> & theAttribute)
149 theAttribute->clear();
150 for (auto it = theValue.begin(); it != theValue.end(); ++it)
151 theAttribute->append(it->resultSubShapePair().first); // use only context
154 //--------------------------------------------------------------------------------------
155 void fillAttribute(const ModelHighAPI_Selection & theValue,
156 const std::shared_ptr<ModelAPI_AttributeSelection> & theAttribute)
158 theValue.fillAttribute(theAttribute);
161 //--------------------------------------------------------------------------------------
162 void fillAttribute(const std::list<ModelHighAPI_Selection> & theValue,
163 const std::shared_ptr<ModelAPI_AttributeSelectionList> & theAttribute)
165 theAttribute->clear();
166 for (auto it = theValue.begin(); it != theValue.end(); ++it)
167 it->appendToList(theAttribute);
170 //--------------------------------------------------------------------------------------
171 void fillAttribute(const std::string & theValue,
172 const std::shared_ptr<ModelAPI_AttributeString> & theAttribute)
174 theAttribute->setValue(theValue);
176 void fillAttribute(const char * theValue,
177 const std::shared_ptr<ModelAPI_AttributeString> & theAttribute)
179 theAttribute->setValue(theValue);
182 //==================================================================================================
183 GeomAPI_Shape::ShapeType shapeTypeByStr(std::string theShapeTypeStr)
185 GeomAPI_Shape::ShapeType aShapeType = GeomAPI_Shape::SHAPE;
187 std::transform(theShapeTypeStr.begin(), theShapeTypeStr.end(), theShapeTypeStr.begin(), ::tolower);
189 if(theShapeTypeStr == "compound") {
190 aShapeType = GeomAPI_Shape::COMPOUND;
191 } else if(theShapeTypeStr == "compsolid") {
192 aShapeType = GeomAPI_Shape::COMPSOLID;
193 } else if(theShapeTypeStr == "solid") {
194 aShapeType = GeomAPI_Shape::SOLID;
195 } else if(theShapeTypeStr == "shell") {
196 aShapeType = GeomAPI_Shape::SHELL;
197 } else if(theShapeTypeStr == "face") {
198 aShapeType = GeomAPI_Shape::FACE;
199 } else if(theShapeTypeStr == "wire") {
200 aShapeType = GeomAPI_Shape::WIRE;
201 } else if(theShapeTypeStr == "edge") {
202 aShapeType = GeomAPI_Shape::EDGE;
203 } else if(theShapeTypeStr == "vertex") {
204 aShapeType = GeomAPI_Shape::VERTEX;
205 } else if(theShapeTypeStr == "shape") {
206 aShapeType = GeomAPI_Shape::SHAPE;
212 //==================================================================================================
213 GeomAPI_Shape::ShapeType getShapeType(const ModelHighAPI_Selection& theSelection)
215 GeomAPI_Shape::ShapeType aShapeType = GeomAPI_Shape::SHAPE;
217 switch(theSelection.variantType()) {
218 case ModelHighAPI_Selection::VT_ResultSubShapePair: {
219 ResultSubShapePair aPair = theSelection.resultSubShapePair();
220 GeomShapePtr aShape = aPair.second;
222 aShape = aPair.first->shape();
227 aShapeType = aShape->shapeType();
230 case ModelHighAPI_Selection::VT_TypeSubShapeNamePair: {
231 TypeSubShapeNamePair aPair = theSelection.typeSubShapeNamePair();
232 std::string aType = aPair.first;
233 aShapeType = shapeTypeByStr(aType);
241 //--------------------------------------------------------------------------------------