Skip to content

Materials Tagging UI [AARD-1880] #1170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 9 commits into
base: dev
Choose a base branch
from
9 changes: 9 additions & 0 deletions exporter/SynthesisFusionAddin/src/UI/ConfigCommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
from src.UI.GeneralConfigTab import GeneralConfigTab
from src.UI.Handlers import PersistentEventHandler
from src.UI.JointConfigTab import JointConfigTab
from src.UI.TaggingConfigTab import TaggingConfigTab

generalConfigTab: GeneralConfigTab
jointConfigTab: JointConfigTab
taggingConfigTab: TaggingConfigTab
gamepieceConfigTab: GamepieceConfigTab

logger = getLogger()
Expand Down Expand Up @@ -81,6 +83,10 @@ def notify(self, args: adsk.core.CommandCreatedEventArgs) -> None:
jointConfigTab = JointConfigTab(args)
generalConfigTab.jointConfigTab = jointConfigTab

global taggingConfigTab
taggingConfigTab = TaggingConfigTab(args)
generalConfigTab.taggingConfigTab = taggingConfigTab

if not exporterOptions.exportMode == ExportMode.FIELD:
gamepieceConfigTab.isVisible = False

Expand Down Expand Up @@ -222,6 +228,9 @@ def notify(self, args: adsk.core.InputChangedEventArgs) -> None:
if gamepieceConfigTab.isVisible and gamepieceConfigTab.isActive:
gamepieceConfigTab.handleInputChanged(args, INPUTS_ROOT)

if taggingConfigTab.isVisible and taggingConfigTab.isActive:
taggingConfigTab.handleInputChanged(args, INPUTS_ROOT)


