|
@@ -1,166 +1,222 @@
|
|
|
-use ezcad::objects::{hatch::HatchSetting, Object};
|
|
|
-use log::debug;
|
|
|
-use serde::{Deserialize, Serialize};
|
|
|
-
|
|
|
-#[derive(Debug, Serialize, Deserialize)]
|
|
|
-
|
|
|
-pub enum PatternHatchField {
|
|
|
- Count(u32),
|
|
|
- LineSpacing(f64),
|
|
|
- EdgeOffset(f64),
|
|
|
- StartOffset(f64),
|
|
|
- EndOffset(f64),
|
|
|
- Angle(f64),
|
|
|
- RotateAngle(f64),
|
|
|
- LineReduction(f64),
|
|
|
- LoopDistance(f64),
|
|
|
- LoopCount(u32),
|
|
|
-}
|
|
|
-
|
|
|
-impl PatternHatchField {
|
|
|
- pub fn pattern(&self, objects: &mut dyn Iterator<Item = (usize, &mut Object)>) {
|
|
|
- let (src_idx, src) = objects
|
|
|
- .next()
|
|
|
- .expect("Pattern must involve at least one pen");
|
|
|
-
|
|
|
- // Obtain settings from first object
|
|
|
- let mut setting: PatternHatchField = match src {
|
|
|
- Object::Hatch(src) => {
|
|
|
- let setting = src
|
|
|
- .hatch_settings
|
|
|
- .iter()
|
|
|
- .find(|h| h.enabled.into())
|
|
|
- .expect("Hatch missing enabled settings");
|
|
|
-
|
|
|
- let setting: PatternHatchField = match self {
|
|
|
- PatternHatchField::Count(_) => {
|
|
|
- debug!("Initial hatch count from object #{} is {}", src_idx, *setting.count);
|
|
|
- PatternHatchField::Count(*setting.count)
|
|
|
-
|
|
|
- },
|
|
|
- PatternHatchField::LineSpacing(_) => {
|
|
|
- debug!("Initial hatch line spacing from object #{} is {}", src_idx, *setting.line_spacing);
|
|
|
- PatternHatchField::LineSpacing(*setting.line_spacing)
|
|
|
- },
|
|
|
- PatternHatchField::EdgeOffset(_) => {
|
|
|
- debug!("Initial hatch edge offset from object #{} is {}", src_idx, *setting.edge_offset);
|
|
|
- PatternHatchField::EdgeOffset(*setting.edge_offset)
|
|
|
- },
|
|
|
- PatternHatchField::StartOffset(_) => {
|
|
|
- debug!("Initial hatch start offset from object #{} is {}", src_idx, *setting.start_offset);
|
|
|
- PatternHatchField::StartOffset(*setting.start_offset)
|
|
|
- },
|
|
|
- PatternHatchField::EndOffset(_) => {
|
|
|
- debug!("Initial hatch end offset from object #{} is {}", src_idx, *setting.end_offset);
|
|
|
- PatternHatchField::EndOffset(*setting.end_offset)
|
|
|
- },
|
|
|
- PatternHatchField::Angle(_) => {
|
|
|
- debug!("Initial hatch angle from object #{} is {}", src_idx, *setting.angle);
|
|
|
- PatternHatchField::Angle(*setting.angle)
|
|
|
- },
|
|
|
- PatternHatchField::RotateAngle(_) => {
|
|
|
- debug!("Initial hatch rotate angle from object #{} is {}", src_idx, *setting.rotate_angle);
|
|
|
- PatternHatchField::RotateAngle(*setting.rotate_angle)
|
|
|
- },
|
|
|
- PatternHatchField::LineReduction(_) => {
|
|
|
- debug!("Initial hatch line reduction angle from object #{} is {}", src_idx, *setting.line_reduction);
|
|
|
- PatternHatchField::LineReduction(*setting.line_reduction)
|
|
|
- },
|
|
|
- PatternHatchField::LoopDistance(_) => {
|
|
|
- debug!("Initial hatch loop distance from object #{} is {}", src_idx, *setting.loop_distance);
|
|
|
- PatternHatchField::LoopDistance(*setting.loop_distance)
|
|
|
- },
|
|
|
- PatternHatchField::LoopCount(_) => {
|
|
|
- debug!("Initial hatch loop count from object #{} is {}", src_idx, *setting.loop_count);
|
|
|
- PatternHatchField::LoopCount(*setting.loop_count)
|
|
|
- },
|
|
|
- };
|
|
|
-
|
|
|
- setting
|
|
|
- }
|
|
|
- _ => panic!("Object #{} not a hatch object", src_idx)
|
|
|
- };
|
|
|
-
|
|
|
- for (idx, dst) in objects {
|
|
|
- // Calculate new setting
|
|
|
- setting = match (setting, self) {
|
|
|
- (PatternHatchField::Count(prev), PatternHatchField::Count(incr)) => {
|
|
|
- let value: u32 = prev + incr;
|
|
|
- debug!("Patching hatch count for object #{} to {}", idx, value);
|
|
|
- PatternHatchField::Count(value)
|
|
|
- }
|
|
|
- (PatternHatchField::LineSpacing(prev), PatternHatchField::LineSpacing(incr)) => {
|
|
|
- let value: f64 = prev + incr;
|
|
|
- debug!("Patching hatch line spacing for object #{} to {}", idx, value);
|
|
|
- PatternHatchField::LineSpacing(value)
|
|
|
- }
|
|
|
- (PatternHatchField::EdgeOffset(prev), PatternHatchField::EdgeOffset(incr)) => {
|
|
|
- let value: f64 = prev + incr;
|
|
|
- debug!("Patching hatch edge offset for object #{} to {}", idx, value);
|
|
|
- PatternHatchField::EdgeOffset(value)
|
|
|
- }
|
|
|
- (PatternHatchField::StartOffset(prev), PatternHatchField::StartOffset(incr)) => {
|
|
|
- let value: f64 = prev + incr;
|
|
|
- debug!("Patching hatch start offset for object #{} to {}", idx, value);
|
|
|
- PatternHatchField::StartOffset(value)
|
|
|
- }
|
|
|
- (PatternHatchField::EndOffset(prev), PatternHatchField::LineSpacing(incr)) => {
|
|
|
- let value: f64 = prev + incr;
|
|
|
- debug!("Patching hatch end offset for object #{} to {}", idx, value);
|
|
|
- PatternHatchField::EndOffset(value)
|
|
|
- }
|
|
|
- (PatternHatchField::Angle(prev), PatternHatchField::Angle(incr)) => {
|
|
|
- let value: f64 = prev + incr;
|
|
|
- debug!("Patching hatch angle for object #{} to {}", idx, value);
|
|
|
- PatternHatchField::Angle(value)
|
|
|
- }
|
|
|
- (PatternHatchField::RotateAngle(prev), PatternHatchField::RotateAngle(incr)) => {
|
|
|
- let value: f64 = prev + incr;
|
|
|
- debug!("Patching hatch rotate angle for object #{} to {}", idx, value);
|
|
|
- PatternHatchField::RotateAngle(value)
|
|
|
- }
|
|
|
- (PatternHatchField::LineReduction(prev), PatternHatchField::LineReduction(incr)) => {
|
|
|
- let value: f64 = prev + incr;
|
|
|
- debug!("Patching hatch line reduction for object #{} to {}", idx, value);
|
|
|
- PatternHatchField::LineReduction(value)
|
|
|
- }
|
|
|
- (PatternHatchField::LoopDistance(prev), PatternHatchField::LoopDistance(incr)) => {
|
|
|
- let value: f64 = prev + incr;
|
|
|
- debug!("Patching hatch loop distance for object #{} to {}", idx, value);
|
|
|
- PatternHatchField::LoopDistance(value)
|
|
|
- }
|
|
|
- (PatternHatchField::LoopCount(prev), PatternHatchField::LoopCount(incr)) => {
|
|
|
- let value: u32 = prev + incr;
|
|
|
- debug!("Patching hatch loop count for object #{} to {}", idx, value);
|
|
|
- PatternHatchField::LoopCount(value)
|
|
|
- }
|
|
|
- _ => unreachable!(),
|
|
|
- };
|
|
|
-
|
|
|
- // Apply setting
|
|
|
- match dst {
|
|
|
- Object::Hatch(dst) => {
|
|
|
- let dst: &mut HatchSetting = dst
|
|
|
- .hatch_settings
|
|
|
- .iter_mut()
|
|
|
- .find(|h| h.enabled.into())
|
|
|
- .expect("Hatch missing enabled settings");
|
|
|
-
|
|
|
- match setting {
|
|
|
- PatternHatchField::Count(x) => *dst.count = x,
|
|
|
- PatternHatchField::LineSpacing(x) => *dst.line_spacing = x,
|
|
|
- PatternHatchField::EdgeOffset(x) => *dst.edge_offset = x,
|
|
|
- PatternHatchField::StartOffset(x) => *dst.start_offset = x,
|
|
|
- PatternHatchField::EndOffset(x) => *dst.end_offset = x,
|
|
|
- PatternHatchField::Angle(x) => *dst.angle = x,
|
|
|
- PatternHatchField::RotateAngle(x) => *dst.rotate_angle = x,
|
|
|
- PatternHatchField::LineReduction(x) => *dst.line_reduction = x,
|
|
|
- PatternHatchField::LoopDistance(x) => *dst.loop_distance = x,
|
|
|
- PatternHatchField::LoopCount(x) => *dst.loop_count = x,
|
|
|
- }
|
|
|
- },
|
|
|
- _ => panic!("Object #{} not a hatch object", src_idx)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
+use ezcad::objects::{hatch::HatchSetting, Object};
|
|
|
+use log::debug;
|
|
|
+use serde::{Deserialize, Serialize};
|
|
|
+
|
|
|
+#[derive(Debug, Serialize, Deserialize)]
|
|
|
+
|
|
|
+pub enum PatternHatchField {
|
|
|
+ Count(u32),
|
|
|
+ LineSpacing(f64),
|
|
|
+ EdgeOffset(f64),
|
|
|
+ StartOffset(f64),
|
|
|
+ EndOffset(f64),
|
|
|
+ Angle(f64),
|
|
|
+ RotateAngle(f64),
|
|
|
+ LineReduction(f64),
|
|
|
+ LoopDistance(f64),
|
|
|
+ LoopCount(u32),
|
|
|
+}
|
|
|
+
|
|
|
+impl PatternHatchField {
|
|
|
+ pub fn pattern(&self, objects: &mut dyn Iterator<Item = (usize, &mut Object)>) {
|
|
|
+ let (src_idx, src) = objects
|
|
|
+ .next()
|
|
|
+ .expect("Pattern must involve at least one pen");
|
|
|
+
|
|
|
+ // Obtain settings from first object
|
|
|
+ let mut setting: PatternHatchField = match src {
|
|
|
+ Object::Hatch(src) => {
|
|
|
+ let setting = src
|
|
|
+ .hatch_settings
|
|
|
+ .iter()
|
|
|
+ .find(|h| h.enabled.into())
|
|
|
+ .expect("Hatch missing enabled settings");
|
|
|
+
|
|
|
+ let setting: PatternHatchField = match self {
|
|
|
+ PatternHatchField::Count(_) => {
|
|
|
+ debug!(
|
|
|
+ "Initial hatch count from object #{} is {}",
|
|
|
+ src_idx, *setting.count
|
|
|
+ );
|
|
|
+ PatternHatchField::Count(*setting.count)
|
|
|
+ }
|
|
|
+ PatternHatchField::LineSpacing(_) => {
|
|
|
+ debug!(
|
|
|
+ "Initial hatch line spacing from object #{} is {:.3}",
|
|
|
+ src_idx, *setting.line_spacing
|
|
|
+ );
|
|
|
+ PatternHatchField::LineSpacing(*setting.line_spacing)
|
|
|
+ }
|
|
|
+ PatternHatchField::EdgeOffset(_) => {
|
|
|
+ debug!(
|
|
|
+ "Initial hatch edge offset from object #{} is {:.3}",
|
|
|
+ src_idx, *setting.edge_offset
|
|
|
+ );
|
|
|
+ PatternHatchField::EdgeOffset(*setting.edge_offset)
|
|
|
+ }
|
|
|
+ PatternHatchField::StartOffset(_) => {
|
|
|
+ debug!(
|
|
|
+ "Initial hatch start offset from object #{} is {:.3}",
|
|
|
+ src_idx, *setting.start_offset
|
|
|
+ );
|
|
|
+ PatternHatchField::StartOffset(*setting.start_offset)
|
|
|
+ }
|
|
|
+ PatternHatchField::EndOffset(_) => {
|
|
|
+ debug!(
|
|
|
+ "Initial hatch end offset from object #{} is {:.3}",
|
|
|
+ src_idx, *setting.end_offset
|
|
|
+ );
|
|
|
+ PatternHatchField::EndOffset(*setting.end_offset)
|
|
|
+ }
|
|
|
+ PatternHatchField::Angle(_) => {
|
|
|
+ debug!(
|
|
|
+ "Initial hatch angle from object #{} is {:.3}",
|
|
|
+ src_idx, *setting.angle
|
|
|
+ );
|
|
|
+ PatternHatchField::Angle(*setting.angle)
|
|
|
+ }
|
|
|
+ PatternHatchField::RotateAngle(_) => {
|
|
|
+ debug!(
|
|
|
+ "Initial hatch rotate angle from object #{} is {:.3}",
|
|
|
+ src_idx, *setting.rotate_angle
|
|
|
+ );
|
|
|
+ PatternHatchField::RotateAngle(*setting.rotate_angle)
|
|
|
+ }
|
|
|
+ PatternHatchField::LineReduction(_) => {
|
|
|
+ debug!(
|
|
|
+ "Initial hatch line reduction angle from object #{} is {:.3}",
|
|
|
+ src_idx, *setting.line_reduction
|
|
|
+ );
|
|
|
+ PatternHatchField::LineReduction(*setting.line_reduction)
|
|
|
+ }
|
|
|
+ PatternHatchField::LoopDistance(_) => {
|
|
|
+ debug!(
|
|
|
+ "Initial hatch loop distance from object #{} is {:.3}",
|
|
|
+ src_idx, *setting.loop_distance
|
|
|
+ );
|
|
|
+ PatternHatchField::LoopDistance(*setting.loop_distance)
|
|
|
+ }
|
|
|
+ PatternHatchField::LoopCount(_) => {
|
|
|
+ debug!(
|
|
|
+ "Initial hatch loop count from object #{} is {:.3}",
|
|
|
+ src_idx, *setting.loop_count
|
|
|
+ );
|
|
|
+ PatternHatchField::LoopCount(*setting.loop_count)
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ setting
|
|
|
+ }
|
|
|
+ _ => panic!("Object #{} not a hatch object", src_idx),
|
|
|
+ };
|
|
|
+
|
|
|
+ for (idx, dst) in objects {
|
|
|
+ // Calculate new setting
|
|
|
+ setting = match (setting, self) {
|
|
|
+ (PatternHatchField::Count(prev), PatternHatchField::Count(incr)) => {
|
|
|
+ let value: u32 = prev + incr;
|
|
|
+ debug!("Patching hatch count for object #{} to {:.3}", idx, value);
|
|
|
+ PatternHatchField::Count(value)
|
|
|
+ }
|
|
|
+ (PatternHatchField::LineSpacing(prev), PatternHatchField::LineSpacing(incr)) => {
|
|
|
+ let value: f64 = prev + incr;
|
|
|
+ debug!(
|
|
|
+ "Patching hatch line spacing for object #{} to {:.3}",
|
|
|
+ idx, value
|
|
|
+ );
|
|
|
+ PatternHatchField::LineSpacing(value)
|
|
|
+ }
|
|
|
+ (PatternHatchField::EdgeOffset(prev), PatternHatchField::EdgeOffset(incr)) => {
|
|
|
+ let value: f64 = prev + incr;
|
|
|
+ debug!(
|
|
|
+ "Patching hatch edge offset for object #{} to {:.3}",
|
|
|
+ idx, value
|
|
|
+ );
|
|
|
+ PatternHatchField::EdgeOffset(value)
|
|
|
+ }
|
|
|
+ (PatternHatchField::StartOffset(prev), PatternHatchField::StartOffset(incr)) => {
|
|
|
+ let value: f64 = prev + incr;
|
|
|
+ debug!(
|
|
|
+ "Patching hatch start offset for object #{} to {:.3}",
|
|
|
+ idx, value
|
|
|
+ );
|
|
|
+ PatternHatchField::StartOffset(value)
|
|
|
+ }
|
|
|
+ (PatternHatchField::EndOffset(prev), PatternHatchField::LineSpacing(incr)) => {
|
|
|
+ let value: f64 = prev + incr;
|
|
|
+ debug!(
|
|
|
+ "Patching hatch end offset for object #{} to {:.3}",
|
|
|
+ idx, value
|
|
|
+ );
|
|
|
+ PatternHatchField::EndOffset(value)
|
|
|
+ }
|
|
|
+ (PatternHatchField::Angle(prev), PatternHatchField::Angle(incr)) => {
|
|
|
+ let value: f64 = prev + incr;
|
|
|
+ debug!("Patching hatch angle for object #{} to {:.3}", idx, value);
|
|
|
+ PatternHatchField::Angle(value)
|
|
|
+ }
|
|
|
+ (PatternHatchField::RotateAngle(prev), PatternHatchField::RotateAngle(incr)) => {
|
|
|
+ let value: f64 = prev + incr;
|
|
|
+ debug!(
|
|
|
+ "Patching hatch rotate angle for object #{} to {:.3}",
|
|
|
+ idx, value
|
|
|
+ );
|
|
|
+ PatternHatchField::RotateAngle(value)
|
|
|
+ }
|
|
|
+ (
|
|
|
+ PatternHatchField::LineReduction(prev),
|
|
|
+ PatternHatchField::LineReduction(incr),
|
|
|
+ ) => {
|
|
|
+ let value: f64 = prev + incr;
|
|
|
+ debug!(
|
|
|
+ "Patching hatch line reduction for object #{} to {:.3}",
|
|
|
+ idx, value
|
|
|
+ );
|
|
|
+ PatternHatchField::LineReduction(value)
|
|
|
+ }
|
|
|
+ (PatternHatchField::LoopDistance(prev), PatternHatchField::LoopDistance(incr)) => {
|
|
|
+ let value: f64 = prev + incr;
|
|
|
+ debug!(
|
|
|
+ "Patching hatch loop distance for object #{} to {:.3}",
|
|
|
+ idx, value
|
|
|
+ );
|
|
|
+ PatternHatchField::LoopDistance(value)
|
|
|
+ }
|
|
|
+ (PatternHatchField::LoopCount(prev), PatternHatchField::LoopCount(incr)) => {
|
|
|
+ let value: u32 = prev + incr;
|
|
|
+ debug!(
|
|
|
+ "Patching hatch loop count for object #{} to {:.3}",
|
|
|
+ idx, value
|
|
|
+ );
|
|
|
+ PatternHatchField::LoopCount(value)
|
|
|
+ }
|
|
|
+ _ => unreachable!(),
|
|
|
+ };
|
|
|
+
|
|
|
+ // Apply setting
|
|
|
+ match dst {
|
|
|
+ Object::Hatch(dst) => {
|
|
|
+ let dst: &mut HatchSetting = dst
|
|
|
+ .hatch_settings
|
|
|
+ .iter_mut()
|
|
|
+ .find(|h| h.enabled.into())
|
|
|
+ .expect("Hatch missing enabled settings");
|
|
|
+
|
|
|
+ match setting {
|
|
|
+ PatternHatchField::Count(x) => *dst.count = x,
|
|
|
+ PatternHatchField::LineSpacing(x) => *dst.line_spacing = x,
|
|
|
+ PatternHatchField::EdgeOffset(x) => *dst.edge_offset = x,
|
|
|
+ PatternHatchField::StartOffset(x) => *dst.start_offset = x,
|
|
|
+ PatternHatchField::EndOffset(x) => *dst.end_offset = x,
|
|
|
+ PatternHatchField::Angle(x) => *dst.angle = x,
|
|
|
+ PatternHatchField::RotateAngle(x) => *dst.rotate_angle = x,
|
|
|
+ PatternHatchField::LineReduction(x) => *dst.line_reduction = x,
|
|
|
+ PatternHatchField::LoopDistance(x) => *dst.loop_distance = x,
|
|
|
+ PatternHatchField::LoopCount(x) => *dst.loop_count = x,
|
|
|
+ }
|
|
|
+ }
|
|
|
+ _ => panic!("Object #{} not a hatch object", src_idx),
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|