Browse Source

Object modify and toggle limit check

Kevin Lee 1 week ago
parent
commit
4401ff1da2

BIN
1mmRect.mlp


BIN
2mmRect.mlp


BIN
2mmRectArray.mlp


+ 2 - 0
README.md

@@ -176,6 +176,8 @@ Op:
     PulseWidth: [2, 350, 2] # [min, max, step]
 
     PowerDensity: [10000, 1000000] # [min, max]
+
+    EnforceLimits: bool # Enforces pulse width / frequency limitations
 ```
 
 Exporting a pen to a file:

+ 38 - 0
config.yml

@@ -0,0 +1,38 @@
+Ops: 
+  - !PatchPen
+    Pen: 0
+    Speed: 2000
+    Frequency: 60000
+    Power: 20.0
+    PulseWidth: 80
+
+  - !ClonePen
+    From: 0
+    To: 255
+    Inclusive: true
+
+  - !RandomizePen
+    Index: 0
+    Count: 256
+    Speed: [1000, 10000, 500]
+    Power: [10, 30, 10]
+    Frequency: [10000, 200000, 1000]
+    PulseWidth: [2, 350, 2]
+    PowerDensity: [1000, 100000000]
+    EnforceLimits: true
+
+  - !Object
+    Input: !Existing { Layer: 0, Object: 0 }
+    Modify:
+      Z: 4.5
+    Array:
+      Columns: 3
+      Rows: 3
+      Spacing: 2.0
+      RandomizeOrder: True
+      StartingPen: 0
+      # PatternPenX: !Speed 100
+      # PatternPenY: !Power 5
+      # PatternHatchX: !LineSpacing 0.01
+      #PatternHatchY: !Count 1
+    ReplaceObject: 0

BIN
export.bin


BIN
samples/Circle2.mlp


BIN
samples/Circle3.mlp


BIN
samples/Circle4.mlp


BIN
samples/Circle5.mlp


BIN
samples/Ellipse.mlp


BIN
samples/Rectangle2.mlp


BIN
samples/Rectangle3.mlp


BIN
samples/Rectangle4.mlp


BIN
samples/RectangleSkewRightUpTopLeft.mlp


+ 28 - 18
src/config/object.rs

@@ -85,7 +85,7 @@ impl From<HatchConfig> for HatchSetting {
             flags.set_average_distribute_line(1);
         }
 
-        let mut ret = Self::default();
+        let mut ret: HatchSetting = Self::default();
 
         *ret.line_spacing = value.line_spacing;
         value.pen.map(|x| *ret.pen = x.into());
@@ -172,24 +172,14 @@ impl InputObject {
 
 #[derive(Debug, Serialize, Deserialize)]
 #[serde(rename_all = "PascalCase")]
-pub struct ObjectOperation {
-    input: InputObject,
+pub struct ObjectModify {
     z: Option<f64>,
     origin: Option<Point>,
     pen: Option<u32>,
-    layer: Option<usize>,
-    array: Option<ArrayConfig>,
-    hatch: Option<HatchConfig>,
-    export: Option<PathBuf>,
-    replace_object: Option<usize>,
 }
 
-impl ObjectOperation {
-    pub fn process(&self, pens: &mut Vec<Pen>, layers: &mut ArrayOf<Layer>) {
-        debug!("Begin processing of object {:?}", self.input);
-
-        let mut object: Object = self.input.new(layers);
-
+impl ObjectModify {
+    pub fn process(&self, object: &mut Object, pens: &mut Vec<Pen>) {
         // Process basic transformation
         if self.origin.is_some() || self.z.is_some() {
             debug!(
@@ -200,14 +190,34 @@ impl ObjectOperation {
         }
 
         self.pen.map(|pen| {
-            if self.array.is_some() {
-                warn!("Ignoring pen setting as values will be overridden by array setting");
-            } else {
                 assert!(pen < pens.len().try_into().unwrap(), "Invalid pen index");
                 debug!("Setting object pen to #{}", pen);
                 object.set_pen(pen);
-            }
+           
         });
+    }
+}
+
+#[derive(Debug, Serialize, Deserialize)]
+#[serde(rename_all = "PascalCase")]
+pub struct ObjectOperation {
+    input: InputObject,
+    modify: Option<ObjectModify>,
+    layer: Option<usize>,
+    array: Option<ArrayConfig>,
+    hatch: Option<HatchConfig>,
+    export: Option<PathBuf>,
+    replace_object: Option<usize>,
+}
+
+impl ObjectOperation {
+    pub fn process(&self, pens: &mut Vec<Pen>, layers: &mut ArrayOf<Layer>) {
+        debug!("Begin processing of object {:?}", self.input);
+
+        let mut object: Object = self.input.new(layers);
+
+        // Modify object properties
+        self.modify.as_ref().map(|modify| modify.process(&mut object, pens));
 
         // Process conversion to hatch object
         let object = self.hatch.as_ref().map_or(object.clone(), |hatch| {

+ 10 - 6
src/config/pen.rs

@@ -108,7 +108,7 @@ impl PatchPen {
         debug!("Patching pen #{}", self.pen);
         let pen: &mut Pen = pens.get_mut(self.pen).expect("Invalid pen index");
         self.patch.patch(pen);
-        pen.valid_settings();
+        pen.valid_settings(true);
     }
 }
 
@@ -251,7 +251,7 @@ impl PatternPenField {
             // Always enable custom settings for pen
             *next.use_default = 0;
 
-            next.valid_settings();
+            next.valid_settings(true);
         });
     }
 }
@@ -315,6 +315,7 @@ pub struct RandomizePen {
     frequency: Option<(u32, u32, u32)>,
     pulse_width: Option<(PulseWidth, PulseWidth, usize)>,
     power_density: Option<(u64, u64)>,
+    enforce_limits: Option<bool>,
 }
 
 impl RandomizePen {
@@ -392,9 +393,12 @@ impl RandomizePen {
                 }
 
                 // Check settings
-                if !pen.valid_settings() {
-                    debug!("Retrying (invalid setting)");
-                    continue;
+                if self.enforce_limits.unwrap_or(true) {
+                    debug!("Checking settings");
+                    if !pen.valid_settings(false) {
+                        debug!("Retrying (invalid setting)");
+                        continue;
+                    }
                 }
 
                 // Check for duplicates
@@ -414,7 +418,7 @@ impl RandomizePen {
                 }
             }
 
-            pen.valid_settings();
+            pen.valid_settings(true);
         }
     }
 }

+ 15 - 11
src/ezcad/pen.rs

@@ -125,7 +125,7 @@ impl Pen {
             .expect("Failed to write to output file");
     }
 
-    pub fn valid_settings(&self) -> bool {
+    pub fn valid_settings(&self, warn_limits: bool) -> bool {
         let mut ret: bool = true;
 
         if *self.frequency != *self.frequency_2 as u32 {
@@ -147,19 +147,23 @@ impl Pen {
         match PulseWidth::try_from(*self.pulse_width) {
             Ok(pw) => match *self.frequency {
                 freq if freq < pw.min_freq() => {
-                    warn!(
-                        "Pen frequency of {} lower than pulse width minimum frequency of {}",
-                        *self.frequency,
-                        pw.min_freq()
-                    );
+                    if warn_limits {
+                        warn!(
+                            "Pen frequency of {} lower than pulse width minimum frequency of {}",
+                            *self.frequency,
+                            pw.min_freq()
+                        );
+                    }
                     ret = false;
                 }
                 freq if freq > pw.max_freq() => {
-                    warn!(
-                        "Pen frequency of {} higher than pulse width maximum frequency of {}",
-                        *self.frequency,
-                        pw.max_freq()
-                    );
+                    if warn_limits {
+                        warn!(
+                            "Pen frequency of {} higher than pulse width maximum frequency of {}",
+                            *self.frequency,
+                            pw.max_freq()
+                        );
+                    }
                     ret = false;
                 }
                 _ => (),

BIN
test.mlp


BIN
test2.mlp


+ 91 - 0
test2.yml

@@ -0,0 +1,91 @@
+Ops: 
+  - !PatchPen
+    Pen: 0
+    Speed: 500
+    Frequency: 50000
+    Power: 30.0
+    PulseWidth: 2
+
+  - !ClonePen
+    From: 0
+    To: 255
+    Inclusive: True
+
+  # - !PatchPen
+  #   Pen: 0
+  #   Power: 10.0
+
+  # - !PatternPen
+  #   From: 0
+  #   To: 40
+  #   Field: !Power 2
+
+  # - !DeleteObjects
+  #   Layer: 0
+
+  # - !HatchArray
+  #   Layer: 0
+  #   Width: 3.0
+  #   Height: 2.0
+  #   Columns: 8
+  #   Rows: 5
+  #   Spacing: 0.5
+  #   Z: 0.0
+  #   StartingPen: 0
+  #   Hatch:
+  #     LineSpacing: 0.1
+
+  # - !Object
+  #   Input: !Existing { Layer: 0, Object: 0 }
+  #   Export: 'export.bin'
+
+  - !Object
+    # Input: !Rectangle { Width: 2, Height: 3 }
+    Input: !Existing { Layer: 0, Object: 0 }
+    Z: 0.8
+    # Origin: { X: 10.0, Y: 10.0 }
+    # Pen: 0
+    Array:
+      Columns: 15
+      Rows: 10
+      Spacing: 2.3
+      RandomizeOrder: True
+      StartingPen: 0
+      # PatternX: !Frequency 5000
+      # PatternY: !Power 1.0
+      # PatternX: !PulseWidth 1
+      # PatternY: !Frequency 10000
+    # Hatch:
+    #   LineSpacing: 0.01
+    ReplaceObject: 0
+
+  - !RandomizePen
+    Index: 0
+    Count: 30
+    Speed: [100, 1000, 100] # [min, max, step]
+    Power: [10, 100, 5] # [min, max, step]
+    Frequency: [20000, 1000000, 1000] # [min, max, step]
+    PulseWidth: [2, 80, 2] # [min, max, step]
+
+  # - !Object
+  #   Input: !Rectangle { Width: 10, Height: 5}
+  #   Z: 0.0
+  #   Origin: { X: 10.0, Y: 10.0 }
+  #   Pen: 0
+  #   ReplaceObject: 0
+
+  # - !Object
+  #   Input: !Existing { Layer: 0, Object: 0 }
+  #   Origin: { X: 10.0, Y: 10.0 }
+  #   ReplaceObject: 0
+
+  # - !Object
+  #   Input: !Existing { Layer: 0, Object: 1 }
+  #   Origin: { X: 10.0, Y: 10.0 }
+  #   ReplaceObject: 1
+
+  # - !Object
+  #   Input: !Circle { Radius: 3.0 }
+
+  # - !Object
+  #   Input: !Import { Path: 'export.bin' }