forked from 1b-agent/opencadstudio-upstream
fix(styles): apply active creation defaults
Resolve style properties before editors and previews open. Use absolute annotation multipliers for style-driven objects. Refs #401 Refs #431
This commit is contained in:
1 parent
53cf31f33d
commit
de2707a23e
14 files changed
+676
-129
No files matched your search
@@ -33,15 +33,25 @@ enum Step {
|
||||
|
||||
pub struct AttdefCommand {
|
||||
step: Step,
|
||||
/// Text height in world units.
|
||||
height: f64,
|
||||
text_style: String,
|
||||
width_factor: f64,
|
||||
oblique_angle: f64,
|
||||
}
|
||||
|
||||
impl AttdefCommand {
|
||||
pub fn new() -> Self {
|
||||
pub fn with_text_defaults(
|
||||
height: f64,
|
||||
text_style: String,
|
||||
width_factor: f64,
|
||||
oblique_angle: f64,
|
||||
) -> Self {
|
||||
Self {
|
||||
step: Step::Tag,
|
||||
height: 0.2,
|
||||
height,
|
||||
text_style,
|
||||
width_factor,
|
||||
oblique_angle,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -130,6 +140,9 @@ impl CadCommand for AttdefCommand {
|
||||
default_value: default.clone(),
|
||||
insertion_point: Vector3::new(pt.x, pt.y, pt.z),
|
||||
height: self.height,
|
||||
text_style: self.text_style.clone(),
|
||||
width_factor: self.width_factor,
|
||||
oblique_angle: self.oblique_angle,
|
||||
..Default::default()
|
||||
};
|
||||
attdef.common.layer = "0".into();
|
||||
|
||||
@@ -19,6 +19,8 @@ pub struct MlineCommand {
|
||||
scale: f64,
|
||||
waiting_scale: bool,
|
||||
style_name: String,
|
||||
style_handle: Option<acadrust::Handle>,
|
||||
style_element_count: usize,
|
||||
}
|
||||
|
||||
impl MlineCommand {
|
||||
@@ -29,15 +31,23 @@ impl MlineCommand {
|
||||
scale: 1.0,
|
||||
waiting_scale: false,
|
||||
style_name: "Standard".into(),
|
||||
style_handle: None,
|
||||
style_element_count: 2,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_style(style_name: impl Into<String>) -> Self {
|
||||
pub fn with_style(
|
||||
style_name: impl Into<String>,
|
||||
style_handle: Option<acadrust::Handle>,
|
||||
style_element_count: usize,
|
||||
) -> Self {
|
||||
Self {
|
||||
points: vec![],
|
||||
scale: 1.0,
|
||||
waiting_scale: false,
|
||||
style_name: style_name.into(),
|
||||
style_handle,
|
||||
style_element_count: style_element_count.max(1),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -94,7 +104,14 @@ impl CadCommand for MlineCommand {
|
||||
|
||||
// Close command
|
||||
if (up == "C" || up == "CLOSE") && self.points.len() >= 3 {
|
||||
let entity = build_mline(&self.points, self.scale, true, &self.style_name);
|
||||
let entity = build_mline(
|
||||
&self.points,
|
||||
self.scale,
|
||||
true,
|
||||
&self.style_name,
|
||||
self.style_handle,
|
||||
self.style_element_count,
|
||||
);
|
||||
return Some(CmdResult::CommitAndExit(entity));
|
||||
}
|
||||
|
||||
@@ -126,7 +143,14 @@ impl CadCommand for MlineCommand {
|
||||
if self.points.len() < 2 {
|
||||
return CmdResult::Cancel;
|
||||
}
|
||||
let entity = build_mline(&self.points, self.scale, false, &self.style_name);
|
||||
let entity = build_mline(
|
||||
&self.points,
|
||||
self.scale,
|
||||
false,
|
||||
&self.style_name,
|
||||
self.style_handle,
|
||||
self.style_element_count,
|
||||
);
|
||||
CmdResult::CommitAndExit(entity)
|
||||
}
|
||||
|
||||
@@ -171,18 +195,25 @@ impl CadCommand for MlineCommand {
|
||||
}
|
||||
}
|
||||
|
||||
fn build_mline(pts: &[DVec3], scale: f64, closed: bool, style_name: &str) -> EntityType {
|
||||
let verts: Vec<Vector3> = pts
|
||||
.iter()
|
||||
.map(|p| Vector3::new(p.x, p.y, p.z))
|
||||
.collect();
|
||||
let mut mline = if closed {
|
||||
MLine::closed_from_points(&verts)
|
||||
} else {
|
||||
MLine::from_points(&verts)
|
||||
};
|
||||
fn build_mline(
|
||||
pts: &[DVec3],
|
||||
scale: f64,
|
||||
closed: bool,
|
||||
style_name: &str,
|
||||
style_handle: Option<acadrust::Handle>,
|
||||
style_element_count: usize,
|
||||
) -> EntityType {
|
||||
let mut mline = MLine::new();
|
||||
mline.scale_factor = scale;
|
||||
mline.style_name = style_name.to_string();
|
||||
mline.style_handle = style_handle;
|
||||
mline.style_element_count = style_element_count;
|
||||
for point in pts {
|
||||
mline.add_vertex(Vector3::new(point.x, point.y, point.z));
|
||||
}
|
||||
if closed {
|
||||
mline.close();
|
||||
}
|
||||
EntityType::MLine(mline)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user