Skip to content

Commit

Permalink
Merge branch 'dev' into dhruv/1787/import-file-move (also moved the b…
Browse files Browse the repository at this point in the history
…utton to the bottom)
  • Loading branch information
LucaHaverty committed Aug 9, 2024
2 parents 937a62e + 1a171c5 commit 51cced9
Show file tree
Hide file tree
Showing 81 changed files with 2,622 additions and 1,521 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/FissionUnitTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
with:
path: |
~/.cache/ms-playwright/
key: ${{ runner.os }}-assets-playwright-${{ env.PLAYWRIGHT_VERSION }}
key: ${{ runner.os }}-assets-playwright-${{ env.PLAYWRIGHT_VERSION }}-v2

- name: Install Dependencies
run: |
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "mirabuf"]
path = mirabuf
url = https://github.com/HiceS/mirabuf.git
[submodule "jolt"]
path = jolt
url = https://github.com/HunterBarclay/JoltPhysics.js.git
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ All code is under a configured formatting utility. See each component for more d

Mirabuf is a file format we use to store physical data from Fusion to load into the Synthesis simulator (Fission). This is a separate project that is a submodule of Synthesis. [See Mirabuf](https://github.com/HiceS/mirabuf/)

### Jolt Physics

Jolt is the core physics engine for our web biased simulator. [See JoltPhysics.js](https://github.com/HunterBarclay/JoltPhysics.js) for more information.

### Tutorials

Our source code for the tutorials featured on our [Tutorials Page](https://synthesis.autodesk.com/tutorials.html).
Expand Down
68 changes: 29 additions & 39 deletions exporter/SynthesisFusionAddin/Synthesis.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,45 @@

import adsk.core

# Currently required for `resolveDependencies()`, will be required for absolute imports.
# Required for absolute imports.
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "proto", "proto_out")))

from .src.Dependencies import resolveDependencies # isort:skip
from src.Dependencies import resolveDependencies
from src.Logging import logFailure, setupLogger

# Transition: AARD-1741
# Import order should be removed in AARD-1737 and `setupLogger()` moved to `__init__.py`
from .src.Logging import getLogger, logFailure, setupLogger # isort:skip

setupLogger()
logger = setupLogger()

