Skip to content

Commit

Permalink
Add support for Simplify3D
Browse files Browse the repository at this point in the history
  • Loading branch information
dalegaard committed Dec 17, 2022
1 parent 697393b commit d9faf65
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/src/slicer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub enum SlicerPreset {
SuperSlicer { version: String },
IdeaMaker { version: String },
Cura { version: Option<String> },
Simplify3D { version: String },
}

impl std::fmt::Display for SlicerPreset {
Expand All @@ -18,6 +19,7 @@ impl std::fmt::Display for SlicerPreset {
SlicerPreset::Cura {
version: Some(version),
} => write!(f, "Cura {}", version),
SlicerPreset::Simplify3D { version } => write!(f, "Simplify3D {}", version),
}
}
}
Expand All @@ -28,6 +30,7 @@ impl SlicerPreset {
.or_else(|| Self::try_ideamaker(comment))
.or_else(|| Self::try_cura_old(comment))
.or_else(|| Self::try_cura_new(comment))
.or_else(|| Self::try_simplify3d(comment))
}

#[allow(clippy::manual_map)]
Expand Down Expand Up @@ -74,4 +77,13 @@ impl SlicerPreset {
RE.captures(comment)
.map(|_| SlicerPreset::Cura { version: None })
}

fn try_simplify3d(comment: &str) -> Option<SlicerPreset> {
lazy_static! {
static ref RE: Regex = Regex::new(r"Simplify3D\(R\)\sVersion\s(.*)").unwrap();
}
RE.captures(comment).map(|c| SlicerPreset::Simplify3D {
version: c.get(1).unwrap().as_str().into(),
})
}
}
46 changes: 46 additions & 0 deletions tool/src/cmd/post_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,58 @@ impl GCodeInterceptor for CuraGCodeInterceptor {
}
}

#[derive(Debug, Default)]
struct Simplify3DGCodeInterceptor {}

impl Simplify3DGCodeInterceptor {
fn format_dhms(mut time: f64) -> String {
use std::fmt::Write;
let mut out = String::new();
time = time.ceil();
let h = (time / 3600.0).floor();
if h > 0.0 {
write!(out, " {:.0} hours", h).unwrap();
}
time %= 3600.0;
let m = (time / 60.0).floor();
if m > 0.0 {
write!(out, " {:.0} minutes", m).unwrap();
}
time %= 60.0;
let s = time;
write!(out, " {:.0} sec", s).unwrap();
out
}
}

impl GCodeInterceptor for Simplify3DGCodeInterceptor {
fn output_process(
&mut self,
command: &GCodeCommand,
result: &PostProcessEstimationResult,
) -> Option<GCodeCommand> {
if let Some(com) = &command.comment {
if com.starts_with(" Build Time: ") {
return Some(GCodeCommand {
op: GCodeOperation::Nop,
comment: Some(format!(
" Build Time:{}",
Self::format_dhms(result.total_time.ceil())
)),
});
}
}
None
}
}

fn metadata_processor(preset: &SlicerPreset) -> Box<dyn GCodeInterceptor> {
match preset {
SlicerPreset::PrusaSlicer { .. } => Box::<PSSSGCodeInterceptor>::default(),
SlicerPreset::SuperSlicer { .. } => Box::<PSSSGCodeInterceptor>::default(),
SlicerPreset::IdeaMaker { .. } => Box::<IdeaMakerGCodeInterceptor>::default(),
SlicerPreset::Cura { .. } => Box::<CuraGCodeInterceptor>::default(),
SlicerPreset::Simplify3D { .. } => Box::<Simplify3DGCodeInterceptor>::default(),
}
}

Expand Down

0 comments on commit d9faf65

Please sign in to comment.