Debian Codegraph @

src/Gui/Selection/SoFCSelectionAction.cpp

raw
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 /***************************************************************************
3 * Copyright (c) 2005 Jürgen Riegel <[email protected]> *
4 * *
5 * This file is part of the FreeCAD CAx development system. *
6 * *
7 * This library is free software; you can redistribute it and/or *
8 * modify it under the terms of the GNU Library General Public *
9 * License as published by the Free Software Foundation; either *
10 * version 2 of the License, or (at your option) any later version. *
11 * *
12 * This library is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU Library General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU Library General Public *
18 * License along with this library; see the file COPYING.LIB. If not, *
19 * write to the Free Software Foundation, Inc., 59 Temple Place, *
20 * Suite 330, Boston, MA 02111-1307, USA *
21 * *
22 ***************************************************************************/
23
24
25 #include <Inventor/actions/SoSearchAction.h>
26 #include <Inventor/actions/SoGetBoundingBoxAction.h>
27 #include <Inventor/elements/SoComplexityElement.h>
28 #include <Inventor/elements/SoComplexityTypeElement.h>
29 #include <Inventor/elements/SoCoordinateElement.h>
30 #include <Inventor/elements/SoFontNameElement.h>
31 #include <Inventor/elements/SoFontSizeElement.h>
32 #include <Inventor/elements/SoModelMatrixElement.h>
33 #include <Inventor/elements/SoProfileCoordinateElement.h>
34 #include <Inventor/elements/SoProfileElement.h>
35 #include <Inventor/elements/SoProjectionMatrixElement.h>
36 #include <Inventor/elements/SoShapeStyleElement.h>
37 #include <Inventor/elements/SoSwitchElement.h>
38 #include <Inventor/elements/SoUnitsElement.h>
39 #include <Inventor/elements/SoViewingMatrixElement.h>
40 #include <Inventor/elements/SoViewportRegionElement.h>
41 #include <Inventor/elements/SoViewVolumeElement.h>
42 #include <Inventor/nodes/SoBaseColor.h>
43 #include <Inventor/nodes/SoCallback.h>
44 #include <Inventor/nodes/SoCamera.h>
45 #include <Inventor/nodes/SoComplexity.h>
46 #include <Inventor/nodes/SoCoordinate3.h>
47 #include <Inventor/nodes/SoCoordinate4.h>
48 #include <Inventor/nodes/SoCube.h>
49 #include <Inventor/nodes/SoDrawStyle.h>
50 #include <Inventor/nodes/SoFont.h>
51 #include <Inventor/nodes/SoIndexedLineSet.h>
52 #include <Inventor/nodes/SoIndexedFaceSet.h>
53 #include <Inventor/nodes/SoLightModel.h>
54 #include <Inventor/nodes/SoMatrixTransform.h>
55 #include <Inventor/nodes/SoPointSet.h>
56 #include <Inventor/nodes/SoProfile.h>
57 #include <Inventor/nodes/SoProfileCoordinate2.h>
58 #include <Inventor/nodes/SoProfileCoordinate3.h>
59 #include <Inventor/nodes/SoSeparator.h>
60 #include <Inventor/nodes/SoSwitch.h>
61 #include <Inventor/nodes/SoTransformation.h>
62
63
64 #include "SoFCSelectionAction.h"
65 #include "SoFCSelection.h"
66
67
68 using namespace Gui;
69
70
71 SO_ACTION_SOURCE(SoFCPreselectionAction)
72
73 /**
74 * The order of the defined SO_ACTION_ADD_METHOD statements is very important. First the base
75 * classes and afterwards subclasses of them must be listed, otherwise the registered methods
76 * of subclasses will be overridden. For more details see the thread in the Coin3d forum
77 * https://www.coin3d.org/pipermail/coin-discuss/2004-May/004346.html.
78 * This means that \c SoSwitch must be listed after \c SoGroup and \c SoFCSelection after
79 * \c SoSeparator because both classes inherits the others.
80 */
81 void SoFCPreselectionAction::initClass()
82 {
83 SO_ACTION_INIT_CLASS(SoFCPreselectionAction, SoAction);
84
85 SO_ENABLE(SoFCPreselectionAction, SoSwitchElement);
86
87 SO_ACTION_ADD_METHOD(SoNode, nullAction);
88
89 SO_ENABLE(SoFCPreselectionAction, SoModelMatrixElement);
90 SO_ENABLE(SoFCPreselectionAction, SoShapeStyleElement);
91 SO_ENABLE(SoFCPreselectionAction, SoComplexityElement);
92 SO_ENABLE(SoFCPreselectionAction, SoComplexityTypeElement);
93 SO_ENABLE(SoFCPreselectionAction, SoCoordinateElement);
94 SO_ENABLE(SoFCPreselectionAction, SoFontNameElement);
95 SO_ENABLE(SoFCPreselectionAction, SoFontSizeElement);
96 SO_ENABLE(SoFCPreselectionAction, SoProfileCoordinateElement);
97 SO_ENABLE(SoFCPreselectionAction, SoProfileElement);
98 SO_ENABLE(SoFCPreselectionAction, SoSwitchElement);
99 SO_ENABLE(SoFCPreselectionAction, SoUnitsElement);
100 SO_ENABLE(SoFCPreselectionAction, SoViewVolumeElement);
101 SO_ENABLE(SoFCPreselectionAction, SoViewingMatrixElement);
102 SO_ENABLE(SoFCPreselectionAction, SoViewportRegionElement);
103
104
105 SO_ACTION_ADD_METHOD(SoCallback, callDoAction);
106 SO_ACTION_ADD_METHOD(SoComplexity, callDoAction);
107 SO_ACTION_ADD_METHOD(SoCoordinate3, callDoAction);
108 SO_ACTION_ADD_METHOD(SoCoordinate4, callDoAction);
109 SO_ACTION_ADD_METHOD(SoFont, callDoAction);
110 SO_ACTION_ADD_METHOD(SoGroup, callDoAction);
111 SO_ACTION_ADD_METHOD(SoProfile, callDoAction);
112 SO_ACTION_ADD_METHOD(SoProfileCoordinate2, callDoAction);
113 SO_ACTION_ADD_METHOD(SoProfileCoordinate3, callDoAction);
114 SO_ACTION_ADD_METHOD(SoTransformation, callDoAction);
115 SO_ACTION_ADD_METHOD(SoSwitch, callDoAction);
116
117 SO_ACTION_ADD_METHOD(SoSeparator, callDoAction);
118 SO_ACTION_ADD_METHOD(SoFCSelection, callDoAction);
119
120 SO_ACTION_ADD_METHOD(SoIndexedLineSet, callDoAction);
121 SO_ACTION_ADD_METHOD(SoIndexedFaceSet, callDoAction);
122 SO_ACTION_ADD_METHOD(SoPointSet, callDoAction);
123 }
124
125 void SoFCPreselectionAction::finish()
126 {
127 atexit_cleanup();
128 }
129
130
131 SoFCPreselectionAction::SoFCPreselectionAction(const SelectionChanges& SelCh)
132 : SelChange(SelCh)
133 {
134 SO_ACTION_CONSTRUCTOR(SoFCPreselectionAction);
135 }
136
137
138 SoFCPreselectionAction::~SoFCPreselectionAction() = default;
139
140
141 void SoFCPreselectionAction::beginTraversal(SoNode* node)
142 {
143 traverse(node);
144 }
145
146 void SoFCPreselectionAction::callDoAction(SoAction* action, SoNode* node)
147 {
148 node->doAction(action);
149 }
150
151 // ---------------------------------------------------------------
152
153 SO_ACTION_SOURCE(SoFCSelectionAction)
154
155 /**
156 * The order of the defined SO_ACTION_ADD_METHOD statements is very important. First the base
157 * classes and afterwards subclasses of them must be listed, otherwise the registered methods
158 * of subclasses will be overridden. For more details see the thread in the Coin3d forum
159 * https://www.coin3d.org/pipermail/coin-discuss/2004-May/004346.html.
160 * This means that \c SoSwitch must be listed after \c SoGroup and \c SoFCSelection after
161 * \c SoSeparator because both classes inherits the others.
162 */
163 void SoFCSelectionAction::initClass()
164 {
165 SO_ACTION_INIT_CLASS(SoFCSelectionAction, SoAction);
166
167 SO_ENABLE(SoFCSelectionAction, SoSwitchElement);
168
169 SO_ACTION_ADD_METHOD(SoNode, nullAction);
170
171 SO_ENABLE(SoFCSelectionAction, SoModelMatrixElement);
172 SO_ENABLE(SoFCSelectionAction, SoShapeStyleElement);
173 SO_ENABLE(SoFCSelectionAction, SoComplexityElement);
174 SO_ENABLE(SoFCSelectionAction, SoComplexityTypeElement);
175 SO_ENABLE(SoFCSelectionAction, SoCoordinateElement);
176 SO_ENABLE(SoFCSelectionAction, SoFontNameElement);
177 SO_ENABLE(SoFCSelectionAction, SoFontSizeElement);
178 SO_ENABLE(SoFCSelectionAction, SoProfileCoordinateElement);
179 SO_ENABLE(SoFCSelectionAction, SoProfileElement);
180 SO_ENABLE(SoFCSelectionAction, SoSwitchElement);
181 SO_ENABLE(SoFCSelectionAction, SoUnitsElement);
182 SO_ENABLE(SoFCSelectionAction, SoViewVolumeElement);
183 SO_ENABLE(SoFCSelectionAction, SoViewingMatrixElement);
184 SO_ENABLE(SoFCSelectionAction, SoViewportRegionElement);
185
186
187 SO_ACTION_ADD_METHOD(SoCallback, callDoAction);
188 SO_ACTION_ADD_METHOD(SoComplexity, callDoAction);
189 SO_ACTION_ADD_METHOD(SoCoordinate3, callDoAction);
190 SO_ACTION_ADD_METHOD(SoCoordinate4, callDoAction);
191 SO_ACTION_ADD_METHOD(SoFont, callDoAction);
192 SO_ACTION_ADD_METHOD(SoGroup, callDoAction);
193 SO_ACTION_ADD_METHOD(SoProfile, callDoAction);
194 SO_ACTION_ADD_METHOD(SoProfileCoordinate2, callDoAction);
195 SO_ACTION_ADD_METHOD(SoProfileCoordinate3, callDoAction);
196 SO_ACTION_ADD_METHOD(SoTransformation, callDoAction);
197 SO_ACTION_ADD_METHOD(SoSwitch, callDoAction);
198
199 SO_ACTION_ADD_METHOD(SoSeparator, callDoAction);
200 SO_ACTION_ADD_METHOD(SoFCSelection, callDoAction);
201
202 SO_ACTION_ADD_METHOD(SoIndexedLineSet, callDoAction);
203 SO_ACTION_ADD_METHOD(SoIndexedFaceSet, callDoAction);
204 SO_ACTION_ADD_METHOD(SoPointSet, callDoAction);
205 }
206
207 void SoFCSelectionAction::finish()
208 {
209 atexit_cleanup();
210 }
211
212
213 SoFCSelectionAction::SoFCSelectionAction(const SelectionChanges& SelCh)
214 : SelChange(SelCh)
215 {
216 SO_ACTION_CONSTRUCTOR(SoFCSelectionAction);
217 }
218
219
220 SoFCSelectionAction::~SoFCSelectionAction() = default;
221
222
223 void SoFCSelectionAction::beginTraversal(SoNode* node)
224 {
225 traverse(node);
226 }
227
228 void SoFCSelectionAction::callDoAction(SoAction* action, SoNode* node)
229 {
230 node->doAction(action);
231 }
232
233 // ---------------------------------------------------------------
234
235 SO_ACTION_SOURCE(SoFCEnableSelectionAction)
236
237 /**
238 * The order of the defined SO_ACTION_ADD_METHOD statements is very important. First the base
239 * classes and afterwards subclasses of them must be listed, otherwise the registered methods
240 * of subclasses will be overridden. For more details see the thread in the Coin3d forum
241 * https://www.coin3d.org/pipermail/coin-discuss/2004-May/004346.html.
242 * This means that \c SoSwitch must be listed after \c SoGroup and \c SoFCSelection after
243 * \c SoSeparator because both classes inherits the others.
244 */
245 void SoFCEnableSelectionAction::initClass()
246 {
247 SO_ACTION_INIT_CLASS(SoFCEnableSelectionAction, SoAction);
248
249 SO_ENABLE(SoFCEnableSelectionAction, SoSwitchElement);
250
251 SO_ACTION_ADD_METHOD(SoNode, nullAction);
252
253 SO_ENABLE(SoFCEnableSelectionAction, SoModelMatrixElement);
254 SO_ENABLE(SoFCEnableSelectionAction, SoShapeStyleElement);
255 SO_ENABLE(SoFCEnableSelectionAction, SoComplexityElement);
256 SO_ENABLE(SoFCEnableSelectionAction, SoComplexityTypeElement);
257 SO_ENABLE(SoFCEnableSelectionAction, SoCoordinateElement);
258 SO_ENABLE(SoFCEnableSelectionAction, SoFontNameElement);
259 SO_ENABLE(SoFCEnableSelectionAction, SoFontSizeElement);
260 SO_ENABLE(SoFCEnableSelectionAction, SoProfileCoordinateElement);
261 SO_ENABLE(SoFCEnableSelectionAction, SoProfileElement);
262 SO_ENABLE(SoFCEnableSelectionAction, SoSwitchElement);
263 SO_ENABLE(SoFCEnableSelectionAction, SoUnitsElement);
264 SO_ENABLE(SoFCEnableSelectionAction, SoViewVolumeElement);
265 SO_ENABLE(SoFCEnableSelectionAction, SoViewingMatrixElement);
266 SO_ENABLE(SoFCEnableSelectionAction, SoViewportRegionElement);
267
268
269 SO_ACTION_ADD_METHOD(SoCallback, callDoAction);
270 SO_ACTION_ADD_METHOD(SoComplexity, callDoAction);
271 SO_ACTION_ADD_METHOD(SoCoordinate3, callDoAction);
272 SO_ACTION_ADD_METHOD(SoCoordinate4, callDoAction);
273 SO_ACTION_ADD_METHOD(SoFont, callDoAction);
274 SO_ACTION_ADD_METHOD(SoGroup, callDoAction);
275 SO_ACTION_ADD_METHOD(SoProfile, callDoAction);
276 SO_ACTION_ADD_METHOD(SoProfileCoordinate2, callDoAction);
277 SO_ACTION_ADD_METHOD(SoProfileCoordinate3, callDoAction);
278 SO_ACTION_ADD_METHOD(SoTransformation, callDoAction);
279 SO_ACTION_ADD_METHOD(SoSwitch, callDoAction);
280
281 SO_ACTION_ADD_METHOD(SoSeparator, callDoAction);
282 SO_ACTION_ADD_METHOD(SoFCSelection, callDoAction);
283 }
284
285 void SoFCEnableSelectionAction::finish()
286 {
287 atexit_cleanup();
288 }
289
290
291 SoFCEnableSelectionAction::SoFCEnableSelectionAction(const SbBool& sel)
292 : enabled(sel)
293 {
294 SO_ACTION_CONSTRUCTOR(SoFCEnableSelectionAction);
295 }
296
297
298 SoFCEnableSelectionAction::~SoFCEnableSelectionAction() = default;
299
300
301 void SoFCEnableSelectionAction::beginTraversal(SoNode* node)
302 {
303 traverse(node);
304 }
305
306 void SoFCEnableSelectionAction::callDoAction(SoAction* action, SoNode* node)
307 {
308 node->doAction(action);
309 }
310
311 // ---------------------------------------------------------------
312
313 SO_ACTION_SOURCE(SoFCEnablePreselectionAction)
314
315 /**
316 * The order of the defined SO_ACTION_ADD_METHOD statements is very important. First the base
317 * classes and afterwards subclasses of them must be listed, otherwise the registered methods
318 * of subclasses will be overridden. For more details see the thread in the Coin3d forum
319 * https://www.coin3d.org/pipermail/coin-discuss/2004-May/004346.html.
320 * This means that \c SoSwitch must be listed after \c SoGroup and \c SoFCSelection after
321 * \c SoSeparator because both classes inherits the others.
322 */
323 void SoFCEnablePreselectionAction::initClass()
324 {
325 SO_ACTION_INIT_CLASS(SoFCEnablePreselectionAction, SoAction);
326
327 SO_ENABLE(SoFCEnablePreselectionAction, SoSwitchElement);
328
329 SO_ACTION_ADD_METHOD(SoNode, nullAction);
330
331 SO_ENABLE(SoFCEnablePreselectionAction, SoModelMatrixElement);
332 SO_ENABLE(SoFCEnablePreselectionAction, SoShapeStyleElement);
333 SO_ENABLE(SoFCEnablePreselectionAction, SoComplexityElement);
334 SO_ENABLE(SoFCEnablePreselectionAction, SoComplexityTypeElement);
335 SO_ENABLE(SoFCEnablePreselectionAction, SoCoordinateElement);
336 SO_ENABLE(SoFCEnablePreselectionAction, SoFontNameElement);
337 SO_ENABLE(SoFCEnablePreselectionAction, SoFontSizeElement);
338 SO_ENABLE(SoFCEnablePreselectionAction, SoProfileCoordinateElement);
339 SO_ENABLE(SoFCEnablePreselectionAction, SoProfileElement);
340 SO_ENABLE(SoFCEnablePreselectionAction, SoSwitchElement);
341 SO_ENABLE(SoFCEnablePreselectionAction, SoUnitsElement);
342 SO_ENABLE(SoFCEnablePreselectionAction, SoViewVolumeElement);
343 SO_ENABLE(SoFCEnablePreselectionAction, SoViewingMatrixElement);
344 SO_ENABLE(SoFCEnablePreselectionAction, SoViewportRegionElement);
345
346
347 SO_ACTION_ADD_METHOD(SoCallback, callDoAction);
348 SO_ACTION_ADD_METHOD(SoComplexity, callDoAction);
349 SO_ACTION_ADD_METHOD(SoCoordinate3, callDoAction);
350 SO_ACTION_ADD_METHOD(SoCoordinate4, callDoAction);
351 SO_ACTION_ADD_METHOD(SoFont, callDoAction);
352 SO_ACTION_ADD_METHOD(SoGroup, callDoAction);
353 SO_ACTION_ADD_METHOD(SoProfile, callDoAction);
354 SO_ACTION_ADD_METHOD(SoProfileCoordinate2, callDoAction);
355 SO_ACTION_ADD_METHOD(SoProfileCoordinate3, callDoAction);
356 SO_ACTION_ADD_METHOD(SoTransformation, callDoAction);
357 SO_ACTION_ADD_METHOD(SoSwitch, callDoAction);
358
359 SO_ACTION_ADD_METHOD(SoSeparator, callDoAction);
360 SO_ACTION_ADD_METHOD(SoFCSelection, callDoAction);
361 }
362
363 void SoFCEnablePreselectionAction::finish()
364 {
365 atexit_cleanup();
366 }
367
368
369 SoFCEnablePreselectionAction::SoFCEnablePreselectionAction(const SbBool& sel)
370 : enabled(sel)
371 {
372 SO_ACTION_CONSTRUCTOR(SoFCEnablePreselectionAction);
373 }
374
375
376 SoFCEnablePreselectionAction::~SoFCEnablePreselectionAction() = default;
377
378
379 void SoFCEnablePreselectionAction::beginTraversal(SoNode* node)
380 {
381 traverse(node);
382 }
383
384 void SoFCEnablePreselectionAction::callDoAction(SoAction* action, SoNode* node)
385 {
386 node->doAction(action);
387 }
388
389 // ---------------------------------------------------------------
390
391 SO_ACTION_SOURCE(SoFCSelectionColorAction)
392
393 /**
394 * The order of the defined SO_ACTION_ADD_METHOD statements is very important. First the base
395 * classes and afterwards subclasses of them must be listed, otherwise the registered methods
396 * of subclasses will be overridden. For more details see the thread in the Coin3d forum
397 * https://www.coin3d.org/pipermail/coin-discuss/2004-May/004346.html.
398 * This means that \c SoSwitch must be listed after \c SoGroup and \c SoFCSelection after
399 * \c SoSeparator because both classes inherits the others.
400 */
401 void SoFCSelectionColorAction::initClass()
402 {
403 SO_ACTION_INIT_CLASS(SoFCSelectionColorAction, SoAction);
404
405 SO_ENABLE(SoFCSelectionColorAction, SoSwitchElement);
406
407 SO_ACTION_ADD_METHOD(SoNode, nullAction);
408
409 SO_ENABLE(SoFCSelectionColorAction, SoModelMatrixElement);
410 SO_ENABLE(SoFCSelectionColorAction, SoShapeStyleElement);
411 SO_ENABLE(SoFCSelectionColorAction, SoComplexityElement);
412 SO_ENABLE(SoFCSelectionColorAction, SoComplexityTypeElement);
413 SO_ENABLE(SoFCSelectionColorAction, SoCoordinateElement);
414 SO_ENABLE(SoFCSelectionColorAction, SoFontNameElement);
415 SO_ENABLE(SoFCSelectionColorAction, SoFontSizeElement);
416 SO_ENABLE(SoFCSelectionColorAction, SoProfileCoordinateElement);
417 SO_ENABLE(SoFCSelectionColorAction, SoProfileElement);
418 SO_ENABLE(SoFCSelectionColorAction, SoSwitchElement);
419 SO_ENABLE(SoFCSelectionColorAction, SoUnitsElement);
420 SO_ENABLE(SoFCSelectionColorAction, SoViewVolumeElement);
421 SO_ENABLE(SoFCSelectionColorAction, SoViewingMatrixElement);
422 SO_ENABLE(SoFCSelectionColorAction, SoViewportRegionElement);
423
424
425 SO_ACTION_ADD_METHOD(SoCallback, callDoAction);
426 SO_ACTION_ADD_METHOD(SoComplexity, callDoAction);
427 SO_ACTION_ADD_METHOD(SoCoordinate3, callDoAction);
428 SO_ACTION_ADD_METHOD(SoCoordinate4, callDoAction);
429 SO_ACTION_ADD_METHOD(SoFont, callDoAction);
430 SO_ACTION_ADD_METHOD(SoGroup, callDoAction);
431 SO_ACTION_ADD_METHOD(SoProfile, callDoAction);
432 SO_ACTION_ADD_METHOD(SoProfileCoordinate2, callDoAction);
433 SO_ACTION_ADD_METHOD(SoProfileCoordinate3, callDoAction);
434 SO_ACTION_ADD_METHOD(SoTransformation, callDoAction);
435 SO_ACTION_ADD_METHOD(SoSwitch, callDoAction);
436
437 SO_ACTION_ADD_METHOD(SoSeparator, callDoAction);
438 SO_ACTION_ADD_METHOD(SoFCSelection, callDoAction);
439 }
440
441 void SoFCSelectionColorAction::finish()
442 {
443 atexit_cleanup();
444 }
445
446
447 SoFCSelectionColorAction::SoFCSelectionColorAction(const SoSFColor& col)
448 : selectionColor(col)
449 {
450 SO_ACTION_CONSTRUCTOR(SoFCSelectionColorAction);
451 }
452
453
454 SoFCSelectionColorAction::~SoFCSelectionColorAction() = default;
455
456
457 void SoFCSelectionColorAction::beginTraversal(SoNode* node)
458 {
459 traverse(node);
460 }
461
462 void SoFCSelectionColorAction::callDoAction(SoAction* action, SoNode* node)
463 {
464 node->doAction(action);
465 }
466
467 // ---------------------------------------------------------------
468
469 SO_ACTION_SOURCE(SoFCHighlightColorAction)
470
471 /**
472 * The order of the defined SO_ACTION_ADD_METHOD statements is very important. First the base
473 * classes and afterwards subclasses of them must be listed, otherwise the registered methods
474 * of subclasses will be overridden. For more details see the thread in the Coin3d forum
475 * https://www.coin3d.org/pipermail/coin-discuss/2004-May/004346.html.
476 * This means that \c SoSwitch must be listed after \c SoGroup and \c SoFCSelection after
477 * \c SoSeparator because both classes inherits the others.
478 */
479 void SoFCHighlightColorAction::initClass()
480 {
481 SO_ACTION_INIT_CLASS(SoFCHighlightColorAction, SoAction);
482
483 SO_ENABLE(SoFCHighlightColorAction, SoSwitchElement);
484
485 SO_ACTION_ADD_METHOD(SoNode, nullAction);
486
487 SO_ENABLE(SoFCHighlightColorAction, SoModelMatrixElement);
488 SO_ENABLE(SoFCHighlightColorAction, SoShapeStyleElement);
489 SO_ENABLE(SoFCHighlightColorAction, SoComplexityElement);
490 SO_ENABLE(SoFCHighlightColorAction, SoComplexityTypeElement);
491 SO_ENABLE(SoFCHighlightColorAction, SoCoordinateElement);
492 SO_ENABLE(SoFCHighlightColorAction, SoFontNameElement);
493 SO_ENABLE(SoFCHighlightColorAction, SoFontSizeElement);
494 SO_ENABLE(SoFCHighlightColorAction, SoProfileCoordinateElement);
495 SO_ENABLE(SoFCHighlightColorAction, SoProfileElement);
496 SO_ENABLE(SoFCHighlightColorAction, SoSwitchElement);
497 SO_ENABLE(SoFCHighlightColorAction, SoUnitsElement);
498 SO_ENABLE(SoFCHighlightColorAction, SoViewVolumeElement);
499 SO_ENABLE(SoFCHighlightColorAction, SoViewingMatrixElement);
500 SO_ENABLE(SoFCHighlightColorAction, SoViewportRegionElement);
501
502
503 SO_ACTION_ADD_METHOD(SoCallback, callDoAction);
504 SO_ACTION_ADD_METHOD(SoComplexity, callDoAction);
505 SO_ACTION_ADD_METHOD(SoCoordinate3, callDoAction);
506 SO_ACTION_ADD_METHOD(SoCoordinate4, callDoAction);
507 SO_ACTION_ADD_METHOD(SoFont, callDoAction);
508 SO_ACTION_ADD_METHOD(SoGroup, callDoAction);
509 SO_ACTION_ADD_METHOD(SoProfile, callDoAction);
510 SO_ACTION_ADD_METHOD(SoProfileCoordinate2, callDoAction);
511 SO_ACTION_ADD_METHOD(SoProfileCoordinate3, callDoAction);
512 SO_ACTION_ADD_METHOD(SoTransformation, callDoAction);
513 SO_ACTION_ADD_METHOD(SoSwitch, callDoAction);
514
515 SO_ACTION_ADD_METHOD(SoSeparator, callDoAction);
516 SO_ACTION_ADD_METHOD(SoFCSelection, callDoAction);
517 }
518
519 void SoFCHighlightColorAction::finish()
520 {
521 atexit_cleanup();
522 }
523
524
525 SoFCHighlightColorAction::SoFCHighlightColorAction(const SoSFColor& col)
526 : highlightColor(col)
527 {
528 SO_ACTION_CONSTRUCTOR(SoFCHighlightColorAction);
529 }
530
531
532 SoFCHighlightColorAction::~SoFCHighlightColorAction() = default;
533
534
535 void SoFCHighlightColorAction::beginTraversal(SoNode* node)
536 {
537 traverse(node);
538 }
539
540 void SoFCHighlightColorAction::callDoAction(SoAction* action, SoNode* node)
541 {
542 node->doAction(action);
543 }
544
545 // ---------------------------------------------------------------
546
547 SO_ACTION_SOURCE(SoFCDocumentAction)
548
549 /**
550 * The order of the defined SO_ACTION_ADD_METHOD statements is very important. First the base
551 * classes and afterwards subclasses of them must be listed, otherwise the registered methods
552 * of subclasses will be overridden. For more details see the thread in the Coin3d forum
553 * https://www.coin3d.org/pipermail/coin-discuss/2004-May/004346.html.
554 * This means that \c SoSwitch must be listed after \c SoGroup and \c SoFCSelection after
555 * \c SoSeparator because both classes inherits the others.
556 */
557 void SoFCDocumentAction::initClass()
558 {
559 SO_ACTION_INIT_CLASS(SoFCDocumentAction, SoAction);
560
561 SO_ENABLE(SoFCDocumentAction, SoSwitchElement);
562
563 SO_ACTION_ADD_METHOD(SoNode, nullAction);
564
565 SO_ENABLE(SoFCDocumentAction, SoModelMatrixElement);
566 SO_ENABLE(SoFCDocumentAction, SoShapeStyleElement);
567 SO_ENABLE(SoFCDocumentAction, SoComplexityElement);
568 SO_ENABLE(SoFCDocumentAction, SoComplexityTypeElement);
569 SO_ENABLE(SoFCDocumentAction, SoCoordinateElement);
570 SO_ENABLE(SoFCDocumentAction, SoFontNameElement);
571 SO_ENABLE(SoFCDocumentAction, SoFontSizeElement);
572 SO_ENABLE(SoFCDocumentAction, SoProfileCoordinateElement);
573 SO_ENABLE(SoFCDocumentAction, SoProfileElement);
574 SO_ENABLE(SoFCDocumentAction, SoSwitchElement);
575 SO_ENABLE(SoFCDocumentAction, SoUnitsElement);
576 SO_ENABLE(SoFCDocumentAction, SoViewVolumeElement);
577 SO_ENABLE(SoFCDocumentAction, SoViewingMatrixElement);
578 SO_ENABLE(SoFCDocumentAction, SoViewportRegionElement);
579
580
581 SO_ACTION_ADD_METHOD(SoCallback, callDoAction);
582 SO_ACTION_ADD_METHOD(SoComplexity, callDoAction);
583 SO_ACTION_ADD_METHOD(SoCoordinate3, callDoAction);
584 SO_ACTION_ADD_METHOD(SoCoordinate4, callDoAction);
585 SO_ACTION_ADD_METHOD(SoFont, callDoAction);
586 SO_ACTION_ADD_METHOD(SoGroup, callDoAction);
587 SO_ACTION_ADD_METHOD(SoProfile, callDoAction);
588 SO_ACTION_ADD_METHOD(SoProfileCoordinate2, callDoAction);
589 SO_ACTION_ADD_METHOD(SoProfileCoordinate3, callDoAction);
590 SO_ACTION_ADD_METHOD(SoTransformation, callDoAction);
591 SO_ACTION_ADD_METHOD(SoSwitch, callDoAction);
592
593 SO_ACTION_ADD_METHOD(SoSeparator, callDoAction);
594 SO_ACTION_ADD_METHOD(SoFCSelection, callDoAction);
595 }
596
597 void SoFCDocumentAction::finish()
598 {
599 atexit_cleanup();
600 }
601
602
603 SoFCDocumentAction::SoFCDocumentAction(const SoSFString& docName)
604 : documentName(docName)
605 {
606 SO_ACTION_CONSTRUCTOR(SoFCDocumentAction);
607 }
608
609
610 SoFCDocumentAction::~SoFCDocumentAction() = default;
611
612
613 void SoFCDocumentAction::beginTraversal(SoNode* node)
614 {
615 traverse(node);
616 }
617
618 void SoFCDocumentAction::callDoAction(SoAction* action, SoNode* node)
619 {
620 node->doAction(action);
621 }
622
623
624 // ---------------------------------------------------------------
625
626 SO_ACTION_SOURCE(SoFCDocumentObjectAction)
627
628 /**
629 * The order of the defined SO_ACTION_ADD_METHOD statements is very important. First the base
630 * classes and afterwards subclasses of them must be listed, otherwise the registered methods
631 * of subclasses will be overridden. For more details see the thread in the Coin3d forum
632 * https://www.coin3d.org/pipermail/coin-discuss/2004-May/004346.html.
633 * This means that \c SoSwitch must be listed after \c SoGroup and \c SoFCSelection after
634 * \c SoSeparator because both classes inherits the others.
635 */
636 void SoFCDocumentObjectAction::initClass()
637 {
638 SO_ACTION_INIT_CLASS(SoFCDocumentObjectAction, SoAction);
639
640 SO_ENABLE(SoFCDocumentObjectAction, SoSwitchElement);
641
642 SO_ACTION_ADD_METHOD(SoNode, nullAction);
643
644 SO_ENABLE(SoFCDocumentObjectAction, SoModelMatrixElement);
645 SO_ENABLE(SoFCDocumentObjectAction, SoShapeStyleElement);
646 SO_ENABLE(SoFCDocumentObjectAction, SoComplexityElement);
647 SO_ENABLE(SoFCDocumentObjectAction, SoComplexityTypeElement);
648 SO_ENABLE(SoFCDocumentObjectAction, SoCoordinateElement);
649 SO_ENABLE(SoFCDocumentObjectAction, SoFontNameElement);
650 SO_ENABLE(SoFCDocumentObjectAction, SoFontSizeElement);
651 SO_ENABLE(SoFCDocumentObjectAction, SoProfileCoordinateElement);
652 SO_ENABLE(SoFCDocumentObjectAction, SoProfileElement);
653 SO_ENABLE(SoFCDocumentObjectAction, SoSwitchElement);
654 SO_ENABLE(SoFCDocumentObjectAction, SoUnitsElement);
655 SO_ENABLE(SoFCDocumentObjectAction, SoViewVolumeElement);
656 SO_ENABLE(SoFCDocumentObjectAction, SoViewingMatrixElement);
657 SO_ENABLE(SoFCDocumentObjectAction, SoViewportRegionElement);
658
659 SO_ACTION_ADD_METHOD(SoCallback, callDoAction);
660 SO_ACTION_ADD_METHOD(SoComplexity, callDoAction);
661 SO_ACTION_ADD_METHOD(SoCoordinate3, callDoAction);
662 SO_ACTION_ADD_METHOD(SoCoordinate4, callDoAction);
663 SO_ACTION_ADD_METHOD(SoFont, callDoAction);
664 SO_ACTION_ADD_METHOD(SoGroup, callDoAction);
665 SO_ACTION_ADD_METHOD(SoProfile, callDoAction);
666 SO_ACTION_ADD_METHOD(SoProfileCoordinate2, callDoAction);
667 SO_ACTION_ADD_METHOD(SoProfileCoordinate3, callDoAction);
668 SO_ACTION_ADD_METHOD(SoTransformation, callDoAction);
669 SO_ACTION_ADD_METHOD(SoSwitch, callDoAction);
670
671 SO_ACTION_ADD_METHOD(SoSeparator, callDoAction);
672 SO_ACTION_ADD_METHOD(SoFCSelection, callDoAction);
673 }
674
675 void SoFCDocumentObjectAction::finish()
676 {
677 atexit_cleanup();
678 }
679
680 SoFCDocumentObjectAction::SoFCDocumentObjectAction()
681 {
682 SO_ACTION_CONSTRUCTOR(SoFCDocumentObjectAction);
683 }
684
685 SoFCDocumentObjectAction::~SoFCDocumentObjectAction() = default;
686
687 void SoFCDocumentObjectAction::beginTraversal(SoNode* node)
688 {
689 traverse(node);
690 }
691
692 void SoFCDocumentObjectAction::callDoAction(SoAction* action, SoNode* node)
693 {
694 node->doAction(action);
695 }
696
697 void SoFCDocumentObjectAction::setHandled()
698 {
699 this->_handled = true;
700 }
701
702 SbBool SoFCDocumentObjectAction::isHandled() const
703 {
704 return this->_handled;
705 }
706
707 // ---------------------------------------------------------------
708
709 SO_ACTION_SOURCE(SoGLSelectAction)
710
711 /**
712 * The order of the defined SO_ACTION_ADD_METHOD statements is very important. First the base
713 * classes and afterwards subclasses of them must be listed, otherwise the registered methods
714 * of subclasses will be overridden. For more details see the thread in the Coin3d forum
715 * https://www.coin3d.org/pipermail/coin-discuss/2004-May/004346.html.
716 * This means that \c SoSwitch must be listed after \c SoGroup and \c SoFCSelection after
717 * \c SoSeparator because both classes inherits the others.
718 */
719 void SoGLSelectAction::initClass()
720 {
721 SO_ACTION_INIT_CLASS(SoGLSelectAction, SoAction);
722
723 SO_ENABLE(SoGLSelectAction, SoSwitchElement);
724
725 SO_ACTION_ADD_METHOD(SoNode, nullAction);
726
727 SO_ENABLE(SoGLSelectAction, SoModelMatrixElement);
728 SO_ENABLE(SoGLSelectAction, SoProjectionMatrixElement);
729 SO_ENABLE(SoGLSelectAction, SoCoordinateElement);
730 SO_ENABLE(SoGLSelectAction, SoViewVolumeElement);
731 SO_ENABLE(SoGLSelectAction, SoViewingMatrixElement);
732 SO_ENABLE(SoGLSelectAction, SoViewportRegionElement);
733
734 SO_ACTION_ADD_METHOD(SoCamera, callDoAction);
735 SO_ACTION_ADD_METHOD(SoCoordinate3, callDoAction);
736 SO_ACTION_ADD_METHOD(SoCoordinate4, callDoAction);
737 SO_ACTION_ADD_METHOD(SoGroup, callDoAction);
738 SO_ACTION_ADD_METHOD(SoSwitch, callDoAction);
739 SO_ACTION_ADD_METHOD(SoShape, callDoAction);
740 SO_ACTION_ADD_METHOD(SoIndexedFaceSet, callDoAction);
741
742 SO_ACTION_ADD_METHOD(SoSeparator, callDoAction);
743 SO_ACTION_ADD_METHOD(SoFCSelection, callDoAction);
744 }
745
746 SoGLSelectAction::SoGLSelectAction(const SbViewportRegion& region, const SbViewportRegion& select)
747 : vpregion(region)
748 , vpselect(select)
749 {
750 SO_ACTION_CONSTRUCTOR(SoGLSelectAction);
751 }
752
753 SoGLSelectAction::~SoGLSelectAction() = default;
754
755 const SbViewportRegion& SoGLSelectAction::getViewportRegion() const
756 {
757 return this->vpselect;
758 }
759
760 void SoGLSelectAction::beginTraversal(SoNode* node)
761 {
762 SoViewportRegionElement::set(this->getState(), this->vpregion);
763 traverse(node);
764 }
765
766 void SoGLSelectAction::callDoAction(SoAction* action, SoNode* node)
767 {
768 node->doAction(action);
769 }
770
771 void SoGLSelectAction::setHandled()
772 {
773 this->_handled = true;
774 }
775
776 SbBool SoGLSelectAction::isHandled() const
777 {
778 return this->_handled;
779 }
780
781 // ---------------------------------------------------------------
782
783 SO_ACTION_SOURCE(SoVisibleFaceAction)
784
785 /**
786 * The order of the defined SO_ACTION_ADD_METHOD statements is very important. First the base
787 * classes and afterwards subclasses of them must be listed, otherwise the registered methods
788 * of subclasses will be overridden. For more details see the thread in the Coin3d forum
789 * https://www.coin3d.org/pipermail/coin-discuss/2004-May/004346.html.
790 * This means that \c SoSwitch must be listed after \c SoGroup and \c SoFCSelection after
791 * \c SoSeparator because both classes inherits the others.
792 */
793 void SoVisibleFaceAction::initClass()
794 {
795 SO_ACTION_INIT_CLASS(SoVisibleFaceAction, SoAction);
796
797 SO_ENABLE(SoVisibleFaceAction, SoSwitchElement);
798
799 SO_ACTION_ADD_METHOD(SoNode, nullAction);
800
801 SO_ENABLE(SoVisibleFaceAction, SoModelMatrixElement);
802 SO_ENABLE(SoVisibleFaceAction, SoProjectionMatrixElement);
803 SO_ENABLE(SoVisibleFaceAction, SoCoordinateElement);
804 SO_ENABLE(SoVisibleFaceAction, SoViewVolumeElement);
805 SO_ENABLE(SoVisibleFaceAction, SoViewingMatrixElement);
806 SO_ENABLE(SoVisibleFaceAction, SoViewportRegionElement);
807
808
809 SO_ACTION_ADD_METHOD(SoCamera, callDoAction);
810 SO_ACTION_ADD_METHOD(SoCoordinate3, callDoAction);
811 SO_ACTION_ADD_METHOD(SoCoordinate4, callDoAction);
812 SO_ACTION_ADD_METHOD(SoGroup, callDoAction);
813 SO_ACTION_ADD_METHOD(SoSwitch, callDoAction);
814 SO_ACTION_ADD_METHOD(SoShape, callDoAction);
815 SO_ACTION_ADD_METHOD(SoIndexedFaceSet, callDoAction);
816
817 SO_ACTION_ADD_METHOD(SoSeparator, callDoAction);
818 SO_ACTION_ADD_METHOD(SoFCSelection, callDoAction);
819 }
820
821 SoVisibleFaceAction::SoVisibleFaceAction()
822 {
823 SO_ACTION_CONSTRUCTOR(SoVisibleFaceAction);
824 }
825
826 SoVisibleFaceAction::~SoVisibleFaceAction() = default;
827
828 void SoVisibleFaceAction::beginTraversal(SoNode* node)
829 {
830 traverse(node);
831 }
832
833 void SoVisibleFaceAction::callDoAction(SoAction* action, SoNode* node)
834 {
835 node->doAction(action);
836 }
837
838 void SoVisibleFaceAction::setHandled()
839 {
840 this->_handled = true;
841 }
842
843 SbBool SoVisibleFaceAction::isHandled() const
844 {
845 return this->_handled;
846 }
847
848 // ---------------------------------------------------------------
849
850
851 SO_ACTION_SOURCE(SoUpdateVBOAction)
852
853 /**
854 * The order of the defined SO_ACTION_ADD_METHOD statements is very important. First the base
855 * classes and afterwards subclasses of them must be listed, otherwise the registered methods
856 * of subclasses will be overridden. For more details see the thread in the Coin3d forum
857 * https://www.coin3d.org/pipermail/coin-discuss/2004-May/004346.html.
858 * This means that \c SoSwitch must be listed after \c SoGroup and \c SoFCSelection after
859 * \c SoSeparator because both classes inherits the others.
860 */
861 void SoUpdateVBOAction::initClass()
862 {
863 SO_ACTION_INIT_CLASS(SoUpdateVBOAction, SoAction);
864
865 SO_ENABLE(SoUpdateVBOAction, SoSwitchElement);
866
867 SO_ACTION_ADD_METHOD(SoNode, nullAction);
868
869 SO_ENABLE(SoUpdateVBOAction, SoModelMatrixElement);
870 SO_ENABLE(SoUpdateVBOAction, SoProjectionMatrixElement);
871 SO_ENABLE(SoUpdateVBOAction, SoCoordinateElement);
872 SO_ENABLE(SoUpdateVBOAction, SoViewVolumeElement);
873 SO_ENABLE(SoUpdateVBOAction, SoViewingMatrixElement);
874 SO_ENABLE(SoUpdateVBOAction, SoViewportRegionElement);
875
876
877 SO_ACTION_ADD_METHOD(SoCamera, callDoAction);
878 SO_ACTION_ADD_METHOD(SoCoordinate3, callDoAction);
879 SO_ACTION_ADD_METHOD(SoCoordinate4, callDoAction);
880 SO_ACTION_ADD_METHOD(SoGroup, callDoAction);
881 SO_ACTION_ADD_METHOD(SoSwitch, callDoAction);
882 SO_ACTION_ADD_METHOD(SoShape, callDoAction);
883 SO_ACTION_ADD_METHOD(SoIndexedFaceSet, callDoAction);
884
885 SO_ACTION_ADD_METHOD(SoSeparator, callDoAction);
886 SO_ACTION_ADD_METHOD(SoFCSelection, callDoAction);
887 }
888
889 SoUpdateVBOAction::SoUpdateVBOAction()
890 {
891 SO_ACTION_CONSTRUCTOR(SoUpdateVBOAction);
892 }
893
894 SoUpdateVBOAction::~SoUpdateVBOAction() = default;
895
896 void SoUpdateVBOAction::finish()
897 {
898 atexit_cleanup();
899 }
900
901 void SoUpdateVBOAction::beginTraversal(SoNode* node)
902 {
903 traverse(node);
904 }
905
906 void SoUpdateVBOAction::callDoAction(SoAction* action, SoNode* node)
907 {
908 node->doAction(action);
909 }
910
911 // ---------------------------------------------------------------
912
913 namespace Gui
914 {
915 class SoBoxSelectionRenderActionP
916 {
917 public:
918 SoBoxSelectionRenderActionP(SoBoxSelectionRenderAction* master)
919 : master(master)
920 {}
921
922 SoBoxSelectionRenderAction* master;
923 SoSearchAction* searchaction {nullptr};
924 SoSearchAction* selectsearch {nullptr};
925 SoSearchAction* camerasearch {nullptr};
926 SoGetBoundingBoxAction* bboxaction {nullptr};
927 SoBaseColor* basecolor {nullptr};
928 SoTempPath* postprocpath {nullptr};
929 SoPath* highlightPath {nullptr};
930 SoSeparator* localRoot {nullptr};
931 SoMatrixTransform* xform {nullptr};
932 SoCube* cube {nullptr};
933 SoDrawStyle* drawstyle {nullptr};
934 SoColorPacker colorpacker;
935
936 void initBoxGraph();
937 void updateBbox(const SoPath* path);
938 };
939
940 } // namespace Gui
941
942 #undef PRIVATE
943 #define PRIVATE(p) ((p)->pimpl)
944 #undef PUBLIC
945 #define PUBLIC(p) ((p)->master)
946
947 // used to initialize the internal storage class with variables
948 void SoBoxSelectionRenderActionP::initBoxGraph()
949 {
950 this->localRoot = new SoSeparator;
951 this->localRoot->ref();
952 this->localRoot->renderCaching = SoSeparator::OFF;
953 this->localRoot->boundingBoxCaching = SoSeparator::OFF;
954
955 this->xform = new SoMatrixTransform;
956 this->cube = new SoCube;
957
958 this->drawstyle = new SoDrawStyle;
959 this->drawstyle->style = SoDrawStyleElement::LINES;
960 this->basecolor = new SoBaseColor;
961
962 auto lightmodel = new SoLightModel;
963 lightmodel->model = SoLightModel::BASE_COLOR;
964
965 auto complexity = new SoComplexity;
966 complexity->textureQuality = 0.0f;
967 complexity->type = SoComplexityTypeElement::BOUNDING_BOX;
968
969 this->localRoot->addChild(this->drawstyle);
970 this->localRoot->addChild(this->basecolor);
971
972 this->localRoot->addChild(lightmodel);
973 this->localRoot->addChild(complexity);
974
975 this->localRoot->addChild(this->xform);
976 this->localRoot->addChild(this->cube);
977 }
978
979
980 // used to render shape and non-shape nodes (usually SoGroup or SoSeparator).
981 void SoBoxSelectionRenderActionP::updateBbox(const SoPath* path)
982 {
983 if (!this->camerasearch) {
984 this->camerasearch = new SoSearchAction;
985 }
986
987 // find camera used to render node
988 this->camerasearch->setFind(SoSearchAction::TYPE);
989 this->camerasearch->setInterest(SoSearchAction::LAST);
990 this->camerasearch->setType(SoCamera::getClassTypeId());
991 this->camerasearch->apply(const_cast<SoPath*>(path));
992
993 if (!this->camerasearch->getPath()) {
994 // if there is no camera there is no point rendering the bbox
995 return;
996 }
997 this->localRoot->insertChild(this->camerasearch->getPath()->getTail(), 0);
998 this->camerasearch->reset();
999
1000 if (!this->bboxaction) {
1001 this->bboxaction = new SoGetBoundingBoxAction(SbViewportRegion(100, 100));
1002 }
1003 this->bboxaction->setViewportRegion(PUBLIC(this)->getViewportRegion());
1004 this->bboxaction->apply(const_cast<SoPath*>(path));
1005
1006 SbXfBox3f& box = this->bboxaction->getXfBoundingBox();
1007
1008 if (!box.isEmpty()) {
1009 // set cube size
1010 float x, y, z;
1011 box.getSize(x, y, z);
1012 this->cube->width = x;
1013 this->cube->height = y;
1014 this->cube->depth = z;
1015
1016 SbMatrix transform = box.getTransform(); // clazy:exclude=rule-of-two-soft
1017
1018 // get center (in the local bbox coordinate system)
1019 SbVec3f center = box.SbBox3f::getCenter();
1020
1021 // if center != (0,0,0), move the cube
1022 if (center != SbVec3f(0.0f, 0.0f, 0.0f)) {
1023 SbMatrix t;
1024 t.setTranslate(center);
1025 transform.multLeft(t);
1026 }
1027 this->xform->matrix = transform;
1028
1029 PUBLIC(this)->SoGLRenderAction::apply(this->localRoot);
1030 }
1031 // remove camera
1032 this->localRoot->removeChild(0);
1033 }
1034
1035 SO_ACTION_SOURCE(SoBoxSelectionRenderAction)
1036
1037 // Overridden from parent class.
1038 void SoBoxSelectionRenderAction::initClass()
1039 {
1040 SO_ACTION_INIT_CLASS(SoBoxSelectionRenderAction, SoGLRenderAction);
1041 }
1042
1043 SoBoxSelectionRenderAction::SoBoxSelectionRenderAction()
1044 : inherited(SbViewportRegion())
1045 {
1046 this->constructorCommon();
1047 }
1048
1049 SoBoxSelectionRenderAction::SoBoxSelectionRenderAction(const SbViewportRegion& viewportregion)
1050 : inherited(viewportregion)
1051 {
1052 this->constructorCommon();
1053 }
1054
1055 //
1056 // private. called by both constructors
1057 //
1058 void SoBoxSelectionRenderAction::constructorCommon()
1059 {
1060 SO_ACTION_CONSTRUCTOR(SoBoxSelectionRenderAction);
1061
1062 PRIVATE(this) = new SoBoxSelectionRenderActionP(this);
1063
1064 // Initialize local variables
1065 PRIVATE(this)->initBoxGraph();
1066
1067 this->hlVisible = false;
1068
1069 PRIVATE(this)->basecolor->rgb.setValue(1.0f, 0.0f, 0.0f);
1070 PRIVATE(this)->drawstyle->linePattern = 0xffff;
1071 PRIVATE(this)->drawstyle->lineWidth = 1.0f;
1072 PRIVATE(this)->searchaction = nullptr;
1073 PRIVATE(this)->selectsearch = nullptr;
1074 PRIVATE(this)->camerasearch = nullptr;
1075 PRIVATE(this)->bboxaction = nullptr;
1076
1077 // SoBase-derived objects should be dynamically allocated.
1078 PRIVATE(this)->postprocpath = new SoTempPath(32);
1079 PRIVATE(this)->postprocpath->ref();
1080 PRIVATE(this)->highlightPath = nullptr;
1081 }
1082
1083 SoBoxSelectionRenderAction::~SoBoxSelectionRenderAction()
1084 {
1085 // clear highlighting node
1086 if (PRIVATE(this)->highlightPath) {
1087 PRIVATE(this)->highlightPath->unref();
1088 }
1089 PRIVATE(this)->postprocpath->unref();
1090 PRIVATE(this)->localRoot->unref();
1091
1092 delete PRIVATE(this)->searchaction;
1093 delete PRIVATE(this)->selectsearch;
1094 delete PRIVATE(this)->camerasearch;
1095 delete PRIVATE(this)->bboxaction;
1096 delete PRIVATE(this);
1097 }
1098
1099 void SoBoxSelectionRenderAction::apply(SoNode* node)
1100 {
1101 SoGLRenderAction::apply(node);
1102 if (this->hlVisible) {
1103 if (!PRIVATE(this)->searchaction) {
1104 PRIVATE(this)->searchaction = new SoSearchAction;
1105 }
1106 PRIVATE(this)->searchaction->setType(SoFCSelection::getClassTypeId());
1107 PRIVATE(this)->searchaction->setInterest(SoSearchAction::ALL);
1108 PRIVATE(this)->searchaction->apply(node);
1109 const SoPathList& pathlist = PRIVATE(this)->searchaction->getPaths();
1110 if (pathlist.getLength() > 0) {
1111 for (int i = 0; i < pathlist.getLength(); i++) {
1112 SoPath* path = pathlist[i];
1113 assert(path);
1114 auto selection = static_cast<SoFCSelection*>(path->getTail());
1115 assert(selection->getTypeId().isDerivedFrom(SoFCSelection::getClassTypeId()));
1116 if (selection->selected.getValue()
1117 && selection->style.getValue() == SoFCSelection::BOX) {
1118 PRIVATE(this)->basecolor->rgb.setValue(selection->colorSelection.getValue());
1119 if (!PRIVATE(this)->selectsearch) {
1120 PRIVATE(this)->selectsearch = new SoSearchAction;
1121 }
1122 PRIVATE(this)->selectsearch->setType(SoShape::getClassTypeId());
1123 PRIVATE(this)->selectsearch->setInterest(SoSearchAction::FIRST);
1124 PRIVATE(this)->selectsearch->apply(selection);
1125 SoPath* shapepath = PRIVATE(this)->selectsearch->getPath();
1126 if (shapepath) {
1127 SoPathList list;
1128 list.append(shapepath);
1129 this->drawBoxes(path, &list);
1130 }
1131 PRIVATE(this)->selectsearch->reset();
1132 }
1133 else if (selection->isHighlighted()
1134 && selection->selected.getValue() == SoFCSelection::NOTSELECTED
1135 && selection->style.getValue() == SoFCSelection::BOX) {
1136 PRIVATE(this)->basecolor->rgb.setValue(selection->colorHighlight.getValue());
1137
1138 if (!PRIVATE(this)->selectsearch) {
1139 PRIVATE(this)->selectsearch = new SoSearchAction;
1140 }
1141 PRIVATE(this)->selectsearch->setType(SoShape::getClassTypeId());
1142 PRIVATE(this)->selectsearch->setInterest(SoSearchAction::FIRST);
1143 PRIVATE(this)->selectsearch->apply(selection);
1144 SoPath* shapepath = PRIVATE(this)->selectsearch->getPath();
1145 if (shapepath) {
1146 SoPathList list;
1147 list.append(shapepath);
1148 // clear old highlighting node if still active
1149 if (PRIVATE(this)->highlightPath) {
1150 PRIVATE(this)->highlightPath->unref();
1151 }
1152 PRIVATE(this)->highlightPath = path;
1153 PRIVATE(this)->highlightPath->ref();
1154 this->drawBoxes(path, &list);
1155 }
1156 PRIVATE(this)->selectsearch->reset();
1157 }
1158 }
1159 }
1160 PRIVATE(this)->searchaction->reset();
1161 }
1162 }
1163
1164 void SoBoxSelectionRenderAction::apply(SoPath* path)
1165 {
1166 SoGLRenderAction::apply(path);
1167 SoNode* node = path->getTail();
1168 if (node && node->getTypeId() == SoFCSelection::getClassTypeId()) {
1169 auto selection = static_cast<SoFCSelection*>(node);
1170
1171 // This happens when dehighlighting the current shape
1172 if (PRIVATE(this)->highlightPath == path) {
1173 PRIVATE(this)->highlightPath->unref();
1174 PRIVATE(this)->highlightPath = nullptr;
1175 // FIXME: Doing a redraw to remove the shown bounding box causes
1176 // some problems when moving the mouse from one shape to another
1177 // because this will destroy the box immediately
1178 selection->touch(); // force a redraw when dehighlighting
1179 }
1180 else if (selection->isHighlighted()
1181 && selection->selected.getValue() == SoFCSelection::NOTSELECTED
1182 && selection->style.getValue() == SoFCSelection::BOX) {
1183 PRIVATE(this)->basecolor->rgb.setValue(selection->colorHighlight.getValue());
1184
1185 if (!PRIVATE(this)->selectsearch) {
1186 PRIVATE(this)->selectsearch = new SoSearchAction;
1187 }
1188 PRIVATE(this)->selectsearch->setType(SoShape::getClassTypeId());
1189 PRIVATE(this)->selectsearch->setInterest(SoSearchAction::FIRST);
1190 PRIVATE(this)->selectsearch->apply(selection);
1191 SoPath* shapepath = PRIVATE(this)->selectsearch->getPath();
1192 if (shapepath) {
1193 SoPathList list;
1194 list.append(shapepath);
1195 // clear old highlighting node if still active
1196 if (PRIVATE(this)->highlightPath) {
1197 PRIVATE(this)->highlightPath->unref();
1198 }
1199 PRIVATE(this)->highlightPath = path;
1200 PRIVATE(this)->highlightPath->ref();
1201 this->drawBoxes(path, &list);
1202 }
1203 PRIVATE(this)->selectsearch->reset();
1204 }
1205 }
1206 }
1207
1208 void SoBoxSelectionRenderAction::apply(const SoPathList& pathlist, SbBool obeysrules)
1209 {
1210 SoGLRenderAction::apply(pathlist, obeysrules);
1211 }
1212
1213 void SoBoxSelectionRenderAction::setColor(const SbColor& color)
1214 {
1215 PRIVATE(this)->basecolor->rgb = color;
1216 }
1217
1218 const SbColor& SoBoxSelectionRenderAction::getColor()
1219 {
1220 return PRIVATE(this)->basecolor->rgb[0];
1221 }
1222
1223 void SoBoxSelectionRenderAction::setLinePattern(unsigned short pattern)
1224 {
1225 PRIVATE(this)->drawstyle->linePattern = pattern;
1226 }
1227
1228 unsigned short SoBoxSelectionRenderAction::getLinePattern() const
1229 {
1230 return PRIVATE(this)->drawstyle->linePattern.getValue();
1231 }
1232
1233 void SoBoxSelectionRenderAction::setLineWidth(const float width)
1234 {
1235 PRIVATE(this)->drawstyle->lineWidth = width;
1236 }
1237
1238 float SoBoxSelectionRenderAction::getLineWidth() const
1239 {
1240 return PRIVATE(this)->drawstyle->lineWidth.getValue();
1241 }
1242
1243 void SoBoxSelectionRenderAction::drawBoxes(SoPath* pathtothis, const SoPathList* pathlist)
1244 {
1245 int i;
1246 int thispos = static_cast<SoFullPath*>(pathtothis)->getLength() - 1;
1247 assert(thispos >= 0);
1248 PRIVATE(this)->postprocpath->truncate(0); // reset
1249
1250 for (i = 0; i < thispos; i++) {
1251 PRIVATE(this)->postprocpath->append(pathtothis->getNode(i));
1252 }
1253
1254 // we need to disable accumulation buffer antialiasing while
1255 // rendering selected objects
1256 int oldnumpasses = this->getNumPasses();
1257 this->setNumPasses(1);
1258
1259 SoState* thestate = this->getState();
1260 thestate->push();
1261
1262 for (i = 0; i < pathlist->getLength(); i++) {
1263 auto path = static_cast<SoFullPath*>((*pathlist)[i]);
1264
1265 for (int j = 0; j < path->getLength(); j++) {
1266 PRIVATE(this)->postprocpath->append(path->getNode(j));
1267 }
1268
1269 // Previously SoGLRenderAction was used to draw the bounding boxes
1270 // of shapes in selection paths, by overriding renderstyle state
1271 // elements to lines drawstyle and simply doing:
1272 //
1273 // SoGLRenderAction::apply(PRIVATE(this)->postprocpath); // Bug
1274 //
1275 // This could have the unwanted side effect of rendering
1276 // non-selected shapes, as they could be part of the path (due to
1277 // being placed below SoGroup nodes (instead of SoSeparator
1278 // nodes)) up to the selected shape.
1279 //
1280 //
1281 // A better approach turned out to be to soup up and draw only the
1282 // bounding boxes of the selected shapes:
1283 PRIVATE(this)->updateBbox(PRIVATE(this)->postprocpath);
1284
1285 // Remove temporary path from path buffer
1286 PRIVATE(this)->postprocpath->truncate(thispos);
1287 }
1288
1289 this->setNumPasses(oldnumpasses);
1290 thestate->pop();
1291 }
1292
1293
1294 #undef PRIVATE
1295 #undef PUBLIC