Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions assets/locales/pending/drawing-update.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"en": {
"cmd.drawing_update": "Update Drawing"
},
"ar": {
"cmd.drawing_update": "تحديث اللوحة"
},
"de": {
"cmd.drawing_update": "Zeichnung aktualisieren"
},
"he": {
"cmd.drawing_update": "עדכון שרטוט"
},
"ja": {
"cmd.drawing_update": "図面を更新"
},
"ko": {
"cmd.drawing_update": "도면 업데이트"
},
"vi": {
"cmd.drawing_update": "Cập nhật bản vẽ"
},
"zh": {
"cmd.drawing_update": "更新图纸"
}
}
20 changes: 20 additions & 0 deletions crates/doc/src/drawing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,17 @@ pub const MIN_DPI: f64 = 25.0;
/// The highest resolution a sheet may ask for.
pub const MAX_DPI: f64 = 2400.0;

/// When a drawing's views follow what they draw.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum Updates {
/// As it changes.
#[default]
Automatic,
/// When asked (`drawing.update`): until then each view shows its last lines, out of date.
Deferred,
}

/// A drawing: its sheets and the designs they draw.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
Expand All @@ -126,6 +137,9 @@ pub struct Drawing {
/// First or third angle: what every projected view shows, and the title block's symbol.
#[serde(default)]
pub projection: Projection,
/// When its views follow a changed model. Saved only when deferred.
#[serde(default, skip_serializing_if = "follows_at_once")]
pub updates: Updates,
/// The language of the drawing's content, a BCP 47 tag (`en-GB`).
pub language: String,
/// The font family its text is set in, by name; empty: the built-in font.
Expand Down Expand Up @@ -328,6 +342,7 @@ impl Drawing {
properties: Arc::default(),
units: Units::default(),
projection: Projection::default(),
updates: Updates::default(),
language: language.into(),
font: String::new(),
sheets: vec![Arc::new(first)],
Expand Down Expand Up @@ -584,6 +599,11 @@ fn no_properties(properties: &Arc<Metadata>) -> bool {
properties.is_empty()
}

/// Whether the drawing's views follow the model as it changes, so its file leaves `updates` out.
fn follows_at_once(updates: &Updates) -> bool {
*updates == Updates::Automatic
}

/// Adds `more` to `records`, each where its id puts it: the order every list of records after the
/// sheets keeps (the module's rule), whatever order they come in.
fn add_by_id<T>(records: &mut Vec<Arc<T>>, more: impl IntoIterator<Item = Arc<T>>, id: impl Fn(&T) -> u64) {
Expand Down
3 changes: 3 additions & 0 deletions crates/doc/src/drawing/format/pending/deferred-updates.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//! A drawing can say when its views follow a changed model (`updates`: `deferred`, only on
//! `drawing.update`), saved only when set. An older drawing follows the model as it changes. The last
//! release refuses a drawing with this format's number.
18 changes: 15 additions & 3 deletions crates/engine/src/cmd/drawing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use solidcraft_doc::drawing::balloon::balloons_by_row;
use solidcraft_doc::drawing::fields::{Component, Values};
use solidcraft_doc::drawing::table::Kind;
use solidcraft_doc::drawing::view::{MAX_VIEW_DEPTH, View, ViewKind};
use solidcraft_doc::drawing::{self, Drawing, Source, Units, template};
use solidcraft_doc::drawing::{self, Drawing, Source, Units, Updates, template};
use solidcraft_doc::drawing_view::ViewDirection;
use solidcraft_doc::{Document, ids};
use solidcraft_geom::cell::{Content, Projection};
Expand Down Expand Up @@ -93,13 +93,13 @@ pub static COMMANDS: &[CommandSpec] = &[
"drawing: id → deleted: its id; closed when it was open (one undo step of the model)",
),
CommandSpec::new("drawing.inspect", "Inspect Drawing", inspect).in_drawing().icon("inspect").noundo().doc_only().params(
"→ {id, name, units, projection, language, font, font_note: why its text is set in the built-in font instead (the font isn't on this computer, or can't be set on paper), or null, properties, sources: [{id}], sheets: [{id, name, size_mm, orientation, title_block (its definition, or null), title_block_cells: [{name, text, value?}] (each text cell as the sheet shows it: its fields' values, \"-\" for one with none, or the text typed over it with the value it hides as `value`), title_block_overrides, dpi, documents, excluded, views: [{id, kind: base|projected, parent?, side?, label, dimensions: [ids], balloons: [ids]}], base views by id, each followed by those projected from it}], revisions: {rows: [{row, revision, description, designer, checker, date, hidden}], the oldest first (the newest is the drawing's revision), next: the revision a new row gets}}. Read-only.",
"→ {id, name, units, projection, updates: automatic or deferred, language, font, font_note: why its text is set in the built-in font instead (the font isn't on this computer, or can't be set on paper), or null, properties, sources: [{id}], sheets: [{id, name, size_mm, orientation, title_block (its definition, or null), title_block_cells: [{name, text, value?}] (each text cell as the sheet shows it: its fields' values, \"-\" for one with none, or the text typed over it with the value it hides as `value`), title_block_overrides, dpi, documents, excluded, views: [{id, kind: base|projected, parent?, side?, label, dimensions: [ids], balloons: [ids]}], base views by id, each followed by those projected from it}], revisions: {rows: [{row, revision, description, designer, checker, date, hidden}], the oldest first (the newest is the drawing's revision), next: the revision a new row gets}}. Read-only.",
),
CommandSpec::new("drawing.set", "Drawing Settings", set)
.in_drawing()
.icon("settings")
.doc_only()
.params("name?, language?: a BCP 47 tag, units?: \"follow_model\" or one length unit such as \"mm\", projection?: first or third (angle), which every projected view follows, font?: the font family its text is set in, by name, never a file (\"\": the built-in font). revision_numbering?: {start: 0 or 1}, the number new revisions count from: rows already there stay as typed. One undo step."),
.params("name?, language?: a BCP 47 tag, units?: \"follow_model\" or one length unit such as \"mm\", projection?: first or third (angle), which every projected view follows, updates?: automatic, or deferred: its views follow a changed model only on drawing.update, font?: the font family its text is set in, by name, never a file (\"\": the built-in font). revision_numbering?: {start: 0 or 1}, the number new revisions count from: rows already there stay as typed. One undo step."),
CommandSpec::new("drawing.properties", "Drawing Properties", properties).in_drawing().icon("settings").noundo().doc_only().params(
"→ metadata: the drawing's properties as saved (other tools' keys too); properties: project, part_number, revision, author, organization, description and license, each its text or null. The design properties' rules (document.metadata).",
),
Expand Down Expand Up @@ -131,6 +131,14 @@ fn projection(cmd: &str, p: &Value) -> Result<Option<Projection>> {
}
}

/// `updates` as given: when the views follow a changed model.
fn updates(cmd: &str, p: &Value) -> Result<Option<Updates>> {
match p.get("updates") {
None => Ok(None),
Some(v) => serde_json::from_value(v.clone()).map(Some).map_err(|_| bad(cmd, "`updates` is automatic or deferred")),
}
}

/// `font` as given: a font family's name, never a file (drawings name fonts by family, so they
/// travel).
fn font<'a>(cmd: &str, p: &'a Value) -> Result<Option<&'a str>> {
Expand Down Expand Up @@ -409,6 +417,7 @@ fn inspect(s: &mut Session, _p: &Value) -> Result<Value> {
"name": d.name,
"units": d.units,
"projection": d.projection,
"updates": d.updates,
"language": d.language,
"font": d.font,
"font_note": solidcraft_sketch::paper_font_note(&solidcraft_sketch::font_dirs(), &d.font),
Expand Down Expand Up @@ -493,6 +502,9 @@ fn set(s: &mut Session, p: &Value) -> Result<Value> {
if let Some(projection) = projection(cmd, p)? {
d.projection = projection;
}
if let Some(updates) = updates(cmd, p)? {
d.updates = updates;
}
if let Some(font) = font(cmd, p)? {
d.font = font.to_string();
}
Expand Down
3 changes: 2 additions & 1 deletion crates/engine/src/cmd/drawing_export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ fn export(s: &mut Session, p: &Value) -> Result<Value> {
}
solidcraft_io::vfs::check(path).map_err(|e| EngineError::Other(e.to_string()))?;
}
let built = crate::drawing_scene::build(s, &d, sheet)?;
let built = crate::drawing_scene::as_shown(s, &d, sheet)?;
let failed: Vec<String> = built
.views
.iter()
Expand Down Expand Up @@ -138,6 +138,7 @@ fn export(s: &mut Session, p: &Value) -> Result<Value> {
report: ExportReport { widths_snapped: grid.widths_snapped, pieces_merged: grid.pieces_merged, pixels },
views: built.views.into_iter().map(Into::into).collect(),
dimensions: super::drawing_scene::dimension_results(built.dimensions),
out_of_date: built.out_of_date.iter().map(|id| ids::encode(*id)).collect(),
param_warnings: Vec::new(),
};
serde_json::to_value(reply).map_err(|e| EngineError::Other(e.to_string()))
Expand Down
49 changes: 39 additions & 10 deletions crates/engine/src/cmd/drawing_scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@
//! page's picking uses ([`crate::drawing_scene::hit`]).
//!
//! `drawing.status` (#4894 WE2) says where the drawing open stands: each view as the provider last
//! drew it, and each dimension as the model has it now, in one read.
//! drew it, and each dimension as the model has it now, in one read. `drawing.update` (#4892) lets a
//! deferred drawing draw from the model as it is now.

use serde_json::Value;
use solidcraft_doc::ids;

use super::CommandSpec;
use crate::drawing_scene::{CMD, DimensionState};
use crate::schema::drawing_scene::{
DimensionStatusResult, DrawingStatusParams, DrawingStatusResult, HitResult, LineHitResult, SheetHitParams, SheetHitResult, SheetLineParams,
SheetLineResult, SheetPaperScene, SheetSceneDimension, SheetSceneParams, SheetSceneResult, ViewStatusResult,
DimensionStatusResult, DrawingStatusParams, DrawingStatusResult, DrawingUpdateParams, DrawingUpdateResult, HitResult, LineHitResult,
SheetHitParams, SheetHitResult, SheetLineParams, SheetLineResult, SheetPaperScene, SheetSceneDimension, SheetSceneParams, SheetSceneResult,
ViewStatusResult,
};
use crate::schema::{TypedContract, output_schema_for};
use crate::{EngineError, Result, Session};
Expand All @@ -28,6 +30,8 @@ const LINE: &str = "drawing.scene.line";
const LINE_CONTRACT: TypedContract<SheetLineParams> = TypedContract::new();
const STATUS: &str = "drawing.status";
const STATUS_CONTRACT: TypedContract<DrawingStatusParams> = TypedContract::new();
const UPDATE: &str = "drawing.update";
const UPDATE_CONTRACT: TypedContract<DrawingUpdateParams> = TypedContract::new();

pub static COMMANDS: &[CommandSpec] = &[CommandSpec::new(STATUS, "Drawing Status", crate::checked!("drawing.status", status))
.icon("inspect")
Expand All @@ -36,7 +40,15 @@ pub static COMMANDS: &[CommandSpec] = &[CommandSpec::new(STATUS, "Drawing Status
.doc_only()
.contract(&STATUS_CONTRACT)
.output(output_schema_for::<DrawingStatusResult>)
.params("→ {views: [{view, sheet, status: current|out_of_date|placeholder|failed, reason?}], dimensions: [{dimension, status: ok|overridden|ambiguous|suppressed|lost|unmeasurable, why?}], waiting: how many views are out of date}. current: drawn, from the model and with the settings the view has now. Balloons aren't listed: drawing.balloon.inspect reads each one. Read-only: nothing is drawn, and each body a dimension names is read once for the call."),
.params("→ {views: [{view, sheet, status: current|out_of_date|placeholder|failed, reason?}], dimensions: [{dimension, status: ok|overridden|ambiguous|suppressed|lost|unmeasurable, why?}], waiting: how many views are out of date, held?: true when a deferred drawing's wait for drawing.update}. current: drawn, from the model and with the settings the view has now. Balloons aren't listed: drawing.balloon.inspect reads each one. Read-only: nothing is drawn, and each body a dimension names is read once for the call."),
CommandSpec::new(UPDATE, "Update Drawing", crate::checked!("drawing.update", update))
.icon("update")
.in_drawing()
.noundo()
.doc_only()
.contract(&UPDATE_CONTRACT)
.output(output_schema_for::<DrawingUpdateResult>)
.params("→ {waiting}: a deferred drawing's views may draw from the model as it is now, until that moves on; waiting: how many are out of date until they are drawn. Nothing is drawn here: the sheet page draws them, as drawing.scene or an export of their sheet does. A drawing that isn't deferred follows the model already."),
CommandSpec::new(HIT, "What Is Under a Point", crate::checked!("drawing.scene.hit", hit))
.icon("inspect")
.in_drawing()
Expand All @@ -60,7 +72,7 @@ pub static COMMANDS: &[CommandSpec] = &[CommandSpec::new(STATUS, "Drawing Status
.doc_only()
.contract(&CONTRACT)
.output(output_schema_for::<SheetSceneResult>)
.params("sheet: id or name → {sheet, scene: {size_mm, groups: [{object, kind: drawing_border|sheet_image|view|dimension|title_block, items: [{kind: stroke, path, closed, width_mm} or {kind: fill, region} or {kind: picture, source, rect: {min, max}, opacity}]}]} in paint order: the sheet's drawing border (object: the sheet), then each image on it by id (object and source: the placement), then each view on it by id (object: the view; its hidden lines dashed, under its visible ones), then the dimensions of those views by view and id (object: the dimension; lines and arrowheads, in paper millimetres at any scale, with no text yet), then its title block's lines (object: the sheet), views: [{view, status: drawn|placeholder|failed, reason?, stats?}], objects: [{object, kind, bounds_mm: {min, max}, boundary_mm?}], where the border, each view and each dimension sit on paper, dimensions: [{dimension, view, status: ok|overridden|ambiguous|suppressed|lost|unmeasurable, drawn, why?}]}. A view with nothing to measure, or one that can't be drawn yet, is left out and says why, and so is a dimension that isn't found again or whose view isn't drawn. Read-only; no model is evaluated.")];
.params("sheet: id or name → {sheet, scene: {size_mm, groups: [{object, kind: drawing_border|sheet_image|view|dimension|title_block, items: [{kind: stroke, path, closed, width_mm} or {kind: fill, region} or {kind: picture, source, rect: {min, max}, opacity}]}]} in paint order: the sheet's drawing border (object: the sheet), then each image on it by id (object and source: the placement), then each view on it by id (object: the view; its hidden lines dashed, under its visible ones), then the dimensions of those views by view and id (object: the dimension; lines and arrowheads, in paper millimetres at any scale, with no text yet), then its title block's lines (object: the sheet), views: [{view, status: drawn|placeholder|failed, reason?, stats?}], objects: [{object, kind, bounds_mm: {min, max}, boundary_mm?}], where the border, each view and each dimension sit on paper, dimensions: [{dimension, view, status: ok|overridden|ambiguous|suppressed|lost|unmeasurable, drawn, why?}]}. A view with nothing to measure, or one that can't be drawn yet, is left out and says why, and so is a dimension that isn't found again or whose view isn't drawn. Read-only; no model is evaluated. A deferred drawing draws only what drawing.update allows; out_of_date lists the views and dimensions it shows as they last were.")];

fn status(s: &mut Session, p: &Value) -> Result<Value> {
let _: DrawingStatusParams = crate::schema::read(STATUS, p)?;
Expand All @@ -80,18 +92,27 @@ fn status(s: &mut Session, p: &Value) -> Result<Value> {
})
.collect();
let waiting = views.iter().filter(|v| v.status == "out_of_date").count();
let reply = DrawingStatusResult { views, dimensions, waiting, param_warnings: Vec::new() };
let held = waiting > 0 && crate::drawing_scene::held(s, &d);
let reply = DrawingStatusResult { views, dimensions, waiting, held, param_warnings: Vec::new() };
serde_json::to_value(reply).map_err(|e| EngineError::Other(e.to_string()))
}

fn update(s: &mut Session, p: &Value) -> Result<Value> {
let _: DrawingUpdateParams = crate::schema::read(UPDATE, p)?;
let d = s.drawing(UPDATE)?.clone();
crate::drawing_scene::update(s);
let waiting = crate::drawing_scene::standing(s, &d).iter().filter(|v| v.status == "out_of_date").count();
serde_json::to_value(DrawingUpdateResult { waiting, param_warnings: Vec::new() }).map_err(|e| EngineError::Other(e.to_string()))
}

fn hit(s: &mut Session, p: &Value) -> Result<Value> {
let request: SheetHitParams = crate::schema::read(HIT, p)?;
if !request.band_mm.is_finite() || request.band_mm < 0.0 {
return Err(crate::params::bad(HIT, "band_mm is a finite number, 0 or more"));
}
let d = s.drawing(HIT)?.clone();
let sheet = crate::drawing_scene::sheet_id(&d, &request.sheet, HIT)?;
let built = crate::drawing_scene::build(s, &d, sheet)?;
let built = crate::drawing_scene::as_shown(s, &d, sheet)?;
let found = crate::drawing_scene::hit(&built.objects, request.point_mm.0, request.band_mm);
let hit = found.map(|h| HitResult { object: ids::encode(h.object), kind: h.kind, on_edge: h.on_edge });
serde_json::to_value(SheetHitResult { hit, param_warnings: Vec::new() }).map_err(|e| EngineError::Other(e.to_string()))
Expand Down Expand Up @@ -134,11 +155,19 @@ fn scene(s: &mut Session, p: &Value) -> Result<Value> {
let request: SheetSceneParams = crate::schema::read(CMD, p)?;
let d = s.drawing(CMD)?.clone();
let sheet = crate::drawing_scene::sheet_id(&d, &request.sheet, CMD)?;
let built = crate::drawing_scene::build(s, &d, sheet)?;
let built = crate::drawing_scene::as_shown(s, &d, sheet)?;
let out_of_date = built.out_of_date.iter().map(|id| ids::encode(*id)).collect();
let views = built.views.into_iter().map(Into::into).collect();
let objects = built.objects.into_iter().map(Into::into).collect();
let dimensions = dimension_results(built.dimensions);
let reply =
SheetSceneResult { sheet: ids::encode(sheet), scene: SheetPaperScene(built.scene), views, objects, dimensions, param_warnings: Vec::new() };
let reply = SheetSceneResult {
sheet: ids::encode(sheet),
scene: SheetPaperScene(built.scene),
views,
objects,
dimensions,
out_of_date,
param_warnings: Vec::new(),
};
serde_json::to_value(reply).map_err(|e| EngineError::Other(e.to_string()))
}
Loading
Loading