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(std::string theShapeTypeStr)
180 GeomAPI_Shape::ShapeType aShapeType = GeomAPI_Shape::SHAPE;
182 std::transform(theShapeTypeStr.begin(), theShapeTypeStr.end(), theShapeTypeStr.begin(), ::tolower);
184 if(theShapeTypeStr == "compound") {
185 aShapeType = GeomAPI_Shape::COMPOUND;
186 } else if(theShapeTypeStr == "compsolid") {
187 aShapeType = GeomAPI_Shape::COMPSOLID;
188 } else if(theShapeTypeStr == "solid") {
189 aShapeType = GeomAPI_Shape::SOLID;
190 } else if(theShapeTypeStr == "shell") {
191 aShapeType = GeomAPI_Shape::SHELL;
192 } else if(theShapeTypeStr == "face") {
193 aShapeType = GeomAPI_Shape::FACE;
194 } else if(theShapeTypeStr == "wire") {
195 aShapeType = GeomAPI_Shape::WIRE;
196 } else if(theShapeTypeStr == "edge") {
197 aShapeType = GeomAPI_Shape::EDGE;
198 } else if(theShapeTypeStr == "vertex") {
199 aShapeType = GeomAPI_Shape::VERTEX;
200 } else if(theShapeTypeStr == "shape") {
201 aShapeType = GeomAPI_Shape::SHAPE;
207 //==================================================================================================
208 GeomAPI_Shape::ShapeType getShapeType(const ModelHighAPI_Selection& theSelection)
210 GeomAPI_Shape::ShapeType aShapeType = GeomAPI_Shape::SHAPE;
212 switch(theSelection.variantType()) {
213 case ModelHighAPI_Selection::VT_ResultSubShapePair: {
214 ResultSubShapePair aPair = theSelection.resultSubShapePair();
215 GeomShapePtr aShape = aPair.second;
217 aShape = aPair.first->shape();
222 aShapeType = aShape->shapeType();
225 case ModelHighAPI_Selection::VT_TypeSubShapeNamePair: {
226 TypeSubShapeNamePair aPair = theSelection.typeSubShapeNamePair();
227 std::string aType = aPair.first;
228 aShapeType = shapeTypeByStr(aType);
236 //--------------------------------------------------------------------------------------