class MyCommandDestroyHandler(PersistentEventHandler, adsk.core.CommandEventHandler):
"""Called when the configuration panel is destroyed."""
Expand Down
2 changes: 2 additions & 0 deletions exporter/SynthesisFusionAddin/src/UI/GeneralConfigTab.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from src.UI.CreateCommandInputsHelper import createBooleanInput
from src.UI.GamepieceConfigTab import GamepieceConfigTab
from src.UI.JointConfigTab import JointConfigTab
from src.UI.TaggingConfigTab import TaggingConfigTab
from src.Util import (
convertMassUnitsFrom,
convertMassUnitsTo,
Expand All @@ -23,6 +24,7 @@ class GeneralConfigTab:
previousSelectedModeDropdownIndex: int
jointConfigTab: JointConfigTab
gamepieceConfigTab: GamepieceConfigTab
taggingConfigTab: TaggingConfigTab

@logFailure
def __init__(self, args: adsk.core.CommandCreatedEventArgs, exporterOptions: ExporterOptions) -> None:
Expand Down
142 changes: 142 additions & 0 deletions exporter/SynthesisFusionAddin/src/UI/TaggingConfigTab.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
import adsk.core
import adsk.fusion

from src.Logging import getLogger, logFailure
from src.UI.CreateCommandInputsHelper import createTableInput, createTextBoxInput

logger = getLogger()

class TaggingConfigTab:
# stores the types of tags available for selection
tagTypes = ["Softbody", "Rigid", "Chain", "Spring", "Rope"]
# TODO: Add a dict to hold the selections and their respective tags

taggingConfigTab: adsk.core.TabCommandInput
taggingListTable: adsk.core.TableCommandInput
tagTypeDropdown: adsk.core.DropDownCommandInput

@logFailure
def __init__(self, args:adsk.core.CommandCreatedEventArgs) -> None:
self.taggingConfigTab = args.command.commandInputs.addTabCommandInput(
"taggingOptionsTab", "Tagging Options"
)
self.taggingConfigTab.tooltip = "Configure tagging options for materials"
taggingConfigTabInputs = self.taggingConfigTab.children

self.tagTypeDropdown = taggingConfigTabInputs.addDropDownCommandInput(
"tageTypeDropdown",
"Tag Type",
dropDownStyle=adsk.core.DropDownStyles.LabeledIconDropDownStyle
)
self.tagTypeDropdown.isFullWidth = False
for tag in self.tagTypes:
self.tagTypeDropdown.listItems.add(tag, False)
self.tagTypeDropdown.isEnabled = self.tagTypeDropdown.isVisible = False

bodySelection = taggingConfigTabInputs.addSelectionInput(
"tagBodySelect",
"Select Body",
"Select a single body."
)
bodySelection.addSelectionFilter("SolidBodies")
bodySelection.addSelectionFilter("SurfaceBodies")

self.taggingListTable = createTableInput("tagListTable", "Tag List", taggingConfigTabInputs, 6, "1:1")
self.taggingListTable.addCommandInput(
createTextBoxInput("headerBodyName", "Body", taggingConfigTabInputs, "Body Name", background="#d9d9d9"),
0,
0
)
self.taggingListTable.addCommandInput(
createTextBoxInput("headerTagType", "Type", taggingConfigTabInputs, "Tag Type", background="#d9d9d9"),
0,
1
)
self.taggingListTable.getInputAtPosition(0,0).parentCommand.isSelectable = False
self.taggingListTable.getInputAtPosition(0,1).parentCommand.isSelectable = False

addTagInputButton = taggingConfigTabInputs.addBoolValueInput("tagAddButton", "Add", False)
removeTagInputButton = taggingConfigTabInputs.addBoolValueInput("tagRemoveButton", "Remove", False)
cancelInputButton = taggingConfigTabInputs.addBoolValueInput("tagCancelButton", "Cancel", False)

self.taggingListTable.addToolbarCommandInput(addTagInputButton)
self.taggingListTable.addToolbarCommandInput(removeTagInputButton)
self.taggingListTable.addToolbarCommandInput(cancelInputButton)

self.toggleSelecting(False)

@property
def isVisible(self) -> bool:
return self.taggingConfigTab.isVisible or False

@isVisible.setter
def isVisible(self, value: bool) -> None:
self.taggingConfigTab.isVisible = value

@property
def isActive(self) -> bool:
return self.taggingConfigTab.isActive or False

def toggleSelecting(self, value: bool) -> None:
tagAddButton: adsk.core.BoolValueCommandInput = self.taggingConfigTab.commandInputs.itemById("tagAddButton")
tagRemoveButton: adsk.core.BoolValueCommandInput = self.taggingConfigTab.commandInputs.itemById("tagRemoveButton")
tagBodySelection: adsk.core.SelectionCommandInput = self.taggingConfigTab.commandInputs.itemById("tagBodySelect")
tagCancelButton: adsk.core.BoolValueCommandInput = self.taggingConfigTab.commandInputs.itemById("tagCancelButton")

tagAddButton.isEnabled = tagRemoveButton.isEnabled = not value
tagCancelButton.isVisible = value
self.tagTypeDropdown.isEnabled = self.tagTypeDropdown.isVisible = value

if not value:
tagBodySelection.clearSelection()
tagBodySelection.setSelectionLimits(0)
tagBodySelection.isEnabled = tagBodySelection.isVisible = False
self.taggingListTable.clearSelection()
self.tagTypeDropdown.selectedItem = None

else:
tagBodySelection.isVisible = tagBodySelection.isEnabled = True
tagBodySelection.setSelectionLimits(0,1)


@logFailure
def handleInputChanged(self, args: adsk.core.InputChangedEventArgs, globalCommandInputs: adsk.core.CommandInputs) -> None:
commandInput = args.input
tagAddButton: adsk.core.BoolValueCommandInput = globalCommandInputs.itemById("tagAddButton")
tagRemoveButton: adsk.core.BoolValueCommandInput = globalCommandInputs.itemById("tagRemoveButton")
tagCancelButton: adsk.core.BoolValueCommandInput = globalCommandInputs.itemById("tagCancelButton")
tagBodySelection: adsk.core.SelectionCommandInput = globalCommandInputs.itemById("tagBodySelect")

if commandInput.id == "tagAddButton":
self.toggleSelecting(True)


elif commandInput.id == "tagRemoveButton":
if self.taggingListTable.selectedRow == -1:
app = adsk.core.Application.get()
ui = app.userInterface
ui.messageBox("No tags to remove.")
return

self.taggingListTable.deleteRow(self.taggingListTable.selectedRow)
# TODO: Remove the tag from the dict

elif commandInput.id == "tagCancelButton":
self.toggleSelecting(False)

elif (tagBodySelection.selectionCount == 1 or self.tagTypeDropdown.selectedItem is not None):
commandInputs = self.taggingConfigTab.commandInputs
row=self.taggingListTable.rowCount
bodyName = commandInputs.addTextBoxCommandInput(f"bodyName_{row}", "Body Name", tagBodySelection.selection(0).entity.name, 1, True)
tagType = commandInputs.addTextBoxCommandInput(f"tagType_{row}", "Tag Type", self.tagTypeDropdown.selectedItem.name, 1, True)

row = self.taggingListTable.rowCount
self.taggingListTable.addCommandInput(bodyName, row, 0)
self.taggingListTable.addCommandInput(tagType, row, 1)

self.toggleSelecting(False)


# @logFailure
# def getTags(self) -> list:

Loading