FreeCAD

Форк
0
/
SoFCSelectionAction.cpp 
1322 строки · 46.2 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2005 Jürgen Riegel <juergen.riegel@web.de>              *
3
 *                                                                         *
4
 *   This file is part of the FreeCAD CAx development system.              *
5
 *                                                                         *
6
 *   This library is free software; you can redistribute it and/or         *
7
 *   modify it under the terms of the GNU Library General Public           *
8
 *   License as published by the Free Software Foundation; either          *
9
 *   version 2 of the License, or (at your option) any later version.      *
10
 *                                                                         *
11
 *   This library  is distributed in the hope that it will be useful,      *
12
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
13
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
14
 *   GNU Library General Public License for more details.                  *
15
 *                                                                         *
16
 *   You should have received a copy of the GNU Library General Public     *
17
 *   License along with this library; see the file COPYING.LIB. If not,    *
18
 *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
19
 *   Suite 330, Boston, MA  02111-1307, USA                                *
20
 *                                                                         *
21
 ***************************************************************************/
22

23
#include "PreCompiled.h"
24

25
#ifndef _PreComp_
26
# include <Inventor/actions/SoSearchAction.h>
27
# include <Inventor/actions/SoGetBoundingBoxAction.h>
28
# include <Inventor/elements/SoComplexityElement.h>
29
# include <Inventor/elements/SoComplexityTypeElement.h>
30
# include <Inventor/elements/SoCoordinateElement.h>
31
# include <Inventor/elements/SoFontNameElement.h>
32
# include <Inventor/elements/SoFontSizeElement.h>
33
# include <Inventor/elements/SoModelMatrixElement.h>
34
# include <Inventor/elements/SoProfileCoordinateElement.h>
35
# include <Inventor/elements/SoProfileElement.h>
36
# include <Inventor/elements/SoProjectionMatrixElement.h>
37
# include <Inventor/elements/SoShapeStyleElement.h>
38
# include <Inventor/elements/SoSwitchElement.h>
39
# include <Inventor/elements/SoUnitsElement.h>
40
# include <Inventor/elements/SoViewingMatrixElement.h>
41
# include <Inventor/elements/SoViewportRegionElement.h>
42
# include <Inventor/elements/SoViewVolumeElement.h>
43
# include <Inventor/nodes/SoBaseColor.h>
44
# include <Inventor/nodes/SoCallback.h>
45
# include <Inventor/nodes/SoCamera.h>
46
# include <Inventor/nodes/SoComplexity.h>
47
# include <Inventor/nodes/SoCoordinate3.h>
48
# include <Inventor/nodes/SoCoordinate4.h>
49
# include <Inventor/nodes/SoCube.h>
50
# include <Inventor/nodes/SoDrawStyle.h>
51
# include <Inventor/nodes/SoFont.h>
52
# include <Inventor/nodes/SoIndexedLineSet.h>
53
# include <Inventor/nodes/SoIndexedFaceSet.h>
54
# include <Inventor/nodes/SoLightModel.h>
55
# include <Inventor/nodes/SoMatrixTransform.h>
56
# include <Inventor/nodes/SoPointSet.h>
57
# include <Inventor/nodes/SoProfile.h>
58
# include <Inventor/nodes/SoProfileCoordinate2.h>
59
# include <Inventor/nodes/SoProfileCoordinate3.h>
60
# include <Inventor/nodes/SoSeparator.h>
61
# include <Inventor/nodes/SoSwitch.h>
62
# include <Inventor/nodes/SoTransformation.h>
63
#endif
64

65
#include "SoFCSelectionAction.h"
66
#include "SoFCSelection.h"
67

68

69
using namespace Gui;
70

71

72
SO_ACTION_SOURCE(SoFCHighlightAction)
73

74
/**
75
 * The order of the defined SO_ACTION_ADD_METHOD statements is very important. First the base
76
 * classes and afterwards subclasses of them must be listed, otherwise the registered methods
77
 * of subclasses will be overridden. For more details see the thread in the Coin3d forum
78
 * https://www.coin3d.org/pipermail/coin-discuss/2004-May/004346.html.
79
 * This means that \c SoSwitch must be listed after \c SoGroup and \c SoFCSelection after
80
 * \c SoSeparator because both classes inherits the others.
81
 */
82
void SoFCHighlightAction::initClass()
83
{
84
  SO_ACTION_INIT_CLASS(SoFCHighlightAction,SoAction);
85

86
  SO_ENABLE(SoFCHighlightAction, SoSwitchElement);
87

88
  SO_ACTION_ADD_METHOD(SoNode,nullAction);
89

90
  SO_ENABLE(SoFCHighlightAction, SoModelMatrixElement);
91
  SO_ENABLE(SoFCHighlightAction, SoShapeStyleElement);
92
  SO_ENABLE(SoFCHighlightAction, SoComplexityElement);
93
  SO_ENABLE(SoFCHighlightAction, SoComplexityTypeElement);
94
  SO_ENABLE(SoFCHighlightAction, SoCoordinateElement);
95
  SO_ENABLE(SoFCHighlightAction, SoFontNameElement);
96
  SO_ENABLE(SoFCHighlightAction, SoFontSizeElement);
97
  SO_ENABLE(SoFCHighlightAction, SoProfileCoordinateElement);
98
  SO_ENABLE(SoFCHighlightAction, SoProfileElement);
99
  SO_ENABLE(SoFCHighlightAction, SoSwitchElement);
100
  SO_ENABLE(SoFCHighlightAction, SoUnitsElement);
101
  SO_ENABLE(SoFCHighlightAction, SoViewVolumeElement);
102
  SO_ENABLE(SoFCHighlightAction, SoViewingMatrixElement);
103
  SO_ENABLE(SoFCHighlightAction, SoViewportRegionElement);
104

105

106

107

108
  SO_ACTION_ADD_METHOD(SoCallback,callDoAction);
109
  SO_ACTION_ADD_METHOD(SoComplexity,callDoAction);
110
  SO_ACTION_ADD_METHOD(SoCoordinate3,callDoAction);
111
  SO_ACTION_ADD_METHOD(SoCoordinate4,callDoAction);
112
  SO_ACTION_ADD_METHOD(SoFont,callDoAction);
113
  SO_ACTION_ADD_METHOD(SoGroup,callDoAction);
114
  SO_ACTION_ADD_METHOD(SoProfile,callDoAction);
115
  SO_ACTION_ADD_METHOD(SoProfileCoordinate2,callDoAction);
116
  SO_ACTION_ADD_METHOD(SoProfileCoordinate3,callDoAction);
117
  SO_ACTION_ADD_METHOD(SoTransformation,callDoAction);
118
  SO_ACTION_ADD_METHOD(SoSwitch,callDoAction);
119

120
  SO_ACTION_ADD_METHOD(SoSeparator,callDoAction);
121
  SO_ACTION_ADD_METHOD(SoFCSelection,callDoAction);
122

123
  SO_ACTION_ADD_METHOD(SoIndexedLineSet,callDoAction);
124
  SO_ACTION_ADD_METHOD(SoIndexedFaceSet,callDoAction);
125
  SO_ACTION_ADD_METHOD(SoPointSet,callDoAction);
126
}
127

128
void SoFCHighlightAction::finish()
129
{
130
  atexit_cleanup();
131
}
132

133

134
SoFCHighlightAction::SoFCHighlightAction (const SelectionChanges &SelCh)
135
:SelChange(SelCh)
136
{
137
  SO_ACTION_CONSTRUCTOR(SoFCHighlightAction);
138
}
139

140

141
SoFCHighlightAction::~SoFCHighlightAction() = default;
142

143

144
void SoFCHighlightAction::beginTraversal(SoNode *node)
145
{
146
  traverse(node);
147
}
148

149
void SoFCHighlightAction::callDoAction(SoAction *action,SoNode *node)
150
{
151
  node->doAction(action);
152
}
153

154
// ---------------------------------------------------------------
155

