File: TInspectorAPI_PluginParameters.cxx

package info (click to toggle)
opencascade 7.9.2%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 301,932 kB
  • sloc: cpp: 1,523,264; tcl: 10,159; cs: 5,173; java: 1,554; sh: 1,342; ansic: 827; xml: 699; makefile: 31; javascript: 22
file content (295 lines) | stat: -rw-r--r-- 10,880 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
// Created on: 2017-06-16
// Created by: Natalia ERMOLAEVA
// Copyright (c) 2017 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.

#include <inspector/TInspectorAPI_PluginParameters.hxx>

IMPLEMENT_STANDARD_RTTIEXT(TInspectorAPI_PluginParameters, Standard_Transient)

// =======================================================================
// function : SetParameters
// purpose :
// =======================================================================
void TInspectorAPI_PluginParameters::SetParameters(
  const TCollection_AsciiString&                      thePluginName,
  const NCollection_List<Handle(Standard_Transient)>& theParameters,
  const Standard_Boolean&)
{
  if (theParameters.Size() > 0)
    myParameters.Bind(thePluginName, theParameters);
  else
    myParameters.UnBind(thePluginName);
}

// =======================================================================
// function : AddFileName
// purpose :
// =======================================================================
void TInspectorAPI_PluginParameters::AddFileName(const TCollection_AsciiString& thePluginName,
                                                 const TCollection_AsciiString& theFileName)
{
  if (myFileNames.IsBound(thePluginName))
    myFileNames.ChangeFind(thePluginName).Append(theFileName);
  else
  {
    NCollection_List<TCollection_AsciiString> aNames;
    aNames.Append(theFileName);
    myFileNames.Bind(thePluginName, aNames);
  }
}

// =======================================================================
// function : SetFileNames
// purpose :
// =======================================================================
void TInspectorAPI_PluginParameters::SetFileNames(
  const TCollection_AsciiString&                   thePluginName,
  const NCollection_List<TCollection_AsciiString>& theFileNames)
{
  if (theFileNames.Size() > 0)
    myFileNames.Bind(thePluginName, theFileNames);
  else
    myFileNames.UnBind(thePluginName);
}

// =======================================================================
// function : SetSelectedNames
// purpose :
// =======================================================================
void TInspectorAPI_PluginParameters::SetSelectedNames(
  const TCollection_AsciiString&                   thePluginName,
  const NCollection_List<TCollection_AsciiString>& theItemNames)
{
  mySelectedItemNames.Bind(thePluginName, theItemNames);
}

// =======================================================================
// function : SetSelected
// purpose :
// =======================================================================
void TInspectorAPI_PluginParameters::SetSelected(
  const TCollection_AsciiString&                      thePluginName,
  const NCollection_List<Handle(Standard_Transient)>& theObjects)
{
  if (theObjects.Size() > 0)
    mySelectedObjects.Bind(thePluginName, theObjects);
  else
    mySelectedObjects.UnBind(thePluginName);
}

// =======================================================================
// function : FindParameters
// purpose :
// =======================================================================
bool TInspectorAPI_PluginParameters::FindParameters(const TCollection_AsciiString& thePluginName)
{
  return myParameters.IsBound(thePluginName);
}

// =======================================================================
// function : Parameters
// purpose :
// =======================================================================
const NCollection_List<Handle(Standard_Transient)>& TInspectorAPI_PluginParameters::Parameters(
  const TCollection_AsciiString& thePluginName)
{
  return myParameters.Find(thePluginName);
}

// =======================================================================
// function : FindFileNames
// purpose :
// =======================================================================
bool TInspectorAPI_PluginParameters::FindFileNames(const TCollection_AsciiString& thePluginName)
{
  return myFileNames.IsBound(thePluginName);
}

// =======================================================================
// function : FileNames
// purpose :
// =======================================================================
const NCollection_List<TCollection_AsciiString>& TInspectorAPI_PluginParameters::FileNames(
  const TCollection_AsciiString& thePluginName)
{
  return myFileNames.Find(thePluginName);
}

// =======================================================================
// function : FindSelectedNames
// purpose :
// =======================================================================
bool TInspectorAPI_PluginParameters::FindSelectedNames(const TCollection_AsciiString& thePluginName)
{
  return mySelectedItemNames.IsBound(thePluginName);
}

// =======================================================================
// function : GetSelectedNames
// purpose :
// =======================================================================
const NCollection_List<TCollection_AsciiString>& TInspectorAPI_PluginParameters::GetSelectedNames(
  const TCollection_AsciiString& thePluginName)
{
  return mySelectedItemNames.Find(thePluginName);
}

// =======================================================================
// function : GetSelectedObjects
// purpose :
// =======================================================================
Standard_Boolean TInspectorAPI_PluginParameters::GetSelectedObjects(
  const TCollection_AsciiString&                thePluginName,
  NCollection_List<Handle(Standard_Transient)>& theObjects)
{
  return mySelectedObjects.Find(thePluginName, theObjects);
}

