Skip to main content

CombinedLineSymbol

Struct CombinedLineSymbol 

Source
pub struct CombinedLineSymbol {
    pub common: SymbolCommon,
    /* private fields */
}
Expand description

A combined line symbol composed of multiple sub-symbols.

Fields§

§common: SymbolCommon

Common symbol properties.

Implementations§

Source§

impl CombinedLineSymbol

Source

pub fn components( &self, ) -> impl Iterator<Item = &PublicOrPrivateSymbol<WeakLinePathSymbol, Box<LineSymbol>>>

Iterate through the symbol component of the symbol

Examples found in repository?
examples/default_write.rs (line 96)
20fn main() -> Result<(), Error> {
21    #[cfg(feature = "geo_ref")]
22    let mut map = {
23        let proj_center = Coord {
24            x: 463_575.5,
25            y: 6_833_849.6,
26        };
27        let map_center_elevation_meters = 2_469.;
28        let crs_epsg_code = 25832;
29        Omap::default_15_000_geo_referenced(
30            proj_center,
31            CrsType::Epsg(crs_epsg_code),
32            map_center_elevation_meters,
33        )?
34    };
35    #[cfg(not(feature = "geo_ref"))]
36    let mut map = Omap::default_15_000()?;
37
38    for color in map.colors.iter() {
39        match color {
40            Color::SpotColor(ref_cell) => {
41                let b = ref_cell.try_borrow().unwrap();
42                println!("{} with spot name {}", b.color_name, b.spotcolor_name);
43            }
44            Color::MixedColor(ref_cell) => {
45                println!("{}", ref_cell.try_borrow().unwrap().color_name);
46            }
47        }
48    }
49
50    let erosion_gully = map
51        .symbols
52        .get_symbol_by_code(Code::new(107, 0, 0))
53        .unwrap()
54        .downgrade();
55
56    let mut ls = LineObject::new(
57        WeakLinePathSymbol::try_from(erosion_gully).unwrap(),
58        // geometry coordinates are always in mm of paper
59        LineString::new(vec![Coord { x: 0., y: 0. }, Coord { x: 200., y: 100. }]),
60    );
61    ls.tags.insert("Some Key".to_owned(), "My value".to_owned());
62
63    map.parts.0[0].add_object(ls);
64
65    println!("\nCombined Line symbols:");
66    for symbol in map.symbols.iter() {
67        if let Symbol::CombinedLine(s) = symbol {
68            println!("{}", s.borrow().common.name);
69        }
70    }
71    if let Some(s) = map.symbols.get_symbol_by_name("Railway, Olive background") {
72        println!("{s:?}");
73    }
74
75    let mut num = 0;
76    for symbol in map.symbols.iter() {
77        if let Symbol::Line(s) = symbol {
78            let borrowed = s.borrow();
79
80            if let Some(_ss_) = &borrowed.start_symbol {
81                num += 1;
82            }
83            if let Some(_ms_) = &borrowed.mid_symbol {
84                num += 1;
85            }
86            if let Some(_ds_) = &borrowed.dash_symbol {
87                num += 1;
88            }
89            if let Some(_es_) = &borrowed.end_symbol {
90                num += 1;
91            }
92        }
93        if let Symbol::CombinedLine(s) = symbol {
94            let borrowed = s.borrow();
95
96            for part in borrowed.components() {
97                if let PublicOrPrivateSymbol::Private(s) = part {
98                    if let Some(_ss_) = &s.start_symbol {
99                        num += 1;
100                    }
101                    if let Some(_ms_) = &s.mid_symbol {
102                        num += 1;
103                    }
104                    if let Some(_ds_) = &s.dash_symbol {
105                        num += 1;
106                    }
107                    if let Some(_es_) = &s.end_symbol {
108                        num += 1;
109                    }
110                }
111            }
112        }
113    }
114    println!("\nNumber of sub symbols in line symbols: {num}");
115
116    map.write_to_file("./test_write.omap")
117}
Source

pub fn components_mut( &mut self, ) -> impl Iterator<Item = &mut PublicOrPrivateSymbol<WeakLinePathSymbol, Box<LineSymbol>>>

Iterate through the mutable symbol component of the symbol

Source

pub fn remove_component( &mut self, index: usize, ) -> Option<PublicOrPrivateSymbol<WeakLinePathSymbol, Box<LineSymbol>>>

Remove and return the symbol component at position index in the component vec. This preserves the order of the components. O(N) run time

Source

pub fn swap_remove_component( &mut self, index: usize, ) -> Option<PublicOrPrivateSymbol<WeakLinePathSymbol, Box<LineSymbol>>>

Remove and return the symbol component at position index in the component vec. This does not preserve the order of the components. O(1) run time

Source

pub fn add_component( &mut self, new_component: PublicOrPrivateSymbol<WeakLinePathSymbol, Box<LineSymbol>>, ) -> Result<(), Error>

Adds a component to the symbol Fails if adding this component will create a cycle in the symbol component definitions

The cycle detection relies on run time borrow checking, meaning that if any of the sub-symbols refcells are already being borrowed (through any of the .(try_)borrow(), .(try_)borrow_mut() functions) it fails

§Errors

Returns an error if the component would introduce a cycle or a child symbol cannot be borrowed during cycle detection.

Source

pub fn new(code: Code, name: impl Into<String>) -> Self

Create a new empty combined line symbol with the given code and name.

Source

pub fn get_name(&self) -> &str

Get the display name of this combined line symbol.

Source

pub fn num_components(&self) -> usize

Get the number of components in this combined symbol.

Source

pub fn as_helper_symbol(self) -> Self

Mark as a helper symbol (builder-style).

Source

pub fn minimum_length(&self) -> Result<f64, Error>

Get the minimum length (in paper dimensions mm) among all line sub-symbols. The check fails if any child combined line symbols cannot be borrowed This will recurse forever if any cycles exist

§Errors

Returns an error if a child line symbol cannot be borrowed.

Source

pub fn contains_symbol(&self, other_symbol: &WeakSymbol) -> Result<bool, Error>

Check if the symbol references the other symbol. The check fails if any sub-symbol cannot be borrowed (is mutably borrowed somewhere else)

§Errors

Returns an error if a referenced combined symbol cannot be borrowed.

Trait Implementations§

Source§

impl Clone for CombinedLineSymbol

Source§

fn clone(&self) -> CombinedLineSymbol

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CombinedLineSymbol

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<CombinedLineSymbol> for Symbol

Source§

fn from(value: CombinedLineSymbol) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.