spray-context.cpp revision 00e64c815306880048be0ce288e18fda9de0d57e
/*
* Spray Tool
*
* Authors:
* Pierre-Antoine MARC
* Pierre CACLIN
* Aurel-Aimé MARMION
* Julien LERAY
* Benoît LAVORATA
* Vincent MONTAGNE
* Pierre BARBRY-BLOT
* Steren GIANNINI (steren.giannini@gmail.com)
* Jon A. Cruz <jon@joncruz.org>
* Abhishek Sharma
*
* Copyright (C) 2009 authors
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#include "config.h"
#include <gdk/gdkkeysyms.h>
#include <numeric>
#include "macros.h"
#include "document.h"
#include "selection.h"
#include "desktop.h"
#include "desktop-events.h"
#include "desktop-handles.h"
#include "unistd.h"
#include "message-context.h"
#include "pixmaps/cursor-spray.xpm"
#include <boost/optional.hpp>
#include "libnr/nr-matrix-ops.h"
#include "libnr/nr-scale-translate-ops.h"
#include "context-fns.h"
#include "sp-item.h"
#include "inkscape.h"
#include "splivarot.h"
#include "sp-item-group.h"
#include "sp-shape.h"
#include "sp-path.h"
#include "path-chemistry.h"
#include "sp-text.h"
#include "sp-flowtext.h"
#include "display/sp-canvas.h"
#include "display/canvas-bpath.h"
#include "display/canvas-arena.h"
#include "preferences.h"
#include "style.h"
#include "box3d.h"
#include "sp-item-transform.h"
#include "filter-chemistry.h"
#include "spray-context.h"
#include "ui/dialog/dialog-manager.h"
#include <iostream>
using Inkscape::DocumentUndo;
using namespace std;
#define DDC_RED_RGBA 0xff0000ff
#define DYNA_MIN_WIDTH 1.0e-6
static SPEventContextClass *parent_class = 0;
/**
* This function returns pseudo-random numbers from a normal distribution
* @param mu : mean
* @param sigma : standard deviation ( > 0 )
*/
{
// use Box Muller's algorithm
return mu + sigma * sqrt( -2.0 * log(g_random_double_range(0, 1)) ) * cos( 2.0*M_PI*g_random_double_range(0, 1) );
}
{
if (!type) {
sizeof(SPSprayContextClass),
sizeof(SPSprayContext),
4,
NULL, /* value_table */
};
}
return type;
}
{
}
/* Method to rotate items */
void sp_spray_rotate_rel(Geom::Point c, SPDesktop */*desktop*/, SPItem *item, Geom::Rotate const &rotation)
{
// Rotate item.
// Use each item's own transform writer, consistent with sp_selection_apply_affine()
// Restore the center position (it's changed because the bbox center changed)
if (item->isCenterSet()) {
item->updateRepr();
}
}
/* Method to scale items */
void sp_spray_scale_rel(Geom::Point c, SPDesktop */*desktop*/, SPItem *item, Geom::Scale const &scale)
{
}
{
/* attributes */
tc->rotation_variation = 0;
tc->is_dilating = false;
tc->has_dilated = false;
}
{
if (tc->dilate_area) {
}
if (tc->_message_context) {
delete tc->_message_context;
}
}
{
return (mode == SPRAY_MODE_COPY ||
mode == SPRAY_MODE_CLONE ||
mode == SPRAY_MODE_SINGLE_PATH ||
mode == SPRAY_OPTION);
}
{
sel_message = g_strdup_printf(ngettext("<b>%i</b> object selected","<b>%i</b> objects selected",num), num);
} else {
}
case SPRAY_MODE_COPY:
tc->_message_context->setF(Inkscape::NORMAL_MESSAGE, _("%s. Drag, click or scroll to spray <b>copies</b> of the initial selection."), sel_message);
break;
case SPRAY_MODE_CLONE:
tc->_message_context->setF(Inkscape::NORMAL_MESSAGE, _("%s. Drag, click or scroll to spray <b>clones</b> of the initial selection."), sel_message);
break;
case SPRAY_MODE_SINGLE_PATH:
tc->_message_context->setF(Inkscape::NORMAL_MESSAGE, _("%s. Drag, click or scroll to spray in a <b>single path</b> of the initial selection."), sel_message);
break;
default:
break;
}
}
{
}
{
/* TODO: have a look at sp_dyna_draw_context_setup where the same is done.. generalize? at least make it an arcto! */
const double C1 = 0.552;
c->moveto(-1,0);
c->closepath();
c->unref();
sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(tc->dilate_area), 0xff9900ff, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
}
tc->is_drawing = false;
ec->enableSelectionCue();
}
ec->enableGrDrag();
}
}
{
if (path == "mode") {
sp_spray_update_cursor(tc, false);
} else if (path == "width") {
} else if (path == "usepressure") {
} else if (path == "population") {
} else if (path == "rotation_variation") {
} else if (path == "scale_variation") {
} else if (path == "standard_deviation") {
} else if (path == "mean") {
// Not implemented in the toolbar and preferences yet
} else if (path == "distribution") {
} else if (path == "tilt") {
} else if (path == "ratio") {
} else if (path == "force") {
}
}
{
} else {
}
}
{
}
{
if (force > 3) {
}
}
{
}
{
return tc->standard_deviation;
}
{
}
{
}
{
return tc->standard_deviation;
}
/**
* Method to handle the distribution of the items
* @param[out] radius : radius of the position of the sprayed object
* @param[out] angle : angle of the position of the sprayed object
* @param[in] a : mean
* @param[in] s : standard deviation
* @param[in] choice :
*/
{
// angle is taken from an uniform distribution
// radius is taken from a Normal Distribution
double radius_temp =-1;
{
radius_temp = NormalDistribution(a, s);
}
// Because we are in polar coordinates, a special treatment has to be done to the radius.
// Otherwise, positions taken from an uniform repartition on radius and angle will not seam to
// be uniformily distributed on the disk (more at the center and less at the boundary).
// We counter this effect with a 0.5 exponent. This is empiric.
}
double radius,
double /*force*/,
double population,
double &scale,
double scale_variation,
bool /*reverse*/,
double mean,
double standard_deviation,
double ratio,
double tilt,
double rotation_variation,
{
bool did = false;
if (SP_IS_BOX3D(item) ) {
// convert 3D boxes to ordinary groups before spraying their shapes
}
double angle = g_random_double_range( - rotation_variation / 100.0 * M_PI , rotation_variation / 100.0 * M_PI );
double _scale = g_random_double_range( 1.0 - scale_variation / 100.0, 1.0 + scale_variation / 100.0 );
if (mode == SPRAY_MODE_COPY) {
if (a) {
if(_fid <= population)
{
// duplicate
//Move the cursor p
Geom::Point move = (Geom::Point(cos(tilt)*cos(dp)*dr/(1-ratio)+sin(tilt)*sin(dp)*dr/(1+ratio), -sin(tilt)*cos(dp)*dr/(1-ratio)+cos(tilt)*sin(dp)*dr/(1+ratio)))+(p-a->midpoint());
did = true;
}
}
} else if (mode == SPRAY_MODE_SINGLE_PATH) {
int i=1;
if (i == 1) {
}
if (i == 2) {
unionResult = item1;
}
i++;
}
if (a) {
if (i == 2) {
unionResult = son;
}
// duplicates the father
// Move around the cursor
Geom::Point move = (Geom::Point(cos(tilt)*cos(dp)*dr/(1-ratio)+sin(tilt)*sin(dp)*dr/(1+ratio), -sin(tilt)*cos(dp)*dr/(1-ratio)+cos(tilt)*sin(dp)*dr/(1+ratio)))+(p-a->midpoint());
// union and duplication
did = true;
}
}
} else if (mode == SPRAY_MODE_CLONE) {
if (a) {
if(_fid <= population) {
// Creation of the clone
// Ad the clone to the list of the father's sons
// Generates the link between father and son attributes
// conversion object->item
Geom::Point move = (Geom::Point(cos(tilt)*cos(dp)*dr/(1-ratio)+sin(tilt)*sin(dp)*dr/(1+ratio), -sin(tilt)*cos(dp)*dr/(1-ratio)+cos(tilt)*sin(dp)*dr/(1+ratio)))+(p-a->midpoint());
did = true;
}
}
}
return did;
}
bool sp_spray_dilate(SPSprayContext *tc, Geom::Point /*event_p*/, Geom::Point p, Geom::Point vector, bool reverse)
{
return false;
}
bool did = false;
if (radius == 0 || path_force == 0) {
return false;
}
return false;
}
if (radius == 0 || path_standard_deviation == 0) {
return false;
}
if (sp_spray_recursive(desktop, selection, item, p, vector, tc->mode, radius, move_force, tc->population, tc->scale, tc->scale_variation, reverse, move_mean, move_standard_deviation, tc->ratio, tc->tilt, tc->rotation_variation, tc->distrib))
did = true;
} else {
if (sp_spray_recursive(desktop, selection, item, p, vector, tc->mode, radius, path_force, tc->population, tc->scale, tc->scale_variation, reverse, path_mean, path_standard_deviation, tc->ratio, tc->tilt, tc->rotation_variation, tc->distrib))
did = true;
}
}
return did;
}
{
sp_canvas_item_affine_absolute(tc->dilate_area, (sm* Geom::Rotate(tc->tilt))* Geom::Translate(SP_EVENT_CONTEXT(tc)->desktop->point()));
}
{
// select the button mode
// need to set explicitly, because the prefs may not have changed by the previous
}
{
// Juggling about so that prefs have the old value but tc->mode and the button show new mode:
// button has changed prefs, restore
// changing prefs changed tc->mode, restore back :)
}
{
case GDK_ENTER_NOTIFY:
break;
case GDK_LEAVE_NOTIFY:
break;
case GDK_BUTTON_PRESS:
return TRUE;
}
tc->is_drawing = true;
tc->is_dilating = true;
tc->has_dilated = false;
}
tc->has_dilated = true;
}
break;
case GDK_MOTION_NOTIFY: {
// draw the dilating cursor
sp_canvas_item_affine_absolute(tc->dilate_area, (sm*Geom::Rotate(tc->tilt))*Geom::Translate(desktop->w2d(motion_w)));
}
if (num == 0) {
tc->_message_context->flash(Inkscape::ERROR_MESSAGE, _("<b>Nothing selected!</b> Select objects to spray."));
}
// dilating:
sp_spray_dilate(tc, motion_w, motion_doc, motion_doc - tc->last_push, event->button.state & GDK_SHIFT_MASK? true : false);
//tc->last_push = motion_doc;
tc->has_dilated = true;
// it's slow, so prevent clogging up with events
return TRUE;
}
}
break;
/*Spray with the scroll*/
case GDK_SCROLL: {
double temp ;
case GDK_SCROLL_DOWN:
case GDK_SCROLL_UP: {
return TRUE;
}
tc->is_drawing = true;
tc->is_dilating = true;
tc->has_dilated = false;
}
tc->has_dilated = true;
}
break;
case GDK_SCROLL_RIGHT:
{} break;
case GDK_SCROLL_LEFT:
{} break;
}
}
break;
}
case GDK_BUTTON_RELEASE: {
tc->is_drawing = false;
if (!tc->has_dilated) {
// if we did not rub, do a light tap
}
tc->is_dilating = false;
tc->has_dilated = false;
case SPRAY_MODE_COPY:
SP_VERB_CONTEXT_SPRAY, _("Spray with copies"));
break;
case SPRAY_MODE_CLONE:
SP_VERB_CONTEXT_SPRAY, _("Spray with clones"));
break;
case SPRAY_MODE_SINGLE_PATH:
SP_VERB_CONTEXT_SPRAY, _("Spray in single path"));
break;
}
}
break;
}
case GDK_KEY_PRESS:
case GDK_j:
case GDK_J:
if (MOD__SHIFT_ONLY) {
}
break;
case GDK_k:
case GDK_K:
if (MOD__SHIFT_ONLY) {
}
break;
case GDK_l:
case GDK_L:
if (MOD__SHIFT_ONLY) {
}
break;
case GDK_Up:
case GDK_KP_Up:
if (!MOD__CTRL_ONLY) {
}
}
break;
case GDK_Down:
case GDK_KP_Down:
if (!MOD__CTRL_ONLY) {
}
}
break;
case GDK_Right:
case GDK_KP_Right:
if (!MOD__CTRL_ONLY) {
}
// the same spinbutton is for alt+x
}
break;
case GDK_Left:
case GDK_KP_Left:
if (!MOD__CTRL_ONLY) {
}
}
break;
case GDK_Home:
case GDK_KP_Home:
break;
case GDK_End:
case GDK_KP_End:
break;
case GDK_x:
case GDK_X:
if (MOD__ALT_ONLY) {
}
break;
case GDK_Shift_L:
case GDK_Shift_R:
sp_spray_update_cursor(tc, true);
break;
case GDK_Control_L:
case GDK_Control_R:
break;
default:
break;
}
break;
case GDK_KEY_RELEASE: {
case GDK_Shift_L:
case GDK_Shift_R:
sp_spray_update_cursor(tc, false);
break;
case GDK_Control_L:
case GDK_Control_R:
break;
default:
break;
}
}
default:
break;
}
if (!ret) {
}
}
return ret;
}
/*
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 :