From d0a87573c960cf948612e2b16c5c866bf7911541 Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Wed, 20 Mar 2024 12:20:31 +0100 Subject: [PATCH 1/3] Draft: Allow to change grid color in WP taskpanel --- src/Mod/Draft/Resources/ui/TaskSelectPlane.ui | 19 +++++++ .../Draft/draftguitools/gui_selectplane.py | 13 +++++ src/Mod/Draft/draftguitools/gui_trackers.py | 54 +++++++++++-------- 3 files changed, 64 insertions(+), 22 deletions(-) diff --git a/src/Mod/Draft/Resources/ui/TaskSelectPlane.ui b/src/Mod/Draft/Resources/ui/TaskSelectPlane.ui index 62d9028ba4..b744c1c377 100644 --- a/src/Mod/Draft/Resources/ui/TaskSelectPlane.ui +++ b/src/Mod/Draft/Resources/ui/TaskSelectPlane.ui @@ -243,6 +243,20 @@ value by using the [ and ] keys while drawing + + + + + + Grid color + + + + + + + + @@ -291,6 +305,11 @@ value by using the [ and ] keys while drawing QLineEdit
Gui/InputField.h
+ + Gui::ColorButton + QPushButton +
Gui/Widgets.h
+
diff --git a/src/Mod/Draft/draftguitools/gui_selectplane.py b/src/Mod/Draft/draftguitools/gui_selectplane.py index 0c2fd18567..ea0b99d515 100644 --- a/src/Mod/Draft/draftguitools/gui_selectplane.py +++ b/src/Mod/Draft/draftguitools/gui_selectplane.py @@ -112,6 +112,13 @@ class Draft_SelectPlane: form.buttonPrevious.setIcon(QtGui.QIcon(":/icons/sel-back.svg")) form.buttonNext.setIcon(QtGui.QIcon(":/icons/sel-forward.svg")) + # color and transparency + color = params.get_param("gridColor") + r = ((color >> 24) & 0xFF) / 255.0 + g = ((color >> 16) & 0xFF) / 255.0 + b = ((color >> 8) & 0xFF) / 255.0 + form.buttonColor.setProperty("color", QtGui.QColor.fromRgbF(r, g, b)) + # Connect slots form.buttonTop.clicked.connect(self.on_click_top) form.buttonFront.clicked.connect(self.on_click_front) @@ -128,6 +135,7 @@ class Draft_SelectPlane: form.fieldGridMainLine.valueChanged.connect(self.on_set_main_line) form.fieldGridExtension.valueChanged.connect(self.on_set_extension) form.fieldSnapRadius.valueChanged.connect(self.on_set_snap_radius) + form.buttonColor.changed.connect(self.on_color_changed) # Enable/disable buttons. form.buttonPrevious.setEnabled(self.wp._has_previous()) @@ -276,6 +284,11 @@ class Draft_SelectPlane: if hasattr(Gui, "Snapper"): Gui.Snapper.showradius() + def on_color_changed(self): + color = self.taskd.form.buttonColor.property("color").rgb() << 8 + params.set_param("gridColor", color) + if self.grid is not None: + self.grid.update() Gui.addCommand('Draft_SelectPlane', Draft_SelectPlane()) diff --git a/src/Mod/Draft/draftguitools/gui_trackers.py b/src/Mod/Draft/draftguitools/gui_trackers.py index 2789ada488..f73a1f3031 100644 --- a/src/Mod/Draft/draftguitools/gui_trackers.py +++ b/src/Mod/Draft/draftguitools/gui_trackers.py @@ -1001,25 +1001,16 @@ class gridTracker(Tracker): def __init__(self): - gtrans = params.get_param("gridTransparency") - col = utils.get_rgba_tuple(params.get_param("gridColor"))[:3] - if params.get_param("coloredGridAxes"): - red = ((1.0+col[0])/2,0.0,0.0) - green = (0.0,(1.0+col[1])/2,0.0) - blue = (0.0,0.0,(1.0+col[2])/2) - else: - red = col - green = col - blue = col + col, red, green, blue, gtrans = self.getGridColors() pick = coin.SoPickStyle() pick.style.setValue(coin.SoPickStyle.UNPICKABLE) self.trans = coin.SoTransform() self.trans.translation.setValue([0, 0, 0]) # small squares - mat1 = coin.SoMaterial() - mat1.transparency.setValue(0.7*(1-gtrans)) - mat1.diffuseColor.setValue(col) + self.mat1 = coin.SoMaterial() + self.mat1.transparency.setValue(0.7*(1-gtrans)) + self.mat1.diffuseColor.setValue(col) self.font = coin.SoFont() self.coords1 = coin.SoCoordinate3() self.lines1 = coin.SoLineSet() # small squares @@ -1044,9 +1035,9 @@ class gridTracker(Tracker): texts.addChild(t2) # big squares - mat2 = coin.SoMaterial() - mat2.transparency.setValue(0.3*(1-gtrans)) - mat2.diffuseColor.setValue(col) + self.mat2 = coin.SoMaterial() + self.mat2.transparency.setValue(0.3*(1-gtrans)) + self.mat2.diffuseColor.setValue(col) self.coords2 = coin.SoCoordinate3() self.lines2 = coin.SoLineSet() # big squares @@ -1058,9 +1049,9 @@ class gridTracker(Tracker): self.human = coin.SoLineSet() # axes - mat3 = coin.SoMaterial() - mat3.transparency.setValue(gtrans) - mat3.diffuseColor.setValues([col,red,green,blue]) + self.mat3 = coin.SoMaterial() + self.mat3.transparency.setValue(gtrans) + self.mat3.diffuseColor.setValues([col,red,green,blue]) self.coords3 = coin.SoCoordinate3() self.lines3 = coin.SoIndexedLineSet() # axes self.lines3.coordIndex.setValues(0,5,[0,1,-1,2,3]) @@ -1072,17 +1063,17 @@ class gridTracker(Tracker): s = coin.SoType.fromName("SoSkipBoundingGroup").createInstance() s.addChild(pick) s.addChild(self.trans) - s.addChild(mat1) + s.addChild(self.mat1) s.addChild(self.coords1) s.addChild(self.lines1) - s.addChild(mat2) + s.addChild(self.mat2) s.addChild(self.coords2) s.addChild(self.lines2) s.addChild(mat_human) s.addChild(self.coords_human) s.addChild(self.human) s.addChild(mbind3) - s.addChild(mat3) + s.addChild(self.mat3) s.addChild(self.coords3) s.addChild(self.lines3) s.addChild(texts) @@ -1181,6 +1172,25 @@ class gridTracker(Tracker): self.coords3.point.setValues(apts) #self.lines3.numVertices.setValues(aidx) self.pts = pts + # update the grid colors + col, red, green, blue, gtrans = self.getGridColors() + self.mat1.diffuseColor.setValue(col) + self.mat2.diffuseColor.setValue(col) + self.mat3.diffuseColor.setValues([col,red,green,blue]) + + def getGridColors(self): + """Returns grid colors stored in the preferences""" + gtrans = params.get_param("gridTransparency")/100.0 + col = utils.get_rgba_tuple(params.get_param("gridColor"))[:3] + if params.get_param("coloredGridAxes"): + red = ((1.0+col[0])/2,0.0,0.0) + green = (0.0,(1.0+col[1])/2,0.0) + blue = (0.0,0.0,(1.0+col[2])/2) + else: + red = col + green = col + blue = col + return col, red, green, blue, gtrans def displayHumanFigure(self, wp): """ Display the human figure at the grid corner. From 70f2f147027413065615184b9961bdbf4cac10e4 Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Wed, 20 Mar 2024 13:35:40 +0100 Subject: [PATCH 2/3] Draft: a bit more contrast to the grid --- src/Mod/Draft/draftguitools/gui_trackers.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Mod/Draft/draftguitools/gui_trackers.py b/src/Mod/Draft/draftguitools/gui_trackers.py index f73a1f3031..a99a7a3701 100644 --- a/src/Mod/Draft/draftguitools/gui_trackers.py +++ b/src/Mod/Draft/draftguitools/gui_trackers.py @@ -42,6 +42,7 @@ import FreeCAD import FreeCADGui import Draft import DraftVecUtils +import WorkingPlane from FreeCAD import Vector from draftutils import params from draftutils import utils @@ -1009,7 +1010,7 @@ class gridTracker(Tracker): # small squares self.mat1 = coin.SoMaterial() - self.mat1.transparency.setValue(0.7*(1-gtrans)) + self.mat1.transparency.setValue(0.8*(1-gtrans)) self.mat1.diffuseColor.setValue(col) self.font = coin.SoFont() self.coords1 = coin.SoCoordinate3() @@ -1036,7 +1037,7 @@ class gridTracker(Tracker): # big squares self.mat2 = coin.SoMaterial() - self.mat2.transparency.setValue(0.3*(1-gtrans)) + self.mat2.transparency.setValue(0.2*(1-gtrans)) self.mat2.diffuseColor.setValue(col) self.coords2 = coin.SoCoordinate3() self.lines2 = coin.SoLineSet() # big squares @@ -1177,6 +1178,7 @@ class gridTracker(Tracker): self.mat1.diffuseColor.setValue(col) self.mat2.diffuseColor.setValue(col) self.mat3.diffuseColor.setValues([col,red,green,blue]) + self.setAxesColor() def getGridColors(self): """Returns grid colors stored in the preferences""" @@ -1220,8 +1222,12 @@ class gridTracker(Tracker): self.coords_human.point.setValues(pts) self.human.numVertices.setValues(pidx) - def setAxesColor(self, wp): + def setAxesColor(self, wp=None): """set axes color""" + if not wp: + wp = getattr(FreeCAD, "DraftWorkingPlane", None) + if not wp: + wp = WorkingPlane.plane() cols = [0,0] if params.get_param("coloredGridAxes"): if round(wp.u.getAngle(FreeCAD.Vector(1,0,0)),2) in (0,3.14): From f90b47cbbc8fd8f50ba7038e303d07349e76c225 Mon Sep 17 00:00:00 2001 From: Roy-043 Date: Sun, 24 Mar 2024 09:58:51 +0100 Subject: [PATCH 3/3] Let param observer trigger grid color change If you change the grid color in the preferences and cick the Apply button, the color of all grids is updated now. So you can experiment while the Preferences Editor is open. I have kept but moved the grid color button in the Draft_SelectPlane task panel for now. So that both options can be tested. --- src/Mod/Draft/Resources/ui/TaskSelectPlane.ui | 24 ++++++++----------- .../Draft/draftguitools/gui_selectplane.py | 12 ++++------ src/Mod/Draft/draftguitools/gui_trackers.py | 9 ++----- 3 files changed, 16 insertions(+), 29 deletions(-) diff --git a/src/Mod/Draft/Resources/ui/TaskSelectPlane.ui b/src/Mod/Draft/Resources/ui/TaskSelectPlane.ui index b744c1c377..16cb11103b 100644 --- a/src/Mod/Draft/Resources/ui/TaskSelectPlane.ui +++ b/src/Mod/Draft/Resources/ui/TaskSelectPlane.ui @@ -153,6 +153,16 @@ will be moved to the center of the view
+ + + + Grid color + + + + + + @@ -243,20 +253,6 @@ value by using the [ and ] keys while drawing - - - - - - Grid color - - - - - - - - diff --git a/src/Mod/Draft/draftguitools/gui_selectplane.py b/src/Mod/Draft/draftguitools/gui_selectplane.py index ea0b99d515..a229eac03c 100644 --- a/src/Mod/Draft/draftguitools/gui_selectplane.py +++ b/src/Mod/Draft/draftguitools/gui_selectplane.py @@ -37,6 +37,7 @@ import WorkingPlane from FreeCAD import Units from drafttaskpanels import task_selectplane from draftutils import params +from draftutils import utils from draftutils.messages import _msg from draftutils.todo import todo from draftutils.translate import translate @@ -112,12 +113,9 @@ class Draft_SelectPlane: form.buttonPrevious.setIcon(QtGui.QIcon(":/icons/sel-back.svg")) form.buttonNext.setIcon(QtGui.QIcon(":/icons/sel-forward.svg")) - # color and transparency + # Grid color color = params.get_param("gridColor") - r = ((color >> 24) & 0xFF) / 255.0 - g = ((color >> 16) & 0xFF) / 255.0 - b = ((color >> 8) & 0xFF) / 255.0 - form.buttonColor.setProperty("color", QtGui.QColor.fromRgbF(r, g, b)) + form.buttonColor.setProperty("color", QtGui.QColor(utils.rgba_to_argb(color))) # Connect slots form.buttonTop.clicked.connect(self.on_click_top) @@ -285,10 +283,8 @@ class Draft_SelectPlane: Gui.Snapper.showradius() def on_color_changed(self): - color = self.taskd.form.buttonColor.property("color").rgb() << 8 + color = utils.argb_to_rgba(self.taskd.form.buttonColor.property("color").rgba()) params.set_param("gridColor", color) - if self.grid is not None: - self.grid.update() Gui.addCommand('Draft_SelectPlane', Draft_SelectPlane()) diff --git a/src/Mod/Draft/draftguitools/gui_trackers.py b/src/Mod/Draft/draftguitools/gui_trackers.py index a99a7a3701..2f5e9e31f5 100644 --- a/src/Mod/Draft/draftguitools/gui_trackers.py +++ b/src/Mod/Draft/draftguitools/gui_trackers.py @@ -42,7 +42,6 @@ import FreeCAD import FreeCADGui import Draft import DraftVecUtils -import WorkingPlane from FreeCAD import Vector from draftutils import params from draftutils import utils @@ -1173,12 +1172,12 @@ class gridTracker(Tracker): self.coords3.point.setValues(apts) #self.lines3.numVertices.setValues(aidx) self.pts = pts + # update the grid colors col, red, green, blue, gtrans = self.getGridColors() self.mat1.diffuseColor.setValue(col) self.mat2.diffuseColor.setValue(col) self.mat3.diffuseColor.setValues([col,red,green,blue]) - self.setAxesColor() def getGridColors(self): """Returns grid colors stored in the preferences""" @@ -1222,12 +1221,8 @@ class gridTracker(Tracker): self.coords_human.point.setValues(pts) self.human.numVertices.setValues(pidx) - def setAxesColor(self, wp=None): + def setAxesColor(self, wp): """set axes color""" - if not wp: - wp = getattr(FreeCAD, "DraftWorkingPlane", None) - if not wp: - wp = WorkingPlane.plane() cols = [0,0] if params.get_param("coloredGridAxes"): if round(wp.u.getAngle(FreeCAD.Vector(1,0,0)),2) in (0,3.14):