156
SO_ACTION_SOURCE(SoFCSelectionAction)
157

158
/**
159
 * The order of the defined SO_ACTION_ADD_METHOD statements is very important. First the base
160
 * classes and afterwards subclasses of them must be listed, otherwise the registered methods
161
 * of subclasses will be overridden. For more details see the thread in the Coin3d forum
162
 * https://www.coin3d.org/pipermail/coin-discuss/2004-May/004346.html.
163
 * This means that \c SoSwitch must be listed after \c SoGroup and \c SoFCSelection after
164
 * \c SoSeparator because both classes inherits the others.
165
 */
166
void SoFCSelectionAction::initClass()
167
{
168
  SO_ACTION_INIT_CLASS(SoFCSelectionAction,SoAction);
169

170
  SO_ENABLE(SoFCSelectionAction, SoSwitchElement);
171

172
  SO_ACTION_ADD_METHOD(SoNode,nullAction);
173

174
  SO_ENABLE(SoFCSelectionAction, SoModelMatrixElement);
175
  SO_ENABLE(SoFCSelectionAction, SoShapeStyleElement);
176
  SO_ENABLE(SoFCSelectionAction, SoComplexityElement);
177
  SO_ENABLE(SoFCSelectionAction, SoComplexityTypeElement);
178
  SO_ENABLE(SoFCSelectionAction, SoCoordinateElement);
179
  SO_ENABLE(SoFCSelectionAction, SoFontNameElement);
180
  SO_ENABLE(SoFCSelectionAction, SoFontSizeElement);
181
  SO_ENABLE(SoFCSelectionAction, SoProfileCoordinateElement);
182
  SO_ENABLE(SoFCSelectionAction, SoProfileElement);
183
  SO_ENABLE(SoFCSelectionAction, SoSwitchElement);
184
  SO_ENABLE(SoFCSelectionAction, SoUnitsElement);
185
  SO_ENABLE(SoFCSelectionAction, SoViewVolumeElement);
186
  SO_ENABLE(SoFCSelectionAction, SoViewingMatrixElement);
187
  SO_ENABLE(SoFCSelectionAction, SoViewportRegionElement);
188

189

190

191

192
  SO_ACTION_ADD_METHOD(SoCallback,callDoAction);
193
  SO_ACTION_ADD_METHOD(SoComplexity,callDoAction);
194
  SO_ACTION_ADD_METHOD(SoCoordinate3,callDoAction);
195
  SO_ACTION_ADD_METHOD(SoCoordinate4,callDoAction);
196
  SO_ACTION_ADD_METHOD(SoFont,callDoAction);
197
  SO_ACTION_ADD_METHOD(SoGroup,callDoAction);
198
  SO_ACTION_ADD_METHOD(SoProfile,callDoAction);
199
  SO_ACTION_ADD_METHOD(SoProfileCoordinate2,callDoAction);
200
  SO_ACTION_ADD_METHOD(SoProfileCoordinate3,callDoAction);
201
  SO_ACTION_ADD_METHOD(SoTransformation,callDoAction);
202
  SO_ACTION_ADD_METHOD(SoSwitch,callDoAction);
203

204
  SO_ACTION_ADD_METHOD(SoSeparator,callDoAction);
205
  SO_ACTION_ADD_METHOD(SoFCSelection,callDoAction);
206

207
  SO_ACTION_ADD_METHOD(SoIndexedLineSet,callDoAction);
208
  SO_ACTION_ADD_METHOD(SoIndexedFaceSet,callDoAction);
209
  SO_ACTION_ADD_METHOD(SoPointSet,callDoAction);
210
}
211

212
void SoFCSelectionAction::finish()
213
{
214
  atexit_cleanup();
215
}
216

217

218
SoFCSelectionAction::SoFCSelectionAction (const SelectionChanges &SelCh)
219
:SelChange(SelCh)
220
{
221
  SO_ACTION_CONSTRUCTOR(SoFCSelectionAction);
222
}
223

224

225
SoFCSelectionAction::~SoFCSelectionAction() = default;
226

227

228
void SoFCSelectionAction::beginTraversal(SoNode *node)
229
{
230
  traverse(node);
231
}
232

233
void SoFCSelectionAction::callDoAction(SoAction *action,SoNode *node)
234
{
235
  node->doAction(action);
236
}
237

238
// ---------------------------------------------------------------
239

240
SO_ACTION_SOURCE(SoFCEnableSelectionAction)
241

242
/**
243
 * The order of the defined SO_ACTION_ADD_METHOD statements is very important. First the base
244
 * classes and afterwards subclasses of them must be listed, otherwise the registered methods
245
 * of subclasses will be overridden. For more details see the thread in the Coin3d forum
246
 * https://www.coin3d.org/pipermail/coin-discuss/2004-May/004346.html.
247
 * This means that \c SoSwitch must be listed after \c SoGroup and \c SoFCSelection after
248
 * \c SoSeparator because both classes inherits the others.
249
 */
250
void SoFCEnableSelectionAction::initClass()
251
{
252
  SO_ACTION_INIT_CLASS(SoFCEnableSelectionAction,SoAction);
253

254
  SO_ENABLE(SoFCEnableSelectionAction, SoSwitchElement);
255

256
  SO_ACTION_ADD_METHOD(SoNode,nullAction);
257

258
  SO_ENABLE(SoFCEnableSelectionAction, SoModelMatrixElement);
259
  SO_ENABLE(SoFCEnableSelectionAction, SoShapeStyleElement);
260
  SO_ENABLE(SoFCEnableSelectionAction, SoComplexityElement);
261
  SO_ENABLE(SoFCEnableSelectionAction, SoComplexityTypeElement);
262
  SO_ENABLE(SoFCEnableSelectionAction, SoCoordinateElement);
263
  SO_ENABLE(SoFCEnableSelectionAction, SoFontNameElement);
264
  SO_ENABLE(SoFCEnableSelectionAction, SoFontSizeElement);
265
  SO_ENABLE(SoFCEnableSelectionAction, SoProfileCoordinateElement);
266
  SO_ENABLE(SoFCEnableSelectionAction, SoProfileElement);
267
  SO_ENABLE(SoFCEnableSelectionAction, SoSwitchElement);
268
  SO_ENABLE(SoFCEnableSelectionAction, SoUnitsElement);
269
  SO_ENABLE(SoFCEnableSelectionAction, SoViewVolumeElement);
270
  SO_ENABLE(SoFCEnableSelectionAction, SoViewingMatrixElement);
271
  SO_ENABLE(SoFCEnableSelectionAction, SoViewportRegionElement);
272

273

274

275

276
  SO_ACTION_ADD_METHOD(SoCallback,callDoAction);
277
  SO_ACTION_ADD_METHOD(SoComplexity,callDoAction);
278
  SO_ACTION_ADD_METHOD(SoCoordinate3,callDoAction);
279
  SO_ACTION_ADD_METHOD(SoCoordinate4,callDoAction);
280
  SO_ACTION_ADD_METHOD(SoFont,callDoAction);
281
  SO_ACTION_ADD_METHOD(SoGroup,callDoAction);
282
  SO_ACTION_ADD_METHOD(SoProfile,callDoAction);
283
  SO_ACTION_ADD_METHOD(SoProfileCoordinate2,callDoAction);
284
  SO_ACTION_ADD_METHOD(SoProfileCoordinate3,callDoAction);
285
  SO_ACTION_ADD_METHOD(SoTransformation,callDoAction);
286
  SO_ACTION_ADD_METHOD(SoSwitch,callDoAction);
287

288
  SO_ACTION_ADD_METHOD(SoSeparator,callDoAction);
289
  SO_ACTION_ADD_METHOD(SoFCSelection,callDoAction);
290
}
291

292
void SoFCEnableSelectionAction::finish()
293
{
294
  atexit_cleanup();
295
}
296

297

298
SoFCEnableSelectionAction::SoFCEnableSelectionAction (const SbBool& sel)
299
  : selection(sel)
