-
Notifications
You must be signed in to change notification settings - Fork 2
/
Settings_BoM.py
192 lines (155 loc) · 6.98 KB
/
Settings_BoM.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# ***************************************************************************
# * Copyright (c) 2023 Paul Ebbers paul.ebbers@gmail.com *
# * *
# * This file is part of the FreeCAD CAx development system. *
# * *
# * 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. *
# * *
# * FreeCAD 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 Lesser General Public License for more details. *
# * *
# * You should have received a copy of the GNU Library General Public *
# * License along with FreeCAD; if not, write to the Free Software *
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
# * USA *
# * *
# ***************************************************************************/
import FreeCAD as App
import Standard_Functions_BOM_WB as Standard_Functions
# Define the translation
translate = App.Qt.translate
preferences = App.ParamGet("User parameter:BaseApp/Preferences/Mod/BoM Workbench")
# endregion
# region -- functions to make sure that a None type result is ""
def GetStringSetting(settingName: str) -> str:
result = preferences.GetString(settingName)
if result.lower() == "none":
result = ""
return result
def GetIntSetting(settingName: str) -> int:
result = preferences.GetInt(settingName)
if result == "":
result = None
return result
def GetFloatSetting(settingName: str) -> int:
result = preferences.GetFloat(settingName)
if result == "":
result = None
return result
def GetBoolSetting(settingName: str) -> bool:
result = preferences.GetBool(settingName)
if str(result).lower() == "none":
result = False
return result
def GetColorSetting(settingName: str) -> object:
from PySide.QtGui import QColor
# Create a tuple from the int value of the color
result = QColor.fromRgba(preferences.GetUnsigned(settingName)).toTuple()
# correct the order of the tuple and devide them by 255
result = (result[3] / 255, result[0] / 255, result[1] / 255, result[2] / 255)
return result
def SetStringSetting(settingName: str, value: str):
Text = translate(
"TitleBlock Workbench",
f"string setting not applied!!\n Settings was: {settingName} and value was {value}",
)
if value.lower() == "none":
if ENABLE_DEBUG is True:
Standard_Functions.Print(Text, "Log")
value = ""
preferences.SetString(settingName, value)
def SetBoolSetting(settingName: str, value):
if value.lower() == "true":
Bool = True
if str(value).lower() == "none" or value.lower() != "true":
Text = translate(
"TitleBlock Workbench",
f"bool setting not applied!!\n Settings was: {settingName} and value was {value}",
)
if ENABLE_DEBUG is True:
Standard_Functions.Print(Text, "Log")
Bool = False
preferences.SetBool(settingName, Bool)
# endregion
# region -- All settings from the UI
# BoM Settings
CUSTOM_HEADERS = GetStringSetting("CustomHeader")
DEBUG_HEADERS = GetStringSetting("DebugHeader")
# UI Settings
SPREADSHEET_HEADERBACKGROUND = GetColorSetting("SpreadSheetHeaderBackGround")
SPREADSHEET_HEADERFOREGROUND = GetColorSetting("SpreadSheetHeaderForeGround")
SPREADSHEET_HEADERFONTSTYLE_BOLD = GetBoolSetting("SpreadsheetHeaderFontStyle_Bold")
SPREADSHEET_HEADERFONTSTYLE_ITALIC = GetBoolSetting("SpreadsheetHeaderFontStyle_Italic")
SPREADSHEET_HEADERFONTSTYLE_UNDERLINE = GetBoolSetting(
"SpreadsheetHeaderFontStyle_Underline"
)
SPREADSHEET_TABLEBACKGROUND_1 = GetColorSetting("SpreadSheetTableBackGround_1")
SPREADSHEET_TABLEBACKGROUND_2 = GetColorSetting("SpreadSheetTableBackGround_2")
SPREADSHEET_TABLEFOREGROUND = GetColorSetting("SpreadSheetTableForeGround")
SPREADSHEET_TABLEFONTSTYLE_BOLD = GetBoolSetting("SpreadsheetTableFontStyle_Bold")
SPREADSHEET_TABLEFONTSTYLE_ITALIC = GetBoolSetting("SpreadsheetTableFontStyle_Italic")
SPREADSHEET_TABLEFONTSTYLE_UNDERLINE = GetBoolSetting(
"SpreadsheetTableFontStyle_Underline"
)
SPREADSHEET_COLUMNFONTSTYLE_BOLD = GetBoolSetting("SpreadsheetColumnFontStyle_Bold")
SPREADSHEET_COLUMNFONTSTYLE_ITALIC = GetBoolSetting("SpreadsheetColumnFontStyle_Italic")
SPREADSHEET_COLUMNFONTSTYLE_UNDERLINE = GetBoolSetting(
"SpreadsheetColumnFontStyle_Underline"
)
AUTOFIT_FACTOR = GetFloatSetting("AutoFitFactor")
# Enable debug mode. This will enable additional report messages
ENABLE_DEBUG = GetBoolSetting("EnableDebug")
ENABLE_DEBUG_COLUMNS = GetBoolSetting("EnableDebugColumns")
# endregion
# Add headers for debugging if enabled
def SetDebugHeaders():
if ENABLE_DEBUG_COLUMNS is True:
DebugHeaders = [
"Original label",
"Type",
"Internal name",
"Fullname",
"TypeId",
]
HeaderString = ""
for Header in DebugHeaders:
HeaderString = HeaderString + f";{Header}"
if HeaderString.startswith(";"):
HeaderString = HeaderString[1:]
if HeaderString.endswith(";"):
HeaderString = HeaderString[:-1]
SetStringSetting("DebugHeader", HeaderString)
if ENABLE_DEBUG_COLUMNS is False:
SetStringSetting("DebugHeader", "")
def ReturnHeaders(Headers: dict = None, AdditionalHeaders: dict = None):
"""_summary_
Args:
AdditionalHeaders (dict, optional): dict with additional headers. Defaults to None.
Returns:
dict: headers as a dict. the key is a cell adress. the value is the header value.\n
Standard output:
{
"A1": "Number",
"B1": "Qty",
"C1": "Label",
"D1": "Description",
}
"""
if Headers is None or bool(Headers) is False:
Headers = {
"A1": "Number",
"B1": "Qty",
"C1": "Label",
"D1": "Description",
}
if AdditionalHeaders is not None or bool(AdditionalHeaders) is True:
Headers.update(AdditionalHeaders)
return Headers
def ListWorkbenches_Toolbar():
WorkbenchDict = App.Gui.listWorkbenches()