fix discard new sketch and render on load

master
howard 2021-04-23 00:33:27 -07:00
parent 4e68e61b67
commit 0258bb39bd
8 changed files with 24 additions and 69 deletions

File diff suppressed because one or more lines are too long

View File

@ -26,7 +26,6 @@ export default async (
throwIfExistingHandleNotGood = false throwIfExistingHandleNotGood = false
) => { ) => {
options.fileName = options.fileName || 'Untitled'; options.fileName = options.fileName || 'Untitled';
console.log(options.fileName,"ddddddddddd")
const accept = {}; const accept = {};
if (options.mimeTypes) { if (options.mimeTypes) {
options.mimeTypes.push(blob.type); options.mimeTypes.push(blob.type);

View File

@ -74,9 +74,9 @@ export const Dialog = () => {
} }
const sketchCancel = () => { const sketchCancel = () => {
if (sc.activeSketch.hasChanged if (!sc.activeSketch.hasChanged
|| sc.activeSketch.idOnActivate != id && sc.activeSketch.idOnActivate == id
|| sc.activeSketch.c_idOnActivate != sc.activeSketch.c_id && sc.activeSketch.c_idOnActivate == sc.activeSketch.c_id
) { ) {
if (sc.newSketch) { if (sc.newSketch) {
dispatch({ type: 'delete-node', id: sc.activeSketch.obj3d.name }) dispatch({ type: 'delete-node', id: sc.activeSketch.obj3d.name })

View File

@ -55,11 +55,11 @@ export const DropDown = () => {
</div> </div>
{ {
open && open &&
<div className="absolute drop-down-top w-full p-1 rounded bg-gray-700" <div className="absolute drop-down-top -left-10 w-48 p-1 rounded bg-gray-700"
onClick={handleInsideClick} onClick={handleInsideClick}
> >
{arr.map(([url, name], idx) => ( {arr.map(([url, name], idx) => (
<div className="w-auto h-8 p-0.5 flex items-center bg-transparent text-gray-200 <div className="w-full h-8 p-0.5 flex items-center bg-transparent text-gray-200
hover:bg-gray-500 " hover:bg-gray-500 "
key={idx} key={idx}
> >

View File

@ -1,14 +1,14 @@
import {
fileOpen,
fileSave,
} from '../../extlib/fs/index';
// import { // import {
// fileOpen, // fileOpen,
// fileSave, // fileSave,
// } from 'browser-fs-access'; // } from '../../extlib/fs/index';
import {
fileOpen,
fileSave,
} from 'browser-fs-access';
// https://web.dev/file-system-access/ // https://web.dev/file-system-access/
@ -46,56 +46,12 @@ export async function saveFile(fileHandle, file, dispatch) {
} }
}; };
// export async function saveFileAs(file, dispatch) {
// try {
// console.log('heeeeeeeeeeeeeer')
// const fileHandle = await fileSave(new Blob([file], { type: 'application/json' }), {
// fileName: 'unamed',
// extensions: ['.json'],
// })
// dispatch({ type: 'set-file-handle', fileHandle, modified: false })
// } catch (ex) {
// const msg = 'Unable to save file.';
// console.error(msg, ex);
// alert(msg);
// return;
// }
// };
export async function saveFileAs(file, dispatch) { export async function saveFileAs(file, dispatch) {
let fileHandle;
try {
const opts = {
suggestedName: 'test',
types: [{
description: 'Text file',
accept: { 'application/json': ['.json'] },
}],
};
fileHandle = await showSaveFilePicker(opts)
} catch (ex) {
if (ex.name === 'AbortError') {
console.log('aborted')
return;
}
const msg = 'An error occured trying to open the file.';
console.error(msg, ex);
alert(msg);
return;
}
try { try {
const writable = await fileHandle.createWritable(); const fileHandle = await fileSave(new Blob([file], { type: 'application/json' }), {
await writable.write(file); extensions: ['.json'],
await writable.close() })
dispatch({ type: 'set-file-handle', fileHandle, modified: false }) dispatch({ type: 'set-file-handle', fileHandle, modified: false })
@ -109,6 +65,7 @@ export async function saveFileAs(file, dispatch) {
}; };
export async function openFile(dispatch) { export async function openFile(dispatch) {
let file let file

View File

@ -51,7 +51,7 @@ export const NavBar = () => {
const addSketch = () => { const addSketch = () => {
const sketch = sc.addSketch() const sketch = sc.addSketch()
if (!sketch) { if (!sketch) {
alert('please select a plane or 3 points to define sketch plane') alert('please select a plane or 3 points to set the sketch plane')
return return
} }
@ -106,9 +106,9 @@ export const NavBar = () => {
dispatch({ type: 'set-dialog', action: 'extrude', target: sc.activeSketch }) dispatch({ type: 'set-dialog', action: 'extrude', target: sc.activeSketch })
}, 'Extrude'], }, 'Extrude'],
[Icon.Dimension, () => sc.activeSketch.command('d'), 'Dimension (D)'],
[Icon.Line, () => sc.activeSketch.command('l'), 'Line (L)'], [Icon.Line, () => sc.activeSketch.command('l'), 'Line (L)'],
[Icon.Arc, () => sc.activeSketch.command('a'), 'Arc (A)'], [Icon.Arc, () => sc.activeSketch.command('a'), 'Arc (A)'],
[Icon.Dimension, () => sc.activeSketch.command('d'), 'Dimension (D)'],
[Icon.Coincident, () => sc.activeSketch.command('c'), 'Coincident (C)'], [Icon.Coincident, () => sc.activeSketch.command('c'), 'Coincident (C)'],
[Icon.Vertical, () => sc.activeSketch.command('v'), 'Vertical (V)'], [Icon.Vertical, () => sc.activeSketch.command('v'), 'Vertical (V)'],
[Icon.Horizontal, () => sc.activeSketch.command('h'), 'Horizontal (H)'], [Icon.Horizontal, () => sc.activeSketch.command('h'), 'Horizontal (H)'],
@ -124,10 +124,10 @@ export const NavBar = () => {
const partModeButtons = [ const partModeButtons = [
[FaEdit, addSketch, 'Sketch'], [FaEdit, addSketch, 'Sketch'],
[Icon.Extrude, () => { [Icon.Extrude, () => {
console.log(treeEntries.byId[sc.selected[0].name], 'here') try {
if (sc.selected[0] && treeEntries.byId[sc.selected[0].name].obj3d) {
dispatch({ type: 'set-dialog', action: 'extrude', target: treeEntries.byId[sc.selected[0].name] }) dispatch({ type: 'set-dialog', action: 'extrude', target: treeEntries.byId[sc.selected[0].name] })
} else { } catch (err) {
console.error(err)
alert('please select a sketch from the left pane extrude') alert('please select a sketch from the left pane extrude')
} }
@ -187,8 +187,7 @@ export const NavBar = () => {
)) ))
} }
</div> </div>
{/* <div className='w-auto h-full flex-1 items-center justify-end flex-shrink-1 hidden lg:flex'> */} <div className='w-auto h-full flex-1 items-center justify-end flex-shrink-1 hidden lg:flex'>
<div className='w-auto h-full flex-1 items-center justify-end flex-shrink-1 flex'>
<DropDown /> <DropDown />
<a href='https://github.com/twpride/threeCAD' className='h-full w=auto'> <a href='https://github.com/twpride/threeCAD' className='h-full w=auto'>
<FaGithub className="btn-green w-auto h-full p-3.5"></FaGithub> <FaGithub className="btn-green w-auto h-full p-3.5"></FaGithub>

View File

@ -12,7 +12,7 @@ export const Tree = () => {
return <div className='sideNav flex flex-col bg-gray-800'> return <div className='sideNav flex flex-col bg-gray-800'>
<div className='w-full text-gray-50 h-9 text-lg mx-1 border-0 flex items-center focus:outline-none bg-transparent'> <div className='w-full text-gray-50 h-9 text-lg mx-1 border-0 flex items-center focus:outline-none bg-transparent'>
{fileHandle ? fileHandle.name.replace(/\.[^/.]+$/, "") : 'untitled'} {fileHandle ? fileHandle.name.replace(/\.[^/.]+$/, "") : 'Untitled'}
</div> </div>
{treeEntries.allIds.map((entId, idx) => ( {treeEntries.allIds.map((entId, idx) => (
<TreeEntry key={idx} entId={entId} /> <TreeEntry key={idx} entId={entId} />

View File

@ -38,6 +38,7 @@ file save, stl export// done
seperate scene from init logic only init cam and rendere // not an issue , ended up just splicing (1) seperate scene from init logic only init cam and rendere // not an issue , ended up just splicing (1)
add download button, different from save button // done add download button, different from save button // done
- vertical and horzontal baseline to dimension to / or just smart ordinate dir dimenensing // done - vertical and horzontal baseline to dimension to / or just smart ordinate dir dimenensing // done
- auto snap done
@ -53,7 +54,6 @@ lighting messed up
reattach sketch reattach sketch
auto snap
highlight button to indicate active mode highlight button to indicate active mode