Constraint icons size at Sketcher edit (PR ready)

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
dukeofdummies
Posts: 1
Joined: Sat Nov 28, 2020 1:37 am

Re: Constraint icons size at Sketcher edit

Postby dukeofdummies » Sat Nov 28, 2020 5:14 pm

Is there currently any plans to roll this into .19? Or any way to implement it on the current version?

Currently trying to switch from fusion to freecad on a 4k screen and I didn't even realize those symbols were even there. I spent an hour just trying to "turn them on", only to find out that they're just that small.
Elyas
Posts: 41
Joined: Fri Sep 04, 2020 12:25 pm

Re: Constraint icons size at Sketcher edit

Postby Elyas » Fri Dec 11, 2020 9:17 am

Scalable icons patch:
The size of the icons is related to the font size of the constraints

Code: Select all

diff --git b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp
index 6fbe9fccb..1dc6e4571 100644
--- b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp
+++ a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp
@@ -70,6 +70,7 @@
 # include <QPainter>
 # include <QTextStream>
 # include <QKeyEvent>
+#include <QDesktopWidget>
 
 # include <boost_bind_bind.hpp>
 # include <boost/scoped_ptr.hpp>
@@ -362,6 +363,7 @@ ViewProviderSketch::ViewProviderSketch()
 
     //rubberband selection
     rubberband = new Gui::Rubberband();
+    InitItemsSizes();
 }
 
 ViewProviderSketch::~ViewProviderSketch()
@@ -2961,7 +2963,11 @@ QString ViewProviderSketch::getPresentationString(const Constraint *constraint)
             }
         }
     }
-
+    if(constraint->Type == Sketcher::Diameter){
+        userStr.insert(0,QChar(8960));
+    }else if(constraint->Type == Sketcher::Radius){
+        userStr.insert(0,QChar(82));
+    }
     return userStr;
 }
 
@@ -2970,25 +2976,25 @@ QString ViewProviderSketch::iconTypeFromConstraint(Constraint *constraint)
     /*! TODO: Consider pushing this functionality up into Constraint */
     switch(constraint->Type) {
     case Horizontal:
-        return QString::fromLatin1("small/Constraint_Horizontal_sm");
+        return QString::fromLatin1("Constraint_Horizontal");
     case Vertical:
-        return QString::fromLatin1("small/Constraint_Vertical_sm");
+        return QString::fromLatin1("Constraint_Vertical");
     case PointOnObject:
-        return QString::fromLatin1("small/Constraint_PointOnObject_sm");
+        return QString::fromLatin1("Constraint_PointOnObject");
     case Tangent:
-        return QString::fromLatin1("small/Constraint_Tangent_sm");
+        return QString::fromLatin1("Constraint_Tangent");
     case Parallel:
-        return QString::fromLatin1("small/Constraint_Parallel_sm");
+        return QString::fromLatin1("Constraint_Parallel");
     case Perpendicular:
-        return QString::fromLatin1("small/Constraint_Perpendicular_sm");
+        return QString::fromLatin1("Constraint_Perpendicular");
     case Equal:
-        return QString::fromLatin1("small/Constraint_EqualLength_sm");
+        return QString::fromLatin1("Constraint_EqualLength");
     case Symmetric:
-        return QString::fromLatin1("small/Constraint_Symmetric_sm");
+        return QString::fromLatin1("Constraint_Symmetric");
     case SnellsLaw:
-        return QString::fromLatin1("small/Constraint_SnellsLaw_sm");
+        return QString::fromLatin1("Constraint_SnellsLaw");
     case Block:
-        return QString::fromLatin1("small/Constraint_Block_sm");
+        return QString::fromLatin1("Constraint_Block");
     default:
         return QString();
     }
