use crate::atoms::NodeId;
use crate::coords::Coords;
use crate::handle::Handle;
use crate::py::node::PyNode;
use pyo3::prelude::*;
#[cfg_attr(feature = "stub-gen", pyo3_stub_gen::derive::gen_stub_pyclass)]
#[pyclass(name = "Coords")]
pub struct PyCoords {
pub(crate) handle: Handle<Coords>,
}
#[cfg_attr(feature = "stub-gen", pyo3_stub_gen::derive::gen_stub_pymethods)]
#[pymethods]
impl PyCoords {
#[new]
fn py_new(dim: u8) -> PyResult<Self> {
let coords = Coords::new(dim)?;
Ok(Self {
handle: Handle::new(coords),
})
}
#[classmethod]
fn axisymmetric(_cls: &pyo3::Bound<'_, pyo3::types::PyType>) -> PyResult<Self> {
Ok(Self {
handle: Handle::new(Coords::axisymmetric()?),
})
}
#[getter]
fn dim(&self) -> u8 {
self.handle.read().dim()
}
#[getter]
fn is_axisymmetric(&self) -> bool {
self.handle.read().is_axisymmetric()
}
fn node_count(&self) -> usize {
self.handle.read().node_count()
}
fn capacity(&self) -> usize {
self.handle.read().capacity()
}
fn is_alive(&self, id: u32) -> bool {
self.handle.read().is_alive(NodeId(id))
}
fn add_node(&self, coords: Vec<f64>) -> PyResult<PyNode> {
let id = self.handle.write().add_node(&coords)?;
Ok(PyNode::from_raw(self.handle.clone(), id))
}
fn acquire(&self, id: u32) -> PyResult<PyNode> {
self.handle.write().incref(NodeId(id))?;
Ok(PyNode::from_raw(self.handle.clone(), NodeId(id)))
}
fn refcount(&self, id: u32) -> u32 {
self.handle.read().refcount(NodeId(id))
}
fn gc(&self) -> usize {
self.handle.write().gc()
}
fn add_config(&self, name: String) -> usize {
self.handle.write().add_config(name)
}
fn select(&self, config: usize) -> PyResult<()> {
self.handle.write().select(config)?;
Ok(())
}
#[getter]
fn active(&self) -> usize {
self.handle.read().active()
}
fn names(&self) -> Vec<String> {
self.handle.read().names().to_vec()
}
fn permutation(&self) -> Option<Vec<u32>> {
self.handle.read().permutation().map(|s| s.to_vec())
}
fn set_permutation(&self, perm: Vec<u32>) -> PyResult<()> {
self.handle.write().set_permutation(perm)?;
Ok(())
}
fn clear_permutation(&self) {
self.handle.write().clear_permutation();
}
}
crate::impl_dump_pymethod!(handle PyCoords, handle);