Refactor Navigation Cube

-Use std commands in menu coming with icons
-Only draggable if activated in menu
-Remove textures except labels and used gl fill instead
-Borders on surrounding buttons
-Fix some openGL issues
-Remove duplicate parameter managment. Kept and improved the one in View3DSettings
-Remove lots of other redundant code
-Replaced FontSize param with FontZoom and enabled auto zoom/size on labels.
-Merged BorderColor and TextColor to single EmphaseColor parameter
-Merged ButtonColor and FrontColor to BaseColor parameter
-Added ChamferSize parameter to control edge and corner size
-Use glDrawArrays() innstead of glBegin() and glEnd()
-Draw butt ends on RGB coordinate system
-Fixe issues where cube switch corner on resize window
This commit is contained in:
Jolbas
2023-04-20 18:06:45 +02:00
parent decc04efbf
commit b613a4ea27
10 changed files with 732 additions and 1308 deletions

View File

@@ -36,7 +36,7 @@
#include "DlgSettingsNavigation.h"
#include "ui_DlgSettingsNavigation.h"
#include "MainWindow.h"
#include "NaviCube.h"
#include "View3DSettings.h"
#include "NavigationStyle.h"
#include "View3DInventor.h"
#include "View3DInventorViewer.h"
@@ -57,7 +57,7 @@ DlgSettingsNavigation::DlgSettingsNavigation(QWidget* parent)
, q0(0), q1(0), q2(0), q3(1)
{
ui->setupUi(this);
ui->naviCubeButtonColor->setAllowTransparency(true);
ui->naviCubeBaseColor->setAllowTransparency(true);
retranslate();
}
@@ -93,8 +93,7 @@ void DlgSettingsNavigation::saveSettings()
ui->naviCubeCorner->onSave();
ui->naviCubeToNearest->onSave();
ui->prefCubeSize->onSave();
ui->naviCubeFontSize->onSave();
ui->naviCubeButtonColor->onSave();
ui->naviCubeBaseColor->onSave();
bool showNaviCube = ui->groupBoxNaviCube->isChecked();
hGrp->SetBool("ShowNaviCube", showNaviCube);
@@ -113,21 +112,6 @@ void DlgSettingsNavigation::saveSettings()
hGrp = App::GetApplication().GetParameterGroupByPath(
"User parameter:BaseApp/Preferences/NaviCube");
hGrp->SetASCII("FontString", ui->naviCubeFontName->currentText().toLatin1());
recreateNaviCubes();
}
void DlgSettingsNavigation::recreateNaviCubes()
{
// we changed the cube's layout, therefore we must re-initialize it
// by deleting and the subsequently recreating
auto views = getMainWindow()->windows();
for (auto view : views) {
if (auto view3d = qobject_cast<View3DInventor*>(view)) {
auto viewer = view3d->getViewer();
viewer->updateNavigationCube();
}
}
}
void DlgSettingsNavigation::loadSettings()
@@ -142,8 +126,7 @@ void DlgSettingsNavigation::loadSettings()
ui->naviCubeCorner->onRestore();
ui->naviCubeToNearest->onRestore();
ui->prefCubeSize->onRestore();
ui->naviCubeFontSize->onRestore();
ui->naviCubeButtonColor->onRestore();
ui->naviCubeBaseColor->onRestore();
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath
("User parameter:BaseApp/Preferences/View");
@@ -190,7 +173,7 @@ void DlgSettingsNavigation::loadSettings()
// fill up font styles
hGrp = App::GetApplication().GetParameterGroupByPath(
"User parameter:BaseApp/Preferences/NaviCube");
std::string defaultSansserifFont = NaviCube::getDefaultSansserifFont().toStdString();
std::string defaultSansserifFont = NaviCubeSettings::getDefaultSansserifFont().toStdString();
// we purposely allow all available fonts on the system
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
@@ -206,15 +189,6 @@ void DlgSettingsNavigation::loadSettings()
indexFamilyNames = 0;
ui->naviCubeFontName->setCurrentIndex(indexFamilyNames);
// if the FontSize parameter does not yet exist, set the default value
// the default is defined in NaviCubeImplementation::getDefaultFontSize()
// but not accessible if there is no cube yet drawn
if (hGrp->GetInt("FontSize", 0) == 0) {
// the "4" is the hardcoded m_OverSample from getDefaultFontSize()
ui->naviCubeFontSize->setValue(int(0.18 * 4 * ui->prefCubeSize->value()));
// we purposely don't write to the parameters because the writing would
// also be done when the user cancels the preferences dialog
}
}
void DlgSettingsNavigation::onMouseButtonClicked()

View File

