Skip to content

Commit

Permalink
update CLI and web
Browse files Browse the repository at this point in the history
  • Loading branch information
sameer committed Feb 2, 2024
1 parent 590ffec commit de33bfb
Show file tree
Hide file tree
Showing 8 changed files with 303 additions and 321 deletions.
369 changes: 172 additions & 197 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
[package]
name = "svg2gcode-cli"
version = "0.0.5"
version = "0.0.6"
authors = ["Sameer Puri <crates@purisa.me>"]
edition = "2021"
description = "Command line interface for svg2gcode"
repository = "https://github.com/sameer/svg2gcode"
license = "MIT"

[dependencies]
svg2gcode = { version = "0.1.4", features = ["serde"]}
svg2gcode = { version = "0.1.5", features = ["serde"]}
env_logger = { version = "0", default-features = false, features = ["atty", "termcolor", "humantime"] }
log = "0"
g-code = "0.3"
codespan-reporting = "0.11"
structopt = "0.3"
roxmltree = "0.19"
svgtypes = "0.12"
svgtypes = "0.13"
serde_json = "1"

[[bin]]
Expand Down
5 changes: 4 additions & 1 deletion lib/src/converter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,10 @@ impl<'a, T: Turtle> visit::XmlVisitor for ConversionVisitor<'a, T> {
self.terrarium.line(true, x, y);
}
} else {
warn!("There is a polyline node containing no actual path: {:?}", node);
warn!(
"There is a polyline node containing no actual path: {:?}",
node
);
}
}

Expand Down
9 changes: 2 additions & 7 deletions lib/src/turtle/g_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,8 @@ impl<'input> Turtle for GCodeTurtle<'input> {

fn move_to(&mut self, to: Point<f64>) {
self.tool_off();
self.program.append(
&mut command!(RapidPositioning {
X: to.x,
Y: to.y,
})
.into_token_vec(),
);
self.program
.append(&mut command!(RapidPositioning { X: to.x, Y: to.y, }).into_token_vec());
}

fn line_to(&mut self, to: Point<f64>) {
Expand Down
8 changes: 4 additions & 4 deletions web/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "svg2gcode-web"
version = "0.0.4"
version = "0.0.5"
authors = ["Sameer Puri <crates@purisa.me>"]
edition = "2021"
description = "Convert vector graphics to g-code for pen plotters, laser engravers, and other CNC machines"
Expand All @@ -10,21 +10,21 @@ license = "MIT"

[dependencies]
wasm-bindgen = "0.2"
svg2gcode = { version = "0.1.4", features = ["serde"] }
svg2gcode = { version = "0.1.5", features = ["serde"] }
roxmltree = "0.19"
g-code = "0.3"
codespan-reporting = "0.11"
codespan = "0.11"
serde = "1"
paste = "1"
log = "0.4"
svgtypes = "0.12"
svgtypes = "0.13"
serde_json = "1"
thiserror = "1.0"
zip = { version = "0.6", default-features = false }

yew = { version ="0.21", features = ["csr"] }
yewdux = "0.9.4"
yewdux = "0.10"
web-sys = { version = "0.3", features = [] }
wasm-logger = "0.2"
gloo-file = { version = "0.3", features = ["futures"] }
Expand Down
28 changes: 16 additions & 12 deletions web/src/forms/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use wasm_bindgen::JsCast;
use wasm_bindgen_futures::JsFuture;
use web_sys::{window, Event, FileList, HtmlElement, HtmlInputElement, Response};
use yew::prelude::*;
use yewdux::{functional::use_store, prelude::Dispatch};
use yewdux::{functional::use_store, use_dispatch};

use crate::{
state::{AppState, FormState, Svg},
Expand All @@ -28,7 +28,7 @@ use inputs::*;

#[function_component(SettingsForm)]
pub fn settings_form() -> Html {
let app_dispatch = Dispatch::<AppState>::new();
let app_dispatch = use_dispatch::<AppState>();
let (form_state, form_dispatch) = use_store::<FormState>();

let disabled = form_state.tolerance.is_err()
Expand Down Expand Up @@ -205,8 +205,8 @@ pub fn settings_form() -> Html {

#[function_component(ImportExportModal)]
pub fn import_export_modal() -> Html {
let app_dispatch = Dispatch::<AppState>::new();
let form_dispatch = Dispatch::<FormState>::new();
let app_dispatch = use_dispatch::<AppState>();
let form_dispatch = use_dispatch::<FormState>();

let import_state = use_state(|| Option::<Result<Settings, String>>::None);

Expand Down Expand Up @@ -349,12 +349,12 @@ pub fn import_export_modal() -> Html {

#[function_component(SvgForm)]
pub fn svg_form() -> Html {
let app_dispatch = Dispatch::<AppState>::new();
let app_dispatch = use_dispatch::<AppState>();

let file_upload_state = use_mut_ref(Vec::default);
let file_upload_state_cloned = file_upload_state.clone();
let file_upload_onchange =
app_dispatch.reduce_mut_future_callback_with(move |app, file_list: FileList| {
app_dispatch.future_callback_with(move |app, file_list: FileList| {
let file_upload_state_cloned = file_upload_state_cloned.clone();
Box::pin(async move {
let mut results = Vec::with_capacity(file_list.length() as usize);
Expand Down Expand Up @@ -384,7 +384,9 @@ pub fn svg_form() -> Html {
.borrow_mut()
.push(result.clone().map(|_| ()));
}
app.svgs.extend(results.drain(..).filter_map(Result::ok));
app.reduce_mut(|app| {
app.svgs.extend(results.drain(..).filter_map(Result::ok));
});
})
});

Expand Down Expand Up @@ -420,7 +422,7 @@ pub fn svg_form() -> Html {
let url_input_parsed = url_input_parsed.clone();
let url_add_loading = url_add_loading.clone();

app_dispatch.reduce_mut_future_callback_with(move |app, _| {
app_dispatch.future_callback_with(move |app, _| {
let url_input_state = url_input_state.clone();
let url_input_parsed = url_input_parsed.clone();
let url_add_loading = url_add_loading.clone();
Expand All @@ -447,10 +449,12 @@ pub fn svg_form() -> Html {
&response_url, err
))));
} else {
app.svgs.push(Svg {
content: text,
filename: response_url,
dimensions: [None; 2],
app.reduce_mut(|app| {
app.svgs.push(Svg {
content: text,
filename: response_url,
dimensions: [None; 2],
});
});
};
}
Expand Down
Loading

0 comments on commit de33bfb

Please sign in to comment.