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
32 changes: 16 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ members = ["crates/*", "apps/*", "xtask"]
# default-members

[workspace.package]
version = "2.0.2"
version = "2.1.0"
edition = "2024"
license = "MIT OR Apache-2.0"
rust-version = "1.95"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ DraftCraft is young and moving fast. [ROADMAP.md](ROADMAP.md) has what is missin
| Annotation | DIM commands with dimension styles and associative dimensions, multileaders, tables, TrueType and SHX fonts, right-to-left text |
| Hatches and blocks | Pattern, solid and gradient fills; blocks, attributes, the Block Editor, in-place editing, external references |
| Parametric | Geometric and dimensional constraints, AUTOCONSTRAIN, parameters with expressions |
| Layouts and output | Paper-space layouts, viewports, page setups, plot styles, PLOT and EXPORTPDF, SVG and PNG export |
| Layouts and output | Paper-space layouts, viewports, page setups, plot styles, PLOT and EXPORTPDF (arcs, circles and splines kept as true curves), SVG and PNG export |
| Files | DWG and DXF reading and writing at a chosen version, AUDIT and RECOVER, autosave and drawing recovery. Objects DraftCraft doesn't model yet can be lost on save |
| Automation | MCP server, JSON control channel, `draftcraft-cli`, AutoLISP, scripts and alias files |

Expand Down
11 changes: 5 additions & 6 deletions ROADMAP.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# DraftCraft roadmap

DraftCraft **2.0.2** is out for macOS (Apple silicon), Windows (x64 and ARM64) and Linux (x64 AppImage). It is a
DraftCraft **2.1.0** is out for macOS (Apple silicon), Windows (x64 and ARM64) and Linux (x64 AppImage). It is a
young project: good for 2D drafting, dimensioning and plotting, and still missing parts of what a full
CAD suite does. This page says what works today, what is known to be missing and what comes next.

Expand All @@ -19,23 +19,22 @@ Something not listed here is broken, or missing something you need?
| Annotation | DIM commands with dimension styles and associative dimensions, multileaders, tables, TrueType and SHX fonts, right-to-left text |
| Hatches and blocks | Pattern, solid and gradient fills; blocks, attributes, the Block Editor, in-place editing, external references |
| Parametric | Geometric and dimensional constraints, AUTOCONSTRAIN, parameters with expressions |
| Layouts and output | Paper-space layouts, viewports, page setups, plot styles, PLOT and EXPORTPDF, SVG and PNG export |
| Files | DWG and DXF reading and writing, at a chosen file version; AUDIT and RECOVER; autosave and drawing recovery |
| Layouts and output | Paper-space layouts, viewports, page setups, plot styles, PLOT and EXPORTPDF (arcs, circles and splines kept as true curves), SVG and PNG export |
| Files | DWG and DXF reading and writing, at a chosen file version; AUDIT and RECOVER; autosave and drawing recovery; PDF underlays and PDFIMPORT (PDF vectors to lines, arcs, circles, polylines, splines, hatches and text) |
| Automation | MCP server, JSON control channel, `draftcraft-cli`, AutoLISP, scripts and alias files |

## Known gaps

- **3D** — there is no 3D modelling yet (no EXTRUDE, REVOLVE, solids or surfaces).
- **File round-trips** — some objects that DraftCraft doesn't model can be lost when a DWG or DXF is
saved. Keep a copy of drawings that come from other programs before saving over them.
- **Ribbon** — no contextual tabs yet (for example a Text Editor tab while editing MTEXT) and no
slide-out panels; collapsed panels open a plain list of their commands.
- **Ribbon** — no slide-out panels yet; collapsed panels open a plain list of their commands.
- **Builds** — the macOS and Windows builds are not signed or notarized, there is no Linux ARM build and
no Windows installer yet.

## Next

1. Contextual ribbon tabs and slide-out panels, so the ribbon behaves like Windows CAD in every state.
1. Slide-out ribbon panels, so the ribbon behaves like Windows CAD in every state.
2. Keep every object through a DWG/DXF save.
3. Signed and notarized builds, a Windows installer, and a Linux ARM build.
4. The first 3D commands.
Expand Down
47 changes: 43 additions & 4 deletions crates/doc/src/extents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ pub const MAX_BLOCK_DEPTH: usize = 16;
/// Bounds of a single-line TEXT / ATTDEF / ATTRIB of `len` characters, following its justification
/// the same way the renderer places it (the stroke font is about 0.88 of the height per character).
fn text_box(t: &crate::Text, len: usize) -> Bounds2 {
Bounds2::from_points(text_quad(t, len))
}

