forked from 1b-agent/opencadstudio-upstream
Merge pull request #1320 from ghost/styled-dimension-preview
This commit is contained in:
commit
79bc800728
23 files changed
+724
-138
No files matched your search
@@ -6,7 +6,8 @@ use cadkernel::geom2d::{
|
||||
};
|
||||
|
||||
use crate::command::{
|
||||
CadCommand, CmdOption, CmdResult, DimensionAssociationInput, InputKind, WorkingPlane,
|
||||
CadCommand, CmdOption, CmdResult, DimensionAssociationInput, DimensionPreview, InputKind,
|
||||
WorkingPlane,
|
||||
};
|
||||
use crate::modules::{IconKind, ModuleEvent, ToolDef};
|
||||
use crate::scene::model::wire_model::WireModel;
|
||||
@@ -107,6 +108,29 @@ impl LinearDimensionCommand {
|
||||
mtext_override: false,
|
||||
}
|
||||
}
|
||||
|
||||
fn build_dimension(&self, first: DVec3, second: DVec3, point: DVec3) -> EntityType {
|
||||
let first = self.plane.to_local(first);
|
||||
let second = self.plane.to_local(second);
|
||||
let point = self.plane.to_local(point);
|
||||
let mut dim = DimensionLinear::new(v3(first), v3(second));
|
||||
let axis = self.axis_mode.axis(first, second, point);
|
||||
dim.rotation = axis.y.atan2(axis.x);
|
||||
dim.set_offset(dimension_line_offset(second, point, axis));
|
||||
dim.base.definition_point = dim.definition_point;
|
||||
dim.base.text_middle_point = v3(linear_text_pos(first, second, point, axis));
|
||||
dim.base.insertion_point = dim.base.text_middle_point;
|
||||
dim.base.actual_measurement = dim.measurement();
|
||||
crate::entities::dimension::set_dimension_text_override(
|
||||
&mut dim.base,
|
||||
self.text_override.clone(),
|
||||
);
|
||||
// An explicit text angle overrides the UCS-derived rotation.
|
||||
if let Some(angle) = self.text_angle {
|
||||
dim.base.text_rotation = angle;
|
||||
}
|
||||
self.plane.place_entity(EntityType::Dimension(Dimension::Linear(dim)))
|
||||
}
|
||||
}
|
||||
|
||||
impl CadCommand for LinearDimensionCommand {
|
||||
@@ -164,28 +188,7 @@ impl CadCommand for LinearDimensionCommand {
|
||||
CmdResult::NeedPoint
|
||||
}
|
||||
Step::DimensionLine { first, second } => {
|
||||
let first = self.plane.to_local(first);
|
||||
let second = self.plane.to_local(second);
|
||||
let pt = self.plane.to_local(pt);
|
||||
let mut dim = DimensionLinear::new(v3(first), v3(second));
|
||||
let axis = self.axis_mode.axis(first, second, pt);
|
||||
dim.rotation = axis.y.atan2(axis.x);
|
||||
dim.set_offset(dimension_line_offset(second, pt, axis));
|
||||
dim.base.definition_point = dim.definition_point;
|
||||
dim.base.text_middle_point = v3(linear_text_pos(first, second, pt, axis));
|
||||
dim.base.insertion_point = dim.base.text_middle_point;
|
||||
dim.base.actual_measurement = dim.measurement();
|
||||
crate::entities::dimension::set_dimension_text_override(
|
||||
&mut dim.base,
|
||||
self.text_override.clone(),
|
||||
);
|
||||
// An explicit text angle overrides the UCS-derived rotation.
|
||||
if let Some(a) = self.text_angle {
|
||||
dim.base.text_rotation = a;
|
||||
}
|
||||
let entity = self.plane.place_entity(EntityType::Dimension(
|
||||
Dimension::Linear(dim),
|
||||
));
|
||||
let entity = self.build_dimension(first, second, pt);
|
||||
CmdResult::CommitDimension {
|
||||
entity,
|
||||
association: DimensionAssociationInput::Infer(self.source_handle),
|
||||
@@ -402,6 +405,23 @@ impl CadCommand for LinearDimensionCommand {
|
||||
ref_point: None,
|
||||
})
|
||||
}
|
||||
|
||||
fn dimension_preview(&self, cursor: DVec3) -> Option<Vec<DimensionPreview>> {
|
||||
if self.selecting_object {
|
||||
return None;
|
||||
}
|
||||
let (first, second) = match self.step {
|
||||
Step::FirstPoint => return None,
|
||||
Step::SecondPoint(first) => (first, cursor),
|
||||
Step::DimensionLine { first, second } => (first, second),
|
||||
};
|
||||
if first.distance_squared(second) <= 1e-24 {
|
||||
return Some(Vec::new());
|
||||
}
|
||||
Some(vec![DimensionPreview::current_style(
|
||||
self.build_dimension(first, second, cursor),
|
||||
)])
|
||||
}
|
||||
}
|
||||
|
||||
fn v3(pt: DVec3) -> Vector3 {
|
||||
|
||||
Reference in new issue
Block a user