300
{
301
  SO_ACTION_CONSTRUCTOR(SoFCEnableSelectionAction);
302
}
303

304

305
SoFCEnableSelectionAction::~SoFCEnableSelectionAction() = default;
306

307

308
void SoFCEnableSelectionAction::beginTraversal(SoNode *node)
309
{
310
  traverse(node);
311
}
312

313
void SoFCEnableSelectionAction::callDoAction(SoAction *action,SoNode *node)
314
{
315
  node->doAction(action);
316
}
317

318
// ---------------------------------------------------------------
319

320
SO_ACTION_SOURCE(SoFCEnableHighlightAction)
321

322
/**
323
 * The order of the defined SO_ACTION_ADD_METHOD statements is very important. First the base
324
 * classes and afterwards subclasses of them must be listed, otherwise the registered methods
325
 * of subclasses will be overridden. For more details see the thread in the Coin3d forum
326
 * https://www.coin3d.org/pipermail/coin-discuss/2004-May/004346.html.
327
 * This means that \c SoSwitch must be listed after \c SoGroup and \c SoFCSelection after
328
 * \c SoSeparator because both classes inherits the others.
329
 */
330
void SoFCEnableHighlightAction::initClass()
331
{
332
  SO_ACTION_INIT_CLASS(SoFCEnableHighlightAction,SoAction);
333

334
  SO_ENABLE(SoFCEnableHighlightAction, SoSwitchElement);
335

336
  SO_ACTION_ADD_METHOD(SoNode,nullAction);
337

338
  SO_ENABLE(SoFCEnableHighlightAction, SoModelMatrixElement);
339
  SO_ENABLE(SoFCEnableHighlightAction, SoShapeStyleElement);
340
  SO_ENABLE(SoFCEnableHighlightAction, SoComplexityElement);
341
  SO_ENABLE(SoFCEnableHighlightAction, SoComplexityTypeElement);
342
  SO_ENABLE(SoFCEnableHighlightAction, SoCoordinateElement);
343
  SO_ENABLE(SoFCEnableHighlightAction, SoFontNameElement);
344
  SO_ENABLE(SoFCEnableHighlightAction, SoFontSizeElement);
345
  SO_ENABLE(SoFCEnableHighlightAction, SoProfileCoordinateElement);
346
  SO_ENABLE(SoFCEnableHighlightAction, SoProfileElement);
347
  SO_ENABLE(SoFCEnableHighlightAction, SoSwitchElement);
348
  SO_ENABLE(SoFCEnableHighlightAction, SoUnitsElement);
349
  SO_ENABLE(SoFCEnableHighlightAction, SoViewVolumeElement);
350
  SO_ENABLE(SoFCEnableHighlightAction, SoViewingMatrixElement);
351
  SO_ENABLE(SoFCEnableHighlightAction, SoViewportRegionElement);
352

353

354

355

356
  SO_ACTION_ADD_METHOD(SoCallback,callDoAction);
357
  SO_ACTION_ADD_METHOD(SoComplexity,callDoAction);
358
  SO_ACTION_ADD_METHOD(SoCoordinate3,callDoAction);
359
  SO_ACTION_ADD_METHOD(SoCoordinate4,callDoAction);
360
  SO_ACTION_ADD_METHOD(SoFont,callDoAction);
361
  SO_ACTION_ADD_METHOD(SoGroup,callDoAction);
362
  SO_ACTION_ADD_METHOD(SoProfile,callDoAction);
363
  SO_ACTION_ADD_METHOD(SoProfileCoordinate2,callDoAction);
364
  SO_ACTION_ADD_METHOD(SoProfileCoordinate3,callDoAction);
365
  SO_ACTION_ADD_METHOD(SoTransformation,callDoAction);
366
  SO_ACTION_ADD_METHOD(SoSwitch,callDoAction);
367

368
  SO_ACTION_ADD_METHOD(SoSeparator,callDoAction);
369
  SO_ACTION_ADD_METHOD(SoFCSelection,callDoAction);
370
}
371

372
void SoFCEnableHighlightAction::finish()
373
{
374
  atexit_cleanup();
375
}
376

377

378
SoFCEnableHighlightAction::SoFCEnableHighlightAction (const SbBool& sel)
379
  : highlight(sel)
380
{
381
  SO_ACTION_CONSTRUCTOR(SoFCEnableHighlightAction);
382
}
383

384

385
SoFCEnableHighlightAction::~SoFCEnableHighlightAction() = default;
386

387

388
void SoFCEnableHighlightAction::beginTraversal(SoNode *node)
389
{
390
  traverse(node);
391
}
392

393
void SoFCEnableHighlightAction::callDoAction(SoAction *action,SoNode *node)
394
{
395
  node->doAction(action);
396
}
397

398
// ---------------------------------------------------------------
399

400
SO_ACTION_SOURCE(SoFCSelectionColorAction)
401

402
/**
403
 * The order of the defined SO_ACTION_ADD_METHOD statements is very important. First the base
404
 * classes and afterwards subclasses of them must be listed, otherwise the registered methods
405
 * of subclasses will be overridden. For more details see the thread in the Coin3d forum
406
 * https://www.coin3d.org/pipermail/coin-discuss/2004-May/004346.html.
407
 * This means that \c SoSwitch must be listed after \c SoGroup and \c SoFCSelection after
408
 * \c SoSeparator because both classes inherits the others.
409
 */
410
void SoFCSelectionColorAction::initClass()
411
{
412
  SO_ACTION_INIT_CLASS(SoFCSelectionColorAction,SoAction);
413

414
  SO_ENABLE(SoFCSelectionColorAction, SoSwitchElement);
415

416
  SO_ACTION_ADD_METHOD(SoNode,nullAction);
417

418
  SO_ENABLE(SoFCSelectionColorAction, SoModelMatrixElement);
419
  SO_ENABLE(SoFCSelectionColorAction, SoShapeStyleElement);
420
  SO_ENABLE(SoFCSelectionColorAction, SoComplexityElement);
421
  SO_ENABLE(SoFCSelectionColorAction, SoComplexityTypeElement);
422
  SO_ENABLE(SoFCSelectionColorAction, SoCoordinateElement);
423
  SO_ENABLE(SoFCSelectionColorAction, SoFontNameElement);
424
  SO_ENABLE(SoFCSelectionColorAction, SoFontSizeElement);
425
  SO_ENABLE(SoFCSelectionColorAction, SoProfileCoordinateElement);
426
  SO_ENABLE(SoFCSelectionColorAction, SoProfileElement);
427
  SO_ENABLE(SoFCSelectionColorAction, SoSwitchElement);
428
  SO_ENABLE(SoFCSelectionColorAction, SoUnitsElement);
429
  SO_ENABLE(SoFCSelectionColorAction, SoViewVolumeElement);
430
  SO_ENABLE(SoFCSelectionColorAction, SoViewingMatrixElement);
431
  SO_ENABLE(SoFCSelectionColorAction, SoViewportRegionElement);
432

433

434

435

436
  SO_ACTION_ADD_METHOD(SoCallback,callDoAction);
437
  SO_ACTION_ADD_METHOD(SoComplexity,callDoAction);
438
  SO_ACTION_ADD_METHOD(SoCoordinate3,callDoAction);
439
  SO_ACTION_ADD_METHOD(SoCoordinate4,callDoAction);
440
  SO_ACTION_ADD_METHOD(SoFont,callDoAction);
441
  SO_ACTION_ADD_METHOD(SoGroup,callDoAction);
442
  SO_ACTION_ADD_METHOD(SoProfile,callDoAction);
443
  SO_ACTION_ADD_METHOD(SoProfileCoordinate2,callDoAction);
444
  SO_ACTION_ADD_METHOD(SoProfileCoordinate3,callDoAction);
445
  SO_ACTION_ADD_METHOD(SoTransformation,callDoAction);
446
  SO_ACTION_ADD_METHOD(SoSwitch,callDoAction);
447

448
  SO_ACTION_ADD_METHOD(SoSeparator,callDoAction);
449
  SO_ACTION_ADD_METHOD(SoFCSelection,callDoAction);
450
}
451

