Draft: Allow to change grid color in WP taskpanel
This commit is contained in:
@@ -243,6 +243,20 @@ value by using the [ and ] keys while drawing</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout_4">
|
||||
<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>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<item row="0" column="0">
|
||||
@@ -291,6 +305,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/>
|
||||
|
||||
@@ -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())
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user