use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use crate::design::{
ActEntity, ActGuid, ActRootComponent, ConstructionRecipe, DesignBodyMember, DesignEntityHeader,
DesignMaterialAssignment, DesignObject, DesignRecordHeader, LostEdgeReference,
PersistentDesignLink, PersistentReference, SketchCurveIdentity, SketchCurveLink, SketchPoint,
SketchRelation,
};
use crate::history::AsmHistory;
pub const F3D_NATIVE_VERSION: u32 = 1;
macro_rules! f3d_arenas {
($macro:ident) => {
$macro! {
act_entities: ActEntity;
act_guids: ActGuid;
act_root_components: ActRootComponent;
design_objects: DesignObject;
design_entity_headers: DesignEntityHeader;
design_record_headers: DesignRecordHeader;
design_body_members: DesignBodyMember;
design_material_assignments: DesignMaterialAssignment;
construction_recipes: ConstructionRecipe;
persistent_design_links: PersistentDesignLink;
persistent_references: PersistentReference;
sketch_curve_links: SketchCurveLink;
sketch_relations: SketchRelation;
sketch_points: SketchPoint;
sketch_curve_identities: SketchCurveIdentity;
lost_edge_references: LostEdgeReference;
asm_histories: AsmHistory;
}
};
}
pub(crate) use f3d_arenas;
macro_rules! sort_f3d_arenas {
($($field:ident: $ty:ty;)*) => {
impl F3dNative {
pub(crate) fn finalize(&mut self) {
$(self.$field.sort_by(|left, right| left.id.cmp(&right.id));)*
}
}
};
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
pub struct F3dNative {
pub version: u32,
#[serde(default)]
pub act_entities: Vec<ActEntity>,
#[serde(default)]
pub act_guids: Vec<ActGuid>,
#[serde(default)]
pub act_root_components: Vec<ActRootComponent>,
#[serde(default)]
pub design_objects: Vec<DesignObject>,
#[serde(default)]
pub design_entity_headers: Vec<DesignEntityHeader>,
#[serde(default)]
pub design_record_headers: Vec<DesignRecordHeader>,
#[serde(default)]
pub design_body_members: Vec<DesignBodyMember>,
#[serde(default)]
pub design_material_assignments: Vec<DesignMaterialAssignment>,
#[serde(default)]
pub construction_recipes: Vec<ConstructionRecipe>,
#[serde(default)]
pub persistent_design_links: Vec<PersistentDesignLink>,
#[serde(default)]
pub persistent_references: Vec<PersistentReference>,
#[serde(default)]
pub sketch_curve_links: Vec<SketchCurveLink>,
#[serde(default)]
pub sketch_relations: Vec<SketchRelation>,
#[serde(default)]
pub sketch_points: Vec<SketchPoint>,
#[serde(default)]
pub sketch_curve_identities: Vec<SketchCurveIdentity>,
#[serde(default)]
pub lost_edge_references: Vec<LostEdgeReference>,
#[serde(default)]
pub asm_histories: Vec<AsmHistory>,
}
impl Default for F3dNative {
fn default() -> Self {
Self {
version: F3D_NATIVE_VERSION,
act_entities: Vec::new(),
act_guids: Vec::new(),
act_root_components: Vec::new(),
design_objects: Vec::new(),
design_entity_headers: Vec::new(),
design_record_headers: Vec::new(),
design_body_members: Vec::new(),
design_material_assignments: Vec::new(),
construction_recipes: Vec::new(),
persistent_design_links: Vec::new(),
persistent_references: Vec::new(),
sketch_curve_links: Vec::new(),
sketch_relations: Vec::new(),
sketch_points: Vec::new(),
sketch_curve_identities: Vec::new(),
lost_edge_references: Vec::new(),
asm_histories: Vec::new(),
}
}
}
f3d_arenas!(sort_f3d_arenas);