Skip to content

Commit

Permalink
Assembly: BOM: Add help button. Make auto-generated columns bold.
Browse files Browse the repository at this point in the history
  • Loading branch information
PaddleStroke committed Jun 19, 2024
1 parent 3b0edd6 commit 7458063
Show file tree
Hide file tree
Showing 2 changed files with 145 additions and 28 deletions.
132 changes: 116 additions & 16 deletions src/Mod/Assembly/CommandCreateBom.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@
import UtilsAssembly
import Preferences

# translate = App.Qt.translate

__title__ = "Assembly Command Create Bill of Materials"
__author__ = "Ondsel"
__url__ = "https://www.freecad.org"
Expand Down Expand Up @@ -118,19 +116,19 @@ def __init__(self, bomObj=None):
self.form.btnAddColumn.clicked.connect(self.addColumn)
self.form.btnExport.clicked.connect(self.export)

self.form.helpButton.clicked.connect(self.showHelpDialog)

pref = Preferences.preferences()

if bomObj:
App.setActiveTransaction("Edit Bill Of Materials")

names = []
for i in range(len(bomObj.columnsNames)):
text = bomObj.columnsNames[i]
if text in ColumnNames:
index = ColumnNames.index(text)
text = TranslatedColumnNames[index]
names.append(text)
self.form.columnList.addItems(names)
for name in bomObj.columnsNames:
if name in ColumnNames:
index = ColumnNames.index(name)
name = TranslatedColumnNames[index]

self.addColItem(name)

self.bomObj = bomObj
self.form.CheckBox_onlyParts.setChecked(bomObj.onlyParts)
Expand All @@ -139,7 +137,10 @@ def __init__(self, bomObj=None):

else:
App.setActiveTransaction("Create Bill Of Materials")
self.form.columnList.addItems(TranslatedColumnNames)

# Add the columns
for name in TranslatedColumnNames:
self.addColItem(name)

self.createBomObject()
self.form.CheckBox_onlyParts.setChecked(pref.GetBool("BOMOnlyParts", False))
Expand Down Expand Up @@ -199,15 +200,37 @@ def addColumn(self):
counter += 1
new_name = f"{new_name}_{counter}"

new_item = QtWidgets.QListWidgetItem(new_name)
new_item.setFlags(new_item.flags() | QtCore.Qt.ItemIsEditable)
self.form.columnList.addItem(new_item)
item = self.addColItem(new_name)

# Ensure the new item is selected and starts editing
self.form.columnList.setCurrentItem(new_item)
self.form.columnList.editItem(new_item)
self.form.columnList.setCurrentItem(item)
self.form.columnList.editItem(item)
self.updateColumnList()

def addColItem(self, name):
item = QtWidgets.QListWidgetItem(name)

isCustomCol = self.isCustomColumn(name)

if isCustomCol:
item.setFlags(item.flags() | QtCore.Qt.ItemIsEditable)
else:
font = item.font()
font.setBold(True)
item.setFont(font)

self.form.columnList.addItem(item)
return item

def isCustomColumn(self, name):
isCustomCol = True
if name in TranslatedColumnNames:
# Description column is currently not auto generated so it's a custom column
index = TranslatedColumnNames.index(name)
if ColumnNames[index] != "Description":
isCustomCol = False
return isCustomCol

def onItemsReordered(self, parent, start, end, destination, row):
self.updateColumnList()

Expand Down Expand Up @@ -248,8 +271,20 @@ def itemUpdated(self, item):
)
item.setText(old_text)
else:
isCustomCol = self.isCustomColumn(new_text)

if not isCustomCol:
font = item.font()
font.setBold(True)
item.setFont(font)
# Use a single-shot timer to defer changing the flags (else FC crashes)
QtCore.QTimer.singleShot(0, lambda: self.makeItemNonEditable(item))

self.updateColumnList()

def makeItemNonEditable(self, item):
item.setFlags(item.flags() & ~QtCore.Qt.ItemIsEditable)

def isNameDuplicate(self, name):
for i in range(self.form.columnList.count()):
if self.form.columnList.item(i).text() == name:
Expand Down Expand Up @@ -289,6 +324,71 @@ def eventFilter(self, watched, event):

return super().eventFilter(watched, event)

def showHelpDialog(self):
help_dialog = QtWidgets.QDialog(self.form)
help_dialog.setWindowFlags(QtCore.Qt.Popup)
help_dialog.setWindowModality(QtCore.Qt.NonModal)
help_dialog.setAttribute(QtCore.Qt.WA_DeleteOnClose)

layout = QtWidgets.QVBoxLayout()
layout.setContentsMargins(10, 10, 10, 10)

