| 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 |
#include <FCConfig.h> |
| 25 |
|
| 26 |
#include <Inventor/SoFullPath.h> |
| 27 |
#include <Inventor/SoPickedPoint.h> |
| 28 |
#include <Inventor/actions/SoCallbackAction.h> |
| 29 |
#include <Inventor/actions/SoGetBoundingBoxAction.h> |
| 30 |
#include <Inventor/actions/SoGetPrimitiveCountAction.h> |
| 31 |
#include <Inventor/actions/SoGLRenderAction.h> |
| 32 |
#include <Inventor/actions/SoHandleEventAction.h> |
| 33 |
#include <Inventor/actions/SoWriteAction.h> |
| 34 |
#include <Inventor/bundles/SoMaterialBundle.h> |
| 35 |
#include <Inventor/details/SoFaceDetail.h> |
| 36 |
#include <Inventor/details/SoLineDetail.h> |
| 37 |
#include <Inventor/elements/SoCacheElement.h> |
| 38 |
#include <Inventor/elements/SoCoordinateElement.h> |
| 39 |
#include <Inventor/elements/SoDrawStyleElement.h> |
| 40 |
#include <Inventor/elements/SoGLCacheContextElement.h> |
| 41 |
#include <Inventor/elements/SoLazyElement.h> |
| 42 |
#include <Inventor/elements/SoLineWidthElement.h> |
| 43 |
#include <Inventor/elements/SoMaterialBindingElement.h> |
| 44 |
#include <Inventor/elements/SoModelMatrixElement.h> |
| 45 |
#include <Inventor/elements/SoOverrideElement.h> |
| 46 |
#include <Inventor/elements/SoShapeStyleElement.h> |
| 47 |
#include <Inventor/elements/SoSwitchElement.h> |
| 48 |
#include <Inventor/elements/SoTextureEnabledElement.h> |
| 49 |
#include <Inventor/events/SoLocation2Event.h> |
| 50 |
#include <Inventor/events/SoMouseButtonEvent.h> |
| 51 |
#include <Inventor/misc/SoChildList.h> |
| 52 |
#include <Inventor/misc/SoState.h> |
| 53 |
#include <Inventor/nodes/SoCoordinate3.h> |
| 54 |
#include <Inventor/nodes/SoCube.h> |
| 55 |
#include <Inventor/nodes/SoIndexedFaceSet.h> |
| 56 |
#include <Inventor/nodes/SoIndexedLineSet.h> |
| 57 |
#include <Inventor/nodes/SoMaterial.h> |
| 58 |
#include <Inventor/nodes/SoMaterialBinding.h> |
| 59 |
#include <Inventor/nodes/SoNormalBinding.h> |
| 60 |
#include <Inventor/nodes/SoPointSet.h> |
| 61 |
#include <Inventor/threads/SbStorage.h> |
| 62 |
|
| 63 |
|
| 64 |
#ifdef FC_OS_MACOSX |
| 65 |
# include <OpenGL/gl.h> |
| 66 |
#else |
| 67 |
# ifdef FC_OS_WIN32 |
| 68 |
# include <windows.h> |
| 69 |
# endif |
| 70 |
# include <GL/gl.h> |
| 71 |
#endif |
| 72 |
|
| 73 |
#include <QOpenGLWidget> |
| 74 |
|
| 75 |
#include <App/Document.h> |
| 76 |
#include <App/GeoFeature.h> |
| 77 |
#include <App/ElementNamingUtils.h> |
| 78 |
#include <Base/Tools.h> |
| 79 |
#include <Base/UnitsApi.h> |
| 80 |
|
| 81 |
#include "SoFCUnifiedSelection.h" |
| 82 |
#include "Application.h" |
| 83 |
#include "Document.h" |
| 84 |
#include "DocumentObserver.h" |
| 85 |
#include "MainWindow.h" |
| 86 |
#include "SoFCInteractiveElement.h" |
| 87 |
#include "SoFCSelectionAction.h" |
| 88 |
#include "ViewParams.h" |
| 89 |
#include "ViewProvider.h" |
| 90 |
#include "ViewProviderDocumentObject.h" |
| 91 |
|
| 92 |
|
| 93 |
FC_LOG_LEVEL_INIT("SoFCUnifiedSelection", false, true, true) |
| 94 |
|
| 95 |
using namespace Gui; |
| 96 |
|
| 97 |
namespace Gui |
| 98 |
{ |
| 99 |
void printPreselectionInfo( |
| 100 |
const char* documentName, |
| 101 |
const char* objectName, |
| 102 |
const char* subElementName, |
| 103 |
float x, |
| 104 |
float y, |
| 105 |
float z, |
| 106 |
double precision |
| 107 |
); |
| 108 |
} |
| 109 |
|
| 110 |
SoFullPath* Gui::SoFCUnifiedSelection::currentHighlightPath = nullptr; |
| 111 |
|
| 112 |
// ************************************************************************* |
| 113 |
|
| 114 |
SO_NODE_SOURCE(SoFCUnifiedSelection) |
| 115 |
|
| 116 |
/*! |
| 117 |
Constructor. |
| 118 |
*/ |
| 119 |
SoFCUnifiedSelection::SoFCUnifiedSelection() |
| 120 |
{ |
| 121 |
SO_NODE_CONSTRUCTOR(SoFCUnifiedSelection); |
| 122 |
|
| 123 |
SO_NODE_ADD_FIELD(colorHighlight, (SbColor(1.0f, 0.6f, 0.0f))); |
| 124 |
SO_NODE_ADD_FIELD(colorSelection, (SbColor(0.1f, 0.8f, 0.1f))); |
| 125 |
SO_NODE_ADD_FIELD(preselectionMode, (AUTO)); |
| 126 |
SO_NODE_ADD_FIELD(selectionMode, (ON)); |
| 127 |
SO_NODE_ADD_FIELD(selectionEnabled, (true)); |
| 128 |
SO_NODE_ADD_FIELD(useNewSelection, (true)); |
| 129 |
|
| 130 |
SO_NODE_DEFINE_ENUM_VALUE(PreselectionModes, AUTO); |
| 131 |
SO_NODE_DEFINE_ENUM_VALUE(PreselectionModes, ON); |
| 132 |
SO_NODE_DEFINE_ENUM_VALUE(PreselectionModes, OFF); |
| 133 |
SO_NODE_SET_SF_ENUM_TYPE(preselectionMode, PreselectionModes); |
| 134 |
|
| 135 |
// Documentation of SoFullPath: |
| 136 |
// Since the SoFullPath is derived from SoPath and contains no private data, you can cast SoPath |
| 137 |
// instances to the SoFullPath type. This will allow you to examine hidden children. Actually, |
| 138 |
// you are not supposed to allocate instances of this class at all. It is only available as an |
| 139 |
// "extended interface" into the superclass SoPath. |
| 140 |
detailPath = static_cast<SoFullPath*>(new SoPath(20)); |
| 141 |
detailPath->ref(); |
| 142 |
|
| 143 |
setPreSelection = false; |
| 144 |
preSelection = -1; |
| 145 |
useNewSelection = ViewParams::instance()->getUseNewSelection(); |
| 146 |
} |
| 147 |
|
| 148 |
/*! |
| 149 |
Destructor. |
| 150 |
*/ |
| 151 |
SoFCUnifiedSelection::~SoFCUnifiedSelection() |
| 152 |
{ |
| 153 |
// If we're being deleted and we're the current highlight, |
| 154 |
// NULL out that variable |
| 155 |
if (currentHighlightPath) { |
| 156 |
currentHighlightPath->unref(); |
| 157 |
currentHighlightPath = nullptr; |
| 158 |
} |
| 159 |
if (detailPath) { |
| 160 |
detailPath->unref(); |
| 161 |
detailPath = nullptr; |
| 162 |
} |
| 163 |
} |
| 164 |
|
| 165 |
// doc from parent |
| 166 |
void SoFCUnifiedSelection::initClass() |
| 167 |
{ |
| 168 |
SO_NODE_INIT_CLASS(SoFCUnifiedSelection, SoSeparator, "Separator"); |
| 169 |
} |
| 170 |
|
| 171 |
void SoFCUnifiedSelection::finish() |
| 172 |
{ |
| 173 |
atexit_cleanup(); |
| 174 |
} |
| 175 |
|
| 176 |
bool SoFCUnifiedSelection::hasHighlight() |
| 177 |
{ |
| 178 |
return currentHighlightPath != nullptr; |
| 179 |
} |
| 180 |
|
| 181 |
void SoFCUnifiedSelection::applySettings() |
| 182 |
{ |
| 183 |
float transparency; |
| 184 |
ParameterGrp::handle hGrp = Gui::WindowParameter::getDefaultParameter()->GetGroup("View"); |
| 185 |
bool enablePreselection = hGrp->GetBool("EnablePreselection", true); |
| 186 |
if (!enablePreselection) { |
| 187 |
this->preselectionMode = SoFCUnifiedSelection::OFF; |
| 188 |
} |
| 189 |
else { |
| 190 |
// Search for a user defined value with the current color as default |
| 191 |
SbColor highlightColor = this->colorHighlight.getValue(); |
| 192 |
auto highlight = (unsigned long)(highlightColor.getPackedValue()); |
| 193 |
highlight = hGrp->GetUnsigned("HighlightColor", highlight); |
| 194 |
highlightColor.setPackedValue((uint32_t)highlight, transparency); |
| 195 |
this->colorHighlight.setValue(highlightColor); |
| 196 |
} |
| 197 |
|
| 198 |
bool enableSelection = hGrp->GetBool("EnableSelection", true); |
| 199 |
if (!enableSelection) { |
| 200 |
this->selectionMode = SoFCUnifiedSelection::OFF; |
| 201 |
} |
| 202 |
else { |
| 203 |
// Do the same with the selection color |
| 204 |
SbColor selectionColor = this->colorSelection.getValue(); |
| 205 |
auto selection = (unsigned long)(selectionColor.getPackedValue()); |
| 206 |
selection = hGrp->GetUnsigned("SelectionColor", selection); |
| 207 |
selectionColor.setPackedValue((uint32_t)selection, transparency); |
| 208 |
this->colorSelection.setValue(selectionColor); |
| 209 |
} |
| 210 |
} |
| 211 |
|
| 212 |
const char* SoFCUnifiedSelection::getFileFormatName() const |
| 213 |
{ |
| 214 |
return "Separator"; |
| 215 |
} |
| 216 |
|
| 217 |
void SoFCUnifiedSelection::write(SoWriteAction* action) |
| 218 |
{ |
| 219 |
SoOutput* out = action->getOutput(); |
| 220 |
if (out->getStage() == SoOutput::WRITE) { |
| 221 |
// Do not write out the fields of this class |
| 222 |
if (this->writeHeader(out, true, false)) { |
| 223 |
return; |
| 224 |
} |
| 225 |
SoGroup::doAction(static_cast<SoAction*>(action)); |
| 226 |
this->writeFooter(out); |
| 227 |
} |
| 228 |
else { |
| 229 |
inherited::write(action); |
| 230 |
} |
| 231 |
} |
| 232 |
|
| 233 |
int SoFCUnifiedSelection::getPriority(const SoPickedPoint* p) |
| 234 |
{ |
| 235 |
const SoDetail* detail = p->getDetail(); |
| 236 |
if (!detail) { |
| 237 |
return 0; |
| 238 |
} |
| 239 |
if (detail->isOfType(SoFaceDetail::getClassTypeId())) { |
| 240 |
return 1; |
| 241 |
} |
| 242 |
if (detail->isOfType(SoLineDetail::getClassTypeId())) { |
| 243 |
return 2; |
| 244 |
} |
| 245 |
if (detail->isOfType(SoPointDetail::getClassTypeId())) { |
| 246 |
return 3; |
| 247 |
} |
| 248 |
return 0; |
| 249 |
} |
| 250 |
|
| 251 |
std::vector<SoFCUnifiedSelection::PickedInfo> SoFCUnifiedSelection::getPickedList( |
| 252 |
SoHandleEventAction* action, |
| 253 |
bool singlePick |
| 254 |
) const |
| 255 |
{ |
| 256 |
ViewProvider* last_vp = nullptr; |
| 257 |
std::vector<PickedInfo> ret; |
| 258 |
const SoPickedPointList& points = action->getPickedPointList(); |
| 259 |
for (int i = 0, count = points.getLength(); i < count; ++i) { |
| 260 |
PickedInfo info; |
| 261 |
info.pp = points[i]; |
| 262 |
info.vpd = nullptr; |
| 263 |
ViewProvider* vp = nullptr; |
| 264 |
auto path = static_cast<SoFullPath*>(info.pp->getPath()); |
| 265 |
if (this->pcDocument && path && path->containsPath(action->getCurPath())) { |
| 266 |
vp = this->pcDocument->getViewProviderByPathFromHead(path); |
| 267 |
if (singlePick && last_vp && last_vp != vp) { |
| 268 |
return ret; |
| 269 |
} |
| 270 |
} |
| 271 |
if (!vp || !vp->isDerivedFrom(ViewProviderDocumentObject::getClassTypeId())) { |
| 272 |
if (!singlePick) { |
| 273 |
continue; |
| 274 |
} |
| 275 |
if (ret.empty()) { |
| 276 |
ret.push_back(info); |
| 277 |
} |
| 278 |
break; |
| 279 |
} |
| 280 |
info.vpd = static_cast<ViewProviderDocumentObject*>(vp); |
| 281 |
if (!(useNewSelection.getValue() || info.vpd->useNewSelectionModel()) |
| 282 |
|| !info.vpd->isSelectable()) { |
| 283 |
if (!singlePick) { |
| 284 |
continue; |
| 285 |
} |
| 286 |
if (ret.empty()) { |
| 287 |
info.vpd = nullptr; |
| 288 |
ret.push_back(info); |
| 289 |
} |
| 290 |
break; |
| 291 |
} |
| 292 |
if (!info.vpd->getElementPicked(info.pp, info.element)) { |
| 293 |
continue; |
| 294 |
} |
| 295 |
|
| 296 |
if (singlePick) { |
| 297 |
last_vp = vp; |
| 298 |
} |
| 299 |
ret.push_back(info); |
| 300 |
} |
| 301 |
|
| 302 |
if (ret.size() <= 1) { |
| 303 |
return ret; |
| 304 |
} |
| 305 |
|
| 306 |
// To identify the picking of lines in a concave area we have to |
| 307 |
// get all intersection points. If we have two or more intersection |
| 308 |
// points where the first is of a face and the second of a line with |
| 309 |
// almost similar coordinates we use the second point, instead. |
| 310 |
|
| 311 |
int picked_prio = getPriority(ret[0].pp); |
| 312 |
auto last_vpd = ret[0].vpd; |
| 313 |
const SbVec3f& picked_pt = ret.front().pp->getPoint(); |
| 314 |
auto itPicked = ret.begin(); |
| 315 |
for (auto it = ret.begin() + 1; it != ret.end(); ++it) { |
| 316 |
auto& info = *it; |
| 317 |
if (last_vpd != info.vpd) { |
| 318 |
break; |
| 319 |
} |
| 320 |
|
| 321 |
int cur_prio = getPriority(info.pp); |
| 322 |
const SbVec3f& cur_pt = info.pp->getPoint(); |
| 323 |
|
| 324 |
if ((cur_prio > picked_prio) && picked_pt.equals(cur_pt, 0.2F)) { |
| 325 |
itPicked = it; |
| 326 |
picked_prio = cur_prio; |
| 327 |
} |
| 328 |
} |
| 329 |
|
| 330 |
if (singlePick) { |
| 331 |
std::vector<PickedInfo> sret(itPicked, itPicked + 1); |
| 332 |
return sret; |
| 333 |
} |
| 334 |
if (itPicked != ret.begin()) { |
| 335 |
std::swap(*itPicked, *ret.begin()); |
| 336 |
} |
| 337 |
return ret; |
| 338 |
} |
| 339 |
|
| 340 |
void SoFCUnifiedSelection::doAction(SoAction* action) |
| 341 |
{ |
| 342 |
if (action->getTypeId() == SoFCEnablePreselectionAction::getClassTypeId()) { |
| 343 |
auto enablePreselectionAction = static_cast<SoFCEnablePreselectionAction*>(action); |
| 344 |
if (enablePreselectionAction->enabled) { |
| 345 |
this->preselectionMode = SoFCUnifiedSelection::AUTO; |
| 346 |
} |
| 347 |
else { |
| 348 |
this->preselectionMode = SoFCUnifiedSelection::OFF; |
| 349 |
} |
| 350 |
} |
| 351 |
|
| 352 |
if (action->getTypeId() == SoFCEnableSelectionAction::getClassTypeId()) { |
| 353 |
auto enableSelectionAction = static_cast<SoFCEnableSelectionAction*>(action); |
| 354 |
if (enableSelectionAction->enabled) { |
| 355 |
this->selectionMode = SoFCUnifiedSelection::ON; |
| 356 |
} |
| 357 |
else { |
| 358 |
this->selectionMode = SoFCUnifiedSelection::OFF; |
| 359 |
} |
| 360 |
} |
| 361 |
|
| 362 |
if (action->getTypeId() == SoFCSelectionColorAction::getClassTypeId()) { |
| 363 |
auto selectionColorAction = static_cast<SoFCSelectionColorAction*>(action); |
| 364 |
this->colorSelection = selectionColorAction->selectionColor; |
| 365 |
} |
| 366 |
|
| 367 |
if (action->getTypeId() == SoFCHighlightColorAction::getClassTypeId()) { |
| 368 |
auto highlightColorAction = static_cast<SoFCHighlightColorAction*>(action); |
| 369 |
this->colorHighlight = highlightColorAction->highlightColor; |
| 370 |
} |
| 371 |
|
| 372 |
if (action->getTypeId() == SoFCPreselectionAction::getClassTypeId()) { |
| 373 |
auto preselectAction = static_cast<SoFCPreselectionAction*>(action); |
| 374 |
// Do not clear currently preselected object when setting new preselection |
| 375 |
if (!setPreSelection && preselectAction->SelChange.Type == SelectionChanges::RmvPreselect) { |
| 376 |
if (currentHighlightPath) { |
| 377 |
SoHighlightElementAction highlightAction; |
| 378 |
highlightAction.apply(currentHighlightPath); |
| 379 |
currentHighlightPath->unref(); |
| 380 |
currentHighlightPath = nullptr; |
| 381 |
} |
| 382 |
} |
| 383 |
else if (preselectionMode.getValue() != OFF |
| 384 |
&& preselectAction->SelChange.Type == SelectionChanges::SetPreselect) { |
| 385 |
if (currentHighlightPath) { |
| 386 |
SoHighlightElementAction highlightAction; |
| 387 |
highlightAction.apply(currentHighlightPath); |
| 388 |
currentHighlightPath->unref(); |
| 389 |
currentHighlightPath = nullptr; |
| 390 |
} |
| 391 |
|
| 392 |
App::Document* doc = App::GetApplication().getDocument(preselectAction->SelChange.pDocName); |
| 393 |
App::DocumentObject* obj = doc->getObject(preselectAction->SelChange.pObjectName); |
| 394 |
ViewProvider* vp = Application::Instance->getViewProvider(obj); |
| 395 |
|
| 396 |
// use getDetailPath() like selection does, instead of just getDetail() |
| 397 |
SoDetail* detail = nullptr; |
| 398 |
detailPath->truncate(0); |
| 399 |
auto subName = preselectAction->SelChange.pSubName; |
| 400 |
|
| 401 |
SoFullPath* pathToHighlight = nullptr; |
| 402 |
if (vp && vp->isDerivedFrom(ViewProviderDocumentObject::getClassTypeId()) |
| 403 |
&& (useNewSelection.getValue() || vp->useNewSelectionModel()) && vp->isSelectable()) { |
| 404 |
|
| 405 |
// get proper detail path for sub-objects (like Assembly parts) |
| 406 |
if (!subName || !subName[0] || vp->getDetailPath(subName, detailPath, true, detail)) { |
| 407 |
if (detailPath->getLength()) { |
| 408 |
pathToHighlight = detailPath; |
| 409 |
} |
| 410 |
else { |
| 411 |
// fallback to ViewProvider root if no specific path |
| 412 |
pathToHighlight = static_cast<SoFullPath*>(new SoPath(2)); |
| 413 |
pathToHighlight->ref(); |
| 414 |
pathToHighlight->append(vp->getRoot()); |
| 415 |
} |
| 416 |
} |
| 417 |
} |
| 418 |
else { |
| 419 |
detail = vp->getDetail(subName); |
| 420 |
pathToHighlight = static_cast<SoFullPath*>(new SoPath(2)); |
| 421 |
pathToHighlight->ref(); |
| 422 |
pathToHighlight->append(vp->getRoot()); |
| 423 |
} |
| 424 |
|
| 425 |
if (pathToHighlight) { |
| 426 |
SoHighlightElementAction highlightAction; |
| 427 |
highlightAction.setHighlighted(true); |
| 428 |
highlightAction.setColor(this->colorHighlight.getValue()); |
| 429 |
highlightAction.setElement(detail); |
| 430 |
highlightAction.apply(pathToHighlight); |
| 431 |
|
| 432 |
currentHighlightPath = static_cast<SoFullPath*>(pathToHighlight->copy()); |
| 433 |
currentHighlightPath->ref(); |
| 434 |
|
| 435 |
// clean up temporary path if we created one |
| 436 |
if (pathToHighlight != detailPath) { |
| 437 |
pathToHighlight->unref(); |
| 438 |
} |
| 439 |
} |
| 440 |
|
| 441 |
delete detail; |
| 442 |
} |
| 443 |
|
| 444 |
if (useNewSelection.getValue()) { |
| 445 |
return; |
| 446 |
} |
| 447 |
} |
| 448 |
|
| 449 |
if (action->getTypeId() == SoFCSelectionAction::getClassTypeId()) { |
| 450 |
auto selectionAction = static_cast<SoFCSelectionAction*>(action); |
| 451 |
if (selectionMode.getValue() == ON |
| 452 |
&& (selectionAction->SelChange.Type == SelectionChanges::AddSelection |
| 453 |
|| selectionAction->SelChange.Type == SelectionChanges::RmvSelection)) { |
| 454 |
// selection changes inside the 3d view are handled in handleEvent() |
| 455 |
App::Document* doc = App::GetApplication().getDocument(selectionAction->SelChange.pDocName); |
| 456 |
App::DocumentObject* obj = doc->getObject(selectionAction->SelChange.pObjectName); |
| 457 |
ViewProvider* vp = Application::Instance->getViewProvider(obj); |
| 458 |
if (vp && (useNewSelection.getValue() || vp->useNewSelectionModel()) |
| 459 |
&& vp->isSelectable()) { |
| 460 |
SoDetail* detail = nullptr; |
| 461 |
detailPath->truncate(0); |
| 462 |
auto subName = selectionAction->SelChange.pSubName; |
| 463 |
App::ElementNamePair elementName; |
| 464 |
; |
| 465 |
App::GeoFeature::resolveElement(obj, subName, elementName); |
| 466 |
if (Data::isMappedElement(subName) |
| 467 |
&& !elementName.oldName.empty()) { // If we have a shortened element name |
| 468 |
subName = elementName.oldName.c_str(); // use it. |
| 469 |
} |
| 470 |
if (!selectionAction->SelChange.pSubName || !selectionAction->SelChange.pSubName[0] |
| 471 |
|| vp->getDetailPath(subName, detailPath, true, detail)) { |
| 472 |
SoSelectionElementAction::Type type = SoSelectionElementAction::None; |
| 473 |
if (selectionAction->SelChange.Type == SelectionChanges::AddSelection) { |
| 474 |
if (detail) { |
| 475 |
type = SoSelectionElementAction::Append; |
| 476 |
} |
| 477 |
else { |
| 478 |
type = SoSelectionElementAction::All; |
| 479 |
} |
| 480 |
} |
| 481 |
else { |
| 482 |
if (detail) { |
| 483 |
type = SoSelectionElementAction::Remove; |
| 484 |
} |
| 485 |
else { |
| 486 |
type = SoSelectionElementAction::None; |
| 487 |
} |
| 488 |
} |
| 489 |
|
| 490 |
SoSelectionElementAction selectionAction(type); |
| 491 |
selectionAction.setColor(this->colorSelection.getValue()); |
| 492 |
selectionAction.setElement(detail); |
| 493 |
if (detailPath->getLength()) { |
| 494 |
selectionAction.apply(detailPath); |
| 495 |
} |
| 496 |
else { |
| 497 |
selectionAction.apply(vp->getRoot()); |
| 498 |
} |
| 499 |
} |
| 500 |
detailPath->truncate(0); |
| 501 |
delete detail; |
| 502 |
} |
| 503 |
} |
| 504 |
else if (selectionAction->SelChange.Type == SelectionChanges::ClrSelection) { |
| 505 |
SoSelectionElementAction selectionAction(SoSelectionElementAction::None); |
| 506 |
for (int i = 0; i < this->getNumChildren(); ++i) { |
| 507 |
selectionAction.apply(this->getChild(i)); |
| 508 |
} |
| 509 |
} |
| 510 |
else if (selectionMode.getValue() == ON |
| 511 |
&& selectionAction->SelChange.Type == SelectionChanges::SetSelection) { |
| 512 |
std::vector<ViewProvider*> vps; |
| 513 |
if (this->pcDocument) { |
| 514 |
vps = this->pcDocument->getViewProvidersOfType( |
| 515 |
ViewProviderDocumentObject::getClassTypeId() |
| 516 |
); |
| 517 |
} |
| 518 |
for (const auto& vp : vps) { |
| 519 |
auto vpd = static_cast<ViewProviderDocumentObject*>(vp); |
| 520 |
if (useNewSelection.getValue() || vpd->useNewSelectionModel()) { |
| 521 |
SoSelectionElementAction::Type type; |
| 522 |
if (Selection().isSelected(vpd->getObject()) && vpd->isSelectable()) { |
| 523 |
type = SoSelectionElementAction::All; |
| 524 |
} |
| 525 |
else { |
| 526 |
type = SoSelectionElementAction::None; |
| 527 |
} |
| 528 |
|
| 529 |
SoSelectionElementAction selectionAction(type); |
| 530 |
selectionAction.setColor(this->colorSelection.getValue()); |
| 531 |
selectionAction.apply(vpd->getRoot()); |
| 532 |
} |
| 533 |
} |
| 534 |
} |
| 535 |
else if (selectionAction->SelChange.Type == SelectionChanges::SetPreselectSignal) { |
| 536 |
// selection changes inside the 3d view are handled in handleEvent() |
| 537 |
App::Document* doc = App::GetApplication().getDocument(selectionAction->SelChange.pDocName); |
| 538 |
App::DocumentObject* obj = doc->getObject(selectionAction->SelChange.pObjectName); |
| 539 |
ViewProvider* vp = Application::Instance->getViewProvider(obj); |
| 540 |
if (vp && vp->isDerivedFrom(ViewProviderDocumentObject::getClassTypeId()) |
| 541 |
&& (useNewSelection.getValue() || vp->useNewSelectionModel()) && vp->isSelectable()) { |
| 542 |
detailPath->truncate(0); |
| 543 |
SoDetail* det = nullptr; |
| 544 |
if (vp->getDetailPath(selectionAction->SelChange.pSubName, detailPath, true, det)) { |
| 545 |
setPreselect( |
| 546 |
detailPath, |
| 547 |
det, |
| 548 |
static_cast<ViewProviderDocumentObject*>(vp), |
| 549 |
selectionAction->SelChange.pSubName, |
| 550 |
selectionAction->SelChange.x, |
| 551 |
selectionAction->SelChange.y, |
| 552 |
selectionAction->SelChange.z |
| 553 |
); |
| 554 |
} |
| 555 |
delete det; |
| 556 |
} |
| 557 |
} |
| 558 |
|
| 559 |
if (useNewSelection.getValue()) { |
| 560 |
return; |
| 561 |
} |
| 562 |
} |
| 563 |
|
| 564 |
inherited::doAction(action); |
| 565 |
} |
| 566 |
|
| 567 |
bool SoFCUnifiedSelection::setPreselect(const PickedInfo& info) |
| 568 |
{ |
| 569 |
if (!info.pp) { |
| 570 |
return setPreselect(nullptr, nullptr, nullptr, nullptr, 0.0, 0.0, 0.0); |
| 571 |
} |
| 572 |
|
| 573 |
const auto& pt = info.pp->getPoint(); |
| 574 |
return setPreselect( |
| 575 |
static_cast<SoFullPath*>(info.pp->getPath()), |
| 576 |
info.pp->getDetail(), |
| 577 |
info.vpd, |
| 578 |
info.element.c_str(), |
| 579 |
pt[0], |
| 580 |
pt[1], |
| 581 |
pt[2] |
| 582 |
); |
| 583 |
} |
| 584 |
|
| 585 |
bool SoFCUnifiedSelection::setPreselect( |
| 586 |
SoFullPath* path, |
| 587 |
const SoDetail* det, |
| 588 |
ViewProviderDocumentObject* vpd, |
| 589 |
const char* element, |
| 590 |
float x, |
| 591 |
float y, |
| 592 |
float z |
| 593 |
) |
| 594 |
{ |
| 595 |
Base::FlagToggler<SbBool> flag(setPreSelection); |
| 596 |
|
| 597 |
bool highlighted = false; |
| 598 |
if (path && path->getLength() && vpd && vpd->getObject() |
| 599 |
&& vpd->getObject()->isAttachedToDocument()) { |
| 600 |
const char* docname = vpd->getObject()->getDocument()->getName(); |
| 601 |
const char* objname = vpd->getObject()->getNameInDocument(); |
| 602 |
|
| 603 |
this->preSelection = 1; |
| 604 |
|
| 605 |
printPreselectionInfo(docname, objname, element, x, y, z, 1e-7); |
| 606 |
|
| 607 |
|
| 608 |
int ret = Gui::Selection().setPreselect(docname, objname, element, x, y, z); |
| 609 |
if (ret < 0 && currentHighlightPath) { |
| 610 |
return true; |
| 611 |
} |
| 612 |
|
| 613 |
if (ret) { |
| 614 |
if (currentHighlightPath) { |
| 615 |
SoHighlightElementAction action; |
| 616 |
action.setHighlighted(false); |
| 617 |
action.apply(currentHighlightPath); |
| 618 |
currentHighlightPath->unref(); |
| 619 |
currentHighlightPath = nullptr; |
| 620 |
} |
| 621 |
currentHighlightPath = static_cast<SoFullPath*>(path->copy()); |
| 622 |
currentHighlightPath->ref(); |
| 623 |
highlighted = true; |
| 624 |
} |
| 625 |
} |
| 626 |
|
| 627 |
if (currentHighlightPath) { |
| 628 |
SoHighlightElementAction action; |
| 629 |
action.setHighlighted(highlighted); |
| 630 |
action.setColor(this->colorHighlight.getValue()); |
| 631 |
action.setElement(det); |
| 632 |
action.apply(currentHighlightPath); |
| 633 |
if (!highlighted) { |
| 634 |
currentHighlightPath->unref(); |
| 635 |
currentHighlightPath = nullptr; |
| 636 |
Selection().rmvPreselect(); |
| 637 |
} |
| 638 |
this->touch(); |
| 639 |
} |
| 640 |
return highlighted; |
| 641 |
} |
| 642 |
|
| 643 |
bool SoFCUnifiedSelection::setSelection(const std::vector<PickedInfo>& infos, bool ctrlDown) |
| 644 |
{ |
| 645 |
if (infos.empty() || !infos[0].vpd) { |
| 646 |
return false; |
| 647 |
} |
| 648 |
|
| 649 |
std::vector<SelectionSingleton::SelObj> sels; |
| 650 |
if (infos.size() > 1) { |
| 651 |
for (auto& info : infos) { |
| 652 |
if (!info.vpd) { |
| 653 |
continue; |
| 654 |
} |
| 655 |
|
| 656 |
SelectionSingleton::SelObj sel; |
| 657 |
sel.pResolvedObject = nullptr; |
| 658 |
sel.pObject = info.vpd->getObject(); |
| 659 |
sel.pDoc = sel.pObject->getDocument(); |
| 660 |
sel.DocName = sel.pDoc->getName(); |
| 661 |
sel.FeatName = sel.pObject->getNameInDocument(); |
| 662 |
sel.TypeName = sel.pObject->getTypeId().getName(); |
| 663 |
sel.SubName = info.element.c_str(); |
| 664 |
const auto& pt = info.pp->getPoint(); |
| 665 |
sel.x = pt[0]; |
| 666 |
sel.y = pt[1]; |
| 667 |
sel.z = pt[2]; |
| 668 |
sels.push_back(sel); |
| 669 |
} |
| 670 |
} |
| 671 |
|
| 672 |
const auto& info = infos[0]; |
| 673 |
auto vpd = info.vpd; |
| 674 |
if (!vpd) { |
| 675 |
return false; |
| 676 |
} |
| 677 |
if (!vpd->getObject()->isAttachedToDocument()) { |
| 678 |
return false; |
| 679 |
} |
| 680 |
const char* objname = vpd->getObject()->getNameInDocument(); |
| 681 |
const char* docname = vpd->getObject()->getDocument()->getName(); |
| 682 |
|
| 683 |
auto getFullSubElementName = [vpd](std::string& subName) { |
| 684 |
App::ElementNamePair elementName; |
| 685 |
App::GeoFeature::resolveElement(vpd->getObject(), subName.c_str(), elementName); |
| 686 |
if (!elementName.newName.empty()) { // If we have a mapped name use it |
| 687 |
auto elementNameSuffix = Data::findElementName(subName.c_str()); // Only suffix |
| 688 |
subName.erase(subName.find(elementNameSuffix)); // Everything except original suffix |
| 689 |
subName = subName.append(elementName.newName); // Add the mapped name suffix, |
| 690 |
} |
| 691 |
}; |
| 692 |
|
| 693 |
bool hasNext = false; |
| 694 |
const SoPickedPoint* pp = info.pp; |
| 695 |
const SoDetail* det = pp->getDetail(); |
| 696 |
SoDetail* detNext = nullptr; |
| 697 |
auto pPath = static_cast<SoFullPath*>(pp->getPath()); |
| 698 |
const auto& pt = pp->getPoint(); |
| 699 |
SoSelectionElementAction::Type type = SoSelectionElementAction::None; |
| 700 |
auto preselectionMode = static_cast<SelectionModes>(this->preselectionMode.getValue()); |
| 701 |
static char buf[513]; |
| 702 |
auto subName = info.element; |
| 703 |
std::string objectName = objname; |
| 704 |
|
| 705 |
if (ctrlDown) { |
| 706 |
if (Gui::Selection().isSelected(docname, objname, info.element.c_str(), ResolveMode::NoResolve)) { |
| 707 |
Gui::Selection().rmvSelection(docname, objname, info.element.c_str(), &sels); |
| 708 |
return true; |
| 709 |
} |
| 710 |
else { |
| 711 |
// Changing the selection may result in destroying this view provider. |
| 712 |
// So, make sure that the object still exists afterwards (#17965) |
| 713 |
ViewProviderWeakPtrT guard(vpd); |
| 714 |
getFullSubElementName(subName); |
| 715 |
bool ok = Gui::Selection() |
| 716 |
.addSelection(docname, objname, subName.c_str(), pt[0], pt[1], pt[2], &sels); |
| 717 |
if (guard.expired()) { |
| 718 |
return false; |
| 719 |
} |
| 720 |
|
| 721 |
if (ok && preselectionMode == OFF) { |
| 722 |
snprintf( |
| 723 |
buf, |
| 724 |
512, |
| 725 |
"Selected: %s.%s.%s (%g, %g, %g)", |
| 726 |
docname, |
| 727 |
objname, |
| 728 |
info.element.c_str(), |
| 729 |
fabs(pt[0]) > 1e-7 ? pt[0] : 0.0, |
| 730 |
fabs(pt[1]) > 1e-7 ? pt[1] : 0.0, |
| 731 |
fabs(pt[2]) > 1e-7 ? pt[2] : 0.0 |
| 732 |
); |
| 733 |
|
| 734 |
getMainWindow()->showMessage(QString::fromLatin1(buf)); |
| 735 |
} |
| 736 |
detailPath->truncate(0); |
| 737 |
if (vpd->getDetailPath(info.element.c_str(), detailPath, true, detNext) |
| 738 |
&& detailPath->getLength()) { |
| 739 |
pPath = detailPath; |
| 740 |
det = detNext; |
| 741 |
FC_TRACE("select next " << objectName << ", " << subName); |
| 742 |
if (ok) { |
| 743 |
type = hasNext ? SoSelectionElementAction::All : SoSelectionElementAction::Append; |
| 744 |
} |
| 745 |
else { |
| 746 |
// don't apply any visual action when selection fails - |
| 747 |
// in a case when we press ctrl and select a geometry that should be |
| 748 |
// filtered out, we don't want to apply any visual action |
| 749 |
pPath = nullptr; |
| 750 |
} |
| 751 |
} |
| 752 |
} |
| 753 |
} |
| 754 |
else { |
| 755 |
// Hierarchy ascending |
| 756 |
// |
| 757 |
// If the clicked subelement is already selected, check if there is an |
| 758 |
// upper hierarchy, and select that hierarchy instead. |
| 759 |
// |
| 760 |
// For example, let's suppose PickedInfo above reports |
| 761 |
// 'link.link2.box.Face1', and below Selection().getSelectedElement returns |
| 762 |
// 'link.link2.box.', meaning that 'box' is the current selected hierarchy, |
| 763 |
// and the user is clicking the box again. So we shall go up one level, |
| 764 |
// and select 'link.link2.' |
| 765 |
// |
| 766 |
|
| 767 |
|
| 768 |
// We need to convert the short name in the selection to a full element path to look it up |
| 769 |
// Ex: Body.Pad.Face9 to Body.Pad.;g3;SKT;:H12dc,E;FAC;:H12dc:4,F;:G0;XTR;:H12dc:8,F.Face9 |
| 770 |
getFullSubElementName(subName); |
| 771 |
const char* subSelected |
| 772 |
= Gui::Selection().getSelectedElement(vpd->getObject(), subName.c_str()); |
| 773 |
|
| 774 |
FC_TRACE( |
| 775 |
"select " << (subSelected ? subSelected : "'null'") << ", " << objectName << ", " << subName |
| 776 |
); |
| 777 |
std::string newElement; |
| 778 |
if (subSelected) { |
| 779 |
newElement = Data::newElementName(subSelected); |
| 780 |
subSelected = newElement.c_str(); |
| 781 |
std::string nextsub; |
| 782 |
const char* next = strrchr(subSelected, '.'); |
| 783 |
if (next && next != subSelected) { |
| 784 |
if (next[1] == 0) { |
| 785 |
// The convention of dot separated SubName demands a mandatory |
| 786 |
// ending dot for every object name reference inside SubName. |
| 787 |
// The non-object sub-element, however, must not end with a dot. |
| 788 |
// So, next[1]==0 here means current selection is a whole object |
| 789 |
// selection (because no sub-element), so we shall search |
| 790 |
// upwards for the second last dot, which is the end of the |
| 791 |
// parent name of the current selected object |
| 792 |
for (--next; next != subSelected; --next) { |
| 793 |
if (*next == '.') { |
| 794 |
break; |
| 795 |
} |
| 796 |
} |
| 797 |
} |
| 798 |
if (*next == '.') { |
| 799 |
nextsub = std::string(subSelected, next - subSelected + 1); |
| 800 |
} |
| 801 |
} |
| 802 |
if (nextsub.length() || *subSelected != 0) { |
| 803 |
hasNext = true; |
| 804 |
subName = nextsub; |
| 805 |
detailPath->truncate(0); |
| 806 |
if (vpd->getDetailPath(subName.c_str(), detailPath, true, detNext) |
| 807 |
&& detailPath->getLength()) { |
| 808 |
pPath = detailPath; |
| 809 |
det = detNext; |
| 810 |
FC_TRACE("select next " << objectName << ", " << subName); |
| 811 |
} |
| 812 |
} |
| 813 |
} |
| 814 |
|
| 815 |
FC_TRACE("clearing selection"); |
| 816 |
Gui::Selection().clearSelection(); |
| 817 |
FC_TRACE("add selection"); |
| 818 |
bool ok = Gui::Selection().addSelection( |
| 819 |
docname, |
| 820 |
objectName.c_str(), |
| 821 |
subName.c_str(), |
| 822 |
pt[0], |
| 823 |
pt[1], |
| 824 |
pt[2], |
| 825 |
&sels |
| 826 |
); |
| 827 |
if (ok) { |
| 828 |
type = hasNext ? SoSelectionElementAction::All : SoSelectionElementAction::Append; |
| 829 |
} |
| 830 |
|
| 831 |
if (preselectionMode == OFF) { |
| 832 |
snprintf( |
| 833 |
buf, |
| 834 |
512, |
| 835 |
"Selected: %s.%s.%s (%g, %g, %g)", |
| 836 |
docname, |
| 837 |
objectName.c_str(), |
| 838 |
subName.c_str(), |
| 839 |
fabs(pt[0]) > 1e-7 ? pt[0] : 0.0, |
| 840 |
fabs(pt[1]) > 1e-7 ? pt[1] : 0.0, |
| 841 |
fabs(pt[2]) > 1e-7 ? pt[2] : 0.0 |
| 842 |
); |
| 843 |
|
| 844 |
getMainWindow()->showMessage(QString::fromLatin1(buf)); |
| 845 |
} |
| 846 |
} |
| 847 |
|
| 848 |
if (pPath) { |
| 849 |
FC_TRACE("applying action"); |
| 850 |
SoSelectionElementAction action(type); |
| 851 |
action.setColor(this->colorSelection.getValue()); |
| 852 |
action.setElement(det); |
| 853 |
action.apply(pPath); |
| 854 |
FC_TRACE("applied action"); |
| 855 |
this->touch(); |
| 856 |
} |
| 857 |
|
| 858 |
if (detNext) { |
| 859 |
delete detNext; |
| 860 |
} |
| 861 |
return true; |
| 862 |
} |
| 863 |
|
| 864 |
// doc from parent |
| 865 |
void SoFCUnifiedSelection::handleEvent(SoHandleEventAction* action) |
| 866 |
{ |
| 867 |
// If off then don't handle this event |
| 868 |
if (!selectionEnabled.getValue()) { |
| 869 |
inherited::handleEvent(action); |
| 870 |
return; |
| 871 |
} |
| 872 |
|
| 873 |
auto preselectionMode = static_cast<SelectionModes>(this->preselectionMode.getValue()); |
| 874 |
const SoEvent* event = action->getEvent(); |
| 875 |
|
| 876 |
// |
| 877 |
// If this is a mouseMotion event, then check for preselected entities. |
| 878 |
// |
| 879 |
bool isMouseMotionEvent = event->isOfType(SoLocation2Event::getClassTypeId()); |
| 880 |
if (isMouseMotionEvent) { |
| 881 |
// NOTE: If preselection is off then we do not check for a picked point because otherwise |
| 882 |
// this search may slow down extremely the system on really big data sets. In this case we |
| 883 |
// just check for a picked point if the data set has been selected. |
| 884 |
if (preselectionMode == AUTO || preselectionMode == ON) { |
| 885 |
// check to see if the mouse is over our geometry... |
| 886 |
auto infos = this->getPickedList(action, true); |
| 887 |
if (!infos.empty()) { |
| 888 |
setPreselect(infos[0]); |
| 889 |
} |
| 890 |
else { |
| 891 |
setPreselect(PickedInfo()); |
| 892 |
if (this->preSelection > 0) { |
| 893 |
this->preSelection = 0; |
| 894 |
// touch() makes sure to call GLRenderBelowPath so that the cursor can be updated |
| 895 |
// because only from there the SoGLWidgetElement delivers the OpenGL window |
| 896 |
this->touch(); |
| 897 |
} |
| 898 |
} |
| 899 |
} |
| 900 |
} |
| 901 |
// mouse press events for (de)selection |
| 902 |
else if (event->isOfType(SoMouseButtonEvent::getClassTypeId()) |
| 903 |
&& selectionMode.getValue() == SoFCUnifiedSelection::ON) { |
| 904 |
const auto e = static_cast<const SoMouseButtonEvent*>(event); |
| 905 |
if (SoMouseButtonEvent::isButtonReleaseEvent(e, SoMouseButtonEvent::BUTTON1)) { |
| 906 |
// check to see if the mouse is over a geometry... |
| 907 |
auto infos = this->getPickedList(action, !Selection().needPickedList()); |
| 908 |
bool greedySel = Gui::Selection().getSelectionStyle() |
| 909 |
== Gui::SelectionSingleton::SelectionStyle::GreedySelection; |
| 910 |
greedySel = greedySel || event->wasCtrlDown(); |
| 911 |
if (setSelection(infos, greedySel) || greedySel) { |
| 912 |
action->setHandled(); |
| 913 |
} |
| 914 |
} // mouse release |
| 915 |
} |
| 916 |
|
| 917 |
inherited::handleEvent(action); |
| 918 |
} |
| 919 |
|
| 920 |
void SoFCUnifiedSelection::GLRenderBelowPath(SoGLRenderAction* action) |
| 921 |
{ |
| 922 |
inherited::GLRenderBelowPath(action); |
| 923 |
|
| 924 |
// nothing picked, so restore the arrow cursor if needed |
| 925 |
if (this->preSelection == 0) { |
| 926 |
// this is called when a selection gate forbade to select an object |
| 927 |
// and the user moved the mouse to an empty area |
| 928 |
this->preSelection = -1; |
| 929 |
QOpenGLWidget* window; |
| 930 |
SoState* state = action->getState(); |
| 931 |
SoGLWidgetElement::get(state, window); |
| 932 |
QWidget* parent = window ? window->parentWidget() : nullptr; |
| 933 |
if (parent) { |
| 934 |
QCursor c = parent->cursor(); |
| 935 |
if (c.shape() == Qt::ForbiddenCursor) { |
| 936 |
c.setShape(Qt::ArrowCursor); |
| 937 |
parent->setCursor(c); |
| 938 |
} |
| 939 |
} |
| 940 |
} |
| 941 |
} |
| 942 |
|
| 943 |
// --------------------------------------------------------------- |
| 944 |
|
| 945 |
SO_ACTION_SOURCE(SoHighlightElementAction) |
| 946 |
|
| 947 |
void SoHighlightElementAction::initClass() |
| 948 |
{ |
| 949 |
SO_ACTION_INIT_CLASS(SoHighlightElementAction, SoAction); |
| 950 |
|
| 951 |
SO_ENABLE(SoHighlightElementAction, SoSwitchElement); |
| 952 |
SO_ENABLE(SoHighlightElementAction, SoModelMatrixElement); |
| 953 |
|
| 954 |
SO_ACTION_ADD_METHOD(SoNode, nullAction); |
| 955 |
|
| 956 |
SO_ENABLE(SoHighlightElementAction, SoCoordinateElement); |
| 957 |
|
| 958 |
SO_ACTION_ADD_METHOD(SoGroup, callDoAction); |
| 959 |
SO_ACTION_ADD_METHOD(SoIndexedLineSet, callDoAction); |
| 960 |
SO_ACTION_ADD_METHOD(SoIndexedFaceSet, callDoAction); |
| 961 |
SO_ACTION_ADD_METHOD(SoPointSet, callDoAction); |
| 962 |
} |
| 963 |
|
| 964 |
SoHighlightElementAction::SoHighlightElementAction() |
| 965 |
{ |
| 966 |
SO_ACTION_CONSTRUCTOR(SoHighlightElementAction); |
| 967 |
} |
| 968 |
|
| 969 |
SoHighlightElementAction::~SoHighlightElementAction() = default; |
| 970 |
|
| 971 |
void SoHighlightElementAction::beginTraversal(SoNode* node) |
| 972 |
{ |
| 973 |
traverse(node); |
| 974 |
} |
| 975 |
|
| 976 |
void SoHighlightElementAction::callDoAction(SoAction* action, SoNode* node) |
| 977 |
{ |
| 978 |
node->doAction(action); |
| 979 |
} |
| 980 |
|
| 981 |
void SoHighlightElementAction::setHighlighted(SbBool ok) |
| 982 |
{ |
| 983 |
this->_highlight = ok; |
| 984 |
} |
| 985 |
|
| 986 |
SbBool SoHighlightElementAction::isHighlighted() const |
| 987 |
{ |
| 988 |
return this->_highlight; |
| 989 |
} |
| 990 |
|
| 991 |
void SoHighlightElementAction::setColor(const SbColor& c) |
| 992 |
{ |
| 993 |
this->_color = c; |
| 994 |
} |
| 995 |
|
| 996 |
const SbColor& SoHighlightElementAction::getColor() const |
| 997 |
{ |
| 998 |
return this->_color; |
| 999 |
} |
| 1000 |
|
| 1001 |
void SoHighlightElementAction::setElement(const SoDetail* det) |
| 1002 |
{ |
| 1003 |
this->_det = det; |
| 1004 |
} |
| 1005 |
|
| 1006 |
const SoDetail* SoHighlightElementAction::getElement() const |
| 1007 |
{ |
| 1008 |
return this->_det; |
| 1009 |
} |
| 1010 |
|
| 1011 |
// --------------------------------------------------------------- |
| 1012 |
|
| 1013 |
SO_ACTION_SOURCE(SoSelectionElementAction) |
| 1014 |
|
| 1015 |
void SoSelectionElementAction::initClass() |
| 1016 |
{ |
| 1017 |
SO_ACTION_INIT_CLASS(SoSelectionElementAction, SoAction); |
| 1018 |
|
| 1019 |
SO_ENABLE(SoSelectionElementAction, SoSwitchElement); |
| 1020 |
SO_ENABLE(SoSelectionElementAction, SoModelMatrixElement); |
| 1021 |
|
| 1022 |
SO_ACTION_ADD_METHOD(SoNode, nullAction); |
| 1023 |
|
| 1024 |
SO_ENABLE(SoSelectionElementAction, SoCoordinateElement); |
| 1025 |
|
| 1026 |
SO_ACTION_ADD_METHOD(SoCoordinate3, callDoAction); |
| 1027 |
SO_ACTION_ADD_METHOD(SoGroup, callDoAction); |
| 1028 |
SO_ACTION_ADD_METHOD(SoIndexedLineSet, callDoAction); |
| 1029 |
SO_ACTION_ADD_METHOD(SoIndexedFaceSet, callDoAction); |
| 1030 |
SO_ACTION_ADD_METHOD(SoPointSet, callDoAction); |
| 1031 |
} |
| 1032 |
|
| 1033 |
SoSelectionElementAction::SoSelectionElementAction(Type t, bool secondary) |
| 1034 |
: _type(t) |
| 1035 |
, _secondary(secondary) |
| 1036 |
{ |
| 1037 |
SO_ACTION_CONSTRUCTOR(SoSelectionElementAction); |
| 1038 |
} |
| 1039 |
|
| 1040 |
SoSelectionElementAction::~SoSelectionElementAction() = default; |
| 1041 |
|
| 1042 |
void SoSelectionElementAction::beginTraversal(SoNode* node) |
| 1043 |
{ |
| 1044 |
traverse(node); |
| 1045 |
} |
| 1046 |
|
| 1047 |
void SoSelectionElementAction::callDoAction(SoAction* action, SoNode* node) |
| 1048 |
{ |
| 1049 |
node->doAction(action); |
| 1050 |
} |
| 1051 |
|
| 1052 |
SoSelectionElementAction::Type SoSelectionElementAction::getType() const |
| 1053 |
{ |
| 1054 |
return this->_type; |
| 1055 |
} |
| 1056 |
|
| 1057 |
void SoSelectionElementAction::setColor(const SbColor& c) |
| 1058 |
{ |
| 1059 |
this->_color = c; |
| 1060 |
} |
| 1061 |
|
| 1062 |
const SbColor& SoSelectionElementAction::getColor() const |
| 1063 |
{ |
| 1064 |
return this->_color; |
| 1065 |
} |
| 1066 |
|
| 1067 |
void SoSelectionElementAction::setElement(const SoDetail* det) |
| 1068 |
{ |
| 1069 |
this->_det = det; |
| 1070 |
} |
| 1071 |
|
| 1072 |
const SoDetail* SoSelectionElementAction::getElement() const |
| 1073 |
{ |
| 1074 |
return this->_det; |
| 1075 |
} |
| 1076 |
|
| 1077 |
// --------------------------------------------------------------- |
| 1078 |
|
| 1079 |
SO_ACTION_SOURCE(SoVRMLAction) |
| 1080 |
|
| 1081 |
void SoVRMLAction::initClass() |
| 1082 |
{ |
| 1083 |
SO_ACTION_INIT_CLASS(SoVRMLAction, SoAction); |
| 1084 |
|
| 1085 |
SO_ENABLE(SoVRMLAction, SoSwitchElement); |
| 1086 |
|
| 1087 |
SO_ACTION_ADD_METHOD(SoNode, nullAction); |
| 1088 |
|
| 1089 |
SO_ENABLE(SoVRMLAction, SoCoordinateElement); |
| 1090 |
SO_ENABLE(SoVRMLAction, SoMaterialBindingElement); |
| 1091 |
SO_ENABLE(SoVRMLAction, SoLazyElement); |
| 1092 |
SO_ENABLE(SoVRMLAction, SoShapeStyleElement); |
| 1093 |
|
| 1094 |
SO_ACTION_ADD_METHOD(SoCoordinate3, callDoAction); |
| 1095 |
SO_ACTION_ADD_METHOD(SoMaterialBinding, callDoAction); |
| 1096 |
SO_ACTION_ADD_METHOD(SoMaterial, callDoAction); |
| 1097 |
SO_ACTION_ADD_METHOD(SoNormalBinding, callDoAction); |
| 1098 |
SO_ACTION_ADD_METHOD(SoGroup, callDoAction); |
| 1099 |
SO_ACTION_ADD_METHOD(SoIndexedLineSet, callDoAction); |
| 1100 |
SO_ACTION_ADD_METHOD(SoIndexedFaceSet, callDoAction); |
| 1101 |
SO_ACTION_ADD_METHOD(SoPointSet, callDoAction); |
| 1102 |
} |
| 1103 |
|
| 1104 |
SoVRMLAction::SoVRMLAction() |
| 1105 |
{ |
| 1106 |
SO_ACTION_CONSTRUCTOR(SoVRMLAction); |
| 1107 |
} |
| 1108 |
|
| 1109 |
SoVRMLAction::~SoVRMLAction() = default; |
| 1110 |
|
| 1111 |
void SoVRMLAction::setOverrideMode(SbBool on) |
| 1112 |
{ |
| 1113 |
overrideMode = on; |
| 1114 |
} |
| 1115 |
|
| 1116 |
SbBool SoVRMLAction::isOverrideMode() const |
| 1117 |
{ |
| 1118 |
return overrideMode; |
| 1119 |
} |
| 1120 |
|
| 1121 |
void SoVRMLAction::callDoAction(SoAction* action, SoNode* node) |
| 1122 |
{ |
| 1123 |
if (node->getTypeId().isDerivedFrom(SoNormalBinding::getClassTypeId()) |
| 1124 |
&& action->isOfType(SoVRMLAction::getClassTypeId())) { |
| 1125 |
auto vrmlAction = static_cast<SoVRMLAction*>(action); |
| 1126 |
if (vrmlAction->overrideMode) { |
| 1127 |
auto bind = static_cast<SoNormalBinding*>(node); |
| 1128 |
vrmlAction->bindList.push_back(bind->value.getValue()); |
| 1129 |
// this normal binding causes some problems for the part view provider |
| 1130 |
// See also #0002222: Number of normals in exported VRML is wrong |
| 1131 |
if (bind->value.getValue() == static_cast<int>(SoNormalBinding::PER_VERTEX_INDEXED)) { |
| 1132 |
bind->value = SoNormalBinding::OVERALL; |
| 1133 |
} |
| 1134 |
} |
| 1135 |
else if (!vrmlAction->bindList.empty()) { |
| 1136 |
static_cast<SoNormalBinding*>(node)->value = static_cast<SoNormalBinding::Binding>( |
| 1137 |
vrmlAction->bindList.front() |
| 1138 |
); |
| 1139 |
vrmlAction->bindList.pop_front(); |
| 1140 |
} |
| 1141 |
} |
| 1142 |
|
| 1143 |
node->doAction(action); |
| 1144 |
} |
| 1145 |
|
| 1146 |
// --------------------------------------------------------------------------------- |
| 1147 |
|
| 1148 |
bool SoFCSelectionRoot::StackComp::operator()(const Stack& a, const Stack& b) const |
| 1149 |
{ |
| 1150 |
if (a.size() - a.offset < b.size() - b.offset) { |
| 1151 |
return true; |
| 1152 |
} |
| 1153 |
if (a.size() - a.offset > b.size() - b.offset) { |
| 1154 |
return false; |
| 1155 |
} |
| 1156 |
auto it1 = a.rbegin(), end1 = a.rend() - a.offset; |
| 1157 |
auto it2 = b.rbegin(); |
| 1158 |
for (; it1 != end1; ++it1, ++it2) { |
| 1159 |
if (*it1 < *it2) { |
| 1160 |
return true; |
| 1161 |
} |
| 1162 |
if (*it1 > *it2) { |
| 1163 |
return false; |
| 1164 |
} |
| 1165 |
} |
| 1166 |
return false; |
| 1167 |
} |
| 1168 |
// --------------------------------------------------------------------------------- |
| 1169 |
SoSeparator::CacheEnabled SoFCSeparator::CacheMode = SoSeparator::AUTO; |
| 1170 |
SO_NODE_SOURCE(SoFCSeparator) |
| 1171 |
|
| 1172 |
SoFCSeparator::SoFCSeparator(bool trackCacheMode) |
| 1173 |
: trackCacheMode(trackCacheMode) |
| 1174 |
{ |
| 1175 |
SO_NODE_CONSTRUCTOR(SoFCSeparator); |
| 1176 |
if (!trackCacheMode) { |
| 1177 |
renderCaching = SoSeparator::OFF; |
| 1178 |
boundingBoxCaching = SoSeparator::OFF; |
| 1179 |
} |
| 1180 |
} |
| 1181 |
|
| 1182 |
void SoFCSeparator::GLRenderBelowPath(SoGLRenderAction* action) |
| 1183 |
{ |
| 1184 |
if (trackCacheMode && renderCaching.getValue() != CacheMode) { |
| 1185 |
renderCaching = CacheMode; |
| 1186 |
boundingBoxCaching = CacheMode; |
| 1187 |
} |
| 1188 |
inherited::GLRenderBelowPath(action); |
| 1189 |
} |
| 1190 |
|
| 1191 |
void SoFCSeparator::initClass() |
| 1192 |
{ |
| 1193 |
SO_NODE_INIT_CLASS(SoFCSeparator, SoSeparator, "FCSeparator"); |
| 1194 |
} |
| 1195 |
|
| 1196 |
void SoFCSeparator::finish() |
| 1197 |
{ |
| 1198 |
atexit_cleanup(); |
| 1199 |
} |
| 1200 |
|
| 1201 |
// --------------------------------------------------------------------------------- |
| 1202 |
// Thread local data for bounding box rendering |
| 1203 |
// |
| 1204 |
// The code is inspred by Coin SoLevelOfDetails.cpp. |
| 1205 |
using SoFCBBoxRenderInfo = struct |
| 1206 |
{ |
| 1207 |
SoGetBoundingBoxAction* bboxaction; |
| 1208 |
SoCube* cube; |
| 1209 |
SoColorPacker* packer; |
| 1210 |
}; |
| 1211 |
|
| 1212 |
static void so_bbox_construct_data(void* closure) |
| 1213 |
{ |
| 1214 |
auto data = static_cast<SoFCBBoxRenderInfo*>(closure); |
| 1215 |
data->bboxaction = nullptr; |
| 1216 |
data->cube = nullptr; |
| 1217 |
data->packer = nullptr; |
| 1218 |
} |
| 1219 |
|
| 1220 |
static void so_bbox_destruct_data(void* closure) |
| 1221 |
{ |
| 1222 |
auto data = static_cast<SoFCBBoxRenderInfo*>(closure); |
| 1223 |
delete data->bboxaction; |
| 1224 |
if (data->cube) { |
| 1225 |
data->cube->unref(); |
| 1226 |
} |
| 1227 |
delete data->packer; |
| 1228 |
} |
| 1229 |
|
| 1230 |
static SbStorage* so_bbox_storage = nullptr; |
| 1231 |
|
| 1232 |
// called from atexit |
| 1233 |
static void so_bbox_cleanup() |
| 1234 |
{ |
| 1235 |
delete so_bbox_storage; |
| 1236 |
} |
| 1237 |
|
| 1238 |
// --------------------------------------------------------------------------------- |
| 1239 |
|
| 1240 |
SoFCSelectionRoot::Stack SoFCSelectionRoot::SelStack; |
| 1241 |
std::unordered_map<SoAction*, SoFCSelectionRoot::Stack> SoFCSelectionRoot::ActionStacks; |
| 1242 |
SoFCSelectionRoot::ColorStack SoFCSelectionRoot::SelColorStack; |
| 1243 |
SoFCSelectionRoot::ColorStack SoFCSelectionRoot::HlColorStack; |
| 1244 |
SoFCSelectionRoot* SoFCSelectionRoot::ShapeColorNode; |
| 1245 |
|
| 1246 |
SO_NODE_SOURCE(SoFCSelectionRoot) |
| 1247 |
|
| 1248 |
SoFCSelectionRoot::SoFCSelectionRoot(bool trackCacheMode) |
| 1249 |
: SoFCSeparator(trackCacheMode) |
| 1250 |
{ |
| 1251 |
SO_NODE_CONSTRUCTOR(SoFCSelectionRoot); |
| 1252 |
SO_NODE_ADD_FIELD(selectionStyle, (Full)); |
| 1253 |
SO_NODE_DEFINE_ENUM_VALUE(SelectStyles, Full); |
| 1254 |
SO_NODE_DEFINE_ENUM_VALUE(SelectStyles, Box); |
| 1255 |
SO_NODE_DEFINE_ENUM_VALUE(SelectStyles, PassThrough); |
| 1256 |
SO_NODE_SET_SF_ENUM_TYPE(selectionStyle, SelectStyles); |
| 1257 |
} |
| 1258 |
|
| 1259 |
SoFCSelectionRoot::~SoFCSelectionRoot() = default; |
| 1260 |
|
| 1261 |
void SoFCSelectionRoot::initClass() |
| 1262 |
{ |
| 1263 |
SO_NODE_INIT_CLASS(SoFCSelectionRoot, SoFCSeparator, "FCSelectionRoot"); |
| 1264 |
|
| 1265 |
so_bbox_storage |
| 1266 |
= new SbStorage(sizeof(SoFCBBoxRenderInfo), so_bbox_construct_data, so_bbox_destruct_data); |
| 1267 |
|
| 1268 |
// cc_coin_atexit((coin_atexit_f*) so_bbox_cleanup); |
| 1269 |
} |
| 1270 |
|
| 1271 |
void SoFCSelectionRoot::finish() |
| 1272 |
{ |
| 1273 |
so_bbox_cleanup(); |
| 1274 |
atexit_cleanup(); |
| 1275 |
} |
| 1276 |
|
| 1277 |
SoNode* SoFCSelectionRoot::getCurrentRoot(bool front, SoNode* def) |
| 1278 |
{ |
| 1279 |
if (!SelStack.empty()) { |
| 1280 |
return front ? SelStack.front() : SelStack.back(); |
| 1281 |
} |
| 1282 |
return def; |
| 1283 |
} |
| 1284 |
|
| 1285 |
SoFCSelectionContextBasePtr SoFCSelectionRoot::getNodeContext( |
| 1286 |
Stack& stack, |
| 1287 |
SoNode* node, |
| 1288 |
SoFCSelectionContextBasePtr def |
| 1289 |
) |
| 1290 |
{ |
| 1291 |
if (stack.empty()) { |
| 1292 |
return def; |
| 1293 |
} |
| 1294 |
|
| 1295 |
auto front = dynamic_cast<SoFCSelectionRoot*>(stack.front()); |
| 1296 |
if (front == nullptr) { |
| 1297 |
return SoFCSelectionContextBasePtr(); |
| 1298 |
} |
| 1299 |
|
| 1300 |
stack.front() = node; |
| 1301 |
|
| 1302 |
auto it = front->contextMap.find(stack); |
| 1303 |
stack.front() = front; |
| 1304 |
if (it != front->contextMap.end()) { |
| 1305 |
return it->second; |
| 1306 |
} |
| 1307 |
return {}; |
| 1308 |
} |
| 1309 |
|
| 1310 |
SoFCSelectionContextBasePtr SoFCSelectionRoot::getNodeContext2( |
| 1311 |
Stack& stack, |
| 1312 |
SoNode* node, |
| 1313 |
SoFCSelectionContextBase::MergeFunc* merge |
| 1314 |
) |
| 1315 |
{ |
| 1316 |
SoFCSelectionContextBasePtr ret; |
| 1317 |
if (stack.empty()) { |
| 1318 |
return ret; |
| 1319 |
} |
| 1320 |
|
| 1321 |
auto* back = dynamic_cast<SoFCSelectionRoot*>(stack.back()); |
| 1322 |
if (back == nullptr || back->contextMap2.empty()) { |
| 1323 |
return ret; |
| 1324 |
} |
| 1325 |
|
| 1326 |
int status = 0; |
| 1327 |
auto& map = back->contextMap2; |
| 1328 |
stack.back() = node; |
| 1329 |
for (stack.offset = 0; stack.offset < stack.size(); ++stack.offset) { |
| 1330 |
auto it = map.find(stack); |
| 1331 |
SoFCSelectionContextBasePtr ctx; |
| 1332 |
if (it != map.end()) { |
| 1333 |
ctx = it->second; |
| 1334 |
} |
| 1335 |
status |
| 1336 |
= merge(status, ret, ctx, stack.offset == stack.size() - 1 ? nullptr : stack[stack.offset]); |
| 1337 |
if (status < 0) { |
| 1338 |
break; |
| 1339 |
} |
| 1340 |
} |
| 1341 |
stack.offset = 0; |
| 1342 |
stack.back() = back; |
| 1343 |
return ret; |
| 1344 |
} |
| 1345 |
|
| 1346 |
std::pair<bool, SoFCSelectionContextBasePtr*> SoFCSelectionRoot::findActionContext( |
| 1347 |
SoAction* action, |
| 1348 |
SoNode* _node, |
| 1349 |
bool create, |
| 1350 |
bool erase |
| 1351 |
) |
| 1352 |
{ |
| 1353 |
std::pair<bool, SoFCSelectionContextBasePtr*> res(false, 0); |
| 1354 |
|
| 1355 |
if (action->isOfType(SoSelectionElementAction::getClassTypeId())) { |
| 1356 |
res.first = static_cast<SoSelectionElementAction*>(action)->isSecondary(); |
| 1357 |
} |
| 1358 |
|
| 1359 |
auto it = ActionStacks.find(action); |
| 1360 |
if (it == ActionStacks.end() || it->second.empty()) { |
| 1361 |
return res; |
| 1362 |
} |
| 1363 |
|
| 1364 |
auto& stack = it->second; |
| 1365 |
|
| 1366 |
if (res.first) { |
| 1367 |
auto back = dynamic_cast<SoFCSelectionRoot*>(stack.back()); |
| 1368 |
if (back != nullptr) { |
| 1369 |
stack.back() = _node; |
| 1370 |
if (create) { |
| 1371 |
res.second = &back->contextMap2[stack]; |
| 1372 |
} |
| 1373 |
else { |
| 1374 |
auto it = back->contextMap2.find(stack); |
| 1375 |
if (it != back->contextMap2.end()) { |
| 1376 |
res.second = &it->second; |
| 1377 |
if (erase) { |
| 1378 |
back->contextMap2.erase(it); |
| 1379 |
} |
| 1380 |
} |
| 1381 |
} |
| 1382 |
stack.back() = back; |
| 1383 |
} |
| 1384 |
} |
| 1385 |
else { |
| 1386 |
auto front = dynamic_cast<SoFCSelectionRoot*>(stack.front()); |
| 1387 |
if (front != nullptr) { |
| 1388 |
stack.front() = _node; |
| 1389 |
if (create) { |
| 1390 |
res.second = &front->contextMap[stack]; |
| 1391 |
} |
| 1392 |
else { |
| 1393 |
auto it = front->contextMap.find(stack); |
| 1394 |
if (it != front->contextMap.end()) { |
| 1395 |
res.second = &it->second; |
| 1396 |
if (erase) { |
| 1397 |
front->contextMap.erase(it); |
| 1398 |
} |
| 1399 |
} |
| 1400 |
} |
| 1401 |
stack.front() = front; |
| 1402 |
} |
| 1403 |
} |
| 1404 |
return res; |
| 1405 |
} |
| 1406 |
|
| 1407 |
bool SoFCSelectionRoot::renderBBox(SoGLRenderAction* action, SoNode* node, SbColor color) |
| 1408 |
{ |
| 1409 |
auto data = static_cast<SoFCBBoxRenderInfo*>(so_bbox_storage->get()); |
| 1410 |
if (!data->bboxaction) { |
| 1411 |
// The viewport region will be replaced every time the action is |
| 1412 |
// used, so we can just feed it a dummy here. |
| 1413 |
data->bboxaction = new SoGetBoundingBoxAction(SbViewportRegion()); |
| 1414 |
data->cube = new SoCube; |
| 1415 |
data->cube->ref(); |
| 1416 |
data->packer = new SoColorPacker; |
| 1417 |
} |
| 1418 |
|
| 1419 |
SbBox3f bbox; |
| 1420 |
data->bboxaction->setViewportRegion(action->getViewportRegion()); |
| 1421 |
data->bboxaction->apply(node); |
| 1422 |
bbox = data->bboxaction->getBoundingBox(); |
| 1423 |
if (bbox.isEmpty()) { |
| 1424 |
return false; |
| 1425 |
} |
| 1426 |
|
| 1427 |
auto state = action->getState(); |
| 1428 |
|
| 1429 |
state->push(); |
| 1430 |
|
| 1431 |
SoMaterialBindingElement::set(state, SoMaterialBindingElement::OVERALL); |
| 1432 |
SoLazyElement::setEmissive(state, &color); |
| 1433 |
SoLazyElement::setDiffuse(state, node, 1, &color, data->packer); |
| 1434 |
SoDrawStyleElement::set(state, node, SoDrawStyleElement::LINES); |
| 1435 |
SoLineWidthElement::set(state, node, 1.0f); |
| 1436 |
|
| 1437 |
const static float trans = 0.0; |
| 1438 |
SoLazyElement::setTransparency(state, node, 1, &trans, data->packer); |
| 1439 |
|
| 1440 |
float x, y, z; |
| 1441 |
bbox.getSize(x, y, z); |
| 1442 |
data->cube->width = x + 0.001; |
| 1443 |
data->cube->height = y + 0.001; |
| 1444 |
data->cube->depth = z + 0.001; |
| 1445 |
|
| 1446 |
SoModelMatrixElement::translateBy(state, node, bbox.getCenter()); |
| 1447 |
|
| 1448 |
SoMaterialBundle mb(action); |
| 1449 |
mb.sendFirst(); |
| 1450 |
|
| 1451 |
data->cube->GLRender(action); |
| 1452 |
|
| 1453 |
state->pop(); |
| 1454 |
return true; |
| 1455 |
} |
| 1456 |
|
| 1457 |
static std::time_t _CyclicLastReported; |
| 1458 |
|
| 1459 |
void SoFCSelectionRoot::renderPrivate(SoGLRenderAction* action, bool inPath) |
| 1460 |
{ |
| 1461 |
if (ViewParams::instance()->getCoinCycleCheck() && !SelStack.nodeSet.insert(this).second) { |
| 1462 |
std::time_t t = std::time(nullptr); |
| 1463 |
if (_CyclicLastReported < t) { |
| 1464 |
_CyclicLastReported = t + 5; |
| 1465 |
FC_ERR("Cyclic scene graph: " << getName()); |
| 1466 |
} |
| 1467 |
return; |
| 1468 |
} |
| 1469 |
SelStack.push_back(this); |
| 1470 |
if (_renderPrivate(action, inPath)) { |
| 1471 |
if (inPath) { |
| 1472 |
SoSeparator::GLRenderInPath(action); |
| 1473 |
} |
| 1474 |
else { |
| 1475 |
SoSeparator::GLRenderBelowPath(action); |
| 1476 |
} |
| 1477 |
} |
| 1478 |
SelStack.pop_back(); |
| 1479 |
SelStack.nodeSet.erase(this); |
| 1480 |
} |
| 1481 |
|
| 1482 |
bool SoFCSelectionRoot::_renderPrivate(SoGLRenderAction* action, bool inPath) |
| 1483 |
{ |
| 1484 |
auto ctx2 = std::static_pointer_cast<SelContext>( |
| 1485 |
getNodeContext2(SelStack, this, SelContext::merge) |
| 1486 |
); |
| 1487 |
if (ctx2 && ctx2->hideAll) { |
| 1488 |
return false; |
| 1489 |
} |
| 1490 |
|
| 1491 |
auto state = action->getState(); |
| 1492 |
SelContextPtr ctx = getRenderContext<SelContext>(this); |
| 1493 |
int style = selectionStyle.getValue(); |
| 1494 |
if ((style == SoFCSelectionRoot::Box || ViewParams::instance()->getShowSelectionBoundingBox()) |
| 1495 |
&& ctx && !ctx->hideAll && (ctx->selAll || ctx->hlAll)) { |
| 1496 |
if (style == SoFCSelectionRoot::PassThrough) { |
| 1497 |
style = SoFCSelectionRoot::Box; |
| 1498 |
} |
| 1499 |
else { |
| 1500 |
renderBBox(action, this, ctx->hlAll ? ctx->hlColor : ctx->selColor); |
| 1501 |
return true; |
| 1502 |
} |
| 1503 |
} |
| 1504 |
|
| 1505 |
// Here, we are not setting (pre)selection color override here. |
| 1506 |
// Instead, we are checking and setting up for any secondary context |
| 1507 |
// color override. |
| 1508 |
// |
| 1509 |
// When the current selection style is full highlight, we should ignore any |
| 1510 |
// secondary override. If the style is bounding box, however, we should |
| 1511 |
// honour the secondary color override. |
| 1512 |
|
| 1513 |
bool colorPushed = false; |
| 1514 |
if (!ShapeColorNode && overrideColor && !SoOverrideElement::getDiffuseColorOverride(state) |
| 1515 |
&& (style == SoFCSelectionRoot::Box || !ctx || (!ctx->selAll && !ctx->hideAll))) { |
| 1516 |
ShapeColorNode = this; |
| 1517 |
colorPushed = true; |
| 1518 |
state->push(); |
| 1519 |
auto& packer = ShapeColorNode->shapeColorPacker; |
| 1520 |
auto& trans = ShapeColorNode->transOverride; |
| 1521 |
auto& color = ShapeColorNode->colorOverride; |
| 1522 |
if (!SoOverrideElement::getTransparencyOverride(state)) { |
| 1523 |
SoLazyElement::setTransparency(state, ShapeColorNode, 1, &trans, &packer); |
| 1524 |
SoOverrideElement::setTransparencyOverride(state, ShapeColorNode, true); |
| 1525 |
} |
| 1526 |
SoLazyElement::setDiffuse(state, ShapeColorNode, 1, &color, &packer); |
| 1527 |
SoOverrideElement::setDiffuseColorOverride(state, ShapeColorNode, true); |
| 1528 |
SoMaterialBindingElement::set(state, ShapeColorNode, SoMaterialBindingElement::OVERALL); |
| 1529 |
SoOverrideElement::setMaterialBindingOverride(state, ShapeColorNode, true); |
| 1530 |
|
| 1531 |
SoTextureEnabledElement::set(state, ShapeColorNode, false); |
| 1532 |
} |
| 1533 |
|
| 1534 |
if (!ctx) { |
| 1535 |
if (inPath) { |
| 1536 |
SoSeparator::GLRenderInPath(action); |
| 1537 |
} |
| 1538 |
else { |
| 1539 |
SoSeparator::GLRenderBelowPath(action); |
| 1540 |
} |
| 1541 |
} |
| 1542 |
else { |
| 1543 |
bool selPushed; |
| 1544 |
bool hlPushed; |
| 1545 |
if ((selPushed = ctx->selAll)) { |
| 1546 |
SelColorStack.push_back(ctx->selColor); |
| 1547 |
|
| 1548 |
if (style != SoFCSelectionRoot::Box) { |
| 1549 |
state->push(); |
| 1550 |
auto& color = SelColorStack.back(); |
| 1551 |
SoLazyElement::setEmissive(state, &color); |
| 1552 |
SoOverrideElement::setEmissiveColorOverride(state, this, true); |
| 1553 |
if (SoLazyElement::getLightModel(state) == SoLazyElement::BASE_COLOR) { |
| 1554 |
auto& packer = shapeColorPacker; |
| 1555 |
SoLazyElement::setDiffuse(state, this, 1, &color, &packer); |
| 1556 |
SoOverrideElement::setDiffuseColorOverride(state, this, true); |
| 1557 |
SoMaterialBindingElement::set(state, this, SoMaterialBindingElement::OVERALL); |
| 1558 |
SoOverrideElement::setMaterialBindingOverride(state, this, true); |
| 1559 |
} |
| 1560 |
} |
| 1561 |
} |
| 1562 |
|
| 1563 |
if ((hlPushed = ctx->hlAll)) { |
| 1564 |
HlColorStack.push_back(ctx->hlColor); |
| 1565 |
} |
| 1566 |
|
| 1567 |
if (inPath) { |
| 1568 |
SoSeparator::GLRenderInPath(action); |
| 1569 |
} |
| 1570 |
else { |
| 1571 |
SoSeparator::GLRenderBelowPath(action); |
| 1572 |
} |
| 1573 |
|
| 1574 |
if (selPushed) { |
| 1575 |
SelColorStack.pop_back(); |
| 1576 |
|
| 1577 |
if (style != SoFCSelectionRoot::Box) { |
| 1578 |
state->pop(); |
| 1579 |
} |
| 1580 |
} |
| 1581 |
if (hlPushed) { |
| 1582 |
HlColorStack.pop_back(); |
| 1583 |
} |
| 1584 |
} |
| 1585 |
|
| 1586 |
if (colorPushed) { |
| 1587 |
ShapeColorNode = nullptr; |
| 1588 |
state->pop(); |
| 1589 |
} |
| 1590 |
|
| 1591 |
return false; |
| 1592 |
} |
| 1593 |
|
| 1594 |
void SoFCSelectionRoot::GLRenderBelowPath(SoGLRenderAction* action) |
| 1595 |
{ |
| 1596 |
renderPrivate(action, false); |
| 1597 |
} |
| 1598 |
|
| 1599 |
void SoFCSelectionRoot::GLRenderInPath(SoGLRenderAction* action) |
| 1600 |
{ |
| 1601 |
if (action->getCurPathCode() == SoAction::BELOW_PATH) { |
| 1602 |
return GLRenderBelowPath(action); |
| 1603 |
} |
| 1604 |
renderPrivate(action, true); |
| 1605 |
} |
| 1606 |
|
| 1607 |
bool SoFCSelectionRoot::checkColorOverride(SoState* state) |
| 1608 |
{ |
| 1609 |
if (ShapeColorNode) { |
| 1610 |
if (!SoOverrideElement::getDiffuseColorOverride(state)) { |
| 1611 |
state->push(); |
| 1612 |
auto& packer = ShapeColorNode->shapeColorPacker; |
| 1613 |
auto& trans = ShapeColorNode->transOverride; |
| 1614 |
auto& color = ShapeColorNode->colorOverride; |
| 1615 |
if (!SoOverrideElement::getTransparencyOverride(state)) { |
| 1616 |
SoLazyElement::setTransparency(state, ShapeColorNode, 1, &trans, &packer); |
| 1617 |
SoOverrideElement::setTransparencyOverride(state, ShapeColorNode, true); |
| 1618 |
} |
| 1619 |
SoLazyElement::setDiffuse(state, ShapeColorNode, 1, &color, &packer); |
| 1620 |
SoOverrideElement::setDiffuseColorOverride(state, ShapeColorNode, true); |
| 1621 |
SoMaterialBindingElement::set(state, ShapeColorNode, SoMaterialBindingElement::OVERALL); |
| 1622 |
SoOverrideElement::setMaterialBindingOverride(state, ShapeColorNode, true); |
| 1623 |
|
| 1624 |
SoTextureEnabledElement::set(state, ShapeColorNode, false); |
| 1625 |
return true; |
| 1626 |
} |
| 1627 |
} |
| 1628 |
return false; |
| 1629 |
} |
| 1630 |
|
| 1631 |
void SoFCSelectionRoot::checkSelection(bool& sel, SbColor& selColor, bool& hl, SbColor& hlColor) |
| 1632 |
{ |
| 1633 |
sel = false; |
| 1634 |
hl = false; |
| 1635 |
if ((sel = !SelColorStack.empty())) { |
| 1636 |
selColor = SelColorStack.back(); |
| 1637 |
} |
| 1638 |
if ((hl = !HlColorStack.empty())) { |
| 1639 |
hlColor = HlColorStack.back(); |
| 1640 |
} |
| 1641 |
} |
| 1642 |
|
| 1643 |
void SoFCSelectionRoot::resetContext() |
| 1644 |
{ |
| 1645 |
contextMap.clear(); |
| 1646 |
} |
| 1647 |
|
| 1648 |
void SoFCSelectionRoot::moveActionStack(SoAction* from, SoAction* to, bool erase) |
| 1649 |
{ |
| 1650 |
auto it = ActionStacks.find(from); |
| 1651 |
if (it == ActionStacks.end()) { |
| 1652 |
return; |
| 1653 |
} |
| 1654 |
auto& stack = ActionStacks[to]; |
| 1655 |
assert(stack.empty()); |
| 1656 |
stack.swap(it->second); |
| 1657 |
if (erase) { |
| 1658 |
ActionStacks.erase(it); |
| 1659 |
} |
| 1660 |
} |
| 1661 |
|
| 1662 |
#define BEGIN_ACTION \ |
| 1663 |
auto& stack = ActionStacks[action]; \ |
| 1664 |
if (ViewParams::instance()->getCoinCycleCheck() && !stack.nodeSet.insert(this).second) { \ |
| 1665 |
std::time_t t = std::time(0); \ |
| 1666 |
if (_CyclicLastReported < t) { \ |
| 1667 |
_CyclicLastReported = t + 5; \ |
| 1668 |
FC_ERR("Cyclic scene graph: " << getName()); \ |
| 1669 |
} \ |
| 1670 |
return; \ |
| 1671 |
} \ |
| 1672 |
stack.push_back(this); \ |
| 1673 |
auto size = stack.size(); |
| 1674 |
|
| 1675 |
#define END_ACTION \ |
| 1676 |
if (stack.size() != size || stack.back() != this) \ |
| 1677 |
FC_ERR("action stack fault"); \ |
| 1678 |
else { \ |
| 1679 |
stack.nodeSet.erase(this); \ |
| 1680 |
stack.pop_back(); \ |
| 1681 |
if (stack.empty()) \ |
| 1682 |
ActionStacks.erase(action); \ |
| 1683 |
} |
| 1684 |
|
| 1685 |
void SoFCSelectionRoot::pick(SoPickAction* action) |
| 1686 |
{ |
| 1687 |
BEGIN_ACTION; |
| 1688 |
if (doActionPrivate(stack, action)) { |
| 1689 |
inherited::pick(action); |
| 1690 |
} |
| 1691 |
END_ACTION; |
| 1692 |
} |
| 1693 |
|
| 1694 |
void SoFCSelectionRoot::rayPick(SoRayPickAction* action) |
| 1695 |
{ |
| 1696 |
BEGIN_ACTION; |
| 1697 |
if (doActionPrivate(stack, action)) { |
| 1698 |
inherited::rayPick(action); |
| 1699 |
} |
| 1700 |
END_ACTION; |
| 1701 |
} |
| 1702 |
|
| 1703 |
void SoFCSelectionRoot::handleEvent(SoHandleEventAction* action) |
| 1704 |
{ |
| 1705 |
BEGIN_ACTION; |
| 1706 |
inherited::handleEvent(action); |
| 1707 |
END_ACTION; |
| 1708 |
} |
| 1709 |
|
| 1710 |
void SoFCSelectionRoot::search(SoSearchAction* action) |
| 1711 |
{ |
| 1712 |
BEGIN_ACTION; |
| 1713 |
inherited::search(action); |
| 1714 |
END_ACTION; |
| 1715 |
} |
| 1716 |
|
| 1717 |
void SoFCSelectionRoot::getPrimitiveCount(SoGetPrimitiveCountAction* action) |
| 1718 |
{ |
| 1719 |
BEGIN_ACTION; |
| 1720 |
inherited::getPrimitiveCount(action); |
| 1721 |
END_ACTION; |
| 1722 |
} |
| 1723 |
|
| 1724 |
void SoFCSelectionRoot::getBoundingBox(SoGetBoundingBoxAction* action) |
| 1725 |
{ |
| 1726 |
BEGIN_ACTION; |
| 1727 |
if (doActionPrivate(stack, action)) { |
| 1728 |
inherited::getBoundingBox(action); |
| 1729 |
} |
| 1730 |
END_ACTION; |
| 1731 |
} |
| 1732 |
|
| 1733 |
void SoFCSelectionRoot::getMatrix(SoGetMatrixAction* action) |
| 1734 |
{ |
| 1735 |
BEGIN_ACTION; |
| 1736 |
if (doActionPrivate(stack, action)) { |
| 1737 |
inherited::getMatrix(action); |
| 1738 |
} |
| 1739 |
END_ACTION; |
| 1740 |
} |
| 1741 |
|
| 1742 |
void SoFCSelectionRoot::callback(SoCallbackAction* action) |
| 1743 |
{ |
| 1744 |
BEGIN_ACTION; |
| 1745 |
inherited::callback(action); |
| 1746 |
END_ACTION; |
| 1747 |
} |
| 1748 |
|
| 1749 |
void SoFCSelectionRoot::doAction(SoAction* action) |
| 1750 |
{ |
| 1751 |
BEGIN_ACTION |
| 1752 |
if (doActionPrivate(stack, action)) { |
| 1753 |
inherited::doAction(action); |
| 1754 |
} |
| 1755 |
END_ACTION |
| 1756 |
} |
| 1757 |
|
| 1758 |
bool SoFCSelectionRoot::doActionPrivate(Stack& stack, SoAction* action) |
| 1759 |
{ |
| 1760 |
// Selection action short-circuit optimization. In case of whole object |
| 1761 |
// selection/preselection, we shall store a SelContext keyed by ourself. |
| 1762 |
// And the action traversal can be short-curcuited once the first targeted |
| 1763 |
// SoFCSelectionRoot is found here. New function checkSelection() is exposed |
| 1764 |
// to check for whole object selection. This greatly improve performance on |
| 1765 |
// large group. |
| 1766 |
|
| 1767 |
SelContextPtr ctx2; |
| 1768 |
bool ctx2Searched = false; |
| 1769 |
bool isTail = false; |
| 1770 |
if (action->getCurPathCode() == SoAction::IN_PATH) { |
| 1771 |
auto path = action->getPathAppliedTo(); |
| 1772 |
if (path) { |
| 1773 |
isTail = path->getTail() == this |
| 1774 |
|| (path->getLength() > 1 && path->getNodeFromTail(1) == this |
| 1775 |
&& path->getTail()->isOfType(SoSwitch::getClassTypeId())); |
| 1776 |
} |
| 1777 |
|
| 1778 |
if (!action->isOfType(SoSelectionElementAction::getClassTypeId())) { |
| 1779 |
ctx2Searched = true; |
| 1780 |
ctx2 = std::static_pointer_cast<SelContext>( |
| 1781 |
getNodeContext2(stack, this, SelContext::merge) |
| 1782 |
); |
| 1783 |
if (ctx2 && ctx2->hideAll) { |
| 1784 |
return false; |
| 1785 |
} |
| 1786 |
} |
| 1787 |
if (!isTail) { |
| 1788 |
return true; |
| 1789 |
} |
| 1790 |
} |
| 1791 |
else if (action->getWhatAppliedTo() != SoAction::NODE |
| 1792 |
&& action->getCurPathCode() != SoAction::BELOW_PATH) { |
| 1793 |
return true; |
| 1794 |
} |
| 1795 |
|
| 1796 |
if (action->isOfType(SoSelectionElementAction::getClassTypeId())) { |
| 1797 |
auto selAction = static_cast<SoSelectionElementAction*>(action); |
| 1798 |
if (selAction->isSecondary()) { |
| 1799 |
if (selAction->getType() == SoSelectionElementAction::Show |
| 1800 |
|| (selAction->getType() == SoSelectionElementAction::Color |
| 1801 |
&& selAction->getColors().empty() |
| 1802 |
&& action->getWhatAppliedTo() == SoAction::NODE)) { |
| 1803 |
auto ctx = getActionContext(action, this, SelContextPtr(), false); |
| 1804 |
if (ctx && ctx->hideAll) { |
| 1805 |
ctx->hideAll = false; |
| 1806 |
if (!ctx->hlAll && !ctx->selAll) { |
| 1807 |
removeActionContext(action, this); |
| 1808 |
} |
| 1809 |
touch(); |
| 1810 |
} |
| 1811 |
// applied to a node means clear all visibility setting, so |
| 1812 |
// return true to propagate the action |
| 1813 |
return selAction->getType() == SoSelectionElementAction::Color |
| 1814 |
|| action->getWhatAppliedTo() == SoAction::NODE; |
| 1815 |
} |
| 1816 |
else if (selAction->getType() == SoSelectionElementAction::Hide) { |
| 1817 |
if (action->getCurPathCode() == SoAction::BELOW_PATH || isTail) { |
| 1818 |
auto ctx = getActionContext(action, this, SelContextPtr()); |
| 1819 |
if (ctx && !ctx->hideAll) { |
| 1820 |
ctx->hideAll = true; |
| 1821 |
touch(); |
| 1822 |
} |
| 1823 |
return false; |
| 1824 |
} |
| 1825 |
} |
| 1826 |
return true; |
| 1827 |
} |
| 1828 |
|
| 1829 |
if (selAction->getType() == SoSelectionElementAction::None) { |
| 1830 |
if (action->getWhatAppliedTo() == SoAction::NODE) { |
| 1831 |
// Here the 'select none' action is applied to a node, and we |
| 1832 |
// are the first SoFCSelectionRoot encountered (which means all |
| 1833 |
// children stores selection context here, both whole object |
| 1834 |
// and element selection), then we can simply perform the |
| 1835 |
// action by clearing the selection context here, and save the |
| 1836 |
// time for traversing a potentially large amount of children |
| 1837 |
// nodes. |
| 1838 |
resetContext(); |
| 1839 |
touch(); |
| 1840 |
return false; |
| 1841 |
} |
| 1842 |
|
| 1843 |
auto ctx = getActionContext(action, this, SelContextPtr(), false); |
| 1844 |
if (ctx && ctx->selAll) { |
| 1845 |
ctx->selAll = false; |
| 1846 |
touch(); |
| 1847 |
return false; |
| 1848 |
} |
| 1849 |
} |
| 1850 |
else if (selAction->getType() == SoSelectionElementAction::All) { |
| 1851 |
auto ctx = getActionContext(action, this, SelContextPtr()); |
| 1852 |
assert(ctx); |
| 1853 |
ctx->selAll = true; |
| 1854 |
ctx->selColor = selAction->getColor(); |
| 1855 |
touch(); |
| 1856 |
return false; |
| 1857 |
} |
| 1858 |
return true; |
| 1859 |
} |
| 1860 |
|
| 1861 |
if (action->isOfType(SoHighlightElementAction::getClassTypeId())) { |
| 1862 |
auto highlightAction = static_cast<SoHighlightElementAction*>(action); |
| 1863 |
if (highlightAction->isHighlighted()) { |
| 1864 |
if (highlightAction->getElement()) { |
| 1865 |
auto ctx = getActionContext(action, this, SelContextPtr(), false); |
| 1866 |
if (ctx && ctx->hlAll) { |
| 1867 |
ctx->hlAll = false; |
| 1868 |
touch(); |
| 1869 |
} |
| 1870 |
} |
| 1871 |
else { |
| 1872 |
auto ctx = getActionContext(action, this, SelContextPtr()); |
| 1873 |
assert(ctx); |
| 1874 |
ctx->hlAll = true; |
| 1875 |
ctx->hlColor = highlightAction->getColor(); |
| 1876 |
touch(); |
| 1877 |
return false; |
| 1878 |
} |
| 1879 |
} |
| 1880 |
else { |
| 1881 |
auto ctx = getActionContext(action, this, SelContextPtr(), false); |
| 1882 |
if (ctx && ctx->hlAll) { |
| 1883 |
ctx->hlAll = false; |
| 1884 |
touch(); |
| 1885 |
return false; |
| 1886 |
} |
| 1887 |
} |
| 1888 |
return true; |
| 1889 |
} |
| 1890 |
|
| 1891 |
if (!ctx2Searched) { |
| 1892 |
ctx2 = std::static_pointer_cast<SelContext>(getNodeContext2(stack, this, SelContext::merge)); |
| 1893 |
if (ctx2 && ctx2->hideAll) { |
| 1894 |
return false; |
| 1895 |
} |
| 1896 |
} |
| 1897 |
return true; |
| 1898 |
} |
| 1899 |
|
| 1900 |
int SoFCSelectionRoot::SelContext::merge( |
| 1901 |
int status, |
| 1902 |
SoFCSelectionContextBasePtr& output, |
| 1903 |
SoFCSelectionContextBasePtr input, |
| 1904 |
SoNode* |
| 1905 |
) |
| 1906 |
{ |
| 1907 |
auto ctx = std::dynamic_pointer_cast<SelContext>(input); |
| 1908 |
if (ctx && ctx->hideAll) { |
| 1909 |
output = ctx; |
| 1910 |
return -1; |
| 1911 |
} |
| 1912 |
return status; |
| 1913 |
} |
| 1914 |
|
| 1915 |
///////////////////////////////////////////////////////////////////////////// |
| 1916 |
|
| 1917 |
SO_NODE_SOURCE(SoFCPathAnnotation) |
| 1918 |
|
| 1919 |
SoFCPathAnnotation::SoFCPathAnnotation() |
| 1920 |
{ |
| 1921 |
SO_NODE_CONSTRUCTOR(SoFCPathAnnotation); |
| 1922 |
path = nullptr; |
| 1923 |
tmpPath = nullptr; |
| 1924 |
det = nullptr; |
| 1925 |
} |
| 1926 |
|
| 1927 |
SoFCPathAnnotation::~SoFCPathAnnotation() |
| 1928 |
{ |
| 1929 |
if (path) { |
| 1930 |
path->unref(); |
| 1931 |
} |
| 1932 |
if (tmpPath) { |
| 1933 |
tmpPath->unref(); |
| 1934 |
} |
| 1935 |
delete det; |
| 1936 |
} |
| 1937 |
|
| 1938 |
void SoFCPathAnnotation::finish() |
| 1939 |
{ |
| 1940 |
atexit_cleanup(); |
| 1941 |
} |
| 1942 |
|
| 1943 |
void SoFCPathAnnotation::initClass() |
| 1944 |
{ |
| 1945 |
SO_NODE_INIT_CLASS(SoFCPathAnnotation, SoSeparator, "Separator"); |
| 1946 |
} |
| 1947 |
|
| 1948 |
void SoFCPathAnnotation::GLRender(SoGLRenderAction* action) |
| 1949 |
{ |
| 1950 |
switch (action->getCurPathCode()) { |
| 1951 |
case SoAction::NO_PATH: |
| 1952 |
case SoAction::BELOW_PATH: |
| 1953 |
this->GLRenderBelowPath(action); |
| 1954 |
break; |
| 1955 |
case SoAction::OFF_PATH: |
| 1956 |
break; |
| 1957 |
case SoAction::IN_PATH: |
| 1958 |
this->GLRenderInPath(action); |
| 1959 |
break; |
| 1960 |
} |
| 1961 |
} |
| 1962 |
|
| 1963 |
void SoFCPathAnnotation::GLRenderBelowPath(SoGLRenderAction* action) |
| 1964 |
{ |
| 1965 |
if (!path || !path->getLength() || !tmpPath || !tmpPath->getLength()) { |
| 1966 |
return; |
| 1967 |
} |
| 1968 |
|
| 1969 |
if (path->getLength() != tmpPath->getLength()) { |
| 1970 |
// The auditing SoPath may be truncated due to harmless things such as |
| 1971 |
// flipping a SoSwitch sibling node. So we keep an unauditing SoTempPath |
| 1972 |
// around to try to restore the path. |
| 1973 |
for (int i = path->getLength() - 1; i < tmpPath->getLength() - 1; ++i) { |
| 1974 |
auto children = path->getNode(i)->getChildren(); |
| 1975 |
if (children) { |
| 1976 |
int idx = children->find(tmpPath->getNode(i + 1)); |
| 1977 |
if (idx >= 0) { |
| 1978 |
path->append(idx); |
| 1979 |
continue; |
| 1980 |
} |
| 1981 |
} |
| 1982 |
tmpPath->unref(); |
| 1983 |
tmpPath = nullptr; |
| 1984 |
return; |
| 1985 |
} |
| 1986 |
} |
| 1987 |
|
| 1988 |
SoState* state = action->getState(); |
| 1989 |
SoGLCacheContextElement::shouldAutoCache(state, SoGLCacheContextElement::DONT_AUTO_CACHE); |
| 1990 |
|
| 1991 |
if (action->isRenderingDelayedPaths()) { |
| 1992 |
SbBool zbenabled = glIsEnabled(GL_DEPTH_TEST); |
| 1993 |
if (zbenabled) { |
| 1994 |
glDisable(GL_DEPTH_TEST); |
| 1995 |
} |
| 1996 |
|
| 1997 |
if (det) { |
| 1998 |
inherited::GLRenderInPath(action); |
| 1999 |
} |
| 2000 |
else { |
| 2001 |
bool bbox = ViewParams::instance()->getShowSelectionBoundingBox(); |
| 2002 |
if (!bbox) { |
| 2003 |
for (int i = 0, count = path->getLength(); i < count; ++i) { |
| 2004 |
if (!path->getNode(i)->isOfType(SoFCSelectionRoot::getClassTypeId())) { |
| 2005 |
continue; |
| 2006 |
} |
| 2007 |
auto node = dynamic_cast<SoFCSelectionRoot*>(path->getNode(i)); |
| 2008 |
if (node != nullptr && node->selectionStyle.getValue() == SoFCSelectionRoot::Box) { |
| 2009 |
bbox = true; |
| 2010 |
break; |
| 2011 |
} |
| 2012 |
} |
| 2013 |
} |
| 2014 |
if (!bbox) { |
| 2015 |
inherited::GLRenderInPath(action); |
| 2016 |
} |
| 2017 |
else { |
| 2018 |
bool sel = false; |
| 2019 |
bool hl = false; |
| 2020 |
SbColor selColor, hlColor; |
| 2021 |
SoFCSelectionRoot::checkSelection(sel, selColor, hl, hlColor); |
| 2022 |
if (sel || hl) { |
| 2023 |
SoFCSelectionRoot::renderBBox(action, this, hl ? hlColor : selColor); |
| 2024 |
} |
| 2025 |
else { |
| 2026 |
inherited::GLRenderInPath(action); |
| 2027 |
} |
| 2028 |
} |
| 2029 |
} |
| 2030 |
|
| 2031 |
if (zbenabled) { |
| 2032 |
glEnable(GL_DEPTH_TEST); |
| 2033 |
} |
| 2034 |
} |
| 2035 |
else { |
| 2036 |
SoCacheElement::invalidate(action->getState()); |
| 2037 |
auto curPath = action->getCurPath(); |
| 2038 |
auto newPath = new SoPath(curPath->getLength() + path->getLength()); |
| 2039 |
newPath->append(curPath); |
| 2040 |
newPath->append(path); |
| 2041 |
action->addDelayedPath(newPath); |
| 2042 |
} |
| 2043 |
} |
| 2044 |
|
| 2045 |
void SoFCPathAnnotation::GLRenderInPath(SoGLRenderAction* action) |
| 2046 |
{ |
| 2047 |
GLRenderBelowPath(action); |
| 2048 |
} |
| 2049 |
|
| 2050 |
void SoFCPathAnnotation::setDetail(SoDetail* d) |
| 2051 |
{ |
| 2052 |
if (d != det) { |
| 2053 |
delete det; |
| 2054 |
det = d; |
| 2055 |
} |
| 2056 |
} |
| 2057 |
|
| 2058 |
void SoFCPathAnnotation::setPath(SoPath* newPath) |
| 2059 |
{ |
| 2060 |
if (path) { |
| 2061 |
path->unref(); |
| 2062 |
coinRemoveAllChildren(this); |
| 2063 |
path = nullptr; |
| 2064 |
if (tmpPath) { |
| 2065 |
tmpPath->unref(); |
| 2066 |
tmpPath = nullptr; |
| 2067 |
} |
| 2068 |
} |
| 2069 |
if (!newPath || !newPath->getLength()) { |
| 2070 |
return; |
| 2071 |
} |
| 2072 |
|
| 2073 |
tmpPath = new SoTempPath(newPath->getLength()); |
| 2074 |
tmpPath->ref(); |
| 2075 |
for (int i = 0; i < newPath->getLength(); ++i) { |
| 2076 |
tmpPath->append(newPath->getNode(i)); |
| 2077 |
} |
| 2078 |
path = newPath->copy(); |
| 2079 |
path->ref(); |
| 2080 |
addChild(path->getNode(0)); |
| 2081 |
} |
| 2082 |
|
| 2083 |
void SoFCPathAnnotation::getBoundingBox(SoGetBoundingBoxAction* action) |
| 2084 |
{ |
| 2085 |
if (path) { |
| 2086 |
SoGetBoundingBoxAction bboxAction(action->getViewportRegion()); |
| 2087 |
SoFCSelectionRoot::moveActionStack(action, &bboxAction, false); |
| 2088 |
bboxAction.apply(path); |
| 2089 |
SoFCSelectionRoot::moveActionStack(&bboxAction, action, true); |
| 2090 |
auto bbox = bboxAction.getBoundingBox(); |
| 2091 |
if (!bbox.isEmpty()) { |
| 2092 |
action->extendBy(bbox); |
| 2093 |
} |
| 2094 |
} |
| 2095 |
} |