From a930e0660361c4a65f49c0d0368c7dd3ecad4cb1 Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Wed, 31 Jul 2024 09:26:44 -0400 Subject: [PATCH] fix circle/rectangle add dialog --- src/mesh/api.js | 31 ++++++++++++++++++++++++------- src/mesh/build.js | 8 ++++---- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/mesh/api.js b/src/mesh/api.js index a492cda0..d0ed8f31 100644 --- a/src/mesh/api.js +++ b/src/mesh/api.js @@ -660,7 +660,7 @@ let add = { /** add sketch components */ - circle(opt = {}) { + circle() { let sketch = selection.sketch(); if (!sketch) { return log('select a sketch'); @@ -669,14 +669,14 @@ let add = { title: "add circle", body: [ h.div({ class: "addgear" }, [ h.label('radius in mm'), - h.input({ value: opt.radius || 10, size: 5, id: "_radius" }), + h.input({ value: 10, size: 5, id: "_radius" }), h.hr(), h.code("optional"), h.hr(), h.label('point spacing'), - h.input({ value: opt.spacing || 0, size: 5, id: "_spacing" }), + h.input({ value: 0, size: 5, id: "_spacing" }), h.label('point count'), - h.input({ value: opt.points || 0, size: 5, id: "_points" }), + h.input({ value: 0, size: 5, id: "_points" }), h.button({ _: "create", onclick() { const { _radius, _points, _spacing } = api.modal.bound; sketch.add.circle({ @@ -692,11 +692,28 @@ let add = { }, rectangle() { - let sel = selection.sketches(); - if (!sel.length) { + let sketch = selection.sketch(); + if (!sketch) { return log('select a sketch'); } - return sel[0].add.rectangle(...arguments); + api.modal.dialog({ + title: "add rectangle", + body: [ h.div({ class: "addgear" }, [ + h.label('width'), + h.input({ value: 20, size: 5, id: "_width" }), + h.label('height'), + h.input({ value: 20, size: 5, id: "_height" }), + h.button({ _: "create", onclick() { + const { _width, _height } = api.modal.bound; + sketch.add.rectangle({ + width: parseFloat(_width.value), + height: parseFloat(_height.value), + }); + api.modal.hide(); + } }) + ]) ] + }); + api.modal.bound._width.focus(); }, /** add models */ diff --git a/src/mesh/build.js b/src/mesh/build.js index cec5428e..bb3b103d 100644 --- a/src/mesh/build.js +++ b/src/mesh/build.js @@ -392,8 +392,8 @@ function ui_build() { div({ class: "menu sketch-on" }, [ div('Edit'), div({ class: "menu-items" }, [ - menu_item('Add Circle', () => { sketch.selected.one?.add.circle() }), - menu_item('Add Rectangle', () => { sketch.selected.one?.add.rectangle() }), + menu_item('Add Circle', api.add.circle), + menu_item('Add Rectangle', api.add.rectangle), hr(), menu_item('Add Sketch', add.sketch), hr(), @@ -563,8 +563,8 @@ function ui_build() { // bind sketch chiclets bind(sketchtools, div([ tool_item('bi-plus', 'New Sketch', add.sketch), - tool_item('bi-circle', 'Add Circle', () => { sketch.selected.one?.add.circle() }), - tool_item('bi-square', 'Add Rectangle', () => { sketch.selected.one?.add.rectangle() }), + tool_item('bi-circle', 'Add Circle', api.add.circle), + tool_item('bi-square', 'Add Rectangle', api.add.rectangle), tool_item('bi-union', 'Union', sketch.boolean.union), tool_item('bi-intersect', 'Intersect', sketch.boolean.intersect), tool_item('bi-exclude', 'Difference', sketch.boolean.difference),