Skip to content

Commit

Permalink
AARD-1671: Fission import panel modal (#980)
Browse files Browse the repository at this point in the history
  • Loading branch information
HunterBarclay authored Jun 27, 2024
2 parents f22f995 + db377a6 commit 0921bc9
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __init__(self, options: ExporterOptions):
def export(self) -> bool:
try:
app = adsk.core.Application.get()
design = app.activeDocument.design
design: adsk.fusion.Design = app.activeDocument.design

assembly_out = assembly_pb2.Assembly()
fill_info(
Expand Down
1 change: 1 addition & 0 deletions exporter/SynthesisFusionAddin/src/UI/ConfigCommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -1351,6 +1351,7 @@ def notify(self, args):
gm.app.activeViewport.refresh()
else:
gm.app.activeDocument.design.rootComponent.opacity = 1

for (
group
) in gm.app.activeDocument.design.rootComponent.customGraphicsGroups:
Expand Down
2 changes: 1 addition & 1 deletion exporter/SynthesisFusionAddin/src/general_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
A_EP = None

# Setup the global state
gm = GlobalManager()
gm: GlobalManager = GlobalManager()
my_addin_path = os.path.dirname(os.path.realpath(__file__))
except:
# should also log this
Expand Down
10 changes: 6 additions & 4 deletions fission/src/Synthesis.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ import ScoringZonesPanel from "@/panels/configuring/scoring/ScoringZonesPanel"
import ZoneConfigPanel from "@/panels/configuring/scoring/ZoneConfigPanel"
import ScoreboardPanel from "@/panels/information/ScoreboardPanel"
import DriverStationPanel from "@/panels/simulation/DriverStationPanel"
import ManageAssembliesModal from "@/modals/spawning/ManageAssembliesModal.tsx"
import World from "@/systems/World.ts"
import { AddRobotsModal, AddFieldsModal, SpawningModal } from "@/modals/spawning/SpawningModals.tsx"
import ImportMirabufModal from "@/modals/mirabuf/ImportMirabufModal.tsx"
import ManageAssembliesModal from '@/modals/spawning/ManageAssembliesModal.tsx';
import World from '@/systems/World.ts';
import { AddRobotsModal, AddFieldsModal, SpawningModal } from '@/modals/spawning/SpawningModals.tsx';
import ImportMirabufModal from '@/modals/mirabuf/ImportMirabufModal.tsx';
import ImportLocalMirabufModal from '@/modals/mirabuf/ImportLocalMirabufModal.tsx';

const DEFAULT_MIRA_PATH = "/api/mira/Robots/Team 2471 (2018)_v7.mira"

Expand Down Expand Up @@ -192,6 +193,7 @@ const initialModals = [
<ConfigMotorModal modalId="config-motor" />,
<ManageAssembliesModal modalId="manage-assembles" />,
<ImportMirabufModal modalId="import-mirabuf" />,
<ImportLocalMirabufModal modalId="import-local-mirabuf" />,
]

const initialPanels: ReactElement[] = [
Expand Down
11 changes: 10 additions & 1 deletion fission/src/ui/components/MainHUD.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,16 @@ const MainHUD: React.FC = () => {
icon={<IoPeople />}
onClick={() => openModal("import-mirabuf")}
/>
<MainHUDButton value={"Test God Mode"} icon={<IoGameControllerOutline />} onClick={TestGodMode} />
<MainHUDButton
value={"Import Local Mira"}
icon={<IoPeople />}
onClick={() => openModal("import-local-mirabuf")}
/>
<MainHUDButton
value={"Test God Mode"}
icon={<IoGameControllerOutline />}
onClick={TestGodMode}
/>
</div>
<div className="flex flex-col gap-0 bg-background w-full rounded-3xl">
<MainHUDButton
Expand Down
68 changes: 68 additions & 0 deletions fission/src/ui/modals/mirabuf/ImportLocalMirabufModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import Button, { ButtonSize } from "@/components/Button"
import Modal, { ModalPropsImpl } from "../../components/Modal"
import { FaPlus } from "react-icons/fa6"
import { ChangeEvent, useRef, useState } from "react"
import Label, { LabelSize } from "@/components/Label"
import { useTooltipControlContext } from "@/ui/TooltipContext"
import { CreateMirabufFromUrl } from "@/mirabuf/MirabufSceneObject"
import World from "@/systems/World"

const ImportLocalMirabufModal: React.FC<ModalPropsImpl> = ({ modalId }) => {
// update tooltip based on type of drivetrain, receive message from Synthesis
const { showTooltip } = useTooltipControlContext()

const fileUploadRef = useRef<HTMLInputElement>(null)

const [selectedFile, setSelectedFile] = useState<File | undefined>(undefined)

const uploadClicked = () => {
if (fileUploadRef.current) {
fileUploadRef.current.click()
}
}

const onInputChanged = (e: ChangeEvent<HTMLInputElement>) => {
if (e.target.files) {
const file = e.target.files[0]
setSelectedFile(file)
}
}

return (
<Modal
name={"Import Local Assemblies"}
icon={<FaPlus />}
modalId={modalId}
acceptEnabled={selectedFile !== undefined}
onAccept={() => {
if (selectedFile) {
console.log(`Mira: '${selectedFile}'`)
showTooltip("controls", [
{ control: "WASD", description: "Drive" },
{ control: "E", description: "Intake" },
{ control: "Q", description: "Dispense" },
])

CreateMirabufFromUrl(URL.createObjectURL(selectedFile)).then(x => {
if (x) {
World.SceneRenderer.RegisterSceneObject(x)
}
})
}
}
}
>
<div className="flex flex-col items-center gap-5">
<input ref={fileUploadRef} onChange={onInputChanged} type="file" hidden={true} />
<Button value="Upload" size={ButtonSize.Large} onClick={uploadClicked} />
{
selectedFile
? (<Label className="text-center" size={LabelSize.Medium}>{`Selected File: ${selectedFile.name}`}</Label>)
: (<></>)
}
</div>
</Modal>
)
}

export default ImportLocalMirabufModal

0 comments on commit 0921bc9

Please sign in to comment.