options_title = QtWidgets.QLabel("<b>" + translate("Assembly", "Options:") + "</b>")
options_text = QtWidgets.QLabel(
" - "
+ translate(
"Assembly",
"Sub-assemblies children : If checked, Sub assemblies children will be added to the bill of materials.",

Check warning on line 341 in src/Mod/Assembly/CommandCreateBom.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

Line too long (120/100) (line-too-long)
)
+ "\n"
" - "
+ translate(
"Assembly",
"Parts children : If checked, Parts children will be added to the bill of materials.",

Check warning on line 347 in src/Mod/Assembly/CommandCreateBom.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

Line too long (102/100) (line-too-long)
)
+ "\n"
" - "
+ translate(
"Assembly",
"Only parts : If checked, only Part containers and sub-assemblies will be added to the bill of materials. Solids like PartDesign Bodies, fasteners or Part workbench primitives will be ignored.",

Check warning on line 353 in src/Mod/Assembly/CommandCreateBom.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

Line too long (210/100) (line-too-long)
)
+ "\n"
)
columns_title = QtWidgets.QLabel("<b>" + translate("Assembly", "Columns:") + "</b>")
columns_text = QtWidgets.QLabel(
" - "
+ translate(
"Assembly",
"Bold columns : (Index, Quantity, Name...) are populated automatically. Any modification you make will be overriden. These columns cannot be renamed.",

Check warning on line 362 in src/Mod/Assembly/CommandCreateBom.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

overriden ==> overridden

Check warning on line 362 in src/Mod/Assembly/CommandCreateBom.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

Line too long (168/100) (line-too-long)
)
+ "\n"
" - "
+ translate(
"Assembly",
"Custom columns : 'Description' and other custom columns you add by clicking on 'Add column' will not have their data overwritten. These columns can be renamed by double-clicking or pressing F2 (Renaming a column will currently lose its data).",

Check warning on line 368 in src/Mod/Assembly/CommandCreateBom.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

Line too long (261/100) (line-too-long)
)
+ "\n"
"\n"
+ translate(
"Assembly",
"Any column (custom or not) can be deleted by pressing Del. If you deleted an auto-populated column and want it back, just create a column with the correct name.",

Check warning on line 374 in src/Mod/Assembly/CommandCreateBom.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

Line too long (179/100) (line-too-long)
)
+ "\n"
)

options_text.setWordWrap(True)
columns_text.setWordWrap(True)

layout.addWidget(options_title)
layout.addWidget(options_text)
layout.addWidget(columns_title)
layout.addWidget(columns_text)

help_dialog.setLayout(layout)
help_dialog.setFixedWidth(500)

help_dialog.show()


if App.GuiUp:
Gui.addCommand("Assembly_CreateBom", CommandCreateBom())
41 changes: 29 additions & 12 deletions src/Mod/Assembly/Gui/Resources/panels/TaskAssemblyCreateBom.ui
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
<string>Create Bill Of Materials</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<item row="0" column="0" colspan="2">
<widget class="Gui::PrefCheckBox" name="CheckBox_detailSubAssemblies">
<property name="toolTip">
<string>If checked, Sub assemblies sub-components will be added to the bill of materials.</string>
<string>If checked, Sub assemblies children will be added to the bill of materials.</string>
</property>
<property name="text">
<string>Detail sub-assemblies</string>
<string>Sub-assemblies children</string>
</property>
<property name="checked">
<bool>true</bool>
Expand All @@ -33,13 +33,13 @@
</property>
</widget>
</item>
<item row="1" column="0">
<item row="1" column="0" colspan="2">
<widget class="Gui::PrefCheckBox" name="CheckBox_detailParts">
<property name="toolTip">
<string>If checked, Parts sub-components will be added to the bill of materials.</string>
<string>If checked, Parts children will be added to the bill of materials.</string>
</property>
<property name="text">
<string>Detail parts</string>
<string>Parts children</string>
</property>
<property name="checked">
<bool>true</bool>
Expand All @@ -52,10 +52,10 @@
</property>
</widget>
</item>
<item row="2" column="0">
<item row="2" column="0" colspan="2">
<widget class="Gui::PrefCheckBox" name="CheckBox_onlyParts">
<property name="toolTip">
<string>If checked, only Part containers will be added to the bill of materials. Solids like PartDesign Bodies will be ignored.</string>
<string>If checked, only Part containers and sub-assemblies will be added to the bill of materials. Solids like PartDesign Bodies, fasteners or Part workbench primitives will be ignored.</string>
</property>
<property name="text">
<string>Only parts</string>
Expand All @@ -71,11 +71,8 @@
</property>
</widget>
</item>
<item row="3" column="0">
<item row="3" column="0" colspan="2">
<widget class="QGroupBox" name="groupBox_1">
<property name="toolTip">
<string>Columns of the bill of materials</string>
</property>
<property name="title">
<string>Columns</string>
</property>
Expand All @@ -100,6 +97,26 @@
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QToolButton" name="helpButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Help</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="Icons/resource.qrc">
<normaloff>:/icons/help-browser.svg</normaloff>:/icons/help-browser.svg</iconset>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
Expand Down

0 comments on commit 7458063

Please sign in to comment.