84 |
87 |
88 |
160 |
161 |
162 |
166 | {isMonacoSupported && (
167 | model.source = s ?? ''}
173 | onMount={onMount} // TODO: This looks a bit silly, does it trigger a re-render??
174 | options={{
175 | ...openscadEditorOptions,
176 | fontSize: 16,
177 | lineNumbers: state.view.lineNumbers ? 'on' : 'off',
178 | }}
179 | />
180 | )}
181 | {!isMonacoSupported && (
182 | model.source = s.target.value ?? ''}
186 | />
187 | )}
188 |
189 |
190 |
195 | {(state.currentRunLogs ?? []).map(([type, text], i) => (
196 |
{text}
197 | ))}
198 |
199 |
200 |
201 | )
202 | }
203 |
--------------------------------------------------------------------------------
/src/components/ExportButton.tsx:
--------------------------------------------------------------------------------
1 | import React, { useContext } from 'react';
2 | import { ModelContext } from './contexts.ts';
3 |
4 | import { SplitButton } from 'primereact/splitbutton';
5 | import { MenuItem } from 'primereact/menuitem';
6 |
7 | type ExtendedMenuItem = MenuItem & { buttonLabel?: string };
8 |
9 | export default function ExportButton({className, style}: {className?: string, style?: React.CSSProperties}) {
10 | const model = useContext(ModelContext);
11 | if (!model) throw new Error('No model');
12 | const state = model.state;
13 |
14 | const dropdownModel: ExtendedMenuItem[] =
15 | state.is2D ? [
16 | {
17 | data: 'svg',
18 | buttonLabel: 'SVG',
19 | label: 'SVG (Simple Vector Graphics)',
20 | icon: 'pi pi-download',
21 | command: () => model!.setFormats('svg', undefined),
22 | },
23 | {
24 | data: 'dxf',
25 | buttonLabel: 'DXF',
26 | label: 'DXF (Drawing Exchange Format)',
27 | icon: 'pi pi-download',
28 | command: () => model!.setFormats('dxf', undefined),
29 | },
30 | ] : [
31 | {
32 | data: 'glb',
33 | buttonLabel: 'Download GLB',
34 | label: 'GLB (binary glTF)',
35 | icon: 'pi pi-file',
36 | command: () => model!.setFormats(undefined, 'glb'),
37 | },
38 | {
39 | data: 'stl',
40 | buttonLabel: 'Download STL',
41 | label: 'STL (binary)',
42 | icon: 'pi pi-file',
43 | command: () => model!.setFormats(undefined, 'stl'),
44 | },
45 | {
46 | data: 'off',
47 | buttonLabel: 'Download OFF',
48 | label: 'OFF (Object File Format)',
49 | icon: 'pi pi-file',
50 | command: () => model!.setFormats(undefined, 'off'),
51 | },
52 | {
53 | data: '3mf',
54 | buttonLabel: 'Download 3MF',
55 | label: '3MF (Multimaterial)',
56 | icon: 'pi pi-file',
57 | command: () => model!.setFormats(undefined, '3mf'),
58 | },
59 | {
60 | separator: true
61 | },
62 | {
63 | label: 'Edit materials' + ((state.params.extruderColors ?? []).length > 0 ? ` (${(state.params.extruderColors ?? []).length})` : ''),
64 | icon: 'pi pi-cog',
65 | command: () => model!.mutate(s => s.view.extruderPickerVisibility = 'editing'),
66 | }
67 | ];
68 |
69 | const exportFormat = state.is2D ? state.params.exportFormat2D : state.params.exportFormat3D;
70 | const selectedItem = dropdownModel.filter(item => item.data === exportFormat)[0] || dropdownModel[0]!;
71 |
72 | return (
73 |