452
void SoFCSelectionColorAction::finish()
453
{
454
  atexit_cleanup();
455
}
456

457

458
SoFCSelectionColorAction::SoFCSelectionColorAction (const SoSFColor& col)
459
  : selectionColor(col)
460
{
461
  SO_ACTION_CONSTRUCTOR(SoFCSelectionColorAction);
462
}
463

464

465
SoFCSelectionColorAction::~SoFCSelectionColorAction() = default;
466

467

468
void SoFCSelectionColorAction::beginTraversal(SoNode *node)
469
{
470
  traverse(node);
471
}
472

473
void SoFCSelectionColorAction::callDoAction(SoAction *action,SoNode *node)
474
{
475
  node->doAction(action);
476
}
477

478
// ---------------------------------------------------------------
479

480
SO_ACTION_SOURCE(SoFCHighlightColorAction)
481

482
/**
483
 * The order of the defined SO_ACTION_ADD_METHOD statements is very important. First the base
484
 * classes and afterwards subclasses of them must be listed, otherwise the registered methods
485
 * of subclasses will be overridden. For more details see the thread in the Coin3d forum
486
 * https://www.coin3d.org/pipermail/coin-discuss/2004-May/004346.html.
487
 * This means that \c SoSwitch must be listed after \c SoGroup and \c SoFCSelection after
488
 * \c SoSeparator because both classes inherits the others.
489
 */
490
void SoFCHighlightColorAction::initClass()
491
{
492
  SO_ACTION_INIT_CLASS(SoFCHighlightColorAction,SoAction);
493

494
  SO_ENABLE(SoFCHighlightColorAction, SoSwitchElement);
495

496
  SO_ACTION_ADD_METHOD(SoNode,nullAction);
497

498
  SO_ENABLE(SoFCHighlightColorAction, SoModelMatrixElement);
499
  SO_ENABLE(SoFCHighlightColorAction, SoShapeStyleElement);
500
  SO_ENABLE(SoFCHighlightColorAction, SoComplexityElement);
501
  SO_ENABLE(SoFCHighlightColorAction, SoComplexityTypeElement);
502
  SO_ENABLE(SoFCHighlightColorAction, SoCoordinateElement);
503
  SO_ENABLE(SoFCHighlightColorAction, SoFontNameElement);
504
  SO_ENABLE(SoFCHighlightColorAction, SoFontSizeElement);
505
  SO_ENABLE(SoFCHighlightColorAction, SoProfileCoordinateElement);
506
  SO_ENABLE(SoFCHighlightColorAction, SoProfileElement);
507
  SO_ENABLE(SoFCHighlightColorAction, SoSwitchElement);
508
  SO_ENABLE(SoFCHighlightColorAction, SoUnitsElement);
509
  SO_ENABLE(SoFCHighlightColorAction, SoViewVolumeElement);
510
  SO_ENABLE(SoFCHighlightColorAction, SoViewingMatrixElement);
511
  SO_ENABLE(SoFCHighlightColorAction, SoViewportRegionElement);
512

513

514

515

516
  SO_ACTION_ADD_METHOD(SoCallback,callDoAction);
517
  SO_ACTION_ADD_METHOD(SoComplexity,callDoAction);
518
  SO_ACTION_ADD_METHOD(SoCoordinate3,callDoAction);
519
  SO_ACTION_ADD_METHOD(SoCoordinate4,callDoAction);
520
  SO_ACTION_ADD_METHOD(SoFont,callDoAction);
521
  SO_ACTION_ADD_METHOD(SoGroup,callDoAction);
522
  SO_ACTION_ADD_METHOD(SoProfile,callDoAction);
523
  SO_ACTION_ADD_METHOD(SoProfileCoordinate2,callDoAction);
524
  SO_ACTION_ADD_METHOD(SoProfileCoordinate3,callDoAction);
525
  SO_ACTION_ADD_METHOD(SoTransformation,callDoAction);
526
  SO_ACTION_ADD_METHOD(SoSwitch,callDoAction);
527

528
  SO_ACTION_ADD_METHOD(SoSeparator,callDoAction);
529
  SO_ACTION_ADD_METHOD(SoFCSelection,callDoAction);
530
}
531

532
void SoFCHighlightColorAction::finish()
533
{
534
  atexit_cleanup();
535
}
536

537

538
SoFCHighlightColorAction::SoFCHighlightColorAction (const SoSFColor& col)
539
  : highlightColor(col)
540
{
541
  SO_ACTION_CONSTRUCTOR(SoFCHighlightColorAction);
542
}
543

544

545
SoFCHighlightColorAction::~SoFCHighlightColorAction() = default;
546

547

548
void SoFCHighlightColorAction::beginTraversal(SoNode *node)
549
{
550
  traverse(node);
551
}
552

553
void SoFCHighlightColorAction::callDoAction(SoAction *action,SoNode *node)
554
{
555
  node->doAction(action);
556
}
557

558
// ---------------------------------------------------------------
559

560
SO_ACTION_SOURCE(SoFCDocumentAction)
561

562
/**
563
 * The order of the defined SO_ACTION_ADD_METHOD statements is very important. First the base
564
 * classes and afterwards subclasses of them must be listed, otherwise the registered methods
565
 * of subclasses will be overridden. For more details see the thread in the Coin3d forum
566
 * https://www.coin3d.org/pipermail/coin-discuss/2004-May/004346.html.
567
 * This means that \c SoSwitch must be listed after \c SoGroup and \c SoFCSelection after
568
 * \c SoSeparator because both classes inherits the others.
569
 */
570
void SoFCDocumentAction::initClass()
571
{
572
  SO_ACTION_INIT_CLASS(SoFCDocumentAction,SoAction);
573

574
  SO_ENABLE(SoFCDocumentAction, SoSwitchElement);
575

576
  SO_ACTION_ADD_METHOD(SoNode,nullAction);
577

578
  SO_ENABLE(SoFCDocumentAction, SoModelMatrixElement);
579
  SO_ENABLE(SoFCDocumentAction, SoShapeStyleElement);
580
  SO_ENABLE(SoFCDocumentAction, SoComplexityElement);
581
  SO_ENABLE(SoFCDocumentAction, SoComplexityTypeElement);
582
  SO_ENABLE(SoFCDocumentAction, SoCoordinateElement);
583
  SO_ENABLE(SoFCDocumentAction, SoFontNameElement);
584
  SO_ENABLE(SoFCDocumentAction, SoFontSizeElement);
585
  SO_ENABLE(SoFCDocumentAction, SoProfileCoordinateElement);
586
  SO_ENABLE(SoFCDocumentAction, SoProfileElement);
587
  SO_ENABLE(SoFCDocumentAction, SoSwitchElement);
588
  SO_ENABLE(SoFCDocumentAction, SoUnitsElement);
589
  SO_ENABLE(SoFCDocumentAction, SoViewVolumeElement);
590
  SO_ENABLE(SoFCDocumentAction, SoViewingMatrixElement);
591
  SO_ENABLE(SoFCDocumentAction, SoViewportRegionElement);
592

593

594

595

596
  SO_ACTION_ADD_METHOD(SoCallback,callDoAction);
597
  SO_ACTION_ADD_METHOD(SoComplexity,callDoAction);
598
  SO_ACTION_ADD_METHOD(SoCoordinate3,callDoAction);
599
  SO_ACTION_ADD_METHOD(SoCoordinate4,callDoAction);
600
  SO_ACTION_ADD_METHOD(SoFont,callDoAction);
601
  SO_ACTION_ADD_METHOD(SoGroup,callDoAction);
602
  SO_ACTION_ADD_METHOD(SoProfile,callDoAction);
603
  SO_ACTION_ADD_METHOD(SoProfileCoordinate2,callDoAction);
604
  SO_ACTION_ADD_METHOD(SoProfileCoordinate3,callDoAction);
605
  SO_ACTION_ADD_METHOD(SoTransformation,callDoAction);
606
  SO_ACTION_ADD_METHOD(SoSwitch,callDoAction);
607

608
  SO_ACTION_ADD_METHOD(SoSeparator,callDoAction);
609
  SO_ACTION_ADD_METHOD(SoFCSelection,callDoAction);
610
}
611

