14bbbdcb |
1 | // Created on: 2017-06-16 |
2 | // Created by: Natalia ERMOLAEVA |
3 | // Copyright (c) 2017 OPEN CASCADE SAS |
4 | // |
5 | // This file is part of Open CASCADE Technology software library. |
6 | // |
7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published |
9 | // by the Free Software Foundation, with special exception defined in the file |
10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
11 | // distribution for complete text of the license and disclaimer of any warranty. |
12 | // |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
15 | |
0cb512c0 |
16 | #include <inspector/TInspectorAPI_PluginParameters.hxx> |
14bbbdcb |
17 | |
14bbbdcb |
18 | IMPLEMENT_STANDARD_RTTIEXT (TInspectorAPI_PluginParameters, Standard_Transient) |
14bbbdcb |
19 | |
14bbbdcb |
20 | // ======================================================================= |
0cb512c0 |
21 | // function : SetParameters |
14bbbdcb |
22 | // purpose : |
23 | // ======================================================================= |
24 | void TInspectorAPI_PluginParameters::SetParameters (const TCollection_AsciiString& thePluginName, |
0cb512c0 |
25 | const NCollection_List<Handle(Standard_Transient)>& theParameters, |
26 | const Standard_Boolean&) |
14bbbdcb |
27 | { |
28 | if (theParameters.Size() > 0) |
29 | myParameters.Bind (thePluginName, theParameters); |
30 | else |
31 | myParameters.UnBind (thePluginName); |
32 | } |
33 | |
34 | // ======================================================================= |
0cb512c0 |
35 | // function : AddFileName |
14bbbdcb |
36 | // purpose : |
37 | // ======================================================================= |
38 | void TInspectorAPI_PluginParameters::AddFileName (const TCollection_AsciiString& thePluginName, |
39 | const TCollection_AsciiString& theFileName) |
40 | { |
6822a3be |
41 | if (myFileNames.IsBound (thePluginName)) |
42 | myFileNames.ChangeFind (thePluginName).Append (theFileName); |
14bbbdcb |
43 | else |
44 | { |
45 | NCollection_List<TCollection_AsciiString> aNames; |
46 | aNames.Append (theFileName); |
47 | myFileNames.Bind (thePluginName, aNames); |
48 | } |
49 | } |
50 | |
51 | // ======================================================================= |
0cb512c0 |
52 | // function : SetFileNames |
14bbbdcb |
53 | // purpose : |
54 | // ======================================================================= |
55 | void TInspectorAPI_PluginParameters::SetFileNames (const TCollection_AsciiString& thePluginName, |
56 | const NCollection_List<TCollection_AsciiString>& theFileNames) |
57 | { |
58 | if (theFileNames.Size() > 0) |
59 | myFileNames.Bind (thePluginName, theFileNames); |
60 | else |
0cb512c0 |
61 | myFileNames.UnBind (thePluginName); |
62 | } |
63 | |
64 | // ======================================================================= |
65 | // function : SetSelectedNames |
66 | // purpose : |
67 | // ======================================================================= |
68 | void TInspectorAPI_PluginParameters::SetSelectedNames (const TCollection_AsciiString& thePluginName, |
69 | const NCollection_List<TCollection_AsciiString>& theItemNames) |
70 | { |
71 | mySelectedItemNames.Bind (thePluginName, theItemNames); |
72 | } |
14bbbdcb |
73 | |
0cb512c0 |
74 | // ======================================================================= |
75 | // function : SetSelected |
76 | // purpose : |
77 | // ======================================================================= |
78 | void TInspectorAPI_PluginParameters::SetSelected (const TCollection_AsciiString& thePluginName, |
79 | const NCollection_List<Handle(Standard_Transient)>& theObjects) |
80 | { |
81 | if (theObjects.Size() > 0) |
82 | mySelectedObjects.Bind (thePluginName, theObjects); |
83 | else |
84 | mySelectedObjects.UnBind (thePluginName); |
14bbbdcb |
85 | } |
86 | |
87 | // ======================================================================= |
0cb512c0 |
88 | // function : FindParameters |
14bbbdcb |
89 | // purpose : |
90 | // ======================================================================= |
91 | bool TInspectorAPI_PluginParameters::FindParameters (const TCollection_AsciiString& thePluginName) |
92 | { |
6822a3be |
93 | return myParameters.IsBound (thePluginName); |
14bbbdcb |
94 | } |
95 | |
96 | // ======================================================================= |
0cb512c0 |
97 | // function : Parameters |
14bbbdcb |
98 | // purpose : |
99 | // ======================================================================= |
100 | const NCollection_List<Handle(Standard_Transient)>& TInspectorAPI_PluginParameters::Parameters |
101 | (const TCollection_AsciiString& thePluginName) |
102 | { |
103 | return myParameters.Find (thePluginName); |
104 | } |
105 | |
106 | // ======================================================================= |
0cb512c0 |
107 | // function : FindFileNames |
14bbbdcb |
108 | // purpose : |
109 | // ======================================================================= |
110 | bool TInspectorAPI_PluginParameters::FindFileNames (const TCollection_AsciiString& thePluginName) |
111 | { |
6822a3be |
112 | return myFileNames.IsBound (thePluginName); |
14bbbdcb |
113 | } |
114 | |
115 | // ======================================================================= |
0cb512c0 |
116 | // function : FileNames |
14bbbdcb |
117 | // purpose : |
118 | // ======================================================================= |
119 | const NCollection_List<TCollection_AsciiString>& TInspectorAPI_PluginParameters::FileNames |
120 | (const TCollection_AsciiString& thePluginName) |
121 | { |
122 | return myFileNames.Find (thePluginName); |
123 | } |
0cb512c0 |
124 | |
125 | // ======================================================================= |
126 | // function : FindSelectedNames |
127 | // purpose : |
128 | // ======================================================================= |
129 | bool TInspectorAPI_PluginParameters::FindSelectedNames (const TCollection_AsciiString& thePluginName) |
130 | { |
6822a3be |
131 | return mySelectedItemNames.IsBound (thePluginName); |
0cb512c0 |
132 | } |
133 | |
134 | // ======================================================================= |
135 | // function : GetSelectedNames |
136 | // purpose : |
137 | // ======================================================================= |
138 | const NCollection_List<TCollection_AsciiString>& TInspectorAPI_PluginParameters::GetSelectedNames |
139 | (const TCollection_AsciiString& thePluginName) |
140 | { |
141 | return mySelectedItemNames.Find (thePluginName); |
142 | } |
143 | |
144 | // ======================================================================= |
145 | // function : GetSelectedObjects |
146 | // purpose : |
147 | // ======================================================================= |
148 | Standard_Boolean TInspectorAPI_PluginParameters::GetSelectedObjects (const TCollection_AsciiString& thePluginName, |
149 | NCollection_List<Handle(Standard_Transient)>& theObjects) |
150 | { |
151 | return mySelectedObjects.Find (thePluginName, theObjects); |
152 | } |
6822a3be |
153 | |
154 | // ======================================================================= |
155 | // function : toString |
156 | // purpose : |
157 | // ======================================================================= |
158 | TCollection_AsciiString toString (const TopLoc_Location& theLocation) |
159 | { |
160 | TCollection_AsciiString anInfo; |
161 | gp_Trsf aTrsf = theLocation.Transformation(); |
162 | for (int aRowId = 1; aRowId <= 3; aRowId++) |
163 | { |
164 | if (!anInfo.IsEmpty()) |
165 | anInfo += " "; |
166 | for (int aColumnId = 1; aColumnId <= 4; aColumnId++) |
167 | { |
168 | if (aColumnId > 1) |
169 | anInfo += ","; |
170 | anInfo += TCollection_AsciiString (aTrsf.Value (aRowId, aColumnId)); |
171 | } |
172 | } |
173 | return anInfo; |
174 | } |
175 | |
176 | // ======================================================================= |
177 | // function : ParametersToString |
178 | // purpose : |
179 | // ======================================================================= |
180 | TCollection_AsciiString TInspectorAPI_PluginParameters::ParametersToString (const TopoDS_Shape& theShape) |
181 | { |
182 | const TopLoc_Location& aLocation = theShape.Location(); |
183 | TCollection_AsciiString aLocationStr = toString (aLocation); |
184 | |
185 | TopAbs_Orientation anOrientation = theShape.Orientation(); |
186 | Standard_SStream aSStream; |
187 | TopAbs::Print (anOrientation, aSStream); |
188 | return TCollection_AsciiString (aSStream.str().c_str()) + ":" + aLocationStr; |
189 | } |
190 | |
191 | // ======================================================================= |
192 | // function : fromString |
193 | // purpose : |
194 | // ======================================================================= |
195 | TopLoc_Location fromString (const TCollection_AsciiString& theValue) |
196 | { |
197 | NCollection_Mat4<Standard_Real> aValues; |
198 | |
199 | TCollection_AsciiString aCurrentString = theValue; |
200 | Standard_Integer aPosition = aCurrentString.Search (" "); |
201 | if (aPosition < 0) |
202 | return TopLoc_Location(); |
203 | TCollection_AsciiString aTailString = aCurrentString.Split (aPosition); |
204 | Standard_Integer aRow = 0; |
205 | while (!aCurrentString.IsEmpty()) |
206 | { |
207 | TCollection_AsciiString aValueString = aCurrentString; |
208 | aPosition = aValueString.Search (","); |
209 | if (aPosition < 0 ) |
210 | break; |
211 | aCurrentString = aValueString.Split (aPosition); |
212 | Standard_Integer aColumn = 0; |
213 | while (!aValueString.IsEmpty()) |
214 | { |
215 | aPosition = aCurrentString.Search (" "); |
216 | if (aPosition > 0) |
217 | aValueString.Split (aValueString.Length() - 1); |
218 | |
219 | aValues.SetValue (aRow, aColumn, aValueString.RealValue()); |
220 | aColumn++; |
221 | if (aCurrentString.IsEmpty()) |
222 | break; |
223 | aValueString = aCurrentString; |
224 | aPosition = aValueString.Search (","); |
225 | if (aPosition < 0 ) |
226 | { |
227 | aValueString = aCurrentString; |
228 | aCurrentString = TCollection_AsciiString(); |
229 | } |
230 | else |
231 | aCurrentString = aValueString.Split (aPosition); |
232 | } |
233 | if (aTailString.IsEmpty()) |
234 | break; |
235 | aCurrentString = aTailString; |
236 | aPosition = aCurrentString.Search (" "); |
237 | if (aPosition < 0 ) |
238 | { |
239 | aCurrentString = aTailString; |
240 | aTailString = TCollection_AsciiString(); |
241 | } |
242 | else |
243 | aTailString = aCurrentString.Split (aPosition); |
244 | aRow++; |
245 | } |
246 | |
247 | //if (aValues.Rows() != 3 || aValues.Cols() != 4) |
248 | // return TopLoc_Location(); |
249 | |
250 | gp_Trsf aTrsf; |
251 | aTrsf.SetValues (aValues.GetValue (0, 0), aValues.GetValue (0, 1), aValues.GetValue (0, 2), aValues.GetValue (0, 3), |
252 | aValues.GetValue (1, 0), aValues.GetValue (1, 1), aValues.GetValue (1, 2), aValues.GetValue (1, 3), |
253 | aValues.GetValue (2, 0), aValues.GetValue (2, 1), aValues.GetValue (2, 2), aValues.GetValue (2, 3)); |
254 | return TopLoc_Location (aTrsf); |
255 | } |
256 | |
257 | // ======================================================================= |
258 | // function : ParametersToShape |
259 | // purpose : |
260 | // ======================================================================= |
261 | void TInspectorAPI_PluginParameters::ParametersToShape (const TCollection_AsciiString& theValue, |
262 | TopoDS_Shape& theShape) |
263 | { |
264 | int aSeparatorPos = theValue.Search (":"); |
265 | TCollection_AsciiString anOrientationStr = theValue; |
266 | TCollection_AsciiString aLocationStr = anOrientationStr.Split (aSeparatorPos); |
267 | // orientation |
268 | if (anOrientationStr.Length() < 2) |
269 | return; |
270 | anOrientationStr.Split (anOrientationStr.Length() - 1); |
271 | |
272 | TopAbs_Orientation anOrientation; |
273 | if (!TopAbs::ShapeOrientationFromString (anOrientationStr.ToCString(), anOrientation)) |
274 | return; |
275 | // location |
276 | TopLoc_Location aLocation = fromString (aLocationStr); |
277 | |
278 | theShape.Location (aLocation); |
279 | theShape.Orientation (anOrientation); |
280 | } |