@@ -3418,10 +3424,10 @@ QImage ViewProviderSketch::renderConstrIcon(const QString &type,
     // Constants to help create constraint icons
     QString joinStr = QString::fromLatin1(", ");
 
-    QImage icon = Gui::BitmapFactory().pixmap(type.toLatin1()).toImage();
+    QImage icon = Gui::BitmapFactory().pixmapFromSvg(type.toLatin1().data(),QSizeF(constraintIconSize,constraintIconSize)).toImage();
 
     QFont font = QApplication::font();
-    font.setPixelSize(11);
+    font.setPixelSize(constraintIconSize * 0.8);
     font.setBold(true);
     QFontMetrics qfm = QFontMetrics(font);
 
@@ -3520,6 +3526,18 @@ float ViewProviderSketch::getScaleFactor()
     }
 }
 
+void ViewProviderSketch::InitItemsSizes()
+{
+    int defaultFontSize = QApplication::fontMetrics().height();
+    int ldpi = QApplication::desktop()->logicalDpiX();
+    float k = 96./ldpi;
+    float view3D_factor = 1.25;
+    ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View");
+    coinFontSize = hGrp->GetInt("EditSketcherFontSize", defaultFontSize * k * k *view3D_factor );
+    constraintIconSize = coinFontSize / k;
+    return;
+}
+
 void ViewProviderSketch::draw(bool temp /*=false*/, bool rebuildinformationlayer /*=true*/)
 {
     assert(edit);
@@ -3555,9 +3573,6 @@ void ViewProviderSketch::draw(bool temp /*=false*/, bool rebuildinformationlayer
         Gui::coinRemoveAllChildren(edit->infoGroup);
     }
 
-    ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View");
-    int fontSize = hGrp->GetInt("EditSketcherFontSize", 17);
-
     int currentInfoNode = 0;
 
     ParameterGrp::handle hGrpsk = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher/General");
@@ -3570,6 +3585,7 @@ void ViewProviderSketch::draw(bool temp /*=false*/, bool rebuildinformationlayer
 
     int GeoId = 0;
 
+    ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View");
     int stdcountsegments = hGrp->GetInt("SegmentsPerGeometry", 50);
     // value cannot be smaller than 3
     if (stdcountsegments < 3)
@@ -3924,7 +3940,7 @@ void ViewProviderSketch::draw(bool temp /*=false*/, bool rebuildinformationlayer
 
             SoFont *font = new SoFont;
             font->name.setValue("Helvetica");
-            font->size.setValue(fontSize);
+            font->size.setValue(coinFontSize);
 
             SoText2 *degreetext = new SoText2;
             degreetext->string = SbString(spline->getDegree());
@@ -4203,7 +4219,7 @@ void ViewProviderSketch::draw(bool temp /*=false*/, bool rebuildinformationlayer
 
                 SoFont *font = new SoFont;
                 font->name.setValue("Helvetica");
-                font->size.setValue(fontSize);
+                font->size.setValue(coinFontSize);
 
                 SoText2 *degreetext = new SoText2;
                 degreetext->string = SbString("(") + SbString(*itm) + SbString(")");
@@ -4270,7 +4286,7 @@ void ViewProviderSketch::draw(bool temp /*=false*/, bool rebuildinformationlayer
 
                 SoFont* font = new SoFont;
                 font->name.setValue("Helvetica");
-                font->size.setValue(fontSize);
+                font->size.setValue(coinFontSize);
 
                 translate->translation.setValue(poleposition.x, poleposition.y, zInfo);
 
@@ -5419,9 +5435,6 @@ void ViewProviderSketch::rebuildConstraintsVisual(void)
     Gui::coinRemoveAllChildren(edit->constrGroup);
     edit->vConstrType.clear();
 
-    ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View");
-    int fontSize = hGrp->GetInt("EditSketcherFontSize", 17);
-
     for (std::vector<Sketcher::Constraint *>::const_iterator it=constrlist.begin(); it != constrlist.end(); ++it) {
         // root separator for one constraint
         SoSeparator *sep = new SoSeparator();
@@ -5465,7 +5478,7 @@ void ViewProviderSketch::rebuildConstraintsVisual(void)
                                             ConstrDimColor
                                             :NonDrivingConstrDimColor)
                                         :DeactivatedConstrDimColor;
-                text->size.setValue(fontSize);
+                text->size.setValue(coinFontSize);
                 text->useAntialiasing = false;
                 SoAnnotation *anno = new SoAnnotation();
                 anno->renderCaching = SoSeparator::OFF;
@@ -6134,10 +6147,9 @@ void ViewProviderSketch::createEditInventorNodes(void)
     CoordTextMaterials->diffuseColor = cursorTextColor;
     Coordsep->addChild(CoordTextMaterials);
 
-    int fontSize = hGrp->GetInt("EditSketcherFontSize", 17);
-
     SoFont *font = new SoFont();
-    font->size.setValue(fontSize);
+    font->size.setValue(coinFontSize);
+
     Coordsep->addChild(font);
 
     edit->textPos = new SoTranslation();
diff --git b/src/Mod/Sketcher/Gui/ViewProviderSketch.h a/src/Mod/Sketcher/Gui/ViewProviderSketch.h
index ffb3a571e..0dce9811a 100644
--- b/src/Mod/Sketcher/Gui/ViewProviderSketch.h
+++ a/src/Mod/Sketcher/Gui/ViewProviderSketch.h
@@ -109,6 +109,9 @@ public:
     App::PropertyBool RestoreCamera;
     App::PropertyString EditingWorkbench;
 
+    /// set icon & font sizes
+    void InitItemsSizes();
+
     /// Draw all constraint icons
     /*! Except maybe the radius and lock ones? */
     void drawConstraintIcons();
@@ -285,7 +288,6 @@ protected:
     boost::signals2::connection connectRedoDocument;
 
     void forceUpdateData();
-
     /// Return display string for constraint including hiding units if
     //requested.
     QString getPresentationString(const Sketcher::Constraint *constraint);
@@ -439,6 +441,9 @@ protected:
     bool isShownVirtualSpace; // indicates whether the present virtual space view is the Real Space or the Virtual Space (virtual space 1 or 2)
 
     ShortcutListener* listener;
+
+    int coinFontSize;
+    int constraintIconSize;
 };
 
 } // namespace PartGui
  • Calculations and access to settings are collected in one place.
  • Default based on system font size
  • and also Symbol for diameter and radius
User avatar
Kunda1
Posts: 9222
Joined: Thu Jan 05, 2017 9:03 pm

Re: Constraint icons size at Sketcher edit

Postby Kunda1 » Fri Dec 11, 2020 2:10 pm

Cool! Can you make a pull request so that we can review the code in context? Also that Abdullah could take a look at it as well
Alone you go faster. Together we go farther
Want to contribute back to FC? Checkout:
#lowhangingfruit | Use the Source, Luke. | How to Help FreeCAD | How to report FC bugs and features
Elyas
Posts: 41
Joined: Fri Sep 04, 2020 12:25 pm

Re: Constraint icons size at Sketcher edit

Postby Elyas » Tue Dec 15, 2020 10:15 am

User avatar
Kunda1
Posts: 9222
Joined: Thu Jan 05, 2017 9:03 pm

Re: Constraint icons size at Sketcher edit

Postby Kunda1 » Tue Dec 15, 2020 11:57 am

abdullah wrote: pinged by pinger macro
Hi @Abdullah care to weigh in? Do you have a HiDPI screen to test this on?
Alone you go faster. Together we go farther
Want to contribute back to FC? Checkout:
#lowhangingfruit | Use the Source, Luke. | How to Help FreeCAD | How to report FC bugs and features
abdullah
Posts: 3883
Joined: Sun May 04, 2014 3:16 pm

Re: Constraint icons size at Sketcher edit

Postby abdullah » Tue Dec 15, 2020 3:54 pm

Kunda1 wrote:
Tue Dec 15, 2020 11:57 am
abdullah wrote: pinged by pinger macro
Hi @Abdullah care to weigh in? Do you have a HiDPI screen to test this on?
Unfortunately my monitor is not HiDPI...
Elyas
Posts: 41
Joined: Fri Sep 04, 2020 12:25 pm

Re: Constraint icons size at Sketcher edit

Postby Elyas » Wed Dec 16, 2020 6:45 am

Yes, these changes are most useful on hidpi, but no hidpi display is required to test functionality new code.
User avatar
vanuan
Posts: 497
Joined: Wed Oct 24, 2018 9:49 pm

Re: Constraint icons size at Sketcher edit

Postby vanuan » Thu Dec 17, 2020 3:24 am

Made some suggestions in the PR.

I don't think the suggested changes work in HiDPI yet. It appears to me that Coin3D uses global scaling, so it would still be pixelised.

The changes suggested here is to make the icon size relative to font size. Which is a pre-requisite to the HiDPI support but not the support itself. That is when you change the Display scaling option, the 3D view would still appear pixelized. Proper HiDPI support in Coin requires much more work.

So to test this, just make sure that the sketcher font size setting affects the constraint icon size. I.e. when you increase sketcher font, the constrain icon becomes bigger and becomes smaller when you decrease it.
kisolre
Posts: 3011
Joined: Wed Nov 21, 2018 1:13 pm

Re: Constraint icons size at Sketcher edit

Postby kisolre » Thu Dec 17, 2020 7:54 am

User/developer clash: https://forum.freecadweb.org/viewtopic. ... 10#p457662
A development that concerns all users is hidden from the regular users in development forum. And it just happens to be recently commented here so I noted that thread... I came here because CrisB mentioned in a thread that he commented in the corresponding thread in the dev forum... which was not mentioned anywhere in the original thread...

On topic: with the parameter and scaling applied in the code of that thread just the constraint icons (and their text numbers) can be scaled and I find it that I can see them better at 1.5 scale on my regular DPI screen. For me personally having the ability to adjust different elements differently is better. I think that such changes should be exposed to broad user audience in Open Discussion subforum before they get included/locked in the code.
User avatar
vanuan
Posts: 497
Joined: Wed Oct 24, 2018 9:49 pm

Re: Constraint icons size at Sketcher edit

Postby vanuan » Thu Dec 17, 2020 4:18 pm

kisolre wrote:
Thu Dec 17, 2020 7:54 am
On topic: with the parameter and scaling applied in the code of that thread just the constraint icons (and their text numbers) can be scaled and I find it that I can see them better at 1.5 scale on my regular DPI screen. For me personally having the ability to adjust different elements differently is better. I think that such changes should be exposed to broad user audience in Open Discussion subforum before they get included/locked in the code.
Let's make a step back to see the issue before jumping into a solution.

As it works now, the constraint icon size is taken as it is specified in XPM files: icons/small/Constraint_XXX.xpm
The constraint subindex (the text next to the constraint icon is hardcoded to 11 pixels)
Also, there's a setting for the sketcher text (17 pixels by default)

So, all these sizes are not related to each other and set independently.

I happens that on some screens (large device resolution, small physical size of the monitor) they appear to be small to a human eye.

What's the solution here?

You might quickly jump to the solution of making an additional user setting "scale factor" and multiply everything by it.
It might work for your immediate use case and other users can change the setting.

But it makes a bad UX. What's so special about FreeCAD that every single option must be user configurable? Wouldn't it be nice if it just sized all its UI elements relative to the system's font like every other application?

So the ideal solution would be this:
  • Take the system font in points
  • Make all the fonts be specified in relative units to that system font (1.5, 0.8, etc)
  • Make all the icons be sized in relation to the font size (pixelSize = pointSize / 72 * dpi_ratio)
  • Make sure we take into an account the device pixel ratio (fonts specified in points should remain the same, while the pixel size should increase according to DPR)

Here we see two half-baked solutions. One lacks proper scaling (or rather OS display text size / scaling setting), another lacks the UI element sizing relative to the system font.