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);
92 //--------------------------------------------------------------------------------------
93 void fillAttribute(const ModelHighAPI_RefAttr & theValue,
94 const std::shared_ptr<ModelAPI_AttributeRefAttr> & theAttribute)
96 theValue.fillAttribute(theAttribute);
99 //--------------------------------------------------------------------------------------
100 void fillAttribute(const std::list<ModelHighAPI_RefAttr> & theValue,
101 const std::shared_ptr<ModelAPI_AttributeRefAttrList> & theAttribute)
103 theAttribute->clear();
104 for (auto it = theValue.begin(); it != theValue.end(); ++it)
105 it->appendToList(theAttribute);
108 //--------------------------------------------------------------------------------------
109 void fillAttribute(const ModelHighAPI_Reference & theValue,
110 const std::shared_ptr<ModelAPI_AttributeReference> & theAttribute)
112 theValue.fillAttribute(theAttribute);
115 //--------------------------------------------------------------------------------------
116 void fillAttribute(const std::list<ModelHighAPI_Reference> & theValue,
117 const std::shared_ptr<ModelAPI_AttributeRefList> & theAttribute)
119 theAttribute->clear();
120 for (auto it = theValue.begin(); it != theValue.end(); ++it)
121 it->appendToList(theAttribute);
124 //--------------------------------------------------------------------------------------
125 void fillAttribute(const std::shared_ptr<ModelAPI_Object> & theValue,
126 const std::shared_ptr<ModelAPI_AttributeReference> & theAttribute)
128 theAttribute->setValue(theValue);
131 //--------------------------------------------------------------------------------------
132 void fillAttribute(const std::list<std::shared_ptr<ModelAPI_Object> > & theValue,
133 const std::shared_ptr<ModelAPI_AttributeRefList> & theAttribute)
135 theAttribute->clear();
136 for (auto it = theValue.begin(); it != theValue.end(); ++it)
137 theAttribute->append(*it);
141 void fillAttribute(const std::list<ModelHighAPI_Selection> & theValue,
142 const std::shared_ptr<ModelAPI_AttributeRefList> & theAttribute)
144 theAttribute->clear();
145 for (auto it = theValue.begin(); it != theValue.end(); ++it)
146 theAttribute->append(it->resultSubShapePair().first); // use only context
149 //--------------------------------------------------------------------------------------
150 void fillAttribute(const ModelHighAPI_Selection & theValue,
151 const std::shared_ptr<ModelAPI_AttributeSelection> & theAttribute)
153 theValue.fillAttribute(theAttribute);
156 //--------------------------------------------------------------------------------------
157 void fillAttribute(const std::list<ModelHighAPI_Selection> & theValue,
158 const std::shared_ptr<ModelAPI_AttributeSelectionList> & theAttribute)
160 theAttribute->clear();
161 for (auto it = theValue.begin(); it != theValue.end(); ++it)
162 it->appendToList(theAttribute);
165 //--------------------------------------------------------------------------------------
166 void fillAttribute(const std::string & theValue,
167 const std::shared_ptr<ModelAPI_AttributeString> & theAttribute)
169 theAttribute->setValue(theValue);
171 void fillAttribute(const char * theValue,
172 const std::shared_ptr<ModelAPI_AttributeString> & theAttribute)
174 theAttribute->setValue(theValue);
177 //==================================================================================================
178 GeomAPI_Shape::ShapeType shapeTypeByStr(const std::string& theShapeTypeStr)
180 GeomAPI_Shape::ShapeType aShapeType = GeomAPI_Shape::SHAPE;
182 std::string aShapeTypeStr = theShapeTypeStr;
183 std::transform(aShapeTypeStr.begin(), aShapeTypeStr.end(), aShapeTypeStr.begin(), ::tolower);
185 if(theShapeTypeStr == "compound") {
186 aShapeType = GeomAPI_Shape::COMPOUND;
187 } else if(theShapeTypeStr == "compsolid") {
188 aShapeType = GeomAPI_Shape::COMPSOLID;
189 } else if(theShapeTypeStr == "solid") {
190 aShapeType = GeomAPI_Shape::SOLID;
191 } else if(theShapeTypeStr == "shell") {
192 aShapeType = GeomAPI_Shape::SHELL;
193 } else if(theShapeTypeStr == "face") {
194 aShapeType = GeomAPI_Shape::FACE;
195 } else if(theShapeTypeStr == "wire") {
196 aShapeType = GeomAPI_Shape::WIRE;
197 } else if(theShapeTypeStr == "edge") {
198 aShapeType = GeomAPI_Shape::EDGE;
199 } else if(theShapeTypeStr == "vertex") {
200 aShapeType = GeomAPI_Shape::VERTEX;
201 } else if(theShapeTypeStr == "shape") {
202 aShapeType = GeomAPI_Shape::SHAPE;
208 //==================================================================================================
209 GeomAPI_Shape::ShapeType getShapeType(const ModelHighAPI_Selection& theSelection)
211 GeomAPI_Shape::ShapeType aShapeType = GeomAPI_Shape::SHAPE;
213 switch(theSelection.variantType()) {
214 case ModelHighAPI_Selection::VT_ResultSubShapePair: {
215 ResultSubShapePair aPair = theSelection.resultSubShapePair();
216 GeomShapePtr aShape = aPair.second;
218 aShape = aPair.first->shape();
223 aShapeType = aShape->shapeType();
226 case ModelHighAPI_Selection::VT_TypeSubShapeNamePair: {
227 TypeSubShapeNamePair aPair = theSelection.typeSubShapeNamePair();
228 std::string aType = aPair.first;
229 aShapeType = shapeTypeByStr(aType);
237 //--------------------------------------------------------------------------------------