canvas-grid.cpp revision c55855b9f7b0074b0a0e4ab8e1cd743e2ed01ad6
/** @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.
*/
#include "ui/widget/registered-widget.h"
#include "desktop.h"
#include "sp-canvas-util.h"
#include "desktop-handles.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 "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 SPCanvasItemClass * parent_class;
grid_canvasitem_get_type (void)
{
static GType grid_canvasitem_type = 0;
if (!grid_canvasitem_type) {
sizeof (GridCanvasItemClass),
sizeof (GridCanvasItem),
0,
};
grid_canvasitem_type = g_type_register_static(SPCanvasItem::getType(), "GridCanvasItem", &grid_canvasitem_info, GTypeFlags(0));
}
return grid_canvasitem_type;
}
{
}
static void
{
}
{
}
/**
*/
static void
{
}
}
static void
{
if (parent_class->update)
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 *
{
}
const char *
{
return grid_svgname[gridtype];
}
{
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(sp_desktop_gridgroup(desktop), 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()
{
return false;
}
return snapper->getEnabled();
}
{
}
// ##########################################################
// 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
static inline void
{
} else {
if (arr[i+1]) {
} else if (arr[i]) {
} else {
}
}
++r;
}
}
{
if (!gridunit) {
}
origin[Geom::X] = sp_units_get_pixels(prefs->getDouble("/options/grids/xy/origin_x", 0.0), *gridunit);
origin[Geom::Y] = sp_units_get_pixels(prefs->getDouble("/options/grids/xy/origin_y", 0.0), *gridunit);
spacing[Geom::X] = sp_units_get_pixels(prefs->getDouble("/options/grids/xy/spacing_x", 0.0), *gridunit);
spacing[Geom::Y] = sp_units_get_pixels(prefs->getDouble("/options/grids/xy/spacing_y", 0.0), *gridunit);
}
CanvasXYGrid::~CanvasXYGrid ()
{
}
/* fixme: Collect all these length parsing methods and think common sane API */
static gboolean
{
if (!str) {
return FALSE;
}
gchar *u;
if (!u) {
return FALSE;
}
while (isspace(*u)) {
u += 1;
}
if (!*u) {
/* No unit specified - keep default */
*val = v;
return TRUE;
}
if (base & SP_UNIT_DEVICE) {
*val = v;
return TRUE;
}
}
if (base & SP_UNIT_ABSOLUTE) {
} else {
return FALSE;
}
*val = v;
return TRUE;
}
return FALSE;
}
{
if (!str) {
return FALSE;
}
gchar *u;
if (!u) {
return FALSE;
}
return TRUE;
}
/** If the passed scalar is invalid (<=0), then set the widget and the scalar
to use the given old value.
@param oldVal Old value to use if the new one is invalid.
@param pTarget The scalar to validate.
@param widget Widget associated with the scalar.
*/
static void validateScalar(double oldVal,
double* pTarget)
{
// 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 scalar and associated widget to the old value.
} //if
} //validateScalar
/** 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
{
}
}
}
}
}
}
}
}
}
}
}
}
}
}
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()) )
}
{
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(
Inkscape::UI::Widget::RegisteredScalarUnit *_rsu_oy = Gtk::manage( new Inkscape::UI::Widget::RegisteredScalarUnit(
Inkscape::UI::Widget::RegisteredScalarUnit *_rsu_sx = Gtk::manage( new Inkscape::UI::Widget::RegisteredScalarUnit(
Inkscape::UI::Widget::RegisteredScalarUnit *_rsu_sy = Gtk::manage( new Inkscape::UI::Widget::RegisteredScalarUnit(
_("Spacing _Y:"), _("Distance between horizontal grid lines"), "spacingy", *_rumg, _wr, repr, doc) );
_("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_sx->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);
gdouble val;
val = origin[Geom::X];
val = sp_pixels_get_units (val, *(gridunit));
_rsu_ox.setValue (val);
val = origin[Geom::Y];
val = sp_pixels_get_units (val, *(gridunit));
_rsu_oy.setValue (val);
val = spacing[Geom::X];
double gridx = sp_pixels_get_units (val, *(gridunit));
_rsu_sx.setValue (gridx);
val = spacing[Geom::Y];
double gridy = sp_pixels_get_units (val, *(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 :