| 1 |
/*************************************************************************** |
| 2 |
* Copyright (c) 2004 Jürgen Riegel <[email protected]> * |
| 3 |
* * |
| 4 |
* This file is part of the FreeCAD CAx development system. * |
| 5 |
* * |
| 6 |
* This library is free software; you can redistribute it and/or * |
| 7 |
* modify it under the terms of the GNU Library General Public * |
| 8 |
* License as published by the Free Software Foundation; either * |
| 9 |
* version 2 of the License, or (at your option) any later version. * |
| 10 |
* * |
| 11 |
* This library is distributed in the hope that it will be useful, * |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 14 |
* GNU Library General Public License for more details. * |
| 15 |
* * |
| 16 |
* You should have received a copy of the GNU Library General Public * |
| 17 |
* License along with this library; see the file COPYING.LIB. If not, * |
| 18 |
* write to the Free Software Foundation, Inc., 59 Temple Place, * |
| 19 |
* Suite 330, Boston, MA 02111-1307, USA * |
| 20 |
* * |
| 21 |
***************************************************************************/ |
| 22 |
|
| 23 |
|
| 24 |
#include <QApplication> |
| 25 |
#include <QKeyEvent> |
| 26 |
#include <QTimer> |
| 27 |
#include <Inventor/SoPickedPoint.h> |
| 28 |
#include <Inventor/actions/SoGetBoundingBoxAction.h> |
| 29 |
#include <Inventor/details/SoDetail.h> |
| 30 |
#include <Inventor/events/SoKeyboardEvent.h> |
| 31 |
#include <Inventor/events/SoLocation2Event.h> |
| 32 |
#include <Inventor/events/SoMouseButtonEvent.h> |
| 33 |
#include <Inventor/nodes/SoSeparator.h> |
| 34 |
#include <Inventor/nodes/SoSwitch.h> |
| 35 |
#include <Inventor/nodes/SoTransform.h> |
| 36 |
|
| 37 |
|
| 38 |
#include <Base/BoundBox.h> |
| 39 |
#include <Base/Console.h> |
| 40 |
#include <Base/Exception.h> |
| 41 |
#include <Base/Matrix.h> |
| 42 |
#include <Base/Tools.h> |
| 43 |
|
| 44 |
#include "Inventor/SoMouseWheelEvent.h" |
| 45 |
#include "Inventor/SoFCTransform.h" |
| 46 |
#include "ViewProvider.h" |
| 47 |
#include "ActionFunction.h" |
| 48 |
#include "Application.h" |
| 49 |
#include "BitmapFactory.h" |
| 50 |
#include "Document.h" |
| 51 |
#include "DockWindowManager.h" |
| 52 |
#include "SoFCDB.h" |
| 53 |
#include "View3DInventor.h" |
| 54 |
#include "View3DInventorViewer.h" |
| 55 |
#include "ViewParams.h" |
| 56 |
#include "ViewProviderExtension.h" |
| 57 |
#include "ViewProviderLink.h" |
| 58 |
#include "ViewProviderPy.h" |
| 59 |
|
| 60 |
#include <Utilities.h> |
| 61 |
|
| 62 |
|
| 63 |
FC_LOG_LEVEL_INIT("ViewProvider", true, true) |
| 64 |
|
| 65 |
using namespace std; |
| 66 |
using namespace Gui; |
| 67 |
|
| 68 |
|
| 69 |
namespace Gui |
| 70 |
{ |
| 71 |
|
| 72 |
void coinRemoveAllChildren(SoGroup* group) |
| 73 |
{ |
| 74 |
if (!group) { |
| 75 |
return; |
| 76 |
} |
| 77 |
int count = group->getNumChildren(); |
| 78 |
if (!count) { |
| 79 |
return; |
| 80 |
} |
| 81 |
FC_TRACE("coin remove all children " << count); |
| 82 |
SbBool autonotify = group->enableNotify(FALSE); |
| 83 |
for (; count > 0; --count) { |
| 84 |
group->removeChild(count - 1); |
| 85 |
} |
| 86 |
group->enableNotify(autonotify); |
| 87 |
group->touch(); |
| 88 |
} |
| 89 |
|
| 90 |
} // namespace Gui |
| 91 |
|
| 92 |
//************************************************************************** |
| 93 |
//************************************************************************** |
| 94 |
// ViewProvider |
| 95 |
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 96 |
|
| 97 |
PROPERTY_SOURCE_ABSTRACT(Gui::ViewProvider, App::TransactionalObject) |
| 98 |
|
| 99 |
ViewProvider::ViewProvider() |
| 100 |
: overrideMode("As Is") |
| 101 |
, toggleVisibilityMode(ToggleVisibilityMode::CanToggleVisibility) |
| 102 |
{ |
| 103 |
setStatus(UpdateData, true); |
| 104 |
|
| 105 |
|
| 106 |
// SoFCSeparator and SoFCSelectionRoot can both track render cache setting. |
| 107 |
// We change to SoFCSelectionRoot so that we can dynamically change full |
| 108 |
// selection mode (full highlight vs. boundbox). Note that comparing to |
| 109 |
// SoFCSeparator, there are some small overhead with SoFCSelectionRoot for |
| 110 |
// selection context tracking. |
| 111 |
// |
| 112 |
// pcRoot = new SoFCSeparator(true); |
| 113 |
pcRoot = new SoFCSelectionRoot(true); |
| 114 |
pcRoot->ref(); |
| 115 |
pcModeSwitch = new SoSwitch(); |
| 116 |
pcModeSwitch->ref(); |
| 117 |
pcModeSwitch->setName("ModeSwitch"); |
| 118 |
pcTransform = new SoFCTransform(); |
| 119 |
pcTransform->ref(); |
| 120 |
pcRoot->addChild(pcTransform); |
| 121 |
pcRoot->addChild(pcModeSwitch); |
| 122 |
sPixmap = "px"; |
| 123 |
pcModeSwitch->whichChild = _iActualMode; |
| 124 |
|
| 125 |
setRenderCacheMode(ViewParams::instance()->getRenderCache()); |
| 126 |
} |
| 127 |
|
| 128 |
ViewProvider::~ViewProvider() |
| 129 |
{ |
| 130 |
if (pyViewObject) { |
| 131 |
Base::PyGILStateLocker lock; |
| 132 |
pyViewObject->setInvalid(); |
| 133 |
pyViewObject->DecRef(); |
| 134 |
} |
| 135 |
|
| 136 |
pcRoot->unref(); |
| 137 |
pcTransform->unref(); |
| 138 |
pcModeSwitch->unref(); |
| 139 |
if (pcAnnotation) { |
| 140 |
pcAnnotation->unref(); |
| 141 |
} |
| 142 |
} |
| 143 |
|
| 144 |
ViewProvider* ViewProvider::startEditing(int ModNum) |
| 145 |
{ |
| 146 |
try { |
| 147 |
if (setEdit(ModNum)) { |
| 148 |
_iEditMode = ModNum; |
| 149 |
return this; |
| 150 |
} |
| 151 |
} |
| 152 |
catch (const Base::Exception& e) { |
| 153 |
e.reportException(); |
| 154 |
} |
| 155 |
return nullptr; |
| 156 |
} |
| 157 |
|
| 158 |
int ViewProvider::getEditingMode() const |
| 159 |
{ |
| 160 |
return _iEditMode; |
| 161 |
} |
| 162 |
|
| 163 |
bool ViewProvider::isEditing() const |
| 164 |
{ |
| 165 |
return getEditingMode() > -1; |
| 166 |
} |
| 167 |
|
| 168 |
void ViewProvider::finishEditing() |
| 169 |
{ |
| 170 |
unsetEdit(_iEditMode); |
| 171 |
_iEditMode = -1; |
| 172 |
} |
| 173 |
|
| 174 |
bool ViewProvider::setEdit(int ModNum) |
| 175 |
{ |
| 176 |
Q_UNUSED(ModNum); |
| 177 |
return true; |
| 178 |
} |
| 179 |
|
| 180 |
void ViewProvider::unsetEdit(int ModNum) |
| 181 |
{ |
| 182 |
Q_UNUSED(ModNum); |
| 183 |
} |
| 184 |
|
| 185 |
void ViewProvider::setEditViewer(View3DInventorViewer*, int ModNum) |
| 186 |
{ |
| 187 |
Q_UNUSED(ModNum); |
| 188 |
} |
| 189 |
|
| 190 |
void ViewProvider::unsetEditViewer(View3DInventorViewer*) |
| 191 |
{} |
| 192 |
|
| 193 |
bool ViewProvider::isUpdatesEnabled() const |
| 194 |
{ |
| 195 |
return testStatus(UpdateData); |
| 196 |
} |
| 197 |
|
| 198 |
void ViewProvider::setUpdatesEnabled(bool enable) |
| 199 |
{ |
| 200 |
setStatus(UpdateData, enable); |
| 201 |
} |
| 202 |
|
| 203 |
void highlight(const HighlightMode& high) |
| 204 |
{ |
| 205 |
Q_UNUSED(high); |
| 206 |
} |
| 207 |
|
| 208 |
void ViewProvider::eventCallback(void* ud, SoEventCallback* node) |
| 209 |
{ |
| 210 |
const SoEvent* ev = node->getEvent(); |
| 211 |
auto viewer = static_cast<Gui::View3DInventorViewer*>(node->getUserData()); |
| 212 |
auto self = static_cast<ViewProvider*>(ud); |
| 213 |
assert(self); |
| 214 |
|
| 215 |
try { |
| 216 |
// Keyboard events |
| 217 |
if (ev->getTypeId().isDerivedFrom(SoKeyboardEvent::getClassTypeId())) { |
| 218 |
auto ke = static_cast<const SoKeyboardEvent*>(ev); |
| 219 |
const SbBool press = ke->getState() == SoButtonEvent::DOWN ? true : false; |
| 220 |
switch (ke->getKey()) { |
| 221 |
case SoKeyboardEvent::ESCAPE: |
| 222 |
if (self->keyPressed(press, ke->getKey())) { |
| 223 |
node->setHandled(); |
| 224 |
} |
| 225 |
else if (QApplication::mouseButtons() == Qt::NoButton) { |
| 226 |
// Because of a Coin bug |
| 227 |
// (https://bitbucket.org/Coin3D/coin/pull-requests/119), FC may crash if |
| 228 |
// user hits ESC to cancel while still holding the mouse button while using |
| 229 |
// some SoDragger. Therefore, we shall ignore ESC while any mouse button is |
| 230 |
// pressed, until this Coin bug is fixed. |
| 231 |
if (!press) { |
| 232 |
// react only on key release |
| 233 |
// Let first selection mode terminate |
| 234 |
Gui::Document* doc = Gui::Application::Instance->activeDocument(); |
| 235 |
const auto view = qobject_cast<Gui::View3DInventor*>(doc->getActiveView()); |
| 236 |
if (view) { |
| 237 |
Gui::View3DInventorViewer* viewer = view->getViewer(); |
| 238 |
if (viewer->isSelecting()) { |
| 239 |
return; |
| 240 |
} |
| 241 |
} |
| 242 |
|
| 243 |
DockWindowManager* pDockMgr = DockWindowManager::instance(); |
| 244 |
if (QWidget* widget = pDockMgr->getDockWindow("Tasks")) { |
| 245 |
auto* ev |
| 246 |
= new QKeyEvent(QEvent::KeyPress, Qt::Key_Escape, Qt::NoModifier); |
| 247 |
qApp->postEvent(widget, ev); |
| 248 |
} |
| 249 |
|
| 250 |
auto func = new Gui::TimerFunction(); |
| 251 |
func->setAutoDelete(true); |
| 252 |
func->setFunction([doc]() { doc->resetEdit(); }); |
| 253 |
func->singleShot(0); |
| 254 |
} |
| 255 |
} |
| 256 |
else if (press) { |
| 257 |
FC_WARN("Release all mouse buttons before exiting editing"); |
| 258 |
} |
| 259 |
break; |
| 260 |
default: |
| 261 |
// call the virtual method |
| 262 |
if (self->keyPressed(press, ke->getKey())) { |
| 263 |
node->setHandled(); |
| 264 |
} |
| 265 |
break; |
| 266 |
} |
| 267 |
} |
| 268 |
// switching the mouse buttons |
| 269 |
else if (ev->getTypeId().isDerivedFrom(SoMouseButtonEvent::getClassTypeId())) { |
| 270 |
|
| 271 |
const auto event = (const SoMouseButtonEvent*)ev; |
| 272 |
const int button = event->getButton(); |
| 273 |
const SbBool press = event->getState() == SoButtonEvent::DOWN ? true : false; |
| 274 |
|
| 275 |
// call the virtual method |
| 276 |
if (self->mouseButtonPressed(button, press, ev->getPosition(), viewer)) { |
| 277 |
node->setHandled(); |
| 278 |
} |
| 279 |
} |
| 280 |
else if (ev->getTypeId().isDerivedFrom(SoMouseWheelEvent::getClassTypeId())) { |
| 281 |
const auto event = (const SoMouseWheelEvent*)ev; |
| 282 |
|
| 283 |
if (self->mouseWheelEvent(event->getDelta(), event->getPosition(), viewer)) { |
| 284 |
node->setHandled(); |
| 285 |
} |
| 286 |
} |
| 287 |
// Mouse Movement handling |
| 288 |
else if (ev->getTypeId().isDerivedFrom(SoLocation2Event::getClassTypeId())) { |
| 289 |
if (self->mouseMove(ev->getPosition(), viewer)) { |
| 290 |
node->setHandled(); |
| 291 |
} |
| 292 |
} |
| 293 |
} |
| 294 |
catch (const Base::Exception& e) { |
| 295 |
Base::Console().error( |
| 296 |
"Unhandled exception in ViewProvider::eventCallback: %s\n" |
| 297 |
"(Event type: %s, object type: %s)\n", |
| 298 |
e.what(), |
| 299 |
ev->getTypeId().getName().getString(), |
| 300 |
self->getTypeId().getName() |
| 301 |
); |
| 302 |
} |
| 303 |
catch (const std::exception& e) { |
| 304 |
Base::Console().error( |
| 305 |
"Unhandled std exception in ViewProvider::eventCallback: %s\n" |
| 306 |
"(Event type: %s, object type: %s)\n", |
| 307 |
e.what(), |
| 308 |
ev->getTypeId().getName().getString(), |
| 309 |
self->getTypeId().getName() |
| 310 |
); |
| 311 |
} |
| 312 |
catch (...) { |
| 313 |
Base::Console().error( |
| 314 |
"Unhandled unknown C++ exception in ViewProvider::eventCallback" |
| 315 |
" (Event type: %s, object type: %s)\n", |
| 316 |
ev->getTypeId().getName().getString(), |
| 317 |
self->getTypeId().getName() |
| 318 |
); |
| 319 |
} |
| 320 |
} |
| 321 |
|
| 322 |
SoSeparator* ViewProvider::getAnnotation() |
| 323 |
{ |
| 324 |
if (!pcAnnotation) { |
| 325 |
pcAnnotation = new SoSeparator(); |
| 326 |
pcAnnotation->ref(); |
| 327 |
pcRoot->addChild(pcAnnotation); |
| 328 |
} |
| 329 |
return pcAnnotation; |
| 330 |
} |
| 331 |
|
| 332 |
void ViewProvider::update(const App::Property* prop) |
| 333 |
{ |
| 334 |
// Hide the object temporarily to speed up the update |
| 335 |
if (!isUpdatesEnabled()) { |
| 336 |
return; |
| 337 |
} |
| 338 |
bool vis = ViewProvider::isShow(); |
| 339 |
if (vis) { |
| 340 |
ViewProvider::hide(); |
| 341 |
} |
| 342 |
updateData(prop); |
| 343 |
if (vis) { |
| 344 |
ViewProvider::show(); |
| 345 |
} |
| 346 |
} |
| 347 |
|
| 348 |
QIcon ViewProvider::getIcon() const |
| 349 |
{ |
| 350 |
return mergeGreyableOverlayIcons(Gui::BitmapFactory().pixmap(sPixmap)); |
| 351 |
} |
| 352 |
|
| 353 |
QIcon ViewProvider::mergeGreyableOverlayIcons(const QIcon& orig) const |
| 354 |
{ |
| 355 |
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>(); |
| 356 |
|
| 357 |
QIcon overlayedIcon = orig; |
| 358 |
|
| 359 |
for (Gui::ViewProviderExtension* ext : vector) { |
| 360 |
if (!ext->ignoreOverlayIcon()) { |
| 361 |
overlayedIcon = ext->extensionMergeGreyableOverlayIcons(overlayedIcon); |
| 362 |
} |
| 363 |
} |
| 364 |
|
| 365 |
return overlayedIcon; |
| 366 |
} |
| 367 |
|
| 368 |
QIcon ViewProvider::mergeColorfulOverlayIcons(const QIcon& orig) const |
| 369 |
{ |
| 370 |
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>(); |
| 371 |
|
| 372 |
QIcon overlayedIcon = orig; |
| 373 |
|
| 374 |
for (Gui::ViewProviderExtension* ext : vector) { |
| 375 |
if (!ext->ignoreOverlayIcon()) { |
| 376 |
overlayedIcon = ext->extensionMergeColorfullOverlayIcons(overlayedIcon); |
| 377 |
} |
| 378 |
} |
| 379 |
|
| 380 |
return overlayedIcon; |
| 381 |
} |
| 382 |
|
| 383 |
void ViewProvider::setTransformation(const Base::Matrix4D& rcMatrix) |
| 384 |
{ |
| 385 |
pcTransform->setMatrix(convert(rcMatrix)); |
| 386 |
} |
| 387 |
|
| 388 |
void ViewProvider::setTransformation(const SbMatrix& rcMatrix) |
| 389 |
{ |
| 390 |
pcTransform->setMatrix(rcMatrix); |
| 391 |
} |
| 392 |
|
| 393 |
SbMatrix ViewProvider::convert(const Base::Matrix4D& rcMatrix) |
| 394 |
{ |
| 395 |
return Base::convertTo<SbMatrix>(rcMatrix); |
| 396 |
} |
| 397 |
|
| 398 |
Base::Matrix4D ViewProvider::convert(const SbMatrix& smat) |
| 399 |
{ |
| 400 |
return Base::convertTo<Base::Matrix4D>(smat); |
| 401 |
} |
| 402 |
|
| 403 |
void ViewProvider::addDisplayMaskMode(SoNode* node, const char* type) |
| 404 |
{ |
| 405 |
_sDisplayMaskModes[type] = pcModeSwitch->getNumChildren(); |
| 406 |
pcModeSwitch->addChild(node); |
| 407 |
} |
| 408 |
|
| 409 |
void ViewProvider::setDisplayMaskMode(const char* type) |
| 410 |
{ |
| 411 |
std::map<std::string, int>::const_iterator it = _sDisplayMaskModes.find(type); |
| 412 |
if (it != _sDisplayMaskModes.end()) { |
| 413 |
_iActualMode = it->second; |
| 414 |
} |
| 415 |
else { |
| 416 |
_iActualMode = -1; |
| 417 |
} |
| 418 |
setModeSwitch(); |
| 419 |
} |
| 420 |
|
| 421 |
SoNode* ViewProvider::getDisplayMaskMode(const char* type) const |
| 422 |
{ |
| 423 |
std::map<std::string, int>::const_iterator it = _sDisplayMaskModes.find(type); |
| 424 |
if (it != _sDisplayMaskModes.end()) { |
| 425 |
return pcModeSwitch->getChild(it->second); |
| 426 |
} |
| 427 |
|
| 428 |
return nullptr; |
| 429 |
} |
| 430 |
|
| 431 |
std::vector<std::string> ViewProvider::getDisplayMaskModes() const |
| 432 |
{ |
| 433 |
std::vector<std::string> types; |
| 434 |
for (const auto& it : _sDisplayMaskModes) { |
| 435 |
types.push_back(it.first); |
| 436 |
} |
| 437 |
return types; |
| 438 |
} |
| 439 |
|
| 440 |
/** |
| 441 |
* If you add new viewing modes in @ref getDisplayModes() then you need to reimplement |
| 442 |
* also seDisplaytMode() to handle these new modes by setting the appropriate display |
| 443 |
* mode. |
| 444 |
*/ |
| 445 |
void ViewProvider::setDisplayMode(const char* ModeName) |
| 446 |
{ |
| 447 |
_sCurrentMode = ModeName; |
| 448 |
|
| 449 |
// infom the exteensions |
| 450 |
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>(); |
| 451 |
for (Gui::ViewProviderExtension* ext : vector) { |
| 452 |
ext->extensionSetDisplayMode(ModeName); |
| 453 |
} |
| 454 |
} |
| 455 |
|
| 456 |
const char* ViewProvider::getDefaultDisplayMode() const |
| 457 |
{ |
| 458 |
|
| 459 |
return nullptr; |
| 460 |
} |
| 461 |
|
| 462 |
vector<std::string> ViewProvider::getDisplayModes() const |
| 463 |
{ |
| 464 |
|
| 465 |
std::vector<std::string> modes; |
| 466 |
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>(); |
| 467 |
for (Gui::ViewProviderExtension* ext : vector) { |
| 468 |
auto extModes = ext->extensionGetDisplayModes(); |
| 469 |
modes.insert(modes.end(), extModes.begin(), extModes.end()); |
| 470 |
} |
| 471 |
return modes; |
| 472 |
} |
| 473 |
|
| 474 |
std::string ViewProvider::getActiveDisplayMode() const |
| 475 |
{ |
| 476 |
return _sCurrentMode; |
| 477 |
} |
| 478 |
|
| 479 |
void ViewProvider::hide() |
| 480 |
{ |
| 481 |
auto exts = getExtensionsDerivedFromType<Gui::ViewProviderExtension>(); |
| 482 |
|
| 483 |
if (pcModeSwitch->whichChild.getValue() >= 0) { |
| 484 |
pcModeSwitch->whichChild = -1; |
| 485 |
for (auto ext : exts) { |
| 486 |
ext->extensionModeSwitchChange(); |
| 487 |
} |
| 488 |
} |
| 489 |
|
| 490 |
// tell extensions that we hide |
| 491 |
for (Gui::ViewProviderExtension* ext : exts) { |
| 492 |
ext->extensionHide(); |
| 493 |
} |
| 494 |
} |
| 495 |
|
| 496 |
void ViewProvider::show() |
| 497 |
{ |
| 498 |
setModeSwitch(); |
| 499 |
|
| 500 |
// tell extensions that we show |
| 501 |
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>(); |
| 502 |
for (Gui::ViewProviderExtension* ext : vector) { |
| 503 |
ext->extensionShow(); |
| 504 |
} |
| 505 |
} |
| 506 |
|
| 507 |
bool ViewProvider::isShow() const |
| 508 |
{ |
| 509 |
return pcModeSwitch->whichChild.getValue() != -1; |
| 510 |
} |
| 511 |
|
| 512 |
void ViewProvider::setVisible(bool s) |
| 513 |
{ |
| 514 |
s ? show() : hide(); |
| 515 |
} |
| 516 |
|
| 517 |
bool ViewProvider::isVisible() const |
| 518 |
{ |
| 519 |
return isShow(); |
| 520 |
} |
| 521 |
|
| 522 |
void ViewProvider::setOverrideMode(const std::string& mode) |
| 523 |
{ |
| 524 |
if (mode == "As Is") { |
| 525 |
viewOverrideMode = -1; |
| 526 |
overrideMode = mode; |
| 527 |
} |
| 528 |
else { |
| 529 |
std::map<std::string, int>::const_iterator it = _sDisplayMaskModes.find(mode); |
| 530 |
if (it == _sDisplayMaskModes.end()) { |
| 531 |
return; // view style not supported |
| 532 |
} |
| 533 |
viewOverrideMode = (*it).second; |
| 534 |
overrideMode = mode; |
| 535 |
} |
| 536 |
if (pcModeSwitch->whichChild.getValue() != -1) { |
| 537 |
setModeSwitch(); |
| 538 |
} |
| 539 |
else { |
| 540 |
for (auto ext : getExtensionsDerivedFromType<Gui::ViewProviderExtension>()) { |
| 541 |
ext->extensionModeSwitchChange(); |
| 542 |
} |
| 543 |
} |
| 544 |
} |
| 545 |
|
| 546 |
const string ViewProvider::getOverrideMode() |
| 547 |
{ |
| 548 |
return overrideMode; |
| 549 |
} |
| 550 |
|
| 551 |
|
| 552 |
void ViewProvider::setModeSwitch() |
| 553 |
{ |
| 554 |
if (viewOverrideMode == -1) { |
| 555 |
pcModeSwitch->whichChild = _iActualMode; |
| 556 |
} |
| 557 |
else if (viewOverrideMode < pcModeSwitch->getNumChildren()) { |
| 558 |
pcModeSwitch->whichChild = viewOverrideMode; |
| 559 |
} |
| 560 |
else { |
| 561 |
return; |
| 562 |
} |
| 563 |
for (auto ext : getExtensionsDerivedFromType<Gui::ViewProviderExtension>()) { |
| 564 |
ext->extensionModeSwitchChange(); |
| 565 |
} |
| 566 |
} |
| 567 |
|
| 568 |
void ViewProvider::setDefaultMode(int val) |
| 569 |
{ |
| 570 |
_iActualMode = val; |
| 571 |
for (auto ext : getExtensionsDerivedFromType<Gui::ViewProviderExtension>()) { |
| 572 |
ext->extensionModeSwitchChange(); |
| 573 |
} |
| 574 |
} |
| 575 |
|
| 576 |
int ViewProvider::getDefaultMode() const |
| 577 |
{ |
| 578 |
return viewOverrideMode >= 0 ? viewOverrideMode : _iActualMode; |
| 579 |
} |
| 580 |
|
| 581 |
void ViewProvider::onBeforeChange(const App::Property* prop) |
| 582 |
{ |
| 583 |
Application::Instance->signalBeforeChangeObject(*this, *prop); |
| 584 |
|
| 585 |
App::TransactionalObject::onBeforeChange(prop); |
| 586 |
} |
| 587 |
|
| 588 |
void ViewProvider::onChanged(const App::Property* prop) |
| 589 |
{ |
| 590 |
Application::Instance->signalChangedObject(*this, *prop); |
| 591 |
Application::Instance->updateActions(); |
| 592 |
|
| 593 |
App::TransactionalObject::onChanged(prop); |
| 594 |
} |
| 595 |
|
| 596 |
std::string ViewProvider::toString() const |
| 597 |
{ |
| 598 |
return SoFCDB::writeNodesToString(pcRoot); |
| 599 |
} |
| 600 |
|
| 601 |
PyObject* ViewProvider::getPyObject() |
| 602 |
{ |
| 603 |
if (!pyViewObject) { |
| 604 |
pyViewObject = new ViewProviderPy(this); |
| 605 |
} |
| 606 |
pyViewObject->IncRef(); |
| 607 |
return pyViewObject; |
| 608 |
} |
| 609 |
|
| 610 |
#include <boost/graph/topological_sort.hpp> |
| 611 |
|
| 612 |
namespace Gui |
| 613 |
{ |
| 614 |
using Graph = boost::adjacency_list< |
| 615 |
boost::vecS, // class OutEdgeListS : a Sequence or an AssociativeContainer |
| 616 |
boost::vecS, // class VertexListS : a Sequence or a RandomAccessContainer |
| 617 |
boost::directedS, // class DirectedS : This is a directed graph |
| 618 |
boost::no_property, // class VertexProperty: |
| 619 |
boost::no_property, // class EdgeProperty: |
| 620 |
boost::no_property, // class GraphProperty: |
| 621 |
boost::listS // class EdgeListS: |
| 622 |
>; |
| 623 |
using Vertex = boost::graph_traits<Graph>::vertex_descriptor; |
| 624 |
using Edge = boost::graph_traits<Graph>::edge_descriptor; |
| 625 |
|
| 626 |
void addNodes(Graph& graph, std::map<SoNode*, Vertex>& vertexNodeMap, SoNode* node) |
| 627 |
{ |
| 628 |
if (node->getTypeId().isDerivedFrom(SoGroup::getClassTypeId())) { |
| 629 |
auto group = static_cast<SoGroup*>(node); |
| 630 |
Vertex groupV = vertexNodeMap[group]; |
| 631 |
|
| 632 |
for (int i = 0; i < group->getNumChildren(); i++) { |
| 633 |
SoNode* child = group->getChild(i); |
| 634 |
auto it = vertexNodeMap.find(child); |
| 635 |
|
| 636 |
// the child node is not yet added to the map |
| 637 |
if (it == vertexNodeMap.end()) { |
| 638 |
Vertex childV = add_vertex(graph); |
| 639 |
vertexNodeMap[child] = childV; |
| 640 |
add_edge(groupV, childV, graph); |
| 641 |
addNodes(graph, vertexNodeMap, child); |
| 642 |
} |
| 643 |
// the child is already there, only add the edge then |
| 644 |
else { |
| 645 |
add_edge(groupV, it->second, graph); |
| 646 |
} |
| 647 |
} |
| 648 |
} |
| 649 |
} |
| 650 |
} // namespace Gui |
| 651 |
|
| 652 |
bool ViewProvider::checkRecursion(SoNode* node) |
| 653 |
{ |
| 654 |
if (node->getTypeId().isDerivedFrom(SoGroup::getClassTypeId())) { |
| 655 |
std::list<Vertex> make_order; |
| 656 |
Graph graph; |
| 657 |
std::map<SoNode*, Vertex> vertexNodeMap; |
| 658 |
Vertex groupV = add_vertex(graph); |
| 659 |
vertexNodeMap[node] = groupV; |
| 660 |
addNodes(graph, vertexNodeMap, node); |
| 661 |
|
| 662 |
try { |
| 663 |
boost::topological_sort(graph, std::front_inserter(make_order)); |
| 664 |
} |
| 665 |
catch (const std::exception&) { |
| 666 |
return false; |
| 667 |
} |
| 668 |
} |
| 669 |
|
| 670 |
return true; |
| 671 |
} |
| 672 |
|
| 673 |
SoPickedPoint* ViewProvider::getPointOnRay(const SbVec2s& pos, const View3DInventorViewer* viewer) const |
| 674 |
{ |
| 675 |
return viewer->getPointOnRay(pos, this); |
| 676 |
} |
| 677 |
|
| 678 |
SoPickedPoint* ViewProvider::getPointOnRay( |
| 679 |
const SbVec3f& pos, |
| 680 |
const SbVec3f& dir, |
| 681 |
const View3DInventorViewer* viewer |
| 682 |
) const |
| 683 |
{ |
| 684 |
return viewer->getPointOnRay(pos, dir, this); |
| 685 |
} |
| 686 |
|
| 687 |
std::vector<Base::Vector3d> ViewProvider::getModelPoints(const SoPickedPoint* pp) const |
| 688 |
{ |
| 689 |
// the default implementation just returns the picked point from the visual representation |
| 690 |
std::vector<Base::Vector3d> pts; |
| 691 |
const SbVec3f& vec = pp->getPoint(); |
| 692 |
pts.emplace_back(vec[0], vec[1], vec[2]); |
| 693 |
return pts; |
| 694 |
} |
| 695 |
|
| 696 |
bool ViewProvider::keyPressed(bool pressed, int key) |
| 697 |
{ |
| 698 |
(void)pressed; |
| 699 |
(void)key; |
| 700 |
return false; |
| 701 |
} |
| 702 |
|
| 703 |
bool ViewProvider::mouseMove(const SbVec2s& cursorPos, View3DInventorViewer* viewer) |
| 704 |
{ |
| 705 |
(void)cursorPos; |
| 706 |
(void)viewer; |
| 707 |
return false; |
| 708 |
} |
| 709 |
|
| 710 |
bool ViewProvider::mouseButtonPressed( |
| 711 |
int button, |
| 712 |
bool pressed, |
| 713 |
const SbVec2s& cursorPos, |
| 714 |
const View3DInventorViewer* viewer |
| 715 |
) |
| 716 |
{ |
| 717 |
(void)button; |
| 718 |
(void)pressed; |
| 719 |
(void)cursorPos; |
| 720 |
(void)viewer; |
| 721 |
return false; |
| 722 |
} |
| 723 |
|
| 724 |
bool ViewProvider::mouseWheelEvent(int delta, const SbVec2s& cursorPos, const View3DInventorViewer* viewer) |
| 725 |
{ |
| 726 |
(void)delta; |
| 727 |
(void)cursorPos; |
| 728 |
(void)viewer; |
| 729 |
return false; |
| 730 |
} |
| 731 |
|
| 732 |
void ViewProvider::setupContextMenu(QMenu* menu, QObject* receiver, const char* method) |
| 733 |
{ |
| 734 |
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>(); |
| 735 |
for (Gui::ViewProviderExtension* ext : vector) { |
| 736 |
ext->extensionSetupContextMenu(menu, receiver, method); |
| 737 |
} |
| 738 |
} |
| 739 |
|
| 740 |
bool ViewProvider::onDelete(const vector<string>& subNames) |
| 741 |
{ |
| 742 |
bool del = true; |
| 743 |
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>(); |
| 744 |
for (Gui::ViewProviderExtension* ext : vector) { |
| 745 |
del &= ext->extensionOnDelete(subNames); |
| 746 |
} |
| 747 |
|
| 748 |
return del; |
| 749 |
} |
| 750 |
|
| 751 |
bool ViewProvider::canDelete(App::DocumentObject*) const |
| 752 |
{ |
| 753 |
return false; |
| 754 |
} |
| 755 |
|
| 756 |
bool ViewProvider::canDragObject(App::DocumentObject* obj) const |
| 757 |
{ |
| 758 |
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>(); |
| 759 |
for (Gui::ViewProviderExtension* ext : vector) { |
| 760 |
if (ext->extensionCanDragObject(obj)) { |
| 761 |
return true; |
| 762 |
} |
| 763 |
} |
| 764 |
|
| 765 |
return false; |
| 766 |
} |
| 767 |
|
| 768 |
bool ViewProvider::canDragObjectToTarget( |
| 769 |
App::DocumentObject* obj, |
| 770 |
[[maybe_unused]] App::DocumentObject* target |
| 771 |
) const |
| 772 |
{ |
| 773 |
return canDragObject(obj); |
| 774 |
} |
| 775 |
|
| 776 |
bool ViewProvider::canDragObjects() const |
| 777 |
{ |
| 778 |
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>(); |
| 779 |
for (Gui::ViewProviderExtension* ext : vector) { |
| 780 |
if (ext->extensionCanDragObjects()) { |
| 781 |
return true; |
| 782 |
} |
| 783 |
} |
| 784 |
|
| 785 |
return false; |
| 786 |
} |
| 787 |
|
| 788 |
void ViewProvider::dragObject(App::DocumentObject* obj) |
| 789 |
{ |
| 790 |
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>(); |
| 791 |
for (Gui::ViewProviderExtension* ext : vector) { |
| 792 |
if (ext->extensionCanDragObject(obj)) { |
| 793 |
ext->extensionDragObject(obj); |
| 794 |
return; |
| 795 |
} |
| 796 |
} |
| 797 |
|
| 798 |
throw Base::RuntimeError( |
| 799 |
"ViewProvider::dragObject: no extension for dragging given object available." |
| 800 |
); |
| 801 |
} |
| 802 |
|
| 803 |
bool ViewProvider::canDropObject(App::DocumentObject* obj) const |
| 804 |
{ |
| 805 |
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>(); |
| 806 |
#if FC_DEBUG |
| 807 |
Base::Console().log("Check extensions for drop\n"); |
| 808 |
#endif |
| 809 |
for (Gui::ViewProviderExtension* ext : vector) { |
| 810 |
#if FC_DEBUG |
| 811 |
Base::Console().log("Check extensions %s\n", ext->name().c_str()); |
| 812 |
#endif |
| 813 |
if (ext->extensionCanDropObject(obj)) { |
| 814 |
return true; |
| 815 |
} |
| 816 |
} |
| 817 |
|
| 818 |
return false; |
| 819 |
} |
| 820 |
|
| 821 |
bool ViewProvider::canDropObjects() const |
| 822 |
{ |
| 823 |
|
| 824 |
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>(); |
| 825 |
for (Gui::ViewProviderExtension* ext : vector) { |
| 826 |
if (ext->extensionCanDropObjects()) { |
| 827 |
return true; |
| 828 |
} |
| 829 |
} |
| 830 |
|
| 831 |
return false; |
| 832 |
} |
| 833 |
|
| 834 |
bool ViewProvider::canDragAndDropObject(App::DocumentObject* obj) const |
| 835 |
{ |
| 836 |
|
| 837 |
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>(); |
| 838 |
for (Gui::ViewProviderExtension* ext : vector) { |
| 839 |
if (ext->extensionCanDragAndDropObject(obj)) { |
| 840 |
return true; |
| 841 |
} |
| 842 |
} |
| 843 |
|
| 844 |
return false; |
| 845 |
} |
| 846 |
|
| 847 |
void ViewProvider::dropObject(App::DocumentObject* obj) |
| 848 |
{ |
| 849 |
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>(); |
| 850 |
for (Gui::ViewProviderExtension* ext : vector) { |
| 851 |
if (ext->extensionCanDropObject(obj)) { |
| 852 |
ext->extensionDropObject(obj); |
| 853 |
break; |
| 854 |
} |
| 855 |
} |
| 856 |
} |
| 857 |
|
| 858 |
bool ViewProvider::canDropObjectEx( |
| 859 |
App::DocumentObject* obj, |
| 860 |
App::DocumentObject* owner, |
| 861 |
const char* subname, |
| 862 |
const std::vector<std::string>& elements |
| 863 |
) const |
| 864 |
{ |
| 865 |
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>(); |
| 866 |
for (Gui::ViewProviderExtension* ext : vector) { |
| 867 |
if (ext->extensionCanDropObjectEx(obj, owner, subname, elements)) { |
| 868 |
return true; |
| 869 |
} |
| 870 |
} |
| 871 |
return canDropObject(obj); |
| 872 |
} |
| 873 |
|
| 874 |
std::string ViewProvider::dropObjectEx( |
| 875 |
App::DocumentObject* obj, |
| 876 |
App::DocumentObject* owner, |
| 877 |
const char* subname, |
| 878 |
const std::vector<std::string>& elements |
| 879 |
) |
| 880 |
{ |
| 881 |
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>(); |
| 882 |
for (Gui::ViewProviderExtension* ext : vector) { |
| 883 |
if (ext->extensionCanDropObjectEx(obj, owner, subname, elements)) { |
| 884 |
return ext->extensionDropObjectEx(obj, owner, subname, elements); |
| 885 |
} |
| 886 |
} |
| 887 |
dropObject(obj); |
| 888 |
return {}; |
| 889 |
} |
| 890 |
|
| 891 |
int ViewProvider::replaceObject(App::DocumentObject* oldValue, App::DocumentObject* newValue) |
| 892 |
{ |
| 893 |
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>(); |
| 894 |
for (Gui::ViewProviderExtension* ext : vector) { |
| 895 |
if (ext->extensionCanDropObject(newValue)) { |
| 896 |
int ret = ext->extensionReplaceObject(oldValue, newValue); |
| 897 |
if (ret >= 0) { |
| 898 |
return !!ret; |
| 899 |
} |
| 900 |
} |
| 901 |
} |
| 902 |
return -1; |
| 903 |
} |
| 904 |
|
| 905 |
void ViewProvider::Restore(Base::XMLReader& reader) |
| 906 |
{ |
| 907 |
// Because some PropertyLists type properties are stored in a separate file, |
| 908 |
// and is thus restored outside this function. So we rely on Gui::Document |
| 909 |
// to set the isRestoring flags for us. |
| 910 |
// |
| 911 |
// setStatus(Gui::isRestoring, true); |
| 912 |
|
| 913 |
TransactionalObject::Restore(reader); |
| 914 |
|
| 915 |
// setStatus(Gui::isRestoring, false); |
| 916 |
} |
| 917 |
|
| 918 |
void ViewProvider::updateData(const App::Property* prop) |
| 919 |
{ |
| 920 |
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>(); |
| 921 |
for (Gui::ViewProviderExtension* ext : vector) { |
| 922 |
ext->extensionUpdateData(prop); |
| 923 |
} |
| 924 |
} |
| 925 |
|
| 926 |
SoSeparator* ViewProvider::getBackRoot() const |
| 927 |
{ |
| 928 |
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>(); |
| 929 |
for (Gui::ViewProviderExtension* ext : vector) { |
| 930 |
auto* node = ext->extensionGetBackRoot(); |
| 931 |
if (node) { |
| 932 |
return node; |
| 933 |
} |
| 934 |
} |
| 935 |
return nullptr; |
| 936 |
} |
| 937 |
|
| 938 |
SoGroup* ViewProvider::getChildRoot() const |
| 939 |
{ |
| 940 |
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>(); |
| 941 |
for (Gui::ViewProviderExtension* ext : vector) { |
| 942 |
auto* node = ext->extensionGetChildRoot(); |
| 943 |
if (node) { |
| 944 |
return node; |
| 945 |
} |
| 946 |
} |
| 947 |
return nullptr; |
| 948 |
} |
| 949 |
|
| 950 |
SoSeparator* ViewProvider::getFrontRoot() const |
| 951 |
{ |
| 952 |
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>(); |
| 953 |
for (Gui::ViewProviderExtension* ext : vector) { |
| 954 |
auto* node = ext->extensionGetFrontRoot(); |
| 955 |
if (node) { |
| 956 |
return node; |
| 957 |
} |
| 958 |
} |
| 959 |
return nullptr; |
| 960 |
} |
| 961 |
|
| 962 |
std::vector<App::DocumentObject*> ViewProvider::claimChildren() const |
| 963 |
{ |
| 964 |
std::vector<App::DocumentObject*> vec; |
| 965 |
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>(); |
| 966 |
for (Gui::ViewProviderExtension* ext : vector) { |
| 967 |
std::vector<App::DocumentObject*> nvec = ext->extensionClaimChildren(); |
| 968 |
if (!nvec.empty()) { |
| 969 |
vec.insert(std::end(vec), std::begin(nvec), std::end(nvec)); |
| 970 |
} |
| 971 |
} |
| 972 |
return vec; |
| 973 |
} |
| 974 |
|
| 975 |
std::vector<App::DocumentObject*> ViewProvider::claimChildrenRecursive() const |
| 976 |
{ |
| 977 |
std::vector<App::DocumentObject*> children = claimChildren(); |
| 978 |
for (auto* child : claimChildren()) { |
| 979 |
auto* vp = Application::Instance->getViewProvider(child); |
| 980 |
if (!vp) { |
| 981 |
continue; |
| 982 |
} |
| 983 |
|
| 984 |
std::vector<App::DocumentObject*> nvec = vp->claimChildrenRecursive(); |
| 985 |
if (!nvec.empty()) { |
| 986 |
children.insert(std::end(children), std::begin(nvec), std::end(nvec)); |
| 987 |
} |
| 988 |
} |
| 989 |
return children; |
| 990 |
} |
| 991 |
|
| 992 |
std::vector<App::DocumentObject*> ViewProvider::claimChildren3D() const |
| 993 |
{ |
| 994 |
std::vector<App::DocumentObject*> vec; |
| 995 |
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>(); |
| 996 |
for (Gui::ViewProviderExtension* ext : vector) { |
| 997 |
std::vector<App::DocumentObject*> nvec = ext->extensionClaimChildren3D(); |
| 998 |
if (!nvec.empty()) { |
| 999 |
vec.insert(std::end(vec), std::begin(nvec), std::end(nvec)); |
| 1000 |
} |
| 1001 |
} |
| 1002 |
return vec; |
| 1003 |
} |
| 1004 |
|
| 1005 |
bool ViewProvider::getElementPicked(const SoPickedPoint* pp, std::string& subname) const |
| 1006 |
{ |
| 1007 |
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>(); |
| 1008 |
for (Gui::ViewProviderExtension* ext : vector) { |
| 1009 |
if (ext->extensionGetElementPicked(pp, subname)) { |
| 1010 |
return true; |
| 1011 |
} |
| 1012 |
} |
| 1013 |
subname = getElement(pp ? pp->getDetail() : nullptr); |
| 1014 |
return true; |
| 1015 |
} |
| 1016 |
|
| 1017 |
bool ViewProvider::getDetailPath(const char* subname, SoFullPath* pPath, bool append, SoDetail*& det) const |
| 1018 |
{ |
| 1019 |
if (pcRoot->findChild(pcModeSwitch) < 0) { |
| 1020 |
// this is possible in case of editing, where the switch node |
| 1021 |
// of the linked view object is temporarily removed from its root |
| 1022 |
// if(append) |
| 1023 |
// pPath->append(pcRoot); |
| 1024 |
return false; |
| 1025 |
} |
| 1026 |
if (append) { |
| 1027 |
pPath->append(pcRoot); |
| 1028 |
pPath->append(pcModeSwitch); |
| 1029 |
} |
| 1030 |
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>(); |
| 1031 |
for (Gui::ViewProviderExtension* ext : vector) { |
| 1032 |
if (ext->extensionGetDetailPath(subname, pPath, det)) { |
| 1033 |
return true; |
| 1034 |
} |
| 1035 |
} |
| 1036 |
det = getDetail(subname); |
| 1037 |
return true; |
| 1038 |
} |
| 1039 |
|
| 1040 |
const std::string& ViewProvider::hiddenMarker() |
| 1041 |
{ |
| 1042 |
return App::DocumentObject::hiddenMarker(); |
| 1043 |
} |
| 1044 |
|
| 1045 |
const char* ViewProvider::hasHiddenMarker(const char* subname) |
| 1046 |
{ |
| 1047 |
return App::DocumentObject::hasHiddenMarker(subname); |
| 1048 |
} |
| 1049 |
|
| 1050 |
int ViewProvider::partialRender(const std::vector<std::string>& elements, bool clear) |
| 1051 |
{ |
| 1052 |
if (elements.empty()) { |
| 1053 |
auto node = pcModeSwitch->getChild(_iActualMode); |
| 1054 |
if (node) { |
| 1055 |
FC_LOG("partial render clear"); |
| 1056 |
SoSelectionElementAction action(SoSelectionElementAction::None, true); |
| 1057 |
action.apply(node); |
| 1058 |
} |
| 1059 |
} |
| 1060 |
int count = 0; |
| 1061 |
auto path = static_cast<SoFullPath*>(new SoPath); |
| 1062 |
path->ref(); |
| 1063 |
SoSelectionElementAction action; |
| 1064 |
action.setSecondary(true); |
| 1065 |
for (auto element : elements) { |
| 1066 |
bool hidden = hasHiddenMarker(element.c_str()); |
| 1067 |
if (hidden) { |
| 1068 |
element.resize(element.size() - hiddenMarker().size()); |
| 1069 |
} |
| 1070 |
path->truncate(0); |
| 1071 |
SoDetail* det = nullptr; |
| 1072 |
if (getDetailPath(element.c_str(), path, false, det)) { |
| 1073 |
if (!hidden && !det) { |
| 1074 |
FC_LOG("partial render element not found: " << element); |
| 1075 |
continue; |
| 1076 |
} |
| 1077 |
FC_LOG("partial render (" << path->getLength() << "): " << element); |
| 1078 |
if (!hidden) { |
| 1079 |
action.setType( |
| 1080 |
clear ? SoSelectionElementAction::Remove : SoSelectionElementAction::Append |
| 1081 |
); |
| 1082 |
} |
| 1083 |
else { |
| 1084 |
action.setType(clear ? SoSelectionElementAction::Show : SoSelectionElementAction::Hide); |
| 1085 |
} |
| 1086 |
action.setElement(det); |
| 1087 |
action.apply(path); |
| 1088 |
++count; |
| 1089 |
} |
| 1090 |
delete det; |
| 1091 |
} |
| 1092 |
path->unref(); |
| 1093 |
return count; |
| 1094 |
} |
| 1095 |
|
| 1096 |
bool ViewProvider::useNewSelectionModel() const |
| 1097 |
{ |
| 1098 |
return ViewParams::instance()->getUseNewSelection(); |
| 1099 |
} |
| 1100 |
|
| 1101 |
void ViewProvider::beforeDelete() |
| 1102 |
{ |
| 1103 |
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>(); |
| 1104 |
for (Gui::ViewProviderExtension* ext : vector) { |
| 1105 |
ext->extensionBeforeDelete(); |
| 1106 |
} |
| 1107 |
} |
| 1108 |
|
| 1109 |
void ViewProvider::setRenderCacheMode(int mode) |
| 1110 |
{ |
| 1111 |
pcRoot->renderCaching = mode == 0 ? SoSeparator::AUTO |
| 1112 |
: (mode == 1 ? SoSeparator::ON : SoSeparator::OFF); |
| 1113 |
} |
| 1114 |
|
| 1115 |
Base::BoundBox3d ViewProvider::getBoundingBox(const char* subname, bool transform, MDIView* view) const |
| 1116 |
{ |
| 1117 |
if (!pcRoot || !pcModeSwitch || pcRoot->findChild(pcModeSwitch) < 0) { |
| 1118 |
return Base::BoundBox3d(); |
| 1119 |
} |
| 1120 |
|
| 1121 |
if (!view) { |
| 1122 |
view = Application::Instance->activeView(); |
| 1123 |
} |
| 1124 |
auto iview = qobject_cast<View3DInventor*>(view); |
| 1125 |
if (!iview) { |
| 1126 |
auto doc = Application::Instance->activeDocument(); |
| 1127 |
if (doc) { |
| 1128 |
auto views = doc->getMDIViewsOfType(View3DInventor::getClassTypeId()); |
| 1129 |
if (!views.empty()) { |
| 1130 |
iview = qobject_cast<View3DInventor*>(views.front()); |
| 1131 |
} |
| 1132 |
} |
| 1133 |
if (!iview) { |
| 1134 |
FC_ERR("no view"); |
| 1135 |
return Base::BoundBox3d(); |
| 1136 |
} |
| 1137 |
} |
| 1138 |
|
| 1139 |
View3DInventorViewer* viewer = iview->getViewer(); |
| 1140 |
SoGetBoundingBoxAction bboxAction(viewer->getSoRenderManager()->getViewportRegion()); |
| 1141 |
|
| 1142 |
auto mode = pcModeSwitch->whichChild.getValue(); |
| 1143 |
if (mode < 0) { |
| 1144 |
pcModeSwitch->whichChild = getDefaultMode(); |
| 1145 |
} |
| 1146 |
|
| 1147 |
SoTempPath path(20); |
| 1148 |
path.ref(); |
| 1149 |
if (!Base::Tools::isNullOrEmpty(subname)) { |
| 1150 |
SoDetail* det = nullptr; |
| 1151 |
if (!getDetailPath(subname, &path, true, det)) { |
| 1152 |
if (mode < 0) { |
| 1153 |
pcModeSwitch->whichChild = mode; |
| 1154 |
} |
| 1155 |
path.unrefNoDelete(); |
| 1156 |
return Base::BoundBox3d(); |
| 1157 |
} |
| 1158 |
delete det; |
| 1159 |
} |
| 1160 |
SoTempPath resetPath(3); |
| 1161 |
resetPath.ref(); |
| 1162 |
if (!transform) { |
| 1163 |
resetPath.append(pcRoot); |
| 1164 |
resetPath.append(pcModeSwitch); |
| 1165 |
bboxAction.setResetPath(&resetPath, true, SoGetBoundingBoxAction::TRANSFORM); |
| 1166 |
} |
| 1167 |
if (path.getLength()) { |
| 1168 |
bboxAction.apply(&path); |
| 1169 |
} |
| 1170 |
else { |
| 1171 |
bboxAction.apply(pcRoot); |
| 1172 |
} |
| 1173 |
if (mode < 0) { |
| 1174 |
pcModeSwitch->whichChild = mode; |
| 1175 |
} |
| 1176 |
resetPath.unrefNoDelete(); |
| 1177 |
path.unrefNoDelete(); |
| 1178 |
auto bbox = bboxAction.getBoundingBox(); |
| 1179 |
float minX, minY, minZ, maxX, maxY, maxZ; |
| 1180 |
bbox.getMax().getValue(maxX, maxY, maxZ); |
| 1181 |
bbox.getMin().getValue(minX, minY, minZ); |
| 1182 |
return Base::BoundBox3d(minX, minY, minZ, maxX, maxY, maxZ); |
| 1183 |
} |
| 1184 |
|
| 1185 |
bool ViewProvider::isLinkVisible() const |
| 1186 |
{ |
| 1187 |
auto ext = getExtensionByType<ViewProviderLinkObserver>(true); |
| 1188 |
if (!ext) { |
| 1189 |
return true; |
| 1190 |
} |
| 1191 |
return ext->isLinkVisible(); |
| 1192 |
} |
| 1193 |
|
| 1194 |
void ViewProvider::setLinkVisible(bool visible) |
| 1195 |
{ |
| 1196 |
auto ext = getExtensionByType<ViewProviderLinkObserver>(true); |
| 1197 |
if (ext) { |
| 1198 |
ext->setLinkVisible(visible); |
| 1199 |
} |
| 1200 |
} |