0029807: [Regression to 7.0.0] Impossible to cut cone from prism
[occt.git] / tools / TInspectorAPI / TInspectorAPI_PluginParameters.cxx
CommitLineData
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>
ae5225df 17#include <inspector/TInspectorAPI_Version.hxx>
14bbbdcb 18
19#if OCC_VERSION_HEX <= 0x060901
20IMPLEMENT_STANDARD_HANDLE (TInspectorAPI_PluginParameters, Standard_Transient)
21IMPLEMENT_STANDARD_RTTIEXT (TInspectorAPI_PluginParameters, Standard_Transient)
22#else
23IMPLEMENT_STANDARD_RTTIEXT (TInspectorAPI_PluginParameters, Standard_Transient)
24#endif
25
14bbbdcb 26// =======================================================================
0cb512c0 27// function : SetParameters
14bbbdcb 28// purpose :
29// =======================================================================
30void TInspectorAPI_PluginParameters::SetParameters (const TCollection_AsciiString& thePluginName,
0cb512c0 31 const NCollection_List<Handle(Standard_Transient)>& theParameters,
32 const Standard_Boolean&)
14bbbdcb 33{
34 if (theParameters.Size() > 0)
35 myParameters.Bind (thePluginName, theParameters);
36 else
37 myParameters.UnBind (thePluginName);
38}
39
40// =======================================================================
0cb512c0 41// function : AddFileName
14bbbdcb 42// purpose :
43// =======================================================================
44void TInspectorAPI_PluginParameters::AddFileName (const TCollection_AsciiString& thePluginName,
45 const TCollection_AsciiString& theFileName)
46{
6822a3be 47 if (myFileNames.IsBound (thePluginName))
48 myFileNames.ChangeFind (thePluginName).Append (theFileName);
14bbbdcb 49 else
50 {
51 NCollection_List<TCollection_AsciiString> aNames;
52 aNames.Append (theFileName);
53 myFileNames.Bind (thePluginName, aNames);
54 }
55}
56
57// =======================================================================
0cb512c0 58// function : SetFileNames
14bbbdcb 59// purpose :
60// =======================================================================
61void TInspectorAPI_PluginParameters::SetFileNames (const TCollection_AsciiString& thePluginName,
62 const NCollection_List<TCollection_AsciiString>& theFileNames)
63{
64 if (theFileNames.Size() > 0)
65 myFileNames.Bind (thePluginName, theFileNames);
66 else
0cb512c0 67 myFileNames.UnBind (thePluginName);
68}
69
70// =======================================================================
71// function : SetSelectedNames
72// purpose :
73// =======================================================================
74void TInspectorAPI_PluginParameters::SetSelectedNames (const TCollection_AsciiString& thePluginName,
75 const NCollection_List<TCollection_AsciiString>& theItemNames)
76{
77 mySelectedItemNames.Bind (thePluginName, theItemNames);
78}
14bbbdcb 79
0cb512c0 80// =======================================================================
81// function : SetSelected
82// purpose :
83// =======================================================================
84void TInspectorAPI_PluginParameters::SetSelected (const TCollection_AsciiString& thePluginName,
85 const NCollection_List<Handle(Standard_Transient)>& theObjects)
86{
87 if (theObjects.Size() > 0)
88 mySelectedObjects.Bind (thePluginName, theObjects);
89 else
90 mySelectedObjects.UnBind (thePluginName);
14bbbdcb 91}
92
93// =======================================================================
0cb512c0 94// function : FindParameters
14bbbdcb 95// purpose :
96// =======================================================================
97bool TInspectorAPI_PluginParameters::FindParameters (const TCollection_AsciiString& thePluginName)
98{
6822a3be 99 return myParameters.IsBound (thePluginName);
14bbbdcb 100}
101
102// =======================================================================
0cb512c0 103// function : Parameters
14bbbdcb 104// purpose :
105// =======================================================================
106const NCollection_List<Handle(Standard_Transient)>& TInspectorAPI_PluginParameters::Parameters
107 (const TCollection_AsciiString& thePluginName)
108{
109 return myParameters.Find (thePluginName);
110}
111
112// =======================================================================
0cb512c0 113// function : FindFileNames
14bbbdcb 114// purpose :
115// =======================================================================
116bool TInspectorAPI_PluginParameters::FindFileNames (const TCollection_AsciiString& thePluginName)
117{
6822a3be 118 return myFileNames.IsBound (thePluginName);
14bbbdcb 119}
120
121// =======================================================================
0cb512c0 122// function : FileNames
14bbbdcb 123// purpose :
124// =======================================================================
125const NCollection_List<TCollection_AsciiString>& TInspectorAPI_PluginParameters::FileNames
126 (const TCollection_AsciiString& thePluginName)
127{
128 return myFileNames.Find (thePluginName);
129}
0cb512c0 130
131// =======================================================================
132// function : FindSelectedNames
133// purpose :
134// =======================================================================
135bool TInspectorAPI_PluginParameters::FindSelectedNames (const TCollection_AsciiString& thePluginName)
136{
6822a3be 137 return mySelectedItemNames.IsBound (thePluginName);
0cb512c0 138}
139
140// =======================================================================
141// function : GetSelectedNames
142// purpose :
143// =======================================================================
144const NCollection_List<TCollection_AsciiString>& TInspectorAPI_PluginParameters::GetSelectedNames
145 (const TCollection_AsciiString& thePluginName)
146{
147 return mySelectedItemNames.Find (thePluginName);
148}
149
150// =======================================================================
151// function : GetSelectedObjects
152// purpose :
153// =======================================================================
154Standard_Boolean TInspectorAPI_PluginParameters::GetSelectedObjects (const TCollection_AsciiString& thePluginName,
155 NCollection_List<Handle(Standard_Transient)>& theObjects)
156{
157 return mySelectedObjects.Find (thePluginName, theObjects);
158}
6822a3be 159
160// =======================================================================
161// function : toString
162// purpose :
163// =======================================================================
164TCollection_AsciiString toString (const TopLoc_Location& theLocation)
165{
166 TCollection_AsciiString anInfo;
167 gp_Trsf aTrsf = theLocation.Transformation();
168 for (int aRowId = 1; aRowId <= 3; aRowId++)
169 {
170 if (!anInfo.IsEmpty())
171 anInfo += " ";
172 for (int aColumnId = 1; aColumnId <= 4; aColumnId++)
173 {
174 if (aColumnId > 1)
175 anInfo += ",";
176 anInfo += TCollection_AsciiString (aTrsf.Value (aRowId, aColumnId));
177 }
178 }
179 return anInfo;
180}
181
182// =======================================================================
183// function : ParametersToString
184// purpose :
185// =======================================================================
186TCollection_AsciiString TInspectorAPI_PluginParameters::ParametersToString (const TopoDS_Shape& theShape)
187{
188 const TopLoc_Location& aLocation = theShape.Location();
189 TCollection_AsciiString aLocationStr = toString (aLocation);
190
191 TopAbs_Orientation anOrientation = theShape.Orientation();
192 Standard_SStream aSStream;
193 TopAbs::Print (anOrientation, aSStream);
194 return TCollection_AsciiString (aSStream.str().c_str()) + ":" + aLocationStr;
195}
196
197// =======================================================================
198// function : fromString
199// purpose :
200// =======================================================================
201TopLoc_Location fromString (const TCollection_AsciiString& theValue)
202{
203 NCollection_Mat4<Standard_Real> aValues;
204
205 TCollection_AsciiString aCurrentString = theValue;
206 Standard_Integer aPosition = aCurrentString.Search (" ");
207 if (aPosition < 0)
208 return TopLoc_Location();
209 TCollection_AsciiString aTailString = aCurrentString.Split (aPosition);
210 Standard_Integer aRow = 0;
211 while (!aCurrentString.IsEmpty())
212 {
213 TCollection_AsciiString aValueString = aCurrentString;
214 aPosition = aValueString.Search (",");
215 if (aPosition < 0 )
216 break;
217 aCurrentString = aValueString.Split (aPosition);
218 Standard_Integer aColumn = 0;
219 while (!aValueString.IsEmpty())
220 {
221 aPosition = aCurrentString.Search (" ");
222 if (aPosition > 0)
223 aValueString.Split (aValueString.Length() - 1);
224
225 aValues.SetValue (aRow, aColumn, aValueString.RealValue());
226 aColumn++;
227 if (aCurrentString.IsEmpty())
228 break;
229 aValueString = aCurrentString;
230 aPosition = aValueString.Search (",");
231 if (aPosition < 0 )
232 {
233 aValueString = aCurrentString;
234 aCurrentString = TCollection_AsciiString();
235 }
236 else
237 aCurrentString = aValueString.Split (aPosition);
238 }
239 if (aTailString.IsEmpty())
240 break;
241 aCurrentString = aTailString;
242 aPosition = aCurrentString.Search (" ");
243 if (aPosition < 0 )
244 {
245 aCurrentString = aTailString;
246 aTailString = TCollection_AsciiString();
247 }
248 else
249 aTailString = aCurrentString.Split (aPosition);
250 aRow++;
251 }
252
253 //if (aValues.Rows() != 3 || aValues.Cols() != 4)
254 // return TopLoc_Location();
255
256 gp_Trsf aTrsf;
257 aTrsf.SetValues (aValues.GetValue (0, 0), aValues.GetValue (0, 1), aValues.GetValue (0, 2), aValues.GetValue (0, 3),
258 aValues.GetValue (1, 0), aValues.GetValue (1, 1), aValues.GetValue (1, 2), aValues.GetValue (1, 3),
259 aValues.GetValue (2, 0), aValues.GetValue (2, 1), aValues.GetValue (2, 2), aValues.GetValue (2, 3));
260 return TopLoc_Location (aTrsf);
261}
262
263// =======================================================================
264// function : ParametersToShape
265// purpose :
266// =======================================================================
267void TInspectorAPI_PluginParameters::ParametersToShape (const TCollection_AsciiString& theValue,
268 TopoDS_Shape& theShape)
269{
270 int aSeparatorPos = theValue.Search (":");
271 TCollection_AsciiString anOrientationStr = theValue;
272 TCollection_AsciiString aLocationStr = anOrientationStr.Split (aSeparatorPos);
273 // orientation
274 if (anOrientationStr.Length() < 2)
275 return;
276 anOrientationStr.Split (anOrientationStr.Length() - 1);
277
ae5225df 278#if TINSPECTORAPI_VERSION_HEX > 0x070200
6822a3be 279 TopAbs_Orientation anOrientation;
280 if (!TopAbs::ShapeOrientationFromString (anOrientationStr.ToCString(), anOrientation))
281 return;
282 // location
283 TopLoc_Location aLocation = fromString (aLocationStr);
284
285 theShape.Location (aLocation);
286 theShape.Orientation (anOrientation);
ae5225df 287#else
288 (void)theValue; (void)theShape;
289#endif
6822a3be 290}