// =======================================================================
// function : toString
// purpose :
// =======================================================================
TCollection_AsciiString toString(const TopLoc_Location& theLocation)
{
  TCollection_AsciiString anInfo;
  gp_Trsf                 aTrsf = theLocation.Transformation();
  for (int aRowId = 1; aRowId <= 3; aRowId++)
  {
    if (!anInfo.IsEmpty())
      anInfo += " ";
    for (int aColumnId = 1; aColumnId <= 4; aColumnId++)
    {
      if (aColumnId > 1)
        anInfo += ",";
      anInfo += TCollection_AsciiString(aTrsf.Value(aRowId, aColumnId));
    }
  }
  return anInfo;
}

// =======================================================================
// function : ParametersToString
// purpose :
// =======================================================================
TCollection_AsciiString TInspectorAPI_PluginParameters::ParametersToString(
  const TopoDS_Shape& theShape)
{
  const TopLoc_Location&  aLocation    = theShape.Location();
  TCollection_AsciiString aLocationStr = toString(aLocation);

  TopAbs_Orientation anOrientation = theShape.Orientation();
  Standard_SStream   aSStream;
  TopAbs::Print(anOrientation, aSStream);
  return TCollection_AsciiString(aSStream.str().c_str()) + ":" + aLocationStr;
}

// =======================================================================
// function : fromString
// purpose :
// =======================================================================
TopLoc_Location fromString(const TCollection_AsciiString& theValue)
{
  NCollection_Mat4<Standard_Real> aValues;

  TCollection_AsciiString aCurrentString = theValue;
  Standard_Integer        aPosition      = aCurrentString.Search(" ");
  if (aPosition < 0)
    return TopLoc_Location();
  TCollection_AsciiString aTailString = aCurrentString.Split(aPosition);
  Standard_Integer        aRow        = 0;
  while (!aCurrentString.IsEmpty())
  {
    TCollection_AsciiString aValueString = aCurrentString;
    aPosition                            = aValueString.Search(",");
    if (aPosition < 0)
      break;
    aCurrentString           = aValueString.Split(aPosition);
    Standard_Integer aColumn = 0;
    while (!aValueString.IsEmpty())
    {
      aPosition = aCurrentString.Search(" ");
      if (aPosition > 0)
        aValueString.Split(aValueString.Length() - 1);

      aValues.SetValue(aRow, aColumn, aValueString.RealValue());
      aColumn++;
      if (aCurrentString.IsEmpty())
        break;
      aValueString = aCurrentString;
      aPosition    = aValueString.Search(",");
      if (aPosition < 0)
      {
        aValueString   = aCurrentString;
        aCurrentString = TCollection_AsciiString();
      }
      else
        aCurrentString = aValueString.Split(aPosition);
    }
    if (aTailString.IsEmpty())
      break;
    aCurrentString = aTailString;
    aPosition      = aCurrentString.Search(" ");
    if (aPosition < 0)
    {
      aCurrentString = aTailString;
      aTailString    = TCollection_AsciiString();
    }
    else
      aTailString = aCurrentString.Split(aPosition);
    aRow++;
  }

  // if (aValues.Rows() != 3 || aValues.Cols() != 4)
  //   return TopLoc_Location();

  gp_Trsf aTrsf;
  aTrsf.SetValues(aValues.GetValue(0, 0),
                  aValues.GetValue(0, 1),
                  aValues.GetValue(0, 2),
                  aValues.GetValue(0, 3),
                  aValues.GetValue(1, 0),
                  aValues.GetValue(1, 1),
                  aValues.GetValue(1, 2),
                  aValues.GetValue(1, 3),
                  aValues.GetValue(2, 0),
                  aValues.GetValue(2, 1),
                  aValues.GetValue(2, 2),
                  aValues.GetValue(2, 3));
  return TopLoc_Location(aTrsf);
}

// =======================================================================
// function : ParametersToShape
// purpose :
// =======================================================================
void TInspectorAPI_PluginParameters::ParametersToShape(const TCollection_AsciiString& theValue,
                                                       TopoDS_Shape&                  theShape)
{
  int                     aSeparatorPos    = theValue.Search(":");
  TCollection_AsciiString anOrientationStr = theValue;
  TCollection_AsciiString aLocationStr     = anOrientationStr.Split(aSeparatorPos);
  // orientation
  if (anOrientationStr.Length() < 2)
    return;
  anOrientationStr.Split(anOrientationStr.Length() - 1);

  TopAbs_Orientation anOrientation;
  if (!TopAbs::ShapeOrientationFromString(anOrientationStr.ToCString(), anOrientation))
    return;
  // location
  TopLoc_Location aLocation = fromString(aLocationStr);

  theShape.Location(aLocation);
  theShape.Orientation(anOrientation);
}