diff --git a/src/Gui/View3DInventorViewer.cpp b/src/Gui/View3DInventorViewer.cpp index eb3cde7394..5677d7cfa8 100644 --- a/src/Gui/View3DInventorViewer.cpp +++ b/src/Gui/View3DInventorViewer.cpp @@ -120,6 +120,7 @@ #include "ViewProviderLink.h" #include "NavigationAnimator.h" #include "NavigationAnimation.h" +#include "Utilities.h" FC_LOG_LEVEL_INIT("3DViewer",true,true) @@ -128,6 +129,8 @@ FC_LOG_LEVEL_INIT("3DViewer",true,true) using namespace Gui; +// NOLINTBEGIN +// clang-format off /*** zoom-style cursor ******/ #define ZOOM_WIDTH 16 @@ -138,17 +141,18 @@ using namespace Gui; static unsigned char zoom_bitmap[ZOOM_BYTES] = { - 0x00, 0x0f, 0x80, 0x1c, 0x40, 0x38, 0x20, 0x70, - 0x90, 0xe4, 0xc0, 0xcc, 0xf0, 0xfc, 0x00, 0x0c, - 0x00, 0x0c, 0xf0, 0xfc, 0xc0, 0xcc, 0x90, 0xe4, - 0x20, 0x70, 0x40, 0x38, 0x80, 0x1c, 0x00, 0x0f + 0x00, 0x0f, 0x80, 0x1c, 0x40, 0x38, 0x20, 0x70, + 0x90, 0xe4, 0xc0, 0xcc, 0xf0, 0xfc, 0x00, 0x0c, + 0x00, 0x0c, 0xf0, 0xfc, 0xc0, 0xcc, 0x90, 0xe4, + 0x20, 0x70, 0x40, 0x38, 0x80, 0x1c, 0x00, 0x0f }; static unsigned char zoom_mask_bitmap[ZOOM_BYTES] = { - 0x00,0x0f,0x80,0x1f,0xc0,0x3f,0xe0,0x7f,0xf0,0xff,0xf0,0xff,0xf0,0xff,0x00, - 0x0f,0x00,0x0f,0xf0,0xff,0xf0,0xff,0xf0,0xff,0xe0,0x7f,0xc0,0x3f,0x80,0x1f, - 0x00,0x0f + 0x00, 0x0f, 0x80, 0x1f, 0xc0, 0x3f, 0xe0, 0x7f, + 0xf0, 0xff, 0xf0, 0xff, 0xf0, 0xff, 0x00, 0x0f, + 0x00, 0x0f, 0xf0, 0xff, 0xf0, 0xff, 0xf0, 0xff, + 0xe0, 0x7f, 0xc0, 0x3f, 0x80, 0x1f, 0x00, 0x0f }; /*** pan-style cursor *******/ @@ -161,17 +165,18 @@ static unsigned char zoom_mask_bitmap[ZOOM_BYTES] = static unsigned char pan_bitmap[PAN_BYTES] = { - 0xc0, 0x03, 0x60, 0x02, 0x20, 0x04, 0x10, 0x08, - 0x68, 0x16, 0x54, 0x2a, 0x73, 0xce, 0x01, 0x80, - 0x01, 0x80, 0x73, 0xce, 0x54, 0x2a, 0x68, 0x16, - 0x10, 0x08, 0x20, 0x04, 0x40, 0x02, 0xc0, 0x03 + 0xc0, 0x03, 0x60, 0x02, 0x20, 0x04, 0x10, 0x08, + 0x68, 0x16, 0x54, 0x2a, 0x73, 0xce, 0x01, 0x80, + 0x01, 0x80, 0x73, 0xce, 0x54, 0x2a, 0x68, 0x16, + 0x10, 0x08, 0x20, 0x04, 0x40, 0x02, 0xc0, 0x03 }; static unsigned char pan_mask_bitmap[PAN_BYTES] = { - 0xc0,0x03,0xe0,0x03,0xe0,0x07,0xf0,0x0f,0xe8,0x17,0xdc,0x3b,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xdc,0x3b,0xe8,0x17,0xf0,0x0f,0xe0,0x07,0xc0,0x03, - 0xc0,0x03 + 0xc0, 0x03, 0xe0, 0x03, 0xe0, 0x07, 0xf0, 0x0f, + 0xe8, 0x17, 0xdc, 0x3b, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xdc, 0x3b, 0xe8, 0x17, + 0xf0, 0x0f, 0xe0, 0x07, 0xc0, 0x03, 0xc0, 0x03 }; /*** rotate-style cursor ****/ @@ -183,17 +188,20 @@ static unsigned char pan_mask_bitmap[PAN_BYTES] = #define ROTATE_HOT_Y 8 static unsigned char rotate_bitmap[ROTATE_BYTES] = { - 0xf0, 0xef, 0x18, 0xb8, 0x0c, 0x90, 0xe4, 0x83, - 0x34, 0x86, 0x1c, 0x83, 0x00, 0x81, 0x00, 0xff, - 0xff, 0x00, 0x81, 0x00, 0xc1, 0x38, 0x61, 0x2c, - 0xc1, 0x27, 0x09, 0x30, 0x1d, 0x18, 0xf7, 0x0f + 0xf0, 0xef, 0x18, 0xb8, 0x0c, 0x90, 0xe4, 0x83, + 0x34, 0x86, 0x1c, 0x83, 0x00, 0x81, 0x00, 0xff, + 0xff, 0x00, 0x81, 0x00, 0xc1, 0x38, 0x61, 0x2c, + 0xc1, 0x27, 0x09, 0x30, 0x1d, 0x18, 0xf7, 0x0f }; static unsigned char rotate_mask_bitmap[ROTATE_BYTES] = { - 0xf0,0xef,0xf8,0xff,0xfc,0xff,0xfc,0xff,0x3c,0xfe,0x1c,0xff,0x00,0xff,0x00, - 0xff,0xff,0x00,0xff,0x00,0xff,0x38,0x7f,0x3c,0xff,0x3f,0xff,0x3f,0xff,0x1f, - 0xf7,0x0f + 0xf0, 0xef, 0xf8, 0xff, 0xfc, 0xff, 0xfc, 0xff, + 0x3c, 0xfe, 0x1c, 0xff, 0x00, 0xff, 0x00, 0xff, + 0xff, 0x00, 0xff, 0x00, 0xff, 0x38, 0x7f, 0x3c, + 0xff, 0x3f, 0xff, 0x3f, 0xff, 0x1f, 0xf7, 0x0f }; +// clang-format on +// NOLINTEND /*! @@ -212,29 +220,32 @@ public: // lead to some unwanted zooming when pressing the MMB for panning. // Thus, we filter out horizontal scrolling. if (event->type() == QEvent::Wheel) { - auto we = static_cast(event); - if (qAbs(we->angleDelta().x()) > qAbs(we->angleDelta().y())) + auto we = static_cast(event); // NOLINT + if (qAbs(we->angleDelta().x()) > qAbs(we->angleDelta().y())) { return true; + } } else if (event->type() == QEvent::KeyPress) { - auto ke = static_cast(event); + auto ke = static_cast(event); // NOLINT if (ke->matches(QKeySequence::SelectAll)) { static_cast(obj)->selectAll(); return true; } } - if (Base::Sequencer().isRunning() && Base::Sequencer().isBlocking()) + + if (Base::Sequencer().isRunning() && Base::Sequencer().isBlocking()) { return false; + } if (event->type() == Spaceball::ButtonEvent::ButtonEventType) { - auto buttonEvent = static_cast(event); + auto buttonEvent = static_cast(event); // NOLINT if (!buttonEvent) { Base::Console().Log("invalid spaceball button event\n"); return true; } } else if (event->type() == Spaceball::MotionEvent::MotionEventType) { - auto motionEvent = static_cast(event); + auto motionEvent = static_cast(event); // NOLINT if (!motionEvent) { Base::Console().Log("invalid spaceball motion event\n"); return true; @@ -252,7 +263,7 @@ public: const SoEvent* translateEvent(QEvent* event) override { if (event->type() == Spaceball::MotionEvent::MotionEventType) { - auto motionEvent = static_cast(event); + auto motionEvent = static_cast(event); // NOLINT if (!motionEvent) { Base::Console().Log("invalid spaceball motion event\n"); return nullptr; @@ -260,14 +271,18 @@ public: motionEvent->setHandled(true); - float xTrans, yTrans, zTrans; + float xTrans{}; + float yTrans{}; + float zTrans{}; xTrans = static_cast(motionEvent->translationX()); yTrans = static_cast(motionEvent->translationY()); zTrans = static_cast(motionEvent->translationZ()); SbVec3f translationVector(xTrans, yTrans, zTrans); - static float rotationConstant(.0001f); - SbRotation xRot, yRot, zRot; + constexpr const float rotationConstant(.0001F); + SbRotation xRot; + SbRotation yRot; + SbRotation zRot; xRot.setValue(SbVec3f(1.0, 0.0, 0.0), static_cast(motionEvent->rotationX()) * rotationConstant); yRot.setValue(SbVec3f(0.0, 1.0, 0.0), static_cast(motionEvent->rotationY()) * rotationConstant); zRot.setValue(SbVec3f(0.0, 0.0, 1.0), static_cast(motionEvent->rotationZ()) * rotationConstant); @@ -376,7 +391,7 @@ View3DInventorViewer::View3DInventorViewer(const QtGLFormat& format, QWidget* pa void View3DInventorViewer::init() { static bool _cacheModeInited; - if(!_cacheModeInited) { + if (!_cacheModeInited) { _cacheModeInited = true; pcViewProviderRoot = nullptr; setRenderCache(-1); @@ -395,11 +410,13 @@ void View3DInventorViewer::init() // setting up the defaults for the spin rotation initialize(); + // NOLINTBEGIN auto cam = new SoOrthographicCamera; cam->position = SbVec3f(0, 0, 1); cam->height = 1; cam->nearDistance = 0.5; cam->farDistance = 1.5; + // NOLINTEND // setup light sources SoDirectionalLight* hl = this->getHeadlight(); @@ -428,11 +445,13 @@ void View3DInventorViewer::init() auto bc = new SoBaseColor; bc->rgb = SbColor(1, 1, 0); + // NOLINTBEGIN cam = new SoOrthographicCamera; cam->position = SbVec3f(0, 0, 5); cam->height = 10; cam->nearDistance = 0; cam->farDistance = 10; + // NOLINTEND this->foregroundroot->addChild(cam); this->foregroundroot->addChild(lm); @@ -508,15 +527,16 @@ void View3DInventorViewer::init() getSoRenderManager()->getGLRenderAction()->setTransparencyType(SoGLRenderAction::SORTED_OBJECT_SORTED_TRIANGLE_BLEND); // Settings - setSeekTime(0.4f); + setSeekTime(0.4F); // NOLINT - if (!isSeekValuePercentage()) + if (!isSeekValuePercentage()) { setSeekValueAsPercentage(true); + } - setSeekDistance(100); + setSeekDistance(100); // NOLINT setViewing(false); - setBackgroundColor(QColor(25, 25, 25)); + setBackgroundColor(QColor(25, 25, 25)); // NOLINT setGradientBackground(Background::LinearGradient); // set some callback functions for user interaction @@ -588,14 +608,16 @@ View3DInventorViewer::~View3DInventorViewer() this->pcEditingRoot->unref(); this->pcEditingTransform->unref(); - if (this->pcClipPlane) + if (this->pcClipPlane) { this->pcClipPlane->unref(); + } delete this->navigation; // Note: When closing the application the main window doesn't exist any more. - if (getMainWindow()) + if (getMainWindow()) { getMainWindow()->setPaneText(2, QLatin1String("")); + } detachSelection(); @@ -618,6 +640,7 @@ View3DInventorViewer::~View3DInventorViewer() void View3DInventorViewer::createStandardCursors(double dpr) { + // NOLINTBEGIN QBitmap cursor = QBitmap::fromData(QSize(ROTATE_WIDTH, ROTATE_HEIGHT), rotate_bitmap); QBitmap mask = QBitmap::fromData(QSize(ROTATE_WIDTH, ROTATE_HEIGHT), rotate_mask_bitmap); #if defined(Q_OS_WIN32) @@ -643,14 +666,15 @@ void View3DInventorViewer::createStandardCursors(double dpr) mask.setDevicePixelRatio(dpr); #endif panCursor = QCursor(cursor, mask, PAN_HOT_X, PAN_HOT_Y); + // NOLINTEND } void View3DInventorViewer::aboutToDestroyGLContext() { if (naviCube) { - auto gl = qobject_cast(this->viewport()); - if (gl) + if (auto gl = qobject_cast(this->viewport())) { gl->makeCurrent(); + } delete naviCube; naviCube = nullptr; naviCubeEnabled = false; @@ -685,32 +709,37 @@ void View3DInventorViewer::initialize() navigation->setViewer(this); this->axiscrossEnabled = true; - this->axiscrossSize = 10; + this->axiscrossSize = 10; // NOLINT } /// @cond DOXERR -void View3DInventorViewer::onSelectionChanged(const SelectionChanges &_Reason) +void View3DInventorViewer::onSelectionChanged(const SelectionChanges & reason) { - if(!getDocument()) + if(!getDocument()) { return; + } - SelectionChanges Reason(_Reason); + SelectionChanges Reason(reason); if(Reason.pDocName && *Reason.pDocName && - strcmp(getDocument()->getDocument()->getName(),Reason.pDocName)!=0) + strcmp(getDocument()->getDocument()->getName(),Reason.pDocName)!=0) { return; + } switch(Reason.Type) { case SelectionChanges::ShowSelection: case SelectionChanges::HideSelection: - if(Reason.Type == SelectionChanges::ShowSelection) + if (Reason.Type == SelectionChanges::ShowSelection) { Reason.Type = SelectionChanges::AddSelection; - else + } + else { Reason.Type = SelectionChanges::RmvSelection; + } // fall through case SelectionChanges::SetPreselect: - if(Reason.SubType != SelectionChanges::MsgSource::TreeView) + if(Reason.SubType != SelectionChanges::MsgSource::TreeView) { break; + } // fall through case SelectionChanges::RmvPreselect: case SelectionChanges::RmvPreselectSignal: @@ -782,13 +811,13 @@ void View3DInventorViewer::addViewProvider(ViewProvider* pcProvider) _ViewProviderMap[root] = pcProvider; } - SoSeparator* fore = pcProvider->getFrontRoot(); - if (fore) + if (SoSeparator* fore = pcProvider->getFrontRoot()) { foregroundroot->addChild(fore); + } - SoSeparator* back = pcProvider->getBackRoot(); - if (back) + if (SoSeparator* back = pcProvider->getBackRoot()) { backgroundroot->addChild(back); + } pcProvider->setOverrideMode(this->getOverrideMode()); _ViewProviderSet.insert(pcProvider); @@ -796,8 +825,9 @@ void View3DInventorViewer::addViewProvider(ViewProvider* pcProvider) void View3DInventorViewer::removeViewProvider(ViewProvider* pcProvider) { - if (this->editViewProvider == pcProvider) + if (this->editViewProvider == pcProvider) { resetEditingViewProvider(); + } SoSeparator* root = pcProvider->getRoot(); @@ -814,19 +844,21 @@ void View3DInventorViewer::removeViewProvider(ViewProvider* pcProvider) _ViewProviderMap.erase(root); } - SoSeparator* fore = pcProvider->getFrontRoot(); - if (fore) + if (SoSeparator* fore = pcProvider->getFrontRoot()) { foregroundroot->removeChild(fore); + } - SoSeparator* back = pcProvider->getBackRoot(); - if (back) + if (SoSeparator* back = pcProvider->getBackRoot()) { backgroundroot->removeChild(back); + } _ViewProviderSet.erase(pcProvider); } -void View3DInventorViewer::setEditingTransform(const Base::Matrix4D &mat) { - if(pcEditingTransform) { +void View3DInventorViewer::setEditingTransform(const Base::Matrix4D &mat) +{ + // NOLINTBEGIN + if (pcEditingTransform) { double dMtrx[16]; mat.getGLMatrix(dMtrx); pcEditingTransform->setMatrix(SbMatrix( @@ -835,16 +867,21 @@ void View3DInventorViewer::setEditingTransform(const Base::Matrix4D &mat) { dMtrx[8], dMtrx[9], dMtrx[10], dMtrx[11], dMtrx[12],dMtrx[13],dMtrx[14], dMtrx[15])); } + // NOLINTEND } void View3DInventorViewer::setupEditingRoot(SoNode *node, const Base::Matrix4D *mat) { - if(!editViewProvider) + if(!editViewProvider) { return; + } + resetEditingRoot(false); - if(mat) + if(mat) { setEditingTransform(*mat); - else + } + else { setEditingTransform(getDocument()->getEditingTransform()); + } if(node) { restoreEditingRoot = false; pcEditingRoot->addChild(node); @@ -854,8 +891,9 @@ void View3DInventorViewer::setupEditingRoot(SoNode *node, const Base::Matrix4D * auto root = editViewProvider->getRoot(); for(int i=0,count=root->getNumChildren();igetChild(i); - if(node != editViewProvider->getTransformNode()) + if(node != editViewProvider->getTransformNode()) { pcEditingRoot->addChild(node); + } } coinRemoveAllChildren(root); ViewProviderLink::updateLinks(editViewProvider); @@ -863,25 +901,29 @@ void View3DInventorViewer::setupEditingRoot(SoNode *node, const Base::Matrix4D * void View3DInventorViewer::resetEditingRoot(bool updateLinks) { - if(!editViewProvider || pcEditingRoot->getNumChildren()<=1) + if(!editViewProvider || pcEditingRoot->getNumChildren()<=1) { return; + } if(!restoreEditingRoot) { pcEditingRoot->getChildren()->truncate(1); return; } restoreEditingRoot = false; auto root = editViewProvider->getRoot(); - if(root->getNumChildren()) + if (root->getNumChildren()) { FC_ERR("WARNING!!! Editing view provider root node is tampered"); + } root->addChild(editViewProvider->getTransformNode()); - for(int i=1,count=pcEditingRoot->getNumChildren();igetNumChildren();iaddChild(pcEditingRoot->getChild(i)); + } pcEditingRoot->getChildren()->truncate(1); // handle exceptions eventually raised by ViewProviderLink try { - if (updateLinks) + if (updateLinks) { ViewProviderLink::updateLinks(editViewProvider); + } } catch (const Py::Exception& e) { /* coverity[UNCAUGHT_EXCEPT] Uncaught exception */ @@ -892,14 +934,14 @@ void View3DInventorViewer::resetEditingRoot(bool updateLinks) // will be handled and thus terminates the application. So, add an // extra try/catch block here. try { - Py::Object o = Py::type(e); - if (o.isString()) { - Py::String s(o); - Base::Console().Warning("%s\n", s.as_std_string("utf-8").c_str()); + Py::Object py = Py::type(e); + if (py.isString()) { + Py::String str(py); + Base::Console().Warning("%s\n", str.as_std_string("utf-8").c_str()); } else { - Py::String s(o.repr()); - Base::Console().Warning("%s\n", s.as_std_string("utf-8").c_str()); + Py::String str(py.repr()); + Base::Console().Warning("%s\n", str.as_std_string("utf-8").c_str()); } // Prints message to console window if we are in interactive mode PyErr_Print(); @@ -913,7 +955,7 @@ void View3DInventorViewer::resetEditingRoot(bool updateLinks) SoPickedPoint* View3DInventorViewer::getPointOnRay(const SbVec2s& pos, const ViewProvider* vp) const { - SoPath *path; + SoPath *path{}; if (vp == editViewProvider && pcEditingRoot->getNumChildren() > 1) { path = new SoPath(1); path->ref(); @@ -926,8 +968,9 @@ SoPickedPoint* View3DInventorViewer::getPointOnRay(const SbVec2s& pos, const Vie sa.setSearchingAll(true); sa.apply(getSoRenderManager()->getSceneGraph()); path = sa.getPath(); - if (!path) + if (!path) { return nullptr; + } path->ref(); } SoGetMatrixAction gm(getSoRenderManager()->getViewportRegion()); @@ -963,7 +1006,7 @@ SoPickedPoint* View3DInventorViewer::getPointOnRay(const SbVec3f& pos, const SbV // Note: There seems to be a bug with setRay() which causes SoRayPickAction // to fail to get intersections between the ray and a line - SoPath *path; + SoPath *path{}; if (vp == editViewProvider && pcEditingRoot->getNumChildren() > 1) { path = new SoPath(1); path->ref(); @@ -976,8 +1019,9 @@ SoPickedPoint* View3DInventorViewer::getPointOnRay(const SbVec3f& pos, const SbV sa.setSearchingAll(true); sa.apply(getSoRenderManager()->getSceneGraph()); path = sa.getPath(); - if (!path) + if (!path) { return nullptr; + } path->ref(); } SoGetMatrixAction gm(getSoRenderManager()->getViewportRegion()); @@ -1010,9 +1054,9 @@ SoPickedPoint* View3DInventorViewer::getPointOnRay(const SbVec3f& pos, const SbV return (pick ? new SoPickedPoint(*pick) : nullptr); } -void View3DInventorViewer::setEditingViewProvider(Gui::ViewProvider* p, int ModNum) +void View3DInventorViewer::setEditingViewProvider(Gui::ViewProvider* vp, int ModNum) { - this->editViewProvider = p; + this->editViewProvider = vp; this->editViewProvider->setEditViewer(this, ModNum); addEventCallback(SoEvent::getClassTypeId(), Gui::ViewProvider::eventCallback,this->editViewProvider); } @@ -1026,8 +1070,9 @@ void View3DInventorViewer::resetEditingViewProvider() // force to release it now SoEventManager* mgr = getSoEventManager(); SoHandleEventAction* heaction = mgr->getHandleEventAction(); - if (heaction && heaction->getGrabber()) + if (heaction && heaction->getGrabber()) { heaction->releaseGrabber(); + } resetEditingRoot(); @@ -1040,14 +1085,15 @@ void View3DInventorViewer::resetEditingViewProvider() /// reset from edit mode SbBool View3DInventorViewer::isEditingViewProvider() const { - return this->editViewProvider ? true : false; + return this->editViewProvider != nullptr; } /// display override mode void View3DInventorViewer::setOverrideMode(const std::string& mode) { - if (mode == overrideMode) + if (mode == overrideMode) { return; + } overrideMode = mode; @@ -1055,21 +1101,24 @@ void View3DInventorViewer::setOverrideMode(const std::string& mode) if (mode == "No Shading") { this->shading = false; std::string flatLines = "Flat Lines"; - for (auto view : views) + for (auto view : views) { view->setOverrideMode(flatLines); + } this->getSoRenderManager()->setRenderMode(SoRenderManager::AS_IS); } else if (mode == "Hidden Line") { this->shading = true; std::string shaded = "Shaded"; - for (auto view : views) + for (auto view : views) { view->setOverrideMode(shaded); + } this->getSoRenderManager()->setRenderMode(SoRenderManager::HIDDEN_LINE); } else { this->shading = true; - for (auto view : views) + for (auto view : views) { view->setOverrideMode(mode); + } this->getSoRenderManager()->setRenderMode(SoRenderManager::AS_IS); } } @@ -1077,8 +1126,9 @@ void View3DInventorViewer::setOverrideMode(const std::string& mode) /// update override mode. doesn't affect providers void View3DInventorViewer::updateOverrideMode(const std::string& mode) { - if (mode == overrideMode) + if (mode == overrideMode) { return; + } overrideMode = mode; @@ -1096,19 +1146,21 @@ void View3DInventorViewer::updateOverrideMode(const std::string& mode) } } -void View3DInventorViewer::setViewportCB(void*, SoAction* action) +void View3DInventorViewer::setViewportCB(void* ud, SoAction* action) { + Q_UNUSED(ud) // Make sure to override the value set inside SoOffscreenRenderer::render() if (action->isOfType(SoGLRenderAction::getClassTypeId())) { SoFCOffscreenRenderer& renderer = SoFCOffscreenRenderer::instance(); const SbViewportRegion& vp = renderer.getViewportRegion(); SoViewportRegionElement::set(action->getState(), vp); - static_cast(action)->setViewportRegion(vp); + static_cast(action)->setViewportRegion(vp); // NOLINT } } -void View3DInventorViewer::clearBufferCB(void*, SoAction* action) +void View3DInventorViewer::clearBufferCB(void* ud, SoAction* action) { + Q_UNUSED(ud) if (action->isOfType(SoGLRenderAction::getClassTypeId())) { // do stuff specific for GL rendering here. glClear(GL_DEPTH_BUFFER_BIT); @@ -1126,9 +1178,9 @@ void View3DInventorViewer::setGLWidgetCB(void* userdata, SoAction* action) } } -void View3DInventorViewer::handleEventCB(void* ud, SoEventCallback* n) +void View3DInventorViewer::handleEventCB(void* userdata, SoEventCallback* n) { - auto that = static_cast(ud); + auto that = static_cast(userdata); SoGLRenderAction* glra = that->getSoRenderManager()->getGLRenderAction(); SoAction* action = n->getAction(); SoGLRenderActionElement::set(action->getState(), glra); @@ -1203,7 +1255,7 @@ void View3DInventorViewer::setRenderCache(int mode) { static int canAutoCache = -1; - if (mode<0) { + if (mode < 0) { // Work around coin bug of unmatched call of // SoGLLazyElement::begin/endCaching() when on top rendering // transparent object with SORTED_OBJECT_SORTED_TRIANGLE_BLEND @@ -1215,13 +1267,15 @@ void View3DInventorViewer::setRenderCache(int mode) int setting = ViewParams::instance()->getRenderCache(); if (mode == -2) { - if (pcViewProviderRoot && setting != 1) + if (pcViewProviderRoot && setting != 1) { pcViewProviderRoot->renderCaching = SoSeparator::ON; + } mode = 2; } else { - if (pcViewProviderRoot) + if (pcViewProviderRoot) { pcViewProviderRoot->renderCaching = SoSeparator::AUTO; + } mode = setting; } } @@ -1233,8 +1287,9 @@ void View3DInventorViewer::setRenderCache(int mode) // If coin auto cache is disabled, do not use 'Auto' render cache mode, but // fallback to 'Distributed' mode. - if (!canAutoCache && mode != 2) + if (!canAutoCache && mode != 2) { mode = 1; + } auto caching = mode == 0 ? SoSeparator::AUTO : (mode == 1 ? SoSeparator::ON : @@ -1253,10 +1308,11 @@ bool View3DInventorViewer::isEnabledNaviCube() const return naviCubeEnabled; } -void View3DInventorViewer::setNaviCubeCorner(int c) +void View3DInventorViewer::setNaviCubeCorner(int cc) { - if (naviCube) - naviCube->setCorner(static_cast(c)); + if (naviCube) { + naviCube->setCorner(static_cast(cc)); + } } NaviCube* View3DInventorViewer::getNaviCube() const @@ -1267,7 +1323,7 @@ NaviCube* View3DInventorViewer::getNaviCube() const void View3DInventorViewer::setAxisCross(bool on) { SoNode* scene = getSceneGraph(); - auto sep = static_cast(scene); + auto sep = static_cast(scene); // NOLINT if (on) { if (!axisGroup) { @@ -1277,7 +1333,7 @@ void View3DInventorViewer::setAxisCross(bool on) axisKit->set("yAxis.appearance.drawStyle", "lineWidth 2"); axisKit->set("zAxis.appearance.drawStyle", "lineWidth 2"); axisCross->setPart("shape", axisKit); - axisCross->scaleFactor = 1.0f; + axisCross->scaleFactor = 1.0F; axisGroup = new SoSkipBoundingGroup; axisGroup->addChild(axisCross); @@ -1304,14 +1360,14 @@ void View3DInventorViewer::showRotationCenter(bool show) return; } - auto sep = static_cast(scene); + auto sep = static_cast(scene); // NOLINT bool showEnabled = App::GetApplication() .GetParameterGroupByPath("User parameter:BaseApp/Preferences/View") ->GetBool("ShowRotationCenter", true); if (show && showEnabled) { - SbBool found; + SbBool found{}; SbVec3f center = navigation->getRotationCenter(found); if (!found) { @@ -1321,12 +1377,12 @@ void View3DInventorViewer::showRotationCenter(bool show) if (!rotationCenterGroup) { float size = App::GetApplication() .GetParameterGroupByPath("User parameter:BaseApp/Preferences/View") - ->GetFloat("RotationCenterSize", 5.0); + ->GetFloat("RotationCenterSize", 5.0); // NOLINT unsigned long rotationCenterColor = App::GetApplication() .GetParameterGroupByPath("User parameter:BaseApp/Preferences/View") - ->GetUnsigned("RotationCenterColor", 4278190131); + ->GetUnsigned("RotationCenterColor", 4278190131); // NOLINT QColor color = App::Color::fromPackedRGBA(rotationCenterColor); @@ -1345,8 +1401,10 @@ void View3DInventorViewer::showRotationCenter(bool show) complexity->value = 1; auto material = new SoMaterial(); - material->emissiveColor = SbColor(color.redF(), color.greenF(), color.blueF()); - material->transparency = 1.0F - color.alphaF(); + material->emissiveColor = SbColor(float(color.redF()), + float(color.greenF()), + float(color.blueF())); + material->transparency = 1.0F - float(color.alphaF()); auto translation = new SoTranslation(); translation->translation.setValue(center); @@ -1375,13 +1433,14 @@ void View3DInventorViewer::showRotationCenter(bool show) } } -void View3DInventorViewer::setNavigationType(Base::Type t) +void View3DInventorViewer::setNavigationType(Base::Type type) { - if (this->navigation && this->navigation->getTypeId() == t) + if (this->navigation && this->navigation->getTypeId() == type) { return; // nothing to do + } - Base::Type type = Base::Type::getTypeIfDerivedFrom(t.getName(), NavigationStyle::getClassTypeId()); - auto ns = static_cast(type.createInstance()); + Base::Type navtype = Base::Type::getTypeIfDerivedFrom(type.getName(), NavigationStyle::getClassTypeId()); + auto ns = static_cast(navtype.createInstance()); // createInstance could return a null pointer if (!ns) { #if FC_DEBUG @@ -1435,12 +1494,13 @@ void View3DInventorViewer::setSceneGraph(SoNode* root) SoNode* scene = this->getSoRenderManager()->getSceneGraph(); if (scene && scene->getTypeId().isDerivedFrom(SoSeparator::getClassTypeId())) { sa.apply(scene); - if (!sa.getPath()) + if (!sa.getPath()) { static_cast(scene)->insertChild(this->backlight, 0); + } } } -void View3DInventorViewer::savePicture(int w, int h, int s, const QColor& bg, QImage& img) const +void View3DInventorViewer::savePicture(int width, int height, int sample, const QColor& bg, QImage& img) const { // Save picture methods: // FramebufferObject -- viewer renders into FBO (no offscreen) @@ -1463,15 +1523,16 @@ void View3DInventorViewer::savePicture(int w, int h, int s, const QColor& bg, QI } if (useFramebufferObject) { - auto self = const_cast(this); - self->imageFromFramebuffer(w, h, s, bg, img); + auto self = const_cast(this); // NOLINT + self->imageFromFramebuffer(width, height, sample, bg, img); return; } - else if (useGrabFramebuffer) { - auto self = const_cast(this); + + if (useGrabFramebuffer) { + auto self = const_cast(this); // NOLINT img = self->grabFramebuffer(); img = img.mirrored(); - img = img.scaledToWidth(w); + img = img.scaledToWidth(width); return; } @@ -1479,8 +1540,9 @@ void View3DInventorViewer::savePicture(int w, int h, int s, const QColor& bg, QI bool useBackground = false; SbViewportRegion vp(getSoRenderManager()->getViewportRegion()); - if (w>0 && h>0) - vp.setWindowSize((short)w, (short)h); + if (width > 0 && height > 0) { + vp.setWindowSize(short(width), short(height)); + } //NOTE: To support pixels per inch we must use SbViewportRegion::setPixelsPerInch( ppi ); //The default value is 72.0. @@ -1544,12 +1606,17 @@ void View3DInventorViewer::savePicture(int w, int h, int s, const QColor& bg, QI // render the scene if (!useCoinOffscreenRenderer) { SoQtOffscreenRenderer renderer(vp); - renderer.setNumPasses(s); + renderer.setNumPasses(sample); renderer.setInternalTextureFormat(getInternalTextureFormat()); - if (bgColor.isValid()) - renderer.setBackgroundColor(SbColor4f(bgColor.redF(), bgColor.greenF(), bgColor.blueF(), bgColor.alphaF())); - if (!renderer.render(root)) + if (bgColor.isValid()) { + renderer.setBackgroundColor(SbColor4f(float(bgColor.redF()), + float(bgColor.greenF()), + float(bgColor.blueF()), + float(bgColor.alphaF()))); + } + if (!renderer.render(root)) { throw Base::RuntimeError("Offscreen rendering failed"); + } renderer.writeToImage(img); root->unref(); @@ -1558,12 +1625,16 @@ void View3DInventorViewer::savePicture(int w, int h, int s, const QColor& bg, QI SoFCOffscreenRenderer& renderer = SoFCOffscreenRenderer::instance(); renderer.setViewportRegion(vp); renderer.getGLRenderAction()->setSmoothing(true); - renderer.getGLRenderAction()->setNumPasses(s); + renderer.getGLRenderAction()->setNumPasses(sample); renderer.getGLRenderAction()->setTransparencyType(SoGLRenderAction::SORTED_OBJECT_SORTED_TRIANGLE_BLEND); - if (bgColor.isValid()) - renderer.setBackgroundColor(SbColor(bgColor.redF(), bgColor.greenF(), bgColor.blueF())); - if (!renderer.render(root)) + if (bgColor.isValid()) { + renderer.setBackgroundColor(SbColor(float(bgColor.redF()), + float(bgColor.greenF()), + float(bgColor.blueF()))); + } + if (!renderer.render(root)) { throw Base::RuntimeError("Offscreen rendering failed"); + } renderer.writeToImage(img); root->unref(); @@ -1586,16 +1657,19 @@ void View3DInventorViewer::savePicture(int w, int h, int s, const QColor& bg, QI void View3DInventorViewer::saveGraphic(int pagesize, const QColor& bgcolor, SoVectorizeAction* va) const { - if (bgcolor.isValid()) - va->setBackgroundColor(true, SbColor(bgcolor.redF(), bgcolor.greenF(), bgcolor.blueF())); + if (bgcolor.isValid()) { + va->setBackgroundColor(true, SbColor(float(bgcolor.redF()), + float(bgcolor.greenF()), + float(bgcolor.blueF()))); + } - float border = 10.0f; + const float border = 10.0F; SbVec2s vpsize = this->getSoRenderManager()->getViewportRegion().getViewportSizePixels(); float vpratio = ((float)vpsize[0]) / ((float)vpsize[1]); - if (vpratio > 1.0f) { + if (vpratio > 1.0F) { va->setOrientation(SoVectorizeAction::LANDSCAPE); - vpratio = 1.0f / vpratio; + vpratio = 1.0F / vpratio; } else { va->setOrientation(SoVectorizeAction::PORTRAIT); @@ -1607,7 +1681,8 @@ void View3DInventorViewer::saveGraphic(int pagesize, const QColor& bgcolor, SoVe SbVec2f size = va->getPageSize(); float pageratio = size[0] / size[1]; - float xsize, ysize; + float xsize{}; + float ysize{}; if (pageratio < vpratio) { xsize = size[0]; @@ -1618,8 +1693,8 @@ void View3DInventorViewer::saveGraphic(int pagesize, const QColor& bgcolor, SoVe xsize = ysize * vpratio; } - float offx = border + (size[0]-xsize) * 0.5f; - float offy = border + (size[1]-ysize) * 0.5f; + float offx = border + (size[0]-xsize) * 0.5F; // NOLINT + float offy = border + (size[1]-ysize) * 0.5F; // NOLINT va->beginViewport(SbVec2f(offx, offy), SbVec2f(xsize, ysize)); va->calibrate(this->getSoRenderManager()->getViewportRegion()); @@ -1657,16 +1732,16 @@ const std::vector& View3DInventorViewer::getPolygon(SelectionRole* role return navigation->getPolygon(role); } -void View3DInventorViewer::setSelectionEnabled(const SbBool enable) +void View3DInventorViewer::setSelectionEnabled(SbBool enable) { SoNode* root = getSceneGraph(); - static_cast(root)->selectionRole.setValue(enable); + static_cast(root)->selectionRole.setValue(enable); // NOLINT } SbBool View3DInventorViewer::isSelectionEnabled() const { SoNode* root = getSceneGraph(); - return static_cast(root)->selectionRole.getValue(); + return static_cast(root)->selectionRole.getValue(); // NOLINT } SbVec2f View3DInventorViewer::screenCoordsOfPath(SoPath* path) const @@ -1679,8 +1754,8 @@ SbVec2f View3DInventorViewer::screenCoordsOfPath(SoPath* path) const // Use that matrix to translate the origin in the picked // object's coordinate space into object space SbVec3f imageCoords(0, 0, 0); - SbMatrix m = gma.getMatrix().transpose(); - m.multMatrixVec(imageCoords, imageCoords); + SbMatrix mat = gma.getMatrix().transpose(); + mat.multMatrixVec(imageCoords, imageCoords); // Now, project the object space coordinates of the object // into "normalized" screen coordinates. @@ -1695,13 +1770,13 @@ SbVec2f View3DInventorViewer::screenCoordsOfPath(SoPath* path) const // width or height. For instance, in a window that's 400px // tall and 800px wide, the Y will be within [0,1], but X can // vary within [-0.5,1.5]... - int width = getGLWidget()->width(), - height = getGLWidget()->height(); + int width = getGLWidget()->width(); + int height = getGLWidget()->height(); if (width >= height) { // "Landscape" orientation, to square imageCoords[0] *= height; - imageCoords[0] += (width-height) / 2.0; + imageCoords[0] += (width-height) / 2.0; // NOLINT imageCoords[1] *= height; } @@ -1709,7 +1784,7 @@ SbVec2f View3DInventorViewer::screenCoordsOfPath(SoPath* path) const // "Portrait" orientation imageCoords[0] *= width; imageCoords[1] *= width; - imageCoords[1] += (height-width) / 2.0; + imageCoords[1] += (height-width) / 2.0; // NOLINT } return {imageCoords[0], imageCoords[1]}; @@ -1718,13 +1793,11 @@ SbVec2f View3DInventorViewer::screenCoordsOfPath(SoPath* path) const std::vector View3DInventorViewer::getGLPolygon(const std::vector& pnts) const { const SbViewportRegion &vp = this->getSoRenderManager()->getViewportRegion(); - const SbVec2s &winSize = vp.getWindowSize(); - short w, h; - winSize.getValue(w, h); const SbVec2s &sp = vp.getViewportSizePixels(); const SbVec2s &op = vp.getViewportOriginPixels(); const SbVec2f &vpSize = vp.getViewportSize(); - float dX, dY; + float dX{}; + float dY{}; vpSize.getValue(dX, dY); float fRatio = vp.getViewportAspectRatio(); @@ -1732,17 +1805,18 @@ std::vector View3DInventorViewer::getGLPolygon(const std::vector 1.0f) { - pX = (pX - 0.5f * dX) * fRatio + 0.5f * dX; + if (fRatio > 1.0F) { + pX = (pX - 0.5F * dX) * fRatio + 0.5F * dX; // NOLINT pos.setValue(pX, pY); } - else if (fRatio < 1.0f) { - pY = (pY - 0.5f * dY) / fRatio + 0.5f * dY; + else if (fRatio < 1.0F) { + pY = (pY - 0.5F * dY) / fRatio + 0.5F * dY; // NOLINT pos.setValue(pX, pY); } @@ -1764,8 +1838,8 @@ bool View3DInventorViewer::dumpToFile(SoNode* node, const char* filename, bool b Base::FileInfo fi(filename); if (fi.hasExtension({"idtf", "svg"})) { - int ps=4; - QColor c = Qt::white; + int ps = 4; + QColor col = Qt::white; std::unique_ptr vo; if (fi.hasExtension("svg")) { @@ -1788,7 +1862,7 @@ bool View3DInventorViewer::dumpToFile(SoNode* node, const char* filename, bool b throw Base::FileSystemError(a_out.str()); } - saveGraphic(ps,c,vo.get()); + saveGraphic(ps, col, vo.get()); out->closeFile(); } else { @@ -1802,8 +1876,9 @@ bool View3DInventorViewer::dumpToFile(SoNode* node, const char* filename, bool b /** * Sets the SoFCInteractiveElement to \a true. */ -void View3DInventorViewer::interactionStartCB(void*, SoQTQuarterAdaptor* viewer) +void View3DInventorViewer::interactionStartCB(void* ud, SoQTQuarterAdaptor* viewer) { + Q_UNUSED(ud) SoGLRenderAction* glra = viewer->getSoRenderManager()->getGLRenderAction(); SoFCInteractiveElement::set(glra->getState(), viewer->getSceneGraph(), true); } @@ -1811,8 +1886,9 @@ void View3DInventorViewer::interactionStartCB(void*, SoQTQuarterAdaptor* viewer) /** * Sets the SoFCInteractiveElement to \a false and forces a redraw. */ -void View3DInventorViewer::interactionFinishCB(void*, SoQTQuarterAdaptor* viewer) +void View3DInventorViewer::interactionFinishCB(void* ud, SoQTQuarterAdaptor* viewer) { + Q_UNUSED(ud) SoGLRenderAction* glra = viewer->getSoRenderManager()->getGLRenderAction(); SoFCInteractiveElement::set(glra->getState(), viewer->getSceneGraph(), false); viewer->redraw(); @@ -1821,8 +1897,9 @@ void View3DInventorViewer::interactionFinishCB(void*, SoQTQuarterAdaptor* viewer /** * Logs the type of the action that traverses the Inventor tree. */ -void View3DInventorViewer::interactionLoggerCB(void*, SoAction* action) +void View3DInventorViewer::interactionLoggerCB(void* ud, SoAction* action) { + Q_UNUSED(ud) Base::Console().Log("%s\n", action->getTypeId().getName().getString()); } @@ -1845,8 +1922,9 @@ std::list View3DInventorViewer::getGraphicsItemsOfType(const Ba { std::list items; for (auto it : this->graphicsItems) { - if (it->isDerivedFrom(type)) + if (it->isDerivedFrom(type)) { items.push_back(it); + } } return items; @@ -1859,9 +1937,10 @@ void View3DInventorViewer::clearGraphicsItems() int View3DInventorViewer::getNumSamples() { - int samples = App::GetApplication().GetParameterGroupByPath + long samples = App::GetApplication().GetParameterGroupByPath ("User parameter:BaseApp/Preferences/View")->GetInt("AntiAliasing", 0); + // NOLINTBEGIN switch (samples) { case View3DInventorViewer::MSAA2x: return 2; @@ -1874,14 +1953,16 @@ int View3DInventorViewer::getNumSamples() default: return 0; } + // NOLINTEND } -GLenum View3DInventorViewer::getInternalTextureFormat() const +GLenum View3DInventorViewer::getInternalTextureFormat() { ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath ("User parameter:BaseApp/Preferences/View"); std::string format = hGrp->GetASCII("InternalTextureFormat", "Default"); + // NOLINTBEGIN if (format == "GL_RGB") { return GL_RGB; } @@ -1916,9 +1997,10 @@ GLenum View3DInventorViewer::getInternalTextureFormat() const QOpenGLFramebufferObjectFormat fboFormat; return fboFormat.internalTextureFormat(); } + // NOLINTEND } -void View3DInventorViewer::setRenderType(const RenderType type) +void View3DInventorViewer::setRenderType(RenderType type) { renderType = type; @@ -1938,7 +2020,7 @@ void View3DInventorViewer::setRenderType(const RenderType type) int width = size[0]; int height = size[1]; - auto gl = static_cast(this->viewport()); + auto gl = static_cast(this->viewport()); // NOLINT gl->makeCurrent(); QOpenGLFramebufferObjectFormat fboFormat; fboFormat.setSamples(getNumSamples()); @@ -1972,7 +2054,7 @@ View3DInventorViewer::RenderType View3DInventorViewer::getRenderType() const QImage View3DInventorViewer::grabFramebuffer() { - auto gl = static_cast(this->viewport()); + auto gl = static_cast(this->viewport()); // NOLINT gl->makeCurrent(); QImage res; @@ -2014,7 +2096,7 @@ QImage View3DInventorViewer::grabFramebuffer() void View3DInventorViewer::imageFromFramebuffer(int width, int height, int samples, const QColor& bgcolor, QImage& img) { - auto gl = static_cast(this->viewport()); + auto gl = static_cast(this->viewport()); // NOLINT gl->makeCurrent(); const QtGLContext* context = QtGLContext::currentContext(); @@ -2038,13 +2120,15 @@ void View3DInventorViewer::imageFromFramebuffer(int width, int height, int sampl const QColor col = backgroundColor(); auto grad = getGradientBackground(); - int alpha = 255; + constexpr const int maxAlpha = 255; + int alpha = maxAlpha; QColor bgopaque = bgcolor; if (bgopaque.isValid()) { // force an opaque background color alpha = bgopaque.alpha(); - if (alpha < 255) - bgopaque.setRgb(255,255,255); + if (alpha < maxAlpha) { + bgopaque.setRgb(maxAlpha, maxAlpha, maxAlpha); + } setBackgroundColor(bgopaque); setGradientBackground(Background::NoGradient); } @@ -2055,20 +2139,22 @@ void View3DInventorViewer::imageFromFramebuffer(int width, int height, int sampl img = fbo.toImage(); // if background color isn't opaque manipulate the image - if (alpha < 255) { + if (alpha < maxAlpha) { QImage image(img.constBits(), img.width(), img.height(), QImage::Format_ARGB32); img = image.copy(); QRgb rgba = bgcolor.rgba(); QRgb rgb = bgopaque.rgb(); QRgb * bits = (QRgb*) img.bits(); - for (int y = 0; y < height; y++) { - for (int x = 0; x < width; x++) { - if (*bits == rgb) + for (int yy = 0; yy < height; yy++) { + for (int xx = 0; xx < width; xx++) { + if (*bits == rgb) { *bits = rgba; - bits++; + } + bits++; // NOLINT } } - } else if (alpha == 255) { + } + else if (alpha == maxAlpha) { QImage image(img.width(), img.height(), QImage::Format_RGB32); QPainter painter(&image); painter.fillRect(image.rect(),Qt::black); @@ -2080,7 +2166,7 @@ void View3DInventorViewer::imageFromFramebuffer(int width, int height, int sampl void View3DInventorViewer::renderToFramebuffer(QtGLFramebufferObject* fbo) { - static_cast(this->viewport())->makeCurrent(); + static_cast(this->viewport())->makeCurrent(); // NOLINT fbo->bind(); int width = fbo->size().width(); int height = fbo->size().height(); @@ -2092,7 +2178,7 @@ void View3DInventorViewer::renderToFramebuffer(QtGLFramebufferObject* fbo) const QColor col = this->backgroundColor(); glViewport(0, 0, width, height); - glClearColor(col.redF(), col.greenF(), col.blueF(), col.alphaF()); + glClearColor(float(col.redF()), float(col.greenF()), float(col.blueF()), float(col.alphaF())); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); SoBoxSelectionRenderAction gl(SbViewportRegion(width, height)); @@ -2157,24 +2243,26 @@ void View3DInventorViewer::renderFramebuffer() glColor3f(1.0, 1.0, 1.0); glBegin(GL_QUADS); - glTexCoord2f(0.0f, 0.0f); - glVertex2f(-1.0, -1.0f); - glTexCoord2f(1.0f, 0.0f); - glVertex2f(1.0f, -1.0f); - glTexCoord2f(1.0f, 1.0f); - glVertex2f(1.0f, 1.0f); - glTexCoord2f(0.0f, 1.0f); - glVertex2f(-1.0f, 1.0f); + glTexCoord2f(0.0F, 0.0F); + glVertex2f(-1.0, -1.0F); + glTexCoord2f(1.0F, 0.0F); + glVertex2f(1.0F, -1.0F); + glTexCoord2f(1.0F, 1.0F); + glVertex2f(1.0F, 1.0F); + glTexCoord2f(0.0F, 1.0F); + glVertex2f(-1.0F, 1.0F); glEnd(); printDimension(); navigation->redraw(); - for (auto it : this->graphicsItems) + for (auto it : this->graphicsItems) { it->paintGL(); + } - if (naviCubeEnabled) + if (naviCubeEnabled) { naviCube->drawNaviCube(); + } glPopAttrib(); } @@ -2189,7 +2277,7 @@ void View3DInventorViewer::renderGLImage() glViewport(0, 0, size[0], size[1]); glMatrixMode(GL_PROJECTION); glLoadIdentity(); - glOrtho(0, size[0], 0, size[1], 0, 100); + glOrtho(0, size[0], 0, size[1], 0, 100); // NOLINT glMatrixMode(GL_MODELVIEW); glLoadIdentity(); @@ -2197,16 +2285,18 @@ void View3DInventorViewer::renderGLImage() glClear(GL_COLOR_BUFFER_BIT); glRasterPos2f(0,0); - glDrawPixels(glImage.width(),glImage.height(),GL_BGRA,GL_UNSIGNED_BYTE,glImage.bits()); + glDrawPixels(glImage.width(), glImage.height(), GL_BGRA,GL_UNSIGNED_BYTE, glImage.bits()); printDimension(); navigation->redraw(); - for (auto it : this->graphicsItems) + for (auto it : this->graphicsItems) { it->paintGL(); + } - if (naviCubeEnabled) + if (naviCubeEnabled) { naviCube->drawNaviCube(); + } glPopAttrib(); } @@ -2230,7 +2320,7 @@ void View3DInventorViewer::renderScene() glViewport(origin[0], origin[1], size[0], size[1]); const QColor col = this->backgroundColor(); - glClearColor(col.redF(), col.greenF(), col.blueF(), 0.0f); + glClearColor(float(col.redF()), float(col.greenF()), float(col.blueF()), 0.0F); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_DEPTH_TEST); @@ -2260,8 +2350,9 @@ void View3DInventorViewer::renderScene() } catch (const Base::MemoryException&) { // FIXME: If this exception appears then the background and camera position get broken somehow. (Werner 2006-02-01) - for (auto it : _ViewProviderSet) + for (auto it : _ViewProviderSet) { it->hide(); + } inherited::actualRedraw(); QMessageBox::warning(parentWidget(), QObject::tr("Out of memory"), @@ -2297,8 +2388,9 @@ void View3DInventorViewer::renderScene() printDimension(); navigation->redraw(); - for (auto it : this->graphicsItems) + for (auto it : this->graphicsItems) { it->paintGL(); + } //fps rendering if (fpsEnabled) { @@ -2306,11 +2398,12 @@ void View3DInventorViewer::renderScene() stream.precision(1); stream.setf(std::ios::fixed | std::ios::showpoint); stream << framesPerSecond[0] << " ms / " << framesPerSecond[1] << " fps"; - draw2DString(stream.str().c_str(), SbVec2s(10,10), SbVec2f(0.1f,0.1f)); + draw2DString(stream.str().c_str(), SbVec2s(10, 10), SbVec2f(0.1F, 0.1F)); // NOLINT } - if (naviCubeEnabled) + if (naviCubeEnabled) { naviCube->drawNaviCube(); + } } void View3DInventorViewer::setSeekMode(SbBool on) @@ -2333,8 +2426,9 @@ void View3DInventorViewer::setSeekMode(SbBool on) SbVec3f View3DInventorViewer::getCenterPointOnFocalPlane() const { SoCamera* cam = getSoRenderManager()->getCamera(); - if (!cam) + if (!cam) { return {0. ,0. ,0. }; + } SbVec3f direction; cam->orientation.getValue().multVec(SbVec3f(0, 0, -1), direction); @@ -2348,22 +2442,29 @@ float View3DInventorViewer::getMaxDimension() const { return std::max(fHeight, fWidth); } -void View3DInventorViewer::getDimensions(float& fHeight, float& fWidth) const { +void View3DInventorViewer::getDimensions(float& fHeight, float& fWidth) const +{ SoCamera* camera = getSoRenderManager()->getCamera(); - if (!camera) // no camera there + if (!camera) { + // no camera there return; + } float aspectRatio = getViewportRegion().getViewportAspectRatio(); SoType type = camera->getTypeId(); if (type.isDerivedFrom(SoOrthographicCamera::getClassTypeId())) { + // NOLINTBEGIN fHeight = static_cast(camera)->height.getValue(); fWidth = fHeight; + // NOLINTEND } else if (type.isDerivedFrom(SoPerspectiveCamera::getClassTypeId())) { + // NOLINTBEGIN float fHeightAngle = static_cast(camera)->heightAngle.getValue(); fHeight = std::tan(fHeightAngle / 2.0) * 2.0 * camera->focalDistance.getValue(); fWidth = fHeight; + // NOLINTEND } if (aspectRatio > 1.0) { @@ -2374,7 +2475,7 @@ void View3DInventorViewer::getDimensions(float& fHeight, float& fWidth) const { } } -void View3DInventorViewer::printDimension() +void View3DInventorViewer::printDimension() const { float fHeight = -1.0; float fWidth = -1.0; @@ -2404,33 +2505,38 @@ void View3DInventorViewer::selectAll() for (auto it : _ViewProviderSet) { if (it->getTypeId().isDerivedFrom(ViewProviderDocumentObject::getClassTypeId())) { - auto vp = static_cast(it); + auto vp = static_cast(it); // NOLINT App::DocumentObject* obj = vp->getObject(); - if (obj) objs.push_back(obj); + if (obj) { + objs.push_back(obj); + } } } - if (!objs.empty()) + if (!objs.empty()) { Gui::Selection().setSelection(objs.front()->getDocument()->getName(), objs); + } } bool View3DInventorViewer::processSoEvent(const SoEvent* ev) { - if (naviCubeEnabled && naviCube->processSoEvent(ev)) + if (naviCubeEnabled && naviCube->processSoEvent(ev)) { return true; + } if (isRedirectedToSceneGraph()) { - SbBool processed = inherited::processSoEvent(ev); + bool processed = inherited::processSoEvent(ev); - if (!processed) + if (!processed) { processed = navigation->processEvent(ev); + } return processed; } if (ev->getTypeId().isDerivedFrom(SoKeyboardEvent::getClassTypeId())) { // filter out 'Q' and 'ESC' keys - const auto ke = static_cast(ev); + const auto ke = static_cast(ev); // NOLINT switch (ke->getKey()) { case SoKeyboardEvent::ESCAPE: @@ -2453,8 +2559,10 @@ SbVec3f View3DInventorViewer::getViewDirection() const { SoCamera* cam = this->getSoRenderManager()->getCamera(); - if (!cam) // this is the default + if (!cam) { + // this is the default return {0,0,-1}; + } SbVec3f projDir = cam->getViewVolume().getProjectionDirection(); return projDir; @@ -2462,17 +2570,18 @@ SbVec3f View3DInventorViewer::getViewDirection() const void View3DInventorViewer::setViewDirection(SbVec3f dir) { - SoCamera* cam = this->getSoRenderManager()->getCamera(); - if (cam) + if (SoCamera* cam = this->getSoRenderManager()->getCamera()) { cam->orientation.setValue(SbRotation(SbVec3f(0, 0, -1), dir)); + } } SbVec3f View3DInventorViewer::getUpDirection() const { SoCamera* cam = this->getSoRenderManager()->getCamera(); - if (!cam) + if (!cam) { return {0,1,0}; + } SbRotation camrot = cam->orientation.getValue(); SbVec3f upvec(0, 1, 0); // init to default up vector @@ -2484,8 +2593,10 @@ SbRotation View3DInventorViewer::getCameraOrientation() const { SoCamera* cam = this->getSoRenderManager()->getCamera(); - if (!cam) - return {0,0,0,1}; // this is the default + if (!cam) { + // this is the default + return {0,0,0,1}; + } return cam->orientation.getValue(); } @@ -2494,24 +2605,28 @@ SbVec2f View3DInventorViewer::getNormalizedPosition(const SbVec2s& pnt) const { const SbViewportRegion& vp = this->getSoRenderManager()->getViewportRegion(); - short x,y; - pnt.getValue(x,y); + short xpos{}; + short ypos{}; + pnt.getValue(xpos, ypos); SbVec2f siz = vp.getViewportSize(); - float dX, dY; + float dX{}; + float dY{}; siz.getValue(dX, dY); float fRatio = vp.getViewportAspectRatio(); - float pX = (float)x / float(vp.getViewportSizePixels()[0]); - float pY = (float)y / float(vp.getViewportSizePixels()[1]); + float pX = float(xpos) / float(vp.getViewportSizePixels()[0]); + float pY = float(ypos) / float(vp.getViewportSizePixels()[1]); // now calculate the real points respecting aspect ratio information // - if (fRatio > 1.0f) { - pX = (pX - 0.5f*dX) * fRatio + 0.5f*dX; + // NOLINTBEGIN + if (fRatio > 1.0F) { + pX = (pX - 0.5F * dX) * fRatio + 0.5F * dX; } - else if (fRatio < 1.0f) { - pY = (pY - 0.5f*dY) / fRatio + 0.5f*dY; + else if (fRatio < 1.0F) { + pY = (pY - 0.5F * dY) / fRatio + 0.5F * dY; } + // NOLINTEND return {pX, pY}; } @@ -2521,8 +2636,10 @@ SbVec3f View3DInventorViewer::getPointOnFocalPlane(const SbVec2s& pnt) const SbVec2f pnt2d = getNormalizedPosition(pnt); SoCamera* pCam = this->getSoRenderManager()->getCamera(); - if (!pCam) // return invalid point + if (!pCam) { + // return invalid point return {}; + } SbViewVolume vol = pCam->getViewVolume(); @@ -2530,8 +2647,9 @@ SbVec3f View3DInventorViewer::getPointOnFocalPlane(const SbVec2s& pnt) const float farDist = pCam->farDistance.getValue(); float focalDist = pCam->focalDistance.getValue(); - if (focalDist < nearDist || focalDist > farDist) - focalDist = 0.5f*(nearDist + farDist); + if (focalDist < nearDist || focalDist > farDist) { + focalDist = 0.5F * (nearDist + farDist); // NOLINT + } SbLine line; SbVec3f pt; @@ -2552,10 +2670,10 @@ SbVec2s View3DInventorViewer::getPointOnViewport(const SbVec3f& pnt) const SbVec3f pt(pnt); vv.projectToScreen(pt, pt); - auto x = short(std::roundf(pt[0] * sp[0])); - auto y = short(std::roundf(pt[1] * sp[1])); + auto xpos = short(std::roundf(pt[0] * sp[0])); // NOLINT + auto ypos = short(std::roundf(pt[1] * sp[1])); // NOLINT - return {x, y}; + return {xpos, ypos}; } QPoint View3DInventorViewer::toQPoint(const SbVec2s& pnt) const @@ -2589,48 +2707,57 @@ SbVec2s View3DInventorViewer::fromQPoint(const QPoint& pnt) const void View3DInventorViewer::getNearPlane(SbVec3f& rcPt, SbVec3f& rcNormal) const { SoCamera* pCam = getSoRenderManager()->getCamera(); - - if (!pCam) // just do nothing + if (!pCam) { + // just do nothing return; + } SbViewVolume vol = pCam->getViewVolume(); // get the normal of the front clipping plane SbPlane nearPlane = vol.getPlane(vol.nearDist); - float d = nearPlane.getDistanceFromOrigin(); + float dist = nearPlane.getDistanceFromOrigin(); rcNormal = nearPlane.getNormal(); rcNormal.normalize(); - float nx, ny, nz; + float nx{}; + float ny{}; + float nz{}; rcNormal.getValue(nx, ny, nz); - rcPt.setValue(d*rcNormal[0], d*rcNormal[1], d*rcNormal[2]); + rcPt.setValue(dist * rcNormal[0], dist * rcNormal[1], dist * rcNormal[2]); } void View3DInventorViewer::getFarPlane(SbVec3f& rcPt, SbVec3f& rcNormal) const { SoCamera* pCam = getSoRenderManager()->getCamera(); - - if (!pCam) // just do nothing + if (!pCam) { + // just do nothing return; + } SbViewVolume vol = pCam->getViewVolume(); // get the normal of the back clipping plane SbPlane farPlane = vol.getPlane(vol.nearDist+vol.nearToFar); - float d = farPlane.getDistanceFromOrigin(); + float dist = farPlane.getDistanceFromOrigin(); rcNormal = farPlane.getNormal(); rcNormal.normalize(); - float nx, ny, nz; + float nx{}; + float ny{}; + float nz{}; rcNormal.getValue(nx, ny, nz); - rcPt.setValue(d*rcNormal[0], d*rcNormal[1], d*rcNormal[2]); + rcPt.setValue(dist * rcNormal[0], dist * rcNormal[1], dist * rcNormal[2]); } SbVec3f View3DInventorViewer::projectOnNearPlane(const SbVec2f& pt) const { - SbVec3f pt1, pt2; + SbVec3f pt1; + SbVec3f pt2; SoCamera* cam = this->getSoRenderManager()->getCamera(); - if (!cam) // return invalid point + // return invalid point + if (!cam) { return {}; + } SbViewVolume vol = cam->getViewVolume(); vol.projectPointToLine(pt, pt1, pt2); @@ -2639,11 +2766,14 @@ SbVec3f View3DInventorViewer::projectOnNearPlane(const SbVec2f& pt) const SbVec3f View3DInventorViewer::projectOnFarPlane(const SbVec2f& pt) const { - SbVec3f pt1, pt2; + SbVec3f pt1; + SbVec3f pt2; SoCamera* cam = this->getSoRenderManager()->getCamera(); - if (!cam) // return invalid point + // return invalid point + if (!cam) { return {}; + } SbViewVolume vol = cam->getViewVolume(); vol.projectPointToLine(pt, pt1, pt2); @@ -2655,8 +2785,9 @@ void View3DInventorViewer::projectPointToLine(const SbVec2s& pt, SbVec3f& pt1, S SbVec2f pnt2d = getNormalizedPosition(pt); SoCamera* pCam = this->getSoRenderManager()->getCamera(); - if (!pCam) + if (!pCam) { return; + } SbViewVolume vol = pCam->getViewVolume(); vol.projectPointToLine(pnt2d, pt1, pt2); @@ -2665,43 +2796,52 @@ void View3DInventorViewer::projectPointToLine(const SbVec2s& pt, SbVec3f& pt1, S void View3DInventorViewer::toggleClippingPlane(int toggle, bool beforeEditing, bool noManip, const Base::Placement &pla) { - if(pcClipPlane) { - if(toggle<=0) { + if (pcClipPlane) { + if (toggle <= 0) { pcViewProviderRoot->removeChild(pcClipPlane); pcClipPlane->unref(); pcClipPlane = nullptr; } return; - }else if(toggle==0) + } + + if (toggle == 0) { return; + } Base::Vector3d dir; - pla.getRotation().multVec(Base::Vector3d(0,0,-1),dir); + pla.getRotation().multVec(Base::Vector3d(0, 0, -1), dir); Base::Vector3d base = pla.getPosition(); - if(!noManip) { + if (!noManip) { auto clip = new SoClipPlaneManip; pcClipPlane = clip; SbBox3f box = getBoundingBox(); if (!box.isEmpty()) { // adjust to overall bounding box of the scene - clip->setValue(box, SbVec3f(dir.x,dir.y,dir.z), 1.0f); + clip->setValue(box, Base::convertTo(dir), 1.0F); } - }else + } + else { pcClipPlane = new SoClipPlane; - pcClipPlane->plane.setValue( - SbPlane(SbVec3f(dir.x,dir.y,dir.z),SbVec3f(base.x,base.y,base.z))); + } + + pcClipPlane->plane.setValue(SbPlane(Base::convertTo(dir), + Base::convertTo(base))); pcClipPlane->ref(); - if(beforeEditing) - pcViewProviderRoot->insertChild(pcClipPlane,0); - else - pcViewProviderRoot->insertChild(pcClipPlane,pcViewProviderRoot->findChild(pcEditingRoot)+1); + if (beforeEditing) { + pcViewProviderRoot->insertChild(pcClipPlane, 0); + } + else { + pcViewProviderRoot->insertChild(pcClipPlane, + pcViewProviderRoot->findChild(pcEditingRoot) + 1); + } } bool View3DInventorViewer::hasClippingPlane() const { - return !!pcClipPlane; + return pcClipPlane != nullptr; } /** @@ -2709,7 +2849,7 @@ bool View3DInventorViewer::hasClippingPlane() const * and returns its location and normal. * If no point was picked false is returned. */ -bool View3DInventorViewer::pickPoint(const SbVec2s& pos,SbVec3f& point,SbVec3f& norm) const +bool View3DInventorViewer::pickPoint(const SbVec2s& pos, SbVec3f& point, SbVec3f& norm) const { // attempting raypick in the event_cb() callback method SoRayPickAction rp(getSoRenderManager()->getViewportRegion()); @@ -2748,8 +2888,9 @@ const SoPickedPoint* View3DInventorViewer::getPickedPoint(SoEventCallback* n) co { if (selectionRoot) { auto ret = selectionRoot->getPickedList(n->getAction(), true); - if(!ret.empty()) + if (!ret.empty()) { return ret[0].pp; + } return nullptr; } return n->getPickedPoint(); @@ -2770,29 +2911,30 @@ void View3DInventorViewer::setCameraOrientation(const SbRotation& orientation, S navigation->setCameraOrientation(orientation, moveToCenter); } -void View3DInventorViewer::setCameraType(SoType t) +void View3DInventorViewer::setCameraType(SoType type) { - inherited::setCameraType(t); + inherited::setCameraType(type); - if (t.isDerivedFrom(SoPerspectiveCamera::getClassTypeId())) { + if (type.isDerivedFrom(SoPerspectiveCamera::getClassTypeId())) { // When doing a viewAll() for an orthographic camera and switching // to perspective the scene looks completely strange because of the // heightAngle. Setting it to 45 deg also causes an issue with a too // close camera but we don't have this other ugly effect. SoCamera* cam = this->getSoRenderManager()->getCamera(); - - if(!cam) + if (!cam) { return; + } - static_cast(cam)->heightAngle = (float)(M_PI / 4.0); + static_cast(cam)->heightAngle = (float)(M_PI / 4.0); // NOLINT } } void View3DInventorViewer::moveCameraTo(const SbRotation& orientation, const SbVec3f& position, int duration) { SoCamera* camera = getCamera(); - if (!camera) + if (!camera) { return; + } if (isAnimationEnabled()) { startAnimation( @@ -2806,8 +2948,9 @@ void View3DInventorViewer::moveCameraTo(const SbRotation& orientation, const SbV void View3DInventorViewer::animatedViewAll(int steps, int ms) { SoCamera* cam = this->getSoRenderManager()->getCamera(); - if (!cam) + if (!cam) { return; + } SbVec3f campos = cam->position.getValue(); SbRotation camrot = cam->orientation.getValue(); @@ -2816,15 +2959,18 @@ void View3DInventorViewer::animatedViewAll(int steps, int ms) float aspectRatio = vp.getViewportAspectRatio(); - if (box.isEmpty()) + if (box.isEmpty()) { return; + } SbSphere sphere; sphere.circumscribe(box); - if (sphere.getRadius() == 0) + if (sphere.getRadius() == 0) { return; + } - SbVec3f direction, pos(0.0f, 0.0f, 0.0f); + SbVec3f direction; + SbVec3f pos(0.0F, 0.0F, 0.0F); camrot.multVec(SbVec3f(0, 0, -1), direction); bool isOrthographic = false; @@ -2833,16 +2979,20 @@ void View3DInventorViewer::animatedViewAll(int steps, int ms) if (cam->isOfType(SoOrthographicCamera::getClassTypeId())) { isOrthographic = true; - height = static_cast(cam)->height.getValue(); - if (aspectRatio < 1.0f) + height = static_cast(cam)->height.getValue(); // NOLINT + if (aspectRatio < 1.0F) { diff = sphere.getRadius() * 2 - height * aspectRatio; - else - diff = sphere.getRadius() * 2 - height; + } + else { + diff = sphere.getRadius() * 2 - height; + } pos = (box.getCenter() - direction * sphere.getRadius()); } else if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) { + // NOLINTBEGIN float movelength = sphere.getRadius()/float(tan(static_cast (cam)->heightAngle.getValue() / 2.0)); + // NOLINTEND pos = box.getCenter() - direction * movelength; } @@ -2852,16 +3002,16 @@ void View3DInventorViewer::animatedViewAll(int steps, int ms) QObject::connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit); for (int i=0; i(cam)->height.setValue(camHeight); + float camHeight = height + diff * par; + static_cast(cam)->height.setValue(camHeight); // NOLINT } - SbVec3f curpos = campos * (1.0f-s) + pos * s; + SbVec3f curpos = campos * (1.0F - par) + pos * par; cam->position.setValue(curpos); - timer.start(Base::clamp(ms,0,5000)); + timer.start(Base::clamp(ms, 0, 5000)); // NOLINT loop.exec(QEventLoop::ExcludeUserInputEvents); } } @@ -2903,13 +3053,15 @@ void View3DInventorViewer::viewAll() { SbBox3f box = getBoundingBox(); - if (box.isEmpty()) + if (box.isEmpty()) { return; + } SbSphere sphere; sphere.circumscribe(box); - if (sphere.getRadius() == 0) + if (sphere.getRadius() == 0) { return; + } // in the scene graph we may have objects which we want to exclude // when doing a fit all. Such objects must be part of the group @@ -2922,26 +3074,29 @@ void View3DInventorViewer::viewAll() for (int i = 0; i < pathlist.getLength(); i++) { SoPath* path = pathlist[i]; - auto group = static_cast(path->getTail()); + auto group = static_cast(path->getTail()); // NOLINT group->mode = SoSkipBoundingGroup::EXCLUDE_BBOX; } // Set the height angle to 45 deg SoCamera* cam = this->getSoRenderManager()->getCamera(); - if (cam && cam->getTypeId().isDerivedFrom(SoPerspectiveCamera::getClassTypeId())) - static_cast(cam)->heightAngle = (float)(M_PI / 4.0); + if (cam && cam->getTypeId().isDerivedFrom(SoPerspectiveCamera::getClassTypeId())) { + static_cast(cam)->heightAngle = (float)(M_PI / 4.0); // NOLINT + } - if (isAnimationEnabled()) - animatedViewAll(10, 20); + if (isAnimationEnabled()) { + animatedViewAll(10, 20); // NOLINT + } // make sure everything is visible - if (cam) + if (cam) { cam->viewAll(getSoRenderManager()->getSceneGraph(), this->getSoRenderManager()->getViewportRegion()); + } for (int i = 0; i < pathlist.getLength(); i++) { SoPath* path = pathlist[i]; - auto group = static_cast(path->getTail()); + auto group = static_cast(path->getTail()); // NOLINT group->mode = SoSkipBoundingGroup::INCLUDE_BBOX; } } @@ -2949,14 +3104,15 @@ void View3DInventorViewer::viewAll() void View3DInventorViewer::viewAll(float factor) { SoCamera* cam = this->getSoRenderManager()->getCamera(); - - if (!cam) + if (!cam) { return; + } - if (factor <= 0.0f) + if (factor <= 0.0F) { return; + } - if (factor != 1.0f) { + if (factor != 1.0F) { SoSearchAction sa; sa.setType(SoSkipBoundingGroup::getClassTypeId()); sa.setInterest(SoSearchAction::ALL); @@ -2965,17 +3121,22 @@ void View3DInventorViewer::viewAll(float factor) for (int i = 0; i < pathlist.getLength(); i++) { SoPath* path = pathlist[i]; - auto group = static_cast(path->getTail()); + auto group = static_cast(path->getTail()); // NOLINT group->mode = SoSkipBoundingGroup::EXCLUDE_BBOX; } SbBox3f box = getBoundingBox(); - float minx,miny,minz,maxx,maxy,maxz; + float minx{}; + float miny{}; + float minz{}; + float maxx{}; + float maxy{}; + float maxz{}; box.getBounds(minx,miny,minz,maxx,maxy,maxz); for (int i = 0; i < pathlist.getLength(); i++) { SoPath* path = pathlist[i]; - auto group = static_cast(path->getTail()); + auto group = static_cast(path->getTail()); // NOLINT group->mode = SoSkipBoundingGroup::INCLUDE_BBOX; } @@ -3005,21 +3166,27 @@ void View3DInventorViewer::viewSelection() Base::BoundBox3d bbox; for(auto &sel : Selection().getSelection(nullptr, ResolveMode::NoResolve)) { auto vp = Application::Instance->getViewProvider(sel.pObject); - if(!vp) + if(!vp) { continue; + } bbox.Add(vp->getBoundingBox(sel.SubName,true)); } SoCamera* cam = this->getSoRenderManager()->getCamera(); if (cam && bbox.IsValid()) { - SbBox3f box(bbox.MinX,bbox.MinY,bbox.MinZ,bbox.MaxX,bbox.MaxY,bbox.MaxZ); + SbBox3f box(float(bbox.MinX), + float(bbox.MinY), + float(bbox.MinZ), + float(bbox.MaxX), + float(bbox.MaxY), + float(bbox.MaxZ)); #if (COIN_MAJOR_VERSION >= 4) float aspectratio = getSoRenderManager()->getViewportRegion().getViewportAspectRatio(); switch (cam->viewportMapping.getValue()) { case SoCamera::CROP_VIEWPORT_FILL_FRAME: case SoCamera::CROP_VIEWPORT_LINE_FRAME: case SoCamera::CROP_VIEWPORT_NO_FRAME: - aspectratio = 1.0f; + aspectratio = 1.0F; break; default: break; @@ -3057,7 +3224,7 @@ void View3DInventorViewer::viewSelection() spin will be stopped. */ void -View3DInventorViewer::setAnimationEnabled(const SbBool enable) +View3DInventorViewer::setAnimationEnabled(SbBool enable) { navigation->setAnimationEnabled(enable); } @@ -3130,7 +3297,7 @@ void View3DInventorViewer::stopAnimating() navigation->stopAnimating(); } -void View3DInventorViewer::setPopupMenuEnabled(const SbBool on) +void View3DInventorViewer::setPopupMenuEnabled(SbBool on) { navigation->setPopupMenuEnabled(on); } @@ -3145,7 +3312,7 @@ SbBool View3DInventorViewer::isPopupMenuEnabled() const */ void -View3DInventorViewer::setFeedbackVisibility(const SbBool enable) +View3DInventorViewer::setFeedbackVisibility(SbBool enable) { if (enable == this->axiscrossEnabled) { return; @@ -3174,7 +3341,7 @@ View3DInventorViewer::isFeedbackVisible() const canvas. */ void -View3DInventorViewer::setFeedbackSize(const int size) +View3DInventorViewer::setFeedbackSize(int size) { if (size < 1) { return; @@ -3220,13 +3387,13 @@ void View3DInventorViewer::setViewing(SbBool enable) return; } - navigation->setViewingMode(enable ? - NavigationStyle::IDLE : NavigationStyle::INTERACT); + navigation->setViewingMode(enable ? NavigationStyle::IDLE : NavigationStyle::INTERACT); inherited::setViewing(enable); } void View3DInventorViewer::drawAxisCross() { + // NOLINTBEGIN // FIXME: convert this to a superimposition scenegraph instead of // OpenGL calls. 20020603 mortene. @@ -3248,7 +3415,7 @@ void View3DInventorViewer::drawAxisCross() // Set the viewport in the OpenGL canvas. Dimensions are calculated // as a percentage of the total canvas size. SbVec2s view = this->getSoRenderManager()->getSize(); - const int pixelarea = int(float(this->axiscrossSize)/100.0f * std::min(view[0], view[1])); + const int pixelarea = int(float(this->axiscrossSize)/100.0F * std::min(view[0], view[1])); SbVec2s origin(view[0] - pixelarea, 0); glViewport(origin[0], origin[1], pixelarea, pixelarea); @@ -3256,8 +3423,8 @@ void View3DInventorViewer::drawAxisCross() glMatrixMode(GL_PROJECTION); glLoadIdentity(); - const float NEARVAL = 0.1f; - const float FARVAL = 10.0f; + const float NEARVAL = 0.1F; + const float FARVAL = 10.0F; const float dim = NEARVAL * float(tan(M_PI / 8.0)); // FOV is 45 deg (45/360 = 1/8) glFrustum(-dim, dim, -dim, dim, NEARVAL, FARVAL); @@ -3332,28 +3499,28 @@ void View3DInventorViewer::drawAxisCross() if (i == XAXIS) { // X axis. if (stereoMode() != Quarter::SoQTQuarterAdaptor::MONO) - glColor3f(0.500f, 0.5f, 0.5f); + glColor3f(0.500F, 0.5F, 0.5F); else - glColor3f(0.500f, 0.125f, 0.125f); + glColor3f(0.500F, 0.125F, 0.125F); } else if (i == YAXIS) { // Y axis. glRotatef(90, 0, 0, 1); if (stereoMode() != Quarter::SoQTQuarterAdaptor::MONO) - glColor3f(0.400f, 0.4f, 0.4f); + glColor3f(0.400F, 0.4F, 0.4F); else - glColor3f(0.125f, 0.500f, 0.125f); + glColor3f(0.125F, 0.500F, 0.125F); } else { // Z axis. glRotatef(-90, 0, 1, 0); if (stereoMode() != Quarter::SoQTQuarterAdaptor::MONO) - glColor3f(0.300f, 0.3f, 0.3f); + glColor3f(0.300F, 0.3F, 0.3F); else - glColor3f(0.125f, 0.125f, 0.500f); + glColor3f(0.125F, 0.125F, 0.500F); } - this->drawArrow(); + drawArrow(); glPopMatrix(); } } @@ -3366,18 +3533,20 @@ void View3DInventorViewer::drawAxisCross() glMatrixMode(GL_MODELVIEW); glLoadIdentity(); - GLint unpack; + GLint unpack{}; glGetIntegerv(GL_UNPACK_ALIGNMENT, &unpack); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - if (stereoMode() != Quarter::SoQTQuarterAdaptor::MONO) - glColor3fv(SbVec3f(1.0f, 1.0f, 1.0f).getValue()); - else - glColor3fv(SbVec3f(0.0f, 0.0f, 0.0f).getValue()); + if (stereoMode() != Quarter::SoQTQuarterAdaptor::MONO) { + glColor3fv(SbVec3f(1.0F, 1.0F, 1.0F).getValue()); + } + else { + glColor3fv(SbVec3f(0.0F, 0.0F, 0.0F).getValue()); + } glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glPixelZoom((float)axiscrossSize/30, (float)axiscrossSize/30); // 30 = 3 (character pixmap ratio) * 10 (default axiscrossSize) + glPixelZoom((float)axiscrossSize / 30, (float)axiscrossSize / 30); // 30 = 3 (character pixmap ratio) * 10 (default axiscrossSize) glRasterPos2d(xpos[0], xpos[1]); glDrawPixels(XPM_WIDTH, XPM_HEIGHT, GL_RGBA, GL_UNSIGNED_BYTE, XPM_PIXEL_DATA); glRasterPos2d(ypos[0], ypos[1]); @@ -3397,52 +3566,55 @@ void View3DInventorViewer::drawAxisCross() glLoadMatrixd(projectionmatrix); glPopAttrib(); + // NOLINTEND } // Draw an arrow for the axis representation directly through OpenGL. void View3DInventorViewer::drawArrow() { + // NOLINTBEGIN glDisable(GL_CULL_FACE); glBegin(GL_QUADS); - glVertex3f(0.0f, -0.02f, 0.02f); - glVertex3f(0.0f, 0.02f, 0.02f); - glVertex3f(1.0f - 1.0f / 3.0f, 0.02f, 0.02f); - glVertex3f(1.0f - 1.0f / 3.0f, -0.02f, 0.02f); + glVertex3f(0.0F, -0.02F, 0.02F); + glVertex3f(0.0F, 0.02F, 0.02F); + glVertex3f(1.0F - 1.0F / 3.0F, 0.02F, 0.02F); + glVertex3f(1.0F - 1.0F / 3.0F, -0.02F, 0.02F); - glVertex3f(0.0f, -0.02f, -0.02f); - glVertex3f(0.0f, 0.02f, -0.02f); - glVertex3f(1.0f - 1.0f / 3.0f, 0.02f, -0.02f); - glVertex3f(1.0f - 1.0f / 3.0f, -0.02f, -0.02f); + glVertex3f(0.0F, -0.02F, -0.02F); + glVertex3f(0.0F, 0.02F, -0.02F); + glVertex3f(1.0F - 1.0F / 3.0F, 0.02F, -0.02F); + glVertex3f(1.0F - 1.0F / 3.0F, -0.02F, -0.02F); - glVertex3f(0.0f, -0.02f, 0.02f); - glVertex3f(0.0f, -0.02f, -0.02f); - glVertex3f(1.0f - 1.0f / 3.0f, -0.02f, -0.02f); - glVertex3f(1.0f - 1.0f / 3.0f, -0.02f, 0.02f); + glVertex3f(0.0F, -0.02F, 0.02F); + glVertex3f(0.0F, -0.02F, -0.02F); + glVertex3f(1.0F - 1.0F / 3.0F, -0.02F, -0.02F); + glVertex3f(1.0F - 1.0F / 3.0F, -0.02F, 0.02F); - glVertex3f(0.0f, 0.02f, 0.02f); - glVertex3f(0.0f, 0.02f, -0.02f); - glVertex3f(1.0f - 1.0f / 3.0f, 0.02f, -0.02f); - glVertex3f(1.0f - 1.0f / 3.0f, 0.02f, 0.02f); + glVertex3f(0.0F, 0.02F, 0.02F); + glVertex3f(0.0F, 0.02F, -0.02F); + glVertex3f(1.0F - 1.0F / 3.0F, 0.02F, -0.02F); + glVertex3f(1.0F - 1.0F / 3.0F, 0.02F, 0.02F); - glVertex3f(0.0f, 0.02f, 0.02f); - glVertex3f(0.0f, 0.02f, -0.02f); - glVertex3f(0.0f, -0.02f, -0.02f); - glVertex3f(0.0f, -0.02f, 0.02f); + glVertex3f(0.0F, 0.02F, 0.02F); + glVertex3f(0.0F, 0.02F, -0.02F); + glVertex3f(0.0F, -0.02F, -0.02F); + glVertex3f(0.0F, -0.02F, 0.02F); glEnd(); glBegin(GL_TRIANGLES); - glVertex3f(1.0f, 0.0f, 0.0f); - glVertex3f(1.0f - 1.0f / 3.0f, +0.5f / 4.0f, 0.0f); - glVertex3f(1.0f - 1.0f / 3.0f, -0.5f / 4.0f, 0.0f); - glVertex3f(1.0f, 0.0f, 0.0f); - glVertex3f(1.0f - 1.0f / 3.0f, 0.0f, +0.5f / 4.0f); - glVertex3f(1.0f - 1.0f / 3.0f, 0.0f, -0.5f / 4.0f); + glVertex3f(1.0F, 0.0F, 0.0F); + glVertex3f(1.0F - 1.0F / 3.0F, +0.5F / 4.0F, 0.0F); + glVertex3f(1.0F - 1.0F / 3.0F, -0.5F / 4.0F, 0.0F); + glVertex3f(1.0F, 0.0F, 0.0F); + glVertex3f(1.0F - 1.0F / 3.0F, 0.0F, +0.5F / 4.0F); + glVertex3f(1.0F - 1.0F / 3.0F, 0.0F, -0.5F / 4.0F); glEnd(); glBegin(GL_QUADS); - glVertex3f(1.0f - 1.0f / 3.0f, +0.5f / 4.0f, 0.0f); - glVertex3f(1.0f - 1.0f / 3.0f, 0.0f, +0.5f / 4.0f); - glVertex3f(1.0f - 1.0f / 3.0f, -0.5f / 4.0f, 0.0f); - glVertex3f(1.0f - 1.0f / 3.0f, 0.0f, -0.5f / 4.0f); + glVertex3f(1.0F - 1.0F / 3.0F, +0.5F / 4.0F, 0.0F); + glVertex3f(1.0F - 1.0F / 3.0F, 0.0F, +0.5F / 4.0F); + glVertex3f(1.0F - 1.0F / 3.0F, -0.5F / 4.0F, 0.0F); + glVertex3f(1.0F - 1.0F / 3.0F, 0.0F, -0.5F / 4.0F); glEnd(); + // NOLINTEND } void View3DInventorViewer::drawSingleBackground(const QColor& col) @@ -3462,13 +3634,13 @@ void View3DInventorViewer::drawSingleBackground(const QColor& col) glDisable(GL_LIGHTING); glDisable(GL_TEXTURE_2D); glBegin(GL_TRIANGLE_STRIP); - glColor3f(col.redF(), col.greenF(), col.blueF()); + glColor3f(float(col.redF()), float(col.greenF()), float(col.blueF())); glVertex2f(-1, 1); - glColor3f(col.redF(), col.greenF(), col.blueF()); + glColor3f(float(col.redF()), float(col.greenF()), float(col.blueF())); glVertex2f(-1, -1); - glColor3f(col.redF(), col.greenF(), col.blueF()); + glColor3f(float(col.redF()), float(col.greenF()), float(col.blueF())); glVertex2f(1, 1); - glColor3f(col.redF(), col.greenF(), col.blueF()); + glColor3f(float(col.redF()), float(col.greenF()), float(col.blueF())); glVertex2f(1, -1); glEnd(); glPopAttrib(); @@ -3496,19 +3668,23 @@ void View3DInventorViewer::setCursorRepresentation(int modearg) // hovered over it the 'WA_SetCursor' attribute is set to the // GL widget but never reset and thus would cause that the // cursor on this widget won't be set. - if (glWindow) + if (glWindow) { glWindow->setAttribute(Qt::WA_SetCursor, false); + } - if (glWindow && glWindow->rect().contains(QCursor::pos())) + if (glWindow && glWindow->rect().contains(QCursor::pos())) { glWindow->setAttribute(Qt::WA_UnderMouse); + } switch (modearg) { case NavigationStyle::IDLE: case NavigationStyle::INTERACT: - if (isEditing()) + if (isEditing()) { this->getWidget()->setCursor(this->editCursor); - else + } + else { this->getWidget()->setCursor(QCursor(Qt::ArrowCursor)); + } break; case NavigationStyle::DRAGGING: @@ -3578,18 +3754,18 @@ SoPath* View3DInventorViewer::pickFilterCB(void* viewer, const SoPickedPoint* pp { ViewProvider* vp = static_cast(viewer)->getViewProviderByPath(pp->getPath()); if (vp && vp->useNewSelectionModel()) { - std::string e = vp->getElement(pp->getDetail()); - vp->getSelectionShape(e.c_str()); + std::string str = vp->getElement(pp->getDetail()); + vp->getSelectionShape(str.c_str()); static char buf[513]; snprintf(buf, sizeof(buf), "Hovered: %s (%f,%f,%f)" - ,e.c_str() - ,pp->getPoint()[0] - ,pp->getPoint()[1] - ,pp->getPoint()[2]); + , str.c_str() + , pp->getPoint()[0] + , pp->getPoint()[1] + , pp->getPoint()[2]); - getMainWindow()->showMessage(QString::fromLatin1(buf),3000); + getMainWindow()->showMessage(QString::fromLatin1(buf), 3000); } return pp->getPath(); @@ -3644,44 +3820,45 @@ void View3DInventorViewer::turnAllDimensionsOff() void View3DInventorViewer::eraseAllDimensions() { - coinRemoveAllChildren(static_cast(dimensionRoot->getChild(0))); - coinRemoveAllChildren(static_cast(dimensionRoot->getChild(1))); + coinRemoveAllChildren(static_cast(dimensionRoot->getChild(0))); // NOLINT + coinRemoveAllChildren(static_cast(dimensionRoot->getChild(1))); // NOLINT } void View3DInventorViewer::turn3dDimensionsOn() { - static_cast(dimensionRoot->getChild(0))->whichChild = SO_SWITCH_ALL; + static_cast(dimensionRoot->getChild(0))->whichChild = SO_SWITCH_ALL; // NOLINT } void View3DInventorViewer::turn3dDimensionsOff() { - static_cast(dimensionRoot->getChild(0))->whichChild = SO_SWITCH_NONE; + static_cast(dimensionRoot->getChild(0))->whichChild = SO_SWITCH_NONE; // NOLINT } void View3DInventorViewer::addDimension3d(SoNode* node) { - static_cast(dimensionRoot->getChild(0))->addChild(node); + static_cast(dimensionRoot->getChild(0))->addChild(node); // NOLINT } void View3DInventorViewer::addDimensionDelta(SoNode* node) { - static_cast(dimensionRoot->getChild(1))->addChild(node); + static_cast(dimensionRoot->getChild(1))->addChild(node); // NOLINT } void View3DInventorViewer::turnDeltaDimensionsOn() { - static_cast(dimensionRoot->getChild(1))->whichChild = SO_SWITCH_ALL; + static_cast(dimensionRoot->getChild(1))->whichChild = SO_SWITCH_ALL; // NOLINT } void View3DInventorViewer::turnDeltaDimensionsOff() { - static_cast(dimensionRoot->getChild(1))->whichChild = SO_SWITCH_NONE; + static_cast(dimensionRoot->getChild(1))->whichChild = SO_SWITCH_NONE; // NOLINT } PyObject *View3DInventorViewer::getPyObject() { - if (!_viewerPy) + if (!_viewerPy) { _viewerPy = new View3DInventorViewerPy(this); + } Py_INCREF(_viewerPy); return _viewerPy; @@ -3690,43 +3867,43 @@ PyObject *View3DInventorViewer::getPyObject() /** * Drops the event \a e and loads the files into the given document. */ -void View3DInventorViewer::dropEvent (QDropEvent * e) +void View3DInventorViewer::dropEvent (QDropEvent* ev) { - const QMimeData* data = e->mimeData(); + const QMimeData* data = ev->mimeData(); if (data->hasUrls() && selectionRoot && selectionRoot->pcDocument) { getMainWindow()->loadUrls(selectionRoot->pcDocument->getDocument(), data->urls()); } else { - inherited::dropEvent(e); + inherited::dropEvent(ev); } } -void View3DInventorViewer::dragEnterEvent (QDragEnterEvent * e) +void View3DInventorViewer::dragEnterEvent (QDragEnterEvent* ev) { // Here we must allow uri drags and check them in dropEvent - const QMimeData* data = e->mimeData(); + const QMimeData* data = ev->mimeData(); if (data->hasUrls()) { - e->accept(); + ev->accept(); } else { - inherited::dragEnterEvent(e); + inherited::dragEnterEvent(ev); } } -void View3DInventorViewer::dragMoveEvent(QDragMoveEvent *e) +void View3DInventorViewer::dragMoveEvent(QDragMoveEvent* ev) { - const QMimeData* data = e->mimeData(); + const QMimeData* data = ev->mimeData(); if (data->hasUrls() && selectionRoot && selectionRoot->pcDocument) { - e->accept(); + ev->accept(); } else { - inherited::dragMoveEvent(e); + inherited::dragMoveEvent(ev); } } -void View3DInventorViewer::dragLeaveEvent(QDragLeaveEvent *e) +void View3DInventorViewer::dragLeaveEvent(QDragLeaveEvent* ev) { - inherited::dragLeaveEvent(e); + inherited::dragLeaveEvent(ev); } #include "moc_View3DInventorViewer.cpp" diff --git a/src/Gui/View3DInventorViewer.h b/src/Gui/View3DInventorViewer.h index 747b3697e3..c2fa305fa6 100644 --- a/src/Gui/View3DInventorViewer.h +++ b/src/Gui/View3DInventorViewer.h @@ -54,11 +54,11 @@ class SoShapeHints; class SoMaterial; class SoRotationXYZ; class SbSphereSheetProjector; -class SoEventCallback; +class SoEventCallback; // NOLINT class SbBox2s; class SoVectorizeAction; class QImage; -class SoGroup; +class SoGroup; // NOLINT class SoPickStyle; class NaviCube; class SoClipPlane; @@ -158,10 +158,10 @@ public: void setSceneGraph (SoNode *root) override; SbBool searchNode(SoNode*) const; - void setAnimationEnabled(const SbBool enable); + void setAnimationEnabled(SbBool enable); SbBool isAnimationEnabled() const; - void setPopupMenuEnabled(const SbBool on); + void setPopupMenuEnabled(SbBool on); SbBool isPopupMenuEnabled() const; void startAnimation(const SbRotation& orientation, const SbVec3f& rotationCenter, @@ -170,15 +170,15 @@ public: void stopAnimating(); SbBool isAnimating() const; - void setFeedbackVisibility(const SbBool enable); + void setFeedbackVisibility(SbBool enable); SbBool isFeedbackVisible() const; - void setFeedbackSize(const int size); + void setFeedbackSize(int size); int getFeedbackSize() const; /// Get the preferred samples from the user settings static int getNumSamples(); - void setRenderType(const RenderType type); + void setRenderType(RenderType type); RenderType getRenderType() const; void renderToFramebuffer(QtGLFramebufferObject*); QImage grabFramebuffer(); @@ -212,7 +212,7 @@ public: /// get all view providers of given type std::vector getViewProvidersOfType(const Base::Type& typeId) const; /// set the ViewProvider in special edit mode - void setEditingViewProvider(Gui::ViewProvider* p, int ModNum); + void setEditingViewProvider(Gui::ViewProvider* vp, int ModNum); /// return whether a view provider is edited SbBool isEditingViewProvider() const; /// reset from edit mode @@ -237,10 +237,10 @@ public: /** @name Making pictures */ //@{ /** - * Creates an image with width \a w and height \a h of the current scene graph - * using a multi-sampling of \a s and exports the rendered scenegraph to an image. + * Creates an image with width \a width and height \a height of the current scene graph + * using a multi-sampling of \a sample and exports the rendered scenegraph to an image. */ - void savePicture(int w, int h, int s, const QColor&, QImage&) const; + void savePicture(int width, int height, int sample, const QColor& bg, QImage& img) const; void saveGraphic(int pagesize, const QColor&, SoVectorizeAction* va) const; //@} /** @@ -257,7 +257,7 @@ public: std::vector getGLPolygon(SelectionRole* role=nullptr) const; std::vector getGLPolygon(const std::vector&) const; const std::vector& getPolygon(SelectionRole* role=nullptr) const; - void setSelectionEnabled(const SbBool enable); + void setSelectionEnabled(SbBool enable); SbBool isSelectionEnabled() const; //@} @@ -376,7 +376,7 @@ public: * set. */ void setCameraOrientation(const SbRotation& orientation, SbBool moveToCenter = false); - void setCameraType(SoType t) override; + void setCameraType(SoType type) override; void moveCameraTo(const SbRotation& orientation, const SbVec3f& position, int duration = -1); /** * Zooms the viewport to the size of the bounding box. @@ -412,17 +412,17 @@ public: const SbColor& midColor); void setNavigationType(Base::Type); - void setAxisCross(bool b); + void setAxisCross(bool on); bool hasAxisCross(); void showRotationCenter(bool show); - void setEnabledFPSCounter(bool b); - void setEnabledNaviCube(bool b); + void setEnabledFPSCounter(bool on); + void setEnabledNaviCube(bool on); bool isEnabledNaviCube() const; void setNaviCubeCorner(int); NaviCube* getNaviCube() const; - void setEnabledVBO(bool b); + void setEnabledVBO(bool on); bool isEnabledVBO() const; void setRenderCache(int); @@ -438,21 +438,21 @@ public: virtual PyObject *getPyObject(); protected: - GLenum getInternalTextureFormat() const; + static GLenum getInternalTextureFormat(); void renderScene(); void renderFramebuffer(); void renderGLImage(); void animatedViewAll(int steps, int ms); void actualRedraw() override; - void setSeekMode(SbBool enable) override; + void setSeekMode(SbBool on) override; void afterRealizeHook() override; bool processSoEvent(const SoEvent * ev) override; - void dropEvent (QDropEvent * e) override; - void dragEnterEvent (QDragEnterEvent * e) override; - void dragMoveEvent(QDragMoveEvent *e) override; - void dragLeaveEvent(QDragLeaveEvent *e) override; + void dropEvent (QDropEvent * ev) override; + void dragEnterEvent (QDragEnterEvent * ev) override; + void dragMoveEvent(QDragMoveEvent* ev) override; + void dragLeaveEvent(QDragLeaveEvent* ev) override; SbBool processSoEventBase(const SoEvent * const ev); - void printDimension(); + void printDimension() const; void selectAll(); private: @@ -465,13 +465,13 @@ private: static void interactionLoggerCB(void * ud, SoAction* action); private: - static void selectCB(void * closure, SoPath * p); - static void deselectCB(void * closure, SoPath * p); - static SoPath * pickFilterCB(void * data, const SoPickedPoint * pick); + static void selectCB(void * viewer, SoPath * path); + static void deselectCB(void * viewer, SoPath * path); + static SoPath * pickFilterCB(void * viewer, const SoPickedPoint * pp); void initialize(); void drawAxisCross(); static void drawArrow(); - void drawSingleBackground(const QColor&); + static void drawSingleBackground(const QColor&); void setCursorRepresentation(int mode); void aboutToDestroyGLContext() override; void createStandardCursors(double);