612
void SoFCDocumentAction::finish()
613
{
614
  atexit_cleanup();
615
}
616

617

618
SoFCDocumentAction::SoFCDocumentAction (const SoSFString& docName)
619
  : documentName(docName)
620
{
621
  SO_ACTION_CONSTRUCTOR(SoFCDocumentAction);
622
}
623

624

625
SoFCDocumentAction::~SoFCDocumentAction() = default;
626

627

628
void SoFCDocumentAction::beginTraversal(SoNode *node)
629
{
630
  traverse(node);
631
}
632

633
void SoFCDocumentAction::callDoAction(SoAction *action,SoNode *node)
634
{
635
  node->doAction(action);
636
}
637

638

639
// ---------------------------------------------------------------
640

641
SO_ACTION_SOURCE(SoFCDocumentObjectAction)
642

643
/**
644
 * The order of the defined SO_ACTION_ADD_METHOD statements is very important. First the base
645
 * classes and afterwards subclasses of them must be listed, otherwise the registered methods
646
 * of subclasses will be overridden. For more details see the thread in the Coin3d forum
647
 * https://www.coin3d.org/pipermail/coin-discuss/2004-May/004346.html.
648
 * This means that \c SoSwitch must be listed after \c SoGroup and \c SoFCSelection after
649
 * \c SoSeparator because both classes inherits the others.
650
 */
651
void SoFCDocumentObjectAction::initClass()
652
{
653
  SO_ACTION_INIT_CLASS(SoFCDocumentObjectAction,SoAction);
654

655
  SO_ENABLE(SoFCDocumentObjectAction, SoSwitchElement);
656

657
  SO_ACTION_ADD_METHOD(SoNode,nullAction);
658

659
  SO_ENABLE(SoFCDocumentObjectAction, SoModelMatrixElement);
660
  SO_ENABLE(SoFCDocumentObjectAction, SoShapeStyleElement);
661
  SO_ENABLE(SoFCDocumentObjectAction, SoComplexityElement);
662
  SO_ENABLE(SoFCDocumentObjectAction, SoComplexityTypeElement);
663
  SO_ENABLE(SoFCDocumentObjectAction, SoCoordinateElement);
664
  SO_ENABLE(SoFCDocumentObjectAction, SoFontNameElement);
665
  SO_ENABLE(SoFCDocumentObjectAction, SoFontSizeElement);
666
  SO_ENABLE(SoFCDocumentObjectAction, SoProfileCoordinateElement);
667
  SO_ENABLE(SoFCDocumentObjectAction, SoProfileElement);
668
  SO_ENABLE(SoFCDocumentObjectAction, SoSwitchElement);
669
  SO_ENABLE(SoFCDocumentObjectAction, SoUnitsElement);
670
  SO_ENABLE(SoFCDocumentObjectAction, SoViewVolumeElement);
671
  SO_ENABLE(SoFCDocumentObjectAction, SoViewingMatrixElement);
672
  SO_ENABLE(SoFCDocumentObjectAction, SoViewportRegionElement);
673

674
  SO_ACTION_ADD_METHOD(SoCallback,callDoAction);
675
  SO_ACTION_ADD_METHOD(SoComplexity,callDoAction);
676
  SO_ACTION_ADD_METHOD(SoCoordinate3,callDoAction);
677
  SO_ACTION_ADD_METHOD(SoCoordinate4,callDoAction);
678
  SO_ACTION_ADD_METHOD(SoFont,callDoAction);
679
  SO_ACTION_ADD_METHOD(SoGroup,callDoAction);
680
  SO_ACTION_ADD_METHOD(SoProfile,callDoAction);
681
  SO_ACTION_ADD_METHOD(SoProfileCoordinate2,callDoAction);
682
  SO_ACTION_ADD_METHOD(SoProfileCoordinate3,callDoAction);
683
  SO_ACTION_ADD_METHOD(SoTransformation,callDoAction);
684
  SO_ACTION_ADD_METHOD(SoSwitch,callDoAction);
685

686
  SO_ACTION_ADD_METHOD(SoSeparator,callDoAction);
687
  SO_ACTION_ADD_METHOD(SoFCSelection,callDoAction);
688
}
689

690
void SoFCDocumentObjectAction::finish()
691
{
692
  atexit_cleanup();
693
}
694

695
SoFCDocumentObjectAction::SoFCDocumentObjectAction()
696
{
697
  SO_ACTION_CONSTRUCTOR(SoFCDocumentObjectAction);
698
}
699

700
SoFCDocumentObjectAction::~SoFCDocumentObjectAction() = default;
701

702
void SoFCDocumentObjectAction::beginTraversal(SoNode *node)
703
{
704
  traverse(node);
705
}
706

707
void SoFCDocumentObjectAction::callDoAction(SoAction *action,SoNode *node)
708
{
709
  node->doAction(action);
710
}
711

712
void SoFCDocumentObjectAction::setHandled()
713
{
714
  this->_handled = true;
715
}
716

717
SbBool SoFCDocumentObjectAction::isHandled() const
718
{
719
  return this->_handled;
720
}
721

722
// ---------------------------------------------------------------
723

724
SO_ACTION_SOURCE(SoGLSelectAction)
725

726
/**
727
 * The order of the defined SO_ACTION_ADD_METHOD statements is very important. First the base
728
 * classes and afterwards subclasses of them must be listed, otherwise the registered methods
729
 * of subclasses will be overridden. For more details see the thread in the Coin3d forum
730
 * https://www.coin3d.org/pipermail/coin-discuss/2004-May/004346.html.
731
 * This means that \c SoSwitch must be listed after \c SoGroup and \c SoFCSelection after
732
 * \c SoSeparator because both classes inherits the others.
733
 */
734
void SoGLSelectAction::initClass()
735
{
736
  SO_ACTION_INIT_CLASS(SoGLSelectAction,SoAction);
737

738
  SO_ENABLE(SoGLSelectAction, SoSwitchElement);
739

740
  SO_ACTION_ADD_METHOD(SoNode,nullAction);
741

742
  SO_ENABLE(SoGLSelectAction, SoModelMatrixElement);
743
  SO_ENABLE(SoGLSelectAction, SoProjectionMatrixElement);
744
  SO_ENABLE(SoGLSelectAction, SoCoordinateElement);
745
  SO_ENABLE(SoGLSelectAction, SoViewVolumeElement);
746
  SO_ENABLE(SoGLSelectAction, SoViewingMatrixElement);
747
  SO_ENABLE(SoGLSelectAction, SoViewportRegionElement);
748

749
  SO_ACTION_ADD_METHOD(SoCamera,callDoAction);
750
  SO_ACTION_ADD_METHOD(SoCoordinate3,callDoAction);
751
  SO_ACTION_ADD_METHOD(SoCoordinate4,callDoAction);
752
  SO_ACTION_ADD_METHOD(SoGroup,callDoAction);
753
  SO_ACTION_ADD_METHOD(SoSwitch,callDoAction);
754
  SO_ACTION_ADD_METHOD(SoShape,callDoAction);
755
  SO_ACTION_ADD_METHOD(SoIndexedFaceSet,callDoAction);
756

757
  SO_ACTION_ADD_METHOD(SoSeparator,callDoAction);
758
  SO_ACTION_ADD_METHOD(SoFCSelection,callDoAction);
759
}
760

761
SoGLSelectAction::SoGLSelectAction (const SbViewportRegion& region,
762
                                    const SbViewportRegion& select)
763
  : vpregion(region), vpselect(select)
764
{
765
  SO_ACTION_CONSTRUCTOR(SoGLSelectAction);
766
}
767

