Edge-measure rulers too.

This commit is contained in:
Matthias Koefferlein 2024-01-28 19:02:51 +01:00
parent 9184bef6f8
commit 1dbb3917c8
6 changed files with 78 additions and 13 deletions

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>668</width>
<height>410</height>
<width>745</width>
<height>438</height>
</rect>
</property>
<property name="windowTitle">
@ -845,7 +845,12 @@
</item>
<item>
<property name="text">
<string>Angle measurement (three mouse clicks)</string>
<string>Auto measure along edge (points will be set automatically)</string>
</property>
</item>
<item>
<property name="text">
<string>Angle or radius measurement (three mouse clicks)</string>
</property>
</item>
<item>

View File

@ -247,6 +247,8 @@ RulerModeConverter::to_string (ant::Template::ruler_mode_type m)
return "single_click";
} else if (m == ant::Template::RulerAutoMetric) {
return "auto_metric";
} else if (m == ant::Template::RulerAutoMetricEdge) {
return "auto_metric_edge";
} else if (m == ant::Template::RulerMultiSegment) {
return "multi_segment";
} else if (m == ant::Template::RulerThreeClicks) {
@ -266,6 +268,8 @@ RulerModeConverter::from_string (const std::string &s, ant::Template::ruler_mode
a = ant::Template::RulerSingleClick;
} else if (t == "auto_metric") {
a = ant::Template::RulerAutoMetric;
} else if (t == "auto_metric_edge") {
a = ant::Template::RulerAutoMetricEdge;
} else if (t == "multi_segment") {
a = ant::Template::RulerMultiSegment;
} else if (t == "angle") {

View File

@ -60,6 +60,9 @@ static std::vector<ant::Template> make_standard_templates ()
templates.push_back (ant::Template (tl::to_string (tr ("Measure")), "$X", "$Y", "$D", ant::Object::STY_ruler, ant::Object::OL_diag, true, lay::AC_Global, "_measure"));
templates.back ().set_mode (ant::Template::RulerAutoMetric);
templates.push_back (ant::Template (tl::to_string (tr ("Measure edge")), "$X", "$Y", "$D", ant::Object::STY_ruler, ant::Object::OL_diag, true, lay::AC_Global, "_measure_edge"));
templates.back ().set_mode (ant::Template::RulerAutoMetricEdge);
templates.push_back (ant::Template (tl::to_string (tr ("Angle")), "", "", "$(sprintf('%.5g',G))°", ant::Object::STY_line, ant::Object::OL_angle, true, lay::AC_Global, "_angle"));
templates.back ().set_mode (ant::Template::RulerThreeClicks);

View File

@ -1910,6 +1910,29 @@ Service::mouse_click_event (const db::DPoint &p, unsigned int buttons, bool prio
}
} else if (tpl.mode () == ant::Template::RulerAutoMetricEdge) {
lay::PointSnapToObjectResult snap_details = snap1_details (p, true);
if (snap_details.object_snap == lay::PointSnapToObjectResult::ObjectEdge) {
// begin the transaction
if (manager ()) {
tl_assert (! manager ()->transacting ());
manager ()->transaction (tl::to_string (tr ("Create ruler")));
}
m_current = ant::Object (snap_details.object_ref.p1 (), snap_details.object_ref.p2 (), 0, tpl);
show_message ();
insert_ruler (m_current, true);
// end the transaction
if (manager ()) {
manager ()->commit ();
}
}
} else {
m_p1 = snap1 (p, m_obj_snap && tpl.snap ()).second;
@ -2006,7 +2029,7 @@ Service::mouse_move_event (const db::DPoint &p, unsigned int buttons, bool prio)
snap_details = snap2_details (m_p1, p, mp_active_ruler->ruler (), ac_from_buttons (buttons));
} else {
const ant::Template &tpl = current_template ();
snap_details = snap1_details (p, m_obj_snap && tpl.snap ());
snap_details = snap1_details (p, m_obj_snap && tpl.snap () && (tpl.mode () != ant::Template::RulerAutoMetricEdge || ! view ()->transient_selection_mode ()));
}
mouse_cursor_from_snap_details (snap_details);
@ -2356,24 +2379,38 @@ Service::timeout ()
// transiently create an auto-metric ruler if requested
ant::Object *ruler = 0;
const ant::Template &tpl = current_template ();
if (tpl.mode () == ant::Template::RulerAutoMetric) {
lay::TwoPointSnapToObjectResult ee = auto_measure (m_hover_point, ac_from_buttons (m_hover_buttons), tpl);
if (ee.any) {
m_current = ant::Object (ee.first, ee.second, 0, tpl);
ruler = &m_current;
}
// HINT: there is no special style for "transient selection on rulers"
mp_transient_ruler = new ant::View (this, &m_current, true /*not selected*/);
if (! editables ()->has_selection ()) {
display_status (true);
}
} else if (tpl.mode () == ant::Template::RulerAutoMetricEdge) {
lay::PointSnapToObjectResult snap_details = snap1_details (m_hover_point, true);
if (snap_details.object_snap == lay::PointSnapToObjectResult::ObjectEdge) {
m_current = ant::Object (snap_details.object_ref.p1 (), snap_details.object_ref.p2 (), 0, tpl);
ruler = &m_current;
}
}
if (ruler) {
// HINT: there is no special style for "transient selection on rulers"
mp_transient_ruler = new ant::View (this, ruler, true /*not selected*/);
if (! editables ()->has_selection ()) {
display_status (true);
}
}
}
#endif

View File

@ -64,15 +64,20 @@ public:
*/
RulerAutoMetric = 2,
/**
* @brief The ruler is auto-metric along an edge: a single click will place a ruler and the ruler will extend to the edge below
*/
RulerAutoMetricEdge = 3,
/**
* @brief The ruler an angle type (two segments, three mouse clicks) for angle and circle radius measurements
*/
RulerThreeClicks = 3,
RulerThreeClicks = 4,
/**
* @brief The ruler is a multi-segment type
*/
RulerMultiSegment = 4
RulerMultiSegment = 5
};
/**

View File

@ -434,6 +434,11 @@ static int ruler_mode_auto_metric ()
return ant::Template::RulerAutoMetric;
}
static int ruler_mode_auto_metric_edge ()
{
return ant::Template::RulerAutoMetricEdge;
}
static int ruler_mode_three_clicks ()
{
return ant::Template::RulerThreeClicks;
@ -525,6 +530,12 @@ gsi::Class<AnnotationRef> decl_Annotation (decl_BasicAnnotation, "lay", "Annotat
"\n"
"This constant has been introduced in version 0.25"
) +
gsi::method ("RulerModeAutoMetricEdge", &gsi::ruler_mode_auto_metric_edge,
"@brief Specifies edge-sensitive auto-metric ruler mode for the \\register_template method\n"
"In auto-metric mode, a ruler can be placed with a single click and p1/p2 will be determined from the edge it is placed on.\n"
"\n"
"This constant has been introduced in version 0.29"
) +
gsi::method ("RulerThreeClicks", &gsi::ruler_mode_three_clicks,
"@brief Specifies three-click ruler mode for the \\register_template method\n"
"In this ruler mode, two segments are created for angle and circle radius measurements. Three mouse clicks are required.\n"