Merge pull request #13051 from yorikvanhavre/draft-wp-set-color

Draft: Allow to change grid color in WP taskpanel
This commit is contained in:
Roy-043
2024-03-26 11:17:13 +01:00
committed by GitHub
3 changed files with 57 additions and 22 deletions

View File

@@ -153,6 +153,16 @@ will be moved to the center of the view</string>
</item>
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label_9">
<property name="text">
<string>Grid color</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="Gui::ColorButton" name="buttonColor"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_3">
<property name="toolTip">
@@ -291,6 +301,11 @@ value by using the [ and ] keys while drawing</string>
<extends>QLineEdit</extends>
<header>Gui/InputField.h</header>
</customwidget>
<customwidget>
<class>Gui::ColorButton</class>
<extends>QPushButton</extends>
<header>Gui/Widgets.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>

View File

@@ -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,6 +113,10 @@ class Draft_SelectPlane:
form.buttonPrevious.setIcon(QtGui.QIcon(":/icons/sel-back.svg"))
form.buttonNext.setIcon(QtGui.QIcon(":/icons/sel-forward.svg"))
# Grid color
color = params.get_param("gridColor")
form.buttonColor.setProperty("color", QtGui.QColor(utils.rgba_to_argb(color)))
# Connect slots
form.buttonTop.clicked.connect(self.on_click_top)
form.buttonFront.clicked.connect(self.on_click_front)
@@ -128,6 +133,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 +282,9 @@ class Draft_SelectPlane:
if hasattr(Gui, "Snapper"):
Gui.Snapper.showradius()
def on_color_changed(self):
color = utils.argb_to_rgba(self.taskd.form.buttonColor.property("color").rgba())
params.set_param("gridColor", color)
Gui.addCommand('Draft_SelectPlane', Draft_SelectPlane())

View File

@@ -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.8*(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.2*(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)
@@ -1182,6 +1173,26 @@ class gridTracker(Tracker):
#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.
The silhouette is displayed only if: