Skip to content

Commit

Permalink
Basic extrusion groups
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom committed Jan 25, 2024
1 parent f56b876 commit 1a9ae17
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
23 changes: 23 additions & 0 deletions detailer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,29 @@ impl<'a> Widget<'a> {
});
})
.body(|ui| {
if group.typ == GroupType::Extrude {
ui.horizontal(|ui| {
let r = ui.available_size();
let text_rect = ui.add(egui::Label::new("Extrusion thickness").wrap(false)).rect;

if text_rect.width() < r.x / 2. {
ui.add_space(r.x / 2. - text_rect.width());
}
let mut amt = group.amt.unwrap_or(3.0);
if ui.add(
egui::DragValue::new(&mut amt)
.clamp_range(0.1..=1000.0)
.suffix("mm")
.min_decimals(2),
).changed() {
if amt == 3.0 {
group.amt = None;
} else {
group.amt = Some(amt);
}
}
});
}
ui.horizontal(|ui| {
let r = ui.available_size();
let text_rect = ui.add(egui::Label::new(format!("{} features", group.features.len())).wrap(false)).rect;
Expand Down
8 changes: 7 additions & 1 deletion drawing/src/data/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ pub struct Group {
pub typ: GroupType,
pub name: String,
pub features: Vec<FeatureKey>,

pub amt: Option<f64>,
}

impl Group {
Expand All @@ -32,6 +34,7 @@ impl Group {
Ok(SerializedGroup {
typ: self.typ,
name: self.name.clone(),
amt: self.amt,
features_idx,
})
}
Expand All @@ -52,6 +55,7 @@ impl Group {
typ: sg.typ,
name: sg.name.clone(),
features,
amt: sg.amt,
})
}

Expand Down Expand Up @@ -153,6 +157,7 @@ pub struct SerializedGroup {
pub typ: GroupType,
pub name: String,
pub features_idx: Vec<usize>,
pub amt: Option<f64>,
}

#[cfg(test)]
Expand All @@ -168,7 +173,8 @@ mod tests {
Group {
typ: GroupType::Boundary,
name: "Ye".into(),
features: vec![point_key]
features: vec![point_key],
amt: None,
}
.serialize(&HashMap::from([(point_key, 42)])),
Ok(SerializedGroup {
Expand Down
4 changes: 3 additions & 1 deletion drawing/src/data/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1171,7 +1171,7 @@ impl Data {
GroupType::Boundary | GroupType::Hole => {}
GroupType::Extrude => {
for p in paths.into_iter() {
ops.push((CADOp::Extrude(3.0), p));
ops.push((CADOp::Extrude(g.amt.unwrap_or(3.0)), p));
}
}
}
Expand Down Expand Up @@ -1411,6 +1411,7 @@ mod tests {
typ: group::GroupType::Boundary,
name: "yolo".into(),
features: vec![p1, p2, l1],
..Group::default()
}];

assert_eq!(
Expand All @@ -1419,6 +1420,7 @@ mod tests {
typ: group::GroupType::Boundary,
name: "yolo".into(),
features_idx: vec![0, 1, 2],
..group::SerializedGroup::default()
},],
);
}
Expand Down

0 comments on commit 1a9ae17

Please sign in to comment.