@@ -53,7 +53,6 @@ public:
private:
void onMouseButtonClicked();
void onNewDocViewChanged(int);
void recreateNaviCubes();
protected:
void changeEvent(QEvent *e) override;

View File

@@ -194,53 +194,15 @@
</property>
</widget>
</item>
<item row="2" column="3">
<widget class="QLabel" name="FontSizeLabel">
<property name="text">
<string>Font size:</string>
</property>
</widget>
</item>
<item row="2" column="4">
<widget class="Gui::PrefSpinBox" name="naviCubeFontSize">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Font size of the navigation cube</string>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>999</number>
</property>
<property name="singleStep">
<number>5</number>
</property>
<property name="value">
<number>100</number>
</property>
<property name="prefEntry" stdset="0">
<cstring>FontSize</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>NaviCube</cstring>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="ButtonColorLabel">
<widget class="QLabel" name="BaseColorLabel">
<property name="text">
<string>Button color</string>
<string>Color</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="Gui::PrefColorButton" name="naviCubeButtonColor">
<widget class="Gui::PrefColorButton" name="naviCubeBaseColor">
<property name="toolTip">
<string>color for all elements
around the cube</string>
@@ -253,7 +215,7 @@ around the cube</string>
</color>
</property>
<property name="prefEntry" stdset="0">
<cstring>ButtonColor</cstring>
<cstring>BaseColor</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>NaviCube</cstring>

File diff suppressed because it is too large Load Diff

View File

@@ -49,21 +49,25 @@ public:
void createContextMenu(const std::vector<std::string>& cmd);
bool processSoEvent(const SoEvent* ev);
void setCorner(Corner);
void setOffset(int x, int y);
bool isDraggable();
void setDraggable(bool draggable);
void setSize(int size);
void setChamfer(float size);
void setNaviRotateToNearest(bool toNearest);
void setNaviStepByTurn(int steps);
void setFont(std::string font);
void setFontSize(int size);
void setTextColor(QColor TextColor);
void setFrontColor(QColor FrontColor);
void setFontWeight(int weight);
void setFontStretch(int stretch);
void setFontZoom(float zoom);
void setBaseColor(QColor TextColor);
void setEmphaseColor(QColor ButtonColor);
void setHiliteColor(QColor HiliteColor);
void setButtonColor(QColor ButtonColor);
void setBorderWidth(double BorderWidth);
void setBorderColor(QColor BorderColor);
static QString getDefaultSansserifFont();
int getDefaultFontSize();
void setShowCS(bool showCS);
// front, top, right, rear, bottom, left
void setNaviCubeLabels(const std::vector<std::string>& labels);
static void setNaviCubeCommands(const std::vector<std::string>& cmd);
static void setNaviCubeLabels(const std::vector<std::string>& labels);
private:
NaviCubeImplementation* m_NaviCubeImplementation;

View File

@@ -145,7 +145,6 @@ View3DInventor::~View3DInventor()
}
viewSettings.reset();
naviSettings.reset();
//If we destroy this viewer by calling 'delete' directly the focus proxy widget which is defined
//by a widget in SoQtViewer isn't reset. This widget becomes a dangling pointer and makes

View File