768
SoGLSelectAction::~SoGLSelectAction() = default;
769

770
const SbViewportRegion& SoGLSelectAction::getViewportRegion () const
771
{
772
  return this->vpselect;
773
}
774

775
void SoGLSelectAction::beginTraversal(SoNode *node)
776
{
777
  SoViewportRegionElement::set(this->getState(), this->vpregion);
778
  traverse(node);
779
}
780

781
void SoGLSelectAction::callDoAction(SoAction *action,SoNode *node)
782
{
783
  node->doAction(action);
784
}
785

786
void SoGLSelectAction::setHandled()
787
{
788
  this->_handled = true;
789
}
790

791
SbBool SoGLSelectAction::isHandled() const
792
{
793
  return this->_handled;
794
}
795

796
// ---------------------------------------------------------------
797

798
SO_ACTION_SOURCE(SoVisibleFaceAction)
799

800
/**
801
 * The order of the defined SO_ACTION_ADD_METHOD statements is very important. First the base
802
 * classes and afterwards subclasses of them must be listed, otherwise the registered methods
803
 * of subclasses will be overridden. For more details see the thread in the Coin3d forum
804
 * https://www.coin3d.org/pipermail/coin-discuss/2004-May/004346.html.
805
 * This means that \c SoSwitch must be listed after \c SoGroup and \c SoFCSelection after
806
 * \c SoSeparator because both classes inherits the others.
807
 */
808
void SoVisibleFaceAction::initClass()
809
{
810
  SO_ACTION_INIT_CLASS(SoVisibleFaceAction,SoAction);
811

812
  SO_ENABLE(SoVisibleFaceAction, SoSwitchElement);
813

814
  SO_ACTION_ADD_METHOD(SoNode,nullAction);
815

816
  SO_ENABLE(SoVisibleFaceAction, SoModelMatrixElement);
817
  SO_ENABLE(SoVisibleFaceAction, SoProjectionMatrixElement);
818
  SO_ENABLE(SoVisibleFaceAction, SoCoordinateElement);
819
  SO_ENABLE(SoVisibleFaceAction, SoViewVolumeElement);
820
  SO_ENABLE(SoVisibleFaceAction, SoViewingMatrixElement);
821
  SO_ENABLE(SoVisibleFaceAction, SoViewportRegionElement);
822

823

824
  SO_ACTION_ADD_METHOD(SoCamera,callDoAction);
825
  SO_ACTION_ADD_METHOD(SoCoordinate3,callDoAction);
826
  SO_ACTION_ADD_METHOD(SoCoordinate4,callDoAction);
827
  SO_ACTION_ADD_METHOD(SoGroup,callDoAction);
828
  SO_ACTION_ADD_METHOD(SoSwitch,callDoAction);
829
  SO_ACTION_ADD_METHOD(SoShape,callDoAction);
830
  SO_ACTION_ADD_METHOD(SoIndexedFaceSet,callDoAction);
831

832
  SO_ACTION_ADD_METHOD(SoSeparator,callDoAction);
833
  SO_ACTION_ADD_METHOD(SoFCSelection,callDoAction);
834
}
835

836
SoVisibleFaceAction::SoVisibleFaceAction ()
837
{
838
  SO_ACTION_CONSTRUCTOR(SoVisibleFaceAction);
839
}
840

841
SoVisibleFaceAction::~SoVisibleFaceAction() = default;
842

843
void SoVisibleFaceAction::beginTraversal(SoNode *node)
844
{
845
  traverse(node);
846
}
847

848
void SoVisibleFaceAction::callDoAction(SoAction *action,SoNode *node)
849
{
850
  node->doAction(action);
851
}
852

853
void SoVisibleFaceAction::setHandled()
854
{
855
  this->_handled = true;
856
}
857

858
SbBool SoVisibleFaceAction::isHandled() const
859
{
860
  return this->_handled;
861
}
862

863
// ---------------------------------------------------------------
864

865

866
SO_ACTION_SOURCE(SoUpdateVBOAction)
867

868
/**
869
 * The order of the defined SO_ACTION_ADD_METHOD statements is very important. First the base
870
 * classes and afterwards subclasses of them must be listed, otherwise the registered methods
871
 * of subclasses will be overridden. For more details see the thread in the Coin3d forum
872
 * https://www.coin3d.org/pipermail/coin-discuss/2004-May/004346.html.
873
 * This means that \c SoSwitch must be listed after \c SoGroup and \c SoFCSelection after
874
 * \c SoSeparator because both classes inherits the others.
875
 */
876
void SoUpdateVBOAction::initClass()
877
{
878
  SO_ACTION_INIT_CLASS(SoUpdateVBOAction,SoAction);
879

880
  SO_ENABLE(SoUpdateVBOAction, SoSwitchElement);
881

882
  SO_ACTION_ADD_METHOD(SoNode,nullAction);
883

884
  SO_ENABLE(SoUpdateVBOAction, SoModelMatrixElement);
885
  SO_ENABLE(SoUpdateVBOAction, SoProjectionMatrixElement);
886
  SO_ENABLE(SoUpdateVBOAction, SoCoordinateElement);
887
  SO_ENABLE(SoUpdateVBOAction, SoViewVolumeElement);
888
  SO_ENABLE(SoUpdateVBOAction, SoViewingMatrixElement);
889
  SO_ENABLE(SoUpdateVBOAction, SoViewportRegionElement);
890

891

892
  SO_ACTION_ADD_METHOD(SoCamera,callDoAction);
893
  SO_ACTION_ADD_METHOD(SoCoordinate3,callDoAction);
894
  SO_ACTION_ADD_METHOD(SoCoordinate4,callDoAction);
895
  SO_ACTION_ADD_METHOD(SoGroup,callDoAction);
896
  SO_ACTION_ADD_METHOD(SoSwitch,callDoAction);
897
  SO_ACTION_ADD_METHOD(SoShape,callDoAction);
898
  SO_ACTION_ADD_METHOD(SoIndexedFaceSet,callDoAction);
899

900
  SO_ACTION_ADD_METHOD(SoSeparator,callDoAction);
901
  SO_ACTION_ADD_METHOD(SoFCSelection,callDoAction);
902
}
903

904
SoUpdateVBOAction::SoUpdateVBOAction ()
905
{
906
  SO_ACTION_CONSTRUCTOR(SoUpdateVBOAction);
907
}
908

909
SoUpdateVBOAction::~SoUpdateVBOAction() = default;
910

911
void SoUpdateVBOAction::finish()
912
{
913
  atexit_cleanup();
914
}
915

916
void SoUpdateVBOAction::beginTraversal(SoNode *node)
917
{
918
  traverse(node);
919
}
920

921
void SoUpdateVBOAction::callDoAction(SoAction *action,SoNode *node)
922
{
923
  node->doAction(action);
924
}
925

926
// ---------------------------------------------------------------
927

928
namespace Gui {
929
class SoBoxSelectionRenderActionP {
930
public:
931
    SoBoxSelectionRenderActionP(SoBoxSelectionRenderAction * master)
932
      : master(master)
933
    {
934
    }
935

936
    SoBoxSelectionRenderAction * master;
937
    SoSearchAction * searchaction{nullptr};
938
    SoSearchAction * selectsearch{nullptr};
939
    SoSearchAction * camerasearch{nullptr};
940
    SoGetBoundingBoxAction * bboxaction{nullptr};
941
    SoBaseColor * basecolor{nullptr};
942
    SoTempPath * postprocpath{nullptr};
943
    SoPath * highlightPath{nullptr};
944
    SoSeparator * localRoot{nullptr};
945
    SoMatrixTransform * xform{nullptr};
946
    SoCube * cube{nullptr};
947
    SoDrawStyle * drawstyle{nullptr};
948
    SoColorPacker colorpacker;
949

950
    void initBoxGraph();
951
    void updateBbox(const SoPath * path);
952
};
953

954
}
955

