diff --git a/src/Gui/CMakeLists.txt b/src/Gui/CMakeLists.txt index 614a8d9fc8..f769346543 100644 --- a/src/Gui/CMakeLists.txt +++ b/src/Gui/CMakeLists.txt @@ -319,6 +319,7 @@ SET(Gui_UIC_SRCS PreferencePages/DlgSettingsEditor.ui PreferencePages/DlgSettingsGeneral.ui DlgSettingsImage.ui + PreferencePages/DlgSettingsLightSources.ui PreferencePages/DlgSettingsMacro.ui PreferencePages/DlgSettingsNavigation.ui PreferencePages/DlgSettingsNotificationArea.ui @@ -565,6 +566,7 @@ SET(Dialog_Settings_CPP_SRCS PreferencePages/DlgSettingsEditor.cpp PreferencePages/DlgSettingsGeneral.cpp DlgSettingsImageImp.cpp + PreferencePages/DlgSettingsLightSources.cpp PreferencePages/DlgSettingsMacroImp.cpp PreferencePages/DlgSettingsNavigation.cpp PreferencePages/DlgSettingsNotificationArea.cpp @@ -586,6 +588,7 @@ SET(Dialog_Settings_HPP_SRCS PreferencePages/DlgSettingsEditor.h PreferencePages/DlgSettingsGeneral.h DlgSettingsImageImp.h + PreferencePages/DlgSettingsLightSources.h PreferencePages/DlgSettingsMacroImp.h PreferencePages/DlgSettingsNavigation.h PreferencePages/DlgSettingsNotificationArea.h @@ -609,6 +612,7 @@ SET(Dialog_Settings_SRCS PreferencePages/DlgSettingsEditor.ui PreferencePages/DlgSettingsGeneral.ui DlgSettingsImage.ui + PreferencePages/DlgSettingsLightSources.ui PreferencePages/DlgSettingsMacro.ui PreferencePages/DlgSettingsNavigation.ui PreferencePages/DlgSettingsNotificationArea.ui @@ -835,6 +839,8 @@ SET(View3D_CPP_SRCS View3DPy.cpp View3DViewerPy.cpp NaviCube.cpp + NavigationAnimator.cpp + NavigationAnimation.cpp ) SET(View3D_SRCS ${View3D_CPP_SRCS} @@ -857,6 +863,8 @@ SET(View3D_SRCS CoinRiftWidget.h View3DViewerPy.h NaviCube.h + NavigationAnimator.h + NavigationAnimation.h ) SOURCE_GROUP("View3D" FILES ${View3D_SRCS}) diff --git a/src/Gui/DemoMode.cpp b/src/Gui/DemoMode.cpp index 5dadc25a0c..ce7b07f4d4 100644 --- a/src/Gui/DemoMode.cpp +++ b/src/Gui/DemoMode.cpp @@ -91,7 +91,7 @@ void DemoMode::reset() view->getViewer()->stopAnimating(); ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath ("User parameter:BaseApp/Preferences/View"); - hGrp->Notify("UseAutoRotation"); + hGrp->Notify("UseNavigationAnimations"); } void DemoMode::accept() @@ -150,7 +150,7 @@ Gui::View3DInventor* DemoMode::activeView() const float DemoMode::getSpeed(int v) const { - float speed = (static_cast(v)) / 50.0f; // let 2.0 be the maximum speed + float speed = (static_cast(v)) / 10.0f; // let 10.0 be the maximum speed return speed; } @@ -273,8 +273,9 @@ void DemoMode::startAnimation(Gui::View3DInventor* view) { if (!view->getViewer()->isAnimationEnabled()) view->getViewer()->setAnimationEnabled(true); - view->getViewer()->startAnimating(getDirection(view), - getSpeed(ui->speedSlider->value())); + + view->getViewer()->startSpinningAnimation(getDirection(view), + getSpeed(ui->speedSlider->value())); } void DemoMode::onTimerCheckToggled(bool on) diff --git a/src/Gui/Document.cpp b/src/Gui/Document.cpp index 63a8ed518c..a4f7925575 100644 --- a/src/Gui/Document.cpp +++ b/src/Gui/Document.cpp @@ -1821,7 +1821,6 @@ MDIView *Document::createView(const Base::Type& typeId) view3D->setWindowTitle(title); view3D->setWindowModified(this->isModified()); - view3D->setWindowIcon(QApplication::windowIcon()); view3D->resize(400, 300); if (!cameraSettings.empty()) { diff --git a/src/Gui/EditableDatumLabel.cpp b/src/Gui/EditableDatumLabel.cpp index 7f33e71e0c..a653d140e0 100644 --- a/src/Gui/EditableDatumLabel.cpp +++ b/src/Gui/EditableDatumLabel.cpp @@ -51,6 +51,7 @@ EditableDatumLabel::EditableDatumLabel(View3DInventorViewer* view, : isSet(false) , autoDistance(autoDistance) , autoDistanceReverse(false) + , value(0.0) , viewer(view) , spinBox(nullptr) , cameraSensor(nullptr) @@ -94,7 +95,7 @@ EditableDatumLabel::~EditableDatumLabel() void EditableDatumLabel::activate() { - if (!viewer) { + if (!viewer || isActive()) { return; } @@ -130,8 +131,12 @@ void EditableDatumLabel::deactivate() } } -void EditableDatumLabel::startEdit(double val, QObject* eventFilteringObj) +void EditableDatumLabel::startEdit(double val, QObject* eventFilteringObj, bool visibleToMouse) { + if (isInEdit()) { + return; + } + QWidget* mdi = viewer->parentWidget(); label->string = " "; @@ -147,6 +152,10 @@ void EditableDatumLabel::startEdit(double val, QObject* eventFilteringObj) spinBox->installEventFilter(eventFilteringObj); } + if (!visibleToMouse) { + setSpinboxVisibleToMouse(visibleToMouse); + } + spinBox->show(); setSpinboxValue(val); //Note: adjustSize apparently uses the Min/Max values to set the size. So if we don't set them to INT_MAX, the spinbox are much too big. @@ -156,6 +165,7 @@ void EditableDatumLabel::startEdit(double val, QObject* eventFilteringObj) connect(spinBox, qOverload(&QuantitySpinBox::valueChanged), this, [this](double value) { this->isSet = true; + this->value = value; Q_EMIT this->valueChanged(value); }); } @@ -163,20 +173,35 @@ void EditableDatumLabel::startEdit(double val, QObject* eventFilteringObj) void EditableDatumLabel::stopEdit() { if (spinBox) { + // write the spinbox value in the label. + Base::Quantity quantity = spinBox->value(); + + double factor{}; + QString unitStr; + QString valueStr; + valueStr = quantity.getUserString(factor, unitStr); + label->string = SbString(valueStr.toUtf8().constData()); + spinBox->deleteLater(); spinBox = nullptr; } } -bool EditableDatumLabel::isInEdit() +bool EditableDatumLabel::isActive() const { - return spinBox; + return cameraSensor != nullptr; +} + +bool EditableDatumLabel::isInEdit() const +{ + return spinBox != nullptr; } -double EditableDatumLabel::getValue() +double EditableDatumLabel::getValue() const { - return spinBox->rawValue(); + // We use value rather than spinBox->rawValue() in case edit stopped. + return value; } void EditableDatumLabel::setSpinboxValue(double val, const Base::Unit& unit) @@ -188,6 +213,7 @@ void EditableDatumLabel::setSpinboxValue(double val, const Base::Unit& unit) QSignalBlocker block(spinBox); spinBox->setValue(Base::Quantity(val, unit)); + value = val; positionSpinbox(); if (spinBox->hasFocus()) { @@ -311,11 +337,13 @@ void EditableDatumLabel::setLabelDistance(double val) label->param1 = float(val); } +// NOLINTNEXTLINE void EditableDatumLabel::setLabelStartAngle(double val) { label->param2 = float(val); } +// NOLINTNEXTLINE void EditableDatumLabel::setLabelRange(double val) { label->param3 = float(val); @@ -340,9 +368,9 @@ void EditableDatumLabel::setLabelAutoDistanceReverse(bool val) autoDistanceReverse = val; } -void EditableDatumLabel::setSpinboxInvisibleToMouse(bool val) +void EditableDatumLabel::setSpinboxVisibleToMouse(bool val) { - spinBox->setAttribute(Qt::WA_TransparentForMouseEvents, val); + spinBox->setAttribute(Qt::WA_TransparentForMouseEvents, !val); } #include "moc_EditableDatumLabel.cpp" diff --git a/src/Gui/EditableDatumLabel.h b/src/Gui/EditableDatumLabel.h index c6fad407d2..482aa044b7 100644 --- a/src/Gui/EditableDatumLabel.h +++ b/src/Gui/EditableDatumLabel.h @@ -51,10 +51,11 @@ public: void activate(); void deactivate(); - void startEdit(double val, QObject* eventFilteringObj = nullptr); + void startEdit(double val, QObject* eventFilteringObj = nullptr, bool visibleToMouse = false); void stopEdit(); - bool isInEdit(); - double getValue(); + bool isActive() const; + bool isInEdit() const; + double getValue() const; void setSpinboxValue(double val, const Base::Unit& unit = Base::Unit::Length); void setPlacement(const Base::Placement& plc); void setColor(SbColor color); @@ -68,13 +69,14 @@ public: void setLabelRange(double val); void setLabelRecommendedDistance(); void setLabelAutoDistanceReverse(bool val); - void setSpinboxInvisibleToMouse(bool val); + void setSpinboxVisibleToMouse(bool val); // NOLINTBEGIN SoDatumLabel* label; bool isSet; bool autoDistance; bool autoDistanceReverse; + double value; // NOLINTEND Q_SIGNALS: diff --git a/src/Gui/InventorAll.h b/src/Gui/InventorAll.h index ce1a6d8916..6af406c021 100644 --- a/src/Gui/InventorAll.h +++ b/src/Gui/InventorAll.h @@ -86,6 +86,7 @@ #include #include +#include #include #include #include diff --git a/src/Gui/NavigationAnimation.cpp b/src/Gui/NavigationAnimation.cpp new file mode 100644 index 0000000000..4a086fc63f --- /dev/null +++ b/src/Gui/NavigationAnimation.cpp @@ -0,0 +1,167 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/**************************************************************************** + * * + * Copyright (c) 2023 Bas Ruigrok (Rexbas) * + * * + * This file is part of FreeCAD. * + * * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * + * * + * FreeCAD is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * + * * + ***************************************************************************/ + +#include "PreCompiled.h" +#include "NavigationAnimation.h" +#include + +using namespace Gui; + +NavigationAnimation::NavigationAnimation(NavigationStyle* navigation) + : navigation(navigation) +{} + +void NavigationAnimation::updateCurrentValue(const QVariant& value) +{ + if (state() == QAbstractAnimation::State::Stopped) { + return; + } + update(value); +} + +void NavigationAnimation::onStop([[maybe_unused]] bool finished) +{} + +FixedTimeAnimation::FixedTimeAnimation(NavigationStyle* navigation, const SbRotation& orientation, + const SbVec3f& rotationCenter, const SbVec3f& translation, + int duration) + : NavigationAnimation(navigation) + , targetOrientation(orientation) + , targetTranslation(translation) + , rotationCenter(rotationCenter) +{ + setDuration(duration); + setStartValue(0.0); + setEndValue(duration * 1.0); +} + +void FixedTimeAnimation::initialize() +{ + prevAngle = 0; + prevTranslation = SbVec3f(0, 0, 0); + + // Find an axis and angle to rotate from the camera orientation to the target orientation using post-multiplication + SbVec3f rotationAxisPost; + float angle; + SbRotation(navigation->getCamera()->orientation.getValue().inverse() * targetOrientation).getValue(rotationAxisPost, angle); + if (angle > M_PI) { + angle -= 2 * M_PI; + } + + // Convert post-multiplication axis to a pre-multiplication axis + navigation->getCamera()->orientation.getValue().inverse().multVec(rotationAxisPost, rotationAxis); + + angularVelocity = angle / duration(); + linearVelocity = targetTranslation / duration(); +} + +/** + * @param value The elapsed time + */ +void FixedTimeAnimation::update(const QVariant& value) +{ + SoCamera* camera = navigation->getCamera(); + if (!camera) { + return; + } + + float angle = value.toFloat() * angularVelocity; + SbVec3f translation = value.toFloat() * linearVelocity; + + SbRotation rotation(rotationAxis, angle - prevAngle); + + camera->position = camera->position.getValue() - prevTranslation; + navigation->reorientCamera(camera, rotation, rotationCenter); + camera->position = camera->position.getValue() + translation; + + prevAngle = angle; + prevTranslation = translation; +} + +/** + * @param finished True when the animation is finished, false when interrupted + */ +void FixedTimeAnimation::onStop(bool finished) +{ + if (finished) { + SoCamera* camera = navigation->getCamera(); + if (!camera) { + return; + } + + // Set exact target orientation + camera->orientation = targetOrientation; + camera->position = camera->position.getValue() + targetTranslation - prevTranslation; + } +} + +/** + * @param navigation The navigation style + * @param axis The rotation axis in screen coordinates + * @param velocity The angular velocity in radians per second + */ +SpinningAnimation::SpinningAnimation(NavigationStyle* navigation, const SbVec3f& axis, + float velocity) + : NavigationAnimation(navigation) + , rotationAxis(axis) +{ + setDuration((2 * M_PI / velocity) * 1000.0); + setStartValue(0.0); + setEndValue(2 * M_PI); + setLoopCount(-1); +} + +void SpinningAnimation::initialize() +{ + prevAngle = 0; + + navigation->setViewing(true); + navigation->setViewingMode(NavigationStyle::SPINNING); +} + +/** + * @param value The angle in radians + */ +void SpinningAnimation::update(const QVariant& value) +{ + SoCamera* camera = navigation->getCamera(); + if (!camera) { + return; + } + + SbRotation deltaRotation = SbRotation(rotationAxis, value.toFloat() - prevAngle); + navigation->reorientCamera(camera, deltaRotation); + + prevAngle = value.toFloat(); +} + +/** + * @param finished True when the animation is finished, false when interrupted + */ +void SpinningAnimation::onStop([[maybe_unused]] bool finished) +{ + if (navigation->getViewingMode() != NavigationStyle::SPINNING) { + return; + } + navigation->setViewingMode(navigation->isViewing() ? NavigationStyle::IDLE : NavigationStyle::INTERACT); +} diff --git a/src/Gui/NavigationAnimation.h b/src/Gui/NavigationAnimation.h new file mode 100644 index 0000000000..6efdae3b42 --- /dev/null +++ b/src/Gui/NavigationAnimation.h @@ -0,0 +1,99 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/**************************************************************************** + * * + * Copyright (c) 2023 Bas Ruigrok (Rexbas) * + * * + * This file is part of FreeCAD. * + * * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * + * * + * FreeCAD is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * + * * + ***************************************************************************/ + +#ifndef GUI_NAVIGATIONANIMATION_H +#define GUI_NAVIGATIONANIMATION_H + +#include "NavigationStyle.h" +#include +#include +#include + +namespace Gui +{ + +class GuiExport NavigationAnimation : protected QVariantAnimation +{ + Q_OBJECT +public: + explicit NavigationAnimation(NavigationStyle* navigation); + +Q_SIGNALS: + void interrupted(); + +protected: + NavigationStyle* navigation; + + virtual void initialize() = 0; + virtual void update(const QVariant& value) = 0; + virtual void onStop(bool finished); + +private: + void updateCurrentValue(const QVariant& value) override; + + friend class NavigationAnimator; + friend class QObject; +}; + +class GuiExport FixedTimeAnimation : public NavigationAnimation +{ +public: + explicit FixedTimeAnimation(NavigationStyle* navigation, const SbRotation& orientation, + const SbVec3f& rotationCenter, const SbVec3f& translation, + int duration); + +private: + float angularVelocity; // [rad/ms] + SbVec3f linearVelocity; // [/ms] + + SbRotation targetOrientation; + SbVec3f targetTranslation; + + float prevAngle; + SbVec3f prevTranslation; + + SbVec3f rotationCenter; + SbVec3f rotationAxis; + + void initialize() override; + void update(const QVariant& value) override; + void onStop(bool finished) override; +}; + +class GuiExport SpinningAnimation : public NavigationAnimation +{ +public: + explicit SpinningAnimation(NavigationStyle* navigation, const SbVec3f& axis, float velocity); + +private: + SbVec3f rotationAxis; + float prevAngle; + + void initialize() override; + void update(const QVariant& value) override; + void onStop(bool finished) override; +}; + +} // namespace Gui + +#endif // GUI_NAVIGATIONANIMATION_H diff --git a/src/Gui/NavigationAnimator.cpp b/src/Gui/NavigationAnimator.cpp new file mode 100644 index 0000000000..4f3a73eff4 --- /dev/null +++ b/src/Gui/NavigationAnimator.cpp @@ -0,0 +1,92 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/**************************************************************************** + * * + * Copyright (c) 2023 Bas Ruigrok (Rexbas) * + * * + * This file is part of FreeCAD. * + * * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * + * * + * FreeCAD is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * + * * + ***************************************************************************/ + +#include "PreCompiled.h" +#include "NavigationAnimator.h" +#include "NavigationAnimation.h" +#include + +using namespace Gui; + +NavigationAnimator::NavigationAnimator() + : activeAnimation(nullptr) +{} + +NavigationAnimator::~NavigationAnimator() +{ + stop(); +} + +/** + * @brief Start an animation + * + * @param animation The animation to start + */ +void NavigationAnimator::start(const std::shared_ptr& animation) +{ + stop(); + activeAnimation = animation; + activeAnimation->initialize(); + + connect(activeAnimation.get(), &NavigationAnimation::finished, this, [this]() { + activeAnimation->onStop(true); + activeAnimation.reset(); + }); + + activeAnimation->start(); +} + +/** + * @brief Start an animation and wait for it to finish + * + * @param animation The animation to start + * @return True if the animation finished, false if interrupted + */ +bool NavigationAnimator::startAndWait(const std::shared_ptr& animation) +{ + stop(); + bool finished = true; + QEventLoop loop; + connect(animation.get(), &NavigationAnimation::finished, &loop, &QEventLoop::quit); + connect(animation.get(), &NavigationAnimation::interrupted, &loop, [&finished, &loop]() { + finished = false; + loop.quit(); + }); + start(animation); + loop.exec(); + return finished; +} + +/** + * @brief Stops an active animation and releases shared ownership of the animation + */ +void NavigationAnimator::stop() +{ + if (activeAnimation && activeAnimation->state() != QAbstractAnimation::State::Stopped) { + disconnect(activeAnimation.get(), &NavigationAnimation::finished, 0, 0); + Q_EMIT activeAnimation->interrupted(); + activeAnimation->stop(); + activeAnimation->onStop(false); + activeAnimation.reset(); + } +} diff --git a/src/Gui/NavigationAnimator.h b/src/Gui/NavigationAnimator.h new file mode 100644 index 0000000000..e2f7290a1e --- /dev/null +++ b/src/Gui/NavigationAnimator.h @@ -0,0 +1,52 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/**************************************************************************** + * * + * Copyright (c) 2023 Bas Ruigrok (Rexbas) * + * * + * This file is part of FreeCAD. * + * * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * + * * + * FreeCAD is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * + * * + ***************************************************************************/ + +#ifndef GUI_NAVIGATIONANIMATOR_H +#define GUI_NAVIGATIONANIMATOR_H + +#include "NavigationStyle.h" +#include +#include + +namespace Gui +{ + +class NavigationAnimation; + +class GuiExport NavigationAnimator : public QObject +{ + Q_OBJECT +public: + NavigationAnimator(); + ~NavigationAnimator(); + void start(const std::shared_ptr& animation); + bool startAndWait(const std::shared_ptr& animation); + void stop(); + +private: + std::shared_ptr activeAnimation; +}; + +} // namespace Gui + +#endif // GUI_NAVIGATIONANIMATOR_H diff --git a/src/Gui/NavigationStyle.cpp b/src/Gui/NavigationStyle.cpp index e3490ead43..5b4243bbf5 100644 --- a/src/Gui/NavigationStyle.cpp +++ b/src/Gui/NavigationStyle.cpp @@ -45,40 +45,13 @@ #include "Application.h" #include "MenuManager.h" #include "MouseSelection.h" +#include "NavigationAnimator.h" +#include "NavigationAnimation.h" #include "SoMouseWheelEvent.h" #include "View3DInventorViewer.h" - using namespace Gui; -namespace Gui { -struct NavigationStyleP { - int animationsteps; - int animationdelta; - SbVec3f focal1, focal2; - SbVec3f rotationCenter; - SbBool rotationCenterFound; - NavigationStyle::RotationCenterModes rotationCenterMode; - SbRotation endRotation; - SoTimerSensor * animsensor; - float sensitivity; - SbBool resetcursorpos; - - NavigationStyleP() - { - this->animationsteps = 0; - this->animationdelta = 0; - this->animsensor = nullptr; - this->sensitivity = 2.0f; - this->resetcursorpos = false; - this->rotationCenterFound = false; - this->rotationCenterMode = NavigationStyle::RotationCenterMode::ScenePointAtCursor | - NavigationStyle::RotationCenterMode::FocalPointAtCursor; - } - static void viewAnimationCB(void * data, SoSensor * sensor); -}; -} - class FCSphereSheetProjector : public SbSphereSheetProjector { using inherited = SbSphereSheetProjector; @@ -184,25 +157,19 @@ const Base::Type& NavigationStyleEvent::style() const return t; } -#define PRIVATE(ptr) (ptr->pimpl) -#define PUBLIC(ptr) (ptr->pub) - TYPESYSTEM_SOURCE_ABSTRACT(Gui::NavigationStyle,Base::BaseClass) NavigationStyle::NavigationStyle() : viewer(nullptr), mouseSelection(nullptr) { - PRIVATE(this) = new NavigationStyleP(); - PRIVATE(this)->animsensor = new SoTimerSensor(NavigationStyleP::viewAnimationCB, this); + this->rotationCenterMode = NavigationStyle::RotationCenterMode::ScenePointAtCursor + | NavigationStyle::RotationCenterMode::FocalPointAtCursor; initialize(); } NavigationStyle::~NavigationStyle() { finalize(); - if (PRIVATE(this)->animsensor->isScheduled()) - PRIVATE(this)->animsensor->unschedule(); - delete PRIVATE(this)->animsensor; - delete PRIVATE(this); + delete this->animator; } NavigationStyle& NavigationStyle::operator = (const NavigationStyle& ns) @@ -222,12 +189,15 @@ void NavigationStyle::setViewer(View3DInventorViewer* view) void NavigationStyle::initialize() { + this->animator = new NavigationAnimator(); + + this->sensitivity = 2.0f; + this->resetcursorpos = false; this->currentmode = NavigationStyle::IDLE; - this->prevRedrawTime = SbTime::getTimeOfDay(); this->spinanimatingallowed = true; this->spinsamplecounter = 0; this->spinincrement = SbRotation::identity(); - this->spinRotation.setValue(SbVec3f(0, 0, -1), 0); + this->rotationCenterFound = false; // FIXME: use a smaller sphere than the default one to have a larger // area close to the borders that gives us "z-axis rotation"? @@ -357,167 +327,72 @@ SbBool NavigationStyle::lookAtPoint(const SbVec2s screenpos) return true; } -void NavigationStyle::lookAtPoint(const SbVec3f& pos) +void NavigationStyle::lookAtPoint(const SbVec3f& position) { - SoCamera* cam = viewer->getSoRenderManager()->getCamera(); - if (!cam) - return; - PRIVATE(this)->rotationCenterFound = false; - - // Find global coordinates of focal point. - SbVec3f direction; - cam->orientation.getValue().multVec(SbVec3f(0, 0, -1), direction); - PRIVATE(this)->focal1 = cam->position.getValue() + - cam->focalDistance.getValue() * direction; - PRIVATE(this)->focal2 = pos; - - // avoid to interfere with spinning (fixes #3101462) - if (this->isAnimating()) - this->stopAnimating(); - - if (PRIVATE(this)->animsensor->isScheduled()) { - PRIVATE(this)->animsensor->unschedule(); - this->interactiveCountDec(); - } - - if (isAnimationEnabled()) { - SbRotation cam_rot = cam->orientation.getValue(); - // get the amount of movement - SbVec3f dir1 = direction, dir2; - dir2 = pos - cam->position.getValue(); - dir2.normalize(); - SbRotation rot(dir1, dir2); - float val = 0.5f*(1.0f + dir1.dot(dir2)); // value in range [0,1] - int div = (int)(val * 20.0f); - int steps = 20-div; // do it with max. 20 steps - - // check whether a movement is required - if (steps > 0) { - PRIVATE(this)->endRotation = cam_rot; - this->spinRotation = cam_rot; - PRIVATE(this)->animationsteps = 5; - PRIVATE(this)->animationdelta = std::max(100/steps, 5); - PRIVATE(this)->animsensor->setBaseTime(SbTime::getTimeOfDay()); - PRIVATE(this)->animsensor->schedule(); - this->interactiveCountInc(); - } - else { - // set to the given position - SbVec3f direction; - cam->orientation.getValue().multVec(SbVec3f(0, 0, -1), direction); - cam->position = pos - cam->focalDistance.getValue() * direction; - } - } - else { - // set to the given position - SbVec3f direction; - cam->orientation.getValue().multVec(SbVec3f(0, 0, -1), direction); - cam->position = pos - cam->focalDistance.getValue() * direction; - } + this->rotationCenterFound = false; + translateCamera(position - getFocalPoint()); } -void NavigationStyle::setCameraOrientation(const SbRotation& rot, SbBool moveToCenter) +SoCamera* NavigationStyle::getCamera() const { - SoCamera* cam = viewer->getSoRenderManager()->getCamera(); - if (!cam) + return this->viewer->getCamera(); +} + +void NavigationStyle::setCameraOrientation(const SbRotation& orientation, SbBool moveToCenter) +{ + SoCamera* camera = getCamera(); + if (!camera) return; - // Find global coordinates of focal point. - SbVec3f direction; - cam->orientation.getValue().multVec(SbVec3f(0, 0, -1), direction); - PRIVATE(this)->focal1 = cam->position.getValue() + - cam->focalDistance.getValue() * direction; - PRIVATE(this)->focal2 = PRIVATE(this)->focal1; + animator->stop(); + + SbVec3f focalPoint = getFocalPoint(); + SbVec3f translation(0, 0, 0); + if (moveToCenter) { SoGetBoundingBoxAction action(viewer->getSoRenderManager()->getViewportRegion()); action.apply(viewer->getSceneGraph()); SbBox3f box = action.getBoundingBox(); if (!box.isEmpty()) { - rot.multVec(SbVec3f(0, 0, -1), direction); - //float s = (this->focal1 - box.getCenter()).dot(direction); - //this->focal2 = box.getCenter() + s * direction; - // setting the center of the overall bounding box as the future focal point - // seems to be a satisfactory solution - PRIVATE(this)->focal2 = box.getCenter(); + translation = box.getCenter() - focalPoint; } } - // avoid to interfere with spinning (fixes #3101462) - if (this->isAnimating()) - this->stopAnimating(); - - if (PRIVATE(this)->animsensor->isScheduled()) { - PRIVATE(this)->animsensor->unschedule(); - this->interactiveCountDec(); - } - + // Start an animation or set the pose directly if (isAnimationEnabled()) { - // get the amount of movement - SbVec3f dir1, dir2; - SbRotation cam_rot = cam->orientation.getValue(); - cam_rot.multVec(SbVec3f(0, 0, -1), dir1); - rot.multVec(SbVec3f(0, 0, -1), dir2); - float val = 0.5f*(1.0f + dir1.dot(dir2)); // value in range [0,1] - int div = (int)(val * 20.0f); - int steps = 20-div; // do it with max. 20 steps - - // check whether a movement is required - if (steps > 0) { - PRIVATE(this)->endRotation = rot; // this is the final camera orientation - this->spinRotation = cam_rot; - PRIVATE(this)->animationsteps = 5; - PRIVATE(this)->animationdelta = std::max(100/steps, 5); - PRIVATE(this)->animsensor->setBaseTime(SbTime::getTimeOfDay()); - PRIVATE(this)->animsensor->schedule(); - this->interactiveCountInc(); - } - else { - // due to possible round-off errors make sure that the - // exact orientation is set - cam->orientation.setValue(rot); - cam->position = PRIVATE(this)->focal2 - cam->focalDistance.getValue() * direction; - } + viewer->startAnimation(orientation, focalPoint, translation); } else { - // set to the given rotation - cam->orientation.setValue(rot); - cam->orientation.getValue().multVec(SbVec3f(0, 0, -1), direction); - cam->position = PRIVATE(this)->focal2 - cam->focalDistance.getValue() * direction; + // Distance from rotation center to camera position in camera coordinate system + SbVec3f rotationCenterDistanceCam = camera->focalDistance.getValue() * SbVec3f(0, 0, 1); + + // Set to the given orientation + camera->orientation = orientation; + + // Distance from rotation center to new camera position in global coordinate system + SbVec3f newRotationCenterDistance; + camera->orientation.getValue().multVec(rotationCenterDistanceCam, newRotationCenterDistance); + + // Reposition camera so the rotation center stays in the same place + // Optionally add translation to move to center + camera->position = focalPoint + newRotationCenterDistance + translation; } } -void NavigationStyleP::viewAnimationCB(void * data, SoSensor * sensor) +void NavigationStyle::translateCamera(const SbVec3f& translation) { - Q_UNUSED(sensor); - auto that = static_cast(data); - if (PRIVATE(that)->animationsteps > 0) { - // here the camera rotates from the current rotation to a given - // rotation (e.g. the standard views). To get this movement animated - // we calculate an interpolated rotation and update the view after - // each step - float step = std::min((float)PRIVATE(that)->animationsteps/100.0f, 1.0f); - SbRotation slerp = SbRotation::slerp(that->spinRotation, PRIVATE(that)->endRotation, step); - SbVec3f focalpoint = (1.0f-step)*PRIVATE(that)->focal1 + step*PRIVATE(that)->focal2; - SoCamera* cam = that->viewer->getSoRenderManager()->getCamera(); - if (!cam) // no camera - return; + SoCamera* camera = getCamera(); + if (!camera) + return; - SbVec3f direction; - cam->orientation.setValue(slerp); - cam->orientation.getValue().multVec(SbVec3f(0, 0, -1), direction); - cam->position = focalpoint - cam->focalDistance.getValue() * direction; + animator->stop(); - PRIVATE(that)->animationsteps += PRIVATE(that)->animationdelta; - if (PRIVATE(that)->animationsteps > 100) { - // now we have reached the end of the movement - PRIVATE(that)->animationsteps=0; - PRIVATE(that)->animsensor->unschedule(); - that->interactiveCountDec(); - // set to the actual given rotation - cam->orientation.setValue(PRIVATE(that)->endRotation); - cam->orientation.getValue().multVec(SbVec3f(0, 0, -1), direction); - cam->position = PRIVATE(that)->focal2 - cam->focalDistance.getValue() * direction; - } + // Start an animation or set the pose directly + if (isAnimationEnabled()) { + viewer->startAnimation(camera->orientation.getValue(), SbVec3f(0, 0, 0), translation); + } + else { + camera->position = camera->position.getValue() + translation; } } @@ -604,29 +479,41 @@ void NavigationStyle::viewAll() } } -/** Rotate the camera by the given amount, then reposition it so we're - * still pointing at the same focal point. +/** Rotate the camera by the given amount, then reposition it so we're still pointing at the same + * focal point */ -void NavigationStyle::reorientCamera(SoCamera * cam, const SbRotation & rot) +void NavigationStyle::reorientCamera(SoCamera* camera, const SbRotation& rotation) { - if (!cam) + reorientCamera(camera, rotation, getFocalPoint()); +} + +/** Rotate the camera by the given amount, then reposition it so the rotation center stays in the + * same place + */ +void NavigationStyle::reorientCamera(SoCamera* camera, const SbRotation& rotation, const SbVec3f& rotationCenter) +{ + if (!camera) { return; - - // Find global coordinates of focal point. - SbVec3f direction; - cam->orientation.getValue().multVec(SbVec3f(0, 0, -1), direction); - SbVec3f focalpoint = cam->position.getValue() + - cam->focalDistance.getValue() * direction; - - // Set new orientation value by accumulating the new rotation. - cam->orientation = rot * cam->orientation.getValue(); - // Fix issue with near clipping in orthogonal view - if (cam->getTypeId().isDerivedFrom(SoOrthographicCamera::getClassTypeId())) { - cam->focalDistance = static_cast(cam)->height; } - // Reposition camera so we are still pointing at the same old focal point. - cam->orientation.getValue().multVec(SbVec3f(0, 0, -1), direction); - cam->position = focalpoint - cam->focalDistance.getValue() * direction; + + // Distance from rotation center to camera position in camera coordinate system + SbVec3f rotationCenterDistanceCam; + camera->orientation.getValue().inverse().multVec(camera->position.getValue() - rotationCenter, rotationCenterDistanceCam); + + // Set new orientation value by accumulating the new rotation + camera->orientation = rotation * camera->orientation.getValue(); + + // Fix issue with near clipping in orthogonal view + if (camera->getTypeId().isDerivedFrom(SoOrthographicCamera::getClassTypeId())) { + camera->focalDistance = static_cast(camera)->height; + } + + // Distance from rotation center to new camera position in global coordinate system + SbVec3f newRotationCenterDistance; + camera->orientation.getValue().multVec(rotationCenterDistanceCam, newRotationCenterDistance); + + // Reposition camera so the rotation center stays in the same place + camera->position = rotationCenter + newRotationCenterDistance; } void NavigationStyle::panCamera(SoCamera * cam, float aspectratio, const SbPlane & panplane, @@ -684,7 +571,7 @@ void NavigationStyle::panToCenter(const SbPlane & pplane, const SbVec2f & currpo const SbViewportRegion & vp = viewer->getSoRenderManager()->getViewportRegion(); float ratio = vp.getViewportAspectRatio(); panCamera(viewer->getSoRenderManager()->getCamera(), ratio, pplane, SbVec2f(0.5,0.5), currpos); - PRIVATE(this)->rotationCenterFound = false; + this->rotationCenterFound = false; } /** Dependent on the camera type this will either shrink or expand the @@ -695,6 +582,9 @@ void NavigationStyle::zoom(SoCamera * cam, float diffvalue) { if (!cam) // can happen for empty scenegraph return; + + animator->stop(); + SoType t = cam->getTypeId(); SbName tname = t.getName(); @@ -862,14 +752,14 @@ void NavigationStyle::doRotate(SoCamera * camera, float angle, const SbVec2f& po SbVec3f NavigationStyle::getRotationCenter(SbBool& found) const { - found = PRIVATE(this)->rotationCenterFound; - return PRIVATE(this)->rotationCenter; + found = this->rotationCenterFound; + return this->rotationCenter; } void NavigationStyle::setRotationCenter(const SbVec3f& cnt) { - PRIVATE(this)->rotationCenter = cnt; - PRIVATE(this)->rotationCenterFound = true; + this->rotationCenter = cnt; + this->rotationCenterFound = true; } SbVec3f NavigationStyle::getFocalPoint() const @@ -901,8 +791,8 @@ void NavigationStyle::spin(const SbVec2f & pointerpos) lastpos[0] = float(this->log.position[1][0]) / float(std::max((int)(glsize[0]-1), 1)); lastpos[1] = float(this->log.position[1][1]) / float(std::max((int)(glsize[1]-1), 1)); - if (PRIVATE(this)->rotationCenterMode && PRIVATE(this)->rotationCenterFound) { - SbVec3f hitpoint = PRIVATE(this)->rotationCenter; + if (this->rotationCenterMode && this->rotationCenterFound) { + SbVec3f hitpoint = this->rotationCenter; // set to the given position SbVec3f direction; @@ -929,7 +819,7 @@ void NavigationStyle::spin(const SbVec2f & pointerpos) r.invert(); this->reorientCamera(viewer->getSoRenderManager()->getCamera(), r); - if (PRIVATE(this)->rotationCenterMode && PRIVATE(this)->rotationCenterFound) { + if (this->rotationCenterMode && this->rotationCenterFound) { float ratio = vp.getViewportAspectRatio(); SbViewVolume vv = viewer->getSoRenderManager()->getCamera()->getViewVolume(vp.getViewportAspectRatio()); SbPlane panplane = vv.getPlane(viewer->getSoRenderManager()->getCamera()->focalDistance.getValue()); @@ -1015,7 +905,7 @@ SbBool NavigationStyle::doSpin() float radians; rot.getValue(axis, radians); if ((radians > 0.01f) && (deltatime < 0.300)) { - this->spinRotation = rot; + viewer->startSpinningAnimation(axis, radians * 5); return true; } } @@ -1030,14 +920,14 @@ void NavigationStyle::saveCursorPosition(const SoEvent * const ev) this->localPos = ev->getPosition(); // mode is WindowCenter - if (!PRIVATE(this)->rotationCenterMode) { + if (!this->rotationCenterMode) { setRotationCenter(getFocalPoint()); } //Option to get point on model (slow) or always on focal plane (fast) // // mode is ScenePointAtCursor to get exact point if possible - if (PRIVATE(this)->rotationCenterMode & NavigationStyle::RotationCenterMode::ScenePointAtCursor) { + if (this->rotationCenterMode & NavigationStyle::RotationCenterMode::ScenePointAtCursor) { SoRayPickAction rpaction(viewer->getSoRenderManager()->getViewportRegion()); rpaction.setPoint(this->localPos); rpaction.setRadius(viewer->getPickRadius()); @@ -1051,7 +941,7 @@ void NavigationStyle::saveCursorPosition(const SoEvent * const ev) } // mode is FocalPointAtCursor or a ScenePointAtCursor failed - if (PRIVATE(this)->rotationCenterMode & NavigationStyle::RotationCenterMode::FocalPointAtCursor) { + if (this->rotationCenterMode & NavigationStyle::RotationCenterMode::FocalPointAtCursor) { // get the intersection point of the ray and the focal plane const SbViewportRegion & vp = viewer->getSoRenderManager()->getViewportRegion(); float ratio = vp.getViewportAspectRatio(); @@ -1072,7 +962,7 @@ void NavigationStyle::saveCursorPosition(const SoEvent * const ev) } // mode is BoundingBoxCenter or a ScenePointAtCursor failed - if (PRIVATE(this)->rotationCenterMode & NavigationStyle::RotationCenterMode::BoundingBoxCenter) { + if (this->rotationCenterMode & NavigationStyle::RotationCenterMode::BoundingBoxCenter) { const SbViewportRegion & vp = viewer->getSoRenderManager()->getViewportRegion(); float ratio = vp.getViewportAspectRatio(); @@ -1128,20 +1018,6 @@ void NavigationStyle::moveCursorPosition() } } -void NavigationStyle::updateAnimation() -{ - SbTime now = SbTime::getTimeOfDay(); - double secs = now.getValue() - prevRedrawTime.getValue(); - this->prevRedrawTime = now; - - if (this->isAnimating()) { - // here the camera rotates around a fix axis - SbRotation deltaRotation = this->spinRotation; - deltaRotation.scaleAngle(secs * 5.0); - this->reorientCamera(viewer->getSoRenderManager()->getCamera(), deltaRotation); - } -} - void NavigationStyle::redraw() { if (mouseSelection) @@ -1168,7 +1044,7 @@ void NavigationStyle::setAnimationEnabled(const SbBool enable) { this->spinanimatingallowed = enable; - if (!enable && this->isAnimating()) { this->stopAnimating(); } + if (!enable && this->isAnimating()) { animator->stop(); } } /*! @@ -1191,52 +1067,39 @@ SbBool NavigationStyle::isAnimating() const return this->currentmode == NavigationStyle::SPINNING; } -/*! - * Starts programmatically the viewer in animation mode. The given axis direction - * is always in screen coordinates, not in world coordinates. - */ -void NavigationStyle::startAnimating(const SbVec3f& axis, float velocity) +void NavigationStyle::startAnimating(const std::shared_ptr& animation, bool wait) const { - if (!isAnimationEnabled()) - return; - - this->prevRedrawTime = SbTime::getTimeOfDay(); - this->spinincrement = SbRotation::identity(); - SbRotation rot; - rot.setValue(axis, velocity); - - this->setViewing(true); - this->setViewingMode(NavigationStyle::SPINNING); - this->spinRotation = rot; + if (wait) { + animator->startAndWait(animation); + } + else { + animator->start(animation); + } } -void NavigationStyle::stopAnimating() +void NavigationStyle::stopAnimating() const { - if (this->currentmode != NavigationStyle::SPINNING) { - return; - } - this->setViewingMode(this->isViewing() ? - NavigationStyle::IDLE : NavigationStyle::INTERACT); + animator->stop(); } void NavigationStyle::setSensitivity(float val) { - PRIVATE(this)->sensitivity = val; + this->sensitivity = val; } float NavigationStyle::getSensitivity() const { - return PRIVATE(this)->sensitivity; + return this->sensitivity; } void NavigationStyle::setResetCursorPosition(SbBool on) { - PRIVATE(this)->resetcursorpos = on; + this->resetcursorpos = on; } SbBool NavigationStyle::isResetCursorPosition() const { - return PRIVATE(this)->resetcursorpos; + return this->resetcursorpos; } void NavigationStyle::setZoomInverted(SbBool on) @@ -1266,12 +1129,12 @@ SbBool NavigationStyle::isZoomAtCursor() const void NavigationStyle::setRotationCenterMode(NavigationStyle::RotationCenterModes mode) { - PRIVATE(this)->rotationCenterMode = mode; + this->rotationCenterMode = mode; } NavigationStyle::RotationCenterModes NavigationStyle::getRotationCenterMode() const { - return PRIVATE(this)->rotationCenterMode; + return this->rotationCenterMode; } void NavigationStyle::startSelection(AbstractMouseSelection* mouse) @@ -1415,6 +1278,7 @@ void NavigationStyle::setViewingMode(const ViewerMode newmode) case DRAGGING: // Set up initial projection point for the projector object when // first starting a drag operation. + animator->stop(); viewer->showRotationCenter(true); this->spinprojector->project(this->lastmouseposition); this->interactiveCountInc(); @@ -1428,15 +1292,18 @@ void NavigationStyle::setViewingMode(const ViewerMode newmode) break; case PANNING: + animator->stop(); pan(viewer->getSoRenderManager()->getCamera()); this->interactiveCountInc(); break; case ZOOMING: + animator->stop(); this->interactiveCountInc(); break; case BOXZOOM: + animator->stop(); this->interactiveCountInc(); break; diff --git a/src/Gui/NavigationStyle.h b/src/Gui/NavigationStyle.h index cbc6204a9a..c499776456 100644 --- a/src/Gui/NavigationStyle.h +++ b/src/Gui/NavigationStyle.h @@ -38,7 +38,7 @@ #include #include #include - +#include // forward declarations class SoEvent; @@ -52,7 +52,9 @@ class SbSphereSheetProjector; namespace Gui { class View3DInventorViewer; +class NavigationAnimator; class AbstractMouseSelection; +class NavigationAnimation; /** * @author Werner Mayer @@ -122,9 +124,9 @@ public: void setAnimationEnabled(const SbBool enable); SbBool isAnimationEnabled() const; - void startAnimating(const SbVec3f& axis, float velocity); - void stopAnimating(); SbBool isAnimating() const; + void startAnimating(const std::shared_ptr& animation, bool wait = false) const; + void stopAnimating() const; void setSensitivity(float); float getSensitivity() const; @@ -144,11 +146,14 @@ public: void setRotationCenter(const SbVec3f& cnt); SbVec3f getFocalPoint() const; - void updateAnimation(); void redraw(); - void setCameraOrientation(const SbRotation& rot, SbBool moveTocenter=false); - void lookAtPoint(const SbVec3f&); + SoCamera* getCamera() const; + void setCameraOrientation(const SbRotation& orientation, SbBool moveToCenter = false); + void translateCamera(const SbVec3f& translation); + void reorientCamera(SoCamera* camera, const SbRotation& rotation); + void reorientCamera(SoCamera* camera, const SbRotation& rotation, const SbVec3f& rotationCenter); + void boxZoom(const SbBox2s& box); virtual void viewAll(); @@ -173,6 +178,9 @@ public: void setOrbitStyle(OrbitStyle style); OrbitStyle getOrbitStyle() const; + SbBool isViewing() const; + void setViewing(SbBool); + SbVec3f getRotationCenter(SbBool&) const; protected: @@ -183,15 +191,13 @@ protected: void interactiveCountDec(); int getInteractiveCount() const; - SbBool isViewing() const; - void setViewing(SbBool); SbBool isSeekMode() const; void setSeekMode(SbBool enable); SbBool seekToPoint(const SbVec2s screenpos); void seekToPoint(const SbVec3f& scenepos); SbBool lookAtPoint(const SbVec2s screenpos); + void lookAtPoint(const SbVec3f& position); - void reorientCamera(SoCamera * camera, const SbRotation & rot); void panCamera(SoCamera * camera, float vpaspect, const SbPlane & panplane, @@ -233,13 +239,13 @@ protected: } log; View3DInventorViewer* viewer{nullptr}; + NavigationAnimator* animator; ViewerMode currentmode; SoMouseButtonEvent mouseDownConsumedEvent; SbVec2f lastmouseposition; SbVec2s globalPos; SbVec2s localPos; SbPlane panningplane; - SbTime prevRedrawTime; SbTime centerTime; SbBool lockrecenter; SbBool menuenabled; @@ -261,13 +267,17 @@ protected: SbBool spinanimatingallowed; int spinsamplecounter; SbRotation spinincrement; - SbRotation spinRotation; SbSphereSheetProjector * spinprojector; //@} private: - struct NavigationStyleP* pimpl; - friend struct NavigationStyleP; + friend class NavigationAnimator; + + SbVec3f rotationCenter; + SbBool rotationCenterFound; + NavigationStyle::RotationCenterModes rotationCenterMode; + float sensitivity; + SbBool resetcursorpos; }; /** Sub-classes of this class appear in the preference dialog where users can diff --git a/src/Gui/PreferencePackTemplates/View.cfg b/src/Gui/PreferencePackTemplates/View.cfg index 6ad815c14c..708b9b9498 100644 --- a/src/Gui/PreferencePackTemplates/View.cfg +++ b/src/Gui/PreferencePackTemplates/View.cfg @@ -32,7 +32,8 @@ - + + diff --git a/src/Gui/PreferencePages/DlgSettingsLightSources.cpp b/src/Gui/PreferencePages/DlgSettingsLightSources.cpp new file mode 100644 index 0000000000..44e635bc82 --- /dev/null +++ b/src/Gui/PreferencePages/DlgSettingsLightSources.cpp @@ -0,0 +1,229 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later + +/*************************************************************************** + * Copyright (c) 2023 Werner Mayer * + * * + * This file is part of FreeCAD. * + * * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * + * * + * FreeCAD is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * + * * + **************************************************************************/ + +#include "PreCompiled.h" + +#ifndef _PreComp_ +#include +#include +#include +#include +#include +#include +#include +#include +#endif + +#include "DlgSettingsLightSources.h" +#include "ui_DlgSettingsLightSources.h" +#include + + +using namespace Gui::Dialog; + +/* TRANSLATOR Gui::Dialog::DlgSettingsLightSources */ + +DlgSettingsLightSources::DlgSettingsLightSources(QWidget* parent) + : PreferencePage(parent) + , ui(new Ui_DlgSettingsLightSources) +{ + ui->setupUi(this); + setupConnection(); +} + +DlgSettingsLightSources::~DlgSettingsLightSources() +{ + delete view; +} + +void DlgSettingsLightSources::setupConnection() +{ + connect(ui->checkBoxLight1, &QCheckBox::toggled, + this, &DlgSettingsLightSources::toggleLight); + connect(ui->sliderIntensity1, &QSlider::valueChanged, + this, &DlgSettingsLightSources::lightIntensity); + connect(ui->light1Color, &Gui::ColorButton::changed, + this, &DlgSettingsLightSources::lightColor); +} + +void DlgSettingsLightSources::showEvent(QShowEvent* event) +{ + Q_UNUSED(event) + if (!view) { + QGroupBox* box = ui->groupBoxLight; + QWidget* widget = createViewer(box); + auto grid = new QGridLayout(box); + grid->addWidget(widget); + box->setLayout(grid); + + loadDirection(); + } +} + +void DlgSettingsLightSources::dragMotionCallback(void *data, SoDragger *drag) +{ + auto lightdrag = static_cast(drag); // NOLINT + auto self = static_cast(data); + SbRotation rotation = lightdrag->rotation.getValue(); + SbVec3f dir(0, 0, -1); + rotation.multVec(dir, dir); + self->view->getHeadlight()->direction = dir; +} + +QWidget* DlgSettingsLightSources::createViewer(QWidget* parent) +{ + // NOLINTBEGIN + view = new Gui::View3DInventorViewer(parent); + view->setRedirectToSceneGraph(true); + view->setViewing(true); + view->setPopupMenuEnabled(false); + + view->setBackgroundColor(QColor(255, 255, 255)); + view->setGradientBackground(Gui::View3DInventorViewer::NoGradient); + view->setEnabledNaviCube(false); + + auto root = static_cast(view->getSceneGraph()); + root->addChild(createDragger()); + + view->setCameraType(SoOrthographicCamera::getClassTypeId()); + view->setViewDirection(SbVec3f(1, 1, -5)); + view->viewAll(); + // NOLINTEND + + const int size = 250; + view->resize(size, size); + + return view; +} + +SoDirectionalLightDragger* DlgSettingsLightSources::createDragger() +{ + // NOLINTBEGIN + lightDragger = new SoDirectionalLightDragger(); + if (SoDragger* translator = dynamic_cast(lightDragger->getPart("translator", false))) { + translator->setPartAsDefault("xTranslator.translatorActive", nullptr); + translator->setPartAsDefault("yTranslator.translatorActive", nullptr); + translator->setPartAsDefault("zTranslator.translatorActive", nullptr); + translator->setPartAsDefault("xTranslator.translator", nullptr); + translator->setPartAsDefault("yTranslator.translator", nullptr); + translator->setPartAsDefault("zTranslator.translator", nullptr); + SoNode* node = translator->getPart("yzTranslator.translator", false); + if (node && node->isOfType(SoGroup::getClassTypeId())) { + auto ps = new SoPickStyle(); + ps->style = SoPickStyle::UNPICKABLE; + static_cast(node)->insertChild(ps, 0); + } + } + + lightDragger->addMotionCallback(dragMotionCallback, this); + return lightDragger; + // NOLINTEND +} + +void DlgSettingsLightSources::saveSettings() +{ + ui->checkBoxLight1->onSave(); + ui->light1Color->onSave(); + ui->sliderIntensity1->onSave(); + saveDirection(); +} + +void DlgSettingsLightSources::loadSettings() +{ + ui->checkBoxLight1->onRestore(); + ui->light1Color->onRestore(); + ui->sliderIntensity1->onRestore(); +} + +void DlgSettingsLightSources::saveDirection() +{ + if (lightDragger) { + ParameterGrp::handle grp = ui->sliderIntensity1->getWindowParameter(); + SbRotation rotation = lightDragger->rotation.getValue(); + grp->SetFloat("HeadlightRotationX", rotation[0]); + grp->SetFloat("HeadlightRotationY", rotation[1]); + grp->SetFloat("HeadlightRotationZ", rotation[2]); + grp->SetFloat("HeadlightRotationW", rotation[3]); + + SbVec3f dir(0, 0, -1); + rotation.multVec(dir, dir); + + QString headlightDir = QString::fromLatin1("(%1,%2,%3)").arg(dir[0]).arg(dir[1]).arg(dir[2]); + grp->SetASCII("HeadlightDirection", headlightDir.toLatin1()); + } +} + +void DlgSettingsLightSources::loadDirection() +{ + ParameterGrp::handle grp = ui->sliderIntensity1->getWindowParameter(); + SbRotation rotation = lightDragger->rotation.getValue(); + // NOLINTBEGIN + float q1 = float(grp->GetFloat("HeadlightRotationX", rotation[0])); + float q2 = float(grp->GetFloat("HeadlightRotationY", rotation[1])); + float q3 = float(grp->GetFloat("HeadlightRotationZ", rotation[2])); + float q4 = float(grp->GetFloat("HeadlightRotationW", rotation[3])); + // NOLINTEND + rotation.setValue(q1, q2, q3, q4); + lightDragger->rotation.setValue(rotation); + + SbVec3f direction(0, 0, -1); + rotation.multVec(direction, direction); + view->getHeadlight()->direction = direction; +} + +void DlgSettingsLightSources::toggleLight(bool on) +{ + if (view) { + view->setHeadlightEnabled(on); + } +} + +void DlgSettingsLightSources::lightIntensity(int value) +{ + if (view) { + float intensity = float(value) / 100.0F; + view->getHeadlight()->intensity = intensity; + } +} + +void DlgSettingsLightSources::lightColor() +{ + if (view) { + QColor color = ui->light1Color->color(); + float red = float(color.redF()); + float green = float(color.greenF()); + float blue = float(color.blueF()); + view->getHeadlight()->color = SbColor(red, green, blue); + } +} + +void DlgSettingsLightSources::changeEvent(QEvent* event) +{ + if (event->type() == QEvent::LanguageChange) { + ui->retranslateUi(this); + } + PreferencePage::changeEvent(event); +} + + +#include "moc_DlgSettingsLightSources.cpp" diff --git a/src/Gui/PreferencePages/DlgSettingsLightSources.h b/src/Gui/PreferencePages/DlgSettingsLightSources.h new file mode 100644 index 0000000000..6b7dfc15c1 --- /dev/null +++ b/src/Gui/PreferencePages/DlgSettingsLightSources.h @@ -0,0 +1,79 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later + +/*************************************************************************** + * Copyright (c) 2023 Werner Mayer * + * * + * This file is part of FreeCAD. * + * * + * FreeCAD is free software: you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 2.1 of the * + * License, or (at your option) any later version. * + * * + * FreeCAD is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with FreeCAD. If not, see * + * . * + * * + **************************************************************************/ + + +#ifndef GUI_DIALOG_DLGSETTINGSLIGHTSOURCES_H +#define GUI_DIALOG_DLGSETTINGSLIGHTSOURCES_H + +#include +#include + +class SoDragger; +class SoDirectionalLightDragger; + +namespace Gui { +class View3DInventorViewer; +namespace Dialog { +class Ui_DlgSettingsLightSources; + +/** + * The DlgSettingsLightSources class implements a preference page to change settings + * for the light sources of a 3D view. + * @author Werner Mayer + */ +class DlgSettingsLightSources : public PreferencePage +{ + Q_OBJECT + +public: + explicit DlgSettingsLightSources(QWidget* parent = nullptr); + ~DlgSettingsLightSources() override; + + void saveSettings() override; + void loadSettings() override; + +protected: + void changeEvent(QEvent* event) override; + void showEvent(QShowEvent* event) override; + +private: + void setupConnection(); + void toggleLight(bool on); + void lightIntensity(int value); + void lightColor(); + void saveDirection(); + void loadDirection(); + QWidget* createViewer(QWidget* parent); + SoDirectionalLightDragger* createDragger(); + static void dragMotionCallback(void *data, SoDragger *drag); + +private: + std::unique_ptr ui; + View3DInventorViewer* view = nullptr; + SoDirectionalLightDragger* lightDragger = nullptr; +}; + +} // namespace Dialog +} // namespace Gui + +#endif // GUI_DIALOG_DLGSETTINGSLIGHTSOURCES_H diff --git a/src/Gui/PreferencePages/DlgSettingsLightSources.ui b/src/Gui/PreferencePages/DlgSettingsLightSources.ui new file mode 100644 index 0000000000..adbe2c86c9 --- /dev/null +++ b/src/Gui/PreferencePages/DlgSettingsLightSources.ui @@ -0,0 +1,199 @@ + + + Gui::Dialog::DlgSettingsLightSources + + + + 0 + 0 + 484 + 515 + + + + Light Sources + + + + + + Light sources + + + + + + Light source + + + true + + + EnableHeadlight + + + View + + + + + + + + 255 + 255 + 255 + + + + HeadlightColor + + + View + + + + + + + Qt::Horizontal + + + + 115 + 13 + + + + + + + + Intensity + + + + + + + 100 + + + 100 + + + Qt::Horizontal + + + QSlider::TicksBelow + + + 10 + + + HeadlightIntensity + + + View + + + + + + + + + + Lights + + + + + + + Qt::Vertical + + + + 428 + 376 + + + + + + + + + Gui::ColorButton + QPushButton +
Gui/Widgets.h
+
+ + Gui::PrefColorButton + Gui::ColorButton +
Gui/PrefWidgets.h
+
+ + Gui::PrefSlider + QSlider +
Gui/PrefWidgets.h
+
+ + Gui::PrefCheckBox + QCheckBox +
Gui/PrefWidgets.h
+
+
+ + + + checkBoxLight1 + toggled(bool) + light1Color + setEnabled(bool) + + + 73 + 53 + + + 150 + 53 + + + + + checkBoxLight1 + toggled(bool) + light1Label + setEnabled(bool) + + + 73 + 53 + + + 284 + 53 + + + + + checkBoxLight1 + toggled(bool) + sliderIntensity1 + setEnabled(bool) + + + 73 + 53 + + + 357 + 53 + + + + +
diff --git a/src/Gui/PreferencePages/DlgSettingsNavigation.cpp b/src/Gui/PreferencePages/DlgSettingsNavigation.cpp index 55ff7a0a66..9e307a8816 100644 --- a/src/Gui/PreferencePages/DlgSettingsNavigation.cpp +++ b/src/Gui/PreferencePages/DlgSettingsNavigation.cpp @@ -88,7 +88,8 @@ void DlgSettingsNavigation::saveSettings() ui->rotationCenterSize->onSave(); ui->rotationCenterColor->onSave(); ui->spinBoxZoomStep->onSave(); - ui->checkBoxUseAutoRotation->onSave(); + ui->checkBoxNavigationAnimations->onSave(); + ui->spinBoxAnimationDuration->onSave(); ui->qspinNewDocScale->onSave(); ui->prefStepByTurn->onSave(); ui->naviCubeCorner->onSave(); @@ -115,7 +116,7 @@ void DlgSettingsNavigation::saveSettings() hGrp = App::GetApplication().GetParameterGroupByPath( "User parameter:BaseApp/Preferences/NaviCube"); if (ui->naviCubeFontName->currentIndex()) { - hGrp->SetASCII("FontString", ui->naviCubeFontName->currentText().toLatin1()); + hGrp->SetASCII("FontString", ui->naviCubeFontName->currentText().toLatin1()); } else { hGrp->RemoveASCII("FontString"); } @@ -129,7 +130,8 @@ void DlgSettingsNavigation::loadSettings() ui->rotationCenterSize->onRestore(); ui->rotationCenterColor->onRestore(); ui->spinBoxZoomStep->onRestore(); - ui->checkBoxUseAutoRotation->onRestore(); + ui->checkBoxNavigationAnimations->onRestore(); + ui->spinBoxAnimationDuration->onRestore(); ui->qspinNewDocScale->onRestore(); ui->prefStepByTurn->onRestore(); ui->naviCubeCorner->onRestore(); @@ -191,7 +193,7 @@ void DlgSettingsNavigation::loadSettings() QStringList familyNames = QFontDatabase::families(QFontDatabase::Any); #endif ui->naviCubeFontName->addItems(familyNames); - + hGrp = App::GetApplication().GetParameterGroupByPath( "User parameter:BaseApp/Preferences/NaviCube"); int indexFamilyNames = familyNames.indexOf( diff --git a/src/Gui/PreferencePages/DlgSettingsNavigation.ui b/src/Gui/PreferencePages/DlgSettingsNavigation.ui index 6ccab19a45..2e7879bdd9 100644 --- a/src/Gui/PreferencePages/DlgSettingsNavigation.ui +++ b/src/Gui/PreferencePages/DlgSettingsNavigation.ui @@ -566,27 +566,91 @@ The value is the diameter of the sphere to fit on the screen. - + true - Enable animated rotations + Enable navigation animations - Enable animation + Enable navigation animations - false + true - UseAutoRotation + UseNavigationAnimations View + + + + Duration of navigation animations that have a fixed duration + + + Animation duration + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + 60 + 16777215 + + + + The duration of navigation animations in milliseconds + + + 100 + + + 10000 + + + 50 + + + 250 + + + AnimationDuration + + + View + + + + + + + Qt::Horizontal + + + QSizePolicy::MinimumExpanding + + + + 10 + 20 + + + + + + @@ -609,7 +673,7 @@ The value is the diameter of the sphere to fit on the screen. - Zoom step + Zoom step Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter diff --git a/src/Gui/Quarter/SoQTQuarterAdaptor.cpp b/src/Gui/Quarter/SoQTQuarterAdaptor.cpp index a52feb389c..db8a3535c6 100644 --- a/src/Gui/Quarter/SoQTQuarterAdaptor.cpp +++ b/src/Gui/Quarter/SoQTQuarterAdaptor.cpp @@ -42,7 +42,8 @@ #include "SoQTQuarterAdaptor.h" - +// NOLINTBEGIN +// clang-format off static unsigned char fps2dfont[][12] = { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, // { 0, 0, 12, 12, 0, 8, 12, 12, 12, 12, 12, 0 }, // ! @@ -140,21 +141,37 @@ static unsigned char fps2dfont[][12] = { { 0, 48, 8, 8, 8, 16, 12, 16, 8, 8, 8, 48 }, // } { 0, 0, 0, 0, 0, 0, 78, 57, 0, 0, 0, 0 } // ~ }; +// clang-format on +// NOLINTEND -SIM::Coin3D::Quarter::SoQTQuarterAdaptor::SoQTQuarterAdaptor(QWidget* parent, const QtGLWidget* sharewidget, Qt::WindowFlags f) - : QuarterWidget(parent, sharewidget, f), matrixaction(SbViewportRegion(100,100)) +constexpr const int defaultSize = 100; + +// NOLINTBEGIN(readability-implicit-bool-conversion) +SIM::Coin3D::Quarter::SoQTQuarterAdaptor::SoQTQuarterAdaptor(QWidget* parent, + const QtGLWidget* sharewidget, + Qt::WindowFlags flags) + : QuarterWidget(parent, sharewidget, flags) + , matrixaction(SbViewportRegion(defaultSize, defaultSize)) { init(); } -SIM::Coin3D::Quarter::SoQTQuarterAdaptor::SoQTQuarterAdaptor(const QtGLFormat& format, QWidget* parent, const QtGLWidget* shareWidget, Qt::WindowFlags f) - : QuarterWidget(format, parent, shareWidget, f), matrixaction(SbViewportRegion(100,100)) +SIM::Coin3D::Quarter::SoQTQuarterAdaptor::SoQTQuarterAdaptor(const QtGLFormat& format, + QWidget* parent, + const QtGLWidget* shareWidget, + Qt::WindowFlags flags) + : QuarterWidget(format, parent, shareWidget, flags) + , matrixaction(SbViewportRegion(defaultSize, defaultSize)) { init(); } -SIM::Coin3D::Quarter::SoQTQuarterAdaptor::SoQTQuarterAdaptor(QtGLContext* context, QWidget* parent, const QtGLWidget* sharewidget, Qt::WindowFlags f) - : QuarterWidget(context, parent, sharewidget, f), matrixaction(SbViewportRegion(100,100)) +SIM::Coin3D::Quarter::SoQTQuarterAdaptor::SoQTQuarterAdaptor(QtGLContext* context, + QWidget* parent, + const QtGLWidget* sharewidget, + Qt::WindowFlags flags) + : QuarterWidget(context, parent, sharewidget, flags) + , matrixaction(SbViewportRegion(defaultSize, defaultSize)) { init(); } @@ -166,10 +183,11 @@ SIM::Coin3D::Quarter::SoQTQuarterAdaptor::~SoQTQuarterAdaptor() void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::init() { + // NOLINTBEGIN m_interactionnesting = 0; - m_seekdistance = 50.0f; + m_seekdistance = 50.0F; m_seekdistanceabs = false; - m_seekperiod = 2.0f; + m_seekperiod = 2.0F; m_inseekmode = false; m_storedcamera = nullptr; m_viewingflag = false; @@ -179,6 +197,7 @@ void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::init() getSoEventManager()->setNavigationState(SoEventManager::NO_NAVIGATION); resetFrameCounter(); + // NOLINTEND } @@ -198,7 +217,7 @@ QWidget* SIM::Coin3D::Quarter::SoQTQuarterAdaptor::getWidget() const { //we keep the function from SoQt as we want to introduce the QGraphicsView and then the GLWidget //is separated from the Widget used in layouts again - return const_cast(this); + return const_cast(this); // NOLINT } QWidget* SIM::Coin3D::Quarter::SoQTQuarterAdaptor::getGLWidget() const @@ -221,38 +240,39 @@ void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::setCameraType(SoType type) SbBool oldisperspective = cam ? cam->getTypeId().isDerivedFrom(perspectivetype) : false; SbBool newisperspective = type.isDerivedFrom(perspectivetype); - if (oldisperspective == newisperspective) // Same old, same old.. + // Same old, same old.. + if (oldisperspective == newisperspective) { return; - + } SoCamera* currentcam = getSoRenderManager()->getCamera(); - SoCamera* newcamera = (SoCamera*)type.createInstance(); + SoCamera* newcamera = static_cast(type.createInstance()); // NOLINT // Transfer and convert values from one camera type to the other. if(newisperspective) { - convertOrtho2Perspective((SoOrthographicCamera*)currentcam, - (SoPerspectiveCamera*)newcamera); + convertOrtho2Perspective(dynamic_cast(currentcam), + dynamic_cast(newcamera)); } else { - convertPerspective2Ortho((SoPerspectiveCamera*)currentcam, - (SoOrthographicCamera*)newcamera); + convertPerspective2Ortho(dynamic_cast(currentcam), + dynamic_cast(newcamera)); } getSoRenderManager()->setCamera(newcamera); getSoEventManager()->setCamera(newcamera); //if the superscene has a camera we need to replace it too - SoSeparator* superscene = (SoSeparator*) getSoRenderManager()->getSceneGraph(); + auto superscene = dynamic_cast(getSoRenderManager()->getSceneGraph()); SoSearchAction sa; sa.setInterest(SoSearchAction::FIRST); sa.setType(SoCamera::getClassTypeId()); sa.apply(superscene); - if(sa.getPath()) { + if (sa.getPath()) { SoNode* node = sa.getPath()->getTail(); - SoGroup* parent = (SoGroup*) sa.getPath()->getNodeFromTail(1); + SoGroup* parent = static_cast(sa.getPath()->getNodeFromTail(1)); // NOLINT - if(node && node->isOfType(SoCamera::getClassTypeId())) { + if (node && node->isOfType(SoCamera::getClassTypeId())) { parent->replaceChild(node, newcamera); } } @@ -274,7 +294,7 @@ void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::convertOrtho2Perspective(const So SbRotation camrot = in->orientation.getValue(); - float focaldist = in->height.getValue() / (2.0*tan(M_PI / 8.0)); + float focaldist = float(in->height.getValue() / (2.0*tan(M_PI / 8.0))); // NOLINT SbVec3f offset(0,0,focaldist-in->focalDistance.getValue()); @@ -284,7 +304,7 @@ void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::convertOrtho2Perspective(const So out->focalDistance.setValue(focaldist); // 45° is the default value of this field in SoPerspectiveCamera. - out->heightAngle = (float)(M_PI / 4.0); + out->heightAngle = (float)(M_PI / 4.0); // NOLINT } void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::convertPerspective2Ortho(const SoPerspectiveCamera* in, @@ -298,7 +318,7 @@ void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::convertPerspective2Ortho(const So float focaldist = in->focalDistance.getValue(); - out->height = 2.0f * focaldist * (float)tan(in->heightAngle.getValue() / 2.0); + out->height = 2.0F * focaldist * (float)tan(in->heightAngle.getValue() / 2.0); // NOLINT } SoCamera* SIM::Coin3D::Quarter::SoQTQuarterAdaptor::getCamera() const @@ -311,9 +331,8 @@ const SbViewportRegion & SIM::Coin3D::Quarter::SoQTQuarterAdaptor::getViewportRe return getSoRenderManager()->getViewportRegion(); } -void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::setViewing(SbBool enable) +void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::setViewing(bool enable) { - m_viewingflag = enable; // Turn off the selection indicators when we go back from picking @@ -321,12 +340,13 @@ void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::setViewing(SbBool enable) if (m_viewingflag) { SoGLRenderAction* action = getSoRenderManager()->getGLRenderAction(); - if (action) + if (action) { SoLocateHighlight::turnOffCurrentHighlight(action); + } } } -SbBool SIM::Coin3D::Quarter::SoQTQuarterAdaptor::isViewing() const +bool SIM::Coin3D::Quarter::SoQTQuarterAdaptor::isViewing() const { return m_viewingflag; } @@ -336,14 +356,14 @@ void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::interactiveCountInc() // Catch problems with missing interactiveCountDec() calls. assert(m_interactionnesting < 100); - if(++m_interactionnesting == 1) { + if (++m_interactionnesting == 1) { m_interactionStartCallback.invokeCallbacks(this); } } void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::interactiveCountDec() { - if(--m_interactionnesting <= 0) { + if (--m_interactionnesting <= 0) { m_interactionEndCallback.invokeCallbacks(this); m_interactionnesting = 0; } @@ -354,26 +374,27 @@ int SIM::Coin3D::Quarter::SoQTQuarterAdaptor::getInteractiveCount() const return m_interactionnesting; } +// clang-format off void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::addStartCallback(SIM::Coin3D::Quarter::SoQTQuarterAdaptorCB* func, void* data) { - m_interactionStartCallback.addCallback((SoCallbackListCB*)func, data); + m_interactionStartCallback.addCallback((SoCallbackListCB*)func, data); // NOLINT } void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::removeStartCallback(SIM::Coin3D::Quarter::SoQTQuarterAdaptorCB* func, void* data) { - m_interactionStartCallback.removeCallback((SoCallbackListCB*)func, data); + m_interactionStartCallback.removeCallback((SoCallbackListCB*)func, data); // NOLINT } void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::addFinishCallback(SIM::Coin3D::Quarter::SoQTQuarterAdaptorCB* func, void* data) { - m_interactionEndCallback.addCallback((SoCallbackListCB*)func, data); + m_interactionEndCallback.addCallback((SoCallbackListCB*)func, data); // NOLINT } void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::removeFinishCallback(SIM::Coin3D::Quarter::SoQTQuarterAdaptorCB* func, void* data) { - m_interactionEndCallback.removeCallback((SoCallbackListCB*)func, data); + m_interactionEndCallback.removeCallback((SoCallbackListCB*)func, data); // NOLINT } - +// clang-format on float SIM::Coin3D::Quarter::SoQTQuarterAdaptor::getSeekDistance() const { @@ -385,14 +406,14 @@ float SIM::Coin3D::Quarter::SoQTQuarterAdaptor::getSeekTime() const return m_seekperiod; } -SbBool SIM::Coin3D::Quarter::SoQTQuarterAdaptor::isSeekMode() const +bool SIM::Coin3D::Quarter::SoQTQuarterAdaptor::isSeekMode() const { return m_inseekmode; } -SbBool SIM::Coin3D::Quarter::SoQTQuarterAdaptor::isSeekValuePercentage() const +bool SIM::Coin3D::Quarter::SoQTQuarterAdaptor::isSeekValuePercentage() const { - return m_seekdistanceabs ? false : true; + return !m_seekdistanceabs; } void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::setPickRadius(float pickRadius) @@ -400,14 +421,14 @@ void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::setPickRadius(float pickRadius) this->pickRadius = pickRadius; SoEventManager* evm = this->getSoEventManager(); if (evm){ - SoHandleEventAction* a = evm->getHandleEventAction(); - if (a){ - a->setPickRadius(pickRadius); + SoHandleEventAction* hea = evm->getHandleEventAction(); + if (hea){ + hea->setPickRadius(pickRadius); } } } -SbBool SIM::Coin3D::Quarter::SoQTQuarterAdaptor::seekToPoint(const SbVec2s screenpos) +bool SIM::Coin3D::Quarter::SoQTQuarterAdaptor::seekToPoint(const SbVec2s& screenpos) { SoRayPickAction rpaction(getSoRenderManager()->getViewportRegion()); @@ -417,7 +438,7 @@ SbBool SIM::Coin3D::Quarter::SoQTQuarterAdaptor::seekToPoint(const SbVec2s scree SoPickedPoint* picked = rpaction.getPickedPoint(); - if(!picked) { + if (!picked) { this->interactiveCountInc(); // decremented in setSeekMode(false) this->setSeekMode(false); return false; @@ -439,7 +460,8 @@ void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::seekToPoint(const SbVec3f& scenep // move point to the camera coordinate system, consider // transformations before camera in the scene graph - SbMatrix cameramatrix, camerainverse; + SbMatrix cameramatrix; + SbMatrix camerainverse; getCameraCoordinateSystem(getSoRenderManager()->getCamera(), getSceneGraph(), cameramatrix, @@ -448,8 +470,9 @@ void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::seekToPoint(const SbVec3f& scenep float fd = m_seekdistance; - if(!m_seekdistanceabs) - fd *= (hitpoint - getSoRenderManager()->getCamera()->position.getValue()).length()/100.0f; + if(!m_seekdistanceabs) { + fd *= (hitpoint - getSoRenderManager()->getCamera()->position.getValue()).length()/100.0F; + } getSoRenderManager()->getCamera()->focalDistance = fd; @@ -479,7 +502,7 @@ void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::setSeekDistance(const float dista m_seekdistance = distance; } -void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::setSeekMode(SbBool enable) +void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::setSeekMode(bool enable) { if(!enable && m_seeksensor->isScheduled()) { m_seeksensor->unschedule(); @@ -494,12 +517,15 @@ void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::setSeekTime(const float seconds) m_seekperiod = seconds; } -void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::setSeekValueAsPercentage(const SbBool on) +void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::setSeekValueAsPercentage(bool on) { - m_seekdistanceabs = on ? false : true; + m_seekdistanceabs = !on; } -void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::getCameraCoordinateSystem(SoCamera* camera, SoNode* root, SbMatrix& matrix, SbMatrix& inverse) +void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::getCameraCoordinateSystem(SoCamera* camera, + SoNode* root, + SbMatrix& matrix, + SbMatrix& inverse) { searchaction.reset(); searchaction.setSearchingAll(true); @@ -518,30 +544,33 @@ void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::getCameraCoordinateSystem(SoCamer searchaction.reset(); } -void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::seeksensorCB(void* data, SoSensor* s) +void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::seeksensorCB(void* data, SoSensor* sensor) { - SoQTQuarterAdaptor* thisp = (SoQTQuarterAdaptor*) data; + SoQTQuarterAdaptor* thisp = static_cast(data); // NOLINT SbTime currenttime = SbTime::getTimeOfDay(); - SoTimerSensor* sensor = (SoTimerSensor*)s; + SoTimerSensor* timer = static_cast(sensor); // NOLINT - float t = - float((currenttime - sensor->getBaseTime()).getValue()) / thisp->m_seekperiod; + float par = float((currenttime - timer->getBaseTime()).getValue()) / thisp->m_seekperiod; - if((t > 1.0f) || (t + sensor->getInterval().getValue() > 1.0f)) t = 1.0f; + if ((par > 1.0F) || (par + timer->getInterval().getValue() > 1.0F)) { + par = 1.0F; + } - SbBool end = (t == 1.0f); + bool end = (par == 1.0F); - t = (float)((1.0 - cos(M_PI*t)) * 0.5); + par = (float)((1.0 - cos(M_PI * par)) * 0.5); // NOLINT thisp->getSoRenderManager()->getCamera()->position = thisp->m_camerastartposition + - (thisp->m_cameraendposition - thisp->m_camerastartposition) * t; + (thisp->m_cameraendposition - thisp->m_camerastartposition) * par; thisp->getSoRenderManager()->getCamera()->orientation = SbRotation::slerp(thisp->m_camerastartorient, thisp->m_cameraendorient, - t); + par); - if(end) thisp->setSeekMode(false); + if (end) { + thisp->setSeekMode(false); + } } void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::saveHomePosition() @@ -551,15 +580,15 @@ void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::saveHomePosition() return; } - SoType t = cam->getTypeId(); - assert(t.isDerivedFrom(SoNode::getClassTypeId())); - assert(t.canCreateInstance()); + SoType type = cam->getTypeId(); + assert(type.isDerivedFrom(SoNode::getClassTypeId())); + assert(type.canCreateInstance()); if(m_storedcamera) { m_storedcamera->unref(); } - m_storedcamera = (SoNode*)t.createInstance(); + m_storedcamera = static_cast(type.createInstance()); // NOLINT m_storedcamera->ref(); m_storedcamera->copyFieldValues(getSoRenderManager()->getCamera()); @@ -576,27 +605,27 @@ void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::resetToHomePosition() return; } - SoType t = getSoRenderManager()->getCamera()->getTypeId(); - SoType s = m_storedcamera->getTypeId(); + SoType ttype = getSoRenderManager()->getCamera()->getTypeId(); + SoType stype = m_storedcamera->getTypeId(); // most common case - if(t == s) { + if (ttype == stype) { // We copy the field data directly, instead of using // SoFieldContainer::copyContents(), for the reason described in // detail in So@Gui@Viewer::saveHomePosition(). getSoRenderManager()->getCamera()->copyFieldValues(m_storedcamera); } // handle common case #1 - else if(t == SoOrthographicCamera::getClassTypeId() && - s == SoPerspectiveCamera::getClassTypeId()) { - convertPerspective2Ortho((SoPerspectiveCamera*)m_storedcamera, - (SoOrthographicCamera*)getSoRenderManager()->getCamera()); + else if(ttype == SoOrthographicCamera::getClassTypeId() && + stype == SoPerspectiveCamera::getClassTypeId()) { + convertPerspective2Ortho(dynamic_cast(m_storedcamera), + dynamic_cast(getSoRenderManager()->getCamera())); } // handle common case #2 - else if(t == SoPerspectiveCamera::getClassTypeId() && - s == SoOrthographicCamera::getClassTypeId()) { - convertOrtho2Perspective((SoOrthographicCamera*)m_storedcamera, - (SoPerspectiveCamera*)getSoRenderManager()->getCamera()); + else if(ttype == SoPerspectiveCamera::getClassTypeId() && + stype == SoOrthographicCamera::getClassTypeId()) { + convertOrtho2Perspective(dynamic_cast(m_storedcamera), + dynamic_cast(getSoRenderManager()->getCamera())); } // otherwise, cameras have changed in ways we don't understand since @@ -606,7 +635,9 @@ void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::resetToHomePosition() void -SIM::Coin3D::Quarter::SoQTQuarterAdaptor::draw2DString(const char* str, SbVec2s glsize, SbVec2f position) +SIM::Coin3D::Quarter::SoQTQuarterAdaptor::draw2DString(const char* str, + SbVec2s glsize, + SbVec2f position) { // Store GL state. glPushAttrib(GL_ENABLE_BIT|GL_CURRENT_BIT); @@ -651,17 +682,19 @@ SIM::Coin3D::Quarter::SoQTQuarterAdaptor::draw2DString(const char* str, SbVec2s glPopAttrib(); } -void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::printString(const char* s) +void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::printString(const char* str) { - int i,n; - n = strlen(s); + // NOLINTBEGIN + std::size_t len = strlen(str); - for(i = 0; i < n; i++) - glBitmap(8, 12, 0.0, 2.0, 10.0, 0.0, fps2dfont[s[i] - 32]); + for(std::size_t i = 0; i < len; i++) { + glBitmap(8, 12, 0.0, 2.0, 10.0, 0.0, fps2dfont[str[i] - 32]); + } + // NOLINTEND } -void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::moveCameraScreen(const SbVec2f& screenpos) { - +void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::moveCameraScreen(const SbVec2f& screenpos) +{ SoCamera* cam = getSoRenderManager()->getCamera(); assert(cam); @@ -669,11 +702,12 @@ void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::moveCameraScreen(const SbVec2f& s SbViewVolume vv = cam->getViewVolume(getGLWidget()->width() / getGLWidget()->height()); SbPlane panplane = vv.getPlane(cam->focalDistance.getValue()); + constexpr const float mid = 0.5F; SbLine line; - vv.projectPointToLine(screenpos + SbVec2f(0.5, 0.5f), line); + vv.projectPointToLine(screenpos + SbVec2f(mid, mid), line); SbVec3f current_planept; panplane.intersect(line, current_planept); - vv.projectPointToLine(SbVec2f(0.5f, 0.5f), line); + vv.projectPointToLine(SbVec2f(mid, mid), line); SbVec3f old_planept; panplane.intersect(line, old_planept); @@ -682,30 +716,31 @@ void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::moveCameraScreen(const SbVec2f& s cam->position = cam->position.getValue() - (current_planept - old_planept); } -bool SIM::Coin3D::Quarter::SoQTQuarterAdaptor::processSoEvent(const SoEvent* event) { - +bool SIM::Coin3D::Quarter::SoQTQuarterAdaptor::processSoEvent(const SoEvent* event) +{ const SoType type(event->getTypeId()); + constexpr const float delta = 0.1F; if(type.isDerivedFrom(SoKeyboardEvent::getClassTypeId())) { - const SoKeyboardEvent* keyevent = static_cast(event); + const SoKeyboardEvent* keyevent = static_cast(event); // NOLINT if(keyevent->getState() == SoButtonEvent::DOWN) { switch(keyevent->getKey()) { case SoKeyboardEvent::LEFT_ARROW: - moveCameraScreen(SbVec2f(-0.1f, 0.0f)); + moveCameraScreen(SbVec2f(-delta, 0.0F)); return true; case SoKeyboardEvent::UP_ARROW: - moveCameraScreen(SbVec2f(0.0f, 0.1f)); + moveCameraScreen(SbVec2f(0.0F, delta)); return true; case SoKeyboardEvent::RIGHT_ARROW: - moveCameraScreen(SbVec2f(0.1f, 0.0f)); + moveCameraScreen(SbVec2f(delta, 0.0F)); return true; case SoKeyboardEvent::DOWN_ARROW: - moveCameraScreen(SbVec2f(0.0f, -0.1f)); + moveCameraScreen(SbVec2f(0.0F, -delta)); return true; default: @@ -730,31 +765,35 @@ void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::paintEvent(QPaintEvent* event) void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::resetFrameCounter() { this->framecount = 0; - this->frametime = 0.0f; - this->drawtime = 0.0f; + this->frametime = 0.0F; + this->drawtime = 0.0F; this->starttime = SbTime::getTimeOfDay().getValue(); this->framesPerSecond = SbVec2f(0, 0); } SbVec2f SIM::Coin3D::Quarter::SoQTQuarterAdaptor::addFrametime(double starttime) { + constexpr const double FPS_FACTOR = 0.7; + constexpr const double FIVE_SECS = 5000.0; + constexpr const float ONE_SEC = 1000.0F; + this->framecount++; double timeofday = SbTime::getTimeOfDay().getValue(); // draw time is the actual time spent on rendering double drawtime = timeofday - starttime; -#define FPS_FACTOR 0.7 - this->drawtime = (drawtime*FPS_FACTOR) + this->drawtime*(1.0-FPS_FACTOR); + this->drawtime = (drawtime*FPS_FACTOR) + this->drawtime*(1.0 - FPS_FACTOR); // frame time is the time spent since the last frame. There could an // indefinite pause between the last frame because the scene is not // changing. So we limit the skew to 5 second. - double frametime = std::min(timeofday-this->starttime, std::max(drawtime,5000.0)); - this->frametime = (frametime*FPS_FACTOR) + this->frametime*(1.0-FPS_FACTOR); + double frametime = std::min(timeofday-this->starttime, std::max(drawtime, FIVE_SECS)); + this->frametime = (frametime*FPS_FACTOR) + this->frametime*(1.0 - FPS_FACTOR); this->starttime = timeofday; - return {1000 * float(this->drawtime), 1.0F / float(this->frametime)}; + return {ONE_SEC * float(this->drawtime), 1.0F / float(this->frametime)}; } +// NOLINTEND(readability-implicit-bool-conversion) #include "moc_SoQTQuarterAdaptor.cpp" diff --git a/src/Gui/Quarter/SoQTQuarterAdaptor.h b/src/Gui/Quarter/SoQTQuarterAdaptor.h index f9f46a25ee..5bd96da736 100644 --- a/src/Gui/Quarter/SoQTQuarterAdaptor.h +++ b/src/Gui/Quarter/SoQTQuarterAdaptor.h @@ -47,9 +47,17 @@ class QUARTER_DLL_API SoQTQuarterAdaptor : public QuarterWidget { Q_OBJECT public: - explicit SoQTQuarterAdaptor(QWidget* parent = nullptr, const QtGLWidget* sharewidget = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); - explicit SoQTQuarterAdaptor(const QtGLFormat& format, QWidget* parent = nullptr, const QtGLWidget* shareWidget = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); - explicit SoQTQuarterAdaptor(QtGLContext* context, QWidget* parent = nullptr, const QtGLWidget* sharewidget = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); + explicit SoQTQuarterAdaptor(QWidget* parent = nullptr, + const QtGLWidget* sharewidget = nullptr, + Qt::WindowFlags flags = Qt::WindowFlags()); + explicit SoQTQuarterAdaptor(const QtGLFormat& format, + QWidget* parent = nullptr, + const QtGLWidget* shareWidget = nullptr, + Qt::WindowFlags flags = Qt::WindowFlags()); + explicit SoQTQuarterAdaptor(QtGLContext* context, + QWidget* parent = nullptr, + const QtGLWidget* sharewidget = nullptr, + Qt::WindowFlags flags = Qt::WindowFlags()); ~SoQTQuarterAdaptor() override; //the functions available in soqtviewer but missing in quarter @@ -63,8 +71,8 @@ public: const SbViewportRegion & getViewportRegion() const; - virtual void setViewing(SbBool enable); - SbBool isViewing() const; + virtual void setViewing(bool enable); + bool isViewing() const; void interactiveCountInc(); void interactiveCountDec(); @@ -75,72 +83,76 @@ public: void removeStartCallback(SoQTQuarterAdaptorCB* func, void* data = nullptr); void removeFinishCallback(SoQTQuarterAdaptorCB* func, void* data = nullptr); - virtual void setSeekMode(SbBool enable); - SbBool isSeekMode() const; - SbBool seekToPoint(const SbVec2s screenpos); + virtual void setSeekMode(bool enable); + bool isSeekMode() const; + bool seekToPoint(const SbVec2s& screenpos); void seekToPoint(const SbVec3f& scenepos); - void setSeekTime(const float seconds); + void setSeekTime(float seconds); float getSeekTime() const; - void setSeekDistance(const float distance); + void setSeekDistance(float distance); float getSeekDistance() const; - void setSeekValueAsPercentage(const SbBool on); - SbBool isSeekValuePercentage() const; + void setSeekValueAsPercentage(bool on); + bool isSeekValuePercentage() const; virtual float getPickRadius() const {return this->pickRadius;} virtual void setPickRadius(float pickRadius); virtual void saveHomePosition(); virtual void resetToHomePosition(); - virtual bool hasHomePosition() const {return m_storedcamera;} + virtual bool hasHomePosition() const + { + return m_storedcamera != nullptr; + } - void setSceneGraph(SoNode* root) override { + void setSceneGraph(SoNode* root) override + { QuarterWidget::setSceneGraph(root); } bool processSoEvent(const SoEvent* event) override; - void paintEvent(QPaintEvent*) override; + void paintEvent(QPaintEvent* event) override; //this functions still need to be ported virtual void afterRealizeHook() {} //enables spacenav and joystick in soqt, dunno if this is needed private: void init(); - void convertPerspective2Ortho(const SoPerspectiveCamera* in, SoOrthographicCamera* out); - void convertOrtho2Perspective(const SoOrthographicCamera* in, SoPerspectiveCamera* out); + static void convertPerspective2Ortho(const SoPerspectiveCamera* in, SoOrthographicCamera* out); + static void convertOrtho2Perspective(const SoOrthographicCamera* in, SoPerspectiveCamera* out); void getCameraCoordinateSystem(SoCamera * camera, SoNode * root, SbMatrix & matrix, SbMatrix & inverse); - static void seeksensorCB(void * data, SoSensor * s); + static void seeksensorCB(void * data, SoSensor * sensor); void moveCameraScreen(const SbVec2f & screenpos); void resetFrameCounter(); SbVec2f addFrametime(double ft); - bool m_viewingflag; - int m_interactionnesting; + bool m_viewingflag = false; + int m_interactionnesting = 0; SoCallbackList m_interactionStartCallback; SoCallbackList m_interactionEndCallback; - double frametime; - double drawtime; - double starttime; - int framecount; + double frametime = 0.0; + double drawtime = 0.0; + double starttime = 0.0; + int framecount = 0.0; // Seek functionality - SoTimerSensor* m_seeksensor; - float m_seekperiod; - SbBool m_inseekmode; + SoTimerSensor* m_seeksensor = nullptr; + float m_seekperiod = 0.0F; + bool m_inseekmode = false; SbVec3f m_camerastartposition, m_cameraendposition; SbRotation m_camerastartorient, m_cameraendorient; - float m_seekdistance; - SbBool m_seekdistanceabs; + float m_seekdistance = 0.0F; + bool m_seekdistanceabs = false; SoSearchAction searchaction; SoGetMatrixAction matrixaction; - float pickRadius; + float pickRadius = 0.0F; // Home position storage. - SoNode * m_storedcamera; - + SoNode * m_storedcamera = nullptr; + protected: - void draw2DString(const char * str, SbVec2s glsize, SbVec2f position); - void printString(const char * s); - SbVec2f framesPerSecond; + static void draw2DString(const char * str, SbVec2s glsize, SbVec2f position); + static void printString(const char * str); + SbVec2f framesPerSecond; // NOLINT }; } //Quarter diff --git a/src/Gui/TaskView/TaskImage.cpp b/src/Gui/TaskView/TaskImage.cpp index 2998517016..e0fec1ecbc 100644 --- a/src/Gui/TaskView/TaskImage.cpp +++ b/src/Gui/TaskView/TaskImage.cpp @@ -529,7 +529,7 @@ void InteractiveScale::collectPoint(const SbVec3f& pos3d) midPoint = (points[0] + points[1]) / 2; - measureLabel->startEdit(getDistance(points[1]), this); + measureLabel->startEdit(getDistance(points[1]), this, true); Q_EMIT enableApplyBtn(); } diff --git a/src/Gui/View3DInventor.cpp b/src/Gui/View3DInventor.cpp index b97de87b90..59b7ba7ae3 100644 --- a/src/Gui/View3DInventor.cpp +++ b/src/Gui/View3DInventor.cpp @@ -57,6 +57,7 @@ #include "View3DInventor.h" #include "View3DSettings.h" #include "Application.h" +#include "BitmapFactory.h" #include "Camera.h" #include "Document.h" #include "FileDialog.h" @@ -134,6 +135,8 @@ View3DInventor::View3DInventor(Gui::Document* pcDocument, QWidget* parent, stopSpinTimer = new QTimer(this); connect(stopSpinTimer, &QTimer::timeout, this, &View3DInventor::stopAnimating); + + setWindowIcon(Gui::BitmapFactory().pixmap("Document")); } View3DInventor::~View3DInventor() diff --git a/src/Gui/View3DInventorViewer.cpp b/src/Gui/View3DInventorViewer.cpp index e4921d730e..eec7834161 100644 --- a/src/Gui/View3DInventorViewer.cpp +++ b/src/Gui/View3DInventorViewer.cpp @@ -118,6 +118,9 @@ #include "ViewProvider.h" #include "ViewProviderDocumentObject.h" #include "ViewProviderLink.h" +#include "NavigationAnimator.h" +#include "NavigationAnimation.h" +#include "Utilities.h" FC_LOG_LEVEL_INIT("3DViewer",true,true) @@ -126,6 +129,8 @@ FC_LOG_LEVEL_INIT("3DViewer",true,true) using namespace Gui; +// NOLINTBEGIN +// clang-format off /*** zoom-style cursor ******/ #define ZOOM_WIDTH 16 @@ -136,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 *******/ @@ -159,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 ****/ @@ -181,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 /*! @@ -210,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; @@ -250,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; @@ -258,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); @@ -374,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); @@ -393,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(); @@ -426,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); @@ -506,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 @@ -586,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(); @@ -616,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) @@ -641,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; @@ -683,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: @@ -738,7 +769,7 @@ void View3DInventorViewer::onSelectionChanged(const SelectionChanges &_Reason) } /// @endcond -SbBool View3DInventorViewer::searchNode(SoNode* node) const +bool View3DInventorViewer::searchNode(SoNode* node) const { SoSearchAction searchAction; searchAction.setNode(node); @@ -748,12 +779,12 @@ SbBool View3DInventorViewer::searchNode(SoNode* node) const return selectionPath ? true : false; } -SbBool View3DInventorViewer::hasViewProvider(ViewProvider* pcProvider) const +bool View3DInventorViewer::hasViewProvider(ViewProvider* pcProvider) const { return _ViewProviderSet.find(pcProvider) != _ViewProviderSet.end(); } -SbBool View3DInventorViewer::containsViewProvider(const ViewProvider* vp) const +bool View3DInventorViewer::containsViewProvider(const ViewProvider* vp) const { SoSearchAction sa; sa.setNode(vp->getRoot()); @@ -780,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); @@ -794,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(); @@ -812,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( @@ -833,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); @@ -852,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); @@ -861,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 */ @@ -890,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(); @@ -911,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(); @@ -924,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()); @@ -961,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(); @@ -974,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()); @@ -1008,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); } @@ -1024,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(); @@ -1036,16 +1083,17 @@ void View3DInventorViewer::resetEditingViewProvider() } /// reset from edit mode -SbBool View3DInventorViewer::isEditingViewProvider() const +bool 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; @@ -1053,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); } } @@ -1075,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; @@ -1094,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); @@ -1124,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); @@ -1201,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 @@ -1213,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; } } @@ -1231,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 : @@ -1251,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 @@ -1265,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) { @@ -1275,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); @@ -1302,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) { @@ -1319,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); @@ -1343,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); @@ -1373,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 @@ -1407,12 +1468,12 @@ SoDirectionalLight* View3DInventorViewer::getBacklight() const return this->backlight; } -void View3DInventorViewer::setBacklight(SbBool on) +void View3DInventorViewer::setBacklightEnabled(bool on) { this->backlight->on = on; } -SbBool View3DInventorViewer::isBacklight() const +bool View3DInventorViewer::isBacklightEnabled() const { return this->backlight->on.getValue(); } @@ -1433,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) @@ -1461,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; } @@ -1477,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. @@ -1542,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(); @@ -1556,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(); @@ -1584,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); @@ -1605,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]; @@ -1616,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()); @@ -1655,16 +1732,16 @@ const std::vector& View3DInventorViewer::getPolygon(SelectionRole* role return navigation->getPolygon(role); } -void View3DInventorViewer::setSelectionEnabled(const SbBool enable) +void View3DInventorViewer::setSelectionEnabled(bool enable) { SoNode* root = getSceneGraph(); - static_cast(root)->selectionRole.setValue(enable); + static_cast(root)->selectionRole.setValue(enable); // NOLINT } -SbBool View3DInventorViewer::isSelectionEnabled() const +bool 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 @@ -1677,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. @@ -1693,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; } @@ -1707,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]}; @@ -1716,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(); @@ -1730,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); } @@ -1762,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")) { @@ -1786,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 { @@ -1800,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); } @@ -1809,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(); @@ -1819,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()); } @@ -1843,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; @@ -1857,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; @@ -1872,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; } @@ -1914,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; @@ -1936,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()); @@ -1970,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; @@ -2012,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(); @@ -2036,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); } @@ -2053,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); @@ -2078,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(); @@ -2090,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)); @@ -2155,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(); } @@ -2187,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(); @@ -2195,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(); } @@ -2228,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); @@ -2246,8 +2338,6 @@ void View3DInventorViewer::renderScene() drawSingleBackground(col); glra->apply(this->backgroundroot); - navigation->updateAnimation(); - if (!this->shading) { state->push(); SoLightModelElement::set(state, selectionRoot, SoLightModelElement::BASE_COLOR); @@ -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,14 +2398,15 @@ 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) +void View3DInventorViewer::setSeekMode(bool on) { // Overrides this method to make sure any animations are stopped // before we go into seek mode. @@ -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->isDerivedFrom()) { - 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: @@ -2444,7 +2550,7 @@ bool View3DInventorViewer::processSoEvent(const SoEvent* ev) return navigation->processEvent(ev); } -SbBool View3DInventorViewer::processSoEventBase(const SoEvent* const ev) +bool View3DInventorViewer::processSoEventBase(const SoEvent* const ev) { return inherited::processSoEvent(ev); } @@ -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,14 +2888,15 @@ 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(); } -SbBool View3DInventorViewer::pubSeekToPoint(const SbVec2s& pos) +bool View3DInventorViewer::pubSeekToPoint(const SbVec2s& pos) { return this->seekToPoint(pos); } @@ -2765,84 +2906,51 @@ void View3DInventorViewer::pubSeekToPoint(const SbVec3f& pos) this->seekToPoint(pos); } -void View3DInventorViewer::setCameraOrientation(const SbRotation& rot, SbBool moveTocenter) +void View3DInventorViewer::setCameraOrientation(const SbRotation& orientation, bool moveToCenter) { - navigation->setCameraOrientation(rot, moveTocenter); + 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 } } -namespace Gui { - class CameraAnimation : public QVariantAnimation - { - SoCamera* camera; - SbRotation startRot, endRot; - SbVec3f startPos, endPos; - - public: - CameraAnimation(SoCamera* camera, const SbRotation& rot, const SbVec3f& pos) - : camera(camera), endRot(rot), endPos(pos) - { - startPos = camera->position.getValue(); - startRot = camera->orientation.getValue(); - } - ~CameraAnimation() override = default; - protected: - void updateCurrentValue(const QVariant & value) override - { - int steps = endValue().toInt(); - int curr = value.toInt(); - - float s = static_cast(curr)/static_cast(steps); - SbVec3f curpos = startPos * (1.0f-s) + endPos * s; - SbRotation currot = SbRotation::slerp(startRot, endRot, s); - camera->orientation.setValue(currot); - camera->position.setValue(curpos); - } - }; -} - -void View3DInventorViewer::moveCameraTo(const SbRotation& rot, const SbVec3f& pos, int steps, int ms) +void View3DInventorViewer::moveCameraTo(const SbRotation& orientation, const SbVec3f& position, int duration) { - SoCamera* cam = this->getSoRenderManager()->getCamera(); - if (!cam) + SoCamera* camera = getCamera(); + if (!camera) { return; + } - CameraAnimation anim(cam, rot, pos); - anim.setDuration(Base::clamp(ms,0,5000)); - anim.setStartValue(static_cast(0)); - anim.setEndValue(steps); + if (isAnimationEnabled()) { + startAnimation( + orientation, camera->position.getValue(), position - camera->position.getValue(), duration, true); + } - QEventLoop loop; - QObject::connect(&anim, &CameraAnimation::finished, &loop, &QEventLoop::quit); - anim.start(); - loop.exec(QEventLoop::ExcludeUserInputEvents); - - cam->orientation.setValue(rot); - cam->position.setValue(pos); + camera->orientation.setValue(orientation); + camera->position.setValue(position); } 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(); @@ -2851,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; @@ -2868,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; } @@ -2887,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); } } @@ -2938,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 @@ -2957,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; } } @@ -2984,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); @@ -3000,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; } @@ -3040,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; @@ -3092,7 +3224,7 @@ void View3DInventorViewer::viewSelection() spin will be stopped. */ void -View3DInventorViewer::setAnimationEnabled(const SbBool enable) +View3DInventorViewer::setAnimationEnabled(bool enable) { navigation->setAnimationEnabled(enable); } @@ -3102,7 +3234,7 @@ View3DInventorViewer::setAnimationEnabled(const SbBool enable) releasing the left mouse button while dragging the mouse. */ -SbBool +bool View3DInventorViewer::isAnimationEnabled() const { return navigation->isAnimationEnabled(); @@ -3112,18 +3244,52 @@ View3DInventorViewer::isAnimationEnabled() const Query if the model in the viewer is currently in spinning mode after a user drag. */ -SbBool View3DInventorViewer::isAnimating() const +bool View3DInventorViewer::isAnimating() const { return navigation->isAnimating(); } -/*! - * Starts programmatically the viewer in animation mode. The given axis direction - * is always in screen coordinates, not in world coordinates. +/** + * @brief Change the camera pose with an animation + * + * @param orientation The new orientation + * @param rotationCenter The rotation center + * @param translation An additional translation on top of the translation caused by the rotation around the rotation center + * @param duration The duration in milliseconds + * @param wait When false, start the animation and continue (asynchronous). When true, start the animation and wait for the animation to finish (synchronous) */ -void View3DInventorViewer::startAnimating(const SbVec3f& axis, float velocity) +void View3DInventorViewer::startAnimation(const SbRotation& orientation, + const SbVec3f& rotationCenter, + const SbVec3f& translation, + int duration, + bool wait) { - navigation->startAnimating(axis, velocity); + // Currently starts a FixedTimeAnimation. If there is going to be an additional animation like + // FixedVelocityAnimation, check the animation type from a parameter and start the right animation + + // Duration was not set or is invalid so use the AnimationDuration parameter as default + if (duration < 0) { + duration = App::GetApplication() + .GetParameterGroupByPath("User parameter:BaseApp/Preferences/View") + ->GetInt("AnimationDuration", 250); + } + + auto animation = std::make_shared( + navigation, orientation, rotationCenter, translation, duration); + + navigation->startAnimating(animation, wait); +} + +/** + * @brief Start an infinite spin animation + * + * @param axis The rotation axis in screen coordinates + * @param velocity The angular velocity in radians per second + */ +void View3DInventorViewer::startSpinningAnimation(const SbVec3f& axis, float velocity) +{ + auto animation = std::make_shared(navigation, axis, velocity); + navigation->startAnimating(animation); } void View3DInventorViewer::stopAnimating() @@ -3131,12 +3297,12 @@ void View3DInventorViewer::stopAnimating() navigation->stopAnimating(); } -void View3DInventorViewer::setPopupMenuEnabled(const SbBool on) +void View3DInventorViewer::setPopupMenuEnabled(bool on) { navigation->setPopupMenuEnabled(on); } -SbBool View3DInventorViewer::isPopupMenuEnabled() const +bool View3DInventorViewer::isPopupMenuEnabled() const { return navigation->isPopupMenuEnabled(); } @@ -3146,7 +3312,7 @@ SbBool View3DInventorViewer::isPopupMenuEnabled() const */ void -View3DInventorViewer::setFeedbackVisibility(const SbBool enable) +View3DInventorViewer::setFeedbackVisibility(bool enable) { if (enable == this->axiscrossEnabled) { return; @@ -3163,7 +3329,7 @@ View3DInventorViewer::setFeedbackVisibility(const SbBool enable) Check if the feedback axis cross is visible. */ -SbBool +bool View3DInventorViewer::isFeedbackVisible() const { return this->axiscrossEnabled; @@ -3175,7 +3341,7 @@ View3DInventorViewer::isFeedbackVisible() const canvas. */ void -View3DInventorViewer::setFeedbackSize(const int size) +View3DInventorViewer::setFeedbackSize(int size) { if (size < 1) { return; @@ -3202,7 +3368,7 @@ View3DInventorViewer::getFeedbackSize() const Decide whether or not the mouse pointer cursor should be visible in the rendering canvas. */ -void View3DInventorViewer::setCursorEnabled(SbBool /*enable*/) +void View3DInventorViewer::setCursorEnabled(bool /*enable*/) { this->setCursorRepresentation(navigation->getViewingMode()); } @@ -3215,19 +3381,19 @@ void View3DInventorViewer::afterRealizeHook() // Documented in superclass. This method overridden from parent class // to make sure the mouse pointer cursor is updated. -void View3DInventorViewer::setViewing(SbBool enable) +void View3DInventorViewer::setViewing(bool enable) { if (this->isViewing() == 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. @@ -3249,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); @@ -3257,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); @@ -3333,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(); } } @@ -3367,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]); @@ -3398,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) @@ -3463,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(); @@ -3497,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: @@ -3541,7 +3716,7 @@ void View3DInventorViewer::setCursorRepresentation(int modearg) } } -void View3DInventorViewer::setEditing(SbBool edit) +void View3DInventorViewer::setEditing(bool edit) { this->editing = edit; this->getWidget()->setCursor(QCursor(Qt::ArrowCursor)); @@ -3579,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(); @@ -3645,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; @@ -3691,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 0f0edfb429..cb00008924 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; @@ -153,38 +153,40 @@ public: void onSelectionChanged(const SelectionChanges &Reason) override; SoDirectionalLight* getBacklight() const; - void setBacklight(SbBool on); - SbBool isBacklight() const; + void setBacklightEnabled(bool on); + bool isBacklightEnabled() const; void setSceneGraph (SoNode *root) override; - SbBool searchNode(SoNode*) const; + bool searchNode(SoNode*) const; - void setAnimationEnabled(const SbBool enable); - SbBool isAnimationEnabled() const; + void setAnimationEnabled(bool enable); + bool isAnimationEnabled() const; - void setPopupMenuEnabled(const SbBool on); - SbBool isPopupMenuEnabled() const; + void setPopupMenuEnabled(bool on); + bool isPopupMenuEnabled() const; - void startAnimating(const SbVec3f& axis, float velocity); + void startAnimation(const SbRotation& orientation, const SbVec3f& rotationCenter, + const SbVec3f& translation, int duration = -1, bool wait = false); + void startSpinningAnimation(const SbVec3f& axis, float velocity); void stopAnimating(); - SbBool isAnimating() const; + bool isAnimating() const; - void setFeedbackVisibility(const SbBool enable); - SbBool isFeedbackVisible() const; + void setFeedbackVisibility(bool enable); + bool 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(); void imageFromFramebuffer(int width, int height, int samples, const QColor& bgcolor, QImage& img); - void setViewing(SbBool enable) override; - virtual void setCursorEnabled(SbBool enable); + void setViewing(bool enable) override; + virtual void setCursorEnabled(bool enable); void addGraphicsItem(GLGraphicsItem*); void removeGraphicsItem(GLGraphicsItem*); @@ -195,11 +197,11 @@ public: /** @name Handling of view providers */ //@{ /// Checks if the view provider is a top-level object of the scene - SbBool hasViewProvider(ViewProvider*) const; + bool hasViewProvider(ViewProvider*) const; /// Checks if the view provider is part of the scene. /// In contrast to hasViewProvider() this method also checks if the view /// provider is a child of another view provider - SbBool containsViewProvider(const ViewProvider*) const; + bool containsViewProvider(const ViewProvider*) const; /// adds an ViewProvider to the view, e.g. from a feature void addViewProvider(ViewProvider*); /// remove a ViewProvider @@ -210,9 +212,9 @@ 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; + bool isEditingViewProvider() const; /// reset from edit mode void resetEditingViewProvider(); void setupEditingRoot(SoNode *node=nullptr, const Base::Matrix4D *mat=nullptr); @@ -235,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; //@} /** @@ -255,8 +257,8 @@ 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); - SbBool isSelectionEnabled() const; + void setSelectionEnabled(bool enable); + bool isSelectionEnabled() const; //@} /// Returns the screen coordinates of the origin of the path's tail object @@ -265,14 +267,14 @@ public: /** @name Edit methods */ //@{ - void setEditing(SbBool edit); - SbBool isEditing() const { return this->editing; } + void setEditing(bool edit); + bool isEditing() const { return this->editing; } void setEditingCursor (const QCursor& cursor); void setComponentCursor(const QCursor& cursor); - void setRedirectToSceneGraph(SbBool redirect) { this->redirected = redirect; } - SbBool isRedirectedToSceneGraph() const { return this->redirected; } - void setRedirectToSceneGraphEnabled(SbBool enable) { this->allowredir = enable; } - SbBool isRedirectToSceneGraphEnabled() const { return this->allowredir; } + void setRedirectToSceneGraph(bool redirect) { this->redirected = redirect; } + bool isRedirectedToSceneGraph() const { return this->redirected; } + void setRedirectToSceneGraphEnabled(bool enable) { this->allowredir = enable; } + bool isRedirectToSceneGraphEnabled() const { return this->allowredir; } //@} /** @name Pick actions */ @@ -281,7 +283,7 @@ public: bool pickPoint(const SbVec2s& pos,SbVec3f &point,SbVec3f &norm) const; SoPickedPoint* pickPoint(const SbVec2s& pos) const; const SoPickedPoint* getPickedPoint(SoEventCallback * n) const; - SbBool pubSeekToPoint(const SbVec2s& pos); + bool pubSeekToPoint(const SbVec2s& pos); void pubSeekToPoint(const SbVec3f& pos); //@} @@ -373,9 +375,9 @@ public: * \a true the reorientation is animated, otherwise its directly * set. */ - void setCameraOrientation(const SbRotation& rot, SbBool moveTocenter=false); - void setCameraType(SoType t) override; - void moveCameraTo(const SbRotation& rot, const SbVec3f& pos, int steps, int ms); + void setCameraOrientation(const SbRotation& orientation, bool moveToCenter = false); + 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. */ @@ -410,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); @@ -436,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(bool 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; - SbBool processSoEventBase(const SoEvent * const ev); - void printDimension(); + void dropEvent (QDropEvent * ev) override; + void dragEnterEvent (QDragEnterEvent * ev) override; + void dragMoveEvent(QDragMoveEvent* ev) override; + void dragLeaveEvent(QDragLeaveEvent* ev) override; + bool processSoEventBase(const SoEvent * const ev); + void printDimension() const; void selectAll(); private: @@ -463,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); @@ -504,11 +506,11 @@ private: RenderType renderType; QtGLFramebufferObject* framebuffer; QImage glImage; - SbBool shading; + bool shading; SoSwitch *dimensionRoot; // small axis cross in the corner - SbBool axiscrossEnabled; + bool axiscrossEnabled; int axiscrossSize; // big one in the middle SoShapeScale* axisCross; @@ -519,12 +521,12 @@ private: //stuff needed to draw the fps counter bool fpsEnabled; bool vboEnabled; - SbBool naviCubeEnabled; + bool naviCubeEnabled; - SbBool editing; + bool editing; QCursor editCursor, zoomCursor, panCursor, spinCursor; - SbBool redirected; - SbBool allowredir; + bool redirected; + bool allowredir; std::string overrideMode; Gui::Document* guiDocument = nullptr; diff --git a/src/Gui/View3DPy.cpp b/src/Gui/View3DPy.cpp index 92f407bbab..b15f2c1803 100644 --- a/src/Gui/View3DPy.cpp +++ b/src/Gui/View3DPy.cpp @@ -777,10 +777,10 @@ Py::Object View3DInventorPy::getCameraOrientation() Py::Object View3DInventorPy::viewPosition(const Py::Tuple& args) { - PyObject* p=nullptr; - int steps = 20; - int ms = 30; - if (!PyArg_ParseTuple(args.ptr(), "|O!ii",&Base::PlacementPy::Type,&p,&steps,&ms)) + PyObject* p = nullptr; + int steps; // Unused but kept as parameter to not break the Python interface + int duration = -1; // Duration in ms, will be replaced with User parameter:BaseApp/Preferences/View/AnimationDuration when not explicitly provided + if (!PyArg_ParseTuple(args.ptr(), "|O!ii", &Base::PlacementPy::Type, &p, &steps, &duration)) throw Py::Exception(); if (p) { @@ -791,7 +791,7 @@ Py::Object View3DInventorPy::viewPosition(const Py::Tuple& args) rot.getValue(q0,q1,q2,q3); getView3DIventorPtr()->getViewer()->moveCameraTo( SbRotation((float)q0, (float)q1, (float)q2, (float)q3), - SbVec3f((float)pos.x, (float)pos.y, (float)pos.z), steps, ms); + SbVec3f((float)pos.x, (float)pos.y, (float)pos.z), duration); } SoCamera* cam = getView3DIventorPtr()->getViewer()->getSoRenderManager()->getCamera(); @@ -810,11 +810,11 @@ Py::Object View3DInventorPy::viewPosition(const Py::Tuple& args) Py::Object View3DInventorPy::startAnimating(const Py::Tuple& args) { - float x,y,z; + float x, y, z; float velocity; - if (!PyArg_ParseTuple(args.ptr(), "ffff", &x,&y,&z,&velocity)) + if (!PyArg_ParseTuple(args.ptr(), "ffff", &x, &y, &z, &velocity)) throw Py::Exception(); - getView3DIventorPtr()->getViewer()->startAnimating(SbVec3f(x,y,z),velocity); + getView3DIventorPtr()->getViewer()->startSpinningAnimation(SbVec3f(x, y, z), velocity); return Py::None(); } diff --git a/src/Gui/View3DSettings.cpp b/src/Gui/View3DSettings.cpp index f16e5e5acb..f97b32e120 100644 --- a/src/Gui/View3DSettings.cpp +++ b/src/Gui/View3DSettings.cpp @@ -74,7 +74,7 @@ void View3DSettings::applySettings() OnChange(*hGrp,"CornerCoordSystem"); OnChange(*hGrp,"CornerCoordSystemSize"); OnChange(*hGrp,"ShowAxisCross"); - OnChange(*hGrp,"UseAutoRotation"); + OnChange(*hGrp,"UseNavigationAnimations"); OnChange(*hGrp,"Gradient"); OnChange(*hGrp,"RadialGradient"); OnChange(*hGrp,"BackgroundColor"); @@ -87,6 +87,7 @@ void View3DSettings::applySettings() OnChange(*hGrp,"UseVBO"); OnChange(*hGrp,"RenderCache"); OnChange(*hGrp,"Orthographic"); + OnChange(*hGrp,"EnableHeadlight"); OnChange(*hGrp,"HeadlightColor"); OnChange(*hGrp,"HeadlightDirection"); OnChange(*hGrp,"HeadlightIntensity"); @@ -108,7 +109,13 @@ void View3DSettings::applySettings() void View3DSettings::OnChange(ParameterGrp::SubjectType &rCaller,ParameterGrp::MessageType Reason) { const ParameterGrp& rGrp = static_cast(rCaller); - if (strcmp(Reason,"HeadlightColor") == 0) { + if (strcmp(Reason,"EnableHeadlight") == 0) { + bool enable = rGrp.GetBool("EnableHeadlight", true); + for (auto _viewer : _viewers) { + _viewer->setHeadlightEnabled(enable); + } + } + else if (strcmp(Reason,"HeadlightColor") == 0) { unsigned long headlight = rGrp.GetUnsigned("HeadlightColor",ULONG_MAX); // default color (white) float transparency; SbColor headlightColor; @@ -137,7 +144,7 @@ void View3DSettings::OnChange(ParameterGrp::SubjectType &rCaller,ParameterGrp::M } else if (strcmp(Reason,"EnableBacklight") == 0) { for (auto _viewer : _viewers) { - _viewer->setBacklight(rGrp.GetBool("EnableBacklight", false)); + _viewer->setBacklightEnabled(rGrp.GetBool("EnableBacklight", false)); } } else if (strcmp(Reason,"BacklightColor") == 0) { @@ -287,9 +294,9 @@ void View3DSettings::OnChange(ParameterGrp::SubjectType &rCaller,ParameterGrp::M _viewer->setAxisCross(rGrp.GetBool("ShowAxisCross", false)); } } - else if (strcmp(Reason,"UseAutoRotation") == 0) { + else if (strcmp(Reason,"UseNavigationAnimations") == 0) { for (auto _viewer : _viewers) { - _viewer->setAnimationEnabled(rGrp.GetBool("UseAutoRotation", false)); + _viewer->setAnimationEnabled(rGrp.GetBool("UseNavigationAnimations", true)); } } else if (strcmp(Reason,"Gradient") == 0 || strcmp(Reason,"RadialGradient") == 0) { diff --git a/src/Gui/resource.cpp b/src/Gui/resource.cpp index 3ec05feb00..a5746990a6 100644 --- a/src/Gui/resource.cpp +++ b/src/Gui/resource.cpp @@ -36,6 +36,7 @@ #include "PreferencePages/DlgSettingsEditor.h" #include "PreferencePages/DlgSettingsGeneral.h" #include "PreferencePages/DlgSettingsMacroImp.h" +#include "PreferencePages/DlgSettingsLightSources.h" #include "PreferencePages/DlgSettingsNavigation.h" #include "PreferencePages/DlgSettingsNotificationArea.h" #include "PreferencePages/DlgSettingsPythonConsole.h" @@ -58,6 +59,7 @@ using namespace Gui; using namespace Gui::Dialog; +// clang-format off /** * Registers all preference pages or widgets to create them dynamically at any later time. */ @@ -74,6 +76,7 @@ WidgetFactorySupplier::WidgetFactorySupplier() new PrefPageProducer ( QT_TRANSLATE_NOOP("QObject","General") ); new PrefPageProducer ( QT_TRANSLATE_NOOP("QObject","General") ); new PrefPageProducer ( QT_TRANSLATE_NOOP("QObject","Display") ); + new PrefPageProducer ( QT_TRANSLATE_NOOP("QObject","Display") ); new PrefPageProducer ( QT_TRANSLATE_NOOP("QObject","Display") ); new PrefPageProducer ( QT_TRANSLATE_NOOP("QObject","Display") ); new PrefPageProducer ( QT_TRANSLATE_NOOP("QObject","Display") ); @@ -122,3 +125,4 @@ WidgetFactorySupplier::WidgetFactorySupplier() new WidgetProducer; new WidgetProducer; } +// clang-format on diff --git a/src/Mod/Arch/ArchBuildingPart.py b/src/Mod/Arch/ArchBuildingPart.py index 51407a1c72..ac1661efa9 100644 --- a/src/Mod/Arch/ArchBuildingPart.py +++ b/src/Mod/Arch/ArchBuildingPart.py @@ -301,9 +301,10 @@ class CommandBuildingPart: ss += "]" FreeCAD.ActiveDocument.openTransaction(translate("Arch","Create BuildingPart")) FreeCADGui.addModule("Arch") - FreeCADGui.doCommand("obj = Arch.makeBuildingPart("+ss+")") FreeCADGui.addModule("Draft") - FreeCADGui.doCommand("obj.Placement = FreeCAD.DraftWorkingPlane.getPlacement()") + FreeCADGui.addModule("WorkingPlane") + FreeCADGui.doCommand("obj = Arch.makeBuildingPart("+ss+")") + FreeCADGui.doCommand("obj.Placement = WorkingPlane.get_working_plane().get_placement()") FreeCADGui.doCommand("Draft.autogroup(obj)") FreeCAD.ActiveDocument.commitTransaction() FreeCAD.ActiveDocument.recompute() @@ -963,30 +964,22 @@ class ViewProviderBuildingPart: FreeCADGui.Selection.clearSelection() def setWorkingPlane(self,restore=False): + vobj = self.Object.ViewObject - if hasattr(self,"Object") and hasattr(FreeCAD,"DraftWorkingPlane"): - import FreeCADGui - autoclip = False - if hasattr(self.Object.ViewObject,"AutoCutView"): - autoclip = self.Object.ViewObject.AutoCutView - if restore: - FreeCAD.DraftWorkingPlane.restore() - if autoclip: - self.Object.ViewObject.CutView = False - else: - FreeCAD.DraftWorkingPlane.save() - FreeCADGui.runCommand("Draft_SelectPlane") - if autoclip: - self.Object.ViewObject.CutView = True - if hasattr(FreeCADGui,"Snapper"): - FreeCADGui.Snapper.setGrid() - if hasattr(FreeCADGui,"draftToolBar"): - if restore and hasattr(self,"wptext"): - FreeCADGui.draftToolBar.wplabel.setText(self.wptext) - else: - self.wptext = FreeCADGui.draftToolBar.wplabel.text() - FreeCADGui.draftToolBar.wplabel.setText(self.Object.Label) - FreeCAD.DraftWorkingPlane.lastBuildingPart = self.Object.Name + import WorkingPlane + wp = WorkingPlane.get_working_plane(update=False) + autoclip = False + if hasattr(vobj,"AutoCutView"): + autoclip = vobj.AutoCutView + if restore: + if wp.label.rstrip("*") == self.Object.Label: + wp._previous() + if autoclip: + vobj.CutView = False + else: + wp.align_to_selection() + if autoclip: + vobj.CutView = True def writeCamera(self): diff --git a/src/Mod/Arch/ArchCurtainWall.py b/src/Mod/Arch/ArchCurtainWall.py index 272a946732..64ce7ea311 100644 --- a/src/Mod/Arch/ArchCurtainWall.py +++ b/src/Mod/Arch/ArchCurtainWall.py @@ -124,8 +124,8 @@ class CommandArchCurtainWall: else: # interactive line drawing self.points = [] - if hasattr(FreeCAD,"DraftWorkingPlane"): - FreeCAD.DraftWorkingPlane.setup() + import WorkingPlane + WorkingPlane.get_working_plane() if hasattr(FreeCADGui,"Snapper"): FreeCADGui.Snapper.getPoint(callback=self.getPoint) diff --git a/src/Mod/Arch/ArchCutPlane.py b/src/Mod/Arch/ArchCutPlane.py index 3aa5e1ce08..796739e360 100644 --- a/src/Mod/Arch/ArchCutPlane.py +++ b/src/Mod/Arch/ArchCutPlane.py @@ -46,8 +46,9 @@ __url__ = "http://www.freecad.org" def getPlanWithLine(line): """Function to make a plane along Normal plan""" import Part - plan = FreeCAD.DraftWorkingPlane - w = plan.getNormal() + import WorkingPlane + plan = WorkingPlane.get_working_plane() + w = plan.axis part = Part.Shape(line) out = part.extrude(w) return out diff --git a/src/Mod/Arch/ArchNesting.py b/src/Mod/Arch/ArchNesting.py index fe9dc0296c..f6533b0506 100644 --- a/src/Mod/Arch/ArchNesting.py +++ b/src/Mod/Arch/ArchNesting.py @@ -583,8 +583,8 @@ class Nester: # flatten the polygon on the XY plane - wp = WorkingPlane.plane() - wp.alignToPointAndAxis(face.CenterOfMass,face.normalAt(0,0)) + wp = WorkingPlane.PlaneBase() + wp.align_to_point_and_axis(face.CenterOfMass,face.normalAt(0,0)) pverts = [] for v in verts: vx = DraftVecUtils.project(v,wp.u) diff --git a/src/Mod/Arch/ArchPanel.py b/src/Mod/Arch/ArchPanel.py index ed5a5a6450..20fb4f4083 100644 --- a/src/Mod/Arch/ArchPanel.py +++ b/src/Mod/Arch/ArchPanel.py @@ -165,9 +165,9 @@ class CommandPanel: return # interactive mode - if hasattr(FreeCAD,"DraftWorkingPlane"): - FreeCAD.DraftWorkingPlane.setup() - + import WorkingPlane + WorkingPlane.get_working_plane() + self.points = [] self.tracker = DraftTrackers.boxTracker() self.tracker.width(self.Width) @@ -434,8 +434,6 @@ class _Panel(ArchComponent.Component): if self.clone(obj): return - import Part #, DraftGeomUtils - layers = [] length = 0 width = 0 diff --git a/src/Mod/Arch/ArchSectionPlane.py b/src/Mod/Arch/ArchSectionPlane.py index c2c340eaef..281c525425 100644 --- a/src/Mod/Arch/ArchSectionPlane.py +++ b/src/Mod/Arch/ArchSectionPlane.py @@ -74,7 +74,8 @@ def makeSectionPlane(objectslist=None,name=None): for o in Draft.get_group_contents(objectslist): if hasattr(o,"Shape") and hasattr(o.Shape,"BoundBox"): bb.add(o.Shape.BoundBox) - obj.Placement = FreeCAD.DraftWorkingPlane.getPlacement() + import WorkingPlane + obj.Placement = WorkingPlane.get_working_plane().get_placement() obj.Placement.Base = bb.Center if FreeCAD.GuiUp: margin = bb.XLength*0.1 @@ -391,13 +392,13 @@ def getSVG(source, svgcache = '' # render using the Arch Vector Renderer import ArchVRM, WorkingPlane - wp = WorkingPlane.plane() + wp = WorkingPlane.PlaneBase() pl = FreeCAD.Placement(source.Placement) if source.ViewObject and hasattr(source.ViewObject,"CutMargin"): mv = pl.multVec(FreeCAD.Vector(0,0,1)) mv.multiply(source.ViewObject.CutMargin) pl.move(mv) - wp.setFromPlacement(pl) + wp.align_to_placement(pl) #wp.inverse() render = ArchVRM.Renderer() render.setWorkingPlane(wp) @@ -748,9 +749,9 @@ def getCoinSVG(cutplane,objs,cameradata=None,linewidth=0.2,singleface=False,face factor = None trans = None import WorkingPlane - wp = WorkingPlane.plane() - wp.alignToPointAndAxis_SVG(Vector(0,0,0),cutplane.normalAt(0,0),0) - p = wp.getLocalCoords(markervec) + wp = WorkingPlane.PlaneBase() + wp.align_to_point_and_axis_svg(Vector(0,0,0),cutplane.normalAt(0,0),0) + p = wp.get_local_coords(markervec) orlength = FreeCAD.Vector(p.x,p.y,0).Length marker = re.findall("",svg) if marker: @@ -763,7 +764,7 @@ def getCoinSVG(cutplane,objs,cameradata=None,linewidth=0.2,singleface=False,face p2 = FreeCAD.Vector(x2,y2,0) factor = orlength/p2.sub(p1).Length if factor: - orig = wp.getLocalCoords(FreeCAD.Vector(boundbox.XMin,boundbox.YMin,boundbox.ZMin)) + orig = wp.get_local_coords(FreeCAD.Vector(boundbox.XMin,boundbox.YMin,boundbox.ZMin)) orig = FreeCAD.Vector(orig.x,-orig.y,0) scaledp1 = FreeCAD.Vector(p1.x*factor,p1.y*factor,0) trans = orig.sub(scaledp1) diff --git a/src/Mod/Arch/ArchStructure.py b/src/Mod/Arch/ArchStructure.py index b575889aa4..41981f26df 100644 --- a/src/Mod/Arch/ArchStructure.py +++ b/src/Mod/Arch/ArchStructure.py @@ -170,9 +170,8 @@ def placeAlongEdge(p1,p2,horizontal=False): pl = FreeCAD.Placement() pl.Base = p1 - up = FreeCAD.Vector(0,0,1) - if hasattr(FreeCAD,"DraftWorkingPlane"): - up = FreeCAD.DraftWorkingPlane.axis + import WorkingPlane + up = WorkingPlane.get_working_plane(update=False).axis zaxis = p2.sub(p1) yaxis = up.cross(zaxis) if yaxis.Length > 0: @@ -290,6 +289,7 @@ class _CommandStructure: self.bpoint = None self.bmode = False self.precastvalues = None + self.wp = None sel = FreeCADGui.Selection.getSelection() if sel: st = Draft.getObjectsOfType(sel,"Structure") @@ -309,15 +309,15 @@ class _CommandStructure: return # interactive mode - if hasattr(FreeCAD,"DraftWorkingPlane"): - FreeCAD.DraftWorkingPlane.setup() + import WorkingPlane + self.wp = WorkingPlane.get_working_plane() self.points = [] self.tracker = DraftTrackers.boxTracker() self.tracker.width(self.Width) self.tracker.height(self.Height) self.tracker.length(self.Length) - self.tracker.setRotation(FreeCAD.DraftWorkingPlane.getRotation().Rotation) + self.tracker.setRotation(self.wp.get_placement().Rotation) self.tracker.on() self.precast = ArchPrecast._PrecastTaskPanel() self.dents = ArchPrecast._DentsTaskPanel() @@ -344,6 +344,7 @@ class _CommandStructure: horiz = True # determines the type of rotation to apply to the final object FreeCAD.ActiveDocument.openTransaction(translate("Arch","Create Structure")) FreeCADGui.addModule("Arch") + FreeCADGui.addModule("WorkingPlane") if self.Profile is not None: try: # try to update latest precast values - fails if dialog has been destroyed already self.precastvalues = self.precast.getValues() @@ -361,8 +362,7 @@ class _CommandStructure: delta = FreeCAD.Vector(0,0-self.Width/2,0) else: delta = FreeCAD.Vector(-self.Length/2,-self.Width/2,0) - if hasattr(FreeCAD,"DraftWorkingPlane"): - delta = FreeCAD.DraftWorkingPlane.getRotation().multVec(delta) + delta = self.wp.get_global_coords(delta,as_vector=True) point = point.add(delta) if self.bpoint: self.bpoint = self.bpoint.add(delta) @@ -396,7 +396,8 @@ class _CommandStructure: FreeCADGui.doCommand('s.Placement = Arch.placeAlongEdge('+DraftVecUtils.toString(self.bpoint)+","+DraftVecUtils.toString(point)+","+str(horiz)+")") else: FreeCADGui.doCommand('s.Placement.Base = '+DraftVecUtils.toString(point)) - FreeCADGui.doCommand('s.Placement.Rotation = s.Placement.Rotation.multiply(FreeCAD.DraftWorkingPlane.getRotation().Rotation)') + FreeCADGui.doCommand('wp = WorkingPlane.get_working_plane()') + FreeCADGui.doCommand('s.Placement.Rotation = s.Placement.Rotation.multiply(wp.get_placement().Rotation)') FreeCADGui.addModule("Draft") FreeCADGui.doCommand("Draft.autogroup(s)") @@ -543,16 +544,14 @@ class _CommandStructure: delta = Vector(0,0,self.Height/2) else: delta = Vector(self.Length/2,0,0) - if hasattr(FreeCAD,"DraftWorkingPlane"): - delta = FreeCAD.DraftWorkingPlane.getRotation().multVec(delta) + delta = self.wp.get_global_coords(delta,as_vector=True) if self.modec.isChecked(): self.tracker.pos(point.add(delta)) self.tracker.on() else: if self.bpoint: delta = Vector(0,0,-self.Height/2) - if hasattr(FreeCAD,"DraftWorkingPlane"): - delta = FreeCAD.DraftWorkingPlane.getRotation().multVec(delta) + delta = self.wp.get_global_coords(delta,as_vector=True) self.tracker.update([self.bpoint.add(delta),point.add(delta)]) self.tracker.on() l = (point.sub(self.bpoint)).Length diff --git a/src/Mod/Arch/ArchTruss.py b/src/Mod/Arch/ArchTruss.py index 0205a2213e..c72bf501fa 100644 --- a/src/Mod/Arch/ArchTruss.py +++ b/src/Mod/Arch/ArchTruss.py @@ -105,8 +105,8 @@ class CommandArchTruss: else: # interactive line drawing self.points = [] - if hasattr(FreeCAD,"DraftWorkingPlane"): - FreeCAD.DraftWorkingPlane.setup() + import WorkingPlane + WorkingPlane.get_working_plane() if hasattr(FreeCADGui,"Snapper"): FreeCADGui.Snapper.getPoint(callback=self.getPoint) diff --git a/src/Mod/Arch/ArchVRM.py b/src/Mod/Arch/ArchVRM.py index b8fd376081..0cfb5a933d 100644 --- a/src/Mod/Arch/ArchVRM.py +++ b/src/Mod/Arch/ArchVRM.py @@ -65,7 +65,7 @@ class Renderer: self.wp = wp else: import WorkingPlane - self.wp = WorkingPlane.plane() + self.wp = WorkingPlane.PlaneBase() if DEBUG: print("Renderer initialized on " + str(self.wp)) @@ -92,7 +92,7 @@ class Renderer: def setWorkingPlane(self,wp): "sets a Draft WorkingPlane or Placement for this renderer" if isinstance(wp,FreeCAD.Placement): - self.wp.setFromPlacement(wp) + self.wp.align_to_placement(wp) else: self.wp = wp if DEBUG: print("Renderer set on " + str(self.wp)) @@ -198,7 +198,7 @@ class Renderer: for e in edges: v = e.Vertexes[0].Point #print(v) - v = self.wp.getLocalCoords(v) + v = self.wp.get_local_coords(v) verts.append(v) verts.append(verts[0]) if len(verts) > 2: @@ -211,7 +211,7 @@ class Renderer: return None else: # restoring flipped normals - vnorm = self.wp.getLocalCoords(norm) + vnorm = self.wp.get_local_coords(norm) if vnorm.getAngle(sh.normalAt(0,0)) > 1: sh.reverse() #print("VRM: projectFace end: ",len(sh.Vertexes)," verts") @@ -220,8 +220,8 @@ class Renderer: def projectEdge(self,edge): "projects a single edge on the WP" if len(edge.Vertexes) > 1: - v1 = self.wp.getLocalCoords(edge.Vertexes[0].Point) - v2 = self.wp.getLocalCoords(edge.Vertexes[-1].Point) + v1 = self.wp.get_local_coords(edge.Vertexes[0].Point) + v2 = self.wp.get_local_coords(edge.Vertexes[-1].Point) return Part.LineSegment(v1,v2).toShape() return edge @@ -293,7 +293,7 @@ class Renderer: # http://paulbourke.net/geometry/insidepoly/ count = 0 - p = self.wp.getLocalCoords(vert.Point) + p = self.wp.get_local_coords(vert.Point) for e in face[0].Edges: p1 = e.Vertexes[0].Point p2 = e.Vertexes[-1].Point diff --git a/src/Mod/Arch/ArchWall.py b/src/Mod/Arch/ArchWall.py index 17a41a8c22..e78c73ec2e 100644 --- a/src/Mod/Arch/ArchWall.py +++ b/src/Mod/Arch/ArchWall.py @@ -316,6 +316,7 @@ class _CommandWall: sel = FreeCADGui.Selection.getSelectionEx() done = False self.existing = [] + self.wp = None if sel: # automatic mode @@ -345,9 +346,9 @@ class _CommandWall: # interactive mode self.points = [] + import WorkingPlane + self.wp = WorkingPlane.get_working_plane() self.tracker = DraftTrackers.boxTracker() - if hasattr(FreeCAD,"DraftWorkingPlane"): - FreeCAD.DraftWorkingPlane.setup() FreeCADGui.Snapper.getPoint(callback=self.getPoint, extradlg=self.taskbox(), title=translate("Arch","First point of wall")+":") @@ -386,8 +387,8 @@ class _CommandWall: elif len(self.points) == 2: import Part - l = Part.LineSegment(FreeCAD.DraftWorkingPlane.getLocalCoords(self.points[0]), - FreeCAD.DraftWorkingPlane.getLocalCoords(self.points[1])) + l = Part.LineSegment(self.wp.get_local_coords(self.points[0]), + self.wp.get_local_coords(self.points[1])) self.tracker.finalize() FreeCAD.ActiveDocument.openTransaction(translate("Arch","Create Wall")) FreeCADGui.addModule("Arch") @@ -431,6 +432,8 @@ class _CommandWall: """ FreeCADGui.addModule("Draft") + FreeCADGui.addModule("WorkingPlane") + FreeCADGui.doCommand("wp = WorkingPlane.get_working_plane()") if FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Arch").GetBool("WallSketches",True): # Use ArchSketch if SketchArch add-on is present try: @@ -439,13 +442,13 @@ class _CommandWall: FreeCADGui.doCommand('base=ArchSketchObject.makeArchSketch()') except: FreeCADGui.doCommand('base=FreeCAD.ActiveDocument.addObject("Sketcher::SketchObject","WallTrace")') - FreeCADGui.doCommand('base.Placement = FreeCAD.DraftWorkingPlane.getPlacement()') + FreeCADGui.doCommand('base.Placement = wp.get_placement()') FreeCADGui.doCommand('base.addGeometry(trace)') else: FreeCADGui.doCommand('base=Draft.makeLine(trace)') FreeCADGui.doCommand('FreeCAD.ActiveDocument.recompute()') FreeCADGui.doCommand('wall = Arch.makeWall(base,width='+str(self.Width)+',height='+str(self.Height)+',align="'+str(self.Align)+'")') - FreeCADGui.doCommand('wall.Normal = FreeCAD.DraftWorkingPlane.getNormal()') + FreeCADGui.doCommand('wall.Normal = wp.axis') if self.MultiMat: FreeCADGui.doCommand("wall.Material = FreeCAD.ActiveDocument."+self.MultiMat.Name) FreeCADGui.doCommand("Draft.autogroup(wall)") @@ -467,7 +470,7 @@ class _CommandWall: if FreeCADGui.Control.activeDialog(): b = self.points[0] - n = FreeCAD.DraftWorkingPlane.axis + n = self.wp.axis bv = point.sub(b) dv = bv.cross(n) dv = DraftVecUtils.scaleTo(dv,self.Width/2) diff --git a/src/Mod/Arch/ArchWindow.py b/src/Mod/Arch/ArchWindow.py index 580c24b20b..0ee9d6def2 100644 --- a/src/Mod/Arch/ArchWindow.py +++ b/src/Mod/Arch/ArchWindow.py @@ -186,6 +186,7 @@ class _CommandWindow: self.Include = True self.baseFace = None self.wparams = ["Width","Height","H1","H2","H3","W1","W2","O1","O2"] + self.wp = None # autobuild mode if FreeCADGui.Selection.getSelectionEx(): @@ -235,8 +236,8 @@ class _CommandWindow: return # interactive mode - if hasattr(FreeCAD,"DraftWorkingPlane"): - FreeCAD.DraftWorkingPlane.setup() + import WorkingPlane + self.wp = WorkingPlane.get_working_plane() self.tracker = DraftTrackers.boxTracker() self.tracker.length(self.Width) @@ -274,8 +275,8 @@ class _CommandWindow: point = point.add(FreeCAD.Vector(0,0,self.Sill)) FreeCAD.ActiveDocument.openTransaction(translate("Arch","Create Window")) - FreeCADGui.doCommand("import math, FreeCAD, Arch, DraftGeomUtils") - FreeCADGui.doCommand("wp = FreeCAD.DraftWorkingPlane") + FreeCADGui.doCommand("import math, FreeCAD, Arch, DraftGeomUtils, WorkingPlane") + FreeCADGui.doCommand("wp = WorkingPlane.get_working_plane()") if self.baseFace is not None: FreeCADGui.doCommand("face = FreeCAD.ActiveDocument." + self.baseFace[0].Name + ".Shape.Faces[" + str(self.baseFace[1]) + "]") @@ -342,9 +343,8 @@ class _CommandWindow: delta = FreeCAD.Vector(self.Width/2,self.Thickness/2,self.Height/2) delta = delta.add(FreeCAD.Vector(0,0,self.Sill)) - wp = FreeCAD.DraftWorkingPlane if self.baseFace is None: - rot = FreeCAD.Rotation(wp.u,wp.v,-wp.axis,"XZY") + rot = FreeCAD.Rotation(self.wp.u,self.wp.v,-self.wp.axis,"XZY") self.tracker.setRotation(rot) if info: if "Face" in info['Component']: @@ -353,7 +353,7 @@ class _CommandWindow: self.baseFace = [o,int(info['Component'][4:])-1] #print("switching to ",o.Label," face ",self.baseFace[1]) f = o.Shape.Faces[self.baseFace[1]] - p = DraftGeomUtils.placement_from_face(f,vec_z=wp.axis,rotated=True) + p = DraftGeomUtils.placement_from_face(f,vec_z=self.wp.axis,rotated=True) rot = p.Rotation self.tracker.setRotation(rot) r = self.tracker.trans.rotation.getValue().getValue() diff --git a/src/Mod/Arch/importIFCHelper.py b/src/Mod/Arch/importIFCHelper.py index 024fe78ed1..3e86fd522e 100644 --- a/src/Mod/Arch/importIFCHelper.py +++ b/src/Mod/Arch/importIFCHelper.py @@ -714,9 +714,7 @@ def getRotation(entity): w = FreeCAD.Vector(entity.Axis3.DirectionRatios) except AttributeError: return FreeCAD.Rotation() - import WorkingPlane - p = WorkingPlane.plane(u=u, v=v, w=w) - return p.getRotation().Rotation + return FreeCAD.Rotation(u, v, w, "ZYX") def getPlacement(entity,scaling=1000): diff --git a/src/Mod/Draft/draftguitools/gui_selectplane.py b/src/Mod/Draft/draftguitools/gui_selectplane.py index a1c9b34b5b..15850a030f 100644 --- a/src/Mod/Draft/draftguitools/gui_selectplane.py +++ b/src/Mod/Draft/draftguitools/gui_selectplane.py @@ -73,6 +73,7 @@ class Draft_SelectPlane: App.activeDraftCommand.finish() App.activeDraftCommand = self + self.call = None # Set variables self.wp = WorkingPlane.get_working_plane() @@ -134,6 +135,7 @@ class Draft_SelectPlane: if Gui.Selection.hasSelection(): if self.wp.align_to_selection(self.offset): Gui.Selection.clearSelection() + self.finish() return # Execute the actual task panel delayed to catch possible active Draft command diff --git a/src/Mod/Draft/draftobjects/facebinder.py b/src/Mod/Draft/draftobjects/facebinder.py index ab56edb56d..cad541c98d 100644 --- a/src/Mod/Draft/draftobjects/facebinder.py +++ b/src/Mod/Draft/draftobjects/facebinder.py @@ -77,6 +77,7 @@ class Facebinder(DraftObject): if "Face" in sub: try: face = Part.getShape(sel[0], sub, needSubElement=True, retType=0) + area += face.Area if offs_val: if face.Surface.isPlanar(): norm = face.normalAt(0, 0) @@ -86,14 +87,14 @@ class Facebinder(DraftObject): else: offs = face.makeOffsetShape(offs_val, 1e-7) faces.extend(offs.Faces) - area += face.Area + else: + faces.append(face) except Part.OCCError: print("Draft: error building facebinder") return if not faces: return try: - sh = None if extr_val: extrs = [] for face in faces: @@ -103,23 +104,26 @@ class Facebinder(DraftObject): else: extr = face.makeOffsetShape(extr_val, 1e-7, fill=True) extrs.extend(extr.Solids) - sh = extrs.pop() - sh = sh.multiFuse(extrs) + shp = Part.Shape() # create empty shape to ensure default Placement + shp = shp.fuse(extrs.pop()) # add 1st shape, multiFuse does not work otherwise + if extrs: + shp = shp.multiFuse(extrs) # multiFuse is more reliable than serial fuse + else: + shp = Part.Shape() + shp = shp.fuse(faces.pop()) + if faces: + shp = shp.multiFuse(faces) if len(faces) > 1: - if not sh: - sh = faces.pop() - sh = sh.multiFuse(faces) if hasattr(obj, "Sew") and obj.Sew: - sh.sewShape() + shp.sewShape() if not hasattr(obj, "RemoveSplitter"): - sh = sh.removeSplitter() + shp = shp.removeSplitter() elif obj.RemoveSplitter: - sh = sh.removeSplitter() + shp = shp.removeSplitter() except Part.OCCError: print("Draft: error building facebinder") return - obj.Shape = sh - obj.Placement = pl + obj.Shape = shp obj.Area = area self.props_changed_clear() diff --git a/src/Mod/Fem/Gui/TaskFemConstraintTemperature.cpp b/src/Mod/Fem/Gui/TaskFemConstraintTemperature.cpp index 7538833a80..3ed30091e7 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintTemperature.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintTemperature.cpp @@ -66,24 +66,28 @@ TaskFemConstraintTemperature::TaskFemConstraintTemperature( std::vector SubElements = pcConstraint->References.getSubValues(); // Fill data into dialog elements - ui->if_temperature->setMinimum(0); - ui->if_temperature->setMaximum(FLOAT_MAX); + ui->qsb_temperature->setMinimum(0); + ui->qsb_temperature->setMaximum(FLOAT_MAX); + ui->qsb_cflux->setMinimum(-FLOAT_MAX); + ui->qsb_cflux->setMaximum(FLOAT_MAX); - std::string constraint_type = pcConstraint->ConstraintType.getValueAsString(); - if (constraint_type == "Temperature") { - ui->rb_temperature->setChecked(true); - ui->if_temperature->setValue(pcConstraint->Temperature.getQuantityValue()); + App::PropertyEnumeration* constrType = &pcConstraint->ConstraintType; + QStringList qTypeList; + for (auto item : constrType->getEnumVector()) { + qTypeList << QString::fromUtf8(item.c_str()); + } - ui->if_temperature->bind(pcConstraint->Temperature); - ui->if_temperature->setUnit(pcConstraint->Temperature.getUnit()); - } - else if (constraint_type == "CFlux") { - ui->rb_cflux->setChecked(true); - std::string str = "Concentrated heat flux"; - ui->if_temperature->setValue(pcConstraint->CFlux.getQuantityValue()); - ui->if_temperature->bind(pcConstraint->CFlux); - ui->if_temperature->setUnit(pcConstraint->CFlux.getUnit()); - } + ui->cb_constr_type->addItems(qTypeList); + ui->cb_constr_type->setCurrentIndex(constrType->getValue()); + onConstrTypeChanged(constrType->getValue()); + + ui->qsb_temperature->setValue(pcConstraint->Temperature.getQuantityValue()); + ui->qsb_temperature->bind(pcConstraint->Temperature); + ui->qsb_temperature->setUnit(pcConstraint->Temperature.getUnit()); + + ui->qsb_cflux->setValue(pcConstraint->CFlux.getQuantityValue()); + ui->qsb_cflux->bind(pcConstraint->CFlux); + ui->qsb_cflux->setUnit(pcConstraint->CFlux.getUnit()); ui->lw_references->clear(); for (std::size_t i = 0; i < Objects.size(); i++) { @@ -108,12 +112,22 @@ TaskFemConstraintTemperature::TaskFemConstraintTemperature( &QListWidget::itemClicked, this, &TaskFemConstraintTemperature::setSelection); - connect(ui->rb_temperature, &QRadioButton::clicked, this, &TaskFemConstraintTemperature::Temp); - connect(ui->rb_cflux, &QRadioButton::clicked, this, &TaskFemConstraintTemperature::Flux); + connect(ui->cb_constr_type, + qOverload(&QComboBox::activated), + this, + &TaskFemConstraintTemperature::onConstrTypeChanged); + connect(ui->qsb_temperature, + qOverload(&Gui::QuantitySpinBox::valueChanged), + this, + &TaskFemConstraintTemperature::onTempChanged); + connect(ui->qsb_cflux, + qOverload(&Gui::QuantitySpinBox::valueChanged), + this, + &TaskFemConstraintTemperature::onCFluxChanged); // Selection buttons - buttonGroup->addButton(ui->btnAdd, (int)SelectionChangeModes::refAdd); - buttonGroup->addButton(ui->btnRemove, (int)SelectionChangeModes::refRemove); + buttonGroup->addButton(ui->btnAdd, static_cast(SelectionChangeModes::refAdd)); + buttonGroup->addButton(ui->btnRemove, static_cast(SelectionChangeModes::refRemove)); updateUI(); } @@ -129,20 +143,41 @@ void TaskFemConstraintTemperature::updateUI() } } -void TaskFemConstraintTemperature::Temp() +void TaskFemConstraintTemperature::onTempChanged(double) { - Fem::ConstraintTemperature* pcConstraint = - static_cast(ConstraintView->getObject()); - ui->if_temperature->setUnit(pcConstraint->Temperature.getUnit()); - ui->if_temperature->setValue(pcConstraint->Temperature.getQuantityValue()); + std::string name = ConstraintView->getObject()->getNameInDocument(); + Gui::Command::doCommand(Gui::Command::Doc, + "App.ActiveDocument.%s.Temperature = \"%s\"", + name.c_str(), + get_temperature().c_str()); } -void TaskFemConstraintTemperature::Flux() +void TaskFemConstraintTemperature::onCFluxChanged(double) { - Fem::ConstraintTemperature* pcConstraint = - static_cast(ConstraintView->getObject()); - ui->if_temperature->setUnit(pcConstraint->CFlux.getUnit()); - ui->if_temperature->setValue(pcConstraint->CFlux.getQuantityValue()); + std::string name = ConstraintView->getObject()->getNameInDocument(); + Gui::Command::doCommand(Gui::Command::Doc, + "App.ActiveDocument.%s.CFlux = \"%s\"", + name.c_str(), + get_cflux().c_str()); +} + +void TaskFemConstraintTemperature::onConstrTypeChanged(int item) +{ + auto obj = static_cast(ConstraintView->getObject()); + obj->ConstraintType.setValue(item); + const char* type = obj->ConstraintType.getValueAsString(); + if (strcmp(type, "Temperature") == 0) { + ui->qsb_temperature->setVisible(true); + ui->qsb_cflux->setVisible(false); + ui->lbl_temperature->setVisible(true); + ui->lbl_cflux->setVisible(false); + } + else if (strcmp(type, "CFlux") == 0) { + ui->qsb_cflux->setVisible(true); + ui->qsb_temperature->setVisible(false); + ui->lbl_cflux->setVisible(true); + ui->lbl_temperature->setVisible(false); + } } void TaskFemConstraintTemperature::addToSelection() @@ -270,25 +305,17 @@ const std::string TaskFemConstraintTemperature::getReferences() const std::string TaskFemConstraintTemperature::get_temperature() const { - return ui->if_temperature->value().getSafeUserString().toStdString(); + return ui->qsb_temperature->value().getSafeUserString().toStdString(); } std::string TaskFemConstraintTemperature::get_cflux() const { - return ui->if_temperature->value().getSafeUserString().toStdString(); + return ui->qsb_cflux->value().getSafeUserString().toStdString(); } std::string TaskFemConstraintTemperature::get_constraint_type() const { - std::string type; - - if (ui->rb_temperature->isChecked()) { - type = "\"Temperature\""; - } - else if (ui->rb_cflux->isChecked()) { - type = "\"CFlux\""; - } - return type; + return ui->cb_constr_type->currentText().toStdString(); } bool TaskFemConstraintTemperature::event(QEvent* e) @@ -357,7 +384,7 @@ bool TaskDlgFemConstraintTemperature::accept() try { Gui::Command::doCommand(Gui::Command::Doc, - "App.ActiveDocument.%s.ConstraintType = %s", + "App.ActiveDocument.%s.ConstraintType = \"%s\"", name.c_str(), parameterTemperature->get_constraint_type().c_str()); if (type == "Temperature") { diff --git a/src/Mod/Fem/Gui/TaskFemConstraintTemperature.h b/src/Mod/Fem/Gui/TaskFemConstraintTemperature.h index fe57160456..889676b93c 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintTemperature.h +++ b/src/Mod/Fem/Gui/TaskFemConstraintTemperature.h @@ -55,8 +55,9 @@ public: private Q_SLOTS: void onReferenceDeleted(); - void Temp(); - void Flux(); + void onConstrTypeChanged(int item); + void onCFluxChanged(double); + void onTempChanged(double); void addToSelection() override; void removeFromSelection() override; diff --git a/src/Mod/Fem/Gui/TaskFemConstraintTemperature.ui b/src/Mod/Fem/Gui/TaskFemConstraintTemperature.ui index 8f8698f6cd..ef867fefe9 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintTemperature.ui +++ b/src/Mod/Fem/Gui/TaskFemConstraintTemperature.ui @@ -49,42 +49,45 @@ - - - + + + - Temperature - - - true - - - false + Constraint type - - + + + + + + + Temperature + + + + + + + K + + + 0.000000000000000 + + + + + Concentrated heat flux - - - - - - - - Temperature - - - - - + + - K + mW 0.000000000000000 diff --git a/src/Mod/PartDesign/SprocketFeature.ui b/src/Mod/PartDesign/SprocketFeature.ui index d45ca8c48f..197790f902 100644 --- a/src/Mod/PartDesign/SprocketFeature.ui +++ b/src/Mod/PartDesign/SprocketFeature.ui @@ -6,16 +6,22 @@ 0 0 - 264 - 142 + 344 + 160 Sprocket parameter - + + + + 0 + 0 + + Number of teeth: @@ -23,6 +29,12 @@ + + + 0 + 0 + + 3 @@ -43,6 +55,12 @@ + + + 0 + 0 + + ANSI 25 @@ -205,7 +223,7 @@ - + 0 0 @@ -245,14 +263,14 @@ - Roller Diameter: + Chain Roller Diameter: - + 0 0 @@ -289,14 +307,14 @@ - Thickness: + Tooth Width - + 0 0 diff --git a/src/Mod/Path/Path/Op/Area.py b/src/Mod/Path/Path/Op/Area.py index 1ef2044a8f..34a2c26283 100644 --- a/src/Mod/Path/Path/Op/Area.py +++ b/src/Mod/Path/Path/Op/Area.py @@ -346,21 +346,25 @@ class ObjectOp(PathOp.ObjectOp): # Note that emitting preambles between moves breaks some dressups and prevents path optimization on some controllers pathParams["preamble"] = False - if self.endVector is None: - verts = hWire.Wires[0].Vertexes - idx = 0 - if obj.Direction == "CCW": - idx = len(verts) - 1 - x = verts[idx].X - y = verts[idx].Y - # Zero start value adjustments for Path.fromShapes() bug - if Path.Geom.isRoughly(x, 0.0): - x = 0.00001 - if Path.Geom.isRoughly(y, 0.0): - y = 0.00001 - pathParams["start"] = FreeCAD.Vector(x, y, verts[0].Z) - else: - pathParams["start"] = self.endVector + # Always manually setting pathParams["start"] to the first or + # last vertex of the wire (depending on obj.Direction) ensures + # the edge is always milled in the correct direction. Using + # self.endVector would allow Path.fromShapes to reverse the + # direction if that would shorten the travel move and thus cause + # the edges being milled in seemingly random directions. + + verts = hWire.Wires[0].Vertexes + idx = 0 + if obj.Direction == "CCW": + idx = len(verts) - 1 + x = verts[idx].X + y = verts[idx].Y + # Zero start value adjustments for Path.fromShapes() bug + if Path.Geom.isRoughly(x, 0.0): + x = 0.00001 + if Path.Geom.isRoughly(y, 0.0): + y = 0.00001 + pathParams["start"] = FreeCAD.Vector(x, y, verts[0].Z) obj.PathParams = str( {key: value for key, value in pathParams.items() if key != "shapes"} diff --git a/src/Mod/Sketcher/Gui/SketcherToolDefaultWidget.cpp b/src/Mod/Sketcher/Gui/SketcherToolDefaultWidget.cpp index 9b73a8f8b6..966e24d7fd 100644 --- a/src/Mod/Sketcher/Gui/SketcherToolDefaultWidget.cpp +++ b/src/Mod/Sketcher/Gui/SketcherToolDefaultWidget.cpp @@ -394,7 +394,7 @@ void SketcherToolDefaultWidget::setParameterLabel(int parameterindex, const QStr void SketcherToolDefaultWidget::setParameter(int parameterindex, double val) { if (parameterindex < nParameters) { - getParameterSpinBox(parameterindex)->setValue(Base::Quantity(val, Base::Unit::Length)); + getParameterSpinBox(parameterindex)->setValue(val); return; } @@ -424,6 +424,45 @@ void SketcherToolDefaultWidget::configureParameterUnit(int parameterindex, const QT_TRANSLATE_NOOP("Exceptions", "ToolWidget parameter index out of range")); } +void SketcherToolDefaultWidget::configureParameterDecimals(int parameterindex, int val) +{ + Base::StateLocker lock(blockParameterSlots, true); + if (parameterindex < nParameters) { + getParameterSpinBox(parameterindex)->setDecimals(val); + + return; + } + + THROWM(Base::IndexError, + QT_TRANSLATE_NOOP("Exceptions", "ToolWidget parameter index out of range")); +} + +void SketcherToolDefaultWidget::configureParameterMin(int parameterindex, double val) +{ + Base::StateLocker lock(blockParameterSlots, true); + if (parameterindex < nParameters) { + getParameterSpinBox(parameterindex)->setMinimum(val); + + return; + } + + THROWM(Base::IndexError, + QT_TRANSLATE_NOOP("Exceptions", "ToolWidget parameter index out of range")); +} + +void SketcherToolDefaultWidget::configureParameterMax(int parameterindex, double val) +{ + Base::StateLocker lock(blockParameterSlots, true); + if (parameterindex < nParameters) { + getParameterSpinBox(parameterindex)->setMaximum(val); + + return; + } + + THROWM(Base::IndexError, + QT_TRANSLATE_NOOP("Exceptions", "ToolWidget parameter index out of range")); +} + void SketcherToolDefaultWidget::setParameterEnabled(int parameterindex, bool active) { if (parameterindex < nParameters) { @@ -714,6 +753,20 @@ void SketcherToolDefaultWidget::restoreCheckBoxPref(int checkboxindex) } } +void SketcherToolDefaultWidget::setCheckboxIcon(int checkboxindex, QIcon icon) +{ + if (checkboxindex < nCheckbox) { + getCheckBox(checkboxindex)->setIcon(icon); + } +} + +void SketcherToolDefaultWidget::setComboboxItemIcon(int comboboxindex, int index, QIcon icon) +{ + if (comboboxindex < nCombobox) { + getComboBox(comboboxindex)->setItemIcon(index, icon); + } +} + void SketcherToolDefaultWidget::setComboboxPrefEntry(int comboboxindex, const std::string& prefEntry) { diff --git a/src/Mod/Sketcher/Gui/SketcherToolDefaultWidget.h b/src/Mod/Sketcher/Gui/SketcherToolDefaultWidget.h index 275d03b239..e4ce688fcb 100644 --- a/src/Mod/Sketcher/Gui/SketcherToolDefaultWidget.h +++ b/src/Mod/Sketcher/Gui/SketcherToolDefaultWidget.h @@ -146,6 +146,9 @@ public: void setParameter(int parameterindex, double val); void configureParameterInitialValue(int parameterindex, double value); void configureParameterUnit(int parameterindex, const Base::Unit& unit); + void configureParameterDecimals(int parameterindex, int val); + void configureParameterMax(int parameterindex, double val); + void configureParameterMin(int parameterindex, double val); double getParameter(int parameterindex); bool isParameterSet(int parameterindex); void @@ -172,6 +175,7 @@ public: void setCheckboxToolTip(int checkboxindex, const QString& string); bool getCheckboxChecked(int checkboxindex); void setCheckboxPrefEntry(int checkboxindex, const std::string& prefEntry); + void setCheckboxIcon(int checkboxindex, QIcon icon); void restoreCheckBoxPref(int checkboxindex); void initNComboboxes(int ncombobox); @@ -180,6 +184,7 @@ public: void setComboboxLabel(int comboboxindex, const QString& string); int getComboboxIndex(int comboboxindex); void setComboboxElements(int comboboxindex, const QStringList& names); + void setComboboxItemIcon(int comboboxindex, int index, QIcon icon); void setComboboxPrefEntry(int comboboxindex, const std::string& prefEntry); void restoreComboboxPref(int comboboxindex); diff --git a/src/Mod/TechDraw/Gui/CommandAnnotate.cpp b/src/Mod/TechDraw/Gui/CommandAnnotate.cpp index ef3b6cdcba..a61c7c013a 100644 --- a/src/Mod/TechDraw/Gui/CommandAnnotate.cpp +++ b/src/Mod/TechDraw/Gui/CommandAnnotate.cpp @@ -1066,11 +1066,12 @@ void execLine2Points(Gui::Command* cmd) //check if editing existing edge if (!edgeNames.empty() && (edgeNames.size() == 1)) { TechDraw::CosmeticEdge* ce = baseFeat->getCosmeticEdgeBySelection(edgeNames.front()); - if (!ce) { + if (!ce || ce->m_geometry->getGeomType() != TechDraw::GeomType::GENERIC) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"), QObject::tr("Selection is not a Cosmetic Line.")); return; } + Gui::Control().showDialog(new TaskDlgCosmeticLine(baseFeat, edgeNames.front())); return; @@ -1208,11 +1209,14 @@ void execCosmeticCircle(Gui::Command* cmd) //check if editing existing edge if (!edgeNames.empty() && (edgeNames.size() == 1)) { TechDraw::CosmeticEdge* ce = baseFeat->getCosmeticEdgeBySelection(edgeNames.front()); - if (!ce) { + if (!ce + || !(ce->m_geometry->getGeomType() == TechDraw::GeomType::CIRCLE + || ce->m_geometry->getGeomType() == TechDraw::GeomType::ARCOFCIRCLE)) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"), - QObject::tr("Selection is not a Cosmetic edge.")); + QObject::tr("Selection is not a Cosmetic Circle or a Cosmetic Arc of Circle.")); return; } + Gui::Control().showDialog(new TaskDlgCosmeticCircle(baseFeat, edgeNames.front())); return; diff --git a/src/Mod/TechDraw/Gui/QGIViewPart.cpp b/src/Mod/TechDraw/Gui/QGIViewPart.cpp index fe4e60d42a..f7b7e13b6d 100644 --- a/src/Mod/TechDraw/Gui/QGIViewPart.cpp +++ b/src/Mod/TechDraw/Gui/QGIViewPart.cpp @@ -289,6 +289,8 @@ void QGIViewPart::drawAllEdges() item->setNormalColor(PreferencesGui::getAccessibleQColor(PreferencesGui::normalQColor())); item->setStyle(Qt::SolidLine); if ((*itGeom)->getCosmetic()) { + item->setCosmetic(true); + // cosmetic edge - format appropriately int source = (*itGeom)->source(); if (source == COSMETICEDGE) {