Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
Inkscape::UI::Tools::MeasureTool Class Reference

#include <measure-tool.h>

Inheritance diagram for Inkscape::UI::Tools::MeasureTool:
Inkscape::UI::Tools::ToolBase

Public Member Functions

 MeasureTool (SPDesktop *desktop)
 
 ~MeasureTool () override
 
bool root_handler (CanvasEvent const &event) override
 
void showCanvasItems (bool to_guides=false, bool to_item=false, bool to_phantom=false, Inkscape::XML::Node *measure_repr=nullptr)
 
void reverseKnots ()
 
void toGuides ()
 
void toPhantom ()
 
void toMarkDimension ()
 
void toItem ()
 
void reset ()
 
void setMarkers ()
 
void setMarker (bool isStart)
 
Geom::Point readMeasurePoint (bool is_start) const
 
void writeMeasurePoint (Geom::Point point, bool is_start) const
 
void showInfoBox (Geom::Point cursor, bool into_groups)
 
void showItemInfoText (Geom::Point pos, Glib::ustring const &measure_str, double fontsize)
 
void setGuide (Geom::Point origin, double angle, const char *label)
 
void setPoint (Geom::Point origin, Inkscape::XML::Node *measure_repr)
 
void setLine (Geom::Point start_point, Geom::Point end_point, bool markers, guint32 color, Inkscape::XML::Node *measure_repr=nullptr)
 
void setMeasureCanvasText (bool is_angle, double precision, double amount, double fontsize, Glib::ustring unit_name, Geom::Point position, guint32 background, bool to_left, bool to_item, bool to_phantom, Inkscape::XML::Node *measure_repr, Glib::ustring label="")
 
void setMeasureCanvasItem (Geom::Point position, bool to_item, bool to_phantom, Inkscape::XML::Node *measure_repr)
 
void setMeasureCanvasControlLine (Geom::Point start, Geom::Point end, bool to_item, bool to_phantom, Inkscape::CanvasItemColor color, Inkscape::XML::Node *measure_repr)
 
void setLabelText (Glib::ustring const &value, Geom::Point pos, double fontsize, Geom::Coord angle, guint32 background, Inkscape::XML::Node *measure_repr=nullptr)
 
void knotStartMovedHandler (SPKnot *, Geom::Point const &ppointer, guint state)
 
void knotEndMovedHandler (SPKnot *, Geom::Point const &ppointer, guint state)
 
void knotClickHandler (SPKnot *knot, guint state)
 
void knotUngrabbedHandler (SPKnot *, unsigned int)
 
void setMeasureItem (Geom::PathVector pathv, bool is_curve, bool markers, guint32 color, Inkscape::XML::Node *measure_repr)
 Create a measure item in current document.
 
void createAngleDisplayCurve (Geom::Point const &center, Geom::Point const &end, Geom::Point const &anchor, double angle, bool to_phantom, Inkscape::XML::Node *measure_repr=nullptr)
 Given an angle, the arc center and edge point, draw an arc segment centered around that edge point.
 
void copyToClipboard ()
 Copies some measurements to the clipboard.
 
std::vector< Geom::PointcalcDeltaBasePoint (double dX, double dY)
 Calculates the base point from which to draw the dX and dY lines.
 
bool equalWithinRange (double value, double reference_value, double epsilon, bool positiveAllowed=true, bool negativeAllowed=true)
 Checks if a value is very close to a reference value and can be considered equal to it.
 
- Public Member Functions inherited from Inkscape::UI::Tools::ToolBase
 ToolBase (SPDesktop *desktop, std::string &&prefs_path, std::string &&cursor_filename, bool uses_snap=true)
 
virtual ~ToolBase ()
 
virtual void set (Preferences::Entry const &val)
 Called by our pref_observer if a preference has been changed.
 
virtual bool item_handler (SPItem *item, CanvasEvent const &event)
 Handles item specific events.
 
virtual void menu_popup (CanvasEvent const &event, SPObject *obj=nullptr)
 Create popup menu and tell Gtk to show it.
 
virtual bool can_undo (bool redo=false)
 
virtual bool is_ready () const
 
virtual void switching_away (std::string const &new_tool)
 
std::string const & getPrefsPath () const
 
