use molframe_core::ExecutionContext;
use molframe_core::MemoryBudgetError;
use molframe_core::diagnostic::Diagnostic;
use molframe_core::index::ChainIndex;
use molframe_core::structure::{
CoordinateEditor, Structure as CoreStructure, StructureEditor as CoreEditor,
};
use super::handle::Structure;
use super::selection::Selection;
#[derive(Debug)]
pub struct StructureEditor {
base: CoreStructure,
overlay: CoreEditor,
}
impl StructureEditor {
pub fn set_annotation(
&mut self,
name: &str,
column: molframe_core::annotation::AtomAnnotation,
) -> Result<(), Diagnostic> {
self.overlay.set_annotation(name, column)
}
pub(super) fn new(base: &CoreStructure) -> Self {
Self {
base: base.clone(),
overlay: base.edit(),
}
}
pub fn delete(&mut self, selection: &Selection) -> Result<(), Diagnostic> {
self.overlay.delete_atoms(selection.atom_selection())
}
pub fn clear_extensions(&mut self) {
self.overlay.clear_extensions();
}
pub fn rename_chain(&mut self, chain: ChainIndex, label: &str) -> Result<(), Diagnostic> {
self.overlay.rename_chain(chain, label)
}
pub fn coordinates(
&self,
context: &ExecutionContext,
) -> Result<CoordinateEditor, MemoryBudgetError> {
self.base.edit_coordinates(context)
}
pub fn finish(self) -> Result<Structure, Vec<Diagnostic>> {
self.overlay.commit().map(Structure::from)
}
}