Draft: Condensed the Draft toolbar style buttons into one with more options

This commit is contained in:
Yorik van Havre
2020-11-10 14:14:18 +01:00
parent 485b0b58a0
commit 88f5fc20b1
11 changed files with 562 additions and 43 deletions

View File

@@ -268,6 +268,7 @@ SET(Draft_GUI_tools
draftguitools/gui_dimension_ops.py
draftguitools/gui_lineslope.py
draftguitools/gui_layers.py
draftguitools/gui_setstyle.py
${Creator_tools}
${Modifier_tools}
draftguitools/README.md

View File

@@ -167,11 +167,14 @@ class DraftToolBar:
self.taskmode = 1 # Draft.getParam("UiMode",1)
# taskmode = 0 was used by draft toolbar that is now obsolete.
# print("taskmode: ",str(self.taskmode))
self.paramcolor = Draft.getParam("color",255)>>8
self.color = QtGui.QColor(self.paramcolor)
self.facecolor = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/View").GetUnsigned("DefaultShapeColor",4294967295)>>8
self.linewidth = Draft.getParam("linewidth",2)
self.fontsize = Draft.getParam("textheight",0.20)
# OBSOLETE - TO BE REMOVED
#self.paramcolor = Draft.getParam("color",255)>>8
#self.color = QtGui.QColor(self.paramcolor)
#self.facecolor = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/View").GetUnsigned("DefaultShapeColor",4294967295)>>8
#self.linewidth = Draft.getParam("linewidth",2)
#self.fontsize = Draft.getParam("textheight",0.20)
self.paramconstr = Draft.getParam("constructioncolor",746455039)>>8
self.constrMode = False
self.continueMode = False
@@ -489,6 +492,7 @@ class DraftToolBar:
QtCore.QObject.connect(self.textValue,QtCore.SIGNAL("textChanged()"),self.checkEnterText)
QtCore.QObject.connect(self.textOkButton,QtCore.SIGNAL("clicked()"),self.sendText)
QtCore.QObject.connect(self.zValue,QtCore.SIGNAL("returnPressed()"),self.setFocus)
# Draft Edit UI obsolete due to introduction of incommand context menu
# QtCore.QObject.connect(self.addButton,QtCore.SIGNAL("toggled(bool)"),self.setAddMode)
# QtCore.QObject.connect(self.delButton,QtCore.SIGNAL("toggled(bool)"),self.setDelMode)
@@ -496,6 +500,7 @@ class DraftToolBar:
# QtCore.QObject.connect(self.tangentButton,QtCore.SIGNAL("toggled(bool)"),self.setTangentMode)
# QtCore.QObject.connect(self.symmetricButton,QtCore.SIGNAL("toggled(bool)"),self.setSymmetricMode)
# QtCore.QObject.connect(self.arc3PtButton,QtCore.SIGNAL("toggled(bool)"),self.setArc3PtMode)
QtCore.QObject.connect(self.finishButton,QtCore.SIGNAL("pressed()"),self.finish)
QtCore.QObject.connect(self.closeButton,QtCore.SIGNAL("pressed()"),self.closeLine)
QtCore.QObject.connect(self.wipeButton,QtCore.SIGNAL("pressed()"),self.wipeLine)
@@ -545,35 +550,44 @@ class DraftToolBar:
self.wplabel.setText(translate("draft","Side"))
else:
self.wplabel.setText(translate("draft","Auto"))
self.constrButton = self._pushbutton("constrButton", self.toptray, hide=False, icon='Draft_Construction',checkable=True,square=True)
self.constrColor = QtGui.QColor(self.paramconstr)
self.colorButton = self._pushbutton("colorButton",self.bottomtray, hide=False,square=True)
self.colorPix = QtGui.QPixmap(16,16)
self.colorPix.fill(self.color)
self.colorButton.setIcon(QtGui.QIcon(self.colorPix))
self.facecolorButton = self._pushbutton("facecolorButton",self.bottomtray, hide=False,square=True)
self.facecolorPix = QtGui.QPixmap(16,16)
self.facecolorPix.fill(QtGui.QColor(self.facecolor))
self.facecolorButton.setIcon(QtGui.QIcon(self.facecolorPix))
p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/General")
bsize = p.GetInt("ToolbarIconSize",24)+2
self.widthButton = self._spinbox("widthButton", self.bottomtray, val=self.linewidth,hide=False,size=(bsize * 2,bsize))
self.widthButton.setSuffix("px")
self.fontsizeButton = self._spinbox("fontsizeButton",self.bottomtray, val=self.fontsize,vmax=999, hide=False,double=True,size=(bsize * 4,bsize))
# OBSOLETE - replaced by style button
#self.colorButton = self._pushbutton("colorButton",self.bottomtray, hide=False,square=True)
#self.colorPix = QtGui.QPixmap(16,16)
#self.colorPix.fill(self.color)
#self.colorButton.setIcon(QtGui.QIcon(self.colorPix))
#self.facecolorButton = self._pushbutton("facecolorButton",self.bottomtray, hide=False,square=True)
#self.facecolorPix = QtGui.QPixmap(16,16)
#self.facecolorPix.fill(QtGui.QColor(self.facecolor))
#self.facecolorButton.setIcon(QtGui.QIcon(self.facecolorPix))
#self.widthButton = self._spinbox("widthButton", self.bottomtray, val=self.linewidth,hide=False,size=(bsize * 2,bsize))
#self.widthButton.setSuffix("px")
#self.fontsizeButton = self._spinbox("fontsizeButton",self.bottomtray, val=self.fontsize,vmax=999, hide=False,double=True,size=(bsize * 4,bsize))
#self.applyButton = self._pushbutton("applyButton", self.toptray, hide=False, icon='Draft_Apply',square=True)
self.styleButton = self._pushbutton("stylebutton", self.toptray, icon='Draft_Apply',hide=False,width=120)
self.setStyleButton()
self.constrButton = self._pushbutton("constrButton", self.toptray, hide=False, icon='Draft_Construction',checkable=True,square=True)
self.constrColor = QtGui.QColor(self.paramconstr)
self.autoGroupButton = self._pushbutton("autoGroup",self.bottomtray,icon=":/icons/button_invalid.svg",hide=False,width=120)
self.autoGroupButton.setText("None")
self.autoGroupButton.setFlat(True)
self.applyButton = self._pushbutton("applyButton", self.toptray, hide=False, icon='Draft_Apply',square=True)
QtCore.QObject.connect(self.wplabel,QtCore.SIGNAL("pressed()"),self.selectplane)
QtCore.QObject.connect(self.colorButton,QtCore.SIGNAL("pressed()"),self.getcol)
QtCore.QObject.connect(self.facecolorButton,QtCore.SIGNAL("pressed()"),self.getfacecol)
QtCore.QObject.connect(self.widthButton,QtCore.SIGNAL("valueChanged(int)"),self.setwidth)
QtCore.QObject.connect(self.fontsizeButton,QtCore.SIGNAL("valueChanged(double)"),self.setfontsize)
QtCore.QObject.connect(self.applyButton,QtCore.SIGNAL("pressed()"),self.apply)
QtCore.QObject.connect(self.styleButton,QtCore.SIGNAL("pressed()"),self.setstyle)
QtCore.QObject.connect(self.constrButton,QtCore.SIGNAL("toggled(bool)"),self.toggleConstrMode)
QtCore.QObject.connect(self.autoGroupButton,QtCore.SIGNAL("pressed()"),self.runAutoGroup)
# OBSOLETE - replaced by style button
#QtCore.QObject.connect(self.colorButton,QtCore.SIGNAL("pressed()"),self.getcol)
#QtCore.QObject.connect(self.facecolorButton,QtCore.SIGNAL("pressed()"),self.getfacecol)
#QtCore.QObject.connect(self.widthButton,QtCore.SIGNAL("valueChanged(int)"),self.setwidth)
#QtCore.QObject.connect(self.fontsizeButton,QtCore.SIGNAL("valueChanged(double)"),self.setfontsize)
#QtCore.QObject.connect(self.applyButton,QtCore.SIGNAL("pressed()"),self.apply)
QtCore.QTimer.singleShot(2000,self.retranslateTray) # delay so translations get a chance to load
def setupStyle(self):
@@ -622,12 +636,15 @@ class DraftToolBar:
self.continueCmd.setText(translate("draft", "Continue")+" ("+inCommandShortcuts["Continue"][0]+")")
self.occOffset.setToolTip(translate("draft", "If checked, an OCC-style offset will be performed instead of the classic offset"))
self.occOffset.setText(translate("draft", "&OCC-style offset"))
# OBSOLETE
# self.addButton.setToolTip(translate("draft", "Add points to the current object"))
# self.delButton.setToolTip(translate("draft", "Remove points from the current object"))
# self.sharpButton.setToolTip(translate("draft", "Make Bezier node sharp"))
# self.tangentButton.setToolTip(translate("draft", "Make Bezier node tangent"))
# self.symmetricButton.setToolTip(translate("draft", "Make Bezier node symmetric"))
# self.arc3PtButton.setToolTip(translate("draft", "Toggle radius and angles arc editing"))
self.undoButton.setText(translate("draft", "&Undo (CTRL+Z)"))
self.undoButton.setToolTip(translate("draft", "Undo the last segment"))
self.closeButton.setText(translate("draft", "Close")+" ("+inCommandShortcuts["Close"][0]+")")
@@ -677,13 +694,17 @@ class DraftToolBar:
def retranslateTray(self,widget=None):
self.wplabel.setToolTip(translate("draft", "Current working plane")+":"+self.wplabel.text())
self.styleButton.setToolTip(translate("draft", "Change default style for new objects"))
self.constrButton.setToolTip(translate("draft", "Toggle construction mode"))
self.colorButton.setToolTip(translate("draft", "Current line color"))
self.facecolorButton.setToolTip(translate("draft", "Current face color"))
self.widthButton.setToolTip(translate("draft", "Current line width"))
self.fontsizeButton.setToolTip(translate("draft", "Current font size"))
self.applyButton.setToolTip(translate("draft", "Apply to selected objects"))
self.autoGroupButton.setToolTip(translate("draft", "Autogroup off"))
# OBSOLETE - replaced by style button
#self.colorButton.setToolTip(translate("draft", "Current line color"))
#self.facecolorButton.setToolTip(translate("draft", "Current face color"))
#self.widthButton.setToolTip(translate("draft", "Current line width"))
#self.fontsizeButton.setToolTip(translate("draft", "Current font size"))
#self.applyButton.setToolTip(translate("draft", "Apply to selected objects"))
#---------------------------------------------------------------------------
# Interface modes
@@ -913,12 +934,15 @@ class DraftToolBar:
self.isRelative.hide()
self.hasFill.hide()
self.finishButton.hide()
# OBSOLETE
# self.addButton.hide()
# self.delButton.hide()
# self.sharpButton.hide()
# self.tangentButton.hide()
# self.symmetricButton.hide()
# self.arc3PtButton.hide()
self.undoButton.hide()
self.closeButton.hide()
self.wipeButton.hide()
@@ -1176,6 +1200,8 @@ class DraftToolBar:
def getcol(self):
"""opens a color picker dialog"""
print("draft: warning: getcol() is obsolete")
return
oldColor = self.color
self.color=QtGui.QColorDialog.getColor(self.color)
if not QtGui.QColor.isValid(self.color): #user canceled
@@ -1200,6 +1226,8 @@ class DraftToolBar:
def getfacecol(self):
"""opens a color picker dialog"""
print("draft: warning: getfacecol() is obsolete")
return
oldColor = self.facecolor
self.facecolor=QtGui.QColorDialog.getColor(self.facecolor)
if not QtGui.QColor.isValid(self.facecolor): #user canceled
@@ -1218,6 +1246,8 @@ class DraftToolBar:
i.ViewObject.ShapeColor = col
def setwidth(self,val):
print("draft: warning: setwidth() is obsolete")
return
self.linewidth = float(val)
if Draft.getParam("saveonexit",False):
Draft.setParam("linewidth",int(val))
@@ -1226,6 +1256,8 @@ class DraftToolBar:
i.ViewObject.LineWidth = float(val)
def setfontsize(self,val):
print("draft: warning: setfontsize() is obsolete")
return
self.fontsize = float(val)
if Draft.getParam("saveonexit",False):
Draft.setParam("textheight",float(val))
@@ -1240,6 +1272,8 @@ class DraftToolBar:
self.fillmode = bool(val)
def apply(self):
print("draft: warning: apply() is obsolete")
return
for i in FreeCADGui.Selection.getSelection():
Draft.formatObject(i)
@@ -1652,9 +1686,20 @@ class DraftToolBar:
g = ((color>>16)&0xFF)/255
b = ((color>>8)&0xFF)/255
elif type == "ui":
print("draft: deprecation warning: Do not use getDefaultColor(\"ui\") anymore - use getDefaultColor(\"line\") instead.")
r = float(self.color.red()/255.0)
g = float(self.color.green()/255.0)
b = float(self.color.blue()/255.0)
elif type == "line":
color = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/View").GetUnsigned("DefaultShapeLineColor",255)
r = ((color>>24)&0xFF)/255
g = ((color>>16)&0xFF)/255
b = ((color>>8)&0xFF)/255
elif type == "text":
color = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft").GetUnsigned("DefaultTextColor",255)
r = ((color>>24)&0xFF)/255
g = ((color>>16)&0xFF)/255
b = ((color>>8)&0xFF)/255
elif type == "face":
color = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/View").GetUnsigned("DefaultShapeColor",4294967295)
r = ((color>>24)&0xFF)/255
@@ -1720,6 +1765,31 @@ class DraftToolBar:
def selectplane(self):
FreeCADGui.runCommand("Draft_SelectPlane")
def setstyle(self):
FreeCADGui.runCommand("Draft_SetStyle")
def setStyleButton(self):
"sets icon and text on the style button"
linecolor = QtGui.QColor(Draft.getParam("color",255)>>8)
facecolor = QtGui.QColor(FreeCAD.ParamGet("User parameter:BaseApp/Preferences/View").GetUnsigned("DefaultShapeColor",4294967295)>>8)
im = QtGui.QImage(32,32,QtGui.QImage.Format_ARGB32)
im.fill(QtCore.Qt.transparent)
pt = QtGui.QPainter(im)
pt.setPen(QtGui.QPen(QtCore.Qt.black, 1, QtCore.Qt.SolidLine, QtCore.Qt.FlatCap))
pt.setBrush(QtGui.QBrush(linecolor, QtCore.Qt.SolidPattern))
pts = [QtCore.QPointF(4.0,4.0),QtCore.QPointF(4.0,26.0),QtCore.QPointF(26.0,4.0)]
pt.drawPolygon(pts,QtCore.Qt.OddEvenFill)
pt.setBrush(QtGui.QBrush(facecolor, QtCore.Qt.SolidPattern))
pts = [QtCore.QPointF(28.0,28.0),QtCore.QPointF(8.0,28.0),QtCore.QPointF(28.0,8.0)]
pt.drawPolygon(pts,QtCore.Qt.OddEvenFill)
pt.end()
icon = QtGui.QIcon(QtGui.QPixmap.fromImage(im))
linewidth = Draft.getParam("linewidth",2)
fontsize = Draft.getParam("textheight",0.20)
txt = str(linewidth)+"px | "+FreeCAD.Units.Quantity(fontsize,FreeCAD.Units.Length).UserString
self.styleButton.setIcon(icon)
self.styleButton.setText(txt)
def popupMenu(self,llist,ilist=None,pos=None):
"""pops up a menu filled with the given list"""
self.groupmenu = QtGui.QMenu()

View File

@@ -76,6 +76,7 @@ if not hasattr(FreeCAD, "DraftWorkingPlane"):
# ---------------------------------------------------------------------------
import draftguitools.gui_edit
import draftguitools.gui_selectplane
import draftguitools.gui_setstyle
import draftguitools.gui_planeproxy
from draftguitools.gui_lineops import FinishLine
from draftguitools.gui_lineops import CloseLine

View File

@@ -181,5 +181,6 @@
<file>ui/TaskSelectPlane.ui</file>
<file>ui/TaskShapeString.ui</file>
<file>ui/dialog_AnnotationStyleEditor.ui</file>
<file>ui/TaskPanel_SetStyle.ui</file>
</qresource>
</RCC>

View File

@@ -0,0 +1,315 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Form</class>
<widget class="QWidget" name="Form">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>251</width>
<height>461</height>
</rect>
</property>
<property name="windowTitle">
<string>Style settings</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout_2">
<item row="8" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Text color</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Shape color</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Line width</string>
</property>
</widget>
</item>
<item row="4" column="2">
<widget class="Gui::ColorButton" name="ShapeColor">
<property name="toolTip">
<string>The color of faces</string>
</property>
</widget>
</item>
<item row="9" column="2">
<widget class="QComboBox" name="ArrowStyle">
<property name="toolTip">
<string>The type of dimension arrows</string>
</property>
<item>
<property name="text">
<string>Dot</string>
</property>
</item>
<item>
<property name="text">
<string>Circle</string>
</property>
</item>
<item>
<property name="text">
<string>Arrow</string>
</property>
</item>
<item>
<property name="text">
<string>Tick</string>
</property>
</item>
<item>
<property name="text">
<string>Tick-2</string>
</property>
</item>
</widget>
</item>
<item row="8" column="2">
<widget class="Gui::ColorButton" name="TextColor">
<property name="toolTip">
<string>The color of texts and dimension texts</string>
</property>
</widget>
</item>
<item row="7" column="2">
<widget class="Gui::InputField" name="TextSize">
<property name="toolTip">
<string>The size of texts and dimension texts</string>
</property>
<property name="unit" stdset="0">
<string notr="true"/>
</property>
</widget>
</item>
<item row="11" column="0">
<widget class="QLabel" name="label_13">
<property name="text">
<string>Show unit</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Line color</string>
</property>
</widget>
</item>
<item row="10" column="2">
<widget class="Gui::InputField" name="ArrowSize">
<property name="toolTip">
<string>The size of dimension arrows</string>
</property>
<property name="unit" stdset="0">
<string notr="true"/>
</property>
</widget>
</item>
<item row="6" column="2">
<widget class="QFontComboBox" name="TextFont">
<property name="sizePolicy">
<sizepolicy hsizetype="Ignored" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>The font to use for texts and dimensions</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QComboBox" name="DrawStyle">
<property name="toolTip">
<string>The line style</string>
</property>
<item>
<property name="text">
<string>Solid</string>
</property>
</item>
<item>
<property name="text">
<string>Dashed</string>
</property>
</item>
<item>
<property name="text">
<string>Dotted</string>
</property>
</item>
<item>
<property name="text">
<string>DashDot</string>
</property>
</item>
</widget>
</item>
<item row="7" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Text size</string>
</property>
</widget>
</item>
<item row="12" column="0">
<widget class="QLabel" name="label_14">
<property name="text">
<string>Unit override</string>
</property>
</widget>
</item>
<item row="11" column="2">
<widget class="QCheckBox" name="ShowUnit">
<property name="toolTip">
<string>If the unit siffix is shown on dimension texts or not</string>
</property>
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="12" column="2">
<widget class="QLineEdit" name="UnitOverride">
<property name="toolTip">
<string>The unit to use for dimensions. Leave blank to use current FreeCAD unit</string>
</property>
</widget>
</item>
<item row="5" column="2">
<widget class="QSpinBox" name="Transparency">
<property name="toolTip">
<string>The transparency of faces</string>
</property>
<property name="suffix">
<string> %</string>
</property>
<property name="maximum">
<number>100</number>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_12">
<property name="text">
<string>Transparency</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_11">
<property name="text">
<string>Display mode</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Text font</string>
</property>
</widget>
</item>
<item row="10" column="0">
<widget class="QLabel" name="label_8">
<property name="text">
<string>Arrow size</string>
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QComboBox" name="DisplayMode">
<property name="toolTip">
<string>The display mode for faces</string>
</property>
<item>
<property name="text">
<string>Flat Lines</string>
</property>
</item>
<item>
<property name="text">
<string>Wireframe</string>
</property>
</item>
<item>
<property name="text">
<string>Shaded</string>
</property>
</item>
<item>
<property name="text">
<string>Points</string>
</property>
</item>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_10">
<property name="text">
<string>Draw style</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="Gui::ColorButton" name="LineColor">
<property name="toolTip">
<string>The color of lines</string>
</property>
</widget>
</item>
<item row="9" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Arrow style</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QSpinBox" name="LineWidth">
<property name="suffix">
<string> px</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QPushButton" name="applyButton">
<property name="text">
<string>Apply to selected objects</string>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>Gui::InputField</class>
<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/>
</ui>

View File

@@ -0,0 +1,117 @@
# ***************************************************************************
# * Copyright (c) 2020 Yorik van Havre <yorik@uncreated.net> *
# * *
# * This program is free software; you can redistribute it and/or modify *
# * it under the terms of the GNU Lesser General Public License (LGPL) *
# * as published by the Free Software Foundation; either version 2 of *
# * the License, or (at your option) any later version. *
# * for detail see the LICENCE text file. *
# * *
# * This program is distributed in the hope that it will be useful, *
# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
# * GNU Library General Public License for more details. *
# * *
# * You should have received a copy of the GNU Library General Public *
# * License along with this program; if not, write to the Free Software *
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
# * USA *
# * *
# ***************************************************************************
"""Provides GUI tools to set up default styles."""
## @package gui_setstyle
# \ingroup draftguitools
# \brief Provides GUI tools to set Draft styles such as color or line width
## \addtogroup draftguitools
# @{
import FreeCAD
if FreeCAD.GuiUp:
import FreeCADGui
import Draft_rc
def QT_TRANSLATE_NOOP(ctx,txt):
return txt
__title__ = "FreeCAD Draft Workbench GUI Tools - Styling tools"
__author__ = ("Yorik van Havre")
__url__ = "https://www.freecadweb.org"
class Draft_SetStyle:
"""The Draft_SetStyle FreeCAD command definition."""
def GetResources(self):
d = {'Pixmap': 'Draft_Apply',
'Accel': "S, S",
'MenuText': QT_TRANSLATE_NOOP("Draft_SetStyle", "Set style"),
'ToolTip': QT_TRANSLATE_NOOP("Draft_SetStyle", "Sets default styles")}
return d
def Activated(self):
FreeCADGui.Control.showDialog(Draft_SetStyle_TaskPanel())
class Draft_SetStyle_TaskPanel:
"""The task panel for the Draft_SetStyle command"""
def __init__(self):
from PySide import QtCore,QtGui
self.p = "User parameter:BaseApp/Preferences/"
self.form = FreeCADGui.PySideUic.loadUi(":/ui/TaskPanel_SetStyle.ui")
self.form.setWindowIcon(QtGui.QIcon(":/icons/Draft_Apply.svg"))
self.form.applyButton.setIcon(QtGui.QIcon(":/icons/Draft_Apply.svg"))
self.form.LineColor.setProperty("color",self.getPrefColor("View","DefaultShapeLineColor",255))
self.form.LineWidth.setValue(FreeCAD.ParamGet(self.p+"View").GetInt("DefaultShapeLineWidth",2))
self.form.DrawStyle.setCurrentIndex(FreeCAD.ParamGet(self.p+"Mod/Draft").GetInt("DefaultDrawStyle",0))
self.form.DisplayMode.setCurrentIndex(FreeCAD.ParamGet(self.p+"Mod/Draft").GetInt("DefaultDisplayMode",0))
self.form.ShapeColor.setProperty("color",self.getPrefColor("View","DefaultShapeColor",4294967295))
self.form.Transparency.setValue(FreeCAD.ParamGet(self.p+"Mod/Draft").GetInt("DefaultTransparency",0))
self.form.TextFont.setCurrentFont(QtGui.QFont(FreeCAD.ParamGet(self.p+"Mod/Draft").GetString("textfont","Sans")))
self.form.TextSize.setText(FreeCAD.Units.Quantity(FreeCAD.ParamGet(self.p+"Mod/Draft").GetFloat("textheight",10),FreeCAD.Units.Length).UserString)
self.form.TextColor.setProperty("color",self.getPrefColor("Mod/Draft","DefaultTextColor",255))
self.form.ArrowStyle.setCurrentIndex(FreeCAD.ParamGet(self.p+"Mod/Draft").GetInt("dimsymbol",0))
self.form.ArrowSize.setText(FreeCAD.Units.Quantity(FreeCAD.ParamGet(self.p+"/Mod/Draft").GetFloat("arrowsize",5),FreeCAD.Units.Length).UserString)
self.form.ShowUnit.setChecked(FreeCAD.ParamGet(self.p+"Mod/Draft").GetBool("showUnit",True))
self.form.UnitOverride.setText(FreeCAD.ParamGet(self.p+"Mod/Draft").GetString("overrideUnit",""))
def getPrefColor(self,group,prop,default):
c = FreeCAD.ParamGet(self.p+group).GetUnsigned(prop,default)
r = ((c>>24)&0xFF)/255.0
g = ((c>>16)&0xFF)/255.0
b = ((c>>8)&0xFF)/255.0
from PySide import QtGui
return QtGui.QColor.fromRgbF(r,g,b)
def reject(self):
FreeCADGui.Control.closeDialog()
def accept(self):
FreeCAD.ParamGet(self.p+"View").SetUnsigned("DefaultShapeLineColor",self.form.LineColor.property("color").rgb()<<8)
FreeCAD.ParamGet(self.p+"View").SetInt("DefaultShapeLineWidth",self.form.LineWidth.value())
FreeCAD.ParamGet(self.p+"Mod/Draft").SetInt("DefaultDrawStyle",self.form.DrawStyle.currentIndex())
FreeCAD.ParamGet(self.p+"Mod/Draft").SetInt("DefaultDisplayMode",self.form.DisplayMode.currentIndex())
FreeCAD.ParamGet(self.p+"View").SetUnsigned("DefaultShapeColor",self.form.ShapeColor.property("color").rgb()<<8)
FreeCAD.ParamGet(self.p+"Mod/Draft").SetInt("DefaultTransparency",self.form.Transparency.value())
FreeCAD.ParamGet(self.p+"Mod/Draft").SetString("textfont",self.form.TextFont.currentFont().family())
FreeCAD.ParamGet(self.p+"Mod/Draft").SetFloat("textheight",FreeCAD.Units.Quantity(self.form.TextSize.text()).Value)
FreeCAD.ParamGet(self.p+"Mod/Draft").SetUnsigned("DefaultTextColor",self.form.TextColor.property("color").rgb()<<8)
FreeCAD.ParamGet(self.p+"Mod/Draft").SetInt("dimsymbol",self.form.ArrowStyle.currentIndex())
FreeCAD.ParamGet(self.p+"/Mod/Draft").SetFloat("arrowsize",FreeCAD.Units.Quantity(self.form.ArrowSize.text()).Value)
FreeCAD.ParamGet(self.p+"Mod/Draft").SetBool("showUnit",self.form.ShowUnit.isChecked())
FreeCAD.ParamGet(self.p+"Mod/Draft").SetString("overrideUnit",self.form.UnitOverride.text())
if hasattr(FreeCADGui,"draftToolBar"):
FreeCADGui.draftToolBar.setStyleButton()
self.reject()
FreeCADGui.addCommand('Draft_SetStyle', Draft_SetStyle())
## @}

View File

@@ -75,7 +75,7 @@ class Snapper:
meant to be used directly, they are all called when necessary by
the general snap() function.
The Snapper lives inside FreeCADGui once the Draft module has been
The Snapper lives inside Gui once the Draft module has been
loaded.
"""
@@ -333,6 +333,7 @@ class Snapper:
fp = self.cstr(lastpoint, constrain, point)
if self.trackLine and lastpoint and (not noTracker):
self.trackLine.p2(fp)
self.trackLine.color.rgb = Gui.draftToolBar.getDefaultColor("line")
self.trackLine.on()
# Set the arch point tracking
if lastpoint:
@@ -475,6 +476,7 @@ class Snapper:
self.running = False
if self.trackLine and lastpoint:
self.trackLine.p2(self.spoint)
self.trackLine.color.rgb = Gui.draftToolBar.getDefaultColor("line")
self.trackLine.on()
return self.spoint
@@ -512,6 +514,7 @@ class Snapper:
fp = self.cstr(lastpoint, constrain, winner[2])
if self.trackLine and lastpoint:
self.trackLine.p2(fp)
self.trackLine.color.rgb = Gui.draftToolBar.getDefaultColor("line")
self.trackLine.on()
# set the cursor
self.setCursor(winner[1])
@@ -573,6 +576,7 @@ class Snapper:
if self.extLine:
self.extLine.p1(tsnap[0])
self.extLine.p2(tsnap[2])
self.extLine.color.rgb = Gui.draftToolBar.getDefaultColor("line")
self.extLine.on()
self.setCursor(tsnap[1])
return tsnap[2], eline
@@ -586,6 +590,7 @@ class Snapper:
self.tracker.on()
if self.extLine:
self.extLine.p2(tsnap[2])
self.extLine.color.rgb = Gui.draftToolBar.getDefaultColor("line")
self.extLine.on()
self.setCursor(tsnap[1])
return tsnap[2], eline
@@ -599,6 +604,7 @@ class Snapper:
self.tracker.on()
if self.extLine:
self.extLine.p2(tsnap[2])
self.extLine.color.rgb = Gui.draftToolBar.getDefaultColor("line")
self.extLine.on()
self.setCursor(tsnap[1])
return tsnap[2], eline
@@ -640,6 +646,7 @@ class Snapper:
else:
self.extLine.p1(p0)
self.extLine.p2(np)
self.extLine.color.rgb = Gui.draftToolBar.getDefaultColor("line")
self.extLine.on()
self.setCursor('extension')
ne = Part.LineSegment(p0,np).toShape()
@@ -699,6 +706,7 @@ class Snapper:
self.extLine2.p1(p0)
self.extLine2.p2(p)
self.extLine.p2(p)
self.extLine.color.rgb = Gui.draftToolBar.getDefaultColor("line")
self.extLine2.on()
return p
return None
@@ -1705,6 +1713,7 @@ class Snapper:
if self.spoint and self.spoint not in self.holdPoints:
if self.holdTracker:
self.holdTracker.addCoords(self.spoint)
self.holdTracker.color.rgb = Gui.draftToolBar.getDefaultColor("line")
self.holdTracker.on()
self.holdPoints.append(self.spoint)

View File

@@ -60,8 +60,8 @@ class Tracker:
global Part, DraftGeomUtils
import Part, DraftGeomUtils
self.ontop = ontop
color = coin.SoBaseColor()
color.rgb = scolor or FreeCADGui.draftToolBar.getDefaultColor("ui")
self.color = coin.SoBaseColor()
self.color.rgb = scolor or FreeCADGui.draftToolBar.getDefaultColor("line")
drawstyle = coin.SoDrawStyle()
if swidth:
drawstyle.lineWidth = swidth
@@ -70,7 +70,7 @@ class Tracker:
drawstyle.lineWeight = 3
drawstyle.linePattern = 0x0f0f # 0xaa
node = coin.SoSeparator()
for c in [drawstyle, color] + children:
for c in [drawstyle, self.color] + children:
node.addChild(c)
self.switch = coin.SoSwitch() # this is the on/off switch
if name:

View File

@@ -84,7 +84,7 @@ def make_point(X=0, Y=0, Z=0, color=None, name = "Point", point_size= 5):
if App.GuiUp:
ViewProviderPoint(obj.ViewObject)
if hasattr(Gui,"draftToolBar") and (not color):
color = Gui.draftToolBar.getDefaultColor('ui')
color = Gui.draftToolBar.getDefaultColor('line')
obj.ViewObject.PointColor = (float(color[0]), float(color[1]), float(color[2]))
obj.ViewObject.PointSize = point_size
obj.ViewObject.Visibility = True

View File

@@ -350,7 +350,9 @@ def format_object(target, origin=None):
if ui:
doc = App.ActiveDocument
if ui.isConstructionMode():
col = fcol = ui.getDefaultColor("constr")
lcol = fcol = ui.getDefaultColor("constr")
tcol = lcol
fcol = lcol
grp = doc.getObject("Draft_Construction")
if not grp:
grp = doc.addObject("App::DocumentObjectGroup", "Draft_Construction")
@@ -359,25 +361,27 @@ def format_object(target, origin=None):
if hasattr(obrep, "Transparency"):
obrep.Transparency = 80
else:
col = ui.getDefaultColor("ui")
lcol = ui.getDefaultColor("line")
tcol = ui.getDefaultColor("text")
fcol = ui.getDefaultColor("face")
col = (float(col[0]), float(col[1]), float(col[2]), 0.0)
lcol = (float(lcol[0]), float(lcol[1]), float(lcol[2]), 0.0)
tcol = (float(tcol[0]), float(tcol[1]), float(tcol[2]), 0.0)
fcol = (float(fcol[0]), float(fcol[1]), float(fcol[2]), 0.0)
lw = ui.linewidth
fs = ui.fontsize
lw = utils.getParam("linewidth",2)
fs = utils.getParam("textheight",0.20)
if not origin or not hasattr(origin, 'ViewObject'):
if "FontSize" in obrep.PropertiesList:
obrep.FontSize = fs
if "TextSize" in obrep.PropertiesList:
obrep.TextSize = fs
if "TextColor" in obrep.PropertiesList:
obrep.TextColor = col
obrep.TextColor = tcol
if "LineWidth" in obrep.PropertiesList:
obrep.LineWidth = lw
if "PointColor" in obrep.PropertiesList:
obrep.PointColor = col
obrep.PointColor = lcol
if "LineColor" in obrep.PropertiesList:
obrep.LineColor = col
obrep.LineColor = lcol
if "ShapeColor" in obrep.PropertiesList:
obrep.ShapeColor = fcol
else:

View File

@@ -97,7 +97,8 @@ def get_draft_context_commands():
return ["Draft_ApplyStyle", "Draft_ToggleDisplayMode",
"Draft_AddToGroup", "Draft_SelectGroup",
"Draft_SelectPlane", "Draft_ShowSnapBar",
"Draft_ToggleGrid", "Draft_AutoGroup"]
"Draft_ToggleGrid", "Draft_AutoGroup",
"Draft_SetStyle"]
def get_draft_line_commands():