Skip to content

Exporter UI Refactor [AARD-1883] #1194

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

Open
wants to merge 18 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions .github/workflows/FusionWebUI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: Fusion - WebUI Build and Format

on:
workflow_dispatch: {}

push:
branches: [ prod, dev ]
paths:
- 'exporter/SynthesisFusionAddin/web/**'
pull_request:
branches: [ prod, dev ]
paths:
- 'exporter/SynthesisFusionAddin/web/**'


jobs:
runFormatValidationScript:
name: ESLint Format Validation
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: JavaScript Setup
uses: actions/setup-node@v4
with:
node-version: 24

- name: Cache Node Dependencies
uses: actions/cache@v3
with:
key: "${{runner.os}}-npm-fusion-${{hashFiles('exporter/SynthesisFusionAddin/web/package-lock.json')}}"
path: 'exporter/SynthesisFusionAddin/web/node_modules'
restore-keys: |
${{runner.os}}-npm-fusion-
${{runner.os}}-npm

- name: Install Dependencies
run: |
cd exporter/SynthesisFusionAddin/web
npm ci

- name: Linter
id: linter-validation
if: ${{ always() }}
run: |
cd exporter/SynthesisFusionAddin/web
npm run lint && echo "ESLint Validation Passed" || (echo "ESLint Validation Failed" && exit 1)

- name: Prettier
id: prettier-validation
if: ${{ always() }}
run: |
cd exporter/SynthesisFusionAddin/web
npx prettier --version
npm run prettier && echo "Prettier Validation Passed" || (echo "Prettier Validation Failed" && exit 1)
runBuildScript:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: JavaScript Setup
uses: actions/setup-node@v4
with:
node-version: 24

- name: Cache Node Dependencies
uses: actions/cache@v3
with:
key: "${{runner.os}}-npm-fusion-${{hashFiles('exporter/SynthesisFusionAddin/web/package-lock.json')}}"
path: 'exporter/SynthesisFusionAddin/web/node_modules'
restore-keys: |
${{runner.os}}-npm-fusion-
${{runner.os}}-npm

- name: Install Dependencies
run: |
cd exporter/SynthesisFusionAddin/web
npm ci

- name: Build
id: build
if: ${{ always() }}
run: |
cd exporter/SynthesisFusionAddin/web
npm run build && echo "Build Successful" || (echo "Build Failed" && exit 1)
28 changes: 25 additions & 3 deletions exporter/SynthesisFusionAddin/src/Parser/ExporterOptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
import os
import platform
from dataclasses import dataclass, field, fields
from typing import Any, List

import adsk.core
from adsk.fusion import CalculationAccuracy, TriangleMeshQualityOptions

from src import INTERNAL_ID
from src.Logging import logFailure, timed
from src.Logging import getLogger, logFailure, timed
from src.Types import (
KG,
ExportLocation,
Expand All @@ -39,7 +40,7 @@ class ExporterOptions:
version: str | None = field(default=None)
materials: int = field(default=0)
exportMode: ExportMode = field(default=ExportMode.ROBOT)
wheels: list[Wheel] = field(default_factory=list)
wheels: List[Wheel] = field(default_factory=list)
joints: list[Joint] = field(default_factory=list)
gamepieces: list[Gamepiece] = field(default_factory=list)
robotWeight: KG = field(default=KG(0.0))
Expand Down Expand Up @@ -67,7 +68,19 @@ def readFromDesign(self) -> "ExporterOptions":
for field in fields(self):
attribute = designAttributes.itemByName(INTERNAL_ID, field.name)
if attribute:
attrJsonData = makeObjectFromJson(type(field.type), json.loads(attribute.value))
attrJsonData = makeObjectFromJson(field.type, json.loads(attribute.value))
setattr(self, field.name, attrJsonData)

self.visualQuality = TriangleMeshQualityOptions.LowQualityTriangleMesh
return self

@logFailure
# @timed
def readFromJSON(self, data: dict[str, Any]) -> "ExporterOptions":
for field in fields(self):
attribute = data.get(field.name)
if attribute is not None:
attrJsonData = makeObjectFromJson(field.type, attribute)
setattr(self, field.name, attrJsonData)

self.visualQuality = TriangleMeshQualityOptions.LowQualityTriangleMesh
Expand All @@ -80,3 +93,12 @@ def writeToDesign(self) -> None:
for field in fields(self):
data = json.dumps(getattr(self, field.name), default=encodeNestedObjects, indent=4)
designAttributes.add(INTERNAL_ID, field.name, data)

@logFailure
@timed
def writeToJson(self) -> dict[str, Any]:
out = {}
for field in fields(self):
data = json.dumps(getattr(self, field.name), default=encodeNestedObjects, indent=4)
out[field.name] = json.loads(data)
return out
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def __init__(self, options: ExporterOptions):
@logFailure(messageBox=True)
@timed
def export(self) -> None:
getLogger().info(f"Exporting with options {self.exporterOptions}")
app = adsk.core.Application.get()
design: adsk.fusion.Design = app.activeDocument.design

Expand Down
6 changes: 3 additions & 3 deletions exporter/SynthesisFusionAddin/src/Types.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,19 +104,19 @@ def encodeNestedObjects(obj: Any) -> Any:
return obj


def makeObjectFromJson(objType: type, data: Any) -> Any:
# This function was previously taking type(field.type) instead of just field.type, but it didn't seem to be able to deal with lists like that, and this version does seem to be working in all the places where it's used
def makeObjectFromJson(objType: type[Any] | str | Any, data: Any) -> Any:
if isinstance(objType, EnumType):
return objType(data)
elif isinstance(objType, PRIMITIVES) or isinstance(data, PRIMITIVES):
return data
elif get_origin(objType) is list:
return [makeObjectFromJson(get_args(objType)[0], item) for item in data]

obj = objType()
assert is_dataclass(obj) and isinstance(data, dict), "Found unsupported type to decode."
for field in fields(obj):
if field.name in data:
setattr(obj, field.name, makeObjectFromJson(type(field.type), data[field.name]))
setattr(obj, field.name, makeObjectFromJson(field.type, data[field.name]))
else:
setattr(obj, field.name, field.default_factory if field.default_factory is not MISSING else field.default)

Expand Down
Loading
Loading