try:
from .src.general_imports import APP_NAME, DESCRIPTION, INTERNAL_ID, gm
from .src.UI import (
HUI,
Camera,
ConfigCommand,
MarkingMenu,
ShowAPSAuthCommand,
ShowWebsiteCommand,
# Attempt to import required pip dependencies to verify their installation.
import requests
from proto.proto_out import (
assembly_pb2,
joint_pb2,
material_pb2,
motor_pb2,
signal_pb2,
types_pb2,
)
from .src.UI.Toolbar import Toolbar
except (ImportError, ModuleNotFoundError) as error:
getLogger().warn(f"Running resolve dependencies with error of:\n{error}")
except (ImportError, ModuleNotFoundError, BaseException) as error: # BaseException required to catch proto.VersionError
logger.warn(f"Running resolve dependencies with error of:\n{error}")
result = resolveDependencies()
if result:
adsk.core.Application.get().userInterface.messageBox("Installed required dependencies.\nPlease restart Fusion.")


from src import APP_NAME, DESCRIPTION, INTERNAL_ID, gm
from src.UI import (
HUI,
Camera,
ConfigCommand,
MarkingMenu,
ShowAPSAuthCommand,
ShowWebsiteCommand,
)
from src.UI.Toolbar import Toolbar


@logFailure
def run(_):
"""## Entry point to application from Fusion.
Expand Down Expand Up @@ -68,28 +78,8 @@ def stop(_):

# nm.deleteMe()

logger = getLogger(INTERNAL_ID)
logger.cleanupHandlers()

for file in gm.files:
try:
os.remove(file)
except OSError:
pass

# removes path so that proto files don't get confused

import sys

path = os.path.abspath(os.path.dirname(__file__))

path_proto_files = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "proto", "proto_out"))

if path in sys.path:
sys.path.remove(path)

if path_proto_files in sys.path:
sys.path.remove(path_proto_files)
gm.clear()


@logFailure
Expand Down
6 changes: 3 additions & 3 deletions exporter/SynthesisFusionAddin/src/APS/APS.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@

import requests

from ..general_imports import INTERNAL_ID, gm, my_addin_path
from ..Logging import getLogger
from src import ADDIN_PATH, gm
from src.Logging import getLogger

logger = getLogger()

CLIENT_ID = "GCxaewcLjsYlK8ud7Ka9AKf9dPwMR3e4GlybyfhAK2zvl3tU"
auth_path = os.path.abspath(os.path.join(my_addin_path, "..", ".aps_auth"))
auth_path = os.path.abspath(os.path.join(ADDIN_PATH, "..", ".aps_auth"))

APS_AUTH = None
APS_USER_INFO = None
Expand Down
17 changes: 7 additions & 10 deletions exporter/SynthesisFusionAddin/src/Dependencies.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import importlib.machinery
import importlib.util
import os
import platform
import subprocess
import sys
from pathlib import Path

import adsk.core
import adsk.fusion

from .Logging import getLogger, logFailure
from src import SYSTEM
from src.Logging import getLogger, logFailure

logger = getLogger()
system = platform.system()

# Since the Fusion python runtime is separate from the system python runtime we need to do some funky things
# in order to download and install python packages separate from the standard library.
Expand All @@ -29,13 +28,11 @@ def getInternalFusionPythonInstillationFolder() -> str:
pythonStandardLibraryModulePath = importlib.machinery.PathFinder.find_spec("os", sys.path).origin

# Depending on platform, adjust to folder to where the python executable binaries are stored.
if system == "Windows":
if SYSTEM == "Windows":
folder = f"{Path(pythonStandardLibraryModulePath).parents[1]}"
elif system == "Darwin":
folder = f"{Path(pythonStandardLibraryModulePath).parents[2]}/bin"
else:
# TODO: System string should be moved to __init__ after GH-1013
raise RuntimeError("Unsupported platform.")
assert SYSTEM == "Darwin"
folder = f"{Path(pythonStandardLibraryModulePath).parents[2]}/bin"

return folder

Expand Down Expand Up @@ -100,7 +97,7 @@ def resolveDependencies() -> bool | None:
adsk.doEvents()

pythonFolder = getInternalFusionPythonInstillationFolder()
pythonExecutableFile = "python.exe" if system == "Windows" else "python" # Confirming 110% everything is fine.
pythonExecutableFile = "python.exe" if SYSTEM == "Windows" else "python" # Confirming 110% everything is fine.
pythonExecutablePath = os.path.join(pythonFolder, pythonExecutableFile)

progressBar = ui.createProgressDialog()
Expand All @@ -109,7 +106,7 @@ def resolveDependencies() -> bool | None:
progressBar.show("Synthesis", f"Installing dependencies...", 0, len(PIP_DEPENDENCY_VERSION_MAP) * 2 + 2, 0)

# Install pip manually on macos as it is not included by default? Really?
if system == "Darwin" and not os.path.exists(os.path.join(pythonFolder, "pip")):
if SYSTEM == "Darwin" and not os.path.exists(os.path.join(pythonFolder, "pip")):
pipInstallScriptPath = os.path.join(pythonFolder, "get-pip.py")
if not os.path.exists(pipInstallScriptPath):
executeCommand("curl", "https://bootstrap.pypa.io/get-pip.py", "-o", pipInstallScriptPath)
Expand Down
10 changes: 5 additions & 5 deletions exporter/SynthesisFusionAddin/src/GlobalManager.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
""" Initializes the global variables that are set in the run method to reduce hanging commands. """

import logging

import adsk.core
import adsk.fusion

from .general_imports import *
from .strings import *


class GlobalManager(object):
"""Global Manager instance"""
Expand Down Expand Up @@ -47,6 +42,11 @@ def __init__(self):
def __str__(self):
return "GlobalManager"

def clear(self):
for attr, value in self.__dict__.items():
if isinstance(value, list):
setattr(self, attr, [])

instance = None

def __new__(cls):
Expand Down
7 changes: 4 additions & 3 deletions exporter/SynthesisFusionAddin/src/Logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

import adsk.core

from .strings import INTERNAL_ID
from .UI.OsHelper import getOSPath
from src import INTERNAL_ID
from src.UI.OsHelper import getOSPath

MAX_LOG_FILES_TO_KEEP = 10
TIMING_LEVEL = 25
Expand All @@ -27,7 +27,7 @@ def cleanupHandlers(self) -> None:
handler.close()


def setupLogger() -> None:
def setupLogger() -> SynthesisLogger:
now = datetime.now().strftime("%H-%M-%S")
today = date.today()
logFileFolder = getOSPath(f"{pathlib.Path(__file__).parent.parent}", "logs")
Expand All @@ -46,6 +46,7 @@ def setupLogger() -> None:
logger = getLogger(INTERNAL_ID)
logger.setLevel(10) # Debug
logger.addHandler(logHandler)
return cast(SynthesisLogger, logger)


def getLogger(name: str | None = None) -> SynthesisLogger:
Expand Down
6 changes: 3 additions & 3 deletions exporter/SynthesisFusionAddin/src/Parser/ExporterOptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
import adsk.core
from adsk.fusion import CalculationAccuracy, TriangleMeshQualityOptions

from ..Logging import logFailure, timed
from ..strings import INTERNAL_ID
from ..Types import (
from src import INTERNAL_ID
from src.Logging import logFailure, timed
from src.Types import (
KG,
ExportLocation,
ExportMode,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
# Contains all of the logic for mapping the Components / Occurrences
import logging
import traceback
import uuid
from typing import *

import adsk.core
import adsk.fusion

from proto.proto_out import assembly_pb2, joint_pb2, material_pb2, types_pb2

from ...Logging import logFailure, timed
from ...Types import ExportMode
from ..ExporterOptions import ExporterOptions
from . import PhysicalProperties
from .PDMessage import PDMessage
from .Utilities import *
from src.Logging import logFailure
from src.Parser.ExporterOptions import ExporterOptions
from src.Parser.SynthesisParser import PhysicalProperties
from src.Parser.SynthesisParser.PDMessage import PDMessage
from src.Parser.SynthesisParser.Utilities import (
fill_info,
guid_component,
guid_occurrence,
)
from src.Types import ExportMode

# TODO: Impelement Material overrides

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import enum
import logging
import traceback
from typing import *
from typing import Union

import adsk.core
import adsk.fusion

from proto.proto_out import joint_pb2, types_pb2

from ...general_imports import *
from ...Logging import getLogger, logFailure
from ..ExporterOptions import ExporterOptions
from .PDMessage import PDMessage
from .Utilities import guid_component, guid_occurrence
from src import gm
from src.Logging import getLogger, logFailure
from src.Parser.ExporterOptions import ExporterOptions
from src.Parser.SynthesisParser.PDMessage import PDMessage
from src.Parser.SynthesisParser.Utilities import guid_component, guid_occurrence

logger = getLogger()

Expand Down
20 changes: 11 additions & 9 deletions exporter/SynthesisFusionAddin/src/Parser/SynthesisParser/Joints.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,17 @@

import adsk.core
import adsk.fusion

from proto.proto_out import assembly_pb2, joint_pb2, motor_pb2, signal_pb2, types_pb2

from ...general_imports import *
from ...Logging import getLogger
from ...Types import JointParentType, SignalType
from ..ExporterOptions import ExporterOptions
from .PDMessage import PDMessage
from .Utilities import construct_info, fill_info, guid_occurrence
from proto.proto_out import assembly_pb2, joint_pb2, signal_pb2, types_pb2

from src.Logging import getLogger
from src.Parser.ExporterOptions import ExporterOptions
from src.Parser.SynthesisParser.PDMessage import PDMessage
from src.Parser.SynthesisParser.Utilities import (
construct_info,
fill_info,
guid_occurrence,
)
from src.Types import JointParentType, SignalType

logger = getLogger()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
# Should contain Physical and Apperance materials ?
import json
import logging
import math
import traceback

import adsk

from proto.proto_out import material_pb2

from ...general_imports import *
from ...Logging import logFailure, timed
from ..ExporterOptions import ExporterOptions
from .PDMessage import PDMessage
from .Utilities import *
from src.Logging import logFailure
from src.Parser.ExporterOptions import ExporterOptions
from src.Parser.SynthesisParser.PDMessage import PDMessage
from src.Parser.SynthesisParser.Utilities import construct_info, fill_info

OPACITY_RAMPING_CONSTANT = 14.0

Expand Down
23 changes: 14 additions & 9 deletions exporter/SynthesisFusionAddin/src/Parser/SynthesisParser/Parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,22 @@
import adsk.core
import adsk.fusion
from google.protobuf.json_format import MessageToJson

from proto.proto_out import assembly_pb2, types_pb2

from ...APS.APS import getAuth, upload_mirabuf
from ...general_imports import *
from ...Logging import getLogger, logFailure, timed
from ...Types import ExportLocation, ExportMode
from ...UI.Camera import captureThumbnail, clearIconCache
from ..ExporterOptions import ExporterOptions
from . import Components, JointHierarchy, Joints, Materials, PDMessage
from .Utilities import *
from src import gm
from src.APS.APS import getAuth, upload_mirabuf
from src.Logging import getLogger, logFailure, timed
from src.Parser.ExporterOptions import ExporterOptions
from src.Parser.SynthesisParser import (
Components,
JointHierarchy,
Joints,
Materials,
PDMessage,
)
from src.Parser.SynthesisParser.Utilities import fill_info
from src.Types import ExportLocation, ExportMode
from src.UI.Camera import captureThumbnail, clearIconCache

logger = getLogger()

Expand Down
Loading

0 comments on commit 51cced9

Please sign in to comment.