@@ -1194,19 +1194,11 @@ void View3DInventorViewer::setNaviCubeCorner(int c)
naviCube->setCorner(static_cast<NaviCube::Corner>(c));
}
NaviCube* View3DInventorViewer::getNavigationCube() const
NaviCube* View3DInventorViewer::getNaviCube() const
{
return naviCube;
}
void View3DInventorViewer::updateNavigationCube()
{
if (naviCube) {
delete naviCube;
naviCube = new NaviCube(this);
}
}
void View3DInventorViewer::setAxisCross(bool on)
{
SoNode* scene = getSceneGraph();

View File

@@ -417,8 +417,7 @@ public:
void setEnabledNaviCube(bool b);
bool isEnabledNaviCube() const;
void setNaviCubeCorner(int);
NaviCube* getNavigationCube() const;
void updateNavigationCube();
NaviCube* getNaviCube() const;
void setEnabledVBO(bool b);
bool isEnabledVBO() const;
void setRenderCache(int);

View File

@@ -438,65 +438,121 @@ NaviCubeSettings::NaviCubeSettings(ParameterGrp::handle hGrp,
: hGrp(hGrp)
, _viewer(view)
{
hGrp->Attach(this);
connectParameterChanged = hGrp->Manager()->signalParamChanged.connect(
[this](ParameterGrp*, ParameterGrp::ParamType, const char *Name, const char *) {
parameterChanged(Name);
});
}
NaviCubeSettings::~NaviCubeSettings()
{
hGrp->Detach(this);
connectParameterChanged.disconnect();
}
QString NaviCubeSettings::getDefaultSansserifFont()
{
// "FreeCAD NaviCube" family susbtitutions are set in MainWindow::MainWindow
QFont font(QStringLiteral("FreeCAD NaviCube"));
font.setStyleHint(QFont::SansSerif);
// QFontInfo is required to get the actually matched font family
return QFontInfo(font).family();
// return QStringLiteral("FreeCAD NaviCube");
}
void NaviCubeSettings::applySettings()
{
OnChange(*hGrp, "CornerNaviCube");
parameterChanged("BaseColor");
parameterChanged("EmphaseColor");
parameterChanged("HiliteColor");
parameterChanged("CornerNaviCube");
parameterChanged("CubeSize");
parameterChanged("ChamferSize");
parameterChanged("NaviRotateToNearest");
parameterChanged("NaviStepByTurn");
parameterChanged("BorderWidth");
parameterChanged("FontZoom");
parameterChanged("FontString");
parameterChanged("FontWeight");
parameterChanged("FontStretch");
parameterChanged("ShowCS");
parameterChanged("TextFront"); // Updates all labels
}
void NaviCubeSettings::OnChange(ParameterGrp::SubjectType &rCaller,ParameterGrp::MessageType Reason)
void NaviCubeSettings::parameterChanged(const char* Name)
{
const ParameterGrp& rGrp = static_cast<ParameterGrp&>(rCaller);
if (strcmp(Reason, "CornerNaviCube") == 0) {
_viewer->setNaviCubeCorner(rGrp.GetInt("CornerNaviCube", 1));
if (Name == nullptr)
return;
NaviCube* nc = _viewer->getNaviCube();
if (strcmp(Name, "CornerNaviCube") == 0) {
nc->setCorner(static_cast<NaviCube::Corner>(hGrp->GetInt("CornerNaviCube", 1)));
}
else if (strcmp(Reason, "CubeSize") == 0) {
_viewer->getNavigationCube()->setSize(rGrp.GetInt("CubeSize", 132));
else if (strcmp(Name, "OffsetX") == 0 || strcmp(Name, "OffsetY") == 0) {
nc->setOffset(hGrp->GetInt("OffsetX", 0), hGrp->GetInt("OffsetY", 0));
}
else if (strcmp(Reason, "NaviRotateToNearest") == 0) {
_viewer->getNavigationCube()->setNaviRotateToNearest(
rGrp.GetBool("NaviRotateToNearest", true));
else if (strcmp(Name, "ChamferSize") == 0) {
nc->setChamfer(hGrp->GetFloat("ChamferSize", 0.12f));
}
else if (strcmp(Reason, "NaviStepByTurn") == 0) {
_viewer->getNavigationCube()->setNaviStepByTurn(rGrp.GetInt("NaviStepByTurn", 8));
else if (strcmp(Name, "CubeSize") == 0) {
nc->setSize(hGrp->GetInt("CubeSize", 132));
}
else if (strcmp(Reason, "FontSize") == 0) {
_viewer->getNavigationCube()->setFontSize(
rGrp.GetInt("FontSize", _viewer->getNavigationCube()->getDefaultFontSize()));
else if (strcmp(Name, "NaviRotateToNearest") == 0) {
nc->setNaviRotateToNearest(hGrp->GetBool("NaviRotateToNearest", true));
}
else if (strcmp(Reason, "FontString") == 0) {
std::string font = rGrp.GetASCII(
"FontString", NaviCube::getDefaultSansserifFont().toStdString().c_str());
_viewer->getNavigationCube()->setFont(font);
else if (strcmp(Name, "NaviStepByTurn") == 0) {
nc->setNaviStepByTurn(hGrp->GetInt("NaviStepByTurn", 8));
}
else if (strcmp(Reason, "TextColor") == 0) {
unsigned long col = rGrp.GetUnsigned("TextColor", 255);
_viewer->getNavigationCube()->setTextColor(App::Color::fromPackedRGBA<QColor>(col));
else if (strcmp(Name, "FontZoom") == 0) {
nc->setFontZoom(hGrp->GetFloat("FontZoom", 0.3));
}
else if (strcmp(Reason, "FrontColor") == 0) {
unsigned long col = rGrp.GetUnsigned("FrontColor", 3806916544);
_viewer->getNavigationCube()->setFrontColor(App::Color::fromPackedRGBA<QColor>(col));
else if (strcmp(Name, "FontString") == 0) {
std::string font =
hGrp->GetASCII("FontString", getDefaultSansserifFont().toStdString().c_str());
nc->setFont(font);
}
else if (strcmp(Reason, "HiliteColor") == 0) {
unsigned long col = rGrp.GetUnsigned("HiliteColor", 2867003391);
_viewer->getNavigationCube()->setHiliteColor(App::Color::fromPackedRGBA<QColor>(col));
else if (strcmp(Name, "FontWeight") == 0) {
nc->setFontWeight(hGrp->GetInt("FontWeight", 0));
}
else if (strcmp(Reason, "ButtonColor") == 0) {
unsigned long col = rGrp.GetUnsigned("ButtonColor", 3806916480);
_viewer->getNavigationCube()->setButtonColor(App::Color::fromPackedRGBA<QColor>(col));
else if (strcmp(Name, "FontStretch") == 0) {
nc->setFontStretch(hGrp->GetInt("FontStretch", 0));
}
else if (strcmp(Reason, "BorderWidth") == 0) {
_viewer->getNavigationCube()->setBorderWidth(rGrp.GetFloat("BorderWidth", 1.1));
else if (strcmp(Name, "BaseColor") == 0) {
unsigned long col = hGrp->GetUnsigned("BaseColor", 3806916544);
nc->setBaseColor(App::Color::fromPackedRGBA<QColor>(col));
// update default contrast colors
parameterChanged("EmphaseColor");
}
else if (strcmp(Name, "EmphaseColor") == 0) {
App::Color bc((uint32_t)hGrp->GetUnsigned("BaseColor", 3806916544));
unsigned long d = bc.r + bc.g + bc.b >= 1.5f ? 255 : 4294967295;
unsigned long col = hGrp->GetUnsigned("EmphaseColor", d);
nc->setEmphaseColor(App::Color::fromPackedRGBA<QColor>(col));
}
else if (strcmp(Reason, "BorderColor") == 0) {
unsigned long col = rGrp.GetUnsigned("BorderColor", 842150655);
_viewer->getNavigationCube()->setBorderColor(App::Color::fromPackedRGBA<QColor>(col));
else if (strcmp(Name, "HiliteColor") == 0) {
unsigned long col = hGrp->GetUnsigned("HiliteColor", 2867003391);
nc->setHiliteColor(App::Color::fromPackedRGBA<QColor>(col));
}
else if (strcmp(Name, "BorderWidth") == 0) {
nc->setBorderWidth(hGrp->GetFloat("BorderWidth", 1.1));
}
else if (strcmp(Name, "ShowCS") == 0) {
nc->setShowCS(hGrp->GetBool("ShowCS", 1));
}
else if (strcmp(Name, "TextTop") == 0 || strcmp(Name, "TextBottom") == 0
|| strcmp(Name, "TextFront") == 0 || strcmp(Name, "TextRear") == 0
|| strcmp(Name, "TextLeft") == 0 || strcmp(Name, "TextRight") == 0) {
std::vector<std::string> labels;
QByteArray frontByteArray = tr("FRONT").toUtf8();
labels.push_back(hGrp->GetASCII("TextFront", frontByteArray.constData()));
QByteArray topByteArray = tr("TOP").toUtf8();
labels.push_back(hGrp->GetASCII("TextTop", topByteArray.constData()));
QByteArray rightByteArray = tr("RIGHT").toUtf8();
labels.push_back(hGrp->GetASCII("TextRight", rightByteArray.constData()));
QByteArray rearByteArray = tr("REAR").toUtf8();
labels.push_back(hGrp->GetASCII("TextRear", rearByteArray.constData()));
QByteArray bottomByteArray = tr("BOTTOM").toUtf8();
labels.push_back(hGrp->GetASCII("TextBottom", bottomByteArray.constData()));
QByteArray leftByteArray = tr("LEFT").toUtf8();
labels.push_back(hGrp->GetASCII("TextLeft", leftByteArray.constData()));
nc->setNaviCubeLabels(labels);
}
_viewer->getSoRenderManager()->scheduleRedraw();
}

View File

@@ -24,6 +24,7 @@
#define GUI_VIEW3DSETTINGS_H
#include <Base/Parameter.h>
#include <QApplication>
namespace Gui {
class View3DInventorViewer;
@@ -51,19 +52,20 @@ private:
std::vector<View3DInventorViewer*> _viewers;
};
class NaviCubeSettings : public ParameterGrp::ObserverType
class NaviCubeSettings
{
Q_DECLARE_TR_FUNCTIONS(NaviCubeSettings)
public:
NaviCubeSettings(ParameterGrp::handle hGrp, View3DInventorViewer *);
~NaviCubeSettings() override;
~NaviCubeSettings();
/// Observer message from the ParameterGrp
void OnChange(ParameterGrp::SubjectType &rCaller,ParameterGrp::MessageType Reason) override;
void applySettings();
static QString getDefaultSansserifFont();
private:
void parameterChanged(ParameterGrp::MessageType pName);
ParameterGrp::handle hGrp;
View3DInventorViewer * _viewer;
boost::signals2::connection connectParameterChanged;
};
} // namespace Gui