Skip to content

Commit

Permalink
rename slicer options to build options (#145)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
paultag authored Oct 21, 2024
1 parent bd03d2b commit f1187b8
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 24 deletions.
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 7 additions & 3 deletions src/machine.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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,
};
Expand Down
8 changes: 4 additions & 4 deletions src/slicer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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<GcodeTemporaryFile> {
async fn generate(&self, design_file: &DesignFile, options: &BuildOptions) -> Result<GcodeTemporaryFile> {
match self {
Self::Prusa(slicer) => GcodeSlicerTrait::generate(slicer, design_file, options).await,
Self::Noop(slicer) => GcodeSlicerTrait::generate(slicer, design_file, options).await,
Expand All @@ -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<ThreeMfTemporaryFile> {
async fn generate(&self, design_file: &DesignFile, options: &BuildOptions) -> Result<ThreeMfTemporaryFile> {
match self {
Self::Prusa(slicer) => ThreeMfSlicerTrait::generate(slicer, design_file, options).await,
Self::Orca(slicer) => ThreeMfSlicerTrait::generate(slicer, design_file, options).await,
Expand Down
6 changes: 3 additions & 3 deletions src/slicer/noop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand All @@ -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<GcodeTemporaryFile> {
async fn generate(&self, _design_file: &DesignFile, _: &BuildOptions) -> Result<GcodeTemporaryFile> {
let filepath = std::env::temp_dir().join(format!("{}", uuid::Uuid::new_v4().simple()));
{
let _ = std::fs::File::create(&filepath);
Expand All @@ -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<ThreeMfTemporaryFile> {
async fn generate(&self, _design_file: &DesignFile, _: &BuildOptions) -> Result<ThreeMfTemporaryFile> {
let filepath = std::env::temp_dir().join(format!("{}", uuid::Uuid::new_v4().simple()));
{
let _ = std::fs::File::create(&filepath);
Expand Down
6 changes: 3 additions & 3 deletions src/slicer/orca.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand All @@ -30,7 +30,7 @@ impl Slicer {
output_flag: &str,
output_extension: &str,
design_file: &DesignFile,
options: &SlicerOptions,
options: &BuildOptions,
) -> Result<TemporaryFile> {
// Make sure the config path is a directory.
if !self.config.is_dir() {
Expand Down Expand Up @@ -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<ThreeMfTemporaryFile> {
async fn generate(&self, design_file: &DesignFile, options: &BuildOptions) -> Result<ThreeMfTemporaryFile> {
Ok(ThreeMfTemporaryFile(
self.generate_via_cli("--export-3mf", "3mf", design_file, options)
.await?,
Expand Down
6 changes: 3 additions & 3 deletions src/slicer/prusa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down Expand Up @@ -109,7 +109,7 @@ impl Slicer {
impl GcodeSlicerTrait for Slicer {
type Error = anyhow::Error;

async fn generate(&self, design_file: &DesignFile, _: &SlicerOptions) -> Result<GcodeTemporaryFile> {
async fn generate(&self, design_file: &DesignFile, _: &BuildOptions) -> Result<GcodeTemporaryFile> {
Ok(GcodeTemporaryFile(
self.generate_from_cli("--export-gcode", "gcode", design_file).await?,
))
Expand All @@ -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<ThreeMfTemporaryFile> {
async fn generate(&self, design_file: &DesignFile, _: &BuildOptions) -> Result<ThreeMfTemporaryFile> {
Ok(ThreeMfTemporaryFile(
self.generate_from_cli("--export-3mf", "3mf", design_file).await?,
))
Expand Down
19 changes: 14 additions & 5 deletions src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,17 +311,26 @@ pub struct SlicerConfiguration {
pub filament_idx: Option<usize>,
}

/// 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,

/// 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<Volume>,
}

/// [Control]-specific slicer which takes a particular [DesignFile], and produces
Expand All @@ -335,7 +344,7 @@ pub trait GcodeSlicer {
fn generate(
&self,
design_file: &DesignFile,
options: &SlicerOptions,
options: &BuildOptions,
) -> impl Future<Output = Result<GcodeTemporaryFile, <Self as GcodeSlicer>::Error>>;
}

Expand All @@ -353,7 +362,7 @@ pub trait ThreeMfSlicer {
fn generate(
&self,
design_file: &DesignFile,
options: &SlicerOptions,
options: &BuildOptions,
) -> impl Future<Output = Result<ThreeMfTemporaryFile, <Self as ThreeMfSlicer>::Error>>;
}

Expand Down

0 comments on commit f1187b8

Please sign in to comment.