forked from 1b-agent/opencadstudio-upstream
Merge pull request #1613 from ramox81/codex/sheet-set-manager
Sheet Set Manager, NEWSHEETSET / OPENSHEETSET and sheet set fields
This commit is contained in:
commit
078306d8fc
50 files changed
+8974
-27
No files matched your search
@@ -82,6 +82,7 @@ pub(super) const NAMES: &[&str] = &[
|
||||
"dialog_ok",
|
||||
"attdef_dialog",
|
||||
"field_dialog",
|
||||
"sheet_set",
|
||||
"close_document",
|
||||
"toggle_properties",
|
||||
"toggle_layers",
|
||||
@@ -1133,6 +1134,24 @@ impl OpenCADStudio {
|
||||
"link_text" => F::HyperlinkText(v.into()),
|
||||
"link_url" => F::HyperlinkUrl(v.into()),
|
||||
"plot_scale" => F::PlotScale(index(codec::fields::PLOT_SCALE_FORMATS.len())?),
|
||||
"ss_custom" => F::SsCustom(v.into()),
|
||||
"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 views = state.name == "SheetView";
|
||||
let id = fd::nav_nodes(db, views)
|
||||
.into_iter()
|
||||
.find(|(_, id, label, _)| label == v || id == v)
|
||||
.map(|(_, id, _, _)| id)
|
||||
.ok_or_else(|| failure("invalid_value", "No such node"))?;
|
||||
F::SsNode(id)
|
||||
}
|
||||
"ss_prop" => F::SsProp(v.into()),
|
||||
"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())?),
|
||||
"table_function" => F::TableFunction(
|
||||
["Average", "Sum", "Count", "Cell"]
|
||||
@@ -1143,6 +1162,203 @@ impl OpenCADStudio {
|
||||
_ => return Err(failure("invalid_value", "Unknown field dialog key")),
|
||||
})
|
||||
}
|
||||
// Sheet Set Manager and its dialogs: "open=<dst>", "tab=list|views|model",
|
||||
// "select=<target>", "activate=<target>", "menu=<action>:<target>"
|
||||
// (open, new_sheet, new_subset, import, rename, remove, properties,
|
||||
// close; a target is a sheet number or title, a subset name or
|
||||
// "set"), "import_file=<dwg>", "new" (wizard), "existing=0|1",
|
||||
// "step=<n>", "name=", "description=", "folder=", "hierarchy=0|1",
|
||||
// "add_folder=<dir>", "layout=<i>:0|1", "wizard_props",
|
||||
// "row=<i>:<value>", "prompt=0|1:<row>", "template=<file>",
|
||||
// "custom=<i>:<value>", "add_custom", "custom_name=", "custom_default=",
|
||||
// "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};
|
||||
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"))
|
||||
};
|
||||
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()))
|
||||
};
|
||||
Message::SheetSet(match key {
|
||||
"open" => M::OpenPicked(Some(std::path::PathBuf::from(arg))),
|
||||
"import_file" => M::ImportPicked(Some(std::path::PathBuf::from(arg))),
|
||||
"tab" => M::Tab(match arg {
|
||||
"views" => SsmTab::SheetViews,
|
||||
"model" => SsmTab::ModelViews,
|
||||
_ => SsmTab::SheetList,
|
||||
}),
|
||||
"select" => M::Select(target(self, arg)?),
|
||||
"activate" => M::Activate(target(self, arg)?),
|
||||
"menu" => {
|
||||
let (action, spec) = arg.split_once(':').unwrap_or((arg, "set"));
|
||||
let action = match action {
|
||||
"open" => A::Open,
|
||||
"new_sheet" => A::NewSheet,
|
||||
"new_subset" => A::NewSubset,
|
||||
"import" => A::ImportLayout,
|
||||
"rename" => A::Rename,
|
||||
"remove" => A::Remove,
|
||||
"properties" => A::Properties,
|
||||
"close" => A::Close,
|
||||
_ => return Err(failure("invalid_value", "Unknown sheet set menu action")),
|
||||
};
|
||||
if action == A::ImportLayout {
|
||||
self.sheet_set_import_parent = Some(target(self, spec)?);
|
||||
return Ok(Task::none());
|
||||
}
|
||||
M::Menu(target(self, spec)?, action)
|
||||
}
|
||||
"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"))?)),
|
||||
"layout" => {
|
||||
let (i, v) = index_value(arg)?;
|
||||
M::Wizard(W::LayoutOn(i, v == "1"))
|
||||
}
|
||||
"name" => M::Input(F::Name, arg.into()),
|
||||
"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))),
|
||||
"wizard_props" => M::WizardProperties,
|
||||
"row" => {
|
||||
let (i, v) = index_value(arg)?;
|
||||
M::Input(F::Row(i), v)
|
||||
}
|
||||
"prompt" => {
|
||||
let (i, v) = index_value(arg)?;
|
||||
M::Choose(F::Row(i), usize::from(v != "1"))
|
||||
}
|
||||
"template" => M::TemplatePicked(Some(std::path::PathBuf::from(arg))),
|
||||
"custom" => {
|
||||
let (i, v) = index_value(arg)?;
|
||||
M::CustomValue(i, v)
|
||||
}
|
||||
"add_custom" => M::AddCustom,
|
||||
"custom_name" => M::Input(F::CustomName, arg.into()),
|
||||
"custom_default" => M::Input(F::CustomDefault, arg.into()),
|
||||
"custom_owner" => M::Choose(F::CustomOwner, usize::from(arg == "1")),
|
||||
"add_custom_ok" => M::AddCustomOk,
|
||||
"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"))?),
|
||||
"refresh" => M::Refresh,
|
||||
"open_after" => M::Toggle(F::OpenAfter, arg == "1"),
|
||||
"row_toggle" => {
|
||||
let (i, v) = index_value(arg)?;
|
||||
M::Toggle(F::Row(i), v == "1")
|
||||
}
|
||||
"publish" => M::Toggle(F::Publish, arg == "1"),
|
||||
"layout_name" => M::Input(F::LayoutName, arg.into()),
|
||||
"rename_opt" => {
|
||||
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_row" => {
|
||||
let (i, v) = index_value(arg)?;
|
||||
M::Toggle(F::ImportRow(i), v == "1")
|
||||
}
|
||||
"prefix" => M::Toggle(F::ImportPrefix, arg == "1"),
|
||||
"previous" => M::Previous,
|
||||
"next" => M::Next,
|
||||
"views_by_category" => M::ViewsByCategory(arg == "1"),
|
||||
"new_category" => M::NewCategory,
|
||||
"category" => {
|
||||
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()))
|
||||
.ok_or_else(|| failure("invalid_value", "No such view category"))?;
|
||||
M::CategoryProperties(id)
|
||||
}
|
||||
"remove_category" => {
|
||||
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()))
|
||||
.ok_or_else(|| failure("invalid_value", "No such view category"))?;
|
||||
M::CategoryRemove(id)
|
||||
}
|
||||
"category_block" => {
|
||||
let (i, v) = index_value(arg)?;
|
||||
M::Toggle(F::CategoryBlock(i), v == "1")
|
||||
}
|
||||
"add_location" => M::LocationPicked(Some(std::path::PathBuf::from(arg))),
|
||||
"remove_location" => {
|
||||
let id = self
|
||||
.sheet_set
|
||||
.locations
|
||||
.iter()
|
||||
.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)
|
||||
}
|
||||
"open_drawing" => M::OpenDrawing(arg.into()),
|
||||
"toggle_drawing" => M::ToggleDrawing(arg.into()),
|
||||
"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())));
|
||||
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 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))
|
||||
.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, ""));
|
||||
let a = match verb {
|
||||
"display" => VA::Display,
|
||||
"rename" => VA::Rename,
|
||||
"label" => VA::Label,
|
||||
"category" => VA::Category(
|
||||
db.view_categories()
|
||||
.iter()
|
||||
.find(|c| c.prop("Name") == Some(name))
|
||||
.map(|c| c.id().to_string())
|
||||
.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"))?,
|
||||
),
|
||||
_ => 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_add" => M::BlockListAdd,
|
||||
"block_list_delete" => M::BlockListDelete,
|
||||
"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)?;
|
||||
M::SelectBlockCheck(i, v == "1")
|
||||
}
|
||||
"ok" => M::Ok,
|
||||
"cancel" => M::Cancel,
|
||||
_ => return Err(failure("invalid_value", "Unknown sheet set action")),
|
||||
})
|
||||
}
|
||||
"ribbon_dropdown" => Message::ToggleRibbonDropdown(string(req, "value")?.into()),
|
||||
"pdf_dialog_ok" => {
|
||||
use crate::ui::window::pdf_dialogs::PdfDialogMsg;
|
||||
@@ -1169,6 +1385,9 @@ impl OpenCADStudio {
|
||||
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,
|
||||
),
|
||||
|
||||
Reference in new issue
Block a user