Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
sp-grid.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Inkscape SPGrid implementation
4 *
5 * Authors:
6 * James Ferrarelli
7 * Johan Engelen <johan@shouraizou.nl>
8 * Lauris Kaplinski
9 * Abhishek Sharma
10 * Jon A. Cruz <jon@joncruz.org>
11 * Tavmong Bah <tavmjong@free.fr>
12 * see git history
13 *
14 * Copyright (C) 2022 Authors
15 *
16 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
17 */
18
19#include "sp-grid.h"
20#include "sp-namedview.h"
21
22#include "colors/manager.h"
25
26#include "attributes.h"
27#include "desktop.h"
28#include "document.h"
29#include "grid-snapper.h"
30#include "page-manager.h"
31#include "snapper.h"
32#include "svg/svg-length.h"
33#include "util/units.h"
34
35#include <glibmm/i18n.h>
36#include <string>
37#include <optional>
38
40
41// default colors
42static auto const GRID_DEFAULT_MAJOR_COLOR = Inkscape::Colors::Color{0x0099e54d};
43static auto const GRID_DEFAULT_MINOR_COLOR = Inkscape::Colors::Color{0x0099e526};
44
46 : _visible(true)
47 , _enabled(true)
48 , _dotted(false)
49 , _snap_to_visible_only(true)
50 , _legacy(false)
51 , _major_color{GRID_DEFAULT_MAJOR_COLOR}
52 , _minor_color{GRID_DEFAULT_MINOR_COLOR}
53 , _pixel(true)
54 , _grid_type(GridType::RECTANGULAR)
55{ }
56
58{
59 auto new_node = document->getReprDoc()->createElement("inkscape:grid");
60 if (type == GridType::AXONOMETRIC) {
61 new_node->setAttribute("type", "axonomgrid");
62 }
63 else if (type == GridType::MODULAR) {
64 new_node->setAttribute("type", "modular");
65 }
66 else {
67 new_node->setAttribute("type", "xygrid");
68 }
69
70 parent->appendChild(new_node);
71
72 auto new_grid = dynamic_cast<SPGrid *>(document->getObjectByRepr(new_node));
73 if (new_grid)
74 new_grid->setPrefValues();
75
76 new_grid->setEnabled(true);
77 new_grid->setVisible(true);
78 Inkscape::GC::release(new_node);
79}
80
81SPGrid::~SPGrid() = default;
82
114
116{
117 if (document) {
118 document->removeResource("grid", this);
119 }
120
121 assert(views.empty());
122
123 _page_selected_connection.disconnect();
124 _page_modified_connection.disconnect();
125
127}
128
129static std::optional<GridType> readGridType(char const *value)
130{
131 if (!value) {
132 return {};
133 } else if (!std::strcmp(value, "xygrid")) {
135 } else if (!std::strcmp(value, "axonomgrid")) {
137 } else if (!std::strcmp(value, "modular")) {
138 return GridType::MODULAR;
139 } else {
140 return {};
141 }
142}
143
144void SPGrid::set(SPAttr key, const gchar* value)
145{
146 switch (key) {
147 case SPAttr::TYPE: {
148 auto const grid_type = readGridType(value).value_or(GridType::RECTANGULAR); // default
149 if (grid_type != _grid_type) {
150 _grid_type = grid_type;
152 requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
153 }
154 break;
155 }
156 case SPAttr::UNITS:
157 {
158 auto unit = UnitTable::get().getUnit(value);
159 if (_display_unit != unit) {
160 _display_unit = unit;
161 requestModified(SP_OBJECT_MODIFIED_FLAG);
162 }
163 break;
164 }
165 case SPAttr::ORIGINX:
166 _origin_x.read(value);
167 requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
168 break;
169 case SPAttr::ORIGINY:
170 _origin_y.read(value);
171 requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
172 break;
173 case SPAttr::SPACINGX:
174 _spacing_x.read(value);
175 requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
176 break;
177 case SPAttr::SPACINGY:
178 _spacing_y.read(value);
179 requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
180 break;
181 case SPAttr::ANGLE_X: // only meaningful for axonomgrid
182 _angle_x.read(value);
183 requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
184 break;
185 case SPAttr::ANGLE_Z: // only meaningful for axonomgrid
186 _angle_z.read(value);
187 requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
188 break;
189 case SPAttr::GAP_X: // only meaningful for modular
190 _gap_x.read(value);
191 requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
192 break;
193 case SPAttr::GAP_Y: // only meaningful for modular
194 _gap_y.read(value);
195 requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
196 break;
197 case SPAttr::MARGIN_X: // only meaningful for modular
198 _margin_x.read(value);
199 requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
200 break;
201 case SPAttr::MARGIN_Y: // only meaningful for modular
202 _margin_y.read(value);
203 requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
204 break;
205 case SPAttr::COLOR: {
206 auto const old_opacity = _minor_color.getOpacity();
207 _minor_color = Inkscape::Colors::Color::parse(value).value_or(GRID_DEFAULT_MINOR_COLOR);
208 _minor_color.setOpacity(old_opacity);
209 requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
210 break;
211 }
212 case SPAttr::EMPCOLOR: {
213 auto const old_opacity = _major_color.getOpacity();
214 _major_color = Inkscape::Colors::Color::parse(value).value_or(GRID_DEFAULT_MAJOR_COLOR);
215 _major_color.setOpacity(old_opacity);
216 requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
217 break;
218 }
219 case SPAttr::VISIBLE:
220 _visible.read(value);
221 requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
222 break;
223 case SPAttr::ENABLED:
224 _enabled.read(value);
225 if (_snapper) _snapper->setEnabled(_enabled);
226 requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
227 break;
228 case SPAttr::OPACITY:
229 _minor_color.setOpacity(value ? g_ascii_strtod(value, nullptr) : 1.0);
230 requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
231 break;
233 _major_color.setOpacity(value ? g_ascii_strtod(value, nullptr) : 1.0);
234 requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
235 break;
237 _major_line_interval = value ? std::max(std::stoi(value), 1) : 5;
238 requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
239 break;
240 case SPAttr::DOTTED: // only meaningful for rectangular grid
241 _dotted.read(value);
242 requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
243 break;
246 if (_snapper) _snapper->setSnapVisibleOnly(_snap_to_visible_only);
247 requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
248 break;
249 default:
250 SPObject::set(key, value);
251 break;
252 }
253}
254
260{
261 // the old defaults
262 std::unordered_map<const char *, const char *> legacyattrs = {
263 { "gridoriginx", "0px" },
264 { "gridoriginy", "0px" },
265 { "gridspacingx", "1px" },
266 { "gridspacingy", "1px" },
267 { "gridcolor", "#3f3fff" },
268 { "gridempcolor", "#3f3fff" },
269 { "gridopacity", "0.15" },
270 { "gridempopacity", "0.38" },
271 { "gridempspacing", "5" },
272 };
273
274 for (auto &iter : legacyattrs) {
275 if (auto attr = repr->attribute(iter.first)) {
276 _legacy = true;
277 iter.second = attr;
278 }
279 }
280
281 if (_legacy) {
282 // generate new xy grid with the correct settings
283 // first create the child xml node, then hook it to repr. This order is important, to not set off listeners to repr before the new node is complete.
285 Inkscape::XML::Node *newnode = xml_doc->createElement("inkscape:grid");
286 newnode->setAttribute("id", "GridFromPre046Settings");
287 newnode->setAttribute("type", getSVGType());
288 newnode->setAttribute("originx", legacyattrs["gridoriginx"]);
289 newnode->setAttribute("originy", legacyattrs["gridoriginy"]);
290 newnode->setAttribute("spacingx", legacyattrs["gridspacingx"]);
291 newnode->setAttribute("spacingy", legacyattrs["gridspacingy"]);
292 newnode->setAttribute("color", legacyattrs["gridcolor"]);
293 newnode->setAttribute("empcolor", legacyattrs["gridempcolor"]);
294 newnode->setAttribute("opacity", legacyattrs["gridopacity"]);
295 newnode->setAttribute("empopacity", legacyattrs["gridempopacity"]);
296 newnode->setAttribute("empspacing", legacyattrs["gridempspacing"]);
297
298 repr->appendChild(newnode);
299 Inkscape::GC::release(newnode);
300
301 // remove all old settings
302 repr->removeAttribute("gridoriginx");
303 repr->removeAttribute("gridoriginy");
304 repr->removeAttribute("gridspacingx");
305 repr->removeAttribute("gridspacingy");
306 repr->removeAttribute("gridcolor");
307 repr->removeAttribute("gridempcolor");
308 repr->removeAttribute("gridopacity");
309 repr->removeAttribute("gridempopacity");
310 repr->removeAttribute("gridempspacing");
311 }
312 else if (repr->attribute("id")) {
313 // TODO(james): These need to come from preferences
314 // fix v1.2 grids without spacing, units, origin defined
315 auto fix = [&] (SPAttr attr, char const *value) {
316 auto key = sp_attribute_name(attr);
317 if (!repr->attribute(key)) {
318 repr->setAttribute(key, value);
319 set(attr, value);
320 }
321 };
322 auto fix_double = [&] (SPAttr attr, double value) {
323 auto key = sp_attribute_name(attr);
324 if (!repr->attribute(key)) {
325 auto str = std::to_string(value);
326 repr->setAttribute(key, str.c_str());
327 set(attr, str.c_str());
328 }
329 };
330
332 Geom::Point default_origin = Geom::Point(0, 0) * scale;
333 Geom::Point default_spacing = Geom::Point(1, 1) * scale;
334
335 fix_double(SPAttr::ORIGINX, default_origin[Geom::X]);
336 fix_double(SPAttr::ORIGINY, default_origin[Geom::Y]);
337 fix_double(SPAttr::SPACINGY, default_spacing[Geom::Y]);
338
339 GridType type = readGridType(repr->attribute("type")).value_or(GridType::RECTANGULAR);
340 switch (type) {
342 fix_double(SPAttr::SPACINGX, default_spacing[Geom::X]);
343 break;
345 fix(SPAttr::ANGLE_X, "30");
346 fix(SPAttr::ANGLE_Z, "30");
347 break;
349 break;
350 default:
351 break;
352 }
353
354 auto prefs = Inkscape::Preferences::get();
355 std::string prefpath = "/options/grids/" + std::string(getSVGType()) + "/units";
356 Glib::ustring unit = prefs->getString(prefpath);
357 if (unit.empty()) {
358 setUnit("px");
359 fix(SPAttr::UNITS, "px");
360 } else {
361 setUnit(unit);
362 fix(SPAttr::UNITS, unit.c_str());
363 }
364 }
365}
366
367/*
368 * The grid needs to be initialized based on user preferences.
369 * When a grid is created by either DocumentProperties or SPNamedView,
370 * update the attributes to the corresponding grid type.
371 */
373{
374 auto prefs = Inkscape::Preferences::get();
375
376 std::string prefix;
377 switch (getType()) {
378 case GridType::RECTANGULAR: prefix = "/options/grids/xy"; break;
379 case GridType::AXONOMETRIC: prefix = "/options/grids/axonom"; break;
380 case GridType::MODULAR: prefix = "/options/grids/modular"; break;
381 default: g_assert_not_reached(); break;
382 }
383
384 const auto modular = _grid_type == GridType::MODULAR;
385
386 auto display_unit = document->getDisplayUnit();
387 auto unit_pref = prefs->getString(prefix + "/units", display_unit->abbr);
388 setUnit(unit_pref);
389
390 _display_unit = UnitTable::get().getUnit(unit_pref);
391
392 // Origin and Spacing are the only two properties that vary depending on selected units
393 // SPGrid should only store values in document units, convert whatever preferences are set to "px"
394 // and then scale "px" to the document unit.
398 Quantity::convert(prefs->getDouble(prefix + "/origin_x"), _display_unit, "px"),
399 Quantity::convert(prefs->getDouble(prefix + "/origin_y"), _display_unit, "px")) * scale);
400
401 auto default_spacing = modular ? 100.0 : 1.0;
403 Quantity::convert(prefs->getDouble(prefix + "/spacing_x", default_spacing), _display_unit, "px"),
404 Quantity::convert(prefs->getDouble(prefix + "/spacing_y", default_spacing), _display_unit, "px")) * scale);
405
406 setMajorColor(prefs->getColor(prefix + "/empcolor", modular ? "#0047cb4d" : "#0099e54d"));
407 setMinorColor(prefs->getColor(prefix + "/color", modular ? "#0047cb26" : "#0099e526"));
408 setMajorLineInterval(prefs->getInt(prefix + "/empspacing"));
409
410 // these prefs are bound specifically to one type of grid
412 setDotted(prefs->getBool("/options/grids/xy/dotted"));
413 setAngleX(prefs->getDouble("/options/grids/axonom/angle_x"));
414 setAngleZ(prefs->getDouble("/options/grids/axonom/angle_z"));
415 }
416
417 // modular grid properties
419 auto m = prefix + "/";
420
421 auto margin = Geom::Point(
422 Quantity::convert(prefs->getDouble(m + "marginx", 0), _display_unit, "px"),
423 Quantity::convert(prefs->getDouble(m + "marginy", 0), _display_unit, "px")
424 ) * scale;
425 auto gap = Geom::Point(
426 Quantity::convert(prefs->getDouble(m + "gapx", 20), _display_unit, "px"),
427 Quantity::convert(prefs->getDouble(m + "gapy", 20), _display_unit, "px")
428 ) * scale;
429
430 getRepr()->setAttributeSvgDouble("marginx", margin.x());
431 getRepr()->setAttributeSvgDouble("marginy", margin.y());
432 getRepr()->setAttributeSvgDouble("gapx", gap.x());
433 getRepr()->setAttributeSvgDouble("gapy", gap.y());
434
435 requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
436 }
437}
438
440{
441 switch (grid_type) {
442 case GridType::RECTANGULAR: return make_canvasitem<Inkscape::CanvasItemGridXY> (canvasgrids); break;
443 case GridType::AXONOMETRIC: return make_canvasitem<Inkscape::CanvasItemGridAxonom>(canvasgrids); break;
444 case GridType::MODULAR: return make_canvasitem<Inkscape::CanvasItemGridTiles> (canvasgrids); break;
445 default: g_assert_not_reached(); return {};
446 }
447}
448
450{
451 // handle change in grid type requiring all views to be recreated as a different type
452 for (auto &view : views) {
453 view = create_view(_grid_type, view->get_parent());
454 }
455}
456
457// update internal state on XML change
458void SPGrid::modified(unsigned int flags)
459{
460 if (flags & SP_OBJECT_MODIFIED_FLAG) {
461 updateRepr();
462 }
463}
464
465// tell canvas to redraw grid
466void SPGrid::update(SPCtx *ctx, unsigned int flags)
467{
468 auto [origin, spacing] = getEffectiveOriginAndSpacing();
469
470 for (auto &view : views) {
471 view->set_visible(_visible && _enabled);
472 if (_enabled) {
473 view->set_origin(origin);
474 view->set_spacing(spacing);
475 view->set_major_color(getMajorColor().toRGBA());
476 view->set_minor_color(getMinorColor().toRGBA());
477 view->set_dotted(_dotted);
478 view->set_major_line_interval(_major_line_interval);
479
480 if (auto axonom = dynamic_cast<Inkscape::CanvasItemGridAxonom *>(view.get())) {
481 axonom->set_angle_x(_angle_x.computed);
482 axonom->set_angle_z(_angle_z.computed);
483 }
484
485 if (auto modular = dynamic_cast<Inkscape::CanvasItemGridTiles*>(view.get())) {
486 const auto scale = document->getDocumentScale();
487 // "set_spacing" above sets block size; add gaps:
490 modular->set_gap_size(gap);
491 modular->set_margin_size(margin);
492 }
493 }
494 }
495}
496
501{
502 if (!desktop) return;
503
504 // check if there is already a canvasitem on this desktop linking to this grid
505 for (auto &view : views) {
506 if (desktop->getCanvasGrids() == view->get_parent()) {
507 return;
508 }
509 }
510
511 // create designated canvasitem for this grid
513
514 requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
515}
516
518{
519 if (!desktop) return;
520
521 for (auto it = views.begin(); it != views.end(); ++it) {
522 auto view = it->get();
523 if (view->get_parent() == desktop->getCanvasGrids()) {
524 views.erase(it);
525 break;
526 }
527 }
528}
529
530void SPGrid::scale(const Geom::Scale &scale)
531{
534}
535
537{
538 if (!_snapper) {
539 // lazily create
540 _snapper = std::make_unique<Inkscape::GridSnapper>(this, &document->getNamedView()->snap_manager, 0);
541 _snapper->setEnabled(_enabled);
542 _snapper->setSnapVisibleOnly(_snap_to_visible_only);
543 }
544 return _snapper.get();
545}
546
547std::pair<Geom::Point, Geom::Point> SPGrid::getEffectiveOriginAndSpacing(int index) const
548{
549 auto origin = getOrigin();
550 auto spacing = getSpacing();
552 if (index >= 0) {
553 spacing = pitch;
554 }
555
556 // modular grid snapping can be supported by making it look like a series of rectangular grids (up to 4)
557 switch (index) {
558 case -1: // rectangular grid case
559 break;
560 case 0: // modular: left/top edge
562 break;
563 case 1: // modular: right/bottom edge
565 break;
566 case 2: // modular: left/top with margin
569 }
570 else {
571 spacing = Geom::Point();
572 }
573 break;
574 case 3: // modular: right/bottom with margin
577 }
578 else {
579 spacing = Geom::Point();
580 }
581 break;
582 default: // end of sequence
583 spacing = Geom::Point();
584 break;
585 }
586
587 constexpr auto MIN_VAL = 0.00001;
588 if (spacing.x() < MIN_VAL || spacing.y() < MIN_VAL) {
589 // too small a spacing can choke snapping; skip
590 spacing = Geom::Point();
591 }
592 else {
593 auto const scale = document->getDocumentScale();
594 origin *= scale;
595 spacing *= scale;
596 }
597
600 }
601
602 return { origin, spacing };
603}
604
605const char *SPGrid::displayName() const
606{
607 switch (_grid_type) {
608 case GridType::RECTANGULAR: return _("Rectangular Grid");
609 case GridType::AXONOMETRIC: return _("Axonometric Grid");
610 case GridType::MODULAR: return _("Modular Grid");
611 default: g_assert_not_reached();
612 }
613}
614
615const char *SPGrid::getSVGType() const
616{
617 switch (_grid_type) {
618 case GridType::RECTANGULAR: return "xygrid";
619 case GridType::AXONOMETRIC: return "axonomgrid";
620 case GridType::MODULAR: return "modular";
621 default: g_assert_not_reached();
622 }
623}
624
625void SPGrid::setSVGType(char const *svgtype)
626{
627 auto target_type = readGridType(svgtype);
628 if (!target_type || *target_type == _grid_type) {
629 return;
630 }
631
632 getRepr()->setAttribute("type", svgtype);
633
634 requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
635}
636
637// finds the canvasitem active in the current active view
639{
640 for (auto &view : views) {
641 if (desktop->getCanvasGrids() == view->get_parent()) {
642 return view.get();
643 }
644 }
645 return nullptr;
646}
647
649{
650 getRepr()->setAttributeBoolean("visible", v);
651
652 requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
653}
654
656{
657 return _enabled;
658}
659
661{
662 getRepr()->setAttributeBoolean("enabled", v);
663
664 if (_snapper) _snapper->setEnabled(v);
665
666 requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
667}
668
669// returns values in "px"
674
675void SPGrid::setOrigin(Geom::Point const &new_origin)
676{
678 repr->setAttributeSvgDouble("originx", new_origin[Geom::X]);
679 repr->setAttributeSvgDouble("originy", new_origin[Geom::Y]);
680
681 requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
682}
683
685{
686 getRepr()->setAttribute("empcolor", color.toString(false));
687 getRepr()->setAttributeSvgDouble("empopacity", color.getOpacity());
688 requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
689}
690
692{
693 getRepr()->setAttribute("color", color.toString(false));
694 getRepr()->setAttributeSvgDouble("opacity", color.getOpacity());
695 requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
696}
697
698// returns values in "px"
703
704void SPGrid::setSpacing(const Geom::Point &spacing)
705{
707 repr->setAttributeSvgDouble("spacingx", spacing[Geom::X]);
708 repr->setAttributeSvgDouble("spacingy", spacing[Geom::Y]);
709
710 requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
711}
712
714{
715 getRepr()->setAttributeInt("empspacing", interval);
716
717 requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
718}
719
721{
722 getRepr()->setAttributeBoolean("dotted", v);
723
724 requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
725}
726
728{
729 getRepr()->setAttributeBoolean("snapvisiblegridlinesonly", v);
730 if (_snapper) _snapper->setSnapVisibleOnly(v);
731
732 requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
733}
734
735void SPGrid::setAngleX(double deg)
736{
737 getRepr()->setAttributeSvgDouble("gridanglex", deg);
738
739 requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
740}
741
742void SPGrid::setAngleZ(double deg)
743{
744 getRepr()->setAttributeSvgDouble("gridanglez", deg);
745
746 requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
747}
748
749const char *SPGrid::typeName() const
750{
751 switch (_grid_type) {
752 case GridType::RECTANGULAR: return "grid-rectangular";
753 case GridType::AXONOMETRIC: return "grid-axonometric";
754 case GridType::MODULAR: return "grid-modular";
755 default: g_assert_not_reached(); return "grid";
756 }
757}
758
760{
761 return _display_unit;
762}
763
764void SPGrid::setUnit(const Glib::ustring &units)
765{
766 if (units.empty()) return;
767
768 if (auto new_unit = UnitTable::get().getUnit(units)) {
769 getRepr()->setAttribute("units", units.c_str());
770 _display_unit = new_unit;
771 requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
772 }
773}
774
776 if (_grid_type == type) return;
777
778 auto node = getRepr();
779 if (type == GridType::AXONOMETRIC) {
780 node->setAttribute("type", "axonomgrid");
781 }
782 else if (type == GridType::MODULAR) {
783 node->setAttribute("type", "modular");
784 }
785 else {
786 node->setAttribute("type", "xygrid");
787 }
788
790 requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
791}
double scale
Definition aa.cpp:228
Point origin
Definition aa.cpp:227
gchar const * sp_attribute_name(SPAttr id)
Get attribute name by id.
Lookup dictionary for attributes/properties.
SPAttr
Definition attributes.h:27
@ MAJOR_LINE_INTERVAL
@ SNAP_TO_VISIBLE_ONLY
@ EMPOPACITY
std::unique_ptr< T, CanvasItemUnlinkDeleter > CanvasItemPtr
Smart pointer used to hold CanvasItems, like std::unique_ptr.
int margin
Definition canvas.cpp:166
Two-dimensional point that doubles as a vector.
Definition point.h:66
Scaling from the origin.
Definition transforms.h:150
Scale inverse() const
Definition transforms.h:172
Canvas Item for axonometric grids.
CanvasItemGroup * get_parent() const
Definition canvas-item.h:62
std::string toString(bool opacity=true) const
Format the color as a css string and return it.
Definition color.cpp:106
uint32_t toRGBA(double opacity=1.0) const
Return an sRGB conversion of the color in RGBA int32 format.
Definition color.cpp:117
bool setOpacity(double opacity)
Set the opacity of this color object.
Definition color.cpp:444
double getOpacity() const
Get the opacity in this color, if it's stored.
Definition color.cpp:407
Geom::Affine getSelectedPageAffine() const
sigc::connection connectPageSelected(const sigc::slot< void(SPPage *)> &slot)
sigc::connection connectPageModified(const sigc::slot< void(SPPage *)> &slot)
static Preferences * get()
Access the singleton Preferences object.
Parent for classes that can snap points to something.
Definition snapper.h:39
Interface for refcounted XML nodes.
Definition node.h:80
virtual void appendChild(Node *child)=0
Append a node as the last child of this node.
void setAttribute(Util::const_char_ptr key, Util::const_char_ptr value)
Change an attribute of this node.
Definition node.cpp:25
bool setAttributeInt(Util::const_char_ptr key, int val)
Definition node.cpp:92
virtual char const * attribute(char const *key) const =0
Get the string representation of a node's attribute.
void removeAttribute(Inkscape::Util::const_char_ptr key)
Remove an attribute of this node.
Definition node.h:280
bool setAttributeBoolean(Util::const_char_ptr key, bool val)
Definition node.cpp:86
bool setAttributeSvgDouble(Util::const_char_ptr key, double val)
For attributes where an exponent is allowed.
Definition node.cpp:111
To do: update description of desktop.
Definition desktop.h:149
Inkscape::CanvasItemGroup * getCanvasGrids() const
Definition desktop.h:199
Typed SVG document implementation.
Definition document.h:101
bool get_origin_follows_page()
bool removeResource(char const *key, SPObject *object)
bool addResource(char const *key, SPObject *object)
Inkscape::PageManager & getPageManager()
Definition document.h:162
Inkscape::XML::Document * getReprDoc()
Our Inkscape::XML::Document.
Definition document.h:211
SPObject * getObjectByRepr(Inkscape::XML::Node *repr) const
SPNamedView * getNamedView()
Get the namedview for this document, creates it if it's not found.
Definition document.cpp:235
Geom::Scale getDocumentScale(bool computed=true) const
Returns document scale as defined by width/height (in pixels) and viewBox (real world to user-units).
Definition document.cpp:764
Inkscape::Util::Unit const * getDisplayUnit()
guaranteed not to return nullptr
Definition document.cpp:732
sigc::connection _page_modified_connection
Definition sp-grid.h:161
SVGAngle _angle_z
Definition sp-grid.h:140
Inkscape::CanvasItemGrid * getAssociatedView(SPDesktop const *desktop)
Definition sp-grid.cpp:638
SVGBool _snap_to_visible_only
Definition sp-grid.h:133
void setType(GridType type)
Definition sp-grid.cpp:775
static void create_new(SPDocument *doc, Inkscape::XML::Node *parent, GridType type)
Definition sp-grid.cpp:57
void modified(unsigned int flags) override
Definition sp-grid.cpp:458
void setEnabled(bool v)
Definition sp-grid.cpp:660
~SPGrid() override
SVGLength _gap_x
Definition sp-grid.h:141
bool _legacy
Definition sp-grid.h:152
Geom::Point getSpacing() const
Definition sp-grid.cpp:699
void show(SPDesktop *desktop)
creates a new grid canvasitem for the SPDesktop given as parameter.
Definition sp-grid.cpp:500
const char * getSVGType() const
Definition sp-grid.cpp:615
Inkscape::Colors::Color _minor_color
Definition sp-grid.h:149
void _recreateViews()
Definition sp-grid.cpp:449
void hide(SPDesktop const *desktop)
Definition sp-grid.cpp:517
void set(SPAttr key, const char *value) override
Definition sp-grid.cpp:144
SVGLength _origin_y
Definition sp-grid.h:136
Inkscape::Colors::Color const & getMinorColor() const
Definition sp-grid.h:76
Inkscape::Snapper * snapper()
Definition sp-grid.cpp:536
SVGLength _margin_x
Definition sp-grid.h:143
void setOrigin(Geom::Point const &new_origin)
Definition sp-grid.cpp:675
void _checkOldGrid(SPDocument *doc, Inkscape::XML::Node *repr)
checks for old grid attriubte keys from version 0.46 to determine if there needs to be legacy attribu...
Definition sp-grid.cpp:259
void setAngleX(double deg)
Definition sp-grid.cpp:735
const char * typeName() const
Definition sp-grid.cpp:749
void update(SPCtx *ctx, unsigned int flags) override
Definition sp-grid.cpp:466
Inkscape::Colors::Color const & getMajorColor() const
Definition sp-grid.h:73
void release() override
Definition sp-grid.cpp:115
bool isEnabled() const
Definition sp-grid.cpp:655
void setMajorColor(Inkscape::Colors::Color const &color)
Definition sp-grid.cpp:684
void setDotted(bool v)
Definition sp-grid.cpp:720
void setSVGType(const char *svgtype)
Definition sp-grid.cpp:625
SVGBool _enabled
Definition sp-grid.h:132
SVGBool _dotted
Definition sp-grid.h:134
Inkscape::Util::Unit const * _display_unit
Definition sp-grid.h:158
SVGAngle _angle_x
Definition sp-grid.h:139
SVGLength _spacing_x
Definition sp-grid.h:137
std::pair< Geom::Point, Geom::Point > getEffectiveOriginAndSpacing(int index=-1) const
Definition sp-grid.cpp:547
void scale(const Geom::Scale &scale)
Definition sp-grid.cpp:530
void setAngleZ(double deg)
Definition sp-grid.cpp:742
const Inkscape::Util::Unit * getUnit() const
Definition sp-grid.cpp:759
Inkscape::Colors::Color _major_color
Definition sp-grid.h:148
SVGLength _origin_x
Definition sp-grid.h:135
const char * displayName() const
Definition sp-grid.cpp:605
SVGLength _spacing_y
Definition sp-grid.h:138
void setSnapToVisibleOnly(bool v)
Definition sp-grid.cpp:727
GridType getType() const
Definition sp-grid.h:100
std::unique_ptr< Inkscape::Snapper > _snapper
Definition sp-grid.h:156
void setSpacing(Geom::Point const &spacing)
Definition sp-grid.cpp:704
SVGBool _visible
Definition sp-grid.h:131
void setPrefValues()
Definition sp-grid.cpp:372
sigc::connection _page_selected_connection
Definition sp-grid.h:160
GridType _grid_type
Definition sp-grid.h:154
SVGLength _gap_y
Definition sp-grid.h:142
void setUnit(const Glib::ustring &units)
Definition sp-grid.cpp:764
Geom::Point getOrigin() const
Definition sp-grid.cpp:670
void build(SPDocument *doc, Inkscape::XML::Node *repr) override
Definition sp-grid.cpp:83
void setMinorColor(Inkscape::Colors::Color const &color)
Definition sp-grid.cpp:691
void setMajorLineInterval(guint32 interval)
Definition sp-grid.cpp:713
std::vector< CanvasItemPtr< Inkscape::CanvasItemGrid > > views
Definition sp-grid.h:117
SVGLength _margin_y
Definition sp-grid.h:144
void setVisible(bool v)
Definition sp-grid.cpp:648
SPGrid()
Definition sp-grid.cpp:45
guint32 _major_line_interval
Definition sp-grid.h:146
SnapManager snap_manager
Inkscape::XML::Node * repr
Definition sp-object.h:193
void appendChild(Inkscape::XML::Node *child)
void requestModified(unsigned int flags)
Requests that a modification notification signal be emitted later (e.g.
SPDocument * document
Definition sp-object.h:188
virtual void set(SPAttr key, const char *value)
SPObject * parent
Definition sp-object.h:189
virtual void release()
Inkscape::XML::Node * updateRepr(unsigned int flags=SP_OBJECT_WRITE_EXT)
Updates the object's repr based on the object's state.
void readAttr(char const *key)
Read value of key attribute from XML node into object.
Inkscape::XML::Node * getRepr()
Returns the XML representation of tree.
virtual void build(SPDocument *doc, Inkscape::XML::Node *repr)
void requestDisplayUpdate(unsigned int flags)
Queues an deferred update of this object's display.
double computed
Definition svg-angle.h:45
bool read(gchar const *str)
Definition svg-angle.cpp:36
bool read(gchar const *str)
Definition svg-bool.cpp:25
bool read(char const *str)
float computed
Definition svg-length.h:50
Editable view implementation.
static char const *const parent
Definition dir-util.cpp:70
unsigned int guint32
Grid Snapper for Rectangular and Axonometric Grids.
@ Y
Definition coord.h:48
@ X
Definition coord.h:48
Inkscape::XML::Node * node
static R & release(R &r)
Decrements the reference count of a anchored object.
static cairo_user_data_key_t key
Snapper class.
static std::optional< GridType > readGridType(char const *value)
Definition sp-grid.cpp:129
static auto const GRID_DEFAULT_MAJOR_COLOR
Definition sp-grid.cpp:42
static CanvasItemPtr< Inkscape::CanvasItemGrid > create_view(GridType grid_type, Inkscape::CanvasItemGroup *canvasgrids)
Definition sp-grid.cpp:439
static auto const GRID_DEFAULT_MINOR_COLOR
Definition sp-grid.cpp:43
GridType
Definition sp-grid.h:42
Interface for XML documents.
Definition document.h:43
virtual Node * createElement(char const *name)=0
Unused.
Definition sp-object.h:94
int index
SPDesktop * desktop