use crate::prelude::*;
-use shapelib::OutlineDefnEnum;
-
// At the implementation level, each loaded item contains an
// `Arc<GroupDetails>`, which is simply stored directly. The
// `GroupDefn` is processed.
#[serde(untagged)]
pub enum OutlineDetails {
Full(FullOutlineDetails), // introduced with mformat=2
- Shape(OutlineDefnEnum),
+ Shape(Shape),
}
#[derive(Debug,Deserialize)]
pub struct FullOutlineDetails {
- shape: OutlineDefnEnum,
+ shape: Shape,
#[serde(default)] size: Vec<f64>,
#[serde(default)] scale: Option<f64>,
}
impl OutlineDetails {
// enum_access could perhaps do this but controlling the serde
// would become confusing
- pub fn shape(&self) -> OutlineDefnEnum { match self {
+ pub fn shape(&self) -> Shape { match self {
OutlineDetails::Full(full) => full.shape,
OutlineDetails::Shape(shape) => *shape,
}}
//---------- OutlineDefn etc. ----------
#[ambassador::delegatable_trait]
-pub trait OutlineDefnTrait: Debug + Sync + Send + 'static {
+pub trait ShapeLoadableTrait: Debug + Sync + Send + 'static {
/// Success or failure must not depend on `svg_sz`
///
/// Called to *check* the group configuration before load, but
fn load_mf1(&self, group: &GroupData) -> Result<Outline,LLE>;
}
-// We used to do this via typetag and Box<dyn OutlineDefn>
+// We used to do shape deser via typetag and Box<dyn OutlineDefn>
//
-// But I didnt manage to get typetag to deserialise these unit variants.
-// Instead, we have this enum and a cheesy macro to impl OutlineDefn
-// by delegating to a freshly made (static) unit struct value.
-macro_rules! outline_defns {
- { $( $Shape:ident ),* } => { paste!{
-
- #[derive(Deserialize,Debug,Copy,Clone,Eq,PartialEq)]
- pub enum OutlineDefnEnum {
- $( $Shape, )*
- }
-
- impl OutlineDefnEnum {
- fn defn(self) -> &'static dyn OutlineDefnTrait {
- match self { $(
- Self::$Shape => &[< $Shape Defn >] as _,
- )* }
- }
- }
-
- } }
-}
-
-outline_defns! { Circle, Rect }
+// But I didnt manage to get typetag to deserialise the way I wanted.
+// Instead, we have the Shape enum and a cheesy macro to impl OutlineDefn
+// by delegating to a freshly made (static) unit struct value,
+// - see outline_defn in mod outline in spec.rs.
impl_via_ambassador!{
- impl OutlineDefnTrait for OutlineDefnEnum { defn() }
+ impl ShapeLoadableTrait for Shape { shapelib_loadable() }
}
//---------- RectOutline ----------
}
}
-#[derive(Deserialize,Debug)]
-struct RectDefn;
-impl OutlineDefnTrait for RectDefn {
+impl ShapeLoadableTrait for RectShapeIndicator {
fn load(&self, size: PosC<f64>) -> Outline {
RectOutline { xy: size }.into()
}
}
}
-#[derive(Deserialize,Debug)]
-struct CircleDefn;
-impl OutlineDefnTrait for CircleDefn {
+impl ShapeLoadableTrait for CircleShapeIndicator {
fn load(&self, size: PosC<f64>) -> Outline {
let diam = size
.coords.into_iter()
$( $Shape:ident $serde:literal ;)*
} => { paste!{
$( use crate::shapelib::[< $Shape Outline >]; )*
+
#[dyn_upcast(OutlineTrait)]
#[enum_dispatch(OutlineTrait)]
#[derive(Clone,Debug,Serialize,Deserialize)]
pub enum Outline { $(
#[serde(rename=$serde)] [< $Shape Outline >],
)* }
+
+ #[derive(Deserialize,Debug,Copy,Clone,Eq,PartialEq)]
+ pub enum Shape { $(
+ #[serde(rename=$serde)] [< $Shape >],
+ )* }
+
+ $(
+ #[derive(Deserialize,Debug)]
+ pub struct [< $Shape ShapeIndicator >];
+ )*
+
+ impl Shape {
+ pub fn shapelib_loadable(self)
+ -> &'static dyn shapelib::ShapeLoadableTrait
+ {
+ match self { $(
+ Self::$Shape => &[< $Shape ShapeIndicator >] as _,
+ )* }
+ }
+ }
+
} } }
shape_defns! {