/*
* Authors:
* Johan Engelen <j.b.c.engelen@alumnus.utwente.nl>
*
* Copyright (C) 2006-2012 Authors
* Released under GNU GPL, read the file 'COPYING' for more information
*/
/*
* Current limits are: one axis (y-axis) is always vertical. The other two
* axes are bound to a certain range of angles. The z-axis always has an angle
* smaller than 90 degrees (measured from horizontal, 0 degrees being a line extending
* to the right). The x-axis will always have an angle between 0 and 90 degrees.
*/
#if HAVE_CONFIG_H
# include "config.h"
#endif
#if WITH_GTKMM_3_0
#else
#endif
#include "display/canvas-axonomgrid.h"
#include "ui/widget/registered-widget.h"
#include "desktop.h"
#include "display/cairo-utils.h"
#include "display/canvas-grid.h"
#include "display/sp-canvas-util.h"
#include "display/sp-canvas.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 "round.h"
enum Dim3 { X=0, Y, Z };
/**
* This function calls Cairo to render a line on a particular canvas buffer.
* Coordinates are interpreted as SCREENcoordinates
*/
static void
{
}
static void
{
return;
}
namespace Inkscape {
/**
* 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.
**/
static inline void
#if WITH_GTKMM_3_0
#else
#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;
}
}
CanvasAxonomGrid::CanvasAxonomGrid (SPNamedView * nv, Inkscape::XML::Node * in_repr, SPDocument * in_doc)
{
if (!gridunit) {
}
origin[Geom::X] = Inkscape::Util::Quantity::convert(prefs->getDouble("/options/grids/axonom/origin_x", 0.0), gridunit, "px");
origin[Geom::Y] = Inkscape::Util::Quantity::convert(prefs->getDouble("/options/grids/axonom/origin_y", 0.0), gridunit, "px");
lengthy = Inkscape::Util::Quantity::convert(prefs->getDouble("/options/grids/axonom/spacing_y", 1.0), gridunit, "px");
angle_deg[Y] = 0;
}
{
}
{
if (!str) {
return FALSE;
}
gchar *u;
if (!u) {
return FALSE;
}
return TRUE;
}
void
{
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'
}
}
// 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
CanvasAxonomGrid::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
_wr.setUpdating (true);
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_sy = Gtk::manage( new Inkscape::UI::Widget::RegisteredScalarUnit(
_("Spacing _Y:"), _("Base length of z-axis"), "spacingy",
Inkscape::UI::Widget::RegisteredScalar *_rsu_ax = Gtk::manage( new Inkscape::UI::Widget::RegisteredScalar(
Inkscape::UI::Widget::RegisteredScalar *_rsu_az = Gtk::manage( new Inkscape::UI::Widget::RegisteredScalar(
_("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"),
Inkscape::UI::Widget::RegisteredSuffixedInteger *_rsi = Gtk::manage( new Inkscape::UI::Widget::RegisteredSuffixedInteger(
_wr.setUpdating (false);
0, _rumg,
0, _rsu_ox,
0, _rsu_oy,
0, _rsu_sy,
0, _rsu_ax,
0, _rsu_az,
0, 0,
0, _rsi,
};
// set widget values
_rsu_ox->setProgrammatically = false;
_rsu_oy->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::Util::Quantity::convert(val, &px, gridunit);
_rsu_ox.setValue (val);
val = origin[Geom::Y];
val = Inkscape::Util::Quantity::convert(val, &px, gridunit);
_rsu_oy.setValue (val);
val = lengthy;
double gridy = Inkscape::Util::Quantity::convert(val, &px, gridunit);
_rsu_sy.setValue (gridy);
_rsu_ax.setValue(angle_deg[X]);
_rsu_az.setValue(angle_deg[Z]);
_rcp_gcol.setRgba32 (color);
_rcp_gmcol.setRgba32 (empcolor);
_rsi.setValue (empspacing);
_wr.setUpdating (false);
return;
*/
}
void
{
scaled = false;
if (scaling_factor <= 1)
scaling_factor = 5;
int watchdog = 0;
scaled = true;
// First pass, go up to the major line spacing, then
// keep increasing by two.
scaling_factor = 2;
watchdog++;
}
}
if (empspacing == 0) {
scaled = true;
}
}
void
{
//set correct coloring, depending preference (when zoomed out, always major coloring or minor coloring)
if( scaled && preference ) {
} else {
}
// gc = gridcoordinates (the coordinates calculated from the grids origin 'grid->ow'.
// sc = screencoordinates ( for example "buf->rect.left()" is in screencoordinates )
// bc = buffer patch coordinates (x=0 on left side of page, y=0 on bottom of page)
// tl = topleft ; br = bottomright
// render the three separate line groups representing the main-axes
// x-axis always goes from topleft to bottomright. (0,0) - (1,1)
gint const xlinestart = round( (xstart_y_sc - buf_tl_gc[Geom::X]*tan_angle[X] - ow[Geom::Y]) / lyw );
// lines starting on left side.
}
} else {
}
}
// lines starting from top side
{
gdouble const xstart_x_sc = buf->rect.left() + (lxw_x - (xstart_y_sc - buf->rect.top()) / tan_angle[X]) ;
} else {
}
}
}
// y-axis lines (vertical)
gdouble const ystart_x_sc = floor (buf_tl_gc[Geom::X] / spacing_ylines) * spacing_ylines + ow[Geom::X];
} else {
}
}
// z-axis always goes from bottomleft to topright. (0,1) - (1,0)
gint const zlinestart = round( (zstart_y_sc + buf_tl_gc[Geom::X]*tan_angle[Z] - ow[Geom::Y]) / lyw );
// lines starting from left side
}
} else {
}
}
// draw lines from bottom-up
{
} else {
}
}
}
}
CanvasAxonomGridSnapper::CanvasAxonomGridSnapper(CanvasAxonomGrid *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
*/
{
}
{
return _snapmanager->snapprefs.getGridTolerance() == 10000; //TODO: Replace this threshold of 10000 by a constant; see also tolerance-slider.cpp
}
{
LineList s;
return s;
}
double spacing_h;
double spacing_v;
if (getSnapVisibleOnly()) {
// Only snapping to visible grid lines
spacing_h = grid->spacing_ylines; // this is the spacing of the visible grid lines measured in screen pixels
// 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
}
// In an axonometric grid, any point will be surrounded by 6 grid lines:
// - 2 vertical grid lines, one left and one right from the point
// - 2 angled z grid lines, one above and one below the point
// - 2 angled x grid lines, one above and one below the point
// Calculate the x coordinate of the vertical grid lines
Geom::Coord x_max = Inkscape::Util::round_to_upper_multiple_plus(p[Geom::X], spacing_h, grid->origin[Geom::X]);
Geom::Coord x_min = Inkscape::Util::round_to_lower_multiple_plus(p[Geom::X], spacing_h, grid->origin[Geom::X]);
// Calculate the y coordinate of the intersection of the angled grid lines with the y-axis
double y_proj_along_z_max = Inkscape::Util::round_to_upper_multiple_plus(y_proj_along_z, spacing_v, grid->origin[Geom::Y]);
double y_proj_along_z_min = Inkscape::Util::round_to_lower_multiple_plus(y_proj_along_z, spacing_v, grid->origin[Geom::Y]);
double y_proj_along_x_max = Inkscape::Util::round_to_upper_multiple_plus(y_proj_along_x, spacing_v, grid->origin[Geom::Y]);
double y_proj_along_x_min = Inkscape::Util::round_to_lower_multiple_plus(y_proj_along_x, spacing_v, grid->origin[Geom::Y]);
// Calculate the versor for the angled grid lines
// Calculate the normal for the angled grid lines
// The four angled grid lines form a parallelogram, enclosing the point
// One of the two vertical grid lines divides this parallelogram in two triangles
// We will now try to find out in which half (i.e. triangle) our point is, and return
// only the three grid lines defining that triangle
// The vertical grid line is at the intersection of two angled grid lines.
// Now go find that intersection!
try
{
}
catch (Geom::InfiniteSolutions &e)
{
// We're probably dealing with parallel lines; this is useless!
return s;
}
// Determine which half of the parallelogram to use
bool use_left_half = true;
bool use_right_half = true;
if (inters) {
}
// Return the three grid lines which define the triangle that encloses our point
// If we didn't find an intersection above, all 6 grid lines will be returned
if (use_left_half) {
}
if (use_right_half) {
}
return s;
}
void CanvasAxonomGridSnapper::_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 CanvasAxonomGridSnapper::_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 CanvasAxonomGridSnapper::_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);
}
{
}
}; // 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 :