956
#undef PRIVATE
957
#define PRIVATE(p) ((p)->pimpl)
958
#undef PUBLIC
959
#define PUBLIC(p) ((p)->master)
960

961
// used to initialize the internal storage class with variables
962
void
963
SoBoxSelectionRenderActionP::initBoxGraph()
964
{
965
    this->localRoot = new SoSeparator;
966
    this->localRoot->ref();
967
    this->localRoot->renderCaching = SoSeparator::OFF;
968
    this->localRoot->boundingBoxCaching = SoSeparator::OFF;
969

970
    this->xform = new SoMatrixTransform;
971
    this->cube = new SoCube;
972

973
    this->drawstyle = new SoDrawStyle;
974
    this->drawstyle->style = SoDrawStyleElement::LINES;
975
    this->basecolor = new SoBaseColor;
976

977
    auto lightmodel = new SoLightModel;
978
    lightmodel->model = SoLightModel::BASE_COLOR;
979

980
    auto complexity = new SoComplexity;
981
    complexity->textureQuality = 0.0f;
982
    complexity->type = SoComplexityTypeElement::BOUNDING_BOX;
983

984
    this->localRoot->addChild(this->drawstyle);
985
    this->localRoot->addChild(this->basecolor);
986

987
    this->localRoot->addChild(lightmodel);
988
    this->localRoot->addChild(complexity);
989

990
    this->localRoot->addChild(this->xform);
991
    this->localRoot->addChild(this->cube);
992
}
993

994

995
// used to render shape and non-shape nodes (usually SoGroup or SoSeparator).
996
void
997
SoBoxSelectionRenderActionP::updateBbox(const SoPath * path)
998
{
999
    if (!this->camerasearch) {
1000
        this->camerasearch = new SoSearchAction;
1001
    }
1002

1003
    // find camera used to render node
1004
    this->camerasearch->setFind(SoSearchAction::TYPE);
1005
    this->camerasearch->setInterest(SoSearchAction::LAST);
1006
    this->camerasearch->setType(SoCamera::getClassTypeId());
1007
    this->camerasearch->apply(const_cast<SoPath*>(path));
1008

1009
    if (!this->camerasearch->getPath()) {
1010
        // if there is no camera there is no point rendering the bbox
1011
        return;
1012
    }
1013
    this->localRoot->insertChild(this->camerasearch->getPath()->getTail(), 0);
1014
    this->camerasearch->reset();
1015

1016
    if (!this->bboxaction) {
1017
        this->bboxaction = new SoGetBoundingBoxAction(SbViewportRegion(100, 100));
1018
    }
1019
    this->bboxaction->setViewportRegion(PUBLIC(this)->getViewportRegion());
1020
    this->bboxaction->apply(const_cast<SoPath*>(path));
1021

1022
    SbXfBox3f & box = this->bboxaction->getXfBoundingBox();
1023

1024
    if (!box.isEmpty()) {
1025
        // set cube size
1026
        float x, y, z;
1027
        box.getSize(x, y, z);
1028
        this->cube->width  = x;
1029
        this->cube->height  = y;
1030
        this->cube->depth = z;
1031

1032
        SbMatrix transform = box.getTransform(); // clazy:exclude=rule-of-two-soft
1033

1034
        // get center (in the local bbox coordinate system)
1035
        SbVec3f center = box.SbBox3f::getCenter();
1036

1037
        // if center != (0,0,0), move the cube
1038
        if (center != SbVec3f(0.0f, 0.0f, 0.0f)) {
1039
            SbMatrix t;
1040
            t.setTranslate(center);
1041
            transform.multLeft(t);
1042
        }
1043
        this->xform->matrix = transform;
1044

1045
        PUBLIC(this)->SoGLRenderAction::apply(this->localRoot);
1046
    }
1047
    // remove camera
1048
    this->localRoot->removeChild(0);
1049
}
1050

1051
SO_ACTION_SOURCE(SoBoxSelectionRenderAction)
1052

1053
// Overridden from parent class.
1054
void
1055
SoBoxSelectionRenderAction::initClass()
1056
{
1057
    SO_ACTION_INIT_CLASS(SoBoxSelectionRenderAction, SoGLRenderAction);
1058
}
1059

1060
SoBoxSelectionRenderAction::SoBoxSelectionRenderAction()
1061
  : inherited(SbViewportRegion())
1062
{
1063
    this->constructorCommon();
1064
}
1065

1066
SoBoxSelectionRenderAction::SoBoxSelectionRenderAction(const SbViewportRegion & viewportregion)
1067
  : inherited(viewportregion)
1068
{
1069
    this->constructorCommon();
1070
}
1071

1072
//
1073
// private. called by both constructors
1074
//
1075
void
1076
SoBoxSelectionRenderAction::constructorCommon()
1077
{
1078
    SO_ACTION_CONSTRUCTOR(SoBoxSelectionRenderAction);
1079

1080
    PRIVATE(this) = new SoBoxSelectionRenderActionP(this);
1081

1082
    // Initialize local variables
1083
    PRIVATE(this)->initBoxGraph();
1084

1085
    this->hlVisible = false;
1086

1087
    PRIVATE(this)->basecolor->rgb.setValue(1.0f, 0.0f, 0.0f);
1088
    PRIVATE(this)->drawstyle->linePattern = 0xffff;
1089
    PRIVATE(this)->drawstyle->lineWidth = 1.0f;
1090
    PRIVATE(this)->searchaction = nullptr;
1091
    PRIVATE(this)->selectsearch = nullptr;
1092
    PRIVATE(this)->camerasearch = nullptr;
1093
    PRIVATE(this)->bboxaction = nullptr;
1094

1095
    // SoBase-derived objects should be dynamically allocated.
1096
    PRIVATE(this)->postprocpath = new SoTempPath(32);
1097
    PRIVATE(this)->postprocpath->ref();
1098
    PRIVATE(this)->highlightPath = nullptr;
1099
}
1100

1101
SoBoxSelectionRenderAction::~SoBoxSelectionRenderAction()
1102
{
1103
    // clear highlighting node
1104
    if (PRIVATE(this)->highlightPath) {
1105
        PRIVATE(this)->highlightPath->unref();
1106
    }
1107
    PRIVATE(this)->postprocpath->unref();
1108
    PRIVATE(this)->localRoot->unref();
1109

1110
    delete PRIVATE(this)->searchaction;
1111
    delete PRIVATE(this)->selectsearch;
1112
    delete PRIVATE(this)->camerasearch;
1113
    delete PRIVATE(this)->bboxaction;
1114
    delete PRIVATE(this);
1115
}
1116