/// The four corners of the box [`text_box`] bounds, turned with the text (counter-clockwise from
/// the bottom left of the text).
fn text_quad(t: &crate::Text, len: usize) -> [Vec2; 4] {
use crate::{HAlign, VAlign};
let w = t.height * 0.9 * t.width_factor.abs().max(0.01) * len.max(1) as f64;
// Justified text (TL, ML and BL too) hangs from its alignment point (DXF group 11).
Expand All @@ -29,7 +35,7 @@ fn text_box(t: &crate::Text, len: usize) -> Bounds2 {
(_, VAlign::Top) => -t.height,
};
let local = [Vec2::new(dx, dy), Vec2::new(dx + w, dy), Vec2::new(dx + w, dy + t.height), Vec2::new(dx, dy + t.height)];
Bounds2::from_points(local.map(|p| origin + p.rotate(t.rotation)))
local.map(|p| origin + p.rotate(t.rotation))
}

/// Whether an entity inside a block definition shows: its own invisible flag and its layer count,
Expand Down Expand Up @@ -65,6 +71,11 @@ fn blank(s: &str) -> bool {

/// Approximate box of an MTEXT, from its attachment point, width and line count.
fn mtext_box(t: &crate::MText) -> Bounds2 {
Bounds2::from_points(mtext_quad(t))
}

/// The four corners of the box [`mtext_box`] bounds, turned with the text.
fn mtext_quad(t: &crate::MText) -> [Vec2; 4] {
let lines = t.contents.split("\\P").count().max(1);
let longest = t.contents.split("\\P").map(|l| l.chars().count()).max().unwrap_or(1);
let estimate = t.height * 0.8 * longest as f64;
Expand All @@ -87,9 +98,37 @@ fn mtext_box(t: &crate::MText) -> Bounds2 {
_ => 0.0,
};
let o = t.insert.xy();
let pts = [Vec2::new(dx, top + dy), Vec2::new(dx + w, top + dy), Vec2::new(dx + w, top - h + dy), Vec2::new(dx, top - h + dy)]
.map(|p| o + p.rotate(t.rotation));
Bounds2::from_points(pts)
[Vec2::new(dx, top + dy), Vec2::new(dx + w, top + dy), Vec2::new(dx + w, top - h + dy), Vec2::new(dx, top - h + dy)]
.map(|p| o + p.rotate(t.rotation))
}

/// The box a TEXT, MTEXT or ATTDEF takes, turned with the text: the four corners of the box whose
/// axis-aligned bounds [`entity_bounds`] gives. Picking hits text inside this box, not inside its
/// bounds, which for turned text reach far past the letters (a text at 45° covered a square around
/// it, taking picks meant for the line beside it). `None` for other objects and for text that
/// draws nothing (blank, or hidden at the current annotation scale).
pub fn text_outline(d: &Drawing, e: &Entity) -> Option<[Vec2; 4]> {
let scaled;
let e = match d.anno_draw(e) {
crate::AnnoDraw::Plain => e,
crate::AnnoDraw::Hidden => return None,
crate::AnnoDraw::Scaled(f) => {
scaled = crate::anno_scaled(e, f);
&scaled
}
};
let upright = e.common.matches_layout_orientation();
let quad = match &e.kind {
EntityKind::Text(t) if blank(&t.value) => return None,
EntityKind::MText(t) if blank(&t.contents) => return None,
EntityKind::Text(t) if upright => text_quad(&crate::Text { rotation: 0.0, ..t.clone() }, t.value.chars().count()),
EntityKind::MText(t) if upright => mtext_quad(&crate::MText { rotation: 0.0, ..t.clone() }),
EntityKind::Text(t) => text_quad(t, t.value.chars().count()),
EntityKind::AttDef(a) => text_quad(&a.text, a.tag.chars().count()),
EntityKind::MText(t) => mtext_quad(t),
_ => return None,
};
quad.iter().all(|p| p.is_finite()).then_some(quad)
}

/// The box of what `e` draws (block contents on layers turned off left out).
Expand Down
2 changes: 1 addition & 1 deletion crates/doc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub use constraint::*;
pub use draftcraft_color as color;
pub use draftcraft_geom as geom;
pub use entity::*;
pub use extents::{BlockBoundsCache, MAX_BLOCK_DEPTH, entity_bounds, entity_bounds_cached, extent_bounds, extent_bounds_cached};
pub use extents::{BlockBoundsCache, MAX_BLOCK_DEPTH, entity_bounds, entity_bounds_cached, extent_bounds, extent_bounds_cached, text_outline};
pub use format::Format;
pub use gdt::*;
pub use header::{HVal, Header};
Expand Down
66 changes: 57 additions & 9 deletions crates/engine/src/select.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Hit testing and window/crossing selection.

use draftcraft_doc::{Drawing, Entity, EntityKind, Handle, Prim, Space, entity_bounds};
use draftcraft_doc::{Drawing, Entity, EntityKind, Handle, Prim, Space, entity_bounds, text_outline};
use draftcraft_geom::{Bounds2, Line, Vec2, point_in_polygon};

use crate::spatial::{self, SpatialIndex};
Expand All @@ -18,12 +18,19 @@ pub fn hit_polylines(d: &Drawing, e: &Entity, tol: f64) -> Vec<Vec<Vec2>> {
| EntityKind::Tolerance(_)
| EntityKind::MLeader(_)
| EntityKind::Image(_) => {
// Text-like objects are hit inside their box.
let b = entity_bounds(d, e, 0);
if b.is_empty() {
return Vec::new();
}
let c = b.corners();
// Text-like objects are hit inside their box: text turned with it, not the (much
// larger) axis-aligned bounds of turned text.
let c = match text_quad(d, e) {
Some(q) => q,
None if matches!(e.kind, EntityKind::Text(_) | EntityKind::MText(_) | EntityKind::AttDef(_)) => return Vec::new(),
None => {
let b = entity_bounds(d, e, 0);
if b.is_empty() {
return Vec::new();
}
b.corners()
}
};
let mut v = vec![vec![c[0], c[1], c[2], c[3], c[0]]];
if matches!(e.kind, EntityKind::Dimension(_) | EntityKind::Insert(_) | EntityKind::MLeader(_)) {
let list = draftcraft_render::build_entities(
Expand Down Expand Up @@ -90,7 +97,7 @@ pub fn entity_distance(d: &Drawing, e: &Entity, p: Vec2, tol: f64) -> f64 {
let mut best = polys.iter().map(|pl| dist_to_polyline(pl, p)).fold(f64::INFINITY, f64::min);
let filled = matches!(e.kind, EntityKind::Text(_) | EntityKind::MText(_) | EntityKind::AttDef(_) | EntityKind::Table(_))
|| matches!(e.kind, EntityKind::Tolerance(_));
if (filled && entity_bounds(d, e, 0).contains(p)) || in_text(d, e, p) {
if (filled && in_text_box(d, e, p)) || in_text(d, e, p) {
best = 0.0;
}
// A solid hatch fills its loops with odd parity under its island style, as it is drawn, not
Expand All @@ -108,6 +115,42 @@ pub fn entity_distance(d: &Drawing, e: &Entity, p: Vec2, tol: f64) -> f64 {
best
}

/// The box around the letters a TEXT, MTEXT or ATTDEF draws, turned with the text: the extents
/// of its drawn strokes and glyphs along and across its baseline, as AutoCAD's text box. Spaces
/// and the room above lower-case letters are not in it, which the estimate [`text_outline`]
/// (the full height, a fixed width per character) took in; that estimate stands in when the text
/// draws nothing measurable.
fn text_quad(d: &Drawing, e: &Entity) -> Option<[Vec2; 4]> {
let est = text_outline(d, e)?;
let (a, b) = (est[0], est[1]);
let along = b - a;
let angle = if along.len() > 1e-12 { along.y.atan2(along.x) } else { 0.0 };
// Fine enough for a box: a few hundred steps along the text's estimated size.
let size = Bounds2::from_points(est);
let tol = ((size.width() + size.height()) / 400.0).max(1e-9);
let list = draftcraft_render::build_entities(
d,
std::iter::once(e),
&draftcraft_render::Options { tolerance: tol, text: true, linetypes: false, ..Default::default() },
);
let ink =
Bounds2::from_points(list.prims.iter().flat_map(|p| list.points(p).iter().copied()).filter(|q| q.is_finite()).map(|q| q.rotate(-angle)));
if ink.is_empty() || (ink.width() <= 0.0 && ink.height() <= 0.0) {
return Some(est);
}
let c = ink.corners();
Some(c.map(|q| q.rotate(angle)))
}

/// Whether `p` is inside the box of a text-like object: around its letters, turned with the
/// text, for TEXT, MTEXT and ATTDEF ([`text_quad`]), the bounds for tables and tolerances.
fn in_text_box(d: &Drawing, e: &Entity, p: Vec2) -> bool {
match text_quad(d, e) {
Some(q) => point_in_polygon(&q, p),
None => !matches!(e.kind, EntityKind::Text(_) | EntityKind::MText(_) | EntityKind::AttDef(_)) && entity_bounds(d, e, 0).contains(p),
}
}

/// Whether `p` is on the text of a dimension or multileader: inside the box around its words,
/// turned with the text, as plain text is hit anywhere inside its box. Their other geometry is
/// hit along its lines, so without this the cursor found the object only between the letters'
Expand Down Expand Up @@ -281,7 +324,12 @@ pub(crate) fn in_window(d: &Drawing, e: &Entity, known: Option<Bounds2>, bx: &Bo
}
});
// A crossing box entirely inside a text/block bounding rectangle also selects it.
if hit || (eb.contains_box(bx) && matches!(e.kind, EntityKind::Text(_) | EntityKind::MText(_) | EntityKind::Insert(_))) {
let inside_text = match &e.kind {
EntityKind::Text(_) | EntityKind::MText(_) => text_quad(d, e).is_some_and(|q| bx.corners().iter().all(|c| point_in_polygon(&q, *c))),
EntityKind::Insert(_) => eb.contains_box(bx),
_ => false,
};
if hit || inside_text {
return true;
}
// SOLID/TRACE are filled polygons. A crossing window wholly within the
Expand Down
Loading