1 // SPDX-License-Identifier: GPL-2.0-or-later
2 #ifndef CANVAS_AXONOMGRID_H
3 #define CANVAS_AXONOMGRID_H
4 
5 /*
6  * Authors:
7  *    Johan Engelen <j.b.c.engelen@alumnus.utwente.nl>
8  *
9  * Copyright (C) 2006-2012 Authors
10  * Released under GNU GPL v2+, read the file 'COPYING' for more information.
11  */
12 
13 #include "line-snapper.h"
14 #include "canvas-grid.h"
15 
16 class SPNamedView;
17 
18 namespace Inkscape {
19 class CanvasItemBuffer;
20 namespace XML {
21     class Node;
22 };
23 
24 class CanvasAxonomGrid : public CanvasGrid {
25 public:
26     CanvasAxonomGrid(SPNamedView * nv, Inkscape::XML::Node * in_repr, SPDocument * in_doc);
27     ~CanvasAxonomGrid() override;
28 
29     void Update (Geom::Affine const &affine, unsigned int flags) override;
30     void Render (Inkscape::CanvasItemBuffer *buf) override;
31 
32     void readRepr() override;
33     void onReprAttrChanged (Inkscape::XML::Node * repr, char const *key, char const *oldval, char const *newval, bool is_interactive) override;
34 
35     double lengthy;       /**< The lengths of the primary y-axis */
36     double angle_deg[3];  /**< Angle of each axis (note that angle[2] == 0) */
37     double angle_rad[3];  /**< Angle of each axis (note that angle[2] == 0) */
38     double tan_angle[3];  /**< tan(angle[.]) */
39 
40     bool scaled;          /**< Whether the grid is in scaled mode */
41 
42 protected:
43     friend class CanvasAxonomGridSnapper;
44 
45     Geom::Point ow;         /**< Transformed origin by the affine for the zoom */
46     double lyw   = 1.0;     /**< Transformed length y by the affine for the zoom */
47     double lxw_x = 1.0;
48     double lxw_z = 1.0;
49     double spacing_ylines = 1.0;
50 
51     Geom::Point sw;          /**< the scaling factors of the affine transform */
52 
53     Gtk::Widget * newSpecificWidget() override;
54 
55 private:
56     CanvasAxonomGrid(const CanvasAxonomGrid&) = delete;
57     CanvasAxonomGrid& operator=(const CanvasAxonomGrid&) = delete;
58 
59     void updateWidgets();
60 
61     Inkscape::UI::Widget::RegisteredUnitMenu *_rumg;
62     Inkscape::UI::Widget::RegisteredScalarUnit *_rsu_ox;
63     Inkscape::UI::Widget::RegisteredScalarUnit *_rsu_oy;
64     Inkscape::UI::Widget::RegisteredScalarUnit *_rsu_sy;
65     Inkscape::UI::Widget::RegisteredScalar *_rsu_ax;
66     Inkscape::UI::Widget::RegisteredScalar *_rsu_az;
67     Inkscape::UI::Widget::RegisteredColorPicker *_rcp_gcol;
68     Inkscape::UI::Widget::RegisteredColorPicker *_rcp_gmcol;
69     Inkscape::UI::Widget::RegisteredSuffixedInteger *_rsi;
70 };
71 
72 
73 
74 class CanvasAxonomGridSnapper : public LineSnapper
75 {
76 public:
77     CanvasAxonomGridSnapper(CanvasAxonomGrid *grid, SnapManager *sm, Geom::Coord const d);
78     bool ThisSnapperMightSnap() const override;
79 
80     Geom::Coord getSnapperTolerance() const override; //returns the tolerance of the snapper in screen pixels (i.e. independent of zoom)
81     bool getSnapperAlwaysSnap() const override; //if true, then the snapper will always snap, regardless of its tolerance
82 
83 private:
84     LineList _getSnapLines(Geom::Point const &p) const override;
85     void _addSnappedLine(IntermSnapResults &isr, Geom::Point const &snapped_point, Geom::Coord const &snapped_distance, SnapSourceType const &source, long source_num, Geom::Point const &normal_to_line, const Geom::Point &point_on_line) const override;
86     void _addSnappedPoint(IntermSnapResults &isr, Geom::Point const &snapped_point, Geom::Coord const &snapped_distance, SnapSourceType const &source, long source_num, bool constrained_snap) const override;
87     void _addSnappedLinePerpendicularly(IntermSnapResults &isr, Geom::Point const &snapped_point, Geom::Coord const &snapped_distance, SnapSourceType const &source, long source_num, bool constrained_snap) const override;
88 
89     CanvasAxonomGrid *grid;
90 };
91 
92 
93 }; //namespace Inkscape
94 
95 
96 
97 #endif
98 
99 
100