canvas-axonomgrid.cpp revision c2057a738f9ea8cb7acdeb1feb69cef5b0d4bc56
#define CANVAS_AXONOMGRID_C
/*
* Copyright (C) 2006-2007 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.
* When I quickly think about it: all possibilities are probably covered this way. Eg.
* a z-axis with negative angle can be replaced with an x-axis, etc.
*/
/*
* 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 "prefs-utils.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)
{
gridunit = sp_unit_get_by_abbreviation( prefs_get_string_attribute("options.grids.axonom", "units") );
if (!gridunit)
origin[NR::X] = sp_units_get_pixels( prefs_get_double_attribute ("options.grids.axonom", "origin_x", 0.0), *(gridunit) );
origin[NR::Y] = sp_units_get_pixels( prefs_get_double_attribute ("options.grids.axonom", "origin_y", 0.0), *(gridunit) );
lengthy = sp_units_get_pixels( prefs_get_double_attribute ("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::RegisteredScalarUnit *_rsu_ox = new Inkscape::UI::Widget::RegisteredScalarUnit();
Inkscape::UI::Widget::RegisteredScalarUnit *_rsu_oy = new Inkscape::UI::Widget::RegisteredScalarUnit();
Inkscape::UI::Widget::RegisteredScalarUnit *_rsu_sy = 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(
Inkscape::UI::Widget::RegisteredColorPicker *_rcp_gcol = new Inkscape::UI::Widget::RegisteredColorPicker();
Inkscape::UI::Widget::RegisteredColorPicker *_rcp_gmcol = new Inkscape::UI::Widget::RegisteredColorPicker();
Inkscape::UI::Widget::RegisteredSuffixedInteger *_rsi = new Inkscape::UI::Widget::RegisteredSuffixedInteger();
_("Color of the major (highlighted) grid lines"),
_wr.setUpdating (false);
0, _rsu_ax,
0, _rsu_az,
0, 0,
};
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[NR::X];
val = sp_pixels_get_units (val, *(gridunit));
_rsu_ox.setValue (val);
val = origin[NR::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
{
// 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[NR::Y]) / lyw );
// lines starting on left side.
} else {
}
}
// lines starting from top side
} else {
}
}
// y-axis lines (vertical)
} 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[X] - ow[NR::Y]) / lyw );
// lines starting from left side
} else {
}
}
// draw lines from bottom-up
} else {
}
}
}
CanvasAxonomGridSnapper::CanvasAxonomGridSnapper(CanvasAxonomGrid *grid, SPNamedView const *nv, NR::Coord const d) : LineSnapper(nv, 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
NR::Coord x_max = Inkscape::Util::round_to_upper_multiple_plus(p[NR::X], scaled_spacing_h, grid->origin[NR::X]);
NR::Coord x_min = Inkscape::Util::round_to_lower_multiple_plus(p[NR::X], scaled_spacing_h, grid->origin[NR::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[NR::Y]);
double y_proj_along_z_min = Inkscape::Util::round_to_lower_multiple_plus(y_proj_along_z, scaled_spacing_v, grid->origin[NR::Y]);
double y_proj_along_x_max = Inkscape::Util::round_to_upper_multiple_plus(y_proj_along_x, scaled_spacing_v, grid->origin[NR::Y]);
double y_proj_along_x_min = Inkscape::Util::round_to_lower_multiple_plus(y_proj_along_x, scaled_spacing_v, grid->origin[NR::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, NR::Point const snapped_point, NR::Coord const snapped_distance, NR::Point const normal_to_line, NR::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 :