use super::ffi;
use super::solid::Solid;
#[cfg(feature = "color")]
use crate::common::color::Color;
pub(crate) struct CompoundShape {
inner: cxx::UniquePtr<ffi::TopoDS_Shape>,
#[cfg(feature = "color")]
colormap: std::collections::HashMap<u64, Color>,
history: Vec<u64>,
}
impl CompoundShape {
pub fn new<'a>(solids: impl IntoIterator<Item = &'a Solid>) -> Self {
let mut inner = ffi::make_empty();
#[cfg(feature = "color")]
let mut colormap = std::collections::HashMap::new();
for s in solids {
ffi::compound_add(inner.pin_mut(), s.inner());
#[cfg(feature = "color")]
colormap.extend(s.colormap().iter().map(|(&k, &v)| (k, v)));
}
CompoundShape {
inner,
#[cfg(feature = "color")]
colormap,
history: Default::default(),
}
}
pub fn from_raw(
inner: cxx::UniquePtr<ffi::TopoDS_Shape>,
#[cfg(feature = "color")] colormap: std::collections::HashMap<u64, Color>,
history: Vec<u64>,
) -> Self {
CompoundShape {
inner,
#[cfg(feature = "color")]
colormap,
history,
}
}
pub fn inner(&self) -> &ffi::TopoDS_Shape {
&self.inner
}
#[cfg(feature = "color")]
pub fn colormap(&self) -> &std::collections::HashMap<u64, Color> {
&self.colormap
}
pub fn decompose(self) -> Vec<Solid> {
let solid_shapes = ffi::decompose_into_solids(&self.inner);
solid_shapes
.iter()
.map(|s| {
Solid::new(
ffi::clone_shape_handle(s),
#[cfg(feature = "color")]
self.colormap.clone(),
self.history.clone(),
)
})
.collect()
}
}