use crate::{with_context, with_context_mut};
pub fn create_group(name: impl Into<String>) -> GroupHandle {
let name = name.into();
with_context_mut(|ctx| {
ctx.create_group(&name);
});
GroupHandle { name }
}
#[must_use]
pub fn get_group(name: &str) -> Option<GroupHandle> {
with_context(|ctx| {
if ctx.has_group(name) {
Some(GroupHandle {
name: name.to_string(),
})
} else {
None
}
})
}
pub fn remove_group(name: &str) {
with_context_mut(|ctx| {
ctx.remove_group(name);
});
}
pub fn remove_all_groups() {
with_context_mut(|ctx| {
ctx.groups.clear();
});
}
#[must_use]
pub fn get_all_groups() -> Vec<String> {
with_context(|ctx| {
ctx.group_names()
.into_iter()
.map(std::string::ToString::to_string)
.collect()
})
}
#[derive(Clone)]
pub struct GroupHandle {
name: String,
}
impl GroupHandle {
#[must_use]
pub fn name(&self) -> &str {
&self.name
}
pub fn set_enabled(&self, enabled: bool) -> &Self {
with_context_mut(|ctx| {
if let Some(group) = ctx.get_group_mut(&self.name) {
group.set_enabled(enabled);
}
});
self
}
#[must_use]
pub fn is_enabled(&self) -> bool {
with_context(|ctx| {
ctx.get_group(&self.name)
.is_some_and(polyscope_core::Group::is_enabled)
})
}
pub fn set_show_child_details(&self, show: bool) -> &Self {
with_context_mut(|ctx| {
if let Some(group) = ctx.get_group_mut(&self.name) {
group.set_show_child_details(show);
}
});
self
}
pub fn add_point_cloud(&self, pc_name: &str) -> &Self {
with_context_mut(|ctx| {
if let Some(group) = ctx.get_group_mut(&self.name) {
group.add_structure("PointCloud", pc_name);
}
});
self
}
pub fn add_surface_mesh(&self, mesh_name: &str) -> &Self {
with_context_mut(|ctx| {
if let Some(group) = ctx.get_group_mut(&self.name) {
group.add_structure("SurfaceMesh", mesh_name);
}
});
self
}
pub fn add_curve_network(&self, cn_name: &str) -> &Self {
with_context_mut(|ctx| {
if let Some(group) = ctx.get_group_mut(&self.name) {
group.add_structure("CurveNetwork", cn_name);
}
});
self
}
pub fn add_volume_mesh(&self, vm_name: &str) -> &Self {
with_context_mut(|ctx| {
if let Some(group) = ctx.get_group_mut(&self.name) {
group.add_structure("VolumeMesh", vm_name);
}
});
self
}
pub fn add_volume_grid(&self, vg_name: &str) -> &Self {
with_context_mut(|ctx| {
if let Some(group) = ctx.get_group_mut(&self.name) {
group.add_structure("VolumeGrid", vg_name);
}
});
self
}
pub fn add_camera_view(&self, cv_name: &str) -> &Self {
with_context_mut(|ctx| {
if let Some(group) = ctx.get_group_mut(&self.name) {
group.add_structure("CameraView", cv_name);
}
});
self
}
pub fn remove_structure(&self, type_name: &str, name: &str) -> &Self {
with_context_mut(|ctx| {
if let Some(group) = ctx.get_group_mut(&self.name) {
group.remove_structure(type_name, name);
}
});
self
}
pub fn add_child_group(&self, child_name: &str) -> &Self {
with_context_mut(|ctx| {
if let Some(child) = ctx.get_group_mut(child_name) {
child.set_parent_group(Some(self.name.clone()));
}
if let Some(group) = ctx.get_group_mut(&self.name) {
group.add_child_group(child_name);
}
});
self
}
pub fn remove_child_group(&self, child_name: &str) -> &Self {
with_context_mut(|ctx| {
if let Some(child) = ctx.get_group_mut(child_name) {
child.set_parent_group(None);
}
if let Some(group) = ctx.get_group_mut(&self.name) {
group.remove_child_group(child_name);
}
});
self
}
#[must_use]
pub fn num_structures(&self) -> usize {
with_context(|ctx| {
ctx.get_group(&self.name)
.map_or(0, polyscope_core::Group::num_child_structures)
})
}
#[must_use]
pub fn num_child_groups(&self) -> usize {
with_context(|ctx| {
ctx.get_group(&self.name)
.map_or(0, polyscope_core::Group::num_child_groups)
})
}
}