canvas-grid.cpp revision ea1e5d4863ad8011b8de3b7c021bbfe26e10d76f
/** @file
* Cartesian grid implementation.
*/
/* Copyright (C) Johan Engelen 2006-2007 <johan@shouraizou.nl>
* Copyright (C) Lauris Kaplinski 2000
* Abhishek Sharma
* Jon A. Cruz <jon@joncruz.org>
*/
/* As a general comment, I am not exactly proud of how things are done.
* (for example the 'enable' widget and readRepr things)
* It does seem to work however. I intend to clean up and sort things out later, but that can take forever...
* Don't be shy to correct things.
*/
#if HAVE_CONFIG_H
# include "config.h"
#endif
#endif
#if WITH_GTKMM_3_0
#else
#endif
#include "ui/widget/registered-widget.h"
#include "desktop.h"
#include "sp-canvas-util.h"
#include "display/cairo-utils.h"
#include "display/canvas-axonomgrid.h"
#include "display/canvas-grid.h"
#include "display/sp-canvas-group.h"
#include "document.h"
#include "inkscape.h"
#include "preferences.h"
#include "sp-namedview.h"
#include "sp-object.h"
#include "sp-root.h"
#include "svg/svg-color.h"
#include "svg/stringstream.h"
#include "xml/node-event-vector.h"
#include "verbs.h"
#include "display/sp-canvas.h"
using Inkscape::DocumentUndo;
namespace Inkscape {
N_("Rectangular grid"),
N_("Axonometric grid")
};
static gchar const *const grid_svgname[] = {
"xygrid",
"axonomgrid"
};
// ##########################################################
// Grid CanvasItem
static void grid_canvasitem_update (SPCanvasItem *item, Geom::Affine const &affine, unsigned int flags);
{
}
static void
{
}
{
}
/**
*/
static void
{
}
}
static void
{
if (gridcanvasitem->grid) {
1000000, 1000000);
}
}
// ##########################################################
// CanvasGrid
NULL, /* child_added */
NULL, /* child_removed */
NULL, /* content_changed */
NULL /* order_changed */
};
CanvasGrid::CanvasGrid(SPNamedView * nv, Inkscape::XML::Node * in_repr, SPDocument *in_doc, GridType type)
{
if (repr) {
}
canvasitems = NULL;
}
CanvasGrid::~CanvasGrid()
{
if (repr) {
repr->removeListenerByData (this);
}
while (canvasitems) {
}
}
const char *
CanvasGrid::getName() const
{
}
const char *
CanvasGrid::getSVGName() const
{
return grid_svgname[gridtype];
}
CanvasGrid::getGridType() const
{
return gridtype;
}
char const *
{
}
char const *
{
return grid_svgname[type];
}
{
if (!typestr) return GRID_RECTANGULAR;
gint t = 0;
for (t = GRID_MAXTYPENR; t >= 0; t--) { //this automatically defaults to grid0 which is rectangular grid
}
return (GridType) t;
}
{
if (!typestr) return GRID_RECTANGULAR;
gint t = 0;
for (t = GRID_MAXTYPENR; t >= 0; t--) { //this automatically defaults to grid0 which is rectangular grid
}
return (GridType) t;
}
/*
* writes an <inkscape:grid> child to repr.
*/
void
{
if (!repr) return;
if (gridtype > GRID_MAXTYPENR) return;
// 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.
}
/*
* Creates a new CanvasGrid object of type gridtype
*/
CanvasGrid::NewGrid(SPNamedView * nv, Inkscape::XML::Node * repr, SPDocument * doc, GridType gridtype)
{
if (!doc) {
g_error("CanvasGrid::NewGrid - doc==NULL");
return NULL;
}
switch (gridtype) {
case GRID_RECTANGULAR:
case GRID_AXONOMETRIC:
}
return NULL;
}
/**
* creates a new grid canvasitem for the SPDesktop given as parameter. Keeps a link to this canvasitem in the canvasitems list.
*/
{
// Johan: I think for multiple desktops it is best if each has their own canvasitem,
// but share the same CanvasGrid object; that is what this function is for.
// check if there is already a canvasitem on this desktop linking to this grid
return NULL;
}
}
GridCanvasItem * item = INKSCAPE_GRID_CANVASITEM( sp_canvas_item_new(desktop->getGridGroup(), INKSCAPE_TYPE_GRID_CANVASITEM, NULL) );
return item;
}
{
str += "</b>";
_("Determines whether to snap to this grid or not. Can be 'on' for invisible grids."),
_("When zoomed out, not all grid lines will be displayed. Only the visible ones will be snapped to"),
_("Determines whether the grid is displayed or not. Objects are still snapped to invisible grids."),
// set widget values
_wr.setUpdating (true);
}
_wr.setUpdating (false);
}
void
CanvasGrid::on_repr_attr_changed(Inkscape::XML::Node *repr, gchar const *key, gchar const *oldval, gchar const *newval, bool is_interactive, void *data)
{
if (!data)
return;
}
bool CanvasGrid::isEnabled() const
{
return false;
}
return snapper->getEnabled();
}
// Used to shift origin when page size changed to fit drawing.
{
double scale_x = 1.0;
double scale_y = 1.0;
if( root->viewBox_set ) {
}
// Write out in 'user-units'
}
// ##########################################################
// CanvasXYGrid
/**
* "attach_all" function
* A DIRECT COPY-PASTE FROM DOCUMENT-PROPERTIES.CPP TO QUICKLY GET RESULTS
*
* Helper function that attachs widgets in a 3xn table. The widgets come in an
* array that has two entries per table row. The two entries code for four
* possible cases: (0,0) means insert space in first column; (0, non-0) means
* widget in columns 2-3; (non-0, 0) means label in columns 1-3; and
* (non-0, non-0) means two widgets in columns 2 and 3.
**/
#define SPACE_SIZE_X 15
#define SPACE_SIZE_Y 10
#if WITH_GTKMM_3_0
static inline void attach_all(Gtk::Grid &table, Gtk::Widget const *const arr[], unsigned size, int start = 0)
#else
static inline void attach_all(Gtk::Table &table, Gtk::Widget const *const arr[], unsigned size, int start = 0)
#endif
{
#if WITH_GTKMM_3_0
#else
#endif
} else {
if (arr[i+1]) {
#if WITH_GTKMM_3_0
#else
#endif
} else if (arr[i]) {
#if WITH_GTKMM_3_0
label.set_hexpand();
#else
#endif
} else {
#if WITH_GTKMM_3_0
#else
#endif
}
}
++r;
}
}
{
if (!gridunit) {
}
origin[Geom::X] = Inkscape::Util::Quantity::convert(prefs->getDouble("/options/grids/xy/origin_x", 0.0), gridunit, "px");
origin[Geom::Y] = Inkscape::Util::Quantity::convert(prefs->getDouble("/options/grids/xy/origin_y", 0.0), gridunit, "px");
spacing[Geom::X] = Inkscape::Util::Quantity::convert(prefs->getDouble("/options/grids/xy/spacing_x", 0.0), gridunit, "px");
spacing[Geom::Y] = Inkscape::Util::Quantity::convert(prefs->getDouble("/options/grids/xy/spacing_y", 0.0), gridunit, "px");
}
CanvasXYGrid::~CanvasXYGrid ()
{
}
{
if (!str) {
return FALSE;
}
gchar *u;
if (!u) {
return FALSE;
}
return TRUE;
}
/** If the passed int is invalid (<=0), then set the widget and the int
to use the given old value.
@param oldVal Old value to use if the new one is invalid.
@param pTarget The int to validate.
@param widget Widget associated with the int.
*/
{
// Avoid nullness.
return;
// Invalid new value?
if ( *pTarget <= 0 ) {
// If the old value is somehow invalid as well, then default to 1.
if ( oldVal <= 0 )
oldVal = 1;
// Reset the int and associated widget to the old value.
} //if
} //validateInt
void
{
double scale_x = 1.0;
double scale_y = 1.0;
if( root->viewBox_set ) {
// scaling is uniform, try to reduce numerical error
}
}
// Legacy grid not in 'user units'
} else {
// Grid in 'user units'
}
}
// Legacy grid not in 'user units'
} else {
// Grid in 'user units'
}
}
// Ensure a valid default value
// Ensure a valid new value
if( q.quantity > 0 ) {
// Legacy grid not in 'user units'
} else {
// Grid in 'user units'
}
}
}
// Ensure a valid default value
// Ensure a valid new value
if( q.quantity > 0 ) {
// Legacy grid not in 'user units'
} else {
// Grid in 'user units'
}
}
}
}
}
}
}
}
}
}
}
}
}
}
return;
}
/**
* Called when XML node attribute changed; updates dialog widgets if change was not done by widgets themselves.
*/
void
CanvasXYGrid::onReprAttrChanged(Inkscape::XML::Node */*repr*/, gchar const */*key*/, gchar const */*oldval*/, gchar const */*newval*/, bool /*is_interactive*/)
{
readRepr();
if ( ! (_wr.isUpdating()) )
}
{
#if WITH_GTKMM_3_0
#else
#endif
Inkscape::UI::Widget::RegisteredUnitMenu *_rumg = Gtk::manage( new Inkscape::UI::Widget::RegisteredUnitMenu(
Inkscape::UI::Widget::RegisteredScalarUnit *_rsu_ox = Gtk::manage( new Inkscape::UI::Widget::RegisteredScalarUnit(
_("_Origin X:"), _("X coordinate of grid origin"), "originx",
Inkscape::UI::Widget::RegisteredScalarUnit *_rsu_oy = Gtk::manage( new Inkscape::UI::Widget::RegisteredScalarUnit(
_("O_rigin Y:"), _("Y coordinate of grid origin"), "originy",
Inkscape::UI::Widget::RegisteredScalarUnit *_rsu_sx = Gtk::manage( new Inkscape::UI::Widget::RegisteredScalarUnit(
_("Spacing _X:"), _("Distance between vertical grid lines"), "spacingx",
Inkscape::UI::Widget::RegisteredScalarUnit *_rsu_sy = Gtk::manage( new Inkscape::UI::Widget::RegisteredScalarUnit(
_("Spacing _Y:"), _("Distance between horizontal grid lines"), "spacingy",
_("Minor grid line _color:"), _("Minor grid line color"), _("Color of the minor grid lines"),
_("Ma_jor grid line color:"), _("Major grid line color"),
_("Color of the major (highlighted) grid lines"), "empcolor", "empopacity",
Inkscape::UI::Widget::RegisteredSuffixedInteger *_rsi = Gtk::manage( new Inkscape::UI::Widget::RegisteredSuffixedInteger(
_wr.setUpdating (true);
_("If set, displays dots at gridpoints instead of gridlines"),
0, _rumg,
0, _rsu_ox,
0, _rsu_oy,
0, _rsu_sx,
0, _rsu_sy,
0, 0,
0, _rsi,
0, _rcb_dotted,
};
// set widget values
_wr.setUpdating (false);
_rsu_ox->setProgrammatically = false;
_rsu_oy->setProgrammatically = false;
_rsu_sx->setProgrammatically = false;
_rsu_sy->setProgrammatically = false;
return table;
}
/**
* Update dialog widgets from object's values.
*/
void
{
/*
if (_wr.isUpdating()) return;
_wr.setUpdating (true);
_rcb_visible.setActive(visible);
if (snapper != NULL) {
_rcb_enabled.setActive(snapper->getEnabled());
}
_rumg.setUnit (gridunit->abbr);
gdouble val;
val = origin[Geom::X];
val = Inkscape::Quantity::convert(val, "px", *gridunit);
_rsu_ox.setValue (val);
val = origin[Geom::Y];
val = Inkscape::Quantity::convert(val, "px", *gridunit);
_rsu_oy.setValue (val);
val = spacing[Geom::X];
double gridx = Inkscape::Quantity::convert(val, "px", *gridunit);
_rsu_sx.setValue (gridx);
val = spacing[Geom::Y];
double gridy = Inkscape::Quantity::convert(val, "px", *gridunit);
_rsu_sy.setValue (gridy);
_rcp_gcol.setRgba32 (color);
_rcp_gmcol.setRgba32 (empcolor);
_rsi.setValue (empspacing);
_rcb_dotted.setActive(render_dotted);
_wr.setUpdating (false);
return;
*/
}
void
{
if (scaling_factor <= 1)
scaling_factor = 5;
/* First pass, go up to the major line spacing, then
keep increasing by two. */
scaling_factor = 2;
}
}
}
static void
{
return;
}
static void
{
return;
}
static void
{
return;
}
void
{
gdouble const sxg = floor ((buf->rect.left() - ow[Geom::X]) / sw[Geom::X]) * sw[Geom::X] + ow[Geom::X];
gdouble const syg = floor ((buf->rect.top() - ow[Geom::Y]) / sw[Geom::Y]) * sw[Geom::Y] + ow[Geom::Y];
//set correct coloring, depending preference (when zoomed out, always major coloring or minor coloring)
} else {
}
if (!render_dotted) {
gdouble y;
} else {
}
}
gdouble x;
} else {
}
}
} else {
gdouble y;
gdouble x;
{
} else {
}
}
}
}
}
CanvasXYGridSnapper::CanvasXYGridSnapper(CanvasXYGrid *grid, SnapManager *sm, Geom::Coord const d) : LineSnapper(sm, d)
{
}
/**
* \return Snap tolerance (desktop coordinates); depends on current zoom so that it's always the same in screen pixels
*/
{
}
bool CanvasXYGridSnapper::getSnapperAlwaysSnap() const
{
return _snapmanager->snapprefs.getGridTolerance() == 10000; //TODO: Replace this threshold of 10000 by a constant; see also tolerance-slider.cpp
}
{
LineList s;
return s;
}
for (unsigned int i = 0; i < 2; ++i) {
double spacing;
if (getSnapVisibleOnly()) {
// Only snapping to visible grid lines
// convert screen pixels to px
// FIXME: after we switch to snapping dist in screen pixels, this will be unnecessary
if (dt) {
}
} else {
// Snapping to any grid line, whether it's visible or not
}
cvec[i] = 1.;
}
return s;
}
void CanvasXYGridSnapper::_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, Geom::Point const &point_on_line) const
{
SnappedLine dummy = SnappedLine(snapped_point, snapped_distance, source, source_num, Inkscape::SNAPTARGET_GRID, getSnapperTolerance(), getSnapperAlwaysSnap(), normal_to_line, point_on_line);
}
void CanvasXYGridSnapper::_addSnappedPoint(IntermSnapResults &isr, Geom::Point const &snapped_point, Geom::Coord const &snapped_distance, SnapSourceType const &source, long source_num, bool constrained_snap) const
{
SnappedPoint dummy = SnappedPoint(snapped_point, source, source_num, Inkscape::SNAPTARGET_GRID, snapped_distance, getSnapperTolerance(), getSnapperAlwaysSnap(), constrained_snap, true);
}
void CanvasXYGridSnapper::_addSnappedLinePerpendicularly(IntermSnapResults &isr, Geom::Point const &snapped_point, Geom::Coord const &snapped_distance, SnapSourceType const &source, long source_num, bool constrained_snap) const
{
SnappedPoint dummy = SnappedPoint(snapped_point, source, source_num, Inkscape::SNAPTARGET_GRID_PERPENDICULAR, snapped_distance, getSnapperTolerance(), getSnapperAlwaysSnap(), constrained_snap, true);
}
/**
* \return true if this Snapper will snap at least one kind of point.
*/
bool CanvasXYGridSnapper::ThisSnapperMightSnap() const
{
}
} // namespace Inkscape
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :