35#include <glibmm/i18n.h>
49 , _snap_to_visible_only(true)
64 new_node->setAttribute(
"type",
"modular");
67 new_node->setAttribute(
"type",
"xygrid");
76 new_grid->setEnabled(
true);
77 new_grid->setVisible(
true);
121 assert(
views.empty());
133 }
else if (!std::strcmp(value,
"xygrid")) {
135 }
else if (!std::strcmp(value,
"axonomgrid")) {
137 }
else if (!std::strcmp(value,
"modular")) {
158 auto unit = UnitTable::get().getUnit(value);
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" },
274 for (
auto &iter : legacyattrs) {
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"]);
315 auto fix = [&] (
SPAttr attr,
char const *value) {
322 auto fix_double = [&] (
SPAttr attr,
double value) {
325 auto str = std::to_string(value);
327 set(attr, str.c_str());
355 std::string prefpath =
"/options/grids/" + std::string(
getSVGType()) +
"/units";
356 Glib::ustring unit = prefs->getString(prefpath);
381 default: g_assert_not_reached();
break;
387 auto unit_pref = prefs->getString(prefix +
"/units", display_unit->abbr);
398 Quantity::convert(prefs->getDouble(prefix +
"/origin_x"),
_display_unit,
"px"),
399 Quantity::convert(prefs->getDouble(prefix +
"/origin_y"),
_display_unit,
"px")) *
scale);
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);
406 setMajorColor(prefs->getColor(prefix +
"/empcolor", modular ?
"#0047cb4d" :
"#0099e54d"));
407 setMinorColor(prefs->getColor(prefix +
"/color", modular ?
"#0047cb26" :
"#0099e526"));
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"));
419 auto m = prefix +
"/";
422 Quantity::convert(prefs->getDouble(m +
"marginx", 0),
_display_unit,
"px"),
423 Quantity::convert(prefs->getDouble(m +
"marginy", 0),
_display_unit,
"px")
426 Quantity::convert(prefs->getDouble(m +
"gapx", 20),
_display_unit,
"px"),
427 Quantity::convert(prefs->getDouble(m +
"gapy", 20),
_display_unit,
"px")
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 {};
452 for (
auto &view :
views) {
460 if (flags & SP_OBJECT_MODIFIED_FLAG) {
470 for (
auto &view :
views) {
474 view->set_spacing(spacing);
490 modular->set_gap_size(gap);
491 modular->set_margin_size(
margin);
505 for (
auto &view :
views) {
521 for (
auto it =
views.begin(); it !=
views.end(); ++it) {
522 auto view = it->get();
587 constexpr auto MIN_VAL = 0.00001;
588 if (spacing.x() < MIN_VAL || spacing.y() < MIN_VAL) {
602 return {
origin, spacing };
611 default: g_assert_not_reached();
621 default: g_assert_not_reached();
628 if (!target_type || *target_type ==
_grid_type) {
640 for (
auto &view :
views) {
755 default: g_assert_not_reached();
return "grid";
766 if (units.empty())
return;
768 if (
auto new_unit = UnitTable::get().
getUnit(units)) {
gchar const * sp_attribute_name(SPAttr id)
Get attribute name by id.
Lookup dictionary for attributes/properties.
std::unique_ptr< T, CanvasItemUnlinkDeleter > CanvasItemPtr
Smart pointer used to hold CanvasItems, like std::unique_ptr.
Two-dimensional point that doubles as a vector.
Canvas Item for axonometric grids.
CanvasItemGroup * get_parent() const
std::string toString(bool opacity=true) const
Format the color as a css string and return it.
uint32_t toRGBA(double opacity=1.0) const
Return an sRGB conversion of the color in RGBA int32 format.
bool setOpacity(double opacity)
Set the opacity of this color object.
double getOpacity() const
Get the opacity in this color, if it's stored.
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.
Interface for refcounted XML nodes.
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.
bool setAttributeInt(Util::const_char_ptr key, int val)
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.
bool setAttributeBoolean(Util::const_char_ptr key, bool val)
bool setAttributeSvgDouble(Util::const_char_ptr key, double val)
For attributes where an exponent is allowed.
To do: update description of desktop.
Inkscape::CanvasItemGroup * getCanvasGrids() const
Typed SVG document implementation.
bool get_origin_follows_page()
bool removeResource(char const *key, SPObject *object)
bool addResource(char const *key, SPObject *object)
Inkscape::PageManager & getPageManager()
Inkscape::XML::Document * getReprDoc()
Our Inkscape::XML::Document.
SPObject * getObjectByRepr(Inkscape::XML::Node *repr) const
SPNamedView * getNamedView()
Get the namedview for this document, creates it if it's not found.
Geom::Scale getDocumentScale(bool computed=true) const
Returns document scale as defined by width/height (in pixels) and viewBox (real world to user-units).
Inkscape::Util::Unit const * getDisplayUnit()
guaranteed not to return nullptr
sigc::connection _page_modified_connection
Inkscape::CanvasItemGrid * getAssociatedView(SPDesktop const *desktop)
SVGBool _snap_to_visible_only
void setType(GridType type)
static void create_new(SPDocument *doc, Inkscape::XML::Node *parent, GridType type)
void modified(unsigned int flags) override
Geom::Point getSpacing() const
void show(SPDesktop *desktop)
creates a new grid canvasitem for the SPDesktop given as parameter.
const char * getSVGType() const
Inkscape::Colors::Color _minor_color
void hide(SPDesktop const *desktop)
void set(SPAttr key, const char *value) override
Inkscape::Colors::Color const & getMinorColor() const
Inkscape::Snapper * snapper()
void setOrigin(Geom::Point const &new_origin)
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...
void setAngleX(double deg)
const char * typeName() const
void update(SPCtx *ctx, unsigned int flags) override
Inkscape::Colors::Color const & getMajorColor() const
void setMajorColor(Inkscape::Colors::Color const &color)
void setSVGType(const char *svgtype)
Inkscape::Util::Unit const * _display_unit
std::pair< Geom::Point, Geom::Point > getEffectiveOriginAndSpacing(int index=-1) const
void scale(const Geom::Scale &scale)
void setAngleZ(double deg)
const Inkscape::Util::Unit * getUnit() const
Inkscape::Colors::Color _major_color
const char * displayName() const
void setSnapToVisibleOnly(bool v)
std::unique_ptr< Inkscape::Snapper > _snapper
void setSpacing(Geom::Point const &spacing)
sigc::connection _page_selected_connection
void setUnit(const Glib::ustring &units)
Geom::Point getOrigin() const
void build(SPDocument *doc, Inkscape::XML::Node *repr) override
void setMinorColor(Inkscape::Colors::Color const &color)
void setMajorLineInterval(guint32 interval)
std::vector< CanvasItemPtr< Inkscape::CanvasItemGrid > > views
guint32 _major_line_interval
Inkscape::XML::Node * repr
void appendChild(Inkscape::XML::Node *child)
void requestModified(unsigned int flags)
Requests that a modification notification signal be emitted later (e.g.
virtual void set(SPAttr key, const char *value)
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.
bool read(gchar const *str)
bool read(gchar const *str)
bool read(char const *str)
Editable view implementation.
static char const *const parent
Grid Snapper for Rectangular and Axonometric Grids.
Inkscape::XML::Node * node
static R & release(R &r)
Decrements the reference count of a anchored object.
static cairo_user_data_key_t key
static std::optional< GridType > readGridType(char const *value)
static auto const GRID_DEFAULT_MAJOR_COLOR
static CanvasItemPtr< Inkscape::CanvasItemGrid > create_view(GridType grid_type, Inkscape::CanvasItemGroup *canvasgrids)
static auto const GRID_DEFAULT_MINOR_COLOR
Interface for XML documents.
virtual Node * createElement(char const *name)=0