forked from 1b-agent/opencadstudio-upstream
style: apply cargo fmt across workspace
This commit is contained in:
1 parent
85710e5454
commit
9cf9ff2c5c
531 files changed
+57740
-33906
No files matched your search
+296
-97
@@ -49,23 +49,46 @@ fn color_value(color: codec::types::Color) -> Value {
|
||||
/// `kind`, `value`, `options`). The node graph moves values in this form too,
|
||||
/// so a port's value round-trips through [`OpenCADStudio::set_property_value`].
|
||||
pub(crate) fn property_json(p: &crate::scene::model::object::Property) -> Value {
|
||||
let (kind,value,options)=match &p.value{
|
||||
PropValue::ReadOnly(v)|PropValue::ReadOnlyWithTooltip{value:v,..}=>("readonly",json!(v),Value::Null),
|
||||
PropValue::EditText(v)=>("number",json!(v),Value::Null),
|
||||
PropValue::PlainText(v)=>("text",json!(v),Value::Null),
|
||||
PropValue::Hyperlink(v)=>("hyperlink",json!(v),Value::Null),
|
||||
PropValue::Choice{selected,options}=>("choice",json!(selected),json!(options)),
|
||||
PropValue::EditChoice{value,options}=>("editable_choice",json!(value),json!(options)),
|
||||
PropValue::LayerChoice(v)=>("layer",json!(v),Value::Null),
|
||||
PropValue::LinetypeChoice(v)=>("linetype",json!(v),Value::Null),
|
||||
PropValue::BoolToggle{value,..}=>("bool",json!(value),Value::Null),
|
||||
PropValue::ColorChoice(value)|PropValue::NamedColorChoice{color:value,..}=>("color",color_value(*value),Value::Null),
|
||||
PropValue::ColorVaries=>("color",Value::Null,Value::Null),
|
||||
PropValue::LwChoice(value)|PropValue::FieldLwChoice{value,..}=>("lineweight",json!(value.value()),json!(crate::ui::properties::lw_options().iter().map(|v|v.0.value()).collect::<Vec<_>>())),
|
||||
PropValue::LwVaries|PropValue::FieldLwVaries{..}=>("lineweight",Value::Null,json!(crate::ui::properties::lw_options().iter().map(|v|v.0.value()).collect::<Vec<_>>())),
|
||||
PropValue::AttrText{tag,value}=>("attribute",json!({"tag":tag,"value":value}),Value::Null),
|
||||
other=>("specialized",json!(format!("{other:?}")),Value::Null),
|
||||
};json!({"id":p.field,"label":p.label,"kind":kind,"value":value,"options":options})
|
||||
let (kind, value, options) = match &p.value {
|
||||
PropValue::ReadOnly(v) | PropValue::ReadOnlyWithTooltip { value: v, .. } => {
|
||||
("readonly", json!(v), Value::Null)
|
||||
}
|
||||
PropValue::EditText(v) => ("number", json!(v), Value::Null),
|
||||
PropValue::PlainText(v) => ("text", json!(v), Value::Null),
|
||||
PropValue::Hyperlink(v) => ("hyperlink", json!(v), Value::Null),
|
||||
PropValue::Choice { selected, options } => ("choice", json!(selected), json!(options)),
|
||||
PropValue::EditChoice { value, options } => {
|
||||
("editable_choice", json!(value), json!(options))
|
||||
}
|
||||
PropValue::LayerChoice(v) => ("layer", json!(v), Value::Null),
|
||||
PropValue::LinetypeChoice(v) => ("linetype", json!(v), Value::Null),
|
||||
PropValue::BoolToggle { value, .. } => ("bool", json!(value), Value::Null),
|
||||
PropValue::ColorChoice(value) | PropValue::NamedColorChoice { color: value, .. } => {
|
||||
("color", color_value(*value), Value::Null)
|
||||
}
|
||||
PropValue::ColorVaries => ("color", Value::Null, Value::Null),
|
||||
PropValue::LwChoice(value) | PropValue::FieldLwChoice { value, .. } => (
|
||||
"lineweight",
|
||||
json!(value.value()),
|
||||
json!(crate::ui::properties::lw_options()
|
||||
.iter()
|
||||
.map(|v| v.0.value())
|
||||
.collect::<Vec<_>>()),
|
||||
),
|
||||
PropValue::LwVaries | PropValue::FieldLwVaries { .. } => (
|
||||
"lineweight",
|
||||
Value::Null,
|
||||
json!(crate::ui::properties::lw_options()
|
||||
.iter()
|
||||
.map(|v| v.0.value())
|
||||
.collect::<Vec<_>>()),
|
||||
),
|
||||
PropValue::AttrText { tag, value } => {
|
||||
("attribute", json!({"tag":tag,"value":value}), Value::Null)
|
||||
}
|
||||
other => ("specialized", json!(format!("{other:?}")), Value::Null),
|
||||
};
|
||||
json!({"id":p.field,"label":p.label,"kind":kind,"value":value,"options":options})
|
||||
}
|
||||
pub(super) const NAMES: &[&str] = &[
|
||||
"close_modal",
|
||||
@@ -242,7 +265,10 @@ impl OpenCADStudio {
|
||||
parse_calibrate(&dummy, image.pixel_width, image.pixel_height)?
|
||||
} else {
|
||||
let default_width = (image.pixel_width as f64 / 100.0).max(1.0);
|
||||
let width = req["width"].as_f64().filter(|w| *w > 0.0).unwrap_or(default_width);
|
||||
let width = req["width"]
|
||||
.as_f64()
|
||||
.filter(|w| *w > 0.0)
|
||||
.unwrap_or(default_width);
|
||||
let scale = width / image.pixel_width as f64;
|
||||
(embed_point(req)?, width, scale)
|
||||
};
|
||||
@@ -413,13 +439,13 @@ impl OpenCADStudio {
|
||||
Some(base) => {
|
||||
let mut base = base.clone();
|
||||
crate::modules::insert::wblock::extract_entities_into(
|
||||
document,
|
||||
&handles?,
|
||||
&mut base,
|
||||
document, &handles?, &mut base,
|
||||
)?;
|
||||
Ok(base)
|
||||
}
|
||||
None => crate::modules::insert::wblock::extract_entities_to_doc(document, &handles?),
|
||||
None => {
|
||||
crate::modules::insert::wblock::extract_entities_to_doc(document, &handles?)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return Err(failure(
|
||||
@@ -489,7 +515,10 @@ impl OpenCADStudio {
|
||||
.find(|name| name.eq_ignore_ascii_case(&requested))
|
||||
.cloned()
|
||||
.ok_or_else(|| {
|
||||
failure("layout_missing", format!("Layout '{requested}' does not exist"))
|
||||
failure(
|
||||
"layout_missing",
|
||||
format!("Layout '{requested}' does not exist"),
|
||||
)
|
||||
})?]
|
||||
};
|
||||
|
||||
@@ -570,9 +599,15 @@ impl OpenCADStudio {
|
||||
"limits" => request.area = "Limits".into(),
|
||||
"layout" => request.area = "Layout".into(),
|
||||
"window" => {
|
||||
let values = req["window"].as_array().filter(|v| v.len() == 4).ok_or_else(|| {
|
||||
failure("window_required", "area \"window\" needs window:[x0,y0,x1,y1]")
|
||||
})?;
|
||||
let values = req["window"]
|
||||
.as_array()
|
||||
.filter(|v| v.len() == 4)
|
||||
.ok_or_else(|| {
|
||||
failure(
|
||||
"window_required",
|
||||
"area \"window\" needs window:[x0,y0,x1,y1]",
|
||||
)
|
||||
})?;
|
||||
let coord = |k: usize| {
|
||||
values[k].as_f64().filter(|v| v.is_finite()).ok_or_else(|| {
|
||||
failure("invalid_window", "window must be four finite numbers")
|
||||
@@ -587,7 +622,11 @@ impl OpenCADStudio {
|
||||
// Snapshot everything the pipeline reads or mutates, like print-all.
|
||||
let original_layout = self.tabs[i].scene.current_layout.clone();
|
||||
let original_viewport = self.tabs[i].scene.active_viewport;
|
||||
let original_psltscale = self.tabs[i].scene.document.header.paper_space_linetype_scaling;
|
||||
let original_psltscale = self.tabs[i]
|
||||
.scene
|
||||
.document
|
||||
.header
|
||||
.paper_space_linetype_scaling;
|
||||
let original_plimcheck = self.tabs[i].scene.document.header.paper_space_limit_check;
|
||||
let original_dialog = self.plot_dialog.clone();
|
||||
let original_window = self.plot_window;
|
||||
@@ -670,8 +709,7 @@ impl OpenCADStudio {
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
let page =
|
||||
page.ok_or_else(|| format!("Layout '{name}' plot area is empty."))?;
|
||||
let page = page.ok_or_else(|| format!("Layout '{name}' plot area is empty."))?;
|
||||
pages.push(page);
|
||||
}
|
||||
Ok(pages)
|
||||
@@ -679,7 +717,11 @@ impl OpenCADStudio {
|
||||
let built = build(self);
|
||||
self.tabs[i].scene.current_layout = original_layout;
|
||||
self.tabs[i].scene.active_viewport = original_viewport;
|
||||
self.tabs[i].scene.document.header.paper_space_linetype_scaling = original_psltscale;
|
||||
self.tabs[i]
|
||||
.scene
|
||||
.document
|
||||
.header
|
||||
.paper_space_linetype_scaling = original_psltscale;
|
||||
self.tabs[i].scene.document.header.paper_space_limit_check = original_plimcheck;
|
||||
self.plot_dialog = original_dialog;
|
||||
self.plot_window = original_window;
|
||||
@@ -695,7 +737,13 @@ impl OpenCADStudio {
|
||||
for (name, page) in targets.iter().zip(&pages) {
|
||||
let safe: String = name
|
||||
.chars()
|
||||
.map(|c| if c.is_alphanumeric() || c == '-' || c == '_' { c } else { '_' })
|
||||
.map(|c| {
|
||||
if c.is_alphanumeric() || c == '-' || c == '_' {
|
||||
c
|
||||
} else {
|
||||
'_'
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
let file = format!("{stem}-{safe}.pdf");
|
||||
crate::io::pdf_export::export_pdf_pages(
|
||||
@@ -762,7 +810,8 @@ impl OpenCADStudio {
|
||||
let target = handle(req)?;
|
||||
let grip_id = req["grip_id"]
|
||||
.as_u64()
|
||||
.ok_or_else(|| failure("invalid_request", "Missing grip_id"))? as usize;
|
||||
.ok_or_else(|| failure("invalid_request", "Missing grip_id"))?
|
||||
as usize;
|
||||
let to = point(req)?;
|
||||
self.tabs[i].scene.deselect_all();
|
||||
self.tabs[i].scene.select_entity(target, false);
|
||||
@@ -976,9 +1025,11 @@ impl OpenCADStudio {
|
||||
"close_modal" => Message::CloseModal,
|
||||
// The open PDF dialog's OK button.
|
||||
// Underlay Layers: switch a layer of the shown underlay.
|
||||
"pdf_layer_toggle" => Message::PdfDialog(
|
||||
crate::ui::window::pdf_dialogs::PdfDialogMsg::LayersToggle(string(req, "value")?.into()),
|
||||
),
|
||||
"pdf_layer_toggle" => {
|
||||
Message::PdfDialog(crate::ui::window::pdf_dialogs::PdfDialogMsg::LayersToggle(
|
||||
string(req, "value")?.into(),
|
||||
))
|
||||
}
|
||||
// Point Cloud Color Map: one edit, "tab=elevation", "count=3",
|
||||
// "even", "reverse", "scheme=Earth", "gradient=0", "max=90",
|
||||
// "min=10", "interval=0.1", "extents=0", "range=2", "current=0".
|
||||
@@ -990,7 +1041,9 @@ impl OpenCADStudio {
|
||||
Message::PdfDialog(match key {
|
||||
"tab" => M::MapTab(arg == "elevation"),
|
||||
"scheme" => M::MapScheme(arg.into()),
|
||||
"count" => M::MapCount(arg.parse().map_err(|_| failure("invalid_value", "count"))?),
|
||||
"count" => {
|
||||
M::MapCount(arg.parse().map_err(|_| failure("invalid_value", "count"))?)
|
||||
}
|
||||
"even" => M::MapEven,
|
||||
"reverse" => M::MapReverse,
|
||||
"gradient" => M::MapGradient(on),
|
||||
@@ -1033,7 +1086,10 @@ impl OpenCADStudio {
|
||||
use crate::ui::window::pc_manager::{PcManagerMsg, Row};
|
||||
let value = string(req, "value")?;
|
||||
let parsed = value.split_once(':').and_then(|(handle, row)| {
|
||||
Some((codec::Handle::new(u64::from_str_radix(handle, 16).ok()?), Row::parse(row)?))
|
||||
Some((
|
||||
codec::Handle::new(u64::from_str_radix(handle, 16).ok()?),
|
||||
Row::parse(row)?,
|
||||
))
|
||||
});
|
||||
let Some((handle, row)) = parsed else {
|
||||
return Err(failure("bad_value", "Expected <handle>:<row>"));
|
||||
@@ -1062,8 +1118,14 @@ impl OpenCADStudio {
|
||||
let [l, s, m] = self.count_palette.expansion(name).ok_or_else(bad)?;
|
||||
let i = self.active_tab;
|
||||
let area = self.tabs[i].count.as_ref().and_then(|c| c.area.clone());
|
||||
let instances = codec::count::block_instances(&self.tabs[i].scene.document, area.as_deref());
|
||||
let (k, _) = codec::count::expanded_counts(&instances, name, l, s, m).into_iter().nth(n).ok_or_else(bad)?;
|
||||
let instances = codec::count::block_instances(
|
||||
&self.tabs[i].scene.document,
|
||||
area.as_deref(),
|
||||
);
|
||||
let (k, _) = codec::count::expanded_counts(&instances, name, l, s, m)
|
||||
.into_iter()
|
||||
.nth(n)
|
||||
.ok_or_else(bad)?;
|
||||
M::Open(name.into(), k)
|
||||
}
|
||||
"menu" => {
|
||||
@@ -1089,7 +1151,10 @@ impl OpenCADStudio {
|
||||
"back" => M::Back,
|
||||
"match" => {
|
||||
let (k, on) = arg.split_once(':').unwrap_or((arg, "1"));
|
||||
M::Match(k.parse::<usize>().ok().filter(|k| *k < 3).ok_or_else(bad)?, flag(on))
|
||||
M::Match(
|
||||
k.parse::<usize>().ok().filter(|k| *k < 3).ok_or_else(bad)?,
|
||||
flag(on),
|
||||
)
|
||||
}
|
||||
"details" => M::ToggleDetails,
|
||||
"errors" => M::ToggleErrors,
|
||||
@@ -1097,7 +1162,13 @@ impl OpenCADStudio {
|
||||
let i = self.active_tab;
|
||||
let n: usize = arg.parse().map_err(|_| bad())?;
|
||||
let mode = self.tabs[i].count.as_ref().ok_or_else(bad)?;
|
||||
M::ShowError(*mode.result(&self.tabs[i].scene.document).errors.get(n).ok_or_else(bad)?)
|
||||
M::ShowError(
|
||||
*mode
|
||||
.result(&self.tabs[i].scene.document)
|
||||
.errors
|
||||
.get(n)
|
||||
.ok_or_else(bad)?,
|
||||
)
|
||||
}
|
||||
"area" => M::Area,
|
||||
"prev" => M::Prev,
|
||||
@@ -1132,20 +1203,45 @@ impl OpenCADStudio {
|
||||
// "drop=<item>@x,y", "menu=<action>:<item>". An item is
|
||||
// "current:NAME", "recent:N", "fav:N", "lib:N" or "file:<path>".
|
||||
"blocks_palette" => {
|
||||
use crate::ui::window::block_palette::{BlockPaletteMsg as M, Item, MenuAction, OptionMsg, Tab, ViewMode};
|
||||
use crate::ui::window::block_palette::{
|
||||
BlockPaletteMsg as M, Item, MenuAction, OptionMsg, Tab, ViewMode,
|
||||
};
|
||||
let value = string(req, "value")?;
|
||||
let (key, arg) = value.split_once('=').unwrap_or((value, ""));
|
||||
let item = |app: &Self, spec: &str| -> Result<Item, Value> {
|
||||
let (kind, rest) = spec.split_once(':').unwrap_or((spec, ""));
|
||||
let index = || rest.parse::<usize>().map_err(|_| failure("invalid_value", "Bad item index"));
|
||||
let index = || {
|
||||
rest.parse::<usize>()
|
||||
.map_err(|_| failure("invalid_value", "Bad item index"))
|
||||
};
|
||||
let missing = || failure("invalid_value", "No such palette item");
|
||||
Ok(match kind {
|
||||
"current" => Item::Current(rest.to_string()),
|
||||
"recent" => Item::Ref(app.block_palette.recent.get(index()?).cloned().ok_or_else(missing)?),
|
||||
"fav" => Item::Ref(app.block_palette.favorites.get(index()?).cloned().ok_or_else(missing)?),
|
||||
"recent" => Item::Ref(
|
||||
app.block_palette
|
||||
.recent
|
||||
.get(index()?)
|
||||
.cloned()
|
||||
.ok_or_else(missing)?,
|
||||
),
|
||||
"fav" => Item::Ref(
|
||||
app.block_palette
|
||||
.favorites
|
||||
.get(index()?)
|
||||
.cloned()
|
||||
.ok_or_else(missing)?,
|
||||
),
|
||||
"lib" => {
|
||||
let e = app.block_palette.library_entries.get(index()?).ok_or_else(missing)?;
|
||||
if e.folder { Item::Folder(e.path.clone()) } else { Item::File(e.path.clone()) }
|
||||
let e = app
|
||||
.block_palette
|
||||
.library_entries
|
||||
.get(index()?)
|
||||
.ok_or_else(missing)?;
|
||||
if e.folder {
|
||||
Item::Folder(e.path.clone())
|
||||
} else {
|
||||
Item::File(e.path.clone())
|
||||
}
|
||||
}
|
||||
"file" => Item::File(std::path::PathBuf::from(rest)),
|
||||
_ => return Err(missing()),
|
||||
@@ -1159,7 +1255,9 @@ impl OpenCADStudio {
|
||||
_ => Tab::Current,
|
||||
})),
|
||||
"search" => Message::BlockPalette(M::Search(arg.into())),
|
||||
"view" => Message::BlockPalette(M::View(ViewMode::from_u8(arg.parse().unwrap_or(1)))),
|
||||
"view" => {
|
||||
Message::BlockPalette(M::View(ViewMode::from_u8(arg.parse().unwrap_or(1))))
|
||||
}
|
||||
"options" => Message::BlockPalette(M::ToggleOptions),
|
||||
"library" => Message::BlockPalette(M::LibraryPicked(Ok(arg.into()))),
|
||||
"up" => Message::BlockPalette(M::LibraryUp),
|
||||
@@ -1187,19 +1285,27 @@ impl OpenCADStudio {
|
||||
Message::BlockPalette(M::Release(it))
|
||||
}
|
||||
"drop" => {
|
||||
let (spec, at) = arg.rsplit_once('@').ok_or_else(|| failure("invalid_value", "drop needs @x,y"))?;
|
||||
let xy: Vec<f64> = at.split(',').filter_map(|v| v.trim().parse().ok()).collect();
|
||||
let (spec, at) = arg
|
||||
.rsplit_once('@')
|
||||
.ok_or_else(|| failure("invalid_value", "drop needs @x,y"))?;
|
||||
let xy: Vec<f64> = at
|
||||
.split(',')
|
||||
.filter_map(|v| v.trim().parse().ok())
|
||||
.collect();
|
||||
if xy.len() < 2 {
|
||||
return Err(failure("invalid_value", "drop needs @x,y"));
|
||||
}
|
||||
let it = item(self, spec)?;
|
||||
let i = self.active_tab;
|
||||
self.tabs[i].last_cursor_world = glam::DVec3::new(xy[0], xy[1], xy.get(2).copied().unwrap_or(0.0));
|
||||
self.tabs[i].last_cursor_world =
|
||||
glam::DVec3::new(xy[0], xy[1], xy.get(2).copied().unwrap_or(0.0));
|
||||
self.block_palette.pressed = Some(it);
|
||||
Message::ViewportLeftRelease
|
||||
}
|
||||
"menu" => {
|
||||
let (action, spec) = arg.split_once(':').ok_or_else(|| failure("invalid_value", "menu needs action:item"))?;
|
||||
let (action, spec) = arg
|
||||
.split_once(':')
|
||||
.ok_or_else(|| failure("invalid_value", "menu needs action:item"))?;
|
||||
let action = match action {
|
||||
"insert" => MenuAction::Insert,
|
||||
"redefine" => MenuAction::Redefine,
|
||||
@@ -1296,26 +1402,46 @@ impl OpenCADStudio {
|
||||
.filter(|i| *i < len)
|
||||
.ok_or_else(|| failure("invalid_value", "index out of range"))
|
||||
};
|
||||
let named_len = self.field_dialog.as_ref().map_or(0, |d| d.named_names.len());
|
||||
let named_len = self
|
||||
.field_dialog
|
||||
.as_ref()
|
||||
.map_or(0, |d| d.named_names.len());
|
||||
let known = |list: &[&'static str]| {
|
||||
list.iter().copied().find(|n| n.eq_ignore_ascii_case(v)).ok_or_else(|| failure("invalid_value", "unknown name"))
|
||||
list.iter()
|
||||
.copied()
|
||||
.find(|n| n.eq_ignore_ascii_case(v))
|
||||
.ok_or_else(|| failure("invalid_value", "unknown name"))
|
||||
};
|
||||
Message::FieldDialog(match key {
|
||||
"category" => F::Category(index(fd::CATEGORIES.len())?),
|
||||
"name" => F::Name(known(&fd::fields_of(0))?),
|
||||
"date" => F::DateFormat(v.into()),
|
||||
"case" => F::TextCase(index(fd::TEXT_CASES.len())?),
|
||||
"file" => F::FileParts(v.parse::<u8>().map_err(|_| failure("invalid_value", "1|2|3"))?),
|
||||
"file" => F::FileParts(
|
||||
v.parse::<u8>()
|
||||
.map_err(|_| failure("invalid_value", "1|2|3"))?,
|
||||
),
|
||||
"ext" => F::FileExtension(v == "1"),
|
||||
"size" => F::SizeUnit(index(fd::SIZE_UNITS.len())?),
|
||||
"sysvar" => F::SysVar(v.into()),
|
||||
"diesel" => F::Diesel(v.into()),
|
||||
"named_type" => F::NamedType(index(fd::NAMED_TYPES.len())?),
|
||||
"named" => F::Named(index(named_len)?),
|
||||
"prop" => F::ObjectProp(known(&["Area", "Center", "Circumference", "Diameter", "EndPoint", "Length", "Radius", "StartPoint"])?),
|
||||
"prop" => F::ObjectProp(known(&[
|
||||
"Area",
|
||||
"Center",
|
||||
"Circumference",
|
||||
"Diameter",
|
||||
"EndPoint",
|
||||
"Length",
|
||||
"Radius",
|
||||
"StartPoint",
|
||||
])?),
|
||||
"select_object" => F::SelectObject,
|
||||
"formula" => F::Formula(v.into()),
|
||||
"formula_format" => F::FormulaFormat(index(codec::fields::FORMULA_FORMATS.len())?),
|
||||
"formula_format" => {
|
||||
F::FormulaFormat(index(codec::fields::FORMULA_FORMATS.len())?)
|
||||
}
|
||||
"precision" => F::FormulaPrecision(index(fd::FORMULA_PRECISIONS.len())?),
|
||||
"link_text" => F::HyperlinkText(v.into()),
|
||||
"link_url" => F::HyperlinkUrl(v.into()),
|
||||
@@ -1326,8 +1452,14 @@ impl OpenCADStudio {
|
||||
"ss_set" => F::SsSet(v.parse().map_err(|_| failure("invalid_value", "index"))?),
|
||||
"ss_dst" => F::SsPicked(Some(std::path::PathBuf::from(v))),
|
||||
"ss_node" => {
|
||||
let state = self.field_dialog.as_ref().ok_or_else(|| failure("invalid_state", "No Field dialog"))?;
|
||||
let db = state.ss_sets.get(state.ss_set).ok_or_else(|| failure("invalid_state", "No sheet set"))?;
|
||||
let state = self
|
||||
.field_dialog
|
||||
.as_ref()
|
||||
.ok_or_else(|| failure("invalid_state", "No Field dialog"))?;
|
||||
let db = state
|
||||
.ss_sets
|
||||
.get(state.ss_set)
|
||||
.ok_or_else(|| failure("invalid_state", "No sheet set"))?;
|
||||
let views = state.name == "SheetView";
|
||||
let id = fd::nav_nodes(db, views)
|
||||
.into_iter()
|
||||
@@ -1340,7 +1472,9 @@ impl OpenCADStudio {
|
||||
"ss_href" => F::SsHref(v == "1"),
|
||||
"ss_placeholder" => F::SsPlaceholder(index(fd::PLACEHOLDER_TYPES.len())?),
|
||||
"ss_scale" => F::SsScaleFormat(index(codec::fields::PLOT_SCALE_FORMATS.len())?),
|
||||
"placeholder" => F::PlaceholderProperty(index(codec::fields::BLOCK_PLACEHOLDER_PROPERTIES.len())?),
|
||||
"placeholder" => F::PlaceholderProperty(index(
|
||||
codec::fields::BLOCK_PLACEHOLDER_PROPERTIES.len(),
|
||||
)?),
|
||||
"table_function" => F::TableFunction(
|
||||
["Average", "Sum", "Count", "Cell"]
|
||||
.into_iter()
|
||||
@@ -1362,15 +1496,22 @@ impl OpenCADStudio {
|
||||
// "custom_owner=0|1", "add_custom_ok", "number=", "title=",
|
||||
// "file_name=", "pick_layout=<i>", "ok", "cancel".
|
||||
"sheet_set" => {
|
||||
use crate::ui::window::sheet_set::{FieldId as F, MenuAction as A, SheetSetMsg as M, SsmTab, WizardMsg as W};
|
||||
use crate::ui::window::sheet_set::{
|
||||
FieldId as F, MenuAction as A, SheetSetMsg as M, SsmTab, WizardMsg as W,
|
||||
};
|
||||
let value = string(req, "value")?;
|
||||
let (key, arg) = value.split_once('=').unwrap_or((value, ""));
|
||||
let target = |app: &Self, spec: &str| {
|
||||
app.sheet_set_target(spec).ok_or_else(|| failure("invalid_value", "No such sheet set component"))
|
||||
app.sheet_set_target(spec)
|
||||
.ok_or_else(|| failure("invalid_value", "No such sheet set component"))
|
||||
};
|
||||
let index_value = |spec: &str| -> Result<(usize, String), Value> {
|
||||
let (i, v) = spec.split_once(':').unwrap_or((spec, ""));
|
||||
Ok((i.parse().map_err(|_| failure("invalid_value", "Expected <index>:<value>"))?, v.to_string()))
|
||||
Ok((
|
||||
i.parse()
|
||||
.map_err(|_| failure("invalid_value", "Expected <index>:<value>"))?,
|
||||
v.to_string(),
|
||||
))
|
||||
};
|
||||
Message::SheetSet(match key {
|
||||
"open" => M::OpenPicked(Some(std::path::PathBuf::from(arg))),
|
||||
@@ -1393,7 +1534,12 @@ impl OpenCADStudio {
|
||||
"remove" => A::Remove,
|
||||
"properties" => A::Properties,
|
||||
"close" => A::Close,
|
||||
_ => return Err(failure("invalid_value", "Unknown sheet set menu action")),
|
||||
_ => {
|
||||
return Err(failure(
|
||||
"invalid_value",
|
||||
"Unknown sheet set menu action",
|
||||
))
|
||||
}
|
||||
};
|
||||
if action == A::ImportLayout {
|
||||
self.sheet_set_import_parent = Some(target(self, spec)?);
|
||||
@@ -1403,7 +1549,9 @@ impl OpenCADStudio {
|
||||
}
|
||||
"new" => return Ok(self.dispatch_command("NEWSHEETSET")),
|
||||
"existing" => M::Wizard(W::Existing(arg == "1")),
|
||||
"step" => M::Wizard(W::Step(arg.parse().map_err(|_| failure("invalid_value", "step"))?)),
|
||||
"step" => M::Wizard(W::Step(
|
||||
arg.parse().map_err(|_| failure("invalid_value", "step"))?,
|
||||
)),
|
||||
"layout" => {
|
||||
let (i, v) = index_value(arg)?;
|
||||
M::Wizard(W::LayoutOn(i, v == "1"))
|
||||
@@ -1412,7 +1560,9 @@ impl OpenCADStudio {
|
||||
"description" => M::Input(F::Description, arg.into()),
|
||||
"folder" => M::Input(F::Folder, arg.into()),
|
||||
"hierarchy" => M::Toggle(F::Hierarchy, arg == "1"),
|
||||
"add_folder" => M::FolderPicked(F::AddFolder, Some(std::path::PathBuf::from(arg))),
|
||||
"add_folder" => {
|
||||
M::FolderPicked(F::AddFolder, Some(std::path::PathBuf::from(arg)))
|
||||
}
|
||||
"wizard_props" => M::WizardProperties,
|
||||
"row" => {
|
||||
let (i, v) = index_value(arg)?;
|
||||
@@ -1435,7 +1585,10 @@ impl OpenCADStudio {
|
||||
"number" => M::Input(F::Number, arg.into()),
|
||||
"title" => M::Input(F::Title, arg.into()),
|
||||
"file_name" => M::Input(F::FileName, arg.into()),
|
||||
"pick_layout" => M::Choose(F::Layout, arg.parse().map_err(|_| failure("invalid_value", "index"))?),
|
||||
"pick_layout" => M::Choose(
|
||||
F::Layout,
|
||||
arg.parse().map_err(|_| failure("invalid_value", "index"))?,
|
||||
),
|
||||
"refresh" => M::Refresh,
|
||||
"open_after" => M::Toggle(F::OpenAfter, arg == "1"),
|
||||
"row_toggle" => {
|
||||
@@ -1448,7 +1601,9 @@ impl OpenCADStudio {
|
||||
let (i, v) = index_value(arg)?;
|
||||
M::Toggle(F::RenameOption(i.min(3)), v == "1")
|
||||
}
|
||||
"import_add" => M::ImportAdd(arg.split('|').map(std::path::PathBuf::from).collect()),
|
||||
"import_add" => {
|
||||
M::ImportAdd(arg.split('|').map(std::path::PathBuf::from).collect())
|
||||
}
|
||||
"import_row" => {
|
||||
let (i, v) = index_value(arg)?;
|
||||
M::Toggle(F::ImportRow(i), v == "1")
|
||||
@@ -1462,7 +1617,12 @@ impl OpenCADStudio {
|
||||
let id = self
|
||||
.sheet_set
|
||||
.db()
|
||||
.and_then(|db| db.view_categories().iter().find(|c| c.prop("Name") == Some(arg)).map(|c| c.id().to_string()))
|
||||
.and_then(|db| {
|
||||
db.view_categories()
|
||||
.iter()
|
||||
.find(|c| c.prop("Name") == Some(arg))
|
||||
.map(|c| c.id().to_string())
|
||||
})
|
||||
.ok_or_else(|| failure("invalid_value", "No such view category"))?;
|
||||
M::CategoryProperties(id)
|
||||
}
|
||||
@@ -1470,7 +1630,12 @@ impl OpenCADStudio {
|
||||
let id = self
|
||||
.sheet_set
|
||||
.db()
|
||||
.and_then(|db| db.view_categories().iter().find(|c| c.prop("Name") == Some(arg)).map(|c| c.id().to_string()))
|
||||
.and_then(|db| {
|
||||
db.view_categories()
|
||||
.iter()
|
||||
.find(|c| c.prop("Name") == Some(arg))
|
||||
.map(|c| c.id().to_string())
|
||||
})
|
||||
.ok_or_else(|| failure("invalid_value", "No such view category"))?;
|
||||
M::CategoryRemove(id)
|
||||
}
|
||||
@@ -1484,7 +1649,10 @@ impl OpenCADStudio {
|
||||
.sheet_set
|
||||
.locations
|
||||
.iter()
|
||||
.find(|(_, folder, _)| codec::sheet_set::path_key(folder) == codec::sheet_set::path_key(arg))
|
||||
.find(|(_, folder, _)| {
|
||||
codec::sheet_set::path_key(folder)
|
||||
== codec::sheet_set::path_key(arg)
|
||||
})
|
||||
.map(|(id, _, _)| id.clone())
|
||||
.ok_or_else(|| failure("invalid_value", "No such location"))?;
|
||||
M::RemoveLocation(id)
|
||||
@@ -1494,19 +1662,29 @@ impl OpenCADStudio {
|
||||
"see_views" => M::SeeViews(arg.into()),
|
||||
// place=<drawing>[|<view>]
|
||||
"place" => {
|
||||
let (drawing, view) = arg.split_once('|').map_or((arg, None), |(d, v)| (d, Some(v.to_string())));
|
||||
let (drawing, view) = arg
|
||||
.split_once('|')
|
||||
.map_or((arg, None), |(d, v)| (d, Some(v.to_string())));
|
||||
M::PlaceOnSheet(drawing.into(), view)
|
||||
}
|
||||
// view=<view title or number - title>:<display|rename|label|category=<name>|callout=<block>>
|
||||
"view" => {
|
||||
use crate::ui::window::sheet_set::ViewAction as VA;
|
||||
let (spec, action) = arg.rsplit_once(':').ok_or_else(|| failure("invalid_value", "view=<view>:<action>"))?;
|
||||
let db = self.sheet_set.db().ok_or_else(|| failure("invalid_state", "No sheet set"))?;
|
||||
let (spec, action) = arg
|
||||
.rsplit_once(':')
|
||||
.ok_or_else(|| failure("invalid_value", "view=<view>:<action>"))?;
|
||||
let db = self
|
||||
.sheet_set
|
||||
.db()
|
||||
.ok_or_else(|| failure("invalid_state", "No sheet set"))?;
|
||||
let view = db
|
||||
.sheets()
|
||||
.into_iter()
|
||||
.flat_map(|s| db.sheet_views(s))
|
||||
.find(|v| codec::sheet_set::number_and_title(v) == spec || v.prop("Title") == Some(spec))
|
||||
.find(|v| {
|
||||
codec::sheet_set::number_and_title(v) == spec
|
||||
|| v.prop("Title") == Some(spec)
|
||||
})
|
||||
.map(|v| v.id().to_string())
|
||||
.ok_or_else(|| failure("invalid_value", "No such sheet view"))?;
|
||||
let (verb, name) = action.split_once('=').unwrap_or((action, ""));
|
||||
@@ -1519,24 +1697,37 @@ impl OpenCADStudio {
|
||||
.iter()
|
||||
.find(|c| c.prop("Name") == Some(name))
|
||||
.map(|c| c.id().to_string())
|
||||
.ok_or_else(|| failure("invalid_value", "No such view category"))?,
|
||||
.ok_or_else(|| {
|
||||
failure("invalid_value", "No such view category")
|
||||
})?,
|
||||
),
|
||||
"callout" => VA::Callout(
|
||||
db.callout_blocks()
|
||||
.iter()
|
||||
.find(|b| b.prop("Name") == Some(name))
|
||||
.map(|b| b.id().to_string())
|
||||
.ok_or_else(|| failure("invalid_value", "No such callout block"))?,
|
||||
.ok_or_else(|| {
|
||||
failure("invalid_value", "No such callout block")
|
||||
})?,
|
||||
),
|
||||
_ => return Err(failure("invalid_value", "display|rename|label|category=|callout=")),
|
||||
_ => {
|
||||
return Err(failure(
|
||||
"invalid_value",
|
||||
"display|rename|label|category=|callout=",
|
||||
))
|
||||
}
|
||||
};
|
||||
M::ViewMenu(view, a)
|
||||
}
|
||||
"add_blocks" => M::AddBlocks,
|
||||
"block_list_select" => M::BlockListSelect(arg.parse().map_err(|_| failure("invalid_value", "index"))?),
|
||||
"block_list_select" => M::BlockListSelect(
|
||||
arg.parse().map_err(|_| failure("invalid_value", "index"))?,
|
||||
),
|
||||
"block_list_add" => M::BlockListAdd,
|
||||
"block_list_delete" => M::BlockListDelete,
|
||||
"select_block_file" => M::SelectBlockPicked(Some(std::path::PathBuf::from(arg))),
|
||||
"select_block_file" => {
|
||||
M::SelectBlockPicked(Some(std::path::PathBuf::from(arg)))
|
||||
}
|
||||
"select_block_whole" => M::SelectBlockWhole(arg == "1"),
|
||||
"select_block_check" => {
|
||||
let (i, v) = index_value(arg)?;
|
||||
@@ -1563,22 +1754,22 @@ impl OpenCADStudio {
|
||||
}
|
||||
// The open dialog's OK button.
|
||||
"dialog_ok" => match self.active_modal {
|
||||
Some(crate::app::ModalKind::XrefAttach) => Message::XrefAttach(
|
||||
crate::ui::window::xref_attach::XrefAttachMsg::Apply,
|
||||
),
|
||||
Some(crate::app::ModalKind::XrefAttach) => {
|
||||
Message::XrefAttach(crate::ui::window::xref_attach::XrefAttachMsg::Apply)
|
||||
}
|
||||
Some(crate::app::ModalKind::BlockDefinition) => Message::BlockDefApply,
|
||||
Some(crate::app::ModalKind::AttDef) => Message::AttdefDialog(
|
||||
crate::ui::window::attdef_dialog::AttdefDialogMsg::Ok,
|
||||
),
|
||||
Some(crate::app::ModalKind::AttDefEdit) => Message::AttdefDialog(
|
||||
crate::ui::window::attdef_dialog::AttdefDialogMsg::EditOk,
|
||||
),
|
||||
Some(crate::app::ModalKind::SheetSet) => Message::SheetSet(
|
||||
crate::ui::window::sheet_set::SheetSetMsg::Ok,
|
||||
),
|
||||
Some(crate::app::ModalKind::Field) => Message::FieldDialog(
|
||||
crate::ui::window::field_dialog::FieldDialogMsg::Ok,
|
||||
),
|
||||
Some(crate::app::ModalKind::AttDef) => {
|
||||
Message::AttdefDialog(crate::ui::window::attdef_dialog::AttdefDialogMsg::Ok)
|
||||
}
|
||||
Some(crate::app::ModalKind::AttDefEdit) => {
|
||||
Message::AttdefDialog(crate::ui::window::attdef_dialog::AttdefDialogMsg::EditOk)
|
||||
}
|
||||
Some(crate::app::ModalKind::SheetSet) => {
|
||||
Message::SheetSet(crate::ui::window::sheet_set::SheetSetMsg::Ok)
|
||||
}
|
||||
Some(crate::app::ModalKind::Field) => {
|
||||
Message::FieldDialog(crate::ui::window::field_dialog::FieldDialogMsg::Ok)
|
||||
}
|
||||
_ => return Err(failure("no_dialog", "No dialog with an OK button is open")),
|
||||
},
|
||||
"close_document" => Message::TabClose(self.tabs[self.active_tab].id),
|
||||
@@ -1597,7 +1788,10 @@ impl OpenCADStudio {
|
||||
"mtext_cancel" => Message::MTextCancel,
|
||||
"text_input" => Message::TextInlineInput(string(req, "value")?.into()),
|
||||
"text_commit" => Message::TextInlineOk,
|
||||
"pointer_move" | "pointer_press" | "pointer_release" | "pointer_right_press"
|
||||
"pointer_move"
|
||||
| "pointer_press"
|
||||
| "pointer_release"
|
||||
| "pointer_right_press"
|
||||
| "pointer_right_release" => {
|
||||
let x = req["x"]
|
||||
.as_f64()
|
||||
@@ -1609,7 +1803,12 @@ impl OpenCADStudio {
|
||||
.filter(|v| v.is_finite())
|
||||
.ok_or_else(|| failure("invalid_point", "Missing finite y"))?
|
||||
as f32;
|
||||
let size = self.tabs[self.active_tab].scene.selection.borrow().view.vp_size;
|
||||
let size = self.tabs[self.active_tab]
|
||||
.scene
|
||||
.selection
|
||||
.borrow()
|
||||
.view
|
||||
.vp_size;
|
||||
if x < 0. || y < 0. || x > size.0 || y > size.1 {
|
||||
return Err(failure(
|
||||
"outside_viewport",
|
||||
|
||||
Reference in new issue
Block a user