* Sketcher: Coin resize when screen change. Fix #23267 * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update ViewProviderSketch.cpp --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
@@ -135,15 +135,15 @@ void EditModeCoinManager::ParameterObserver::initParameters()
|
||||
}},
|
||||
{"ViewScalingFactor",
|
||||
[this](const std::string& param) {
|
||||
updateElementSizeParameters(param);
|
||||
Client.updateElementSizeParameters();
|
||||
}},
|
||||
{"MarkerSize",
|
||||
[this](const std::string& param) {
|
||||
updateElementSizeParameters(param);
|
||||
Client.updateElementSizeParameters();
|
||||
}},
|
||||
{"EditSketcherFontSize",
|
||||
[this](const std::string& param) {
|
||||
updateElementSizeParameters(param);
|
||||
Client.updateElementSizeParameters();
|
||||
}},
|
||||
{"EdgeWidth",
|
||||
[this, &drawingParameters = Client.drawingParameters](const std::string& param) {
|
||||
@@ -355,54 +355,6 @@ void EditModeCoinManager::ParameterObserver::updateOverlayVisibilityParameter(
|
||||
Client.overlayParameters.visibleInformationChanged = true;
|
||||
}
|
||||
|
||||
void EditModeCoinManager::ParameterObserver::updateElementSizeParameters(
|
||||
const std::string& parametername)
|
||||
{
|
||||
(void)parametername;
|
||||
|
||||
// Add scaling to Constraint icons
|
||||
ParameterGrp::handle hGrp =
|
||||
App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View");
|
||||
|
||||
double viewScalingFactor = hGrp->GetFloat("ViewScalingFactor", 1.0);
|
||||
viewScalingFactor = std::clamp<double>(viewScalingFactor, 0.5, 5.0);
|
||||
|
||||
int markerSize = hGrp->GetInt("MarkerSize", 7);
|
||||
|
||||
int defaultFontSizePixels =
|
||||
Client.defaultApplicationFontSizePixels(); // returns height in pixels, not points
|
||||
|
||||
int sketcherfontSize = hGrp->GetInt("EditSketcherFontSize", defaultFontSizePixels);
|
||||
int constraintSymbolSizePref = hGrp->GetInt("ConstraintSymbolSize", defaultFontSizePixels);
|
||||
|
||||
double dpi = Client.getApplicationLogicalDPIX();
|
||||
double devicePixelRatio = Client.getDevicePixelRatio();
|
||||
|
||||
// simple scaling factor for hardcoded pixel values in the Sketcher
|
||||
Client.drawingParameters.pixelScalingFactor = devicePixelRatio * viewScalingFactor;
|
||||
|
||||
// About sizes:
|
||||
// SoDatumLabel takes the size in points, not in pixels. This is because it uses QFont
|
||||
// internally. Coin, at least our coin at this time, takes pixels, not points.
|
||||
|
||||
Client.drawingParameters.coinFontSize =
|
||||
std::lround(sketcherfontSize * devicePixelRatio); // in pixels (Coin uses pixels)
|
||||
Client.drawingParameters.labelFontSize = std::lround(
|
||||
sketcherfontSize * devicePixelRatio * 72.0f / dpi); // in points (SoDatumLabel uses points)
|
||||
Client.drawingParameters.constraintIconSize = constraintSymbolSizePref;
|
||||
|
||||
auto supportedsizes = Gui::Inventor::MarkerBitmaps::getSupportedSizes("CIRCLE_LINE");
|
||||
auto scaledMarkerSize = std::lround(markerSize * devicePixelRatio);
|
||||
auto const it =
|
||||
std::lower_bound(supportedsizes.begin(), supportedsizes.end(), scaledMarkerSize);
|
||||
if (it != supportedsizes.end()) {
|
||||
scaledMarkerSize = *it;
|
||||
}
|
||||
Client.drawingParameters.markerSize = scaledMarkerSize;
|
||||
|
||||
Client.updateInventorNodeSizes();
|
||||
}
|
||||
|
||||
void EditModeCoinManager::ParameterObserver::updateWidth(int& width,
|
||||
const std::string& parametername,
|
||||
int def)
|
||||
@@ -1117,6 +1069,51 @@ void EditModeCoinManager::setEditDrawStyle(GeometryCreationMode mode)
|
||||
toCopy->linePatternScaleFactor;
|
||||
}
|
||||
|
||||
void EditModeCoinManager::updateElementSizeParameters()
|
||||
{
|
||||
// Add scaling to Constraint icons
|
||||
ParameterGrp::handle hGrp =
|
||||
App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View");
|
||||
|
||||
double viewScalingFactor = hGrp->GetFloat("ViewScalingFactor", 1.0);
|
||||
viewScalingFactor = std::clamp<double>(viewScalingFactor, 0.5, 5.0);
|
||||
|
||||
int markerSize = hGrp->GetInt("MarkerSize", 7);
|
||||
|
||||
int defaultFontSizePixels =
|
||||
defaultApplicationFontSizePixels(); // returns height in pixels, not points
|
||||
|
||||
int sketcherfontSize = hGrp->GetInt("EditSketcherFontSize", defaultFontSizePixels);
|
||||
int constraintSymbolSizePref = hGrp->GetInt("ConstraintSymbolSize", defaultFontSizePixels);
|
||||
|
||||
double dpi = getApplicationLogicalDPIX();
|
||||
double devicePixelRatio = getDevicePixelRatio();
|
||||
|
||||
// simple scaling factor for hardcoded pixel values in the Sketcher
|
||||
drawingParameters.pixelScalingFactor = devicePixelRatio * viewScalingFactor;
|
||||
|
||||
// About sizes:
|
||||
// SoDatumLabel takes the size in points, not in pixels. This is because it uses QFont
|
||||
// internally. Coin, at least our coin at this time, takes pixels, not points.
|
||||
|
||||
drawingParameters.coinFontSize =
|
||||
std::lround(sketcherfontSize * devicePixelRatio); // in pixels (Coin uses pixels)
|
||||
drawingParameters.labelFontSize = std::lround(sketcherfontSize * devicePixelRatio * 72.0f
|
||||
/ dpi); // in points (SoDatumLabel uses points)
|
||||
drawingParameters.constraintIconSize = constraintSymbolSizePref;
|
||||
|
||||
auto supportedsizes = Gui::Inventor::MarkerBitmaps::getSupportedSizes("CIRCLE_LINE");
|
||||
auto scaledMarkerSize = std::lround(markerSize * devicePixelRatio);
|
||||
auto const it =
|
||||
std::lower_bound(supportedsizes.begin(), supportedsizes.end(), scaledMarkerSize);
|
||||
if (it != supportedsizes.end()) {
|
||||
scaledMarkerSize = *it;
|
||||
}
|
||||
drawingParameters.markerSize = scaledMarkerSize;
|
||||
|
||||
updateInventorNodeSizes();
|
||||
}
|
||||
|
||||
/************************ Delegated constraint public interface **********/
|
||||
|
||||
// public function that triggers drawing of most constraint icons
|
||||
|
||||
@@ -143,7 +143,6 @@ class SketcherGuiExport EditModeCoinManager
|
||||
void updateCurvedEdgeCountSegmentsParameter(const std::string& parametername);
|
||||
void updateLineRenderingOrderParameters(const std::string& parametername);
|
||||
void updateConstraintPresentationParameters(const std::string& parametername);
|
||||
void updateElementSizeParameters(const std::string& parametername);
|
||||
void updateWidth(int& width, const std::string& parametername, int def);
|
||||
void updatePattern(unsigned int& pattern, const std::string& pname, unsigned int def);
|
||||
void updateColor(SbColor& sbcolor, const std::string& parametername);
|
||||
@@ -262,6 +261,8 @@ public:
|
||||
// Updates the Axes extension to span the specified area.
|
||||
void updateAxesLength(const Base::BoundBox2d& bb);
|
||||
|
||||
void updateElementSizeParameters();
|
||||
|
||||
private:
|
||||
// This function populates the coin nodes with the information of the current geometry
|
||||
void processGeometry(const GeoListFacade& geolistfacade);
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
#include <QMessageBox>
|
||||
#include <QScreen>
|
||||
#include <QTextStream>
|
||||
#include <QWindow>
|
||||
|
||||
#include <limits>
|
||||
#endif
|
||||
@@ -3738,6 +3739,15 @@ void ViewProviderSketch::setEditViewer(Gui::View3DInventorViewer* viewer, int Mo
|
||||
cameraSensor.attach(viewer->getCamera());
|
||||
|
||||
blockContextMenu = false;
|
||||
|
||||
if (auto* window = viewer->window()->windowHandle()) {
|
||||
screenChangeConnection = QObject::connect(window, &QWindow::screenChanged, [this](QScreen*) {
|
||||
if (isInEditMode() && editCoinManager) {
|
||||
editCoinManager->updateElementSizeParameters();
|
||||
draw();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void ViewProviderSketch::unsetEditViewer(Gui::View3DInventorViewer* viewer)
|
||||
@@ -3753,6 +3763,8 @@ void ViewProviderSketch::unsetEditViewer(Gui::View3DInventorViewer* viewer)
|
||||
viewer->setSelectionEnabled(true);
|
||||
|
||||
blockContextMenu = false;
|
||||
|
||||
QObject::disconnect(screenChangeConnection);
|
||||
}
|
||||
|
||||
void ViewProviderSketch::camSensDeleteCB(void* data, SoSensor *s)
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include <Inventor/SoRenderManager.h>
|
||||
#include <Inventor/sensors/SoNodeSensor.h>
|
||||
#include <QCoreApplication>
|
||||
#include <QMetaObject>
|
||||
#include <boost/signals2.hpp>
|
||||
#include <memory>
|
||||
|
||||
@@ -956,6 +957,8 @@ private:
|
||||
boost::signals2::connection connectRedoDocument;
|
||||
boost::signals2::connection connectSolverUpdate;
|
||||
|
||||
QMetaObject::Connection screenChangeConnection;
|
||||
|
||||
// modes while sketching
|
||||
SketchMode Mode;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user