Skip to content

Commit

Permalink
Small refactor to rely on enums
Browse files Browse the repository at this point in the history
  • Loading branch information
BrandonPacewic committed Jun 19, 2024
1 parent 3e943c1 commit 18033c3
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 66 deletions.
62 changes: 13 additions & 49 deletions exporter/SynthesisFusionAddin/src/Parser/ParseOptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,13 @@
from dataclasses import dataclass, fields, field
import adsk.core, adsk.fusion

# from .unity import Parse
from ..strings import INTERNAL_ID
from .SynthesisParser.Parser import Parser


# Contains enums for parents of joints that have special cases
class JointParentType: # validate for unique key and value
ROOT = 0 # grounded root object
END = 1

# JointParentType = Enum("JointParentType", ["ROOT", "END"])

class WheelType:
STANDARD = 0
OMNI = 1

# WheelType = Enum("WheelType", ["STANDARD", "OMNI"])


class SignalType:
PWM = 0
CAN = 1
PASSIVE = 2

# SignalType = Enum("SignalType", ["PWM", "CAN", "PASSIVE"])
JointParentType = Enum("JointParentType", ["ROOT", "END"])
WheelType = Enum("WheelType", ["STANDARD", "OMNI"])
SignalType = Enum("SignalType", ["PWM", "CAN", "PASSIVE"])
ExportMode = Enum("ExportMode", ["ROBOT", "FIELD"])


# will need to be constructed in the UI Configure on Export
Expand All @@ -64,8 +46,7 @@ class Gamepiece:
friction: float


class PhysicalDepth:
# class PhysicalDepth(Enum):
class PhysicalDepth(Enum):
"""Depth at which the Physical Properties are generated and saved
- This is mostly dictated by export type as flattening or any hierarchical modification takes precedence
"""
Expand All @@ -80,8 +61,7 @@ class PhysicalDepth:
""" Every Single Occurrence has Physical Properties even if empty """


class ModelHierarchy:
# class ModelHierarchy(Enum):
class ModelHierarchy(Enum):
"""
Enum Class to describe how the model format should look on export to suit different needs
"""
Expand All @@ -99,13 +79,6 @@ class ModelHierarchy:
""" Generates the root assembly as a single mesh and stores the associated data """


class Mode:
Synthesis = 0
SynthesisField = 3

# Mode = Enum("Mode", ["ROBOT", "FIELD"])


class ParseOptions:
"""Options to supply to the parser object that will generate the output file"""

Expand All @@ -119,7 +92,7 @@ def __init__(
physical=adsk.fusion.CalculationAccuracy.LowCalculationAccuracy,
physicalDepth=PhysicalDepth.AllOccurrence,
materials=1,
mode=Mode.Synthesis,
mode=ExportMode.ROBOT,
wheels=list[_Wheel],
joints=list[_Joint], # [{Occurrence, wheeltype} , {entitytoken, wheeltype}]
gamepieces=list[Gamepiece],
Expand Down Expand Up @@ -155,19 +128,6 @@ def __init__(
self.weight = weight # full weight of robot in KG
self.compress = compress

def parse(self, _: bool) -> str | bool:
"""Parses the file given the options
Args:
sendReq (bool): Do you want to send the request generated by the parser with sockets
Returns:
str | bool: Either a str indicating success or False indicating failure
"""

Parser(self).export()
return True


# TODO: This should be the only parse option class
@dataclass
Expand All @@ -177,7 +137,9 @@ class ExporterOptions:
name: str = field(default=None)
version: str = field(default=None)
materials: int = field(default=0) # TODO: Find out what this is for
mode: Mode = field(default=Mode.Synthesis)
mode: ExportMode = field(
default=ExportMode.ROBOT
) # TODO: Maybe rename 'mode' to 'exportMode'
wheels: list[_Wheel] = field(default=None)
joints: list[_Joint] = field(default=None)
gamepieces: list[Gamepiece] = field(default=None)
Expand Down Expand Up @@ -207,7 +169,9 @@ def read(self):

def readHelper(self, objectType, data):
primitives = (bool, str, int, float, type(None))
if objectType in primitives or type(data) in primitives: # Required to catch `fusion.TriangleMeshQualityOptions`
if (
objectType in primitives or type(data) in primitives
): # Required to catch `fusion.TriangleMeshQualityOptions`
return data
elif isinstance(objectType, EnumType):
return objectType(data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def __parseChildOccurrence(
part.part_definition_reference = compRef

# TODO: Maybe make this a separate step where you dont go backwards and search for the gamepieces
if options.mode == ParseOptions.Mode.SynthesisField:
if options.mode == ParseOptions.ExportMode.FIELD:
for x in options.gamepieces:
if x.occurrence_token == mapConstant:
partsData.part_definitions[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from ...general_imports import *
from .Utilities import fill_info, construct_info, guid_occurrence
from .PDMessage import PDMessage
from .. import ParseOptions
from ..ParseOptions import ParseOptions, JointParentType


# Need to take in a graphcontainer
Expand Down Expand Up @@ -481,10 +481,10 @@ def createJointGraph(
# second sort them
for supplied_joint in supplied_joints:
current_node = node_map[supplied_joint.joint_token]
if supplied_joint.parent == 0:
if supplied_joint.parent == JointParentType.ROOT:
node_map["ground"].children.append(node_map[supplied_joint.joint_token])
elif (
node_map[supplied_joint.parent] is not None
node_map[supplied_joint.parent.value] is not None
and node_map[supplied_joint.joint_token] is not None
):
node_map[supplied_joint.parent].children.append(
Expand Down
18 changes: 5 additions & 13 deletions exporter/SynthesisFusionAddin/src/UI/ConfigCommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from . import Helper, OsHelper, CustomGraphics, IconPaths
from ..Parser.ParseOptions import (
Gamepiece,
Mode,
ExportMode,
ParseOptions,
ExporterOptions, # TODO
_Joint,
Expand Down Expand Up @@ -1168,7 +1168,7 @@ def notify(self, args):
_exportJoints = [] # all selected joints, formatted for parseOptions
_exportGamepieces = [] # TODO work on the code to populate Gamepiece
_robotWeight = float
_mode = Mode
_mode = ExportMode.ROBOT

"""
Loops through all rows in the wheel table to extract all the input values
Expand Down Expand Up @@ -1301,9 +1301,9 @@ def notify(self, args):
"""
dropdownExportMode = INPUTS_ROOT.itemById("mode")
if dropdownExportMode.selectedItem.index == 0:
_mode = Mode.Synthesis
_mode = ExportMode.ROBOT
elif dropdownExportMode.selectedItem.index == 1:
_mode = Mode.SynthesisField
_mode = ExportMode.FIELD

global compress
compress = (
Expand Down Expand Up @@ -1342,15 +1342,7 @@ def notify(self, args):
# )
# exporterOptions.write()

# if not options.parse():
# # Fail message
# self.log.error(
# f"Error: \n\t{name} could not be written to \n {savepath}"
# )

options.parse(False)
# Parser(options).export()
# exporterOptions.write()
Parser(options).export()
except:
if gm.ui:
gm.ui.messageBox("Failed:\n{}".format(traceback.format_exc()))
Expand Down

0 comments on commit 18033c3

Please sign in to comment.