mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-19 10:17:58 +00:00
Merge pull request #8405 from dotCooCoo/feat/layers-drag-into-live-paint
Layers: dragging a path into a Live Paint group adds it to the group as Live Paint › Merge does
This commit is contained in:
@@ -38,7 +38,7 @@ mod shape_builder;
|
||||
mod trace;
|
||||
|
||||
pub use live_paint::live_paint_gaps;
|
||||
pub(crate) use live_paint::{isolated_live_paint, merge_drawn_in_isolation};
|
||||
pub(crate) use live_paint::{LivePaintMove, check_part_name, clear_part_name, isolated_live_paints, merge_drawn_in_isolation};
|
||||
use live_paint::{lp_expand, lp_fill, lp_gap_options, lp_info, lp_make, lp_merge, lp_release, lp_stroke_edge};
|
||||
use shape_builder::{sb_merge, sb_regions};
|
||||
pub(crate) use trace::TracePresetChanges;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use super::{
|
||||
Appearance, AppearanceItem, Arc, Beside, Document, EDGE_NAME, EngineError, FACE_NAME, GapOptions, GapSize, LIVE_PAINT_NAME, Node, NodeId,
|
||||
PathData, Point, Rect, Result, Selection, Session, SubPath, Value, b, bad, build_children, edge_near, face_at, finite, fit_to_old_edge, ids_json,
|
||||
is_live_paint, json, number_or, object_param, paint_from, po, point_param, repaint_from, replace_roots, root_ids, source_nodes, source_shapes,
|
||||
switch_or,
|
||||
PathData, Point, Rect, Result, SOURCES_NAME, Selection, Session, SubPath, Value, b, bad, build_children, edge_near, face_at, finite,
|
||||
fit_to_old_edge, ids_json, is_live_paint, json, number_or, object_param, paint_from, po, point_param, repaint_from, replace_roots, root_ids,
|
||||
source_nodes, source_shapes, switch_or,
|
||||
};
|
||||
|
||||
/// `options` as stored on a Live Paint group: none for the defaults.
|
||||
@@ -74,6 +74,44 @@ fn set_parts(g: &mut Node, mut parts: Vec<Arc<Node>>, gone: &[NodeId]) {
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether a path named `name` directly in a Live Paint group is one of its faces or edges: the
|
||||
/// name is [`FACE_NAME`] or [`EDGE_NAME`].
|
||||
fn part_name(name: Option<&str>) -> bool {
|
||||
matches!(name, Some(FACE_NAME | EDGE_NAME))
|
||||
}
|
||||
|
||||
/// Whether `n` is a path whose parent `parent` is a Live Paint group.
|
||||
fn path_in_live_paint(d: &Document, parent: Option<NodeId>, n: &Node) -> bool {
|
||||
n.path_data().is_some() && parent.and_then(|p| d.node(p)).is_some_and(is_live_paint)
|
||||
}
|
||||
|
||||
/// Clear the name of `n`, put directly in `parent`, when it is a path named like a face or an edge
|
||||
/// ([`part_name`]) and `parent` is a Live Paint group, so that the group's other children
|
||||
/// ([`others_in`]) keep it when its faces and edges are made again. Paste uses it.
|
||||
pub(crate) fn clear_part_name(d: &Document, parent: Option<NodeId>, n: &mut Node) {
|
||||
if part_name(n.name.as_deref()) && path_in_live_paint(d, parent, n) {
|
||||
n.name = None;
|
||||
}
|
||||
}
|
||||
|
||||
/// Refuse naming rows `ids` `name` when it is the name of a face or an edge ([`part_name`]) and one
|
||||
/// of them is a path directly in a Live Paint group that is not named `name` already. Checked
|
||||
/// before anything changes.
|
||||
pub(crate) fn check_part_name(d: &Document, ids: &[NodeId], name: &str) -> Result<()> {
|
||||
if !part_name(Some(name)) {
|
||||
return Ok(());
|
||||
}
|
||||
for id in ids {
|
||||
if let Some(n) = d.node(*id)
|
||||
&& n.name.as_deref() != Some(name)
|
||||
&& path_in_live_paint(d, d.parent_of(*id), n)
|
||||
{
|
||||
return Err(EngineError::Other("`Face` and `Edge` name the faces and edges of a Live Paint group: give the path another name".into()));
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Select `ids` alone, without an undo step, when they are not selected that way already.
|
||||
fn select_only(s: &mut Session, ids: &[NodeId]) -> Result<()> {
|
||||
let st = s.doc()?;
|
||||
@@ -149,11 +187,16 @@ fn merge_live(d: &mut Document, sel: &mut Selection, roots: &[NodeId]) -> Result
|
||||
.ok_or_else(|| EngineError::Other("Live Paint Merge: select a Live Paint group and the paths to add".into()))?;
|
||||
check_live_paint_takes(d, roots)?;
|
||||
let old = d.node(target).cloned().ok_or(EngineError::NoNode(target))?;
|
||||
// The rows that join are children of the group already when Merge runs after a drag, and a joining
|
||||
// path named like a face or an edge is not one of the group's parts.
|
||||
let mut old_parts = old.clone();
|
||||
if let Some(ch) = old_parts.children_mut() {
|
||||
ch.retain(|c| !roots.contains(&c.id));
|
||||
}
|
||||
// Paint to carry over: (point inside face, paint) for faces that draw; edges are matched to the
|
||||
// old edges below.
|
||||
let keep_faces: Vec<(Point, Carried)> =
|
||||
b::faces(&old).iter().filter(|f| draws(f)).filter_map(|f| Some((po::interior_point(f.path_data()?)?, Carried::of(f)))).collect();
|
||||
let old_parts = old.clone();
|
||||
b::faces(&old_parts).iter().filter(|f| draws(f)).filter_map(|f| Some((po::interior_point(f.path_data()?)?, Carried::of(f)))).collect();
|
||||
let mut sources = source_nodes(&old);
|
||||
// The objects drawn in the other Live Paint groups besides their parts stay in the merged group.
|
||||
let mut others = vec![];
|
||||
@@ -227,19 +270,22 @@ pub(super) fn lp_merge(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
Ok(json!({ "id": id.0, "faces": faces, "edges": edges }))
|
||||
}
|
||||
|
||||
/// The Live Paint group whose drawn art is added when isolation mode leaves `isolated`: the innermost
|
||||
/// Live Paint group that is `isolated` or holds it, such as a group drawn in an isolated Live Paint
|
||||
/// group and then isolated itself. None when `isolated` is not in a Live Paint group.
|
||||
pub(crate) fn isolated_live_paint(d: &Document, isolated: NodeId) -> Option<NodeId> {
|
||||
d.ancestry(isolated)?.into_iter().rev().find(|id| d.node(*id).is_some_and(is_live_paint))
|
||||
/// The Live Paint groups whose drawn art can be added when isolation mode leaves `isolated`, innermost
|
||||
/// first: every Live Paint group that is `isolated` or holds it, such as a group drawn in an isolated
|
||||
/// Live Paint group and then isolated itself, and the group it was drawn in. Empty when `isolated` is
|
||||
/// not in a Live Paint group.
|
||||
pub(crate) fn isolated_live_paints(d: &Document, isolated: NodeId) -> Vec<NodeId> {
|
||||
d.ancestry(isolated).unwrap_or_default().into_iter().rev().filter(|id| d.node(*id).is_some_and(is_live_paint)).collect()
|
||||
}
|
||||
|
||||
/// The children of Live Paint group `g` besides its parts ([`others_in`]) that Live Paint takes
|
||||
/// ([`b::live_paint_takes`]) and that are shown and unlocked with everything in them, back to
|
||||
/// front: the paths drawn in it in isolation mode.
|
||||
/// front: the paths drawn in it in isolation mode. A Live Paint group's sources group, which is
|
||||
/// always hidden, does not count.
|
||||
fn drawn_in(g: &Node) -> Vec<NodeId> {
|
||||
fn open(n: &Node) -> bool {
|
||||
n.visible && !n.locked && n.children().is_none_or(|ch| ch.iter().all(|c| open(c)))
|
||||
let src = b::sources(n).filter(|_| is_live_paint(n)).map(|s| s.id);
|
||||
n.visible && !n.locked && n.children().is_none_or(|ch| ch.iter().filter(|c| Some(c.id) != src).all(|c| open(c)))
|
||||
}
|
||||
others_in(g).filter(|c| open(c) && b::live_paint_takes(c)).map(|c| c.id).collect()
|
||||
}
|
||||
@@ -259,6 +305,189 @@ pub(crate) fn merge_drawn_in_isolation(s: &mut Session, g: NodeId) -> Result<boo
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
/// Where a row sits for Live Paint: among the paths of a Live Paint group (in its sources group,
|
||||
/// at any depth), directly in a Live Paint group, or neither.
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
enum Spot {
|
||||
Source(NodeId),
|
||||
In(NodeId),
|
||||
Outside,
|
||||
}
|
||||
|
||||
/// The [`Spot`] of a row whose parent is `parent` (None: the top level).
|
||||
fn spot_in(d: &Document, parent: Option<NodeId>) -> Spot {
|
||||
let Some(p) = parent else { return Spot::Outside };
|
||||
for x in d.ancestry(p).unwrap_or_default().into_iter().rev() {
|
||||
let n = d.node(x);
|
||||
if n.is_some_and(is_live_paint) {
|
||||
return if x == p { Spot::In(x) } else { Spot::Outside };
|
||||
}
|
||||
if let Some(g) = d.parent_of(x)
|
||||
&& d.node(g).filter(|n| is_live_paint(n)).and_then(b::sources).is_some_and(|s| s.id == x)
|
||||
{
|
||||
return Spot::Source(g);
|
||||
}
|
||||
}
|
||||
Spot::Outside
|
||||
}
|
||||
|
||||
/// The Live Paint groups that hold Live Paint group `g` among their paths (in their sources group,
|
||||
/// at any depth), innermost first.
|
||||
fn enclosing_live_paints(d: &Document, g: NodeId) -> Vec<NodeId> {
|
||||
let mut out = vec![];
|
||||
let mut at = g;
|
||||
while let Spot::Source(o) = spot_in(d, d.parent_of(at)) {
|
||||
if out.contains(&o) {
|
||||
break;
|
||||
}
|
||||
out.push(o);
|
||||
at = o;
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// What moving rows in the Layers panel (`layer.move`, `node.move`) does to Live Paint groups.
|
||||
/// Rows that go into a Live Paint group from elsewhere are added to it as `livePaint.merge` adds
|
||||
/// paths. Rows that go into or leave a group's paths (its sources group) change those paths, and
|
||||
/// the group's faces and edges are made again from them, keeping the paint of the faces and edges
|
||||
/// that stay, and so are those of every Live Paint group that holds a changed group among its
|
||||
/// paths. Rows moved within one group's paths, or among a group's own children, change no faces.
|
||||
pub(crate) struct LivePaintMove {
|
||||
/// The Live Paint group the rows go into, and for each row whether it joins the group's paths.
|
||||
join: Option<(NodeId, Vec<bool>)>,
|
||||
/// The Live Paint group the rows go among the children of, with its sources group as it is
|
||||
/// before the move.
|
||||
keep_sources: Option<(NodeId, NodeId)>,
|
||||
/// The Live Paint groups whose paths change.
|
||||
rebuild: Vec<NodeId>,
|
||||
}
|
||||
|
||||
impl LivePaintMove {
|
||||
/// Plan moving `rows` (with `copy`, copies of them) into `parent`, before anything changes.
|
||||
/// Refuses rows Live Paint can't take ([`b::live_paint_takes`]) that would go among a group's
|
||||
/// paths, with the message Make and Merge give.
|
||||
pub(crate) fn plan(d: &Document, rows: &[NodeId], parent: Option<NodeId>, copy: bool) -> Result<Self> {
|
||||
let to = spot_in(d, parent);
|
||||
let from: Vec<Spot> = rows.iter().map(|r| if copy { Spot::Outside } else { spot_in(d, d.parent_of(*r)) }).collect();
|
||||
let mut rebuild = vec![];
|
||||
for f in &from {
|
||||
if let Spot::Source(g) = *f
|
||||
&& *f != to
|
||||
&& !rebuild.contains(&g)
|
||||
{
|
||||
rebuild.push(g);
|
||||
}
|
||||
}
|
||||
if let Spot::Source(g) = to
|
||||
&& from.iter().any(|f| *f != to)
|
||||
&& !rebuild.contains(&g)
|
||||
{
|
||||
rebuild.push(g);
|
||||
}
|
||||
let entering: Vec<NodeId> = rows.iter().zip(&from).filter(|(_, f)| **f != to).map(|(r, _)| *r).collect();
|
||||
let join = match to {
|
||||
Spot::In(g) if !entering.is_empty() => Some((g, from.iter().map(|f| *f != to).collect())),
|
||||
_ => None,
|
||||
};
|
||||
if to != Spot::Outside {
|
||||
check_live_paint_takes(d, &entering)?;
|
||||
}
|
||||
let keep_sources = match to {
|
||||
Spot::In(g) => d.node(g).and_then(b::sources).map(|s| (g, s.id)),
|
||||
_ => None,
|
||||
};
|
||||
Ok(Self { join, keep_sources, rebuild })
|
||||
}
|
||||
|
||||
/// Whether rows join a Live Paint group, which makes the move a "Merge Live Paint" step.
|
||||
pub(crate) fn joins(&self) -> bool {
|
||||
self.join.is_some()
|
||||
}
|
||||
|
||||
/// After the rows were moved, now `moved` (in the order [`LivePaintMove::plan`] took them),
|
||||
/// make the faces and edges of the groups whose paths changed again, and add the rows that
|
||||
/// joined a group to it. → `moved` with the joined rows replaced by their group, once, and
|
||||
/// without the faces and edges that were made again.
|
||||
pub(crate) fn finish(self, d: &mut Document, sel: &mut Selection, moved: &[NodeId]) -> Result<Vec<NodeId>> {
|
||||
// A moved object named like the sources group may now sit before it, where a lookup by name
|
||||
// finds the object first. The group's own sources group goes back in front.
|
||||
if let Some((g, src)) = self.keep_sources {
|
||||
let ch = d.children_mut(Some(g))?;
|
||||
if let Some(at) = ch.iter().position(|c| c.id == src)
|
||||
&& ch[..at].iter().any(|c| c.name.as_deref() == Some(SOURCES_NAME))
|
||||
{
|
||||
let s = ch.remove(at);
|
||||
ch.insert(0, s);
|
||||
}
|
||||
}
|
||||
if self.join.is_none() && self.rebuild.is_empty() {
|
||||
return Ok(moved.to_vec());
|
||||
}
|
||||
// The group the rows join is made again by the merge below, from its paths as they are now
|
||||
// and with the paint of its faces and edges as they were before the move.
|
||||
let join_group = self.join.as_ref().map(|(g, _)| *g);
|
||||
// A Live Paint group among another group's paths gives that group its faces and edges, so
|
||||
// the groups holding a changed group among their paths are made again too, innermost first.
|
||||
let mut groups: Vec<NodeId> = vec![];
|
||||
for g in self.rebuild.iter().copied().chain(join_group) {
|
||||
for x in std::iter::once(g).chain(enclosing_live_paints(d, g)) {
|
||||
if !groups.contains(&x) {
|
||||
groups.push(x);
|
||||
}
|
||||
}
|
||||
}
|
||||
groups.sort_by_cached_key(|g| std::cmp::Reverse(d.ancestry(*g).map_or(0, |a| a.len())));
|
||||
let joined: Vec<NodeId> = match &self.join {
|
||||
Some((_, mask)) => moved.iter().zip(mask).filter(|(_, j)| **j).map(|(r, _)| *r).collect(),
|
||||
None => vec![],
|
||||
};
|
||||
for g in groups {
|
||||
if Some(g) == join_group {
|
||||
let roots: Vec<NodeId> = std::iter::once(g).chain(joined.iter().copied()).collect();
|
||||
merge_live(d, sel, &roots)?;
|
||||
} else if d.node(g).is_some() {
|
||||
rebuild_paths(d, g)?;
|
||||
}
|
||||
}
|
||||
let Some((g, mask)) = self.join else { return Ok(moved.iter().copied().filter(|r| d.node(*r).is_some()).collect()) };
|
||||
// `moved` holds each row once, so only the group can come twice. Faces and edges of the
|
||||
// group moved along with the joining rows were made again, so they are left out.
|
||||
let mut out = vec![];
|
||||
let mut listed = false;
|
||||
for (r, j) in moved.iter().zip(&mask) {
|
||||
if *j {
|
||||
if !listed {
|
||||
out.push(g);
|
||||
listed = true;
|
||||
}
|
||||
} else if d.node(*r).is_some() {
|
||||
out.push(*r);
|
||||
}
|
||||
}
|
||||
Ok(out)
|
||||
}
|
||||
}
|
||||
|
||||
/// Make Live Paint group `g`'s faces and edges again from the paths its sources group holds now,
|
||||
/// with its Gap Options, carrying over the paint of the faces and edges that stay. With no path
|
||||
/// left, the group keeps its sources group and its other children, and has no faces or edges.
|
||||
fn rebuild_paths(d: &mut Document, g: NodeId) -> Result<()> {
|
||||
let old = d.node(g).cloned().ok_or(EngineError::NoNode(g))?;
|
||||
let sources = source_nodes(&old);
|
||||
let mut n = old.clone();
|
||||
if source_shapes(&sources).0.is_empty() {
|
||||
let src = b::sources(&old).cloned().ok_or(EngineError::NoNode(g))?;
|
||||
set_parts(&mut n, vec![src], &[]);
|
||||
} else {
|
||||
let (children, _, _) = build_children(d, sources, old.gap_options().max_gap())?;
|
||||
set_parts(&mut n, children, &[]);
|
||||
repaint_from(&mut n, &old);
|
||||
}
|
||||
let mut changed = Beside::replacing(d, &[g]);
|
||||
changed.put(d, g, vec![n])?;
|
||||
changed.finish(d)
|
||||
}
|
||||
|
||||
fn live_targets(s: &Session, p: &Value) -> Result<Vec<NodeId>> {
|
||||
let d = &s.doc()?.doc;
|
||||
let ids = root_ids(s, p)?;
|
||||
|
||||
@@ -1611,6 +1611,7 @@ fn paste_clip(s: &mut Session, p: &Value, mode: PasteMode, clip: &Clipboard, cho
|
||||
}
|
||||
} else {
|
||||
super::object::keep_pixel_aligned(&mut c, sc);
|
||||
super::buildcmds::clear_part_name(d, par, &mut c);
|
||||
new_ids.push(d.insert(par, idx, c)?);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ use serde_json::{Value, json};
|
||||
use vectorcraft_doc::{Artboard, ArtboardSide, Document, LAYER_COLORS, LayerColor, Node, NodeId, NodeKind, Scaling};
|
||||
use vectorcraft_geom::{Affine, Rect};
|
||||
|
||||
use super::buildcmds::LivePaintMove;
|
||||
use super::{
|
||||
CommandSpec, Result, Session, bad, bool_or, check_numbers, check_switches, checked_id, checked_ids_param, checked_node, checked_nodes_param, cmd,
|
||||
color_value, f64_or, has_doc, has_selection, ids_param, index, object_param, ok, str_param, switch_or,
|
||||
@@ -83,7 +84,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Layer Options…",
|
||||
["Window", "Layers"],
|
||||
None,
|
||||
"{ids?|id? (default: the highlighted rows, else the current layer), name? (with prefs.identifyObjectsBy xmlId: a valid XML ID, stored as the object name), visible?, locked?, template?, printable?, preview?, dimImages?: 0..100|false, color?: index 0..26|\"#rrggbb\"|preset name (a hex color with an alpha part, #rrggbbaa or #rgba, is an error)} Layer Options; rows that are not layers take name, visible and locked, and `ids` may name ruler guides (their `guide.list` id), which hide or lock on their own. Template on also locks the layer and dims its images to 50% (unless given); off unlocks it and stops dimming. One undo step",
|
||||
"{ids?|id? (default: the highlighted rows, else the current layer), name? (with prefs.identifyObjectsBy xmlId: a valid XML ID, stored as the object name), visible?, locked?, template?, printable?, preview?, dimImages?: 0..100|false, color?: index 0..26|\"#rrggbb\"|preset name (a hex color with an alpha part, #rrggbbaa or #rgba, is an error)} Layer Options; rows that are not layers take name, visible and locked, and `ids` may name ruler guides (their `guide.list` id), which hide or lock on their own. Template on also locks the layer and dims its images to 50% (unless given); off unlocks it and stops dimming. A path directly in a Live Paint group can't take the name Face or Edge, which name the group's faces and edges, unless it has it already. One undo step",
|
||||
has_doc,
|
||||
set_props
|
||||
),
|
||||
@@ -110,7 +111,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Move Rows",
|
||||
[],
|
||||
None,
|
||||
"{ids|id, target, place?: \"above\"|\"below\"|\"inside\" (default inside), copy?: bool} drag rows in the Layers panel: above or below the target row (beside it, in its layer or group), or inside a layer, group or Intertwine group (on top of its contents). Layers go only in layers or at the top level, objects in layers, groups and Intertwine groups; an object placed beside a top-level layer goes inside it. An object placed in an Intertwine group becomes a member drawn in its row's order, with no arranged areas, and one placed in a group that is a member becomes part of that member; one that is or holds an Intertwine group, a Repeat, a graph or a Live Paint group is refused. A member moved out of its Intertwine group drops its arranged areas, and a group left with one member is replaced by that member, or becomes a plain group of it when the group has an opacity, blending, appearance, mask, lock or hidden state of its own (with no member, it is removed). A row never goes into itself; a locked layer or group takes nothing. `copy` (Alt-drag) moves copies, which may also go above or below a row they copy (the target among `ids`). Every selected object left hidden or locked, such as one moved into a hidden layer or group, is deselected (the key object too). One undo step → {ids}",
|
||||
"{ids|id, target, place?: \"above\"|\"below\"|\"inside\" (default inside), copy?: bool} drag rows in the Layers panel: above or below the target row (beside it, in its layer or group), or inside a layer, group or Intertwine group (on top of its contents). Layers go only in layers or at the top level, objects in layers, groups and Intertwine groups; an object placed beside a top-level layer goes inside it. An object placed in an Intertwine group becomes a member drawn in its row's order, with no arranged areas, and one placed in a group that is a member becomes part of that member; one that is or holds an Intertwine group, a Repeat, a graph or a Live Paint group is refused. A member moved out of its Intertwine group drops its arranged areas, and a group left with one member is replaced by that member, or becomes a plain group of it when the group has an opacity, blending, appearance, mask, lock or hidden state of its own (with no member, it is removed). A row never goes into itself; a locked layer or group takes nothing. `copy` (Alt-drag) moves copies, which may also go above or below a row they copy (the target among `ids`). A row that goes into a Live Paint group from elsewhere joins its paths as livePaint.merge adds them, and the group is selected (paths, compound paths, groups of them and Live Paint groups; anything else is refused and nothing moves); a row that goes into or leaves a Live Paint group's paths makes the group's faces and edges again, keeping the paint of those that stay. Every selected object left hidden or locked, such as one moved into a hidden layer or group, is deselected (the key object too). One undo step → {ids} (a row that joined a Live Paint group is listed as the group)",
|
||||
has_doc,
|
||||
move_rows
|
||||
),
|
||||
@@ -119,7 +120,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Reorder",
|
||||
[],
|
||||
None,
|
||||
"{id, parent?: id (null = top level), index} put a row at `index` (0 = bottom) of `parent` (layers only at the top level or in layers; an Intertwine group takes and gives up members as layer.move does), deselecting every selected object left hidden or locked (the key object too)",
|
||||
"{id, parent?: id (null = top level), index} put a row at `index` (0 = bottom) of `parent` (layers only at the top level or in layers; an Intertwine group takes and gives up members as layer.move does), deselecting every selected object left hidden or locked (the key object too); a Live Paint group or its paths take a row as layer.move does",
|
||||
has_doc,
|
||||
move_node
|
||||
),
|
||||
@@ -651,6 +652,10 @@ fn set_props(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
if ids.is_empty() {
|
||||
return Err(bad(C, "no rows"));
|
||||
}
|
||||
if let Some(v) = str_param(p, "name").filter(|v| !v.trim().is_empty()) {
|
||||
let name = if xml_id { vectorcraft_doc::xml_id::to_object_name(v) } else { v.to_string() };
|
||||
super::buildcmds::check_part_name(&s.doc()?.doc, &ids, &name)?;
|
||||
}
|
||||
s.edit("Layer Options", |d, sel| {
|
||||
for id in &ids {
|
||||
apply_options(d.node_mut(*id).ok_or(EngineError::NoNode(*id))?, p, xml_id);
|
||||
@@ -807,7 +812,15 @@ fn move_rows(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
if parent.is_some_and(|p| locked_within(d, p)) {
|
||||
return Err(EngineError::Other("the layer or group is locked".into()));
|
||||
}
|
||||
let label = if copy { "Duplicate Rows" } else { "Move Rows" };
|
||||
// Rows that go into a Live Paint group join its paths, as Live Paint › Merge adds them.
|
||||
let live_paint = LivePaintMove::plan(d, &ids, parent, copy)?;
|
||||
let label = if live_paint.joins() {
|
||||
"Merge Live Paint"
|
||||
} else if copy {
|
||||
"Duplicate Rows"
|
||||
} else {
|
||||
"Move Rows"
|
||||
};
|
||||
// Where each moved row comes from (a copy has a new id, so it comes from nowhere), and the
|
||||
// Intertwine groups it leaves.
|
||||
let from: std::collections::HashMap<NodeId, Option<NodeId>> = ids.iter().map(|i| (*i, d.parent_of(*i))).collect();
|
||||
@@ -848,6 +861,7 @@ fn move_rows(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
}
|
||||
let placed: Vec<(NodeId, Option<NodeId>)> = out.iter().map(|o| (*o, from.get(o).copied().flatten())).collect();
|
||||
super::intertwine::settle_members(d, &placed, &left)?;
|
||||
let out = live_paint.finish(d, sel, &out)?;
|
||||
sel.prune(d);
|
||||
sel.deselect_uneditable(d);
|
||||
Ok(out)
|
||||
@@ -870,11 +884,14 @@ fn move_node(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
if let Some(what) = super::intertwine::refused_in(d, parent, n) {
|
||||
return Err(bad(C, format!("{what} can't be intertwined")));
|
||||
}
|
||||
let live_paint = LivePaintMove::plan(d, &[id], parent, false)?;
|
||||
let label = if live_paint.joins() { "Merge Live Paint" } else { "Reorder" };
|
||||
let from = d.parent_of(id);
|
||||
let left = super::intertwine::groups_of(d, &[id]);
|
||||
s.edit("Reorder", |d, sel| {
|
||||
s.edit(label, |d, sel| {
|
||||
d.move_node(id, parent, index)?;
|
||||
super::intertwine::settle_members(d, &[(id, from)], &left)?;
|
||||
live_paint.finish(d, sel, &[id])?;
|
||||
sel.prune(d);
|
||||
sel.deselect_uneditable(d);
|
||||
Ok(())
|
||||
|
||||
@@ -371,16 +371,21 @@ pub(super) fn isolate(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
}
|
||||
|
||||
/// Leaving isolation mode in `isolated` for `next` (None: out of isolation mode) adds the paths drawn
|
||||
/// in the Live Paint group isolation put new art in to that group, as `livePaint.merge` does, in one
|
||||
/// undo step ([`crate::cmd::buildcmds::merge_drawn_in_isolation`]), unless `next` is that group or is
|
||||
/// inside it; → the group when paths were added.
|
||||
/// in each Live Paint group that is `isolated` or holds it to that group, as `livePaint.merge` does,
|
||||
/// innermost group first, one undo step per group ([`crate::cmd::buildcmds::merge_drawn_in_isolation`]).
|
||||
/// A group that `next` is or is inside is skipped, since isolation stays in it. → the outermost group
|
||||
/// that paths were added to.
|
||||
fn add_drawn_live_paint(s: &mut Session, isolated: NodeId, next: Option<NodeId>) -> Result<Option<NodeId>> {
|
||||
let d = &s.doc()?.doc;
|
||||
let Some(g) = crate::cmd::buildcmds::isolated_live_paint(d, isolated) else { return Ok(None) };
|
||||
if next.is_some_and(|n| d.ancestry(n).is_some_and(|a| a.contains(&g))) {
|
||||
return Ok(None);
|
||||
let stays = next.and_then(|n| d.ancestry(n)).unwrap_or_default();
|
||||
let left: Vec<NodeId> = crate::cmd::buildcmds::isolated_live_paints(d, isolated).into_iter().filter(|g| !stays.contains(g)).collect();
|
||||
let mut added = None;
|
||||
for g in left {
|
||||
if crate::cmd::buildcmds::merge_drawn_in_isolation(s, g)? {
|
||||
added = Some(g);
|
||||
}
|
||||
}
|
||||
Ok(crate::cmd::buildcmds::merge_drawn_in_isolation(s, g)?.then_some(g))
|
||||
Ok(added)
|
||||
}
|
||||
|
||||
pub(super) fn exit_isolation(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
|
||||
@@ -250,7 +250,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Exit Isolation Mode",
|
||||
[],
|
||||
None,
|
||||
"{all?: bool (default false)} leave isolation mode; from an isolated sublayer, go up one level to its parent layer instead (the next call goes up again), unless all is true or the parent layer is hidden or locked; no undo step for the move up; while a symbol is edited, a group isolated in its art goes back to the symbol's layer first, with or without all; leaving an isolated Live Paint group adds the paths, compound paths and groups of them drawn in it (shown and unlocked with everything in them) to the group as livePaint.merge does, in one undo step, and leaves type, images and other objects in it as they are; object.isolate on a level outside the group does the same",
|
||||
"{all?: bool (default false)} leave isolation mode; from an isolated sublayer, go up one level to its parent layer instead (the next call goes up again), unless all is true or the parent layer is hidden or locked; no undo step for the move up; while a symbol is edited, a group isolated in its art goes back to the symbol's layer first, with or without all; leaving an isolated Live Paint group adds the paths, compound paths and groups of them drawn in it (shown and unlocked with everything in them) to the group as livePaint.merge does, in one undo step, and leaves type, images and other objects in it as they are; object.isolate on a level outside the group does the same. Leaving a Live Paint group drawn in another isolated Live Paint group, and that group too, does this for each, innermost first, one undo step each",
|
||||
has_doc,
|
||||
exit_isolation
|
||||
),
|
||||
@@ -259,7 +259,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Object Properties",
|
||||
[],
|
||||
None,
|
||||
"{ids?|id?, name?, visible?, locked? (visible: false or locked: true deselects every selected object hidden or locked after the call, the key object included), opacity?: 0..100, blend?: \"Multiply\"…, isolate?, knockout?: \"on\"|\"off\"|\"neutral\"|bool (true = on, false = neutral), knockoutShape?: bool, data?: {key: \"value\" | null (removes it)} (the object's own data, SVG data-* attributes: {pivot: \"100,180\"} is data-pivot; document.node → attrs.data)}. On a path directly in a graph series, the graph also stores the object's opacity and blend mode, and on a series group the group's opacity, blend mode, isolate, knockout and knockoutShape (exceptions: docs/mcp.md); on a graph label, or a graph's axis line, tick mark or radar ring, the graph stores that object's opacity and blend mode for every label or line of its kind",
|
||||
"{ids?|id?, name?, visible?, locked? (visible: false or locked: true deselects every selected object hidden or locked after the call, the key object included), opacity?: 0..100, blend?: \"Multiply\"…, isolate?, knockout?: \"on\"|\"off\"|\"neutral\"|bool (true = on, false = neutral), knockoutShape?: bool, data?: {key: \"value\" | null (removes it)} (the object's own data, SVG data-* attributes: {pivot: \"100,180\"} is data-pivot; document.node → attrs.data)}. On a path directly in a graph series, the graph also stores the object's opacity and blend mode, and on a series group the group's opacity, blend mode, isolate, knockout and knockoutShape (exceptions: docs/mcp.md); on a graph label, or a graph's axis line, tick mark or radar ring, the graph stores that object's opacity and blend mode for every label or line of its kind. A path directly in a Live Paint group can't take the name Face or Edge, which name the group's faces and edges, unless it has it already",
|
||||
has_doc,
|
||||
set_props
|
||||
),
|
||||
|
||||
@@ -65,6 +65,9 @@ pub(super) fn set_props(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
})
|
||||
};
|
||||
let d = &s.doc()?.doc;
|
||||
if let Some(v) = str_param(p, "name") {
|
||||
crate::cmd::buildcmds::check_part_name(d, &ids, v)?;
|
||||
}
|
||||
// A graph keeps the object opacity and blend mode set on a mark of a series for the whole series, and set on a label
|
||||
// for its kind of label, so a value a mark or label already has still replaces the one another left on the graph.
|
||||
let transparency = opacity.is_some() || blend.is_some();
|
||||
|
||||
Reference in New Issue
Block a user