1117
void
1118
SoBoxSelectionRenderAction::apply(SoNode * node)
1119
{
1120
    SoGLRenderAction::apply(node);
1121
    if (this->hlVisible) {
1122
        if (!PRIVATE(this)->searchaction) {
1123
            PRIVATE(this)->searchaction = new SoSearchAction;
1124
        }
1125
        PRIVATE(this)->searchaction->setType(SoFCSelection::getClassTypeId());
1126
        PRIVATE(this)->searchaction->setInterest(SoSearchAction::ALL);
1127
        PRIVATE(this)->searchaction->apply(node);
1128
        const SoPathList & pathlist = PRIVATE(this)->searchaction->getPaths();
1129
        if (pathlist.getLength() > 0) {
1130
            for (int i = 0; i < pathlist.getLength(); i++ ) {
1131
                SoPath * path = pathlist[i];
1132
                assert(path);
1133
                auto selection = static_cast<SoFCSelection *>(path->getTail());
1134
                assert(selection->getTypeId().isDerivedFrom(SoFCSelection::getClassTypeId()));
1135
                if (selection->selected.getValue() && selection->style.getValue() == SoFCSelection::BOX) {
1136
                    PRIVATE(this)->basecolor->rgb.setValue(selection->colorSelection.getValue());
1137
                    if (!PRIVATE(this)->selectsearch) {
1138
                        PRIVATE(this)->selectsearch = new SoSearchAction;
1139
                    }
1140
                    PRIVATE(this)->selectsearch->setType(SoShape::getClassTypeId());
1141
                    PRIVATE(this)->selectsearch->setInterest(SoSearchAction::FIRST);
1142
                    PRIVATE(this)->selectsearch->apply(selection);
1143
                    SoPath* shapepath = PRIVATE(this)->selectsearch->getPath();
1144
                    if (shapepath) {
1145
                        SoPathList list;
1146
                        list.append(shapepath);
1147
                        this->drawBoxes(path, &list);
1148
                    }
1149
                    PRIVATE(this)->selectsearch->reset();
1150
                }
1151
                else if (selection->isHighlighted() &&
1152
                         selection->selected.getValue() == SoFCSelection::NOTSELECTED &&
1153
                         selection->style.getValue() == SoFCSelection::BOX) {
1154
                    PRIVATE(this)->basecolor->rgb.setValue(selection->colorHighlight.getValue());
1155

1156
                    if (!PRIVATE(this)->selectsearch) {
1157
                        PRIVATE(this)->selectsearch = new SoSearchAction;
1158
                    }
1159
                    PRIVATE(this)->selectsearch->setType(SoShape::getClassTypeId());
1160
                    PRIVATE(this)->selectsearch->setInterest(SoSearchAction::FIRST);
1161
                    PRIVATE(this)->selectsearch->apply(selection);
1162
                    SoPath* shapepath = PRIVATE(this)->selectsearch->getPath();
1163
                    if (shapepath) {
1164
                        SoPathList list;
1165
                        list.append(shapepath);
1166
                        // clear old highlighting node if still active
1167
                        if (PRIVATE(this)->highlightPath) {
1168
                            PRIVATE(this)->highlightPath->unref();
1169
                        }
1170
                        PRIVATE(this)->highlightPath = path;
1171
                        PRIVATE(this)->highlightPath->ref();
1172
                        this->drawBoxes(path, &list);
1173
                    }
1174
                    PRIVATE(this)->selectsearch->reset();
1175
                }
1176
            }
1177
        }
1178
        PRIVATE(this)->searchaction->reset();
1179
    }
1180
}
1181

1182
void
1183
SoBoxSelectionRenderAction::apply(SoPath * path)
1184
{
1185
    SoGLRenderAction::apply(path);
1186
    SoNode* node = path->getTail();
1187
    if (node && node->getTypeId() == SoFCSelection::getClassTypeId()) {
1188
        auto selection = static_cast<SoFCSelection *>(node);
1189

1190
        // This happens when dehighlighting the current shape
1191
        if (PRIVATE(this)->highlightPath == path) {
1192
            PRIVATE(this)->highlightPath->unref();
1193
            PRIVATE(this)->highlightPath = nullptr;
1194
            // FIXME: Doing a redraw to remove the shown bounding box causes
1195
            // some problems when moving the mouse from one shape to another
1196
            // because this will destroy the box immediately
1197
            selection->touch(); // force a redraw when dehighlighting
1198
        }
1199
        else if (selection->isHighlighted() &&
1200
                 selection->selected.getValue() == SoFCSelection::NOTSELECTED &&
1201
                 selection->style.getValue() == SoFCSelection::BOX) {
1202
            PRIVATE(this)->basecolor->rgb.setValue(selection->colorHighlight.getValue());
1203

1204
            if (!PRIVATE(this)->selectsearch) {
1205
                PRIVATE(this)->selectsearch = new SoSearchAction;
1206
            }
1207
            PRIVATE(this)->selectsearch->setType(SoShape::getClassTypeId());
1208
            PRIVATE(this)->selectsearch->setInterest(SoSearchAction::FIRST);
1209
            PRIVATE(this)->selectsearch->apply(selection);
1210
            SoPath* shapepath = PRIVATE(this)->selectsearch->getPath();
1211
            if (shapepath) {
1212
                SoPathList list;
1213
                list.append(shapepath);
1214
                // clear old highlighting node if still active
1215
                if (PRIVATE(this)->highlightPath) {
1216
                    PRIVATE(this)->highlightPath->unref();
1217
                }
1218
                PRIVATE(this)->highlightPath = path;
1219
                PRIVATE(this)->highlightPath->ref();
1220
                this->drawBoxes(path, &list);
1221
            }
1222
            PRIVATE(this)->selectsearch->reset();
1223
        }
1224
    }
1225
}
1226

1227
void
1228
SoBoxSelectionRenderAction::apply(const SoPathList & pathlist,
1229
                                  SbBool obeysrules)
1230
{
1231
    SoGLRenderAction::apply(pathlist, obeysrules);
1232
}
1233

1234
void
1235
SoBoxSelectionRenderAction::setColor(const SbColor & color)
1236
{
1237
    PRIVATE(this)->basecolor->rgb = color;
1238
}
1239

1240
const SbColor &
1241
SoBoxSelectionRenderAction::getColor()
1242
{
1243
    return PRIVATE(this)->basecolor->rgb[0];
1244
}
1245

1246
void
1247
SoBoxSelectionRenderAction::setLinePattern(unsigned short pattern)
1248
{
1249
    PRIVATE(this)->drawstyle->linePattern = pattern;
1250
}
1251

1252
unsigned short
1253
SoBoxSelectionRenderAction::getLinePattern() const
1254
{
1255
    return PRIVATE(this)->drawstyle->linePattern.getValue();
1256
}
1257

1258
void
1259
SoBoxSelectionRenderAction::setLineWidth(const float width)
1260
{
1261
    PRIVATE(this)->drawstyle->lineWidth = width;
1262
}
1263

1264
float
1265
SoBoxSelectionRenderAction::getLineWidth() const
1266
{
1267
    return PRIVATE(this)->drawstyle->lineWidth.getValue();
1268
}
1269

1270
void
1271
SoBoxSelectionRenderAction::drawBoxes(SoPath * pathtothis, const SoPathList * pathlist)
1272
{
1273
    int i;
1274
    int thispos = static_cast<SoFullPath *>(pathtothis)->getLength()-1;
1275
    assert(thispos >= 0);
1276
    PRIVATE(this)->postprocpath->truncate(0); // reset
1277

1278
    for (i = 0; i < thispos; i++)
1279
        PRIVATE(this)->postprocpath->append(pathtothis->getNode(i));
1280

1281
    // we need to disable accumulation buffer antialiasing while
1282
    // rendering selected objects
1283
    int oldnumpasses = this->getNumPasses();
1284
    this->setNumPasses(1);
1285

1286
    SoState * thestate = this->getState();
1287
    thestate->push();
1288

1289
    for (i = 0; i < pathlist->getLength(); i++) {
1290
        auto path = static_cast<SoFullPath *>((*pathlist)[i]);
1291

1292
        for (int j = 0; j < path->getLength(); j++) {
1293
            PRIVATE(this)->postprocpath->append(path->getNode(j));
1294
        }
1295

1296
        // Previously SoGLRenderAction was used to draw the bounding boxes
1297
        // of shapes in selection paths, by overriding renderstyle state
1298
        // elements to lines drawstyle and simply doing:
1299
        //
1300
        //   SoGLRenderAction::apply(PRIVATE(this)->postprocpath); // Bug
1301
        //
1302
        // This could have the unwanted side effect of rendering
1303
        // non-selected shapes, as they could be part of the path (due to
1304
        // being placed below SoGroup nodes (instead of SoSeparator
1305
        // nodes)) up to the selected shape.
1306
        //
1307
        //
1308
        // A better approach turned out to be to soup up and draw only the
1309
        // bounding boxes of the selected shapes:
1310
        PRIVATE(this)->updateBbox(PRIVATE(this)->postprocpath);
1311

1312
        // Remove temporary path from path buffer
1313
        PRIVATE(this)->postprocpath->truncate(thispos);
1314
    }
1315

1316
    this->setNumPasses(oldnumpasses);
1317
    thestate->pop();
1318
}
1319

1320

1321
#undef PRIVATE
1322
#undef PUBLIC
1323

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.