void enableSelectionCue (bool enable=true)
 Enables/disables the ToolBase's SelCue.
 
MessageContextdefaultMessageContext () const
 
SPDesktopgetDesktop () const
 
SPGroupcurrentLayer () const
 
void set_last_active_tool (Glib::ustring last_tool)
 
const Glib::ustring & get_last_active_tool () const
 
bool start_root_handler (CanvasEvent const &event)
 Handles snapping events for all tools and then passes to tool_root_handler.
 
bool tool_root_handler (CanvasEvent const &event)
 Calls the right tool's event handler, depending on the selected tool and state.
 
bool start_item_handler (SPItem *item, CanvasEvent const &event)
 Starts handling item snapping and pass to virtual_item_handler afterwards.
 
bool virtual_item_handler (SPItem *item, CanvasEvent const &event)
 
bool is_panning () const
 True if we're panning with any method (space bar, middle-mouse, right-mouse+Ctrl)
 
bool is_space_panning () const
 True if we're panning with the space bar.
 
void snap_delay_handler (gpointer item, gpointer item2, MotionEvent const &event, DelayedSnapEvent::Origin origin)
 Analyses the current event, calculates the mouse speed, turns snapping off (temporarily) if the mouse speed is above a threshold, and stores the current event such that it can be re-triggered when needed (re-triggering is controlled by a timeout).
 
void process_delayed_snap_event ()
 When the delayed snap event timer expires, this method will be called and will re-inject the last motion event in an appropriate place, with snapping being turned on again.
 
void discard_delayed_snap_event ()
 If a delayed snap event has been scheduled, this function will cancel it.
 
void set_cursor (std::string filename)
 Sets the current cursor to the given filename.
 
void use_cursor (Glib::RefPtr< Gdk::Cursor > cursor)
 Set the cursor to this specific one, don't remember it.
 
Glib::RefPtr< Gdk::Cursor > get_cursor (Gtk::Widget &widget, std::string const &filename) const
 Returns the Gdk Cursor for the given filename.
 
void use_tool_cursor ()
 Uses the saved cursor, based on the saved filename.
 
void enableGrDrag (bool enable=true)
 
bool deleteSelectedDrag (bool just_one)
 Delete a selected GrDrag point.
 
bool hasGradientDrag () const
 Return true if there is a gradient drag.
 
GrDragget_drag ()
 

Public Attributes

MT::ClipboardMeaClass clipBMeas
 
- Public Attributes inherited from Inkscape::UI::Tools::ToolBase
std::unique_ptr< MessageContextmessage_context
 
SelCue_selcue = nullptr
 
GrDrag_grdrag = nullptr
 
ShapeEditorshape_editor = nullptr
 
bool _uses_snap = false
 

Private Attributes

std::optional< Geom::Pointexplicit_base
 
std::optional< Geom::Pointlast_end
 
SPKnotknot_start = nullptr
 
SPKnotknot_end = nullptr
 
int dimension_offset = 20
 
Geom::Point start_p
 
Geom::Point end_p
 
Geom::Point last_pos
 
std::vector< CanvasItemPtr< CanvasItem > > measure_tmp_items
 
std::vector< CanvasItemPtr< CanvasItem > > measure_phantom_items
 
std::vector< CanvasItemPtr< CanvasItem > > measure_item
 
double item_width
 
double item_height
 
double item_x
 
double item_y
 
double item_length
 
SPItemover
 
sigc::scoped_connection _knot_start_moved_connection
 
sigc::scoped_connection _knot_start_ungrabbed_connection
 
sigc::scoped_connection _knot_start_click_connection
 
sigc::scoped_connection _knot_end_moved_connection
 
sigc::scoped_connection _knot_end_click_connection
 
sigc::scoped_connection _knot_end_ungrabbed_connection
 

Additional Inherited Members

- Protected Member Functions inherited from Inkscape::UI::Tools::ToolBase
void setup_for_drag_start (ButtonPressEvent const &ev)
 
void saveDragOrigin (Geom::Point const &pos)
 
bool checkDragMoved (Geom::Point const &pos)
 Analyse the current position and return true once it has moved farther than tolerance from the drag origin (indicating they intend to move the object, not click).
 
void grabCanvasEvents (EventMask mask=EventType::KEY_PRESS|EventType::BUTTON_RELEASE|EventType::MOTION|EventType::BUTTON_PRESS)
 Grab events from the Canvas Catchall.
 
void ungrabCanvasEvents ()
 Ungrab events from the Canvas Catchall.
 
bool sp_event_context_knot_mouseover () const
 Returns true if we're hovering above a knot (needed because we don't want to pre-snap in that case).
 
void set_high_motion_precision (bool high_precision=true)
 Enable (or disable) high precision for motion events.
 
- Protected Attributes inherited from Inkscape::UI::Tools::ToolBase
Glib::RefPtr< Gdk::Cursor > _cursor
 
std::string _cursor_filename = "select.svg"
 
std::string _cursor_default = "select.svg"
 
Geom::IntPoint xyp
 where drag started
 
bool dragging = false
 are we dragging?
 
int tolerance = 0
 
bool within_tolerance = false
 are we still within tolerance of origin
 
bool _button1on = false
 
bool _button2on = false
 
bool _button3on = false
 
SPItemitem_to_select = nullptr
 the item where mouse_press occurred, to be selected if this is a click not drag
 
SPDesktop_desktop = nullptr
 
Util::ActionAccel _acc_undo
 
Util::ActionAccel _acc_redo
 
Util::ActionAccel _acc_quick_preview
 
Util::ActionAccel _acc_quick_zoom
 
Util::ActionAccel _acc_quick_pan
 

Detailed Description

Definition at line 121 of file measure-tool.h.

Constructor & Destructor Documentation

◆ MeasureTool()

◆ ~MeasureTool()

Inkscape::UI::Tools::MeasureTool::~MeasureTool ( )
override

Member Function Documentation

◆ calcDeltaBasePoint()

std::vector< Geom::Point > Inkscape::UI::Tools::MeasureTool::calcDeltaBasePoint ( double  dX,
double  dY 
)

Calculates the base point from which to draw the dX and dY lines.

It puts the point on the opposite side from where the angle is drawn The returned array contains the following points:

___point0 is the base point; ___point1 is the dX normal; ___point2 is the dY normal;
___point3 is the dXbase (mid point along the dX line);
___point4 is the dYbase (mid point along the dY line)

Definition at line 1700 of file measure-tool.cpp.

References end_p, result, start_p, Geom::X, and Geom::Y.

Referenced by showCanvasItems().

◆ copyToClipboard()

void Inkscape::UI::Tools::MeasureTool::copyToClipboard ( )

Copies some measurements to the clipboard.

It deals with Alt + C event

It copies the measurements to the clipboard. The settings for what should be copied are in the MeasureToolSettingsDialog. The path to the settings of the MeasureToolSettingsDialog is saved in the preferences, so if for any reason the path of the MeasureToolSettingsDialog is changed, no change is needed here. Probably all settings can go in /tools/measure/, but the other dialogs have their own path starting with /dialog/, so I have done it the same.

The measurements are unset only when they are not visible, visible measurements are always accurate. Measurements that are not visible have not been (re)calculated, so the stored value may be inaccurate.

Definition at line 1552 of file measure-tool.cpp.

References Inkscape::UI::Tools::ToolBase::_desktop, Inkscape::UI::Tools::MT::ANGLE, clipBMeas, Inkscape::UI::Tools::MT::ClipboardMeaClass::composeMeaStr(), Inkscape::UI::ClipboardManager::copyString(), Inkscape::UI::Tools::MT::DX, Inkscape::UI::Tools::MT::DY, Inkscape::MessageStack::flash(), Inkscape::Preferences::get(), Inkscape::UI::ClipboardManager::get(), Inkscape::Preferences::getBool(), Inkscape::Preferences::getInt(), Inkscape::Preferences::getString(), Inkscape::INFORMATION_MESSAGE, key, Inkscape::UI::Tools::MT::LENGTH, Inkscape::UI::Tools::MT::LENGTH_BETWEEN, Inkscape::UI::Tools::MT::ClipboardMeaClass::lengths, Inkscape::UI::Tools::MT::ClipboardMeaClass::measureIsSet, SPDesktop::messageStack(), Inkscape::UI::Tools::MT::ClipboardMeaClass::segLengths, Inkscape::UI::Tools::MT::SEGMENT, Inkscape::UI::Tools::MT::SHAPE_HEIGHT, Inkscape::UI::Tools::MT::SHAPE_LENGTH, Inkscape::UI::Tools::MT::SHAPE_WIDTH, Inkscape::UI::Tools::MT::SHAPE_X, Inkscape::UI::Tools::MT::SHAPE_Y, and Inkscape::UI::Tools::MT::ClipboardMeaClass::symbols.

Referenced by root_handler().

◆ createAngleDisplayCurve()

void Inkscape::UI::Tools::MeasureTool::createAngleDisplayCurve ( Geom::Point const &  center,
Geom::Point const &  end,
Geom::Point const &  anchor,
double  angle,
bool  to_phantom,
Inkscape::XML::Node measure_repr = nullptr 
)

Given an angle, the arc center and edge point, draw an arc segment centered around that edge point.

Parameters
desktopthe desktop that is being used.
centerthe center point for the arc.
endthe point that ends at the edge of the arc segment.
anchorthe anchor point for displaying the text label.
anglethe angle of the arc segment to draw.
measure_rprthe container of the curve if converted to items.

Definition at line 224 of file measure-tool.cpp.

References Inkscape::UI::Tools::ToolBase::_desktop, Geom::Path::appendNew(), Inkscape::CANVAS_ITEM_SECONDARY, Inkscape::LayerManager::currentLayer(), SPDesktop::doc2dt(), Geom::PathVector::empty(), Inkscape::UI::end, SPDesktop::getCanvasTemp(), SPDesktop::layerManager(), measure_phantom_items, measure_tmp_items, Geom::PathVector::push_back(), setMeasureItem(), Geom::Path::start(), Geom::X, and Geom::Y.

Referenced by showCanvasItems().

◆ equalWithinRange()

bool Inkscape::UI::Tools::MeasureTool::equalWithinRange ( double  value,
double  reference_value,
double  epsilon,
bool  positiveAllowed = true,
bool  negativeAllowed = true 
)

Checks if a value is very close to a reference value and can be considered equal to it.

Parameters
epsilonthe value of the acceptable discrepancy from true equality
positiveAllowedif true (default) it checks for reference_value + epsilon range
negativeAllowedif true (default) it checks for reference_value - epsilon range

If value is not allowed to cross a limit, then the range can be limited to either side of the limit by setting the appropriate flag to false

Definition at line 1756 of file measure-tool.cpp.

Referenced by showCanvasItems().

◆ knotClickHandler()

void Inkscape::UI::Tools::MeasureTool::knotClickHandler ( SPKnot knot,
guint  state 
)

◆ knotEndMovedHandler()

◆ knotStartMovedHandler()

◆ knotUngrabbedHandler()

void Inkscape::UI::Tools::MeasureTool::knotUngrabbedHandler ( SPKnot ,
unsigned int   
)

Definition at line 443 of file measure-tool.cpp.

References end_p, knot_end, knot_start, SPKnot::moveto(), showCanvasItems(), and start_p.

Referenced by MeasureTool().

◆ readMeasurePoint()

Geom::Point Inkscape::UI::Tools::MeasureTool::readMeasurePoint ( bool  is_start) const

◆ reset()

void Inkscape::UI::Tools::MeasureTool::reset ( )

Definition at line 949 of file measure-tool.cpp.

References SPKnot::hide(), knot_end, knot_start, and measure_tmp_items.

Referenced by toItem().

◆ reverseKnots()

void Inkscape::UI::Tools::MeasureTool::reverseKnots ( )

◆ root_handler()

◆ setGuide()

◆ setLabelText()

◆ setLine()

◆ setMarker()

◆ setMarkers()

void Inkscape::UI::Tools::MeasureTool::setMarkers ( )

◆ setMeasureCanvasControlLine()

void Inkscape::UI::Tools::MeasureTool::setMeasureCanvasControlLine ( Geom::Point  start,
Geom::Point  end,
bool  to_item,
bool  to_phantom,
Inkscape::CanvasItemColor  color,
Inkscape::XML::Node measure_repr 
)

◆ setMeasureCanvasItem()

void Inkscape::UI::Tools::MeasureTool::setMeasureCanvasItem ( Geom::Point  position,
bool  to_item,
bool  to_phantom,
Inkscape::XML::Node measure_repr 
)

◆ setMeasureCanvasText()

void Inkscape::UI::Tools::MeasureTool::setMeasureCanvasText ( bool  is_angle,
double  precision,
double  amount,
double  fontsize,
Glib::ustring  unit_name,
Geom::Point  position,
guint32  background,
bool  to_left,
bool  to_item,
bool  to_phantom,
Inkscape::XML::Node measure_repr,
Glib::ustring  label = "" 
)

◆ setMeasureItem()

◆ setPoint()

◆ showCanvasItems()

void Inkscape::UI::Tools::MeasureTool::showCanvasItems ( bool  to_guides = false,
bool  to_item = false,
bool  to_phantom = false,
Inkscape::XML::Node measure_repr = nullptr 
)

Definition at line 1159 of file measure-tool.cpp.

References Inkscape::UI::Tools::ToolBase::_desktop, Inkscape::UI::Tools::MT::ANGLE, Geom::Path::appendNew(), calcDeltaBasePoint(), Inkscape::UI::Tools::calculate_intersections(), Inkscape::CANVAS_ITEM_PRIMARY, Inkscape::CANVAS_ITEM_SECONDARY, clipBMeas, Inkscape::Util::Quantity::convert(), createAngleDisplayCurve(), Inkscape::LayerManager::currentLayer(), SPDesktop::d2w(), dimension_offset, SPDesktop::dkey, SPDesktop::doc2dt(), SPDesktop::dt2doc(), Inkscape::UI::Tools::MT::DX, Inkscape::UI::Tools::MT::DY, Inkscape::UI::end, end_p, equalWithinRange(), explicit_base, Inkscape::UI::Tools::fontsize, Inkscape::Preferences::get(), SPDesktop::getDocument(), SPDocument::getItemsPartiallyInBox(), SPDesktop::getSelection(), Inkscape::Selection::includes(), Geom::Point::isFinite(), item, items, Inkscape::LayerManager::layerForObject(), SPDesktop::layerManager(), Inkscape::UI::Tools::MT::LENGTH, Inkscape::UI::Tools::MT::LENGTH_BETWEEN, Inkscape::UI::Tools::MT::ClipboardMeaClass::lengths, measure_tmp_items, Inkscape::UI::Tools::MT::ClipboardMeaClass::measureIsSet, Inkscape::Text::Layout::iterator::nextGlyph(), origin, pathv_to_linear_and_cubic_beziers(), Geom::PathVector::pointAt(), Geom::PathVector::push_back(), Geom::rot90(), scale, Inkscape::UI::Tools::MT::ClipboardMeaClass::segLengths, Inkscape::UI::Tools::MT::SEGMENT, setGuide(), setMeasureCanvasControlLine(), setMeasureCanvasItem(), setMeasureCanvasText(), Geom::Path::start(), Inkscape::UI::start, start_p, Inkscape::UI::Tools::MT::ClipboardMeaClass::symbols, te_get_layout(), Geom::unit_vector(), SPDesktop::w2d(), writeMeasurePoint(), Geom::X, and Geom::Y.

Referenced by knotEndMovedHandler(), knotStartMovedHandler(), knotUngrabbedHandler(), MeasureTool(), reverseKnots(), root_handler(), toGuides(), toItem(), and toPhantom().

◆ showInfoBox()

◆ showItemInfoText()

void Inkscape::UI::Tools::MeasureTool::showItemInfoText ( Geom::Point  pos,
Glib::ustring const &  measure_str,
double  fontsize 
)

◆ toGuides()

◆ toItem()

◆ toMarkDimension()

◆ toPhantom()

◆ writeMeasurePoint()

void Inkscape::UI::Tools::MeasureTool::writeMeasurePoint ( Geom::Point  point,
bool  is_start 
) const

Member Data Documentation

◆ _knot_end_click_connection

sigc::scoped_connection Inkscape::UI::Tools::MeasureTool::_knot_end_click_connection
private

Definition at line 195 of file measure-tool.h.

Referenced by MeasureTool().

◆ _knot_end_moved_connection

sigc::scoped_connection Inkscape::UI::Tools::MeasureTool::_knot_end_moved_connection
private

Definition at line 194 of file measure-tool.h.

Referenced by MeasureTool().

◆ _knot_end_ungrabbed_connection

sigc::scoped_connection Inkscape::UI::Tools::MeasureTool::_knot_end_ungrabbed_connection
private

Definition at line 196 of file measure-tool.h.

Referenced by MeasureTool().

◆ _knot_start_click_connection

sigc::scoped_connection Inkscape::UI::Tools::MeasureTool::_knot_start_click_connection
private

Definition at line 193 of file measure-tool.h.

Referenced by MeasureTool().

◆ _knot_start_moved_connection

sigc::scoped_connection Inkscape::UI::Tools::MeasureTool::_knot_start_moved_connection
private

Definition at line 191 of file measure-tool.h.

Referenced by MeasureTool().

◆ _knot_start_ungrabbed_connection

sigc::scoped_connection Inkscape::UI::Tools::MeasureTool::_knot_start_ungrabbed_connection
private

Definition at line 192 of file measure-tool.h.

Referenced by MeasureTool().

◆ clipBMeas

MT::ClipboardMeaClass Inkscape::UI::Tools::MeasureTool::clipBMeas

Definition at line 169 of file measure-tool.h.

Referenced by copyToClipboard(), showCanvasItems(), and showInfoBox().

◆ dimension_offset

int Inkscape::UI::Tools::MeasureTool::dimension_offset = 20
private

Definition at line 176 of file measure-tool.h.

Referenced by showCanvasItems(), and toMarkDimension().

◆ end_p

◆ explicit_base

std::optional<Geom::Point> Inkscape::UI::Tools::MeasureTool::explicit_base
private

Definition at line 172 of file measure-tool.h.

Referenced by knotClickHandler(), root_handler(), showCanvasItems(), and toGuides().

◆ item_height

double Inkscape::UI::Tools::MeasureTool::item_height
private

Definition at line 186 of file measure-tool.h.

Referenced by showInfoBox().

◆ item_length

double Inkscape::UI::Tools::MeasureTool::item_length
private

Definition at line 189 of file measure-tool.h.

Referenced by showInfoBox().

◆ item_width

double Inkscape::UI::Tools::MeasureTool::item_width
private

Definition at line 185 of file measure-tool.h.

Referenced by showInfoBox().

◆ item_x

double Inkscape::UI::Tools::MeasureTool::item_x
private

Definition at line 187 of file measure-tool.h.

Referenced by showInfoBox().

◆ item_y

double Inkscape::UI::Tools::MeasureTool::item_y
private

Definition at line 188 of file measure-tool.h.

Referenced by showInfoBox().

◆ knot_end

SPKnot* Inkscape::UI::Tools::MeasureTool::knot_end = nullptr
private

◆ knot_start

SPKnot* Inkscape::UI::Tools::MeasureTool::knot_start = nullptr
private

◆ last_end

std::optional<Geom::Point> Inkscape::UI::Tools::MeasureTool::last_end
private

Definition at line 173 of file measure-tool.h.

Referenced by root_handler().

◆ last_pos

Geom::Point Inkscape::UI::Tools::MeasureTool::last_pos
private

Definition at line 179 of file measure-tool.h.

Referenced by root_handler().

◆ measure_item

std::vector<CanvasItemPtr<CanvasItem> > Inkscape::UI::Tools::MeasureTool::measure_item
private

Definition at line 183 of file measure-tool.h.

Referenced by root_handler(), showInfoBox(), showItemInfoText(), and toItem().

◆ measure_phantom_items

std::vector<CanvasItemPtr<CanvasItem> > Inkscape::UI::Tools::MeasureTool::measure_phantom_items
private

◆ measure_tmp_items

std::vector<CanvasItemPtr<CanvasItem> > Inkscape::UI::Tools::MeasureTool::measure_tmp_items
private

◆ over

SPItem* Inkscape::UI::Tools::MeasureTool::over
private

Definition at line 190 of file measure-tool.h.

Referenced by showInfoBox().

◆ start_p


The documentation for this class was generated from the following files: