use std::collections::{BTreeMap, BTreeSet};
use crate::component::Component;
use crate::component::capability::{Capability, CapabilityRole};
use crate::error::ModelError;
use crate::identity::{CapabilityId, ComponentInstanceId, ComponentTypeId, LinkId, RobotId};
use crate::robot::{Clock, ComponentInstance, KinematicConfig, MotionLimits, Robot};
use crate::simulation::{self, Simulation};
use crate::structure::Structure;
pub struct RobotParts {
pub id: RobotId,
pub clock: Clock,
pub kinematic: KinematicConfig,
pub motion_limits: MotionLimits,
pub component_instances: BTreeMap<ComponentInstanceId, ComponentInstance>,
pub component_types: BTreeMap<ComponentTypeId, Component>,
pub simulation_types: BTreeMap<ComponentTypeId, Simulation>,
pub structure: Structure,
}
pub fn structure(document: serde_json::Value) -> Result<Structure, ModelError> {
Ok(Structure::from_compiler_value(document)?)
}
#[must_use]
pub fn component(
capabilities: BTreeMap<CapabilityId, Capability>,
structure: Structure,
) -> Component {
Component::new(capabilities, structure)
}
#[must_use]
pub fn simulation(
capabilities: BTreeMap<CapabilityId, simulation::Capability>,
links: BTreeMap<LinkId, Option<String>>,
) -> Simulation {
Simulation::new(capabilities, links)
}
#[must_use]
pub fn component_instance(
id: ComponentInstanceId,
component_type: ComponentTypeId,
mount_link: LinkId,
direction_signs: BTreeMap<CapabilityId, i8>,
) -> ComponentInstance {
ComponentInstance::new(
id,
component_type,
mount_link,
direction_signs,
BTreeMap::<CapabilityId, BTreeSet<CapabilityRole>>::new(),
)
}
#[must_use]
pub fn component_instance_with_roles(
id: ComponentInstanceId,
component_type: ComponentTypeId,
mount_link: LinkId,
direction_signs: BTreeMap<CapabilityId, i8>,
roles: BTreeMap<CapabilityId, BTreeSet<CapabilityRole>>,
) -> ComponentInstance {
ComponentInstance::new(id, component_type, mount_link, direction_signs, roles)
}
pub fn robot(parts: RobotParts) -> Result<Robot, ModelError> {
let footprint = crate::footprint::compile(
&parts.structure,
&parts.component_instances,
&parts.component_types,
)?;
Robot::new(parts, footprint)
}