Skip to content

Commit 2bfd332

Browse files
authored
Remove all references to legacy layers (#1523)
* Remove visible field from LegacyLayer * Remove LegacyLayer wrapper around LegacyLayerType * Remove FolderLegacyLayer and LayerLegacyLayer wrappers around their data * Remove legacy layers
1 parent da8214c commit 2bfd332

File tree

26 files changed

+217
-1084
lines changed

26 files changed

+217
-1084
lines changed

document-legacy/src/document.rs

Lines changed: 0 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
use crate::document_metadata::{is_artboard, DocumentMetadata, LayerNodeIdentifier};
2-
use crate::layers::folder_layer::FolderLegacyLayer;
3-
use crate::layers::layer_info::{LegacyLayer, LegacyLayerType};
4-
use crate::DocumentError;
52

63
use graph_craft::document::{DocumentNode, DocumentNodeImplementation, NodeId, NodeNetwork, NodeOutput};
74
use graphene_core::renderer::ClickTarget;
@@ -23,9 +20,6 @@ pub type LayerId = u64;
2320
pub struct Document {
2421
#[serde(default)]
2522
pub document_network: NodeNetwork,
26-
/// The root layer, usually a [FolderLegacyLayer](layers::folder_layer::FolderLegacyLayer) that contains all other [LegacyLayers](layers::layer_info::LegacyLayer).
27-
#[serde(skip)]
28-
pub root: LegacyLayer,
2923
/// The state_identifier serves to provide a way to uniquely identify a particular state that the document is in.
3024
/// This identifier is not a hash and is not guaranteed to be equal for equivalent documents.
3125
#[serde(skip)]
@@ -43,11 +37,6 @@ impl PartialEq for Document {
4337
impl Default for Document {
4438
fn default() -> Self {
4539
Self {
46-
root: LegacyLayer {
47-
name: None,
48-
visible: true,
49-
data: LegacyLayerType::Folder(FolderLegacyLayer::default()),
50-
},
5140
state_identifier: DefaultHasher::new(),
5241
document_network: {
5342
use graph_craft::document::{value::TaggedValue, NodeInput};
@@ -156,100 +145,4 @@ impl Document {
156145
pub fn current_state_identifier(&self) -> u64 {
157146
self.state_identifier.finish()
158147
}
159-
160-
/// Returns a reference to the requested folder. Fails if the path does not exist,
161-
/// or if the requested layer is not of type folder.
162-
pub fn folder(&self, path: impl AsRef<[LayerId]>) -> Result<&FolderLegacyLayer, DocumentError> {
163-
let mut root = &self.root;
164-
for id in path.as_ref() {
165-
root = root.as_folder()?.layer(*id).ok_or_else(|| DocumentError::LayerNotFound(path.as_ref().into()))?;
166-
}
167-
root.as_folder()
168-
}
169-
170-
/// Returns a mutable reference to the requested folder. Fails if the path does not exist,
171-
/// or if the requested layer is not of type folder.
172-
fn folder_mut(&mut self, path: &[LayerId]) -> Result<&mut FolderLegacyLayer, DocumentError> {
173-
let mut root = &mut self.root;
174-
for id in path {
175-
root = root.as_folder_mut()?.layer_mut(*id).ok_or_else(|| DocumentError::LayerNotFound(path.into()))?;
176-
}
177-
root.as_folder_mut()
178-
}
179-
180-
/// Returns a reference to the layer or folder at the path.
181-
pub fn layer(&self, path: &[LayerId]) -> Result<&LegacyLayer, DocumentError> {
182-
if path.is_empty() {
183-
return Ok(&self.root);
184-
}
185-
let (path, id) = split_path(path)?;
186-
self.folder(path)?.layer(id).ok_or_else(|| DocumentError::LayerNotFound(path.into()))
187-
}
188-
189-
/// Returns a mutable reference to the layer or folder at the path.
190-
pub fn layer_mut(&mut self, path: &[LayerId]) -> Result<&mut LegacyLayer, DocumentError> {
191-
if path.is_empty() {
192-
return Ok(&mut self.root);
193-
}
194-
let (path, id) = split_path(path)?;
195-
self.folder_mut(path)?.layer_mut(id).ok_or_else(|| DocumentError::LayerNotFound(path.into()))
196-
}
197-
198-
pub fn common_layer_path_prefix<'a>(&self, layers: impl Iterator<Item = &'a [LayerId]>) -> &'a [LayerId] {
199-
layers.reduce(|a, b| &a[..a.iter().zip(b.iter()).take_while(|&(a, b)| a == b).count()]).unwrap_or_default()
200-
}
201-
202-
/// Returns the shallowest folder given the selection, even if the selection doesn't contain any folders
203-
pub fn shallowest_common_folder<'a>(&self, layers: impl Iterator<Item = &'a [LayerId]>) -> Result<&'a [LayerId], DocumentError> {
204-
let common_prefix_of_path = self.common_layer_path_prefix(layers);
205-
206-
Ok(match self.layer(common_prefix_of_path)?.data {
207-
LegacyLayerType::Folder(_) => common_prefix_of_path,
208-
_ => &common_prefix_of_path[..common_prefix_of_path.len() - 1],
209-
})
210-
}
211-
212-
/// Returns all layers that are not contained in any other of the given folders
213-
/// Takes and Iterator over &[LayerId] or &Vec<LayerId>.
214-
pub fn shallowest_unique_layers<'a, T>(layers: impl Iterator<Item = T>) -> Vec<T>
215-
where
216-
T: AsRef<[LayerId]> + std::cmp::Ord + 'a,
217-
{
218-
let mut sorted_layers: Vec<_> = layers.collect();
219-
sorted_layers.sort();
220-
// Sorting here creates groups of similar UUID paths
221-
sorted_layers.dedup_by(|a, b| a.as_ref().starts_with(b.as_ref()));
222-
sorted_layers
223-
}
224-
225-
/// Given a path to a layer, returns a vector of the indices in the layer tree
226-
/// These indices can be used to order a list of layers
227-
pub fn indices_for_path(&self, path: &[LayerId]) -> Result<Vec<usize>, DocumentError> {
228-
let mut root = self.root.as_folder()?;
229-
let mut indices = vec![];
230-
let (path, layer_id) = split_path(path)?;
231-
232-
// TODO: appears to be n^2? should we maintain a lookup table?
233-
for id in path {
234-
let pos = root.layer_ids.iter().position(|x| *x == *id).ok_or_else(|| DocumentError::LayerNotFound(path.into()))?;
235-
indices.push(pos);
236-
root = match root.layer(*id) {
237-
Some(LegacyLayer {
238-
data: LegacyLayerType::Folder(folder),
239-
..
240-
}) => Some(folder),
241-
_ => None,
242-
}
243-
.ok_or_else(|| DocumentError::LayerNotFound(path.into()))?;
244-
}
245-
246-
indices.push(root.layer_ids.iter().position(|x| *x == layer_id).ok_or_else(|| DocumentError::LayerNotFound(path.into()))?);
247-
248-
Ok(indices)
249-
}
250-
}
251-
252-
fn split_path(path: &[LayerId]) -> Result<(&[LayerId], LayerId), DocumentError> {
253-
let (id, path) = path.split_last().ok_or(DocumentError::InvalidPath)?;
254-
Ok((path, *id))
255148
}

document-legacy/src/document_metadata.rs

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -154,24 +154,20 @@ impl DocumentMetadata {
154154

155155
// selected layer modifications
156156
impl DocumentMetadata {
157-
#[must_use]
158-
pub fn retain_selected_nodes(&mut self, f: impl FnMut(&NodeId) -> bool) -> SelectionChanged {
157+
pub fn retain_selected_nodes(&mut self, f: impl FnMut(&NodeId) -> bool) {
159158
self.selected_nodes.retain(f);
160-
SelectionChanged
161159
}
162-
#[must_use]
163-
pub fn set_selected_nodes(&mut self, new: Vec<NodeId>) -> SelectionChanged {
160+
161+
pub fn set_selected_nodes(&mut self, new: Vec<NodeId>) {
164162
self.selected_nodes = new;
165-
SelectionChanged
166163
}
167-
#[must_use]
168-
pub fn add_selected_nodes(&mut self, iter: impl IntoIterator<Item = NodeId>) -> SelectionChanged {
164+
165+
pub fn add_selected_nodes(&mut self, iter: impl IntoIterator<Item = NodeId>) {
169166
self.selected_nodes.extend(iter);
170-
SelectionChanged
171167
}
172-
#[must_use]
173-
pub fn clear_selected_nodes(&mut self) -> SelectionChanged {
174-
self.set_selected_nodes(Vec::new())
168+
169+
pub fn clear_selected_nodes(&mut self) {
170+
self.set_selected_nodes(Vec::new());
175171
}
176172

177173
/// Loads the structure of layer nodes from a node graph.
@@ -374,8 +370,8 @@ impl LayerNodeIdentifier {
374370
#[track_caller]
375371
pub fn new(node_id: NodeId, network: &NodeNetwork) -> Self {
376372
debug_assert!(
377-
is_layer_node(node_id, network),
378-
"Layer identifier constructed from non layer node {node_id}: {:#?}",
373+
node_id == LayerNodeIdentifier::ROOT.to_node() || network.nodes.get(&node_id).is_some_and(|node| node.is_layer()),
374+
"Layer identifier constructed from non-layer node {node_id}: {:#?}",
379375
network.nodes.get(&node_id)
380376
);
381377
Self::new_unchecked(node_id)
@@ -633,10 +629,6 @@ pub struct NodeRelations {
633629
last_child: Option<LayerNodeIdentifier>,
634630
}
635631

636-
fn is_layer_node(node: NodeId, network: &NodeNetwork) -> bool {
637-
node == LayerNodeIdentifier::ROOT.to_node() || network.nodes.get(&node).is_some_and(|node| node.is_layer())
638-
}
639-
640632
#[test]
641633
fn test_tree() {
642634
let mut document_metadata = DocumentMetadata::default();

document-legacy/src/layers/folder_layer.rs

Lines changed: 0 additions & 27 deletions
This file was deleted.

document-legacy/src/layers/layer_info.rs

Lines changed: 0 additions & 124 deletions
This file was deleted.

document-legacy/src/layers/layer_layer.rs

Lines changed: 0 additions & 11 deletions
This file was deleted.

document-legacy/src/layers/mod.rs

Lines changed: 0 additions & 20 deletions
This file was deleted.

document-legacy/src/lib.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,2 @@
1-
// `macro_use` puts the log macros (`error!`, `warn!`, `debug!`, `info!` and `trace!`) in scope for the crate
2-
// #[macro_use]
3-
extern crate log;
4-
51
pub mod document;
62
pub mod document_metadata;
7-
pub mod layers;
8-
9-
/// A set of different errors that can occur when using this crate.
10-
#[derive(Debug, Clone, PartialEq, Eq)]
11-
pub enum DocumentError {
12-
LayerNotFound(Vec<document::LayerId>),
13-
InvalidPath,
14-
NotFolder,
15-
InvalidFile(String),
16-
}

0 commit comments

Comments
 (0)