canvas-axonomgrid.cpp revision 13fb8f69456a16aa361d3c7db68b9551f3f3ae53
#define CANVAS_AXONOMGRID_C
/*
* Copyright (C) 2006-2008 Johan Engelen <johan@shouraizou.nl>
*/
/*
* 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.
*/
/*
* TODO:
* THIS FILE AND THE HEADER FILE NEED CLEANING UP. PLEASE DO NOT HESISTATE TO DO SO.
* For example: the line drawing code should not be here. There _must_ be a function somewhere else that can provide this functionality...
*/
#include "sp-canvas-util.h"
#include "canvas-axonomgrid.h"
#include "display-forward.h"
#include <libnr/nr-pixops.h>
#include "canvas-grid.h"
#include "desktop-handles.h"
#include "svg/svg-color.h"
#include "xml/node-event-vector.h"
#include "sp-object.h"
#include "sp-namedview.h"
#include "inkscape.h"
#include "desktop.h"
#include "document.h"
#include "preferences.h"
#define SAFE_SETPIXEL //undefine this when it is certain that setpixel is never called with invalid params
enum Dim3 { X=0, Y, Z };
#ifndef M_PI
# define M_PI 3.14159265358979323846
#endif
/**
\brief This function renders a pixel on a particular buffer.
The topleft of the buffer equals
( rect.x0 , rect.y0 ) in screen coordinates
( 0 , 0 ) in setpixel coordinates
The bottomright of the buffer equals
( rect.x1 , rect,y1 ) in screen coordinates
( rect.x1 - rect.x0 , rect.y1 - rect.y0 ) in setpixel coordinates
*/
static void
{
#ifdef SAFE_SETPIXEL
#endif
guint r, g, b, a;
r = NR_RGBA32_R (rgba);
g = NR_RGBA32_G (rgba);
b = NR_RGBA32_B (rgba);
a = NR_RGBA32_A (rgba);
p[0] = NR_COMPOSEN11_1111 (r, a, p[0]);
#ifdef SAFE_SETPIXEL
}
#endif
}
/**
\brief This function renders a line on a particular canvas buffer,
using Bresenham's line drawing function.
Coordinates are interpreted as SCREENcoordinates
*/
static void
{
if (fraction >= 0) {
}
}
} else {
if (fraction >= 0) {
}
}
}
}
static void
{
guint r, g, b, a;
guchar *p;
r = NR_RGBA32_R(rgba);
g = NR_RGBA32_G (rgba);
b = NR_RGBA32_B (rgba);
a = NR_RGBA32_A (rgba);
p[0] = NR_COMPOSEN11_1111 (r, a, p[0]);
p += buf->buf_rowstride;
}
}
}
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.
**/
#define SPACE_SIZE_X 15
#define SPACE_SIZE_Y 10
static inline void
{
} else {
if (arr[i+1]) {
} else if (arr[i]) {
} else {
}
}
++r;
}
}
CanvasAxonomGrid::CanvasAxonomGrid (SPNamedView * nv, Inkscape::XML::Node * in_repr, SPDocument * in_doc)
{
if (!gridunit)
origin[Geom::X] = sp_units_get_pixels( prefs->getDouble("/options/grids/axonom/origin_x", 0.0), *gridunit );
origin[Geom::Y] = sp_units_get_pixels( prefs->getDouble("/options/grids/axonom/origin_y", 0.0), *gridunit );
lengthy = sp_units_get_pixels( prefs->getDouble("/options/grids/axonom/spacing_y", 1.0), *gridunit );
angle_deg[Y] = 0;
}
{
}
/* fixme: Collect all these length parsing methods and think common sane API */
{
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;
}
void
{
}
}
}
}
}
}
}
}
}
}
}
}
}
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()) )
}
{
_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(
Inkscape::UI::Widget::RegisteredScalarUnit *_rsu_oy = Gtk::manage( new Inkscape::UI::Widget::RegisteredScalarUnit(
Inkscape::UI::Widget::RegisteredScalarUnit *_rsu_sy = Gtk::manage( new Inkscape::UI::Widget::RegisteredScalarUnit(
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(
_("Grid line _color:"), _("Grid line color"), _("Color of 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
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 = lengthy;
double gridy = sp_pixels_get_units (val, *(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
{
if (scaling_factor <= 1)
scaling_factor = 5;
int watchdog = 0;
// First pass, go up to the major line spacing, then
// keep increasing by two.
scaling_factor = 2;
watchdog++;
}
}
if (empspacing == 0) {
}
}
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.x0" is in screencoordinates )
// bc = buffer patch coordinates
// tl = topleft ; br = bottomright
gdouble x;
gdouble y;
// 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 = (gint) Inkscape::round( (xstart_y_sc - buf->rect.x0*tan_angle[X] -ow[Geom::Y]) / lyw );
// lines starting on left side.
} else {
}
}
// lines starting from top side
} 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 = (gint) Inkscape::round( (zstart_y_sc + buf->rect.x0*tan_angle[Z] - ow[Geom::Y]) / lyw );
// lines starting from left side
} else {
}
}
// draw lines from bottom-up
} else {
}
}
}
CanvasAxonomGridSnapper::CanvasAxonomGridSnapper(CanvasAxonomGrid *grid, SnapManager const *sm, Geom::Coord const d) : LineSnapper(sm, d)
{
}
{
LineList s;
return s;
}
/* This is to make sure we snap to only visible grid lines */
double scaled_spacing_h = grid->spacing_ylines; // this is spacing of visible lines if screen pixels
// convert screen pixels to px
// FIXME: after we switch to snapping dist in screen pixels, this will be unnecessary
if (SP_ACTIVE_DESKTOP) {
}
// 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], scaled_spacing_h, grid->origin[Geom::X]);
Geom::Coord x_min = Inkscape::Util::round_to_lower_multiple_plus(p[Geom::X], scaled_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, scaled_spacing_v, grid->origin[Geom::Y]);
double y_proj_along_z_min = Inkscape::Util::round_to_lower_multiple_plus(y_proj_along_z, scaled_spacing_v, grid->origin[Geom::Y]);
double y_proj_along_x_max = Inkscape::Util::round_to_upper_multiple_plus(y_proj_along_x, scaled_spacing_v, grid->origin[Geom::Y]);
double y_proj_along_x_min = Inkscape::Util::round_to_lower_multiple_plus(y_proj_along_x, scaled_spacing_v, grid->origin[Geom::Y]);
// Calculate the normal for the angled grid lines
// The four angled grid lines form a parallellogram, enclosing the point
// One of the two vertical grid lines divides this parallellogram 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!
result);
// Determine which half of the parallellogram to use
bool use_left_half = true;
bool use_right_half = true;
}
//std::cout << "intersection at " << result << " leads to use_left_half = " << use_left_half << " and use_right_half = " << use_right_half << std::endl;
// 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(SnappedConstraints &sc, Geom::Point const snapped_point, Geom::Coord const snapped_distance, Geom::Point const normal_to_line, Geom::Point const point_on_line) const
{
SnappedLine dummy = SnappedLine(snapped_point, snapped_distance, getSnapperTolerance(), getSnapperAlwaysSnap(), normal_to_line, point_on_line);
}
}; // 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:encoding=utf-8:textwidth=99 :