Skip to content

Commit

Permalink
Merge branch 'wip2'
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Koefferlein committed Feb 18, 2024
2 parents b491531 + 3a83175 commit 890b389
Show file tree
Hide file tree
Showing 24 changed files with 595 additions and 160 deletions.
11 changes: 8 additions & 3 deletions src/ant/ant/RulerConfigPage4.ui
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down Expand Up @@ -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>
Expand Down
4 changes: 4 additions & 0 deletions src/ant/ant/antConfig.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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") {
Expand Down
3 changes: 3 additions & 0 deletions src/ant/ant/antPlugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
192 changes: 161 additions & 31 deletions src/ant/ant/antService.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1056,8 +1056,18 @@ Service::Service (db::Manager *manager, lay::LayoutViewBase *view)
m_drawing (false), m_current (),
m_move_mode (MoveNone),
m_seg_index (0),
m_current_template (0)
{
m_current_template (0),
m_hover (false),
m_hover_wait (false),
m_hover_buttons (0),
m_mouse_in_window (false)
{
#if defined(HAVE_QT)
m_timer.setInterval (100 /*hover time*/);
m_timer.setSingleShot (true);
connect (&m_timer, SIGNAL (timeout ()), this, SLOT (timeout ()));
#endif

mp_view->annotations_changed_event.add (this, &Service::annotations_changed);
}

Expand Down Expand Up @@ -1809,9 +1819,36 @@ Service::mouse_double_click_event (const db::DPoint & /*p*/, unsigned int button
return false;
}

lay::TwoPointSnapToObjectResult
Service::auto_measure (const db::DPoint &p, lay::angle_constraint_type ac, const ant::Template &tpl)
{
// for auto-metric we need some cutline constraint - any or global won't do.
if (ac == lay::AC_Global) {
ac = tpl.angle_constraint ();
}
if (ac == lay::AC_Global) {
ac = m_snap_mode;
}
if (ac == lay::AC_Global) {
ac = lay::AC_Diagonal;
}

db::DVector g;
if (m_grid_snap) {
g = db::DVector (m_grid, m_grid);
}

double snap_range = ui ()->mouse_event_trans ().inverted ().ctrans (m_snap_range);
snap_range *= 0.5;

return lay::obj_snap2 (mp_view, p, g, ac, snap_range, snap_range * 1000.0);
}

bool
Service::mouse_click_event (const db::DPoint &p, unsigned int buttons, bool prio)
{
hover_reset ();

if (prio && (buttons & lay::LeftButton) != 0) {

const ant::Template &tpl = current_template ();
Expand Down Expand Up @@ -1852,36 +1889,39 @@ Service::mouse_click_event (const db::DPoint &p, unsigned int buttons, bool prio

} else if (tpl.mode () == ant::Template::RulerAutoMetric) {

// for auto-metric we need some cutline constraint - any or global won't do.
lay::angle_constraint_type ac = ac_from_buttons (buttons);
if (ac == lay::AC_Global) {
ac = tpl.angle_constraint ();
}
if (ac == lay::AC_Global) {
ac = m_snap_mode;
}
if (ac == lay::AC_Global) {
ac = lay::AC_Diagonal;
}
lay::TwoPointSnapToObjectResult ee = auto_measure (p, ac_from_buttons (buttons), tpl);
if (ee.any) {

// begin the transaction
if (manager ()) {
tl_assert (! manager ()->transacting ());
manager ()->transaction (tl::to_string (tr ("Create ruler")));
}

m_current = ant::Object (ee.first, ee.second, 0, tpl);
show_message ();

insert_ruler (m_current, true);

// end the transaction
if (manager ()) {
manager ()->commit ();
}

db::DVector g;
if (m_grid_snap) {
g = db::DVector (m_grid, m_grid);
}

double snap_range = ui ()->mouse_event_trans ().inverted ().ctrans (m_snap_range);
snap_range *= 0.5;
} else if (tpl.mode () == ant::Template::RulerAutoMetricEdge) {

lay::TwoPointSnapToObjectResult ee = lay::obj_snap2 (mp_view, p, g, ac, snap_range, snap_range * 1000.0);
if (ee.any) {
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 (ee.first, ee.second, 0, tpl);
m_current = ant::Object (snap_details.object_ref.p1 (), snap_details.object_ref.p2 (), 0, tpl);
show_message ();

insert_ruler (m_current, true);
Expand Down Expand Up @@ -1968,21 +2008,33 @@ Service::create_measure_ruler (const db::DPoint &pt, lay::angle_constraint_type
bool
Service::mouse_move_event (const db::DPoint &p, unsigned int buttons, bool prio)
{
if (prio) {
if (! prio) {
return false;
}

lay::PointSnapToObjectResult snap_details;
if (m_drawing) {
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 ());
}
if (! m_drawing && m_mouse_in_window && view ()->transient_selection_mode ()) {

// Restart hover timer
m_hover_wait = true;
#if defined(HAVE_QT)
m_timer.start ();
#endif
m_hover_point = p;
m_hover_buttons = buttons;

mouse_cursor_from_snap_details (snap_details);
}

lay::PointSnapToObjectResult snap_details;
if (m_drawing) {
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 () && (tpl.mode () != ant::Template::RulerAutoMetricEdge || ! view ()->transient_selection_mode ()));
}

if (m_drawing && prio) {
mouse_cursor_from_snap_details (snap_details);

if (m_drawing) {

set_cursor (lay::Cursor::cross);

Expand Down Expand Up @@ -2284,6 +2336,84 @@ Service::click_proximity (const db::DPoint &pos, lay::Editable::SelectionMode mo
}
}

bool
Service::enter_event (bool /*prio*/)
{
m_mouse_in_window = true;
return false;
}

bool
Service::leave_event (bool)
{
m_mouse_in_window = false;
hover_reset ();
return false;
}

void
Service::hover_reset ()
{
if (m_hover_wait) {
#if defined(HAVE_QT)
m_timer.stop ();
#endif
m_hover_wait = false;
}
if (m_hover) {
// as we use the transient selection for the hover ruler, we have to remove it here
clear_transient_selection ();
m_hover = false;
}
}

#if defined(HAVE_QT)
void
Service::timeout ()
{
m_hover_wait = false;
m_hover = true;

// as we use the transient selection for the hover ruler, we have to remove it here
clear_transient_selection ();

// 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;
}

} 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

bool
Service::transient_select (const db::DPoint &pos)
{
Expand Down
50 changes: 47 additions & 3 deletions src/ant/ant/antService.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
#include <map>
#include <vector>

#if defined (HAVE_QT)
# include <QTimer>
# include <QObject>
#endif

namespace ant {

class LayoutViewBase;
Expand Down Expand Up @@ -177,12 +182,19 @@ class ANT_PUBLIC AnnotationIterator

// -------------------------------------------------------------

class ANT_PUBLIC Service
: public lay::EditorServiceBase,
class ANT_PUBLIC Service :
#if defined (HAVE_QT)
public QObject,
#endif
public lay::EditorServiceBase,
public lay::Drawing,
public db::Object
{
public:
#if defined (HAVE_QT)
Q_OBJECT
#endif

public:
typedef lay::AnnotationShapes::iterator obj_iterator;

/**
Expand Down Expand Up @@ -341,6 +353,21 @@ class ANT_PUBLIC Service
*/
virtual db::DBox selection_bbox ();

/**
* @brief Implementation of the editables API
*/
virtual bool enter_event (bool);

/**
* @brief Implementation of the editables API
*/
virtual bool leave_event (bool);

/**
* @brief Implementation of the editables API
*/
virtual void hover_reset ();

/**
* @brief Transform the selection (reimplementation of lay::Editable interface)
*/
Expand Down Expand Up @@ -506,6 +533,11 @@ class ANT_PUBLIC Service
*/
tl::Event annotation_selection_changed_event;

#if defined (HAVE_QT)
public slots:
void timeout ();
#endif

private:
// Ruler display and snapping configuration
tl::Color m_color;
Expand Down Expand Up @@ -551,10 +583,22 @@ class ANT_PUBLIC Service
std::vector<ant::Template> m_ruler_templates;
unsigned int m_current_template;

// Hover detector
bool m_hover;
bool m_hover_wait;
db::DPoint m_hover_point;
unsigned int m_hover_buttons;
#if defined (HAVE_QT)
QTimer m_timer;
#endif

bool m_mouse_in_window;

std::pair<bool, db::DPoint> snap1 (const db::DPoint &p, bool obj_snap);
lay::PointSnapToObjectResult snap1_details (const db::DPoint &p, bool obj_snap);
std::pair<bool, db::DPoint> snap2 (const db::DPoint &p1, const db::DPoint &p2, const ant::Object *obj, lay::angle_constraint_type ac);
lay::PointSnapToObjectResult snap2_details (const db::DPoint &p1, const db::DPoint &p2, const ant::Object *obj, lay::angle_constraint_type ac);
lay::TwoPointSnapToObjectResult auto_measure (const db::DPoint &p, lay::angle_constraint_type ac, const ant::Template &tpl);

const ant::Template &current_template () const;

Expand Down
Loading

0 comments on commit 890b389

Please sign in to comment.