1 // Created on: 2017-06-16
2 // Created by: Natalia ERMOLAEVA
3 // Copyright (c) 2017 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <inspector/TInspectorAPI_PluginParameters.hxx>
18 IMPLEMENT_STANDARD_RTTIEXT (TInspectorAPI_PluginParameters, Standard_Transient)
20 // =======================================================================
21 // function : SetParameters
23 // =======================================================================
24 void TInspectorAPI_PluginParameters::SetParameters (const TCollection_AsciiString& thePluginName,
25 const NCollection_List<Handle(Standard_Transient)>& theParameters,
26 const Standard_Boolean&)
28 if (theParameters.Size() > 0)
29 myParameters.Bind (thePluginName, theParameters);
31 myParameters.UnBind (thePluginName);
34 // =======================================================================
35 // function : AddFileName
37 // =======================================================================
38 void TInspectorAPI_PluginParameters::AddFileName (const TCollection_AsciiString& thePluginName,
39 const TCollection_AsciiString& theFileName)
41 if (myFileNames.IsBound (thePluginName))
42 myFileNames.ChangeFind (thePluginName).Append (theFileName);
45 NCollection_List<TCollection_AsciiString> aNames;
46 aNames.Append (theFileName);
47 myFileNames.Bind (thePluginName, aNames);
51 // =======================================================================
52 // function : SetFileNames
54 // =======================================================================
55 void TInspectorAPI_PluginParameters::SetFileNames (const TCollection_AsciiString& thePluginName,
56 const NCollection_List<TCollection_AsciiString>& theFileNames)
58 if (theFileNames.Size() > 0)
59 myFileNames.Bind (thePluginName, theFileNames);
61 myFileNames.UnBind (thePluginName);
64 // =======================================================================
65 // function : SetSelectedNames
67 // =======================================================================
68 void TInspectorAPI_PluginParameters::SetSelectedNames (const TCollection_AsciiString& thePluginName,
69 const NCollection_List<TCollection_AsciiString>& theItemNames)
71 mySelectedItemNames.Bind (thePluginName, theItemNames);
74 // =======================================================================
75 // function : SetSelected
77 // =======================================================================
78 void TInspectorAPI_PluginParameters::SetSelected (const TCollection_AsciiString& thePluginName,
79 const NCollection_List<Handle(Standard_Transient)>& theObjects)
81 if (theObjects.Size() > 0)
82 mySelectedObjects.Bind (thePluginName, theObjects);
84 mySelectedObjects.UnBind (thePluginName);
87 // =======================================================================
88 // function : FindParameters
90 // =======================================================================
91 bool TInspectorAPI_PluginParameters::FindParameters (const TCollection_AsciiString& thePluginName)
93 return myParameters.IsBound (thePluginName);
96 // =======================================================================
97 // function : Parameters
99 // =======================================================================
100 const NCollection_List<Handle(Standard_Transient)>& TInspectorAPI_PluginParameters::Parameters
101 (const TCollection_AsciiString& thePluginName)
103 return myParameters.Find (thePluginName);
106 // =======================================================================
107 // function : FindFileNames
109 // =======================================================================
110 bool TInspectorAPI_PluginParameters::FindFileNames (const TCollection_AsciiString& thePluginName)
112 return myFileNames.IsBound (thePluginName);
115 // =======================================================================
116 // function : FileNames
118 // =======================================================================
119 const NCollection_List<TCollection_AsciiString>& TInspectorAPI_PluginParameters::FileNames
120 (const TCollection_AsciiString& thePluginName)
122 return myFileNames.Find (thePluginName);
125 // =======================================================================
126 // function : FindSelectedNames
128 // =======================================================================
129 bool TInspectorAPI_PluginParameters::FindSelectedNames (const TCollection_AsciiString& thePluginName)
131 return mySelectedItemNames.IsBound (thePluginName);
134 // =======================================================================
135 // function : GetSelectedNames
137 // =======================================================================
138 const NCollection_List<TCollection_AsciiString>& TInspectorAPI_PluginParameters::GetSelectedNames
139 (const TCollection_AsciiString& thePluginName)
141 return mySelectedItemNames.Find (thePluginName);
144 // =======================================================================
145 // function : GetSelectedObjects
147 // =======================================================================
148 Standard_Boolean TInspectorAPI_PluginParameters::GetSelectedObjects (const TCollection_AsciiString& thePluginName,
149 NCollection_List<Handle(Standard_Transient)>& theObjects)
151 return mySelectedObjects.Find (thePluginName, theObjects);
154 // =======================================================================
155 // function : toString
157 // =======================================================================
158 TCollection_AsciiString toString (const TopLoc_Location& theLocation)
160 TCollection_AsciiString anInfo;
161 gp_Trsf aTrsf = theLocation.Transformation();
162 for (int aRowId = 1; aRowId <= 3; aRowId++)
164 if (!anInfo.IsEmpty())
166 for (int aColumnId = 1; aColumnId <= 4; aColumnId++)
170 anInfo += TCollection_AsciiString (aTrsf.Value (aRowId, aColumnId));
176 // =======================================================================
177 // function : ParametersToString
179 // =======================================================================
180 TCollection_AsciiString TInspectorAPI_PluginParameters::ParametersToString (const TopoDS_Shape& theShape)
182 const TopLoc_Location& aLocation = theShape.Location();
183 TCollection_AsciiString aLocationStr = toString (aLocation);
185 TopAbs_Orientation anOrientation = theShape.Orientation();
186 Standard_SStream aSStream;
187 TopAbs::Print (anOrientation, aSStream);
188 return TCollection_AsciiString (aSStream.str().c_str()) + ":" + aLocationStr;
191 // =======================================================================
192 // function : fromString
194 // =======================================================================
195 TopLoc_Location fromString (const TCollection_AsciiString& theValue)
197 NCollection_Mat4<Standard_Real> aValues;
199 TCollection_AsciiString aCurrentString = theValue;
200 Standard_Integer aPosition = aCurrentString.Search (" ");
202 return TopLoc_Location();
203 TCollection_AsciiString aTailString = aCurrentString.Split (aPosition);
204 Standard_Integer aRow = 0;
205 while (!aCurrentString.IsEmpty())
207 TCollection_AsciiString aValueString = aCurrentString;
208 aPosition = aValueString.Search (",");
211 aCurrentString = aValueString.Split (aPosition);
212 Standard_Integer aColumn = 0;
213 while (!aValueString.IsEmpty())
215 aPosition = aCurrentString.Search (" ");
217 aValueString.Split (aValueString.Length() - 1);
219 aValues.SetValue (aRow, aColumn, aValueString.RealValue());
221 if (aCurrentString.IsEmpty())
223 aValueString = aCurrentString;
224 aPosition = aValueString.Search (",");
227 aValueString = aCurrentString;
228 aCurrentString = TCollection_AsciiString();
231 aCurrentString = aValueString.Split (aPosition);
233 if (aTailString.IsEmpty())
235 aCurrentString = aTailString;
236 aPosition = aCurrentString.Search (" ");
239 aCurrentString = aTailString;
240 aTailString = TCollection_AsciiString();
243 aTailString = aCurrentString.Split (aPosition);
247 //if (aValues.Rows() != 3 || aValues.Cols() != 4)
248 // return TopLoc_Location();
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);
257 // =======================================================================
258 // function : ParametersToShape
260 // =======================================================================
261 void TInspectorAPI_PluginParameters::ParametersToShape (const TCollection_AsciiString& theValue,
262 TopoDS_Shape& theShape)
264 int aSeparatorPos = theValue.Search (":");
265 TCollection_AsciiString anOrientationStr = theValue;
266 TCollection_AsciiString aLocationStr = anOrientationStr.Split (aSeparatorPos);
268 if (anOrientationStr.Length() < 2)
270 anOrientationStr.Split (anOrientationStr.Length() - 1);
272 TopAbs_Orientation anOrientation;
273 if (!TopAbs::ShapeOrientationFromString (anOrientationStr.ToCString(), anOrientation))
276 TopLoc_Location aLocation = fromString (aLocationStr);
278 theShape.Location (aLocation);
279 theShape.Orientation (anOrientation);