mirror of
https://github.com/storytold/cadcraft.git
synced 2026-12-01 18:25:32 -06:00
Merge pull request #2740 from 2ez4gcx/feat/qleader
QLEADER at the command line, as AutoCAD 2024 runs it
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
//! Dimensions and leaders: DIMLINEAR, DIMALIGNED, DIMRADIUS, DIMDIAMETER, DIMANGULAR, DIMARC,
|
||||
//! DIMORDINATE, DIMCONTINUE, DIMBASELINE, QDIM, DIM (smart), MLEADER, LEADER, DIMOVERRIDE,
|
||||
//! DIMORDINATE, DIMCONTINUE, DIMBASELINE, QDIM, DIM (smart), MLEADER, LEADER, QLEADER, DIMOVERRIDE,
|
||||
//! DIMREASSOCIATE / DIMDISASSOCIATE, DIMTEDIT, DIMSPACE; DIMEDIT, DIMJOGGED, DIMJOGLINE,
|
||||
//! DIMBREAK and DIMINSPECT in `annotate_dimedit.rs`.
|
||||
|
||||
@@ -19,6 +19,7 @@ mod edit;
|
||||
mod leader;
|
||||
mod linear;
|
||||
mod mleader;
|
||||
mod qleader;
|
||||
mod radial;
|
||||
|
||||
use angular::{AngularM, ArcLenM, run_angular, run_arclen};
|
||||
@@ -27,6 +28,7 @@ use common::{DimText, add_dim, assoc_enabled, circle_of, dim, pick_at};
|
||||
use edit::{DimSpaceM, OverrideM, dims_of, run_dimspace, run_dimtedit, run_disassociate, run_override, run_reassociate, run_tedit, run_update};
|
||||
use linear::{ChainM, LinearM, MAX_CHAIN, OrdinateM, run_aligned, run_baseline, run_continue, run_linear, run_ordinate};
|
||||
use mleader::{MLeaderM, run_leader, run_mleader};
|
||||
use qleader::{QLeaderM, run_qleader};
|
||||
use radial::{RadialM, run_diameter, run_radius};
|
||||
|
||||
pub fn specs() -> Vec<CommandSpec> {
|
||||
@@ -93,6 +95,10 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
.alias(&["lead"])
|
||||
.params("{points: [[x,y]...], text?}")
|
||||
.interactive(|_| Ok(Box::new(leader::LeaderM::default()))),
|
||||
CommandSpec::new("qleader", "Quick Leader", run_qleader)
|
||||
.alias(&["le"])
|
||||
.params("{points: [[x,y], [x,y], [x,y]?] (2 or 3), width?: text width (default 0), text?: lines split at \\n}")
|
||||
.interactive(|_| Ok(Box::new(QLeaderM::default()))),
|
||||
CommandSpec::new("dimstyle.update", "Update", run_update)
|
||||
.menu(&["Dimension", "Update"])
|
||||
.params("{handles?}")
|
||||
|
||||
@@ -42,8 +42,13 @@ pub(super) struct LeaderM {
|
||||
}
|
||||
|
||||
/// What follows the leader.
|
||||
enum Annotation {
|
||||
pub(super) enum Annotation {
|
||||
Text(Vec<String>),
|
||||
/// QLEADER's text: its lines and its width.
|
||||
Quick {
|
||||
lines: Vec<String>,
|
||||
width: f64,
|
||||
},
|
||||
/// A copy of a text or multiline text: its contents, height, width and style.
|
||||
Copy(MText),
|
||||
None,
|
||||
@@ -263,13 +268,13 @@ pub(super) fn json_leader(s: &mut Session, pts: &[Vec2], text: Option<&str>) ->
|
||||
}
|
||||
|
||||
/// Draw the leader through `pts` and its annotation, as AutoCAD 2024 places them; their handles.
|
||||
fn add_leader(s: &mut Session, pts: &[Vec2], spline: bool, arrow: bool, ann: Annotation) -> Result<Vec<Handle>> {
|
||||
pub(super) fn add_leader(s: &mut Session, pts: &[Vec2], spline: bool, arrow: bool, ann: Annotation) -> Result<Vec<Handle>> {
|
||||
let (Some(&end), Some(&before)) = (pts.last(), pts.len().checked_sub(2).and_then(|i| pts.get(i))) else { return Ok(Vec::new()) };
|
||||
let z = sizes(s);
|
||||
// The side the leader runs to: right unless its last segment runs left.
|
||||
let dir = if end.x < before.x { -1.0 } else { 1.0 };
|
||||
let mut vertices = pts.to_vec();
|
||||
if let Annotation::Text(_) | Annotation::Copy(_) = ann {
|
||||
if let Annotation::Text(_) | Annotation::Quick { .. } | Annotation::Copy(_) = ann {
|
||||
let d = end - before;
|
||||
// A copied text is centred on its line, and with DIMTAD on that line is above the leader:
|
||||
// the leader ends half the text height lower.
|
||||
@@ -310,6 +315,23 @@ fn add_leader(s: &mut Session, pts: &[Vec2], spline: bool, arrow: bool, ann: Ann
|
||||
columns: None,
|
||||
}))?)
|
||||
}
|
||||
Annotation::Quick { lines, width } => {
|
||||
// The middle of the first line level with the end on the right, of the last line on
|
||||
// the left, whatever DIMTAD.
|
||||
let (attach, lift) = if dir > 0.0 { (1, z.text / 2.0) } else { (9, -z.text / 2.0) };
|
||||
Some(s.add_entity(EntityKind::MText(MText {
|
||||
insert: v3(end + Vec2::new(dir * z.gap, lift)),
|
||||
height: z.text,
|
||||
width,
|
||||
attach,
|
||||
rotation: 0.0,
|
||||
style: z.text_style,
|
||||
contents: lines.join("\\P"),
|
||||
line_spacing: 1.0,
|
||||
line_spacing_exact: false,
|
||||
columns: None,
|
||||
}))?)
|
||||
}
|
||||
Annotation::Copy(m) => {
|
||||
let lift = if z.above { z.gap } else { 0.0 };
|
||||
let attach = if dir > 0.0 { 4 } else { 6 };
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
//! QLEADER at the command line, as AutoCAD 2024 runs it with its default settings (accoreconsole,
|
||||
//! synthetic drawings): up to three points, a text width, then lines of text.
|
||||
//!
|
||||
//! The leader is LEADER's, with an arrow and a hook line DIMASZ long when its last segment is more
|
||||
//! than 15° off horizontal and text follows. The multiline text sits DIMGAP past the leader's end,
|
||||
//! as wide as the width given: with the middle of its first line level with the end when the
|
||||
//! leader runs right, and of its last line when it runs left, whatever DIMTAD. Enter at the first
|
||||
//! line of text leaves the leader without text. The Settings dialog isn't available yet.
|
||||
|
||||
use serde_json::{Value, json};
|
||||
|
||||
use super::leader::{Annotation, add_leader};
|
||||
use super::{Accept, Input, Interactive, Prompt, Result, Session, Step, Vec2, bad, points_param, str_param};
|
||||
use crate::cmd::size_param;
|
||||
|
||||
/// QLEADER's default number of leader points.
|
||||
const MAX_POINTS: usize = 3;
|
||||
|
||||
#[derive(Clone, Copy, Default, PartialEq)]
|
||||
enum Ask {
|
||||
#[default]
|
||||
Points,
|
||||
Width,
|
||||
FirstLine,
|
||||
NextLine,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub(super) struct QLeaderM {
|
||||
ask: Ask,
|
||||
pts: Vec<Vec2>,
|
||||
width: f64,
|
||||
lines: Vec<String>,
|
||||
}
|
||||
|
||||
impl Interactive for QLeaderM {
|
||||
fn name(&self) -> &'static str {
|
||||
"QLEADER"
|
||||
}
|
||||
fn prompt(&self, _s: &Session) -> Prompt {
|
||||
let last = self.pts.last().copied();
|
||||
match self.ask {
|
||||
Ask::Points if self.pts.is_empty() => Prompt::new("Specify first leader point,", Accept::POINT).kw(&["Settings"]).default("Settings"),
|
||||
Ask::Points => Prompt::new("Specify next point", Accept::POINT).base_opt(last),
|
||||
// The width isn't remembered: AutoCAD 2024 offers 0 again after a width of 20.
|
||||
Ask::Width => Prompt::new("Specify text width", Accept::POINT_OR_NUMBER).distance().default("0").base_opt(last),
|
||||
Ask::FirstLine => Prompt::new("Enter first line of annotation text", Accept::TEXT).default("Mtext"),
|
||||
Ask::NextLine => Prompt::new("Enter next line of annotation text", Accept::TEXT),
|
||||
}
|
||||
}
|
||||
fn input(&mut self, s: &mut Session, i: Input) -> Result<Step> {
|
||||
match self.ask {
|
||||
Ask::Points => match i {
|
||||
Input::Point(p) => {
|
||||
self.pts.push(p);
|
||||
if self.pts.len() == MAX_POINTS {
|
||||
self.ask = Ask::Width;
|
||||
}
|
||||
}
|
||||
Input::Enter | Input::Keyword(_) if self.pts.is_empty() => s.echo("The QLEADER Settings dialog is not available yet."),
|
||||
// Enter after one point: no leader.
|
||||
Input::Enter if self.pts.len() < 2 => return Ok(Step::Done),
|
||||
Input::Enter => self.ask = Ask::Width,
|
||||
_ => {}
|
||||
},
|
||||
Ask::Width => {
|
||||
// A point gives the width as its distance from the leader's end; a negative
|
||||
// width is none.
|
||||
let width = match i {
|
||||
Input::Point(p) => self.pts.last().map(|e| e.dist(p)),
|
||||
Input::Text(t) => crate::units::parse_distance(&t),
|
||||
Input::Enter => Some(0.0),
|
||||
_ => return Ok(Step::Continue),
|
||||
};
|
||||
let finite = width.filter(|w| w.is_finite());
|
||||
self.width = finite.ok_or_else(|| crate::EngineError::Other("Requires numeric distance or two points.".into()))?.max(0.0);
|
||||
self.ask = Ask::FirstLine;
|
||||
}
|
||||
// Only typed text and Enter: a click in the drawing is no line of text, as at TEXT's.
|
||||
Ask::FirstLine | Ask::NextLine => match i {
|
||||
Input::Text(t) if !t.is_empty() => {
|
||||
self.lines.push(t);
|
||||
self.ask = Ask::NextLine;
|
||||
}
|
||||
Input::Text(_) | Input::Enter => {
|
||||
let lines = std::mem::take(&mut self.lines);
|
||||
let ann = if lines.is_empty() { Annotation::None } else { Annotation::Quick { lines, width: self.width } };
|
||||
add_leader(s, &std::mem::take(&mut self.pts), false, true, ann)?;
|
||||
return Ok(Step::Done);
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
}
|
||||
Ok(Step::Continue)
|
||||
}
|
||||
}
|
||||
|
||||
/// QLEADER's JSON form: a leader through 2 or 3 `points`, with `text` (one line per line of it) as wide
|
||||
/// as `width`, placed as the command line places them. The handles of the leader and its text.
|
||||
pub(super) fn run_qleader(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
if p.get("points").is_none_or(Value::is_null) {
|
||||
return Err(bad("qleader", "`points` is required"));
|
||||
}
|
||||
let pts = points_param(p, "points").ok_or_else(|| bad("qleader", "`points` must be a list of [x, y] points"))?;
|
||||
if !(2..=MAX_POINTS).contains(&pts.len()) {
|
||||
return Err(bad("qleader", "`points` takes 2 or 3 points"));
|
||||
}
|
||||
let width = size_param("qleader", p, "width", true)?.unwrap_or(0.0);
|
||||
if p.get("text").is_some_and(|t| !t.is_null() && !t.is_string()) {
|
||||
return Err(bad("qleader", "`text` must be a string"));
|
||||
}
|
||||
// Empty lines at the end are dropped, as the command line ends at one: a left-running leader
|
||||
// would otherwise sit level with a blank last line. Text with nothing left is no text.
|
||||
let mut lines: Vec<String> = str_param(p, "text").map(|t| t.lines().map(str::to_string).collect()).unwrap_or_default();
|
||||
while lines.last().is_some_and(String::is_empty) {
|
||||
lines.pop();
|
||||
}
|
||||
let ann = if lines.is_empty() { Annotation::None } else { Annotation::Quick { lines, width } };
|
||||
let hs = add_leader(s, &pts, false, true, ann)?;
|
||||
Ok(json!({ "handles": hs.iter().map(|h| h.hex()).collect::<Vec<_>>() }))
|
||||
}
|
||||
@@ -202,6 +202,7 @@ pub const NO_FILES: &[&str] = &[
|
||||
"dim",
|
||||
"mleader",
|
||||
"leader",
|
||||
"qleader",
|
||||
"dimstyle.update",
|
||||
"dimoverride",
|
||||
"dimreassociate",
|
||||
|
||||
@@ -146,6 +146,7 @@ mod purge_mlinestyles;
|
||||
mod purge_prompts;
|
||||
mod qdim;
|
||||
mod qdim_modes;
|
||||
mod qleader;
|
||||
mod query_entities;
|
||||
mod quickcalc;
|
||||
mod recent_commands;
|
||||
|
||||
@@ -0,0 +1,253 @@
|
||||
//! QLEADER at the command line as AutoCAD 2024 runs it with its default settings (accoreconsole,
|
||||
//! `(command "_.QLEADER" ...)` on a metric drawing, then `entget` of the LEADER and the MTEXT):
|
||||
//! up to three points, a text width, lines of text; the text sits DIMGAP past the leader's end
|
||||
//! with the middle of its first line level with it on the right, of its last line on the left.
|
||||
|
||||
use cadcraft_engine::doc::EntityKind;
|
||||
use cadcraft_engine::geom::Vec2;
|
||||
use cadcraft_engine::{Input, Session};
|
||||
use serde_json::json;
|
||||
|
||||
/// What QLEADER drew: the leader's vertices, and the text's insertion point, height, width,
|
||||
/// attachment and contents (rounded to 1e-9).
|
||||
type Drawn = (Vec<(f64, f64)>, Option<((f64, f64), f64, f64, u8, String)>);
|
||||
|
||||
fn drawn(s: &Session) -> Drawn {
|
||||
let r = |v: f64| (v * 1e9).round() / 1e9;
|
||||
let d = s.doc().unwrap();
|
||||
let leader = d
|
||||
.model
|
||||
.iter()
|
||||
.find_map(|e| if let EntityKind::Leader(l) = &e.kind { Some(l.vertices.iter().map(|p| (r(p.x), r(p.y))).collect()) } else { None });
|
||||
let text = d.model.iter().find_map(|e| match &e.kind {
|
||||
EntityKind::MText(m) => Some(((r(m.insert.x), r(m.insert.y)), r(m.height), r(m.width), m.attach, m.contents.clone())),
|
||||
_ => None,
|
||||
});
|
||||
(leader.unwrap_or_default(), text)
|
||||
}
|
||||
|
||||
/// A drawing with the measured scripts' dimension settings: DIMTAD 1, DIMGAP 0.625, DIMASZ 2.5,
|
||||
/// DIMSCALE 1 and DIMTXT 2.5.
|
||||
fn session() -> Session {
|
||||
let mut s = Session::new();
|
||||
for (name, v) in [("DIMTAD", 1.0), ("DIMGAP", 0.625), ("DIMASZ", 2.5), ("DIMSCALE", 1.0), ("DIMTXT", 2.5)] {
|
||||
s.execute("setvar", &json!({ "name": name, "value": v })).unwrap();
|
||||
}
|
||||
s
|
||||
}
|
||||
|
||||
/// Types QLEADER then each of `inputs`, and checks it ended.
|
||||
fn qleader(s: &mut Session, inputs: &[&str]) {
|
||||
s.cmdline("QLEADER").unwrap();
|
||||
for t in inputs {
|
||||
s.cmdline(t).unwrap();
|
||||
}
|
||||
assert!(s.running.is_none(), "{inputs:?}: {}", s.prompt_text());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn qleader_places_the_text_as_autocad_does() {
|
||||
// (inputs, AutoCAD's leader vertices, text insertion point, width, attachment, contents)
|
||||
type Case<'a> = (&'a [&'a str], &'a [(f64, f64)], (f64, f64), f64, u8, &'a str);
|
||||
let cases: [Case; 8] = [
|
||||
// Three points, the last segment level: no hook line.
|
||||
(&["0,0", "20,15", "40,15", "0", "ABC", ""], &[(0.0, 0.0), (20.0, 15.0), (40.0, 15.0)], (40.625, 16.25), 0.0, 1, "ABC"),
|
||||
// Two points: a hook line DIMASZ (2.5) long into the end.
|
||||
(&["0,0", "20,15", "", "0", "ABC", ""], &[(0.0, 0.0), (17.5, 15.0), (20.0, 15.0)], (20.625, 16.25), 0.0, 1, "ABC"),
|
||||
(
|
||||
&["0,0", "20,15", "35,30", "20", "AB", "CD", ""],
|
||||
&[(0.0, 0.0), (20.0, 15.0), (32.5, 30.0), (35.0, 30.0)],
|
||||
(35.625, 31.25),
|
||||
20.0,
|
||||
1,
|
||||
"AB\\PCD",
|
||||
),
|
||||
// Running left: the middle of the last line level with the end.
|
||||
(&["0,0", "-20,15", "-40,15", "0", "AB", "CD", ""], &[(0.0, 0.0), (-20.0, 15.0), (-40.0, 15.0)], (-40.625, 13.75), 0.0, 9, "AB\\PCD"),
|
||||
(&["0,0", "-20,15", "-40,15", "0", "A", "B", "C", ""], &[(0.0, 0.0), (-20.0, 15.0), (-40.0, 15.0)], (-40.625, 13.75), 0.0, 9, "A\\PB\\PC"),
|
||||
// A short leader running left: the hook line comes from past the start.
|
||||
(&["0.5,0.25", "0.48,0.265", "", "0", "ABC", ""], &[(0.5, 0.25), (2.98, 0.265), (0.48, 0.265)], (-0.145, -0.985), 0.0, 9, "ABC"),
|
||||
// Straight up: it counts as running right.
|
||||
(&["0,0", "0,20", "", "0", "ABC", ""], &[(0.0, 0.0), (-2.5, 20.0), (0.0, 20.0)], (0.625, 21.25), 0.0, 1, "ABC"),
|
||||
// Survey coordinates, running left.
|
||||
(
|
||||
&["612345.678,2398765.432", "612325.678,2398780.432", "612305.678,2398780.432", "0", "ABC", ""],
|
||||
&[(612345.678, 2398765.432), (612325.678, 2398780.432), (612305.678, 2398780.432)],
|
||||
(612305.053, 2398779.182),
|
||||
0.0,
|
||||
9,
|
||||
"ABC",
|
||||
),
|
||||
];
|
||||
for (inputs, leader, at, width, attach, text) in cases {
|
||||
let mut s = session();
|
||||
qleader(&mut s, inputs);
|
||||
assert_eq!(drawn(&s), (leader.to_vec(), Some((at, 2.5, width, attach, text.to_string()))), "{inputs:?}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn qleader_scales_with_dimscale_and_ignores_dimtad() {
|
||||
// DIMGAP 2 and DIMSCALE 2: text 5 high, 4 past the end; the hook line 5 long.
|
||||
let mut s = session();
|
||||
s.execute("setvar", &json!({ "name": "DIMGAP", "value": 2.0 })).unwrap();
|
||||
s.execute("setvar", &json!({ "name": "DIMSCALE", "value": 2.0 })).unwrap();
|
||||
qleader(&mut s, &["0,0", "20,15", "35,30", "0", "ABC", ""]);
|
||||
let want = vec![(0.0, 0.0), (20.0, 15.0), (30.0, 30.0), (35.0, 30.0)];
|
||||
assert_eq!(drawn(&s), (want, Some(((39.0, 32.5), 5.0, 0.0, 1, "ABC".to_string()))));
|
||||
// DIMTAD 0 or 1, the same place.
|
||||
for tad in [0, 1] {
|
||||
let mut s = session();
|
||||
s.execute("setvar", &json!({ "name": "DIMTAD", "value": tad })).unwrap();
|
||||
qleader(&mut s, &["0,0", "20,15", "40,15", "0", "ABC", ""]);
|
||||
assert_eq!(drawn(&s).1, Some(((40.625, 16.25), 2.5, 0.0, 1, "ABC".to_string())), "DIMTAD {tad}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn qleader_prompts_and_its_width() {
|
||||
let mut s = session();
|
||||
let mut asked = Vec::new();
|
||||
s.cmdline("QLEADER").unwrap();
|
||||
for t in ["0,0", "20,15", "40,15", "50,15", "ABC", ""] {
|
||||
asked.push(s.current_prompt().unwrap().display());
|
||||
s.cmdline(t).unwrap();
|
||||
}
|
||||
assert_eq!(
|
||||
asked,
|
||||
[
|
||||
"Specify first leader point, or [Settings] <Settings>:",
|
||||
"Specify next point:",
|
||||
"Specify next point:",
|
||||
"Specify text width <0>:",
|
||||
"Enter first line of annotation text <Mtext>:",
|
||||
"Enter next line of annotation text:",
|
||||
]
|
||||
);
|
||||
// A point gives the width as its distance from the end, so Dynamic Input shows a distance.
|
||||
assert_eq!(drawn(&s).1.map(|t| t.2), Some(10.0));
|
||||
let mut s = session();
|
||||
s.cmdline("QLEADER").unwrap();
|
||||
for t in ["0,0", "20,15", "40,15"] {
|
||||
s.cmdline(t).unwrap();
|
||||
}
|
||||
assert!(s.current_prompt().unwrap().distance);
|
||||
// Text that isn't a distance is refused and asked again; Enter is no width.
|
||||
let _ = s.cmdline("abc");
|
||||
assert!(s.log.iter().any(|l| l.contains("Requires numeric distance or two points.")), "{:?}", s.log);
|
||||
assert_eq!(s.current_prompt().unwrap().display(), "Specify text width <0>:");
|
||||
for t in ["", "ABC", ""] {
|
||||
s.cmdline(t).unwrap();
|
||||
}
|
||||
assert!(s.running.is_none());
|
||||
assert_eq!(drawn(&s).1.map(|t| t.2), Some(0.0));
|
||||
// A point so far off that its distance overflows is refused like bad text.
|
||||
let mut s = session();
|
||||
s.cmdline("QLEADER").unwrap();
|
||||
for p in [Vec2::new(0.0, 0.0), Vec2::new(1e308, 0.0)] {
|
||||
s.input(Input::Point(p)).unwrap();
|
||||
}
|
||||
s.cmdline("").unwrap();
|
||||
let _ = s.input(Input::Point(Vec2::new(-1e308, 0.0)));
|
||||
assert!(s.log.iter().any(|l| l.contains("Requires numeric distance or two points.")), "{:?}", s.log);
|
||||
assert_eq!(s.current_prompt().unwrap().display(), "Specify text width <0>:");
|
||||
// A negative width is none. A width isn't remembered: AutoCAD 2024 offers 0 again after 20.
|
||||
for width in ["-5", "20"] {
|
||||
let mut s = session();
|
||||
qleader(&mut s, &["0,0", "20,15", "40,15", width, "ABC", ""]);
|
||||
assert_eq!(drawn(&s).1.map(|t| t.2), Some(width.parse::<f64>().unwrap().max(0.0)));
|
||||
s.cmdline("QLEADER").unwrap();
|
||||
for t in ["0,0", "20,15", "40,15"] {
|
||||
s.cmdline(t).unwrap();
|
||||
}
|
||||
assert_eq!(s.current_prompt().unwrap().display(), "Specify text width <0>:", "{width}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_click_at_the_text_prompts_is_no_line_of_text() {
|
||||
let mut s = session();
|
||||
s.cmdline("QLEADER").unwrap();
|
||||
for t in ["0,0", "20,15", "40,15", "0"] {
|
||||
s.cmdline(t).unwrap();
|
||||
}
|
||||
s.input(Input::Point(Vec2::new(5.0, 5.0))).unwrap();
|
||||
assert_eq!(s.current_prompt().unwrap().display(), "Enter first line of annotation text <Mtext>:");
|
||||
s.cmdline("AB").unwrap();
|
||||
s.input(Input::Point(Vec2::new(5.0, 5.0))).unwrap();
|
||||
assert_eq!(s.current_prompt().unwrap().display(), "Enter next line of annotation text:");
|
||||
s.cmdline("CD").unwrap();
|
||||
s.cmdline("").unwrap();
|
||||
assert!(s.running.is_none());
|
||||
assert_eq!(drawn(&s).1.map(|t| t.4), Some("AB\\PCD".to_string()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn qleader_without_text_or_points() {
|
||||
// Enter at the first line: the leader alone.
|
||||
let mut s = session();
|
||||
qleader(&mut s, &["0,0", "20,15", "40,15", "0", ""]);
|
||||
assert_eq!(drawn(&s), (vec![(0.0, 0.0), (20.0, 15.0), (40.0, 15.0)], None));
|
||||
// Sloped, without text: no hook line either (AutoCAD 2024: two vertices).
|
||||
let mut s = session();
|
||||
qleader(&mut s, &["0,0", "20,15", "", "0", ""]);
|
||||
assert_eq!(drawn(&s), (vec![(0.0, 0.0), (20.0, 15.0)], None));
|
||||
// Enter after one point: nothing.
|
||||
let mut s = session();
|
||||
qleader(&mut s, &["0,0", ""]);
|
||||
assert_eq!(s.doc().unwrap().model.iter().count(), 0);
|
||||
// Settings, typed or by Enter: no dialog yet, the first point is asked again.
|
||||
for settings in ["S", ""] {
|
||||
let mut s = session();
|
||||
s.cmdline("QLEADER").unwrap();
|
||||
s.cmdline(settings).unwrap();
|
||||
assert!(s.log.iter().any(|l| l == "The QLEADER Settings dialog is not available yet."), "{settings:?}: {:?}", s.log);
|
||||
assert_eq!(s.current_prompt().unwrap().display(), "Specify first leader point, or [Settings] <Settings>:", "{settings:?}");
|
||||
}
|
||||
// LE starts it too.
|
||||
let mut s = session();
|
||||
s.cmdline("LE").unwrap();
|
||||
assert_eq!(s.current_prompt().unwrap().display(), "Specify first leader point, or [Settings] <Settings>:");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn qleader_by_json() {
|
||||
let mut s = session();
|
||||
let r = s.execute("qleader", &json!({ "points": [[0, 0], [20, 15], [35, 30]], "width": 20, "text": "AB\r\nCD" })).unwrap();
|
||||
assert_eq!(r["handles"].as_array().map(Vec::len), Some(2));
|
||||
let want = vec![(0.0, 0.0), (20.0, 15.0), (32.5, 30.0), (35.0, 30.0)];
|
||||
assert_eq!(drawn(&s), (want, Some(((35.625, 31.25), 2.5, 20.0, 1, "AB\\PCD".to_string()))));
|
||||
// Text with nothing on its lines is no text: the leader alone, without a hook line.
|
||||
for text in ["", "\n", "\r\n\r\n"] {
|
||||
let mut s = session();
|
||||
let r = s.execute("qleader", &json!({ "points": [[0, 0], [20, 15]], "width": 0, "text": text })).unwrap();
|
||||
assert_eq!(r["handles"].as_array().map(Vec::len), Some(1), "{text:?}");
|
||||
assert_eq!(drawn(&s), (vec![(0.0, 0.0), (20.0, 15.0)], None), "{text:?}");
|
||||
}
|
||||
// Empty lines at the end are dropped: running left, the text sits as the command line puts it.
|
||||
let mut s = session();
|
||||
s.execute("qleader", &json!({ "points": [[0, 0], [-20, 15], [-40, 15]], "text": "AB\n\n" })).unwrap();
|
||||
assert_eq!(drawn(&s).1, Some(((-40.625, 13.75), 2.5, 0.0, 9, "AB".to_string())));
|
||||
// 2 or 3 points, a width of 0 or more, text as a string.
|
||||
for bad in [
|
||||
json!({ "points": [[0, 0]] }),
|
||||
json!({ "points": [[0, 0], [1, 1], [2, 1], [3, 1]] }),
|
||||
json!({ "points": [[0, 0], [1, 1]], "width": -1 }),
|
||||
json!({ "points": [[0, 0], [1, 1]], "width": "x" }),
|
||||
json!({ "points": [[0, 0], [1, 1]], "text": 5 }),
|
||||
json!({ "points": [[0, 0], [1, 1]], "text": ["AB", "CD"] }),
|
||||
] {
|
||||
let before = s.doc().unwrap().model.iter().count();
|
||||
assert!(s.execute("qleader", &bad).is_err(), "{bad}");
|
||||
assert_eq!(s.doc().unwrap().model.iter().count(), before, "{bad}");
|
||||
}
|
||||
// A point that can't be read is named as such, not as missing points.
|
||||
for (bad, says) in [
|
||||
(json!({}), "`points` is required"),
|
||||
(json!({ "points": null }), "`points` is required"),
|
||||
(json!({ "points": [[0, 0], ["x", 1]] }), "`points` must be a list of [x, y] points"),
|
||||
] {
|
||||
let e = s.execute("qleader", &bad).unwrap_err().to_string();
|
||||
assert!(e.contains(says), "{bad}: {e}");
|
||||
}
|
||||
}
|
||||
@@ -592,6 +592,7 @@
|
||||
Query Entities 查询实体
|
||||
Quick 快速
|
||||
Quick Dimension 快速标注
|
||||
Quick Leader 快速引线
|
||||
Quick Properties 快速特性
|
||||
Quick Select 快速选择
|
||||
Quick Select Properties 快速选择特性
|
||||
|
||||
|
@@ -151,7 +151,7 @@ presence: an option that prints "not available yet" doesn't count.
|
||||
| Layers and properties | 7% | 70% | 10–15 | Layer Properties Manager with filters, states, VP overrides; QSELECT; Quick Properties; object transparency drawn on screen, in exports and in plots (#764); linetype manager thin; 19 linetypes of ~45 | [gaps](gaps.md#features) |
|
||||
| Dimensions | 9% | 45% | 25–35 | all core DIM types and associativity; style variables, DIMJOGGED, DIMJOGLINE, DIMBREAK, DIMEDIT, DIMINSPECT, QDIM modes (#507) and TOLERANCE (#420); no DIMSTYLE manager dialog or smart DIM | [gaps](gaps.md#features) |
|
||||
| Text and MTEXT | 6% | 35% | 30–45 | TrueType, formatting codes, stacking; MTEXT prompt options (#408), indents, tabs, bullets, numbering and columns (#547), annotative scaling (#468); in-place editor with formatting toolbar and ruler for new MTEXT (#792; existing TEXT is edited on the command line with TEXTEDIT; an existing MTEXT opens in the in-place editor with its contents, #1002); no fields or SPELL (open PR #551), no SHX | [gaps](gaps.md#features) |
|
||||
| Leaders, tables, fields | 4% | 25% | 25–35 | MLEADER options and block content (#408), native MULTILEADER in DXF (#459); MLEADEREDIT, MLEADERALIGN and MLEADERCOLLECT (#816); tables with cell styles, formulas, breaking and CSV data links (#534); no FIELD (open PR #551) | [gaps](gaps.md#features) |
|
||||
| Leaders, tables, fields | 4% | 25% | 25–35 | MLEADER options and block content (#408), native MULTILEADER in DXF (#459); MLEADEREDIT, MLEADERALIGN and MLEADERCOLLECT (#816); QLEADER at the command line, without its Settings dialog (#2740, #3532); tables with cell styles, formulas, breaking and CSV data links (#534); no FIELD (open PR #551) | [gaps](gaps.md#features) |
|
||||
| Hatch and gradients | 5% | 35% | 15–25 | pick points with islands; 23 patterns of ~85; gradients render flat; origin, gap tolerance, separate hatches, island styles and HATCHEDIT options (#451); Hatch and Gradient / Hatch Edit dialogs (no Preview or Inherit Properties) | [gaps](gaps.md#features) |
|
||||
| Blocks, attributes, xrefs, groups | 9% | 25% | 80–120 | static blocks and attributes; ATTSYNC, BATTMAN editing, DATAEXTRACTION/EATTEXT (#433); xrefs (#525); groups (#417); Block Editor for static blocks (BEDIT, BSAVE, BSAVEAS, BCLOSE); REFEDIT, REFSET and REFCLOSE (#818); XCLIP and XCLIPFRAME (#2354); dynamic block references read and edited, with grips (#838–#883); no dynamic-block authoring, DesignCenter | [gaps](gaps.md#features) |
|
||||
| Layouts, viewports, plotting | 9% | 35% | 35–50 | layouts, per-VP layers, page setups, plot styles (CTB/STB), Plot dialog (#160), Plot Preview and PUBLISH (#186), plotter devices (#564), PDF with text, layers and sheets (#567, #571), polygonal/object/clipped viewports (#453), annotative scales (#468), MVIEW Restore (#633); no system printers (CUPS printing is open PR #755) | [gaps](gaps.md#features) |
|
||||
@@ -222,6 +222,7 @@ DWG/DXF corpus (files from people who own them); black-box checks in AutoCAD of
|
||||
|
||||
| Date | Change | Summary |
|
||||
|---|---|---|
|
||||
| 2026-11-26 | minor | Leaders, tables, fields row: QLEADER at the command line, without its Settings dialog (#2740, #3532); parity percentages and hours not re-measured |
|
||||
| 2026-10-27 | minor | Blocks, attributes, xrefs, groups row: XCLIP and XCLIPFRAME clip block and xref references; parity percentages and hours not re-measured |
|
||||
| 2026-10-24 | minor | Re-audit against main 41d9b5e95: evidence text of the feature, stability, platforms and localization rows refreshed against main 41d9b5e95; percentages, hours and breadth counts (245/491, 233/491) not re-measured |
|
||||
| 2026-10-24 | minor | Inquiry and utilities row: COMPAREEXPORT exports a comparison to a new drawing; parity percentages and hours not re-measured |
|
||||
|
||||
Reference in New Issue
Block a user