Draft: [WIP] Annotation styles editor
This commit is contained in:
@@ -165,5 +165,6 @@
|
||||
<file>ui/TaskPanel_PolarArray.ui</file>
|
||||
<file>ui/TaskSelectPlane.ui</file>
|
||||
<file>ui/TaskShapeString.ui</file>
|
||||
<file>ui/dialog_AnnotationStyleEditor.ui</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
||||
447
src/Mod/Draft/Resources/ui/dialog_AnnotationStyleEditor.ui
Normal file
447
src/Mod/Draft/Resources/ui/dialog_AnnotationStyleEditor.ui
Normal file
@@ -0,0 +1,447 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Dialog</class>
|
||||
<widget class="QDialog" name="Dialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>418</width>
|
||||
<height>694</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
<string>Style name</string>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QComboBox" name="comboBoxStyles">
|
||||
<property name="toolTip">
|
||||
<string>The name of your style. Existing style names can be edited</string>
|
||||
</property>
|
||||
<property name="editable">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Add new...</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButtonRename">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>80</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Renames the selected style</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Rename</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButtonDelete">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>80</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Deletes the selected style</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Delete</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox_3">
|
||||
<property name="title">
|
||||
<string>Text</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Font size</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Font name</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Line spacing</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="Gui::QuantitySpinBox" name="FontSize">
|
||||
<property name="toolTip">
|
||||
<string>The size of the text in real-world units</string>
|
||||
</property>
|
||||
<property name="unit" stdset="0">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="Gui::QuantitySpinBox" name="LineSpacing">
|
||||
<property name="toolTip">
|
||||
<string>The spacing between lines of text in real-world units</string>
|
||||
</property>
|
||||
<property name="unit" stdset="0">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QFontComboBox" name="FontName">
|
||||
<property name="toolTip">
|
||||
<string>The font to use for texts and dimensions</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox_2">
|
||||
<property name="title">
|
||||
<string>Units</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>Scale multiplier</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>Decimals</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_6">
|
||||
<property name="text">
|
||||
<string>Únit override</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_7">
|
||||
<property name="text">
|
||||
<string>Show unit</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QDoubleSpinBox" name="ScaleMultiplier">
|
||||
<property name="toolTip">
|
||||
<string>A multiplier value that affects distances shown by dimensions</string>
|
||||
</property>
|
||||
<property name="decimals">
|
||||
<number>4</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<double>1.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QLineEdit" name="UnitOverride">
|
||||
<property name="toolTip">
|
||||
<string>Forces dimensions to be shown in a specific unit</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QSpinBox" name="Decimals">
|
||||
<property name="toolTip">
|
||||
<string>The number of decimals to show on dimensions</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QCheckBox" name="ShowUnit">
|
||||
<property name="toolTip">
|
||||
<string>Shows the units suffix on dimensions or not</string>
|
||||
</property>
|
||||
<property name="layoutDirection">
|
||||
<enum>Qt::RightToLeft</enum>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox_4">
|
||||
<property name="title">
|
||||
<string>Line and arrows</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_14">
|
||||
<property name="text">
|
||||
<string>Line width</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="0">
|
||||
<widget class="QLabel" name="label_12">
|
||||
<property name="text">
|
||||
<string>Extension overshoot</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<widget class="QLabel" name="label_8">
|
||||
<property name="text">
|
||||
<string>Arrow size</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_13">
|
||||
<property name="text">
|
||||
<string>Show lines</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="0">
|
||||
<widget class="QLabel" name="label_10">
|
||||
<property name="text">
|
||||
<string>Dimension overshoot</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="0">
|
||||
<widget class="QLabel" name="label_11">
|
||||
<property name="text">
|
||||
<string>Extension lines</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="label_9">
|
||||
<property name="text">
|
||||
<string>Arrow type</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_15">
|
||||
<property name="text">
|
||||
<string>Line / text color</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QCheckBox" name="ShowLines">
|
||||
<property name="toolTip">
|
||||
<string>Shows the dimension line or not</string>
|
||||
</property>
|
||||
<property name="layoutDirection">
|
||||
<enum>Qt::RightToLeft</enum>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QSpinBox" name="LineWidth">
|
||||
<property name="toolTip">
|
||||
<string>The width of the dimension lines</string>
|
||||
</property>
|
||||
<property name="suffix">
|
||||
<string>px</string>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>1</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="Gui::ColorButton" name="LineColor">
|
||||
<property name="toolTip">
|
||||
<string>The color of dimension lines, arrows and texts</string>
|
||||
</property>
|
||||
<property name="color">
|
||||
<color>
|
||||
<red>0</red>
|
||||
<green>0</green>
|
||||
<blue>0</blue>
|
||||
</color>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QComboBox" name="ArrowType">
|
||||
<property name="toolTip">
|
||||
<string>The typeof arrows to use for dimensions</string>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Dot</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Arrow</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Tick</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
<widget class="Gui::QuantitySpinBox" 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="1">
|
||||
<widget class="Gui::QuantitySpinBox" name="DimensionOvershoot">
|
||||
<property name="toolTip">
|
||||
<string>How far must the main dimension line extend pass the measured points</string>
|
||||
</property>
|
||||
<property name="unit" stdset="0">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="1">
|
||||
<widget class="Gui::QuantitySpinBox" name="ExtensionLines">
|
||||
<property name="toolTip">
|
||||
<string>The length of extension lines</string>
|
||||
</property>
|
||||
<property name="unit" stdset="0">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="1">
|
||||
<widget class="Gui::QuantitySpinBox" name="ExtensionOvershoot">
|
||||
<property name="toolTip">
|
||||
<string>How far must the extension lines extend above the main dimension line</string>
|
||||
</property>
|
||||
<property name="unit" stdset="0">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>Gui::QuantitySpinBox</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>Gui/QuantitySpinBox.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>Gui::ColorButton</class>
|
||||
<extends>QPushButton</extends>
|
||||
<header>Gui/Widgets.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>Dialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>Dialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
175
src/Mod/Draft/draftguitools/gui_annotationstyleeditor.py
Normal file
175
src/Mod/Draft/draftguitools/gui_annotationstyleeditor.py
Normal file
@@ -0,0 +1,175 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# ***************************************************************************
|
||||
# * 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 all gui and tools to create and edit annotation styles
|
||||
Provides Draft_AnnotationStyleEditor command
|
||||
"""
|
||||
|
||||
import FreeCAD,FreeCADGui
|
||||
import json
|
||||
|
||||
EMPTYSTYLE = {
|
||||
"FontName":"Sans",
|
||||
"FontSize":0,
|
||||
"LineSpacing":0,
|
||||
"ScaleMultiplier":1,
|
||||
"ShowUnit":False,
|
||||
"UnitOverride":"",
|
||||
"Decimals":0,
|
||||
"ShowLines":True,
|
||||
"LineWidth":1,
|
||||
"LineColor":255,
|
||||
"ArrowType":0,
|
||||
"ArrowSize":0,
|
||||
"DimensionOvershoot":0,
|
||||
"ExtensionLines":0,
|
||||
"ExtensionOvershoot":0,
|
||||
}
|
||||
|
||||
|
||||
class Draft_AnnotationStyleEditor:
|
||||
|
||||
def __init__(self):
|
||||
|
||||
self.styles = {}
|
||||
|
||||
def GetResources(self):
|
||||
|
||||
return {'Pixmap' : ":icons/Draft_AnnotationStyleEditor.svg",
|
||||
'MenuText': QT_TRANSLATE_NOOP("Draft_AnnotationStyleEditor", "Annotation styles..."),
|
||||
'ToolTip' : QT_TRANSLATE_NOOP("Draft_AnnotationStyleEditor", "Manage or create annotation styles")}
|
||||
|
||||
def IsActive(self):
|
||||
|
||||
return bool(FreeCAD.ActiveDocument)
|
||||
|
||||
def Activated(self):
|
||||
|
||||
from PySide import QtGui
|
||||
|
||||
# load dialog
|
||||
self.form = FreeCADGui.PySideUic.loadUi(":/ui/dialog_AnnotationStyleEditor.ui")
|
||||
|
||||
# center the dialog over FreeCAD window
|
||||
mw = FreeCADGui.getMainWindow()
|
||||
self.form.move(mw.frameGeometry().topLeft() + mw.rect().center() - self.form.rect().center())
|
||||
|
||||
# set icons
|
||||
self.form.pushButtonDelete.setIcon(QtGui.QIcon(":/icons/edit_Cancel.svg"))
|
||||
self.form.pushButtonRename.setIcon(QtGui.QIcon(":/icons/edit_Cancel.svg"))
|
||||
|
||||
# fill the styles combo
|
||||
self.styles = self.read_meta()
|
||||
for style in self.styles.keys():
|
||||
self.form.comboBoxStyles.addItem(style)
|
||||
|
||||
# connect signals/slots
|
||||
self.form.comboBoxStyles.currentIndexChanged.connect(self.on_style_changed)
|
||||
self.form.pushButtonDelete.clicked.connect(self.on_delete)
|
||||
self.form.pushButtonRename.clicked.connect(self.on_rename)
|
||||
# TODO connect all other controls to a function that saves to self.styles
|
||||
|
||||
# show editor dialog
|
||||
result = self.form.exec_()
|
||||
|
||||
# process if OK was clicked
|
||||
if result:
|
||||
self.save_meta(self.styles)
|
||||
|
||||
return
|
||||
|
||||
def read_meta(self):
|
||||
|
||||
styles = {}
|
||||
meta = FreeCAD.ActiveDocument.Meta
|
||||
for key,value in meta.keys:
|
||||
if key.startswith("Draft_Style_"):
|
||||
styles[key[12:]] = json.loads(value)
|
||||
return styles
|
||||
|
||||
def save_meta(self,styles):
|
||||
|
||||
meta = FreeCAD.ActiveDocument.Meta
|
||||
for key,value in styles:
|
||||
meta["Draft_Style_"+key] = json.dumps(value)
|
||||
FreeCAD.ActiveDocument.Meta = meta
|
||||
|
||||
# TODO must also save meta and also update the styles
|
||||
# of comboboxes of all dimensions and texts
|
||||
# found in the doc. If a dimension/text uses a style
|
||||
# that has now been deleted, that case must also be handled
|
||||
# maybe warn the user if the style is in use in on_delete?
|
||||
|
||||
|
||||
def on_style_changed(self,index):
|
||||
|
||||
from PySide import QtGui
|
||||
|
||||
if index <= 1:
|
||||
self.form.pushButtonDelete.setEnabled(False)
|
||||
self.form.pushButtonRename.setEnabled(False)
|
||||
self.fill_editor(None)
|
||||
if index == 1:
|
||||
reply = QtGui.QInputDialog.getText(None, "Create new style","Style name:")
|
||||
if reply[1]: # OK or Enter pressed
|
||||
name = reply[0]
|
||||
self.form.comboBoxStyles.addItem(name)
|
||||
self.form.comboBoxStyles.setCurrentIndex(self.form.comboBoxStyles.count()-1)
|
||||
elif index > 1:
|
||||
self.form.pushButtonDelete.setEnabled(True)
|
||||
self.form.pushButtonRename.setEnabled(True)
|
||||
self.fill_editor(self.form.comboBoxStyles.itemText(index))
|
||||
|
||||
def on_delete(self):
|
||||
|
||||
index = self.form.comboBox.currentIndex()
|
||||
if index > 1:
|
||||
style = self.form.comboBoxStyles.itemText(index)
|
||||
self.form.comboBoxStyles.removeItem(index)
|
||||
del self.styles[style]
|
||||
|
||||
def on_rename(self):
|
||||
|
||||
from PySide import QtGui
|
||||
|
||||
index = self.form.comboBox.currentIndex()
|
||||
if index > 1:
|
||||
style = self.form.comboBoxStyles.itemText(index)
|
||||
reply = QtGui.QInputDialog.getText(None, "Rename style","New name:",QtGui.QLineEdit.Normal,style)
|
||||
if reply[1]: # OK or Enter pressed
|
||||
newname = reply[0]
|
||||
self.form.comboBoxStyles.setItemText(index,newname)
|
||||
value = self.styles[style]
|
||||
del self.styles[style]
|
||||
self.styles[newname] = value
|
||||
|
||||
def fill_editor(self,style):
|
||||
|
||||
if style is None:
|
||||
style = EMPTYSTYLE
|
||||
for key,value in style:
|
||||
setattr(self.form,key,value)
|
||||
|
||||
|
||||
FreeCADGui.addCommand('Draft_AnnotationStyleEditor', Draft_AnnotationStyleEditor())
|
||||
Reference in New Issue
Block a user