Skip to content

Commit

Permalink
Final formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
BrandonPacewic committed Jun 20, 2024
1 parent 4b5f889 commit dda2853
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 113 deletions.
4 changes: 1 addition & 3 deletions exporter/SynthesisFusionAddin/src/Parser/ExporterOptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,7 @@ def writeToDesign(self) -> None:
{
key: (
lambda value: (
value
if not isinstance(value, Enum)
else value.value
value if not isinstance(value, Enum) else value.value
)
)(value)
for key, value in obj.__dict__.items()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ def _MapAllComponents(

fill_info(partDefinition, component, comp_ref)

PhysicalProperties.GetPhysicalProperties(
component, partDefinition.physical_data
)
PhysicalProperties.GetPhysicalProperties(component, partDefinition.physical_data)

if options.exportMode == ExporterOptions.ExportMode.FIELD:
partDefinition.dynamic = False
Expand All @@ -58,9 +56,7 @@ def processBody(body: adsk.fusion.BRepBody | adsk.fusion.MeshBody):
else:
_ParseMesh(body, options, part_body.triangle_mesh)

appearance_key = "{}_{}".format(
body.appearance.name, body.appearance.id
)
appearance_key = "{}_{}".format(body.appearance.name, body.appearance.id)
# this should be appearance
if appearance_key in materials.appearances:
part_body.appearance_override = appearance_key
Expand Down Expand Up @@ -156,9 +152,7 @@ def __parseChildOccurrence(
if options.exportMode == ExporterOptions.ExportMode.FIELD:
for x in options.gamepieces:
if x.occurrenceToken == mapConstant:
partsData.part_definitions[part.part_definition_reference].dynamic = (
True
)
partsData.part_definitions[part.part_definition_reference].dynamic = True
break

part.transform.spatial_matrix.extend(occurrence.transform.asArray())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ class JointRelationship(enum.Enum):


class DynamicOccurrenceNode(GraphNode):
def __init__(
self, occurrence: adsk.fusion.Occurrence, isGround=False, previous=None
):
def __init__(self, occurrence: adsk.fusion.Occurrence, isGround=False, previous=None):
super().__init__(occurrence)
self.isGround = isGround
self.name = occurrence.name
Expand Down Expand Up @@ -124,9 +122,7 @@ def getConnectedAxisTokens(self) -> list:


class DynamicEdge(GraphEdge):
def __init__(
self, relationship: OccurrenceRelationship, node: DynamicOccurrenceNode
):
def __init__(self, relationship: OccurrenceRelationship, node: DynamicOccurrenceNode):
super().__init__(relationship, node)

# should print all in this class
Expand Down Expand Up @@ -518,9 +514,7 @@ def populateJoint(simNode: SimulationNode, joints: joint_pb2.Joints, progressDia
# print(f"Configuring {proto_joint.info.name}")

# construct body tree if possible
createTreeParts(
simNode.data, OccurrenceRelationship.CONNECTION, root, progressDialog
)
createTreeParts(simNode.data, OccurrenceRelationship.CONNECTION, root, progressDialog)

proto_joint.parts.nodes.append(root)

Expand All @@ -539,10 +533,7 @@ def createTreeParts(
raise RuntimeError("User canceled export")

# if it's the next part just exit early for our own sanity
if (
relationship == OccurrenceRelationship.NEXT
or dynNode.data.isLightBulbOn == False
):
if relationship == OccurrenceRelationship.NEXT or dynNode.data.isLightBulbOn == False:
return

# set the occurrence / component id to reference the part
Expand Down
14 changes: 4 additions & 10 deletions exporter/SynthesisFusionAddin/src/Parser/SynthesisParser/Joints.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,18 +116,13 @@ def populateJoints(

# really could just map the enum to a friggin string
if (
parse_joints.signalType
!= ExporterOptions.SignalType.PASSIVE
parse_joints.signalType != ExporterOptions.SignalType.PASSIVE
and assembly.dynamic
):
if (
parse_joints.signalType
== ExporterOptions.SignalType.CAN
):
if parse_joints.signalType == ExporterOptions.SignalType.CAN:
signal.device_type = signal_pb2.DeviceType.CANBUS
elif (
parse_joints.signalType
== ExporterOptions.SignalType.PWM
parse_joints.signalType == ExporterOptions.SignalType.PWM
):
signal.device_type = signal_pb2.DeviceType.PWM

Expand Down Expand Up @@ -405,8 +400,7 @@ def _jointOrigin(
geometryOrOrigin = (
(
fusionJoint.geometryOrOriginOne
if fusionJoint.geometryOrOriginOne.objectType
== "adsk::fusion::JointGeometry"
if fusionJoint.geometryOrOriginOne.objectType == "adsk::fusion::JointGeometry"
else fusionJoint.geometryOrOriginTwo
)
if fusionJoint.objectType == "adsk::fusion::Joint"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,9 @@ def _format(self):
# TABS DO NOTHING HALP
out = f"{self.assemblyName} parsing:\n"
out += f"\t Components: \t[ {self.currentCompCount} / {self.componentCount} ]\n"
out += (
f"\t Occurrences: \t[ {self.currentOccCount} / {self.occurrenceCount} ]\n"
)
out += f"\t Occurrences: \t[ {self.currentOccCount} / {self.occurrenceCount} ]\n"
out += f"\t Materials: \t[ {self.currentMatCount} / {self.materialCount} ]\n"
out += (
f"\t Appearances: \t[ {self.currentAppCount} / {self.appearanceCount} ]\n"
)
out += f"\t Appearances: \t[ {self.currentAppCount} / {self.appearanceCount} ]\n"
out += f"{self.currentMessage}"

return out
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,18 +214,14 @@ def export(self) -> bool:

for child in node.children:
if child.value == "ground":
joint_hierarchy_out = (
f"{joint_hierarchy_out} |---> ground\n"
)
joint_hierarchy_out = f"{joint_hierarchy_out} |---> ground\n"
else:
newnode = assembly_out.data.joints.joint_instances[
child.value
]
jointdefinition = (
assembly_out.data.joints.joint_definitions[
newnode.joint_reference
]
)
jointdefinition = assembly_out.data.joints.joint_definitions[
newnode.joint_reference
]
wheel_ = (
" wheel : true"
if (jointdefinition.user_data.data["wheel"] != "")
Expand Down
62 changes: 18 additions & 44 deletions exporter/SynthesisFusionAddin/src/UI/ConfigCommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,8 @@ def notify(self, args):
cmd.isAutoExecute = False
cmd.isExecutedWhenPreEmpted = False
cmd.okButtonText = "Export" # replace default OK text with "export"
cmd.setDialogInitialSize(
400, 350
) # these aren't working for some reason...
cmd.setDialogMinimumSize(
400, 350
) # these aren't working for some reason...
cmd.setDialogInitialSize(400, 350) # these aren't working for some reason...
cmd.setDialogMinimumSize(400, 350) # these aren't working for some reason...

global INPUTS_ROOT # Global CommandInputs arg
INPUTS_ROOT = cmd.commandInputs
Expand Down Expand Up @@ -419,9 +415,7 @@ def notify(self, args):
)
jointConfig.isExpanded = False
jointConfig.isVisible = True
jointConfig.tooltip = (
"Select and define joint occurrences in your assembly."
)
jointConfig.tooltip = "Select and define joint occurrences in your assembly."

joint_inputs = jointConfig.children

Expand Down Expand Up @@ -571,9 +565,7 @@ def notify(self, args):
)
weightTableInput_f.tablePresentationStyle = 2 # set to clear background

weight_name_f = gamepiece_inputs.addStringValueInput(
"weight_name", "Weight"
)
weight_name_f = gamepiece_inputs.addStringValueInput("weight_name", "Weight")
weight_name_f.value = "Unit of Mass"
weight_name_f.isReadOnly = True

Expand All @@ -586,9 +578,7 @@ def notify(self, args):
enabled=True,
isCheckBox=False,
)
auto_calc_weight_f.resourceFolder = IconPaths.stringIcons[
"calculate-enabled"
]
auto_calc_weight_f.resourceFolder = IconPaths.stringIcons["calculate-enabled"]
auto_calc_weight_f.isFullWidth = True

weight_unit_f = gamepiece_inputs.addDropDownCommandInput(
Expand Down Expand Up @@ -630,9 +620,7 @@ def notify(self, args):
50,
)

addFieldInput = gamepiece_inputs.addBoolValueInput(
"field_add", "Add", False
)
addFieldInput = gamepiece_inputs.addBoolValueInput("field_add", "Add", False)

removeFieldInput = gamepiece_inputs.addBoolValueInput(
"field_delete", "Remove", False
Expand Down Expand Up @@ -1465,9 +1453,7 @@ def traverseAssembly(
if occ in value:
return [joint, occ] # occurrence that is jointed

if (
occ.childOccurrences
): # if occurrence has children, traverse sub-tree
if occ.childOccurrences: # if occurrence has children, traverse sub-tree
self.traverseAssembly(occ.childOccurrences, jointedOcc)
return None # no jointed occurrence found
except:
Expand Down Expand Up @@ -1540,9 +1526,7 @@ def wheelParent(self, occ: adsk.fusion.Occurrence):
treeParent = parent # each parent that will traverse up in algorithm.

while treeParent != None: # loops until reaches top-level component
returned = self.traverseAssembly(
treeParent.childOccurrences, jointedOcc
)
returned = self.traverseAssembly(treeParent.childOccurrences, jointedOcc)

if returned != None:
for i in range(parentLevel):
Expand Down Expand Up @@ -2014,10 +1998,7 @@ def notify(self, args):
# gm.ui.activeSelections.clear()

addWheelInput.isEnabled = True
if (
wheelTableInput.selectedRow == -1
or wheelTableInput.selectedRow == 0
):
if wheelTableInput.selectedRow == -1 or wheelTableInput.selectedRow == 0:
wheelTableInput.selectedRow = wheelTableInput.rowCount - 1
gm.ui.messageBox("Select a row to delete.")
else:
Expand All @@ -2030,10 +2011,7 @@ def notify(self, args):
addJointInput.isEnabled = True
addWheelInput.isEnabled = True

if (
jointTableInput.selectedRow == -1
or jointTableInput.selectedRow == 0
):
if jointTableInput.selectedRow == -1 or jointTableInput.selectedRow == 0:
jointTableInput.selectedRow = jointTableInput.rowCount - 1
gm.ui.messageBox("Select a row to delete.")
else:
Expand Down Expand Up @@ -2189,9 +2167,7 @@ def notify(self, args):
onSelect.allWheelPreselections.clear()
onSelect.wheelJointList.clear()

for (
group
) in gm.app.activeDocument.design.rootComponent.customGraphicsGroups:
for group in gm.app.activeDocument.design.rootComponent.customGraphicsGroups:
group.deleteMe()

# Currently causes Internal Autodesk Error
Expand Down Expand Up @@ -2260,9 +2236,7 @@ def addJointToTable(joint: adsk.fusion.Joint) -> None:
icon.tooltip = "Ball joint"

# joint name
name = cmdInputs.addTextBoxCommandInput(
"name_j", "Occurrence name", "", 1, True
)
name = cmdInputs.addTextBoxCommandInput("name_j", "Occurrence name", "", 1, True)
name.tooltip = joint.name
name.formattedText = "<p style='font-size:11px'>{}</p>".format(joint.name)

Expand Down Expand Up @@ -2535,9 +2509,9 @@ def removeWheelFromTable(index: int) -> None:
except IndexError:
pass
except:
logging.getLogger(
"{INTERNAL_ID}.UI.ConfigCommand.removeWheelFromTable()"
).error("Failed:\n{}".format(traceback.format_exc()))
logging.getLogger("{INTERNAL_ID}.UI.ConfigCommand.removeWheelFromTable()").error(
"Failed:\n{}".format(traceback.format_exc())
)


def removeJointFromTable(joint: adsk.fusion.Joint) -> None:
Expand Down Expand Up @@ -2573,9 +2547,9 @@ def removeJointFromTable(joint: adsk.fusion.Joint) -> None:
else:
listItems.item(index).deleteMe()
except:
logging.getLogger(
"{INTERNAL_ID}.UI.ConfigCommand.removeJointFromTable()"
).error("Failed:\n{}".format(traceback.format_exc()))
logging.getLogger("{INTERNAL_ID}.UI.ConfigCommand.removeJointFromTable()").error(
"Failed:\n{}".format(traceback.format_exc())
)


def removeGamePieceFromTable(index: int) -> None:
Expand Down
6 changes: 2 additions & 4 deletions exporter/SynthesisFusionAddin/src/UI/CustomGraphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ def createTextGraphics(wheel: adsk.fusion.Occurrence, _wheels) -> None:
graphicsText.cullMode = (
adsk.fusion.CustomGraphicsCullModes.CustomGraphicsCullBack
)
graphicsText.color = (
adsk.fusion.CustomGraphicsShowThroughColorEffect.create(
adsk.core.Color.create(230, 146, 18, 255), 1
)
graphicsText.color = adsk.fusion.CustomGraphicsShowThroughColorEffect.create(
adsk.core.Color.create(230, 146, 18, 255), 1
) # orange/synthesis theme
graphicsText.depthPriority = 0

Expand Down
12 changes: 3 additions & 9 deletions exporter/SynthesisFusionAddin/src/UI/HUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,19 +138,15 @@ def __init__(
cmdDef = gm.ui.commandDefinitions.itemById(self.uid)
if cmdDef:
# gm.ui.messageBox("Looks like you have experienced a crash we will do cleanup.")
self.logger.debug(
"Looks like there was a crash, doing cleanup in button id"
)
self.logger.debug("Looks like there was a crash, doing cleanup in button id")
self.scrub()

# needs to updated with new OString data
self.button = gm.ui.commandDefinitions.addButtonDefinition(
self.uid,
f"{name}",
f"{description}",
OsHelper.getOSPath(
".", "src", "Resources", f'{self.name.replace(" ", "")}'
),
OsHelper.getOSPath(".", "src", "Resources", f'{self.name.replace(" ", "")}'),
)
""" Button Command Definition stored as a member """

Expand Down Expand Up @@ -208,9 +204,7 @@ def deleteMe(self):
self.logger.debug(f"Removing Button {self.uid}")
cmdDef.deleteMe()

ctrl = gm.ui.allToolbarPanels.itemById(self.location).controls.itemById(
self.uid
)
ctrl = gm.ui.allToolbarPanels.itemById(self.location).controls.itemById(self.uid)
if ctrl:
self.logger.debug(f"Removing Button Control {self.location}:{self.uid}")
ctrl.deleteMe()
Expand Down
6 changes: 2 additions & 4 deletions exporter/SynthesisFusionAddin/src/UI/IconPaths.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@
"omni": resources + os.path.join("WheelIcons", "omni-wheel-preview190x24.png"),
"standard": resources
+ os.path.join("WheelIcons", "standard-wheel-preview190x24.png"),
"mecanum": resources
+ os.path.join("WheelIcons", "mecanum-wheel-preview190x24.png"),
"mecanum": resources + os.path.join("WheelIcons", "mecanum-wheel-preview190x24.png"),
}

jointIcons = {
"rigid": resources + os.path.join("JointIcons", "JointRigid", "rigid190x24.png"),
"revolute": resources
+ os.path.join("JointIcons", "JointRev", "revolute190x24.png"),
"revolute": resources + os.path.join("JointIcons", "JointRev", "revolute190x24.png"),
"slider": resources + os.path.join("JointIcons", "JointSlider", "slider190x24.png"),
"cylindrical": resources
+ os.path.join("JointIcons", "JointCyl", "cylindrical190x24.png"),
Expand Down
4 changes: 1 addition & 3 deletions exporter/SynthesisFusionAddin/src/UI/Toolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ def getPanel(self, name: str, visibility: bool = True) -> str or None:
self.logger.debug(f"Created Panel {panel_uid} in Toolbar {self.uid}")
return panel_uid
else:
self.logger.error(
f"Failed to Create Panel {panel_uid} in Toolbar {self.uid}"
)
self.logger.error(f"Failed to Create Panel {panel_uid} in Toolbar {self.uid}")
return None

@staticmethod
Expand Down

0 comments on commit dda2853

Please sign in to comment.