From f1187b83e49454c0e476f9a48ae990f28ad8b724 Mon Sep 17 00:00:00 2001 From: Paul Tagliamonte Date: Mon, 21 Oct 2024 10:26:16 -0400 Subject: [PATCH] rename slicer options to build options (#145) additionally, i'm pulling more off the machine and packing it with it. the build options is binding the (part, slicer, machine, machine configuration) all together to give parts the best idea of how the part is going to be made. --- src/lib.rs | 6 +++--- src/machine.rs | 10 +++++++--- src/slicer/mod.rs | 8 ++++---- src/slicer/noop.rs | 6 +++--- src/slicer/orca.rs | 6 +++--- src/slicer/prusa.rs | 6 +++--- src/traits.rs | 19 ++++++++++++++----- 7 files changed, 37 insertions(+), 24 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 7143cd4..229d0be 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -43,10 +43,10 @@ use serde::{Deserialize, Serialize}; pub use slicer::AnySlicer; pub use sync::SharedMachine; pub use traits::{ - Control, FdmHardwareConfiguration, FilamentMaterial, GcodeControl, GcodeSlicer, GcodeTemporaryFile, + BuildOptions, Control, FdmHardwareConfiguration, FilamentMaterial, GcodeControl, GcodeSlicer, GcodeTemporaryFile, HardwareConfiguration, MachineInfo, MachineMakeModel, MachineState, MachineType, SlicerConfiguration, - SlicerOptions, SuspendControl, TemperatureSensor, TemperatureSensorReading, TemperatureSensors, ThreeMfControl, - ThreeMfSlicer, ThreeMfTemporaryFile, + SuspendControl, TemperatureSensor, TemperatureSensorReading, TemperatureSensors, ThreeMfControl, ThreeMfSlicer, + ThreeMfTemporaryFile, }; /// A specific file containing a design to be manufactured. diff --git a/src/machine.rs b/src/machine.rs index a6aa514..9546bdf 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -1,8 +1,8 @@ use anyhow::Result; use crate::{ - traits::Control, AnyMachine, AnySlicer, DesignFile, GcodeControl, GcodeSlicer, SlicerConfiguration, SlicerOptions, - ThreeMfControl, ThreeMfSlicer, + AnyMachine, AnySlicer, BuildOptions, Control, DesignFile, GcodeControl, GcodeSlicer, MachineInfo, + SlicerConfiguration, ThreeMfControl, ThreeMfSlicer, }; /// Create a handle to a specific Machine which is capable of producing a 3D @@ -56,8 +56,12 @@ impl Machine { ) -> Result<()> { tracing::debug!(name = job_name, "building"); let hardware_configuration = self.machine.hardware_configuration().await?; + let machine_info = self.machine.machine_info().await?; - let options = SlicerOptions { + let options = BuildOptions { + make_model: machine_info.make_model(), + machine_type: machine_info.machine_type(), + max_part_volume: machine_info.max_part_volume(), hardware_configuration, slicer_configuration: *slicer_configuration, }; diff --git a/src/slicer/mod.rs b/src/slicer/mod.rs index 981f28d..c94e04d 100644 --- a/src/slicer/mod.rs +++ b/src/slicer/mod.rs @@ -11,8 +11,8 @@ use anyhow::Result; pub use config::Config; use crate::{ - DesignFile, GcodeSlicer as GcodeSlicerTrait, GcodeTemporaryFile, SlicerOptions, - ThreeMfSlicer as ThreeMfSlicerTrait, ThreeMfTemporaryFile, + BuildOptions, DesignFile, GcodeSlicer as GcodeSlicerTrait, GcodeTemporaryFile, ThreeMfSlicer as ThreeMfSlicerTrait, + ThreeMfTemporaryFile, }; /// All Slicers that are supported by the machine-api. @@ -50,7 +50,7 @@ impl GcodeSlicerTrait for AnySlicer { type Error = anyhow::Error; /// Generate gcode from some input file. - async fn generate(&self, design_file: &DesignFile, options: &SlicerOptions) -> Result { + async fn generate(&self, design_file: &DesignFile, options: &BuildOptions) -> Result { match self { Self::Prusa(slicer) => GcodeSlicerTrait::generate(slicer, design_file, options).await, Self::Noop(slicer) => GcodeSlicerTrait::generate(slicer, design_file, options).await, @@ -63,7 +63,7 @@ impl ThreeMfSlicerTrait for AnySlicer { type Error = anyhow::Error; /// Generate gcode from some input file. - async fn generate(&self, design_file: &DesignFile, options: &SlicerOptions) -> Result { + async fn generate(&self, design_file: &DesignFile, options: &BuildOptions) -> Result { match self { Self::Prusa(slicer) => ThreeMfSlicerTrait::generate(slicer, design_file, options).await, Self::Orca(slicer) => ThreeMfSlicerTrait::generate(slicer, design_file, options).await, diff --git a/src/slicer/noop.rs b/src/slicer/noop.rs index ca5c67d..3672274 100644 --- a/src/slicer/noop.rs +++ b/src/slicer/noop.rs @@ -4,7 +4,7 @@ use anyhow::Result; use crate::{ - DesignFile, GcodeSlicer as GcodeSlicerTrait, GcodeTemporaryFile, SlicerOptions, TemporaryFile, + BuildOptions, DesignFile, GcodeSlicer as GcodeSlicerTrait, GcodeTemporaryFile, TemporaryFile, ThreeMfSlicer as ThreeMfSlicerTrait, ThreeMfTemporaryFile, }; @@ -28,7 +28,7 @@ impl Default for Slicer { impl GcodeSlicerTrait for Slicer { type Error = anyhow::Error; - async fn generate(&self, _design_file: &DesignFile, _: &SlicerOptions) -> Result { + async fn generate(&self, _design_file: &DesignFile, _: &BuildOptions) -> Result { let filepath = std::env::temp_dir().join(format!("{}", uuid::Uuid::new_v4().simple())); { let _ = std::fs::File::create(&filepath); @@ -40,7 +40,7 @@ impl GcodeSlicerTrait for Slicer { impl ThreeMfSlicerTrait for Slicer { type Error = anyhow::Error; - async fn generate(&self, _design_file: &DesignFile, _: &SlicerOptions) -> Result { + async fn generate(&self, _design_file: &DesignFile, _: &BuildOptions) -> Result { let filepath = std::env::temp_dir().join(format!("{}", uuid::Uuid::new_v4().simple())); { let _ = std::fs::File::create(&filepath); diff --git a/src/slicer/orca.rs b/src/slicer/orca.rs index 7812ab6..5e25345 100644 --- a/src/slicer/orca.rs +++ b/src/slicer/orca.rs @@ -6,7 +6,7 @@ use anyhow::{Context, Result}; use tokio::process::Command; use crate::{ - DesignFile, HardwareConfiguration, SlicerOptions, TemporaryFile, ThreeMfSlicer as ThreeMfSlicerTrait, + BuildOptions, DesignFile, HardwareConfiguration, TemporaryFile, ThreeMfSlicer as ThreeMfSlicerTrait, ThreeMfTemporaryFile, }; @@ -30,7 +30,7 @@ impl Slicer { output_flag: &str, output_extension: &str, design_file: &DesignFile, - options: &SlicerOptions, + options: &BuildOptions, ) -> Result { // Make sure the config path is a directory. if !self.config.is_dir() { @@ -225,7 +225,7 @@ impl ThreeMfSlicerTrait for Slicer { type Error = anyhow::Error; /// Generate gcode from some input file. - async fn generate(&self, design_file: &DesignFile, options: &SlicerOptions) -> Result { + async fn generate(&self, design_file: &DesignFile, options: &BuildOptions) -> Result { Ok(ThreeMfTemporaryFile( self.generate_via_cli("--export-3mf", "3mf", design_file, options) .await?, diff --git a/src/slicer/prusa.rs b/src/slicer/prusa.rs index 00960d8..e40eea5 100644 --- a/src/slicer/prusa.rs +++ b/src/slicer/prusa.rs @@ -7,7 +7,7 @@ use anyhow::{Context, Result}; use tokio::process::Command; use crate::{ - DesignFile, GcodeSlicer as GcodeSlicerTrait, GcodeTemporaryFile, SlicerOptions, TemporaryFile, + BuildOptions, DesignFile, GcodeSlicer as GcodeSlicerTrait, GcodeTemporaryFile, TemporaryFile, ThreeMfSlicer as ThreeMfSlicerTrait, ThreeMfTemporaryFile, }; @@ -109,7 +109,7 @@ impl Slicer { impl GcodeSlicerTrait for Slicer { type Error = anyhow::Error; - async fn generate(&self, design_file: &DesignFile, _: &SlicerOptions) -> Result { + async fn generate(&self, design_file: &DesignFile, _: &BuildOptions) -> Result { Ok(GcodeTemporaryFile( self.generate_from_cli("--export-gcode", "gcode", design_file).await?, )) @@ -119,7 +119,7 @@ impl GcodeSlicerTrait for Slicer { impl ThreeMfSlicerTrait for Slicer { type Error = anyhow::Error; - async fn generate(&self, design_file: &DesignFile, _: &SlicerOptions) -> Result { + async fn generate(&self, design_file: &DesignFile, _: &BuildOptions) -> Result { Ok(ThreeMfTemporaryFile( self.generate_from_cli("--export-3mf", "3mf", design_file).await?, )) diff --git a/src/traits.rs b/src/traits.rs index b1f5259..4fae1dc 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -311,10 +311,10 @@ pub struct SlicerConfiguration { pub filament_idx: Option, } -/// Options passed to a slicer that are specific to a (Machine, DesignFile and -/// Slicer). +/// Options passed along with the Build request that are specific to a +/// (Machine, DesignFile and Slicer). #[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)] -pub struct SlicerOptions { +pub struct BuildOptions { /// Specific configuration of the hardware platform producing the file /// in real life. pub hardware_configuration: HardwareConfiguration, @@ -322,6 +322,15 @@ pub struct SlicerOptions { /// Requested configuration of the slicer -- things like supports, /// infill or other configuration to the designed file. pub slicer_configuration: SlicerConfiguration, + + /// Make/Model of the target platform. + pub make_model: MachineMakeModel, + + /// Method by which the machine can create a physical 3D part. + pub machine_type: MachineType, + + /// Largest build volume that the machine can construct. + pub max_part_volume: Option, } /// [Control]-specific slicer which takes a particular [DesignFile], and produces @@ -335,7 +344,7 @@ pub trait GcodeSlicer { fn generate( &self, design_file: &DesignFile, - options: &SlicerOptions, + options: &BuildOptions, ) -> impl Future::Error>>; } @@ -353,7 +362,7 @@ pub trait ThreeMfSlicer { fn generate( &self, design_file: &DesignFile, - options: &SlicerOptions, + options: &BuildOptions, ) -> impl Future::Error>>; }