use std::collections::BTreeMap;
use serde::{Deserialize, Serialize};
use crate::core::ids::{
BindingId, EdgeId, GraphId, GroupId, NodeId, PortId, StickyNoteId, SymbolId,
};
use crate::core::imports::GraphImport;
use super::binding::Binding;
use super::edge::Edge;
use super::node::Node;
use super::port::Port;
use super::resources::{Group, StickyNote, Symbol};
pub const GRAPH_VERSION: u32 = 1;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Graph {
pub graph_id: GraphId,
pub graph_version: u32,
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub imports: BTreeMap<GraphId, GraphImport>,
pub symbols: BTreeMap<SymbolId, Symbol>,
pub nodes: BTreeMap<NodeId, Node>,
pub ports: BTreeMap<PortId, Port>,
pub edges: BTreeMap<EdgeId, Edge>,
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub groups: BTreeMap<GroupId, Group>,
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub sticky_notes: BTreeMap<StickyNoteId, StickyNote>,
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub bindings: BTreeMap<BindingId, Binding>,
}
impl Default for Graph {
fn default() -> Self {
Self::new(GraphId::new())
}
}
impl Graph {
pub fn new(graph_id: GraphId) -> Self {
Self {
graph_id,
graph_version: GRAPH_VERSION,
imports: BTreeMap::new(),
symbols: BTreeMap::new(),
nodes: BTreeMap::new(),
ports: BTreeMap::new(),
edges: BTreeMap::new(),
groups: BTreeMap::new(),
sticky_notes: BTreeMap::new(),
bindings: BTreeMap::new(),
}
}
}