summaryrefslogtreecommitdiffstats
path: root/src/ui/tools
diff options
context:
space:
mode:
authorJabier Arraiza Cenoz <jabier.arraiza@marker.es>2014-11-23 23:36:49 +0000
committerJabiertxof <jtx@jtx.marker.es>2014-11-23 23:36:49 +0000
commit0969085ddf607a7a98cf7fd6d9b10da5fbebe62d (patch)
tree59b2bc9ed3412ab2de4c703ef30342dfe2401704 /src/ui/tools
parentrefactor from lastApplied (diff)
parentFixed a bug pointed by suv running from comand line, also removed another des... (diff)
downloadinkscape-0969085ddf607a7a98cf7fd6d9b10da5fbebe62d.tar.gz
inkscape-0969085ddf607a7a98cf7fd6d9b10da5fbebe62d.zip
fixing to trunk
(bzr r12588.1.34)
Diffstat (limited to 'src/ui/tools')
-rw-r--r--src/ui/tools/arc-tool.cpp10
-rw-r--r--src/ui/tools/arc-tool.h2
-rw-r--r--src/ui/tools/box3d-tool.cpp10
-rw-r--r--src/ui/tools/calligraphic-tool.cpp2
-rw-r--r--src/ui/tools/connector-tool.cpp2
-rw-r--r--src/ui/tools/dropper-tool.cpp2
-rw-r--r--src/ui/tools/eraser-tool.cpp2
-rw-r--r--src/ui/tools/flood-tool.cpp10
-rw-r--r--src/ui/tools/flood-tool.h4
-rw-r--r--src/ui/tools/freehand-base.cpp232
-rw-r--r--src/ui/tools/freehand-base.h6
-rw-r--r--src/ui/tools/gradient-tool.cpp19
-rw-r--r--src/ui/tools/lpe-tool.cpp11
-rw-r--r--src/ui/tools/measure-tool.cpp61
-rw-r--r--src/ui/tools/mesh-tool.cpp2
-rw-r--r--src/ui/tools/node-tool.cpp74
-rw-r--r--src/ui/tools/node-tool.h5
-rw-r--r--src/ui/tools/pen-tool.cpp1034
-rw-r--r--src/ui/tools/pen-tool.h31
-rw-r--r--src/ui/tools/pencil-tool.cpp48
-rw-r--r--src/ui/tools/rect-tool.cpp10
-rw-r--r--src/ui/tools/rect-tool.h4
-rw-r--r--src/ui/tools/select-tool.cpp82
-rw-r--r--src/ui/tools/select-tool.h1
-rw-r--r--src/ui/tools/spiral-tool.cpp10
-rw-r--r--src/ui/tools/spiral-tool.h8
-rw-r--r--src/ui/tools/spray-tool.cpp36
-rw-r--r--src/ui/tools/star-tool.cpp10
-rw-r--r--src/ui/tools/text-tool.cpp10
-rw-r--r--src/ui/tools/text-tool.h7
-rw-r--r--src/ui/tools/tool-base.cpp20
-rw-r--r--src/ui/tools/tool-base.h4
-rw-r--r--src/ui/tools/tweak-tool.cpp88
-rw-r--r--src/ui/tools/zoom-tool.cpp2
34 files changed, 1495 insertions, 364 deletions
diff --git a/src/ui/tools/arc-tool.cpp b/src/ui/tools/arc-tool.cpp
index 43f8eb9e1..4f64ade25 100644
--- a/src/ui/tools/arc-tool.cpp
+++ b/src/ui/tools/arc-tool.cpp
@@ -40,7 +40,7 @@
#include "desktop-style.h"
#include "context-fns.h"
#include "verbs.h"
-#include "shape-editor.h"
+#include "ui/shape-editor.h"
#include "ui/tools/tool-base.h"
#include "ui/tools/arc-tool.h"
@@ -48,7 +48,7 @@
using Inkscape::DocumentUndo;
-#include "tool-factory.h"
+#include "ui/tool-factory.h"
namespace Inkscape {
namespace UI {
@@ -102,8 +102,8 @@ ArcTool::~ArcTool() {
* destroys old and creates new knotholder.
*/
void ArcTool::selection_changed(Inkscape::Selection* selection) {
- this->shape_editor->unset_item(SH_KNOTHOLDER);
- this->shape_editor->set_item(selection->singleItem(), SH_KNOTHOLDER);
+ this->shape_editor->unset_item();
+ this->shape_editor->set_item(selection->singleItem());
}
void ArcTool::setup() {
@@ -115,7 +115,7 @@ void ArcTool::setup() {
SPItem *item = sp_desktop_selection(this->desktop)->singleItem();
if (item) {
- this->shape_editor->set_item(item, SH_KNOTHOLDER);
+ this->shape_editor->set_item(item);
}
this->sel_changed_connection.disconnect();
diff --git a/src/ui/tools/arc-tool.h b/src/ui/tools/arc-tool.h
index c4c67660d..55cbaf78c 100644
--- a/src/ui/tools/arc-tool.h
+++ b/src/ui/tools/arc-tool.h
@@ -30,7 +30,7 @@ namespace Inkscape {
}
#define SP_ARC_CONTEXT(obj) (dynamic_cast<Inkscape::UI::Tools::ArcTool*>((Inkscape::UI::Tools::ToolBase*)obj))
-#define SP_IS_ARC_CONTEXT(obj) (dynamic_cast<const Inkscape::UI::Tools::ArcTool*>(const Inkscape::UI::Tools::ToolBase*(obj)) != NULL)
+#define SP_IS_ARC_CONTEXT(obj) (dynamic_cast<const Inkscape::UI::Tools::ArcTool*>(obj) != NULL)
namespace Inkscape {
namespace UI {
diff --git a/src/ui/tools/box3d-tool.cpp b/src/ui/tools/box3d-tool.cpp
index e00894d55..0a20a0842 100644
--- a/src/ui/tools/box3d-tool.cpp
+++ b/src/ui/tools/box3d-tool.cpp
@@ -47,12 +47,12 @@
#include "box3d-side.h"
#include "document-private.h"
#include "line-geometry.h"
-#include "shape-editor.h"
+#include "ui/shape-editor.h"
#include "verbs.h"
using Inkscape::DocumentUndo;
-#include "tool-factory.h"
+#include "ui/tool-factory.h"
namespace Inkscape {
namespace UI {
@@ -112,8 +112,8 @@ Box3dTool::~Box3dTool() {
* destroys old and creates new knotholder.
*/
void Box3dTool::selection_changed(Inkscape::Selection* selection) {
- this->shape_editor->unset_item(SH_KNOTHOLDER);
- this->shape_editor->set_item(selection->singleItem(), SH_KNOTHOLDER);
+ this->shape_editor->unset_item();
+ this->shape_editor->set_item(selection->singleItem());
if (selection->perspList().size() == 1) {
// selecting a single box changes the current perspective
@@ -147,7 +147,7 @@ void Box3dTool::setup() {
SPItem *item = sp_desktop_selection(this->desktop)->singleItem();
if (item) {
- this->shape_editor->set_item(item, SH_KNOTHOLDER);
+ this->shape_editor->set_item(item);
}
this->sel_changed_connection.disconnect();
diff --git a/src/ui/tools/calligraphic-tool.cpp b/src/ui/tools/calligraphic-tool.cpp
index 64097e834..d297fe5e1 100644
--- a/src/ui/tools/calligraphic-tool.cpp
+++ b/src/ui/tools/calligraphic-tool.cpp
@@ -82,7 +82,7 @@ using Inkscape::DocumentUndo;
#define DYNA_MIN_WIDTH 1.0e-6
-#include "tool-factory.h"
+#include "ui/tool-factory.h"
namespace Inkscape {
namespace UI {
diff --git a/src/ui/tools/connector-tool.cpp b/src/ui/tools/connector-tool.cpp
index d1355e807..7b5c84c16 100644
--- a/src/ui/tools/connector-tool.cpp
+++ b/src/ui/tools/connector-tool.cpp
@@ -109,7 +109,7 @@
using Inkscape::DocumentUndo;
-#include "tool-factory.h"
+#include "ui/tool-factory.h"
namespace Inkscape {
namespace UI {
diff --git a/src/ui/tools/dropper-tool.cpp b/src/ui/tools/dropper-tool.cpp
index 99d42a211..6c55f7484 100644
--- a/src/ui/tools/dropper-tool.cpp
+++ b/src/ui/tools/dropper-tool.cpp
@@ -52,7 +52,7 @@ using Inkscape::DocumentUndo;
static GdkCursor *cursor_dropper_fill = NULL;
static GdkCursor *cursor_dropper_stroke = NULL;
-#include "tool-factory.h"
+#include "ui/tool-factory.h"
namespace Inkscape {
namespace UI {
diff --git a/src/ui/tools/eraser-tool.cpp b/src/ui/tools/eraser-tool.cpp
index 4106785e7..bf4015b4c 100644
--- a/src/ui/tools/eraser-tool.cpp
+++ b/src/ui/tools/eraser-tool.cpp
@@ -84,7 +84,7 @@ using Inkscape::DocumentUndo;
#define DRAG_DEFAULT 1.0
#define DRAG_MAX 1.0
-#include "tool-factory.h"
+#include "ui/tool-factory.h"
namespace Inkscape {
namespace UI {
diff --git a/src/ui/tools/flood-tool.cpp b/src/ui/tools/flood-tool.cpp
index d74848dc6..5745fc9cc 100644
--- a/src/ui/tools/flood-tool.cpp
+++ b/src/ui/tools/flood-tool.cpp
@@ -50,7 +50,7 @@
#include "preferences.h"
#include "rubberband.h"
#include "selection.h"
-#include "shape-editor.h"
+#include "ui/shape-editor.h"
#include "sp-defs.h"
#include "sp-item.h"
#include "splivarot.h"
@@ -74,7 +74,7 @@ using Inkscape::Display::ExtractARGB32;
using Inkscape::Display::ExtractRGB32;
using Inkscape::Display::AssembleARGB32;
-#include "tool-factory.h"
+#include "ui/tool-factory.h"
namespace Inkscape {
namespace UI {
@@ -119,8 +119,8 @@ FloodTool::~FloodTool() {
* destroys old and creates new knotholder.
*/
void FloodTool::selection_changed(Inkscape::Selection* selection) {
- this->shape_editor->unset_item(SH_KNOTHOLDER);
- this->shape_editor->set_item(selection->singleItem(), SH_KNOTHOLDER);
+ this->shape_editor->unset_item();
+ this->shape_editor->set_item(selection->singleItem());
}
void FloodTool::setup() {
@@ -130,7 +130,7 @@ void FloodTool::setup() {
SPItem *item = sp_desktop_selection(this->desktop)->singleItem();
if (item) {
- this->shape_editor->set_item(item, SH_KNOTHOLDER);
+ this->shape_editor->set_item(item);
}
this->sel_changed_connection.disconnect();
diff --git a/src/ui/tools/flood-tool.h b/src/ui/tools/flood-tool.h
index 3ed670e8b..5104a42e9 100644
--- a/src/ui/tools/flood-tool.h
+++ b/src/ui/tools/flood-tool.h
@@ -11,9 +11,7 @@
* Released under GNU GPL
*/
-#include <stddef.h>
-#include <sigc++/sigc++.h>
-#include <gtk/gtk.h>
+#include <sigc++/connection.h>
#include "ui/tools/tool-base.h"
#define SP_FLOOD_CONTEXT(obj) (dynamic_cast<Inkscape::UI::Tools::FloodTool*>((Inkscape::UI::Tools::ToolBase*)obj))
diff --git a/src/ui/tools/freehand-base.cpp b/src/ui/tools/freehand-base.cpp
index 4f2ec6c48..68b57dc90 100644
--- a/src/ui/tools/freehand-base.cpp
+++ b/src/ui/tools/freehand-base.cpp
@@ -31,7 +31,7 @@
#include "desktop-handles.h"
#include "desktop-style.h"
#include "document.h"
-#include "draw-anchor.h"
+#include "ui/draw-anchor.h"
#include "macros.h"
#include "message-stack.h"
#include "ui/tools/pen-tool.h"
@@ -45,6 +45,7 @@
#include "live_effects/lpe-powerstroke.h"
#include "style.h"
#include "ui/control-manager.h"
+// clipboard support
#include "ui/clipboard.h"
#include "ui/tools/freehand-base.h"
@@ -80,6 +81,7 @@ FreehandBase::FreehandBase(gchar const *const *cursor_shape, gint hot_x, gint ho
, red_color(0xff00007f)
, blue_color(0x0000ff7f)
, green_color(0x00ff007f)
+ , highlight_color(0x0000007f)
, red_bpath(NULL)
, red_curve(NULL)
, blue_bpath(NULL)
@@ -91,6 +93,7 @@ FreehandBase::FreehandBase(gchar const *const *cursor_shape, gint hot_x, gint ho
, white_item(NULL)
, white_curves(NULL)
, white_anchors(NULL)
+ , overwriteCurve(NULL)
, sa(NULL)
, ea(NULL)
, waiting_LPE_type(Inkscape::LivePathEffect::INVALID_LPE)
@@ -146,6 +149,9 @@ void FreehandBase::setup() {
this->green_anchor = NULL;
this->green_closed = FALSE;
+ // Create start anchor alternative curve
+ this->overwriteCurve = new SPCurve();
+
this->attach = TRUE;
spdc_attach_selection(this, this->selection);
}
@@ -227,6 +233,32 @@ static void spdc_apply_powerstroke_shape(const std::vector<Geom::Point> & points
Effect* lpe = SP_LPE_ITEM(item)->getCurrentLPE();
static_cast<LPEPowerStroke*>(lpe)->offset_points.param_set_and_write_new_value(points);
+ // find out stroke width (TODO: is there an easier way??)
+ SPDesktop *desktop = dc->desktop;
+ Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc();
+ Inkscape::XML::Node *repr = xml_doc->createElement("svg:path");
+ Inkscape::GC::release(repr);
+
+ char const* tool = SP_IS_PEN_CONTEXT(dc) ? "/tools/freehand/pen" : "/tools/freehand/pencil";
+
+ // apply the tool's current style
+ sp_desktop_apply_style_tool(desktop, repr, tool, false);
+
+ double stroke_width = 1.0;
+ char const *style_str = NULL;
+ style_str = repr->attribute("style");
+ if (style_str) {
+ SPStyle *style = sp_style_new(SP_ACTIVE_DOCUMENT);
+ sp_style_merge_from_style_string(style, style_str);
+ stroke_width = style->stroke_width.computed;
+ style->stroke_width.computed = 0;
+ sp_style_unref(style);
+ }
+
+ std::ostringstream s;
+ s.imbue(std::locale::classic());
+ s << "0," << stroke_width / 2.;
+
// write powerstroke parameters:
lpe->getRepr()->setAttribute("start_linecap_type", "zerowidth");
lpe->getRepr()->setAttribute("end_linecap_type", "zerowidth");
@@ -234,6 +266,7 @@ static void spdc_apply_powerstroke_shape(const std::vector<Geom::Point> & points
lpe->getRepr()->setAttribute("sort_points", "true");
lpe->getRepr()->setAttribute("interpolator_type", "CubicBezierJohan");
lpe->getRepr()->setAttribute("interpolator_beta", "0.2");
+ lpe->getRepr()->setAttribute("offset_points", s.str().c_str());
}
@@ -241,7 +274,9 @@ static void spdc_apply_bend_shape(gchar const *svgd, FreehandBase *dc, SPItem *i
{
using namespace Inkscape::LivePathEffect;
- Effect::createAndApply(BEND_PATH, dc->desktop->doc(), item);
+ if(!SP_LPE_ITEM(item)->hasPathEffectOfType(BEND_PATH)){
+ Effect::createAndApply(BEND_PATH, dc->desktop->doc(), item);
+ }
Effect* lpe = SP_LPE_ITEM(item)->getCurrentLPE();
// write bend parameters:
@@ -261,37 +296,41 @@ static void spdc_check_for_and_apply_waiting_LPE(FreehandBase *dc, SPItem *item,
if (prefs->getInt(tool_name(dc) + "/freehand-mode", 0) == 1) {
Effect::createAndApply(SPIRO, dc->desktop->doc(), item);
}
+ //add the bspline node in the waiting effects
+ if (prefs->getInt(tool_name(dc) + "/freehand-mode", 0) == 2) {
+ Effect::createAndApply(BSPLINE, dc->desktop->doc(), item);
+ }
+
+ //Store the clipboard path to apply in the future without the use of clipboard
- //Store the clipboard path to apply in the future without the use of clipboard
static Geom::PathVector previous_shape_pathv;
- //Last shape applied type "-1" means "no previous shape"
- int shape = prefs->getInt(tool_name(dc) + "/shape", 0);
+ enum shapeType { NONE, TRIANGLE_IN, TRIANGLE_OUT, ELLIPSE, CLIPBOARD, BEND_CLIPBOARD, LAST_APPLIED };
+ static shapeType previous_shape_type = NONE;
+
+
+ shapeType shape = (shapeType)prefs->getInt(tool_name(dc) + "/shape", 0);
bool shape_applied = false;
SPCSSAttr *css_item = sp_css_attr_from_object(item, SP_STYLE_FLAG_ALWAYS);
const char *cstroke = sp_repr_css_property(css_item, "stroke", "none");
- static SPItem *itemEnd;
+ static SPItem *bendItem;
#define SHAPE_LENGTH 10
#define SHAPE_HEIGHT 10
- if(shape == 6){
+
+ if(shape == LAST_APPLIED){
+
shape = previous_shape_type;
- if(shape == 4){
- shape = 6;
- }
- if(shape == 5){
- shape = 7;
- }
- if(previous_shape_type == -1){
- shape = 0;
+ if(shape == CLIPBOARD || shape == BEND_CLIPBOARD){
+ shape = LAST_APPLIED;
}
}
switch (shape) {
- case 0:
+ case NONE:
// don't apply any shape
break;
- case 1:
+ case TRIANGLE_IN:
{
// "triangle in"
std::vector<Geom::Point> points(1);
@@ -301,7 +340,7 @@ static void spdc_check_for_and_apply_waiting_LPE(FreehandBase *dc, SPItem *item,
shape_applied = true;
break;
}
- case 2:
+ case TRIANGLE_OUT:
{
// "triangle out"
guint curve_length = curve->get_segment_count();
@@ -312,7 +351,7 @@ static void spdc_check_for_and_apply_waiting_LPE(FreehandBase *dc, SPItem *item,
shape_applied = true;
break;
}
- case 3:
+ case ELLIPSE:
{
// "ellipse"
SPCurve *c = new SPCurve();
@@ -329,7 +368,7 @@ static void spdc_check_for_and_apply_waiting_LPE(FreehandBase *dc, SPItem *item,
shape_applied = true;
break;
}
- case 4:
+ case CLIPBOARD:
{
// take shape from clipboard; TODO: catch the case where clipboard is empty
Effect::createAndApply(PATTERN_ALONG_PATH, dc->desktop->doc(), item);
@@ -342,74 +381,56 @@ static void spdc_check_for_and_apply_waiting_LPE(FreehandBase *dc, SPItem *item,
shape_applied = true;
break;
}
- case 5:
+ case BEND_CLIPBOARD:
{
- // take shape from clipboard; TODO: catch the case where clipboard is empty
Inkscape::UI::ClipboardManager *cm = Inkscape::UI::ClipboardManager::get();
if(cm->paste(SP_ACTIVE_DESKTOP,false) == true){
gchar const *svgd = item->getRepr()->attribute("d");
- item->deleteObject();
- if(itemEnd != NULL && itemEnd->getRepr() != NULL)
- itemEnd->deleteObject();
- Inkscape::Selection *selection = sp_desktop_selection(dc->desktop);
- sp_selection_group(selection, dc->desktop);
- GSList *items = const_cast<GSList *>(selection->itemList());
- SPObject *obj = reinterpret_cast<SPObject *>(g_slist_nth_data(items,0));
- if(SP_IS_OBJECT(obj)){
- itemEnd = SP_ITEM(obj);
- sp_selection_duplicate(dc->desktop);
- itemEnd->setExplicitlyHidden(true);
- items = const_cast<GSList *>(selection->itemList());
- obj = reinterpret_cast<SPObject *>(g_slist_nth_data(items,0));
- if(SP_IS_OBJECT(obj)){
- spdc_apply_bend_shape(svgd, dc, SP_ITEM(obj));
- SP_ITEM(obj)->setExplicitlyHidden(false);
- selection->set(SP_ITEM(obj),true);
- }
- }
- }
- break;
- }
- case 6:
- {
- if(previous_shape_pathv.size() != 0){
- SPCurve * c = new SPCurve();
- c->set_pathvector(previous_shape_pathv);
- spdc_paste_curve_as_freehand_shape(c, dc, item);
- c->unref();
-
- shape_applied = true;
+ item->getRepr()->setAttribute("d", "");
+ bendItem = dc->selection->singleItem();
+ item->setSuccessor(bendItem);
+ item = bendItem;
+ g_assert(item != NULL);
+ spdc_apply_bend_shape(svgd, dc, item);
+ dc->selection->set(item,true);
}
-
- shape = previous_shape_type;
break;
}
- case 7:
+ case LAST_APPLIED:
{
- // take shape from clipboard; TODO: catch the case where clipboard is empty
- if(itemEnd != NULL && itemEnd->getRepr() != NULL){
- gchar const *svgd = item->getRepr()->attribute("d");
- item->deleteObject();
- Inkscape::Selection *selection = sp_desktop_selection(dc->desktop);
- selection->add(SP_OBJECT(itemEnd));
- sp_selection_duplicate(dc->desktop);
- selection->remove(SP_OBJECT(itemEnd));
- GSList *items = const_cast<GSList *>(selection->itemList());
- SPObject *obj = reinterpret_cast<SPObject *>(g_slist_nth_data(items,0));
- if(SP_IS_OBJECT(obj)){
- SP_ITEM(obj)->getRepr()->setAttribute("inkscape:path-effect", NULL);
- spdc_apply_bend_shape(svgd, dc, SP_ITEM(obj));
- SP_ITEM(obj)->setExplicitlyHidden(false);
- selection->set(SP_ITEM(obj),true);
+ if(previous_shape_type == CLIPBOARD){
+ if(previous_shape_pathv.size() != 0){
+ SPCurve * c = new SPCurve();
+ c->set_pathvector(previous_shape_pathv);
+ spdc_paste_curve_as_freehand_shape(c, dc, item);
+ c->unref();
+
+ shape_applied = true;
+ }
+ } else {
+ if(bendItem != NULL && bendItem->getRepr() != NULL){
+ gchar const *svgd = item->getRepr()->attribute("d");
+ item->getRepr()->setAttribute("d", "");
+ Inkscape::Selection *selection = sp_desktop_selection(dc->desktop);
+ selection->add(SP_OBJECT(bendItem));
+ sp_selection_duplicate(dc->desktop);
+ selection->remove(SP_OBJECT(bendItem));
+ bendItem = dc->selection->singleItem();
+ item->setSuccessor(bendItem);
+ item = bendItem;
+ g_assert(item != NULL);
+ spdc_apply_bend_shape(svgd, dc, item);
+ dc->selection->set(item,true);
}
}
- shape = previous_shape_type;
break;
}
default:
break;
}
- previous_shape_type = shape;
+ if(shape != LAST_APPLIED){
+ previous_shape_type = shape;
+ }
if (shape_applied) {
// apply original stroke color as fill and unset stroke; then return
SPCSSAttr *css = sp_repr_css_attr_new();
@@ -424,8 +445,9 @@ static void spdc_check_for_and_apply_waiting_LPE(FreehandBase *dc, SPItem *item,
sp_repr_css_attr_unref(css);
return;
}
- if(previous_shape_type == 5)return;
-
+ if(previous_shape_type == 5 || previous_shape_type == 6 || previous_shape_type == 7){
+ return;
+ }
if (dc->waiting_LPE_type != INVALID_LPE) {
Effect::createAndApply(dc->waiting_LPE_type, dc->desktop->doc(), item);
dc->waiting_LPE_type = INVALID_LPE;
@@ -564,7 +586,7 @@ void spdc_concat_colors_and_flush(FreehandBase *dc, gboolean forceclosed)
{
// Concat RBG
SPCurve *c = dc->green_curve;
-
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
// Green
dc->green_curve = new SPCurve();
while (dc->green_bpaths) {
@@ -611,9 +633,20 @@ void spdc_concat_colors_and_flush(FreehandBase *dc, gboolean forceclosed)
if (dc->sa->start && !(dc->sa->curve->is_closed()) ) {
c = reverse_then_unref(c);
}
- dc->sa->curve->append_continuous(c, 0.0625);
- c->unref();
- dc->sa->curve->closepath_current();
+ if(prefs->getInt(tool_name(dc) + "/freehand-mode", 0) == 1 ||
+ prefs->getInt(tool_name(dc) + "/freehand-mode", 0) == 2){
+ dc->overwriteCurve->append_continuous(c, 0.0625);
+ c->unref();
+ dc->overwriteCurve->closepath_current();
+ if(dc->sa){
+ dc->white_curves = g_slist_remove(dc->white_curves, dc->sa->curve);
+ dc->white_curves = g_slist_append(dc->white_curves, dc->overwriteCurve);
+ }
+ }else{
+ dc->sa->curve->append_continuous(c, 0.0625);
+ c->unref();
+ dc->sa->curve->closepath_current();
+ }
spdc_flush_white(dc, NULL);
return;
}
@@ -622,6 +655,10 @@ void spdc_concat_colors_and_flush(FreehandBase *dc, gboolean forceclosed)
if (dc->sa) {
SPCurve *s = dc->sa->curve;
dc->white_curves = g_slist_remove(dc->white_curves, s);
+ if(prefs->getInt(tool_name(dc) + "/freehand-mode", 0) == 1 ||
+ prefs->getInt(tool_name(dc) + "/freehand-mode", 0) == 2){
+ s = dc->overwriteCurve;
+ }
if (dc->sa->start) {
s = reverse_then_unref(s);
}
@@ -634,6 +671,25 @@ void spdc_concat_colors_and_flush(FreehandBase *dc, gboolean forceclosed)
if (!dc->ea->start) {
e = reverse_then_unref(e);
}
+ if(prefs->getInt(tool_name(dc) + "/freehand-mode", 0) == 1 ||
+ prefs->getInt(tool_name(dc) + "/freehand-mode", 0) == 2){
+ e = reverse_then_unref(e);
+ Geom::CubicBezier const * cubic = dynamic_cast<Geom::CubicBezier const*>(&*e->last_segment());
+ SPCurve *lastSeg = new SPCurve();
+ if(cubic){
+ lastSeg->moveto((*cubic)[0]);
+ lastSeg->curveto((*cubic)[1],(*cubic)[3],(*cubic)[3]);
+ if( e->get_segment_count() == 1){
+ e = lastSeg;
+ }else{
+ //we eliminate the last segment
+ e->backspace();
+ //and we add it again with the recreation
+ e->append_continuous(lastSeg, 0.0625);
+ }
+ }
+ e = reverse_then_unref(e);
+ }
c->append_continuous(e, 0.0625);
e->unref();
}
@@ -647,7 +703,6 @@ void spdc_concat_colors_and_flush(FreehandBase *dc, gboolean forceclosed)
static void spdc_flush_white(FreehandBase *dc, SPCurve *gc)
{
SPCurve *c;
-
if (dc->white_curves) {
g_assert(dc->white_item);
c = SPCurve::concat(dc->white_curves);
@@ -677,6 +732,7 @@ static void spdc_flush_white(FreehandBase *dc, SPCurve *gc)
bool has_lpe = false;
Inkscape::XML::Node *repr;
+
if (dc->white_item) {
repr = dc->white_item->getRepr();
has_lpe = SP_LPE_ITEM(dc->white_item)->hasPathEffectRecursive();
@@ -700,12 +756,17 @@ static void spdc_flush_white(FreehandBase *dc, SPCurve *gc)
// we finished the path; now apply any waiting LPEs or freehand shapes
spdc_check_for_and_apply_waiting_LPE(dc, item, c);
-
- if(previous_shape_type != 5) dc->selection->set(repr);
+ if(previous_shape_type == -1 || previous_shape_type == 5 || previous_shape_type == 6){
+ return;
+ }
+ if(previous_shape_type != 7){
+ dc->selection->set(repr);
+ }
+
Inkscape::GC::release(repr);
- if(previous_shape_type != 5) item->transform = SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse();
- if(previous_shape_type != 5) item->doWriteTransform(item->getRepr(), item->transform, NULL, true);
- if(previous_shape_type != 5) item->updateRepr();
+ item->transform = SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse();
+ item->updateRepr();
+ item->doWriteTransform(item->getRepr(), item->transform, NULL, true);
}
DocumentUndo::done(doc, SP_IS_PEN_CONTEXT(dc)? SP_VERB_CONTEXT_PEN : SP_VERB_CONTEXT_PENCIL,
@@ -740,7 +801,6 @@ SPDrawAnchor *spdc_test_inside(FreehandBase *dc, Geom::Point p)
active = na;
}
}
-
return active;
}
diff --git a/src/ui/tools/freehand-base.h b/src/ui/tools/freehand-base.h
index 5a4b91800..6b4265215 100644
--- a/src/ui/tools/freehand-base.h
+++ b/src/ui/tools/freehand-base.h
@@ -55,6 +55,7 @@ public:
guint32 red_color;
guint32 blue_color;
guint32 green_color;
+ guint32 highlight_color;
// Red
SPCanvasItem *red_bpath;
@@ -75,12 +76,17 @@ public:
GSList *white_curves;
GSList *white_anchors;
+ //ALternative curve to use on continuing exisiting curve in case of bspline or spirolive
+ //because usigh anchor curves give memory and random bugs, - and obscure code- in some plataform reported by su_v in mac
+ SPCurve *overwriteCurve;
+
// Start anchor
SPDrawAnchor *sa;
// End anchor
SPDrawAnchor *ea;
+
/* type of the LPE that is to be applied automatically to a finished path (if any) */
Inkscape::LivePathEffect::EffectType waiting_LPE_type;
diff --git a/src/ui/tools/gradient-tool.cpp b/src/ui/tools/gradient-tool.cpp
index a0bbfbaf1..9c853917e 100644
--- a/src/ui/tools/gradient-tool.cpp
+++ b/src/ui/tools/gradient-tool.cpp
@@ -51,7 +51,7 @@
using Inkscape::DocumentUndo;
-#include "tool-factory.h"
+#include "ui/tool-factory.h"
namespace Inkscape {
namespace UI {
@@ -213,17 +213,20 @@ sp_gradient_context_is_over_line (GradientTool *rc, SPItem *item, Geom::Point ev
//Translate mouse point into proper coord system
rc->mousepoint_doc = desktop->w2d(event_p);
- SPCtrlLine* line = SP_CTRLLINE(item);
+ if (SP_IS_CTRLLINE(item)) {
+ SPCtrlLine* line = SP_CTRLLINE(item);
- Geom::LineSegment ls(line->s, line->e);
- Geom::Point nearest = ls.pointAt(ls.nearestPoint(rc->mousepoint_doc));
- double dist_screen = Geom::L2 (rc->mousepoint_doc - nearest) * desktop->current_zoom();
+ Geom::LineSegment ls(line->s, line->e);
+ Geom::Point nearest = ls.pointAt(ls.nearestPoint(rc->mousepoint_doc));
+ double dist_screen = Geom::L2 (rc->mousepoint_doc - nearest) * desktop->current_zoom();
- double tolerance = (double) SP_EVENT_CONTEXT(rc)->tolerance;
+ double tolerance = (double) SP_EVENT_CONTEXT(rc)->tolerance;
- bool close = (dist_screen < tolerance);
+ bool close = (dist_screen < tolerance);
- return close;
+ return close;
+ }
+ return false;
}
static std::vector<Geom::Point>
diff --git a/src/ui/tools/lpe-tool.cpp b/src/ui/tools/lpe-tool.cpp
index 9ab6d7814..1fd1ebf8c 100644
--- a/src/ui/tools/lpe-tool.cpp
+++ b/src/ui/tools/lpe-tool.cpp
@@ -28,7 +28,7 @@
#include "desktop.h"
#include "message-context.h"
#include "preferences.h"
-#include "shape-editor.h"
+#include "ui/shape-editor.h"
#include "selection.h"
#include "desktop-handles.h"
#include "document.h"
@@ -59,7 +59,7 @@ SubtoolEntry lpesubtools[] = {
};
-#include "tool-factory.h"
+#include "ui/tool-factory.h"
namespace Inkscape {
namespace UI {
@@ -129,8 +129,7 @@ void LpeTool::setup() {
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
if (item) {
- this->shape_editor->set_item(item, SH_NODEPATH);
- this->shape_editor->set_item(item, SH_KNOTHOLDER);
+ this->shape_editor->set_item(item);
}
if (prefs->getBool("/tools/lpetool/selcue")) {
@@ -146,9 +145,9 @@ void sp_lpetool_context_selection_changed(Inkscape::Selection *selection, gpoint
{
LpeTool *lc = SP_LPETOOL_CONTEXT(data);
- lc->shape_editor->unset_item(SH_KNOTHOLDER);
+ lc->shape_editor->unset_item();
SPItem *item = selection->singleItem();
- lc->shape_editor->set_item(item, SH_KNOTHOLDER);
+ lc->shape_editor->set_item(item);
}
void LpeTool::set(const Inkscape::Preferences::Entry& val) {
diff --git a/src/ui/tools/measure-tool.cpp b/src/ui/tools/measure-tool.cpp
index 2c85874bc..6b5cbeccd 100644
--- a/src/ui/tools/measure-tool.cpp
+++ b/src/ui/tools/measure-tool.cpp
@@ -49,7 +49,7 @@ using Inkscape::ControlManager;
using Inkscape::CTLINE_SECONDARY;
using Inkscape::Util::unit_table;
-#include "tool-factory.h"
+#include "ui/tool-factory.h"
namespace Inkscape {
namespace UI {
@@ -277,21 +277,13 @@ void MeasureTool::finish() {
// return ret;
//}
-static bool GeomPointSortPredicate(const Geom::Point& p1, const Geom::Point& p2)
+static void calculate_intersections(SPDesktop * /*desktop*/, SPItem* item, Geom::PathVector const &lineseg, SPCurve *curve, std::vector<double> &intersections)
{
- if (p1[Geom::Y] == p2[Geom::Y]) {
- return p1[Geom::X] < p2[Geom::X];
- } else {
- return p1[Geom::Y] < p2[Geom::Y];
- }
-}
-static void calculate_intersections(SPDesktop * /*desktop*/, SPItem* item, Geom::PathVector const &lineseg, SPCurve *curve, std::vector<Geom::Point> &intersections)
-{
curve->transform(item->i2doc_affine());
-
// Find all intersections of the control-line with this shape
Geom::CrossingSet cs = Geom::crossings(lineseg, curve->get_pathvector());
+ Geom::delete_duplicates(cs[0]);
// Reconstruct and store the points of intersection
for (Geom::Crossings::const_iterator m = cs[0].begin(); m != cs[0].end(); ++m) {
@@ -304,10 +296,11 @@ static void calculate_intersections(SPDesktop * /*desktop*/, SPItem* item, Geom:
item == doc->getItemAtPoint(desktop->dkey, lineseg[0].pointAt((*m).ta - eps), false, NULL)) ||
((*m).ta + eps < 1 &&
item == doc->getItemAtPoint(desktop->dkey, lineseg[0].pointAt((*m).ta + eps), false, NULL)) ) {
- intersections.push_back(intersection);
+ intersections.push_back((*m).ta);
}
#else
- intersections.push_back(lineseg[0].pointAt((*m).ta));
+ intersections.push_back((*m).ta);
+
#endif
}
}
@@ -441,28 +434,20 @@ bool MeasureTool::root_handler(GdkEvent* event) {
points.push_back(desktop->d2w(start_point + (i / NPOINTS) * (end_point - start_point)));
}
-// TODO: Felipe, why don't you simply iterate over all items, and test whether their bounding boxes intersect
-// with the measurement line, instead of interpolating? E.g. bbox_of_measurement_line.intersects(*bbox_of_item).
-// That's also how the object-snapper works, see _findCandidates() in object-snapper.cpp.
+ // TODO: Felipe, why don't you simply iterate over all items, and test whether their bounding boxes intersect
+ // with the measurement line, instead of interpolating over 800 points? E.g. bbox_of_measurement_line.intersects(*bbox_of_item).
+ // That's also how the object-snapper works, see _findCandidates() in object-snapper.cpp.
+
+ // TODO switch to a different variable name. The single letter 'l' is easy to misread.
//select elements crossed by line segment:
GSList *items = sp_desktop_document(desktop)->getItemsAtPoints(desktop->dkey, points);
- std::vector<Geom::Point> intersections;
- Inkscape::Preferences *prefs = Inkscape::Preferences::get();
- bool ignore_1st_and_last = prefs->getBool("/tools/measure/ignore_1st_and_last", true);
-
- if (!ignore_1st_and_last) {
- intersections.push_back(desktop->dt2doc(start_point));
- }
-
- std::vector<LabelPlacement> placements;
-
- // TODO switch to a different variable name. The single letter 'l' is easy to misread.
+ std::vector<double> intersection_times;
for (GSList *l = items; l != NULL; l = l->next) {
SPItem *item = static_cast<SPItem*>(l->data);
if (SP_IS_SHAPE(item)) {
- calculate_intersections(desktop, item, lineseg, SP_SHAPE(item)->getCurve(), intersections);
+ calculate_intersections(desktop, item, lineseg, SP_SHAPE(item)->getCurve(), intersection_times);
} else {
if (SP_IS_TEXT(item) || SP_IS_FLOWTEXT(item)) {
Inkscape::Text::Layout::iterator iter = te_get_layout(item)->begin();
@@ -486,7 +471,7 @@ bool MeasureTool::root_handler(GdkEvent* event) {
curve->transform(item->i2doc_affine());
- calculate_intersections(desktop, item, lineseg, curve, intersections);
+ calculate_intersections(desktop, item, lineseg, curve, intersection_times);
if (iter == te_get_layout(item)->end()) {
break;
@@ -496,13 +481,10 @@ bool MeasureTool::root_handler(GdkEvent* event) {
}
}
- if (!ignore_1st_and_last) {
- intersections.push_back(desktop->dt2doc(end_point));
- }
-
- //sort intersections
- if (intersections.size() > 2) {
- std::sort(intersections.begin(), intersections.end(), GeomPointSortPredicate);
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+ if (!prefs->getBool("/tools/measure/ignore_1st_and_last", true)) {
+ intersection_times.push_back(0);
+ intersection_times.push_back(1);
}
Glib::ustring unit_name = prefs->getString("/tools/measure/unit");
@@ -516,6 +498,13 @@ bool MeasureTool::root_handler(GdkEvent* event) {
Geom::Point windowNormal = Geom::unit_vector(Geom::rot90(desktop->d2w(end_point - start_point)));
Geom::Point normal = desktop->w2d(windowNormal);
+ std::vector<Geom::Point> intersections;
+ std::sort(intersection_times.begin(), intersection_times.end());
+ for (std::vector<double>::iterator iter_t = intersection_times.begin(); iter_t != intersection_times.end(); iter_t++) {
+ intersections.push_back(lineseg[0].pointAt(*iter_t));
+ }
+
+ std::vector<LabelPlacement> placements;
for (size_t idx = 1; idx < intersections.size(); ++idx) {
LabelPlacement placement;
placement.lengthVal = (intersections[idx] - intersections[idx - 1]).length();
diff --git a/src/ui/tools/mesh-tool.cpp b/src/ui/tools/mesh-tool.cpp
index 7d6d3bc23..8a1fb7c72 100644
--- a/src/ui/tools/mesh-tool.cpp
+++ b/src/ui/tools/mesh-tool.cpp
@@ -53,7 +53,7 @@
using Inkscape::DocumentUndo;
-#include "tool-factory.h"
+#include "ui/tool-factory.h"
namespace Inkscape {
namespace UI {
diff --git a/src/ui/tools/node-tool.cpp b/src/ui/tools/node-tool.cpp
index b1e11bd66..838c2a884 100644
--- a/src/ui/tools/node-tool.cpp
+++ b/src/ui/tools/node-tool.cpp
@@ -19,10 +19,13 @@
#include "display/curve.h"
#include "display/sp-canvas.h"
#include "document.h"
+#include "live_effects/effect.h"
#include "live_effects/lpeobject.h"
#include "message-context.h"
#include "selection.h"
-#include "shape-editor.h" // temporary!
+#include "ui/shape-editor.h" // temporary!
+#include "live_effects/effect.h"
+#include "display/curve.h"
#include "sp-clippath.h"
#include "sp-item-group.h"
#include "sp-mask.h"
@@ -104,7 +107,7 @@
using Inkscape::ControlManager;
-#include "tool-factory.h"
+#include "ui/tool-factory.h"
namespace Inkscape {
namespace UI {
@@ -166,6 +169,13 @@ NodeTool::~NodeTool() {
if (this->flash_tempitem) {
this->desktop->remove_temporary_canvasitem(this->flash_tempitem);
}
+ if (this->helperpath_tmpitem) {
+ this->desktop->remove_temporary_canvasitem(this->helperpath_tmpitem);
+ }
+
+ if (this->helperpath_tmpitem) {
+ this->desktop->remove_temporary_canvasitem(this->helperpath_tmpitem);
+ }
this->_selection_changed_connection.disconnect();
//this->_selection_modified_connection.disconnect();
@@ -235,7 +245,7 @@ void NodeTool::setup() {
)
);
- this->_selected_nodes->signal_point_changed.connect(
+ this->_selected_nodes->signal_selection_changed.connect(
// Hide both signal parameters and bind the function parameter to 0
// sigc::signal<void, SelectableControlPoint *, bool>
// <=>
@@ -246,12 +256,14 @@ void NodeTool::setup() {
)))
);
+ this->helperpath_tmpitem = NULL;
this->cursor_drag = false;
this->show_transform_handles = true;
this->single_node_transform_handles = false;
this->flash_tempitem = NULL;
this->flashed_item = NULL;
this->_last_over = NULL;
+ this->helperpath_tmpitem = NULL;
// read prefs before adding items to selection to prevent momentarily showing the outline
sp_event_context_read(this, "show_handles");
@@ -278,6 +290,50 @@ void NodeTool::setup() {
}
this->desktop->emitToolSubselectionChanged(NULL); // sets the coord entry fields to inactive
+ this->update_helperpath();
+}
+
+// show helper paths of the applied LPE, if any
+void NodeTool::update_helperpath () {
+ Inkscape::Selection *selection = sp_desktop_selection (this->desktop);
+
+ if (this->helperpath_tmpitem) {
+ this->desktop->remove_temporary_canvasitem(this->helperpath_tmpitem);
+ this->helperpath_tmpitem = NULL;
+ }
+
+ if (SP_IS_LPE_ITEM(selection->singleItem())) {
+ Inkscape::LivePathEffect::Effect *lpe = SP_LPE_ITEM(selection->singleItem())->getCurrentLPE();
+ if (lpe && lpe->isVisible()/* && lpe->showOrigPath()*/) {
+ Inkscape::UI::ControlPointSelection::Set &selectionNodes = _selected_nodes->allPoints();
+ std::vector<Geom::Point> selectedNodesPositions;
+ for (Inkscape::UI::ControlPointSelection::Set::iterator i = selectionNodes.begin(); i != selectionNodes.end(); ++i) {
+ if ((*i)->selected()) {
+ Inkscape::UI::Node *n = dynamic_cast<Inkscape::UI::Node *>(*i);
+ selectedNodesPositions.push_back(n->position());
+ }
+ }
+ lpe->setSelectedNodePoints(selectedNodesPositions);
+ lpe->setCurrentZoom(this->desktop->current_zoom());
+ SPCurve *c = new SPCurve();
+ SPCurve *cc = new SPCurve();
+ std::vector<Geom::PathVector> cs = lpe->getCanvasIndicators(SP_LPE_ITEM(selection->singleItem()));
+ for (std::vector<Geom::PathVector>::iterator p = cs.begin(); p != cs.end(); ++p) {
+ cc->set_pathvector(*p);
+ c->append(cc, false);
+ cc->reset();
+ }
+ if (!c->is_empty()) {
+ SPCanvasItem *helperpath = sp_canvas_bpath_new(sp_desktop_tempgroup(this->desktop), c);
+ sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(helperpath), 0x0000ff9A, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
+ sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(helperpath), 0, SP_WIND_RULE_NONZERO);
+ sp_canvas_item_affine_absolute(helperpath, selection->singleItem()->i2dt_affine());
+ this->helperpath_tmpitem = this->desktop->add_temporary_canvasitem(helperpath, 0);
+ }
+ c->unref();
+ cc->unref();
+ }
+ }
}
void NodeTool::set(const Inkscape::Preferences::Entry& value) {
@@ -392,11 +448,11 @@ void NodeTool::selection_changed(Inkscape::Selection *sel) {
for (std::set<ShapeRecord>::iterator i = shapes.begin(); i != shapes.end(); ++i) {
ShapeRecord const &r = *i;
- if ((SP_IS_SHAPE(r.item) || SP_IS_TEXT(r.item)) &&
+ if ((SP_IS_SHAPE(r.item) || SP_IS_TEXT(r.item) || SP_IS_GROUP(r.item) || SP_IS_OBJECTGROUP(r.item)) &&
this->_shape_editors.find(r.item) == this->_shape_editors.end())
{
ShapeEditor *si = new ShapeEditor(this->desktop);
- si->set_item(r.item, SH_KNOTHOLDER);
+ si->set_item(r.item);
this->_shape_editors.insert(const_cast<SPItem*&>(r.item), si);
}
}
@@ -416,7 +472,7 @@ bool NodeTool::root_handler(GdkEvent* event) {
Inkscape::Selection *selection = desktop->selection;
static Inkscape::Preferences *prefs = Inkscape::Preferences::get();
-
+
if (this->_multipath->event(this, event)) {
return true;
}
@@ -432,7 +488,9 @@ bool NodeTool::root_handler(GdkEvent* event) {
switch (event->type)
{
case GDK_MOTION_NOTIFY: {
+ this->update_helperpath();
combine_motion_events(desktop->canvas, event->motion, 0);
+ this->update_helperpath();
SPItem *over_item = sp_event_context_find_item (desktop, event_point(event->button),
FALSE, TRUE);
@@ -441,7 +499,6 @@ bool NodeTool::root_handler(GdkEvent* event) {
//ink_node_tool_update_tip(nt, event);
this->update_tip(event);
}
-
// create pathflash outline
if (prefs->getBool("/tools/nodes/pathflash_enabled")) {
if (over_item == this->flashed_item) {
@@ -473,7 +530,8 @@ bool NodeTool::root_handler(GdkEvent* event) {
SPCanvasItem *flash = sp_canvas_bpath_new(sp_desktop_tempgroup(desktop), c);
sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(flash),
- prefs->getInt("/tools/nodes/highlight_color", 0xff0000ff), 1.0,
+ //prefs->getInt("/tools/nodes/highlight_color", 0xff0000ff), 1.0,
+ over_item->highlight_color(), 1.0,
SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(flash), 0, SP_WIND_RULE_NONZERO);
diff --git a/src/ui/tools/node-tool.h b/src/ui/tools/node-tool.h
index 4d15ab70e..ab72f3632 100644
--- a/src/ui/tools/node-tool.h
+++ b/src/ui/tools/node-tool.h
@@ -15,6 +15,9 @@
#include <glib.h>
#include "ui/tools/tool-base.h"
+// we need it to call it from Live Effect
+#include "selection.h"
+
namespace Inkscape {
namespace Display {
class TemporaryItem;
@@ -51,6 +54,7 @@ public:
static const std::string prefsPath;
virtual void setup();
+ virtual void update_helperpath();
virtual void set(const Inkscape::Preferences::Entry& val);
virtual bool root_handler(GdkEvent* event);
@@ -62,6 +66,7 @@ private:
sigc::connection _sizeUpdatedConn;
SPItem *flashed_item;
+ Inkscape::Display::TemporaryItem *helperpath_tmpitem;
Inkscape::Display::TemporaryItem *flash_tempitem;
Inkscape::UI::Selector* _selector;
Inkscape::UI::PathSharedData* _path_data;
diff --git a/src/ui/tools/pen-tool.cpp b/src/ui/tools/pen-tool.cpp
index 09c0a2a4f..92937a135 100644
--- a/src/ui/tools/pen-tool.cpp
+++ b/src/ui/tools/pen-tool.cpp
@@ -26,7 +26,7 @@
#include "desktop-handles.h"
#include "selection.h"
#include "selection-chemistry.h"
-#include "draw-anchor.h"
+#include "ui/draw-anchor.h"
#include "message-stack.h"
#include "message-context.h"
#include "preferences.h"
@@ -40,9 +40,40 @@
#include <glibmm/i18n.h>
#include "macros.h"
#include "context-fns.h"
-#include "tools-switch.h"
+#include "ui/tools-switch.h"
#include "ui/control-manager.h"
-#include "tool-factory.h"
+// we include the necessary files for BSpline & Spiro
+#include "live_effects/effect.h"
+#include "live_effects/lpeobject.h"
+#include "live_effects/lpeobject-reference.h"
+#include "live_effects/parameter/path.h"
+#define INKSCAPE_LPE_SPIRO_C
+#include "live_effects/lpe-spiro.h"
+
+
+#include <typeinfo>
+#include <2geom/pathvector.h>
+#include <2geom/affine.h>
+#include <2geom/bezier-curve.h>
+#include <2geom/hvlinesegment.h>
+#include "helper/geom-nodetype.h"
+#include "helper/geom-curves.h"
+
+// For handling un-continuous paths:
+#include "message-stack.h"
+#include "inkscape.h"
+#include "desktop.h"
+
+#include "live_effects/spiro.h"
+
+#define INKSCAPE_LPE_BSPLINE_C
+#include "live_effects/lpe-bspline.h"
+#include <2geom/nearest-point.h>
+
+#include "ui/tool-factory.h"
+
+#include "live_effects/effect.h"
+
using Inkscape::ControlManager;
@@ -53,17 +84,17 @@ namespace Tools {
static Geom::Point pen_drag_origin_w(0, 0);
static bool pen_within_tolerance = false;
static int pen_last_paraxial_dir = 0; // last used direction in horizontal/vertical mode; 0 = horizontal, 1 = vertical
-
+const double handleCubicGap = 0.01;
namespace {
- ToolBase* createPenContext() {
- return new PenTool();
- }
+ ToolBase* createPenContext() {
+ return new PenTool();
+ }
- bool penContextRegistered = ToolFactory::instance().registerObject("/tools/freehand/pen", createPenContext);
+ bool penContextRegistered = ToolFactory::instance().registerObject("/tools/freehand/pen", createPenContext);
}
const std::string& PenTool::getPrefsPath() {
- return PenTool::prefsPath;
+ return PenTool::prefsPath;
}
const std::string PenTool::prefsPath = "/tools/freehand/pen";
@@ -135,8 +166,22 @@ PenTool::~PenTool() {
void PenTool::setPolylineMode() {
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
guint mode = prefs->getInt("/tools/freehand/pen/freehand-mode", 0);
- this->polylines_only = (mode == 2 || mode == 3);
- this->polylines_paraxial = (mode == 3);
+ // change the nodes to make space for bspline mode
+ this->polylines_only = (mode == 3 || mode == 4);
+ this->polylines_paraxial = (mode == 4);
+ //we call the function which defines the Spiro modes and the BSpline
+ //todo: merge to one function only
+ this->_pen_context_set_mode(mode);
+}
+
+/*
+*.Set the mode of draw spiro, and bsplines
+*/
+void PenTool::_pen_context_set_mode(guint mode) {
+ // define the nodes
+ this->spiro = (mode == 1);
+ this->bspline = (mode == 2);
+ this->_bspline_spiro_color();
}
/**
@@ -144,7 +189,6 @@ void PenTool::setPolylineMode() {
*/
void PenTool::setup() {
FreehandBase::setup();
-
ControlManager &mgr = ControlManager::getManager();
// Pen indicators
@@ -195,7 +239,9 @@ void PenTool::finish() {
sp_event_context_discard_delayed_snap_event(this);
if (this->npoints != 0) {
- this->_cancel();
+ // switching context - finish path
+ this->ea = NULL; // unset end anchor if set (otherwise crashes)
+ this->_finish(false);
}
FreehandBase::finish();
@@ -277,7 +323,7 @@ bool PenTool::item_handler(SPItem* item, GdkEvent* event) {
}
if (!ret) {
- ret = FreehandBase::item_handler(item, event);
+ ret = FreehandBase::item_handler(item, event);
}
return ret;
@@ -315,7 +361,7 @@ bool PenTool::root_handler(GdkEvent* event) {
}
if (!ret) {
- ret = FreehandBase::root_handler(event);
+ ret = FreehandBase::root_handler(event);
}
return ret;
@@ -332,9 +378,20 @@ bool PenTool::_handleButtonPress(GdkEventButton const &bevent) {
Geom::Point const event_w(bevent.x, bevent.y);
Geom::Point event_dt(desktop->w2d(event_w));
-
+ //Test whether we hit any anchor.
+ SPDrawAnchor * const anchor = spdc_test_inside(this, event_w);
+
+ //with this we avoid creating a new point over the existing one
+ if(bevent.button != 3 && (this->spiro || this->bspline) && this->npoints > 0 && this->p[0] == this->p[3]){
+ if( anchor && anchor == this->sa && this->green_curve->is_empty()){
+ //remove the following line to avoid having one node on top of another
+ _finishSegment(event_dt, bevent.state);
+ _finish( false);
+ return true;
+ }
+ return false;
+ }
bool ret = false;
-
if (bevent.button == 1 && !this->space_panning
// make sure this is not the last click for a waiting LPE (otherwise we want to finish the path)
&& this->expecting_clicks_for_LPE != 1) {
@@ -355,10 +412,8 @@ bool PenTool::_handleButtonPress(GdkEventButton const &bevent) {
pen_drag_origin_w = event_w;
pen_within_tolerance = true;
- // Test whether we hit any anchor.
- SPDrawAnchor * const anchor = spdc_test_inside(this, event_w);
-
switch (this->mode) {
+
case PenTool::MODE_CLICK:
// In click mode we add point on release
switch (this->state) {
@@ -380,7 +435,7 @@ bool PenTool::_handleButtonPress(GdkEventButton const &bevent) {
// This is allowed, if we just canceled curve
case PenTool::POINT:
if (this->npoints == 0) {
-
+ this->_bspline_spiro_color();
Geom::Point p;
if ((bevent.state & GDK_CONTROL_MASK) && (this->polylines_only || this->polylines_paraxial)) {
p = event_dt;
@@ -399,8 +454,12 @@ bool PenTool::_handleButtonPress(GdkEventButton const &bevent) {
// distinction so that the case of a waiting LPE is treated separately
// Set start anchor
+
this->sa = anchor;
- if (anchor && !this->hasWaitingLPE()) {
+ if(anchor){
+ this->_bspline_spiro_start_anchor(bevent.state & GDK_SHIFT_MASK);
+ }
+ if (anchor && (!this->hasWaitingLPE()|| this->bspline || this->spiro)) {
// Adjust point to anchor if needed; if we have a waiting LPE, we need
// a fresh path to be created so don't continue an existing one
p = anchor->dp;
@@ -422,7 +481,7 @@ bool PenTool::_handleButtonPress(GdkEventButton const &bevent) {
// Create green anchor
p = event_dt;
this->_endpointSnap(p, bevent.state);
- this->green_anchor = sp_draw_anchor_new(this, this->green_curve, TRUE, p);
+ this->green_anchor = sp_draw_anchor_new(this, this->green_curve, true, p);
}
this->_setInitialPoint(p);
} else {
@@ -439,7 +498,7 @@ bool PenTool::_handleButtonPress(GdkEventButton const &bevent) {
if (this->green_anchor && this->green_anchor->active) {
// we clicked on the current curve start, so close it even if
// we drag a handle away from it
- this->green_closed = TRUE;
+ this->green_closed = true;
}
ret = true;
break;
@@ -450,8 +509,8 @@ bool PenTool::_handleButtonPress(GdkEventButton const &bevent) {
this->_setSubsequentPoint(p, true);
}
}
-
- this->state = this->polylines_only ? PenTool::POINT : PenTool::CONTROL;
+ // avoid the creation of a control point so a node is created in the release event
+ this->state = (this->spiro || this->bspline || this->polylines_only) ? PenTool::POINT : PenTool::CONTROL;
ret = true;
break;
case PenTool::CONTROL:
@@ -481,6 +540,7 @@ bool PenTool::_handleButtonPress(GdkEventButton const &bevent) {
ret = true;
} else if (bevent.button == 3 && this->npoints != 0) {
// right click - finish path
+ this->ea = NULL; // unset end anchor if set (otherwise crashes)
this->_finish(false);
ret = true;
}
@@ -510,9 +570,11 @@ bool PenTool::_handleMotionNotify(GdkEventMotion const &mevent) {
Geom::Point const event_w(mevent.x, mevent.y);
+ //we take out the function the const "tolerance" because we need it later
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+ gint const tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100);
+
if (pen_within_tolerance) {
- Inkscape::Preferences *prefs = Inkscape::Preferences::get();
- gint const tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100);
if ( Geom::LInfty( event_w - pen_drag_origin_w ) < tolerance ) {
return false; // Do not drag if we're within tolerance from origin.
}
@@ -536,7 +598,7 @@ bool PenTool::_handleMotionNotify(GdkEventMotion const &mevent) {
// Only set point, if we are already appending
this->_endpointSnap(p, mevent.state);
this->_setSubsequentPoint(p, true);
- ret = TRUE;
+ ret = true;
} else if (!this->sp_event_context_knot_mouseover()) {
SnapManager &m = desktop->namedview->snap_manager;
m.setup(desktop);
@@ -572,7 +634,11 @@ bool PenTool::_handleMotionNotify(GdkEventMotion const &mevent) {
}
if (anchor && !this->anchor_statusbar) {
- this->message_context->set(Inkscape::NORMAL_MESSAGE, _("<b>Click</b> or <b>click and drag</b> to close and finish the path."));
+ if(!this->spiro && !this->bspline){
+ this->message_context->set(Inkscape::NORMAL_MESSAGE, _("<b>Click</b> or <b>click and drag</b> to close and finish the path."));
+ }else{
+ this->message_context->set(Inkscape::NORMAL_MESSAGE, _("<b>Click</b> or <b>click and drag</b> to close and finish the path. Shift+Click make a cusp node"));
+ }
this->anchor_statusbar = true;
} else if (!anchor && this->anchor_statusbar) {
this->message_context->clear();
@@ -582,11 +648,16 @@ bool PenTool::_handleMotionNotify(GdkEventMotion const &mevent) {
ret = true;
} else {
if (anchor && !this->anchor_statusbar) {
- this->message_context->set(Inkscape::NORMAL_MESSAGE, _("<b>Click</b> or <b>click and drag</b> to continue the path from this point."));
+ if(!this->spiro && !this->bspline){
+ this->message_context->set(Inkscape::NORMAL_MESSAGE, _("<b>Click</b> or <b>click and drag</b> to continue the path from this point."));
+ }else{
+ this->message_context->set(Inkscape::NORMAL_MESSAGE, _("<b>Click</b> or <b>click and drag</b> to continue the path from this point. Shift+Click make a cusp node"));
+ }
this->anchor_statusbar = true;
} else if (!anchor && this->anchor_statusbar) {
this->message_context->clear();
this->anchor_statusbar = false;
+
}
if (!this->sp_event_context_knot_mouseover()) {
SnapManager &m = desktop->namedview->snap_manager;
@@ -601,6 +672,7 @@ bool PenTool::_handleMotionNotify(GdkEventMotion const &mevent) {
// Placing controls is last operation in CLOSE state
// snap the handle
+
this->_endpointSnapHandle(p, mevent.state);
if (!this->polylines_only) {
@@ -608,6 +680,7 @@ bool PenTool::_handleMotionNotify(GdkEventMotion const &mevent) {
} else {
this->_setCtrl(this->p[1], mevent.state);
}
+
gobble_motion_events(GDK_BUTTON1_MASK);
ret = true;
break;
@@ -627,6 +700,16 @@ bool PenTool::_handleMotionNotify(GdkEventMotion const &mevent) {
default:
break;
}
+ // calls the function "bspline_spiro_motion" when the mouse starts or stops moving
+ if(this->bspline){
+ this->_bspline_spiro_motion(mevent.state & GDK_SHIFT_MASK);
+ }else{
+ if ( Geom::LInfty( event_w - pen_drag_origin_w ) > (tolerance/2) || mevent.time == 0) {
+ this->_bspline_spiro_motion(mevent.state & GDK_SHIFT_MASK);
+ pen_drag_origin_w = event_w;
+ }
+ }
+
return ret;
}
@@ -648,7 +731,12 @@ bool PenTool::_handleButtonRelease(GdkEventButton const &revent) {
Geom::Point p = this->desktop->w2d(event_w);
// Test whether we hit any anchor.
+
SPDrawAnchor *anchor = spdc_test_inside(this, event_w);
+ // if we try to create a node in the same place as another node, we skip
+ if((!anchor || anchor == this->sa) && (this->spiro || this->bspline) && this->npoints > 0 && this->p[0] == this->p[3]){
+ return true;
+ }
switch (this->mode) {
case PenTool::MODE_CLICK:
@@ -656,10 +744,17 @@ bool PenTool::_handleButtonRelease(GdkEventButton const &revent) {
case PenTool::POINT:
if ( this->npoints == 0 ) {
// Start new thread only with button release
+ this->_bspline_spiro_color();
if (anchor) {
p = anchor->dp;
}
this->sa = anchor;
+ // continue the existing curve
+ if (anchor) {
+ if(this->bspline || this->spiro){
+ this->_bspline_spiro_start_anchor(revent.state & GDK_SHIFT_MASK);;
+ }
+ }
this->_setInitialPoint(p);
} else {
// Set end anchor here
@@ -684,6 +779,10 @@ bool PenTool::_handleButtonRelease(GdkEventButton const &revent) {
this->_endpointSnap(p, revent.state);
}
this->_finishSegment(p, revent.state);
+ // hude the guide of the penultimate node when closing the curve
+ if(this->spiro){
+ sp_canvas_item_hide(this->c1);
+ }
this->_finish(true);
this->state = PenTool::POINT;
ret = true;
@@ -707,6 +806,10 @@ bool PenTool::_handleButtonRelease(GdkEventButton const &revent) {
case PenTool::CLOSE:
this->_endpointSnap(p, revent.state);
this->_finishSegment(p, revent.state);
+ // hide the penultimate node guide when closing the curve
+ if(this->spiro){
+ sp_canvas_item_hide(this->c1);
+ }
if (this->green_closed) {
// finishing at the start anchor, close curve
this->_finish(true);
@@ -727,7 +830,6 @@ bool PenTool::_handleButtonRelease(GdkEventButton const &revent) {
default:
break;
}
-
if (this->grab) {
// Release grab now
sp_canvas_item_ungrab(this->grab, revent.time);
@@ -736,7 +838,7 @@ bool PenTool::_handleButtonRelease(GdkEventButton const &revent) {
ret = true;
- this->green_closed = FALSE;
+ this->green_closed = false;
}
// TODO: can we be sure that the path was created correctly?
@@ -764,7 +866,7 @@ bool PenTool::_handle2ButtonPress(GdkEventButton const &bevent) {
bool ret = false;
// only end on LMB double click. Otherwise horizontal scrolling causes ending of the path
if (this->npoints != 0 && bevent.button == 1) {
- this->_finish(FALSE);
+ this->_finish(false);
ret = true;
}
return ret;
@@ -785,7 +887,6 @@ void PenTool::_redrawAll() {
this->green_bpaths = g_slist_prepend(this->green_bpaths, cshape);
}
-
if (this->green_anchor)
SP_CTRL(this->green_anchor->ctrl)->moveto(this->green_anchor->dp);
@@ -795,7 +896,8 @@ void PenTool::_redrawAll() {
sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), this->red_curve);
// handles
- if (this->p[0] != this->p[1]) {
+ // hide the handlers in bspline and spiro modes
+ if (this->p[0] != this->p[1] && !this->spiro && !this->bspline) {
SP_CTRL(this->c1)->moveto(this->p[1]);
this->cl1->setCoords(this->p[0], this->p[1]);
sp_canvas_item_show(this->c1);
@@ -808,8 +910,9 @@ void PenTool::_redrawAll() {
Geom::Curve const * last_seg = this->green_curve->last_segment();
if (last_seg) {
Geom::CubicBezier const * cubic = dynamic_cast<Geom::CubicBezier const *>( last_seg );
+ // hide the handlers in bspline and spiro modes
if ( cubic &&
- (*cubic)[2] != this->p[0] )
+ (*cubic)[2] != this->p[0] && !this->spiro && !this->bspline )
{
Geom::Point p2 = (*cubic)[2];
SP_CTRL(this->c0)->moveto(p2);
@@ -821,6 +924,10 @@ void PenTool::_redrawAll() {
sp_canvas_item_hide(this->cl0);
}
}
+
+ // simply redraw the spiro. because its a redrawing, we don't call the global function,
+ // but we call the redrawing at the ending.
+ this->_bspline_spiro_build();
}
void PenTool::_lastpointMove(gdouble x, gdouble y) {
@@ -838,6 +945,7 @@ void PenTool::_lastpointMove(gdouble x, gdouble y) {
}
// red
+
this->p[0] += Geom::Point(x, y);
this->p[1] += Geom::Point(x, y);
this->_redrawAll();
@@ -848,25 +956,105 @@ void PenTool::_lastpointMoveScreen(gdouble x, gdouble y) {
}
void PenTool::_lastpointToCurve() {
- if (this->npoints != 5)
+ // avoid that if the "red_curve" contains only two points ( rect ), it doesn't stop here.
+ if (this->npoints != 5 && !this->spiro && !this->bspline)
return;
- Geom::CubicBezier const * cubic = dynamic_cast<Geom::CubicBezier const *>( this->green_curve->last_segment() );
- if ( cubic ) {
- this->p[1] = this->p[0] + (Geom::Point)( (*cubic)[3] - (*cubic)[2] );
- } else {
- this->p[1] = this->p[0] + (1./3)*(this->p[3] - this->p[0]);
+ this->p[1] = this->red_curve->last_segment()->initialPoint() + (1./3.)*(this->red_curve->last_segment()->finalPoint() - this->red_curve->last_segment()->initialPoint());
+ //modificate the last segment of the green curve so it creates the type of node we need
+ if (this->spiro||this->bspline) {
+ if (!this->green_curve->is_empty()) {
+ Geom::Point A(0,0);
+ Geom::Point B(0,0);
+ Geom::Point C(0,0);
+ Geom::Point D(0,0);
+ Geom::CubicBezier const *cubic = dynamic_cast<Geom::CubicBezier const *>( this->green_curve->last_segment() );
+ //We obtain the last segment 4 points in the previous curve
+ if ( cubic ){
+ A = (*cubic)[0];
+ B = (*cubic)[1];
+ if (this->spiro) {
+ C = this->p[0] + (this->p[0] - this->p[1]);
+ } else {
+ C = this->green_curve->last_segment()->finalPoint() + (1./3.)*(this->green_curve->last_segment()->initialPoint() - this->green_curve->last_segment()->finalPoint());
+ }
+ D = (*cubic)[3];
+ } else {
+ A = this->green_curve->last_segment()->initialPoint();
+ B = this->green_curve->last_segment()->initialPoint();
+ if (this->spiro) {
+ C = this->p[0] + (this->p[0] - this->p[1]);
+ } else {
+ C = this->green_curve->last_segment()->finalPoint() + (1./3.)*(this->green_curve->last_segment()->initialPoint() - this->green_curve->last_segment()->finalPoint());
+ }
+ D = this->green_curve->last_segment()->finalPoint();
+ }
+ SPCurve *previous = new SPCurve();
+ previous->moveto(A);
+ previous->curveto(B, C, D);
+ if ( this->green_curve->get_segment_count() == 1) {
+ this->green_curve = previous;
+ } else {
+ //we eliminate the last segment
+ this->green_curve->backspace();
+ //and we add it again with the recreation
+ this->green_curve->append_continuous(previous, 0.0625);
+ }
+ }
+ //if the last node is an union with another curve
+ if (this->green_curve->is_empty() && this->sa && !this->sa->curve->is_empty()) {
+ this->_bspline_spiro_start_anchor(false);
+ }
}
this->_redrawAll();
}
+
void PenTool::_lastpointToLine() {
- if (this->npoints != 5)
+ // avoid that if the "red_curve" contains only two points ( rect) it doesn't stop here.
+ if (this->npoints != 5 && !this->bspline)
return;
+ // modify the last segment of the green curve so the type of node we want is created.
+ if(this->spiro || this->bspline){
+ if(!this->green_curve->is_empty()){
+ Geom::Point A(0,0);
+ Geom::Point B(0,0);
+ Geom::Point C(0,0);
+ Geom::Point D(0,0);
+ SPCurve * previous = new SPCurve();
+ Geom::CubicBezier const * cubic = dynamic_cast<Geom::CubicBezier const *>( this->green_curve->last_segment() );
+ if ( cubic ) {
+ A = this->green_curve->last_segment()->initialPoint();
+ B = (*cubic)[1];
+ C = this->green_curve->last_segment()->finalPoint();
+ D = C;
+ } else {
+ //We obtain the last segment 4 points in the previous curve
+ A = this->green_curve->last_segment()->initialPoint();
+ B = A;
+ C = this->green_curve->last_segment()->finalPoint();
+ D = C;
+ }
+ previous->moveto(A);
+ previous->curveto(B, C, D);
+ if( this->green_curve->get_segment_count() == 1){
+ this->green_curve = previous;
+ }else{
+ //we eliminate the last segment
+ this->green_curve->backspace();
+ //and we add it again with the recreation
+ this->green_curve->append_continuous(previous, 0.0625);
+ }
+ }
+ // if the last node is an union with another curve
+ if(this->green_curve->is_empty() && this->sa && !this->sa->curve->is_empty()){
+ this->_bspline_spiro_start_anchor(true);
+ }
+ }
+
this->p[1] = this->p[0];
-
this->_redrawAll();
}
@@ -971,7 +1159,7 @@ bool PenTool::_handleKeyPress(GdkEvent *event) {
case GDK_KEY_p:
if (MOD__SHIFT_ONLY(event)) {
sp_pen_context_wait_for_LPE_mouse_clicks(pc, Inkscape::LivePathEffect::PARALLEL, 2);
- ret = TRUE;
+ ret = true;
}
break;
@@ -979,7 +1167,7 @@ bool PenTool::_handleKeyPress(GdkEvent *event) {
case GDK_KEY_c:
if (MOD__SHIFT_ONLY(event)) {
sp_pen_context_wait_for_LPE_mouse_clicks(pc, Inkscape::LivePathEffect::CIRCLE_3PTS, 3);
- ret = TRUE;
+ ret = true;
}
break;
@@ -987,7 +1175,7 @@ bool PenTool::_handleKeyPress(GdkEvent *event) {
case GDK_KEY_b:
if (MOD__SHIFT_ONLY(event)) {
sp_pen_context_wait_for_LPE_mouse_clicks(pc, Inkscape::LivePathEffect::PERP_BISECTOR, 2);
- ret = TRUE;
+ ret = true;
}
break;
@@ -995,7 +1183,7 @@ bool PenTool::_handleKeyPress(GdkEvent *event) {
case GDK_KEY_a:
if (MOD__SHIFT_ONLY(event)) {
sp_pen_context_wait_for_LPE_mouse_clicks(pc, Inkscape::LivePathEffect::ANGLE_BISECTOR, 3);
- ret = TRUE;
+ ret = true;
}
break;
*/
@@ -1018,6 +1206,7 @@ bool PenTool::_handleKeyPress(GdkEvent *event) {
case GDK_KEY_Return:
case GDK_KEY_KP_Enter:
if (this->npoints != 0) {
+ this->ea = NULL; // unset end anchor if set (otherwise crashes)
this->_finish(false);
ret = true;
}
@@ -1059,8 +1248,9 @@ bool PenTool::_handleKeyPress(GdkEvent *event) {
this->red_curve->reset();
// Destroy topmost green bpath
if (this->green_bpaths) {
- if (this->green_bpaths->data)
+ if (this->green_bpaths->data) {
sp_canvas_item_destroy(SP_CANVAS_ITEM(this->green_bpaths->data));
+ }
this->green_bpaths = g_slist_remove(this->green_bpaths, this->green_bpaths->data);
}
// Get last segment
@@ -1068,19 +1258,49 @@ bool PenTool::_handleKeyPress(GdkEvent *event) {
g_warning("pen_handle_key_press, case GDK_KP_Delete: Green curve is empty");
break;
}
- // The code below assumes that pc->green_curve has only ONE path !
+ // The code below assumes that this->green_curve has only ONE path !
Geom::Curve const * crv = this->green_curve->last_segment();
this->p[0] = crv->initialPoint();
if ( Geom::CubicBezier const * cubic = dynamic_cast<Geom::CubicBezier const *>(crv)) {
this->p[1] = (*cubic)[1];
+
} else {
this->p[1] = this->p[0];
}
- Geom::Point const pt(( this->npoints < 4
- ? (Geom::Point)(crv->finalPoint())
- : this->p[3] ));
+
+ // asign the value in a third of the distance of the last segment.
+ if (this->bspline){
+ this->p[1] = this->p[0] + (1./3)*(this->p[3] - this->p[0]);
+ }
+
+ Geom::Point const pt( (this->npoints < 4) ? crv->finalPoint() : this->p[3] );
+
this->npoints = 2;
- this->green_curve->backspace();
+ // delete the last segment of the green curve
+ if (this->green_curve->get_segment_count() == 1) {
+ this->npoints = 5;
+ if (this->green_bpaths) {
+ if (this->green_bpaths->data) {
+ sp_canvas_item_destroy(SP_CANVAS_ITEM(this->green_bpaths->data));
+ }
+ this->green_bpaths = g_slist_remove(this->green_bpaths, this->green_bpaths->data);
+ }
+ this->green_curve->reset();
+ } else {
+ this->green_curve->backspace();
+ }
+
+ // assign the value of this->p[1] to the oposite of the green line last segment
+ if (this->spiro){
+ Geom::CubicBezier const *cubic = dynamic_cast<Geom::CubicBezier const *>(this->green_curve->last_segment());
+ if ( cubic ) {
+ this->p[1] = (*cubic)[3] + (*cubic)[3] - (*cubic)[2];
+ SP_CTRL(this->c1)->moveto(this->p[0]);
+ } else {
+ this->p[1] = this->p[0];
+ }
+ }
+
sp_canvas_item_hide(this->c0);
sp_canvas_item_hide(this->c1);
sp_canvas_item_hide(this->cl0);
@@ -1088,6 +1308,9 @@ bool PenTool::_handleKeyPress(GdkEvent *event) {
this->state = PenTool::POINT;
this->_setSubsequentPoint(pt, true);
pen_last_paraxial_dir = !pen_last_paraxial_dir;
+
+ //redraw
+ this->_bspline_spiro_build();
ret = true;
}
break;
@@ -1154,11 +1377,686 @@ void PenTool::_setAngleDistanceStatusMessage(Geom::Point const p, int pc_point_t
}
this->message_context->setF(Inkscape::IMMEDIATE_MESSAGE, message, angle, dist->str);
- g_string_free(dist, FALSE);
+ g_string_free(dist, false);
+}
+
+// this function changes the colors red, green and blue making them transparent or not, depending on if spiro is being used.
+void PenTool::_bspline_spiro_color()
+{
+ static Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+ if(this->spiro){
+ this->red_color = 0xff00000;
+ this->green_color = 0x00ff000;
+ }else if(this->bspline){
+ this->highlight_color = SP_ITEM(this->desktop->currentLayer())->highlight_color();
+ if((unsigned int)prefs->getInt("/tools/nodes/highlight_color", 0xff0000ff) == this->highlight_color){
+ this->green_color = 0xff00007f;
+ this->red_color = 0xff00007f;
+ } else {
+ this->green_color = this->highlight_color;
+ this->red_color = this->highlight_color;
+ }
+ }else{
+ this->highlight_color = SP_ITEM(this->desktop->currentLayer())->highlight_color();
+ this->red_color = 0xff00007f;
+ if((unsigned int)prefs->getInt("/tools/nodes/highlight_color", 0xff0000ff) == this->highlight_color){
+ this->green_color = 0x00ff007f;
+ } else {
+ this->green_color = this->highlight_color;
+ }
+ sp_canvas_item_hide(this->blue_bpath);
+ }
+ //We erase all the "green_bpaths" to recreate them after with the colour
+ //transparency recently modified
+ if (this->green_bpaths) {
+ // remove old piecewise green canvasitems
+ while (this->green_bpaths) {
+ sp_canvas_item_destroy(SP_CANVAS_ITEM(this->green_bpaths->data));
+ this->green_bpaths = g_slist_remove(this->green_bpaths, this->green_bpaths->data);
+ }
+ // one canvas bpath for all of green_curve
+ SPCanvasItem *cshape = sp_canvas_bpath_new(sp_desktop_sketch(this->desktop), this->green_curve);
+ sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(cshape), this->green_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
+ sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(cshape), 0, SP_WIND_RULE_NONZERO);
+ this->green_bpaths = g_slist_prepend(this->green_bpaths, cshape);
+ }
+ sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(this->red_bpath), this->red_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
+}
+
+
+void PenTool::_bspline_spiro(bool shift)
+{
+ if(!this->spiro && !this->bspline)
+ return;
+
+ shift?this->_bspline_spiro_off():this->_bspline_spiro_on();
+ this->_bspline_spiro_build();
+}
+
+void PenTool::_bspline_spiro_on()
+{
+ if(!this->red_curve->is_empty()){
+ using Geom::X;
+ using Geom::Y;
+ this->npoints = 5;
+ this->p[0] = this->red_curve->first_segment()->initialPoint();
+ this->p[3] = this->red_curve->first_segment()->finalPoint();
+ this->p[2] = this->p[3] + (1./3)*(this->p[0] - this->p[3]);
+ this->p[2] = Geom::Point(this->p[2][X] + handleCubicGap,this->p[2][Y] + handleCubicGap);
+ }
+}
+
+void PenTool::_bspline_spiro_off()
+{
+ if(!this->red_curve->is_empty()){
+ this->npoints = 5;
+ this->p[0] = this->red_curve->first_segment()->initialPoint();
+ this->p[3] = this->red_curve->first_segment()->finalPoint();
+ this->p[2] = this->p[3];
+ }
+}
+
+void PenTool::_bspline_spiro_start_anchor(bool shift)
+{
+ if(this->sa->curve->is_empty()){
+ return;
+ }
+
+ LivePathEffect::LPEBSpline *lpe_bsp = NULL;
+
+ if (SP_IS_LPE_ITEM(this->white_item) && SP_LPE_ITEM(this->white_item)->hasPathEffect()){
+ Inkscape::LivePathEffect::Effect* thisEffect = SP_LPE_ITEM(this->white_item)->getPathEffectOfType(Inkscape::LivePathEffect::BSPLINE);
+ if(thisEffect){
+ lpe_bsp = dynamic_cast<LivePathEffect::LPEBSpline*>(thisEffect->getLPEObj()->get_lpe());
+ }
+ }
+ if(lpe_bsp){
+ this->bspline = true;
+ }else{
+ this->bspline = false;
+ }
+ LivePathEffect::LPESpiro *lpe_spi = NULL;
+
+ if (SP_IS_LPE_ITEM(this->white_item) && SP_LPE_ITEM(this->white_item)->hasPathEffect()){
+ Inkscape::LivePathEffect::Effect* thisEffect = SP_LPE_ITEM(this->white_item)->getPathEffectOfType(Inkscape::LivePathEffect::SPIRO);
+ if(thisEffect){
+ lpe_spi = dynamic_cast<LivePathEffect::LPESpiro*>(thisEffect->getLPEObj()->get_lpe());
+ }
+ }
+ if(lpe_spi){
+ this->spiro = true;
+ }else{
+ this->spiro = false;
+ }
+ if(!this->spiro && !this->bspline)
+ return;
+
+ if(shift)
+ this->_bspline_spiro_start_anchor_off();
+ else
+ this->_bspline_spiro_start_anchor_on();
+}
+
+void PenTool::_bspline_spiro_start_anchor_on()
+{
+ using Geom::X;
+ using Geom::Y;
+ SPCurve *tmpCurve = new SPCurve();
+ tmpCurve = this->sa->curve->copy();
+ if(this->sa->start)
+ tmpCurve = tmpCurve->create_reverse();
+ Geom::CubicBezier const * cubic = dynamic_cast<Geom::CubicBezier const*>(&*tmpCurve->last_segment());
+ SPCurve *lastSeg = new SPCurve();
+ Geom::Point A = tmpCurve->last_segment()->initialPoint();
+ Geom::Point D = tmpCurve->last_segment()->finalPoint();
+ Geom::Point C = D + (1./3)*(A - D);
+ C = Geom::Point(C[X] + handleCubicGap,C[Y] + handleCubicGap);
+ if(cubic){
+ lastSeg->moveto(A);
+ lastSeg->curveto((*cubic)[1],C,D);
+ }else{
+ lastSeg->moveto(A);
+ lastSeg->curveto(A,C,D);
+ }
+ if( tmpCurve->get_segment_count() == 1){
+ tmpCurve = lastSeg;
+ }else{
+ //we eliminate the last segment
+ tmpCurve->backspace();
+ //and we add it again with the recreation
+ tmpCurve->append_continuous(lastSeg, 0.0625);
+ }
+ if (this->sa->start) {
+ tmpCurve = tmpCurve->create_reverse();
+ }
+ this->overwriteCurve = tmpCurve;
+}
+
+void PenTool::_bspline_spiro_start_anchor_off()
+{
+ SPCurve *tmpCurve = new SPCurve();
+ tmpCurve = this->sa->curve->copy();
+ if(this->sa->start)
+ tmpCurve = tmpCurve->create_reverse();
+ Geom::CubicBezier const * cubic = dynamic_cast<Geom::CubicBezier const*>(&*tmpCurve->last_segment());
+ if(cubic){
+ SPCurve *lastSeg = new SPCurve();
+ lastSeg->moveto((*cubic)[0]);
+ lastSeg->curveto((*cubic)[1],(*cubic)[3],(*cubic)[3]);
+ if( tmpCurve->get_segment_count() == 1){
+ tmpCurve = lastSeg;
+ }else{
+ //we eliminate the last segment
+ tmpCurve->backspace();
+ //and we add it again with the recreation
+ tmpCurve->append_continuous(lastSeg, 0.0625);
+ }
+ }
+ if (this->sa->start) {
+ tmpCurve = tmpCurve->create_reverse();
+ }
+ this->overwriteCurve = tmpCurve;
+}
+
+void PenTool::_bspline_spiro_motion(bool shift){
+ if(!this->spiro && !this->bspline)
+ return;
+
+ using Geom::X;
+ using Geom::Y;
+ if(this->red_curve->is_empty()) return;
+ this->npoints = 5;
+ SPCurve *tmpCurve = new SPCurve();
+ this->p[2] = this->p[3] + (1./3)*(this->p[0] - this->p[3]);
+ this->p[2] = Geom::Point(this->p[2][X] + handleCubicGap,this->p[2][Y] + handleCubicGap);
+ if(this->green_curve->is_empty() && !this->sa){
+ this->p[1] = this->p[0] + (1./3)*(this->p[3] - this->p[0]);
+ this->p[1] = Geom::Point(this->p[1][X] + handleCubicGap,this->p[1][Y] + handleCubicGap);
+ if(shift){
+ this->p[2] = this->p[3];
+ }
+ }else if(!this->green_curve->is_empty()){
+ tmpCurve = this->green_curve->copy();
+ }else{
+ tmpCurve = this->overwriteCurve->copy();
+ if(this->sa->start)
+ tmpCurve = tmpCurve->create_reverse();
+ }
+
+ if(!tmpCurve->is_empty()){
+ Geom::CubicBezier const * cubic = dynamic_cast<Geom::CubicBezier const*>(&*tmpCurve->last_segment());
+ if(cubic){
+ if(this->bspline){
+ SPCurve * WPower = new SPCurve();
+ Geom::D2< Geom::SBasis > SBasisWPower;
+ WPower->moveto(tmpCurve->last_segment()->finalPoint());
+ WPower->lineto(tmpCurve->last_segment()->initialPoint());
+ float WP = Geom::nearest_point((*cubic)[2],*WPower->first_segment());
+ WPower->reset();
+ WPower->moveto(this->red_curve->last_segment()->initialPoint());
+ WPower->lineto(this->red_curve->last_segment()->finalPoint());
+ SBasisWPower = WPower->first_segment()->toSBasis();
+ WPower->reset();
+ this->p[1] = SBasisWPower.valueAt(WP);
+ if(!Geom::are_near(this->p[1],this->p[0])){
+ this->p[1] = Geom::Point(this->p[1][X] + handleCubicGap,this->p[1][Y] + handleCubicGap);
+ } else {
+ this->p[1] = this->p[0];
+ }
+ if(shift)
+ this->p[2] = this->p[3];
+ }else{
+ this->p[1] = (*cubic)[3] + ((*cubic)[3] - (*cubic)[2] );
+ }
+ }else{
+ this->p[1] = this->p[0];
+ if(shift)
+ this->p[2] = this->p[3];
+ }
+ }
+
+ if(this->anchor_statusbar && !this->red_curve->is_empty()){
+ if(shift){
+ this->_bspline_spiro_end_anchor_off();
+ }else{
+ this->_bspline_spiro_end_anchor_on();
+ }
+ }
+
+ this->_bspline_spiro_build();
+}
+
+void PenTool::_bspline_spiro_end_anchor_on()
+{
+
+ using Geom::X;
+ using Geom::Y;
+ this->p[2] = this->p[3] + (1./3)*(this->p[0] - this->p[3]);
+ this->p[2] = Geom::Point(this->p[2][X] + handleCubicGap,this->p[2][Y] + handleCubicGap);
+ SPCurve *tmpCurve = new SPCurve();
+ SPCurve *lastSeg = new SPCurve();
+ Geom::Point C(0,0);
+ bool reverse = false;
+ if( this->green_anchor && this->green_anchor->active ){
+ tmpCurve = this->green_curve->create_reverse();
+ if(this->green_curve->get_segment_count()==0){
+ return;
+ }
+ reverse = true;
+ } else if(this->sa){
+ tmpCurve = this->overwriteCurve->copy();
+ if(!this->sa->start){
+ tmpCurve = tmpCurve->create_reverse();
+ reverse = true;
+ }
+ }else{
+ return;
+ }
+ Geom::CubicBezier const * cubic = dynamic_cast<Geom::CubicBezier const*>(&*tmpCurve->last_segment());
+ if(this->bspline){
+ C = tmpCurve->last_segment()->finalPoint() + (1./3)*(tmpCurve->last_segment()->initialPoint() - tmpCurve->last_segment()->finalPoint());
+ C = Geom::Point(C[X] + handleCubicGap,C[Y] + handleCubicGap);
+ }else{
+ C = this->p[3] + this->p[3] - this->p[2];
+ }
+ if(cubic){
+ lastSeg->moveto((*cubic)[0]);
+ lastSeg->curveto((*cubic)[1],C,(*cubic)[3]);
+ }else{
+ lastSeg->moveto(tmpCurve->last_segment()->initialPoint());
+ lastSeg->lineto(tmpCurve->last_segment()->finalPoint());
+ }
+ if( tmpCurve->get_segment_count() == 1){
+ tmpCurve = lastSeg;
+ }else{
+ //we eliminate the last segment
+ tmpCurve->backspace();
+ //and we add it again with the recreation
+ tmpCurve->append_continuous(lastSeg, 0.0625);
+ }
+ if (reverse) {
+ tmpCurve = tmpCurve->create_reverse();
+ }
+ if( this->green_anchor && this->green_anchor->active )
+ {
+ this->green_curve->reset();
+ this->green_curve = tmpCurve;
+ }else{
+ this->overwriteCurve->reset();
+ this->overwriteCurve = tmpCurve;
+ }
+}
+
+void PenTool::_bspline_spiro_end_anchor_off()
+{
+
+ SPCurve *tmpCurve = new SPCurve();
+ SPCurve *lastSeg = new SPCurve();
+ bool reverse = false;
+ this->p[2] = this->p[3];
+ if( this->green_anchor && this->green_anchor->active ){
+ tmpCurve = this->green_curve->create_reverse();
+ if(this->green_curve->get_segment_count()==0){
+ return;
+ }
+ reverse = true;
+ } else if(this->sa){
+ tmpCurve = this->overwriteCurve->copy();
+ if(!this->sa->start){
+ tmpCurve = tmpCurve->create_reverse();
+ reverse = true;
+ }
+ }else{
+ return;
+ }
+ Geom::CubicBezier const * cubic = dynamic_cast<Geom::CubicBezier const*>(&*tmpCurve->last_segment());
+ if(cubic){
+ lastSeg->moveto((*cubic)[0]);
+ lastSeg->curveto((*cubic)[1],(*cubic)[3],(*cubic)[3]);
+ }else{
+ lastSeg->moveto(tmpCurve->last_segment()->initialPoint());
+ lastSeg->lineto(tmpCurve->last_segment()->finalPoint());
+ }
+ if( tmpCurve->get_segment_count() == 1){
+ tmpCurve = lastSeg;
+ }else{
+ //we eliminate the last segment
+ tmpCurve->backspace();
+ //and we add it again with the recreation
+ tmpCurve->append_continuous(lastSeg, 0.0625);
+ }
+ if (reverse) {
+ tmpCurve = tmpCurve->create_reverse();
+ }
+ if( this->green_anchor && this->green_anchor->active )
+ {
+ this->green_curve->reset();
+ this->green_curve = tmpCurve;
+ }else{
+ this->overwriteCurve->reset();
+ this->overwriteCurve = tmpCurve;
+ }
+}
+
+//prepares the curves for its transformation into BSpline curve.
+void PenTool::_bspline_spiro_build()
+{
+ if(!this->spiro && !this->bspline){
+ return;
+ }
+
+ //We create the base curve
+ SPCurve *curve = new SPCurve();
+ //If we continuate the existing curve we add it at the start
+ if(this->sa && !this->sa->curve->is_empty()){
+ curve = this->overwriteCurve->copy();
+ if (this->sa->start) {
+ curve = curve->create_reverse();
+ }
+ }
+
+ if (!this->green_curve->is_empty()){
+ curve->append_continuous(this->green_curve, 0.0625);
+ }
+
+ //and the red one
+ if (!this->red_curve->is_empty()){
+ this->red_curve->reset();
+ this->red_curve->moveto(this->p[0]);
+ if(this->anchor_statusbar && !this->sa && !(this->green_anchor && this->green_anchor->active)){
+ this->red_curve->curveto(this->p[1],this->p[3],this->p[3]);
+ }else{
+ this->red_curve->curveto(this->p[1],this->p[2],this->p[3]);
+ }
+ sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), this->red_curve);
+ curve->append_continuous(this->red_curve, 0.0625);
+ }
+
+ if(!curve->is_empty()){
+ // close the curve if the final points of the curve are close enough
+ if(Geom::are_near(curve->first_path()->initialPoint(), curve->last_path()->finalPoint())){
+ curve->closepath_current();
+ }
+ //TODO: CALL TO CLONED FUNCTION SPIRO::doEffect IN lpe-spiro.cpp
+ //For example
+ //using namespace Inkscape::LivePathEffect;
+ //LivePathEffectObject *lpeobj = static_cast<LivePathEffectObject*> (curve);
+ //Effect *spr = static_cast<Effect*> ( new LPEbspline(lpeobj) );
+ //spr->doEffect(curve);
+ if(this->bspline){
+ this->_bspline_doEffect(curve);
+ }else{
+ this->_spiro_doEffect(curve);
+ }
+
+ sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->blue_bpath), curve);
+ sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(this->blue_bpath), this->blue_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
+ sp_canvas_item_show(this->blue_bpath);
+ curve->unref();
+ this->blue_curve->reset();
+ //We hide the holders that doesn't contribute anything
+ if(this->spiro){
+ sp_canvas_item_show(this->c1);
+ SP_CTRL(this->c1)->moveto(this->p[0]);
+ }else
+ sp_canvas_item_hide(this->c1);
+ sp_canvas_item_hide(this->cl1);
+ sp_canvas_item_hide(this->c0);
+ sp_canvas_item_hide(this->cl0);
+ }else{
+ //if the curve is empty
+ sp_canvas_item_hide(this->blue_bpath);
+
+ }
+}
+
+void PenTool::_bspline_doEffect(SPCurve * curve)
+{
+ // commenting the function doEffect in src/live_effects/lpe-bspline.cpp
+ if (curve->get_segment_count() < 1){
+ return;
+ }
+ // Make copy of old path as it is changed during processing
+ Geom::PathVector const original_pathv = curve->get_pathvector();
+ curve->reset();
+
+ //Recorremos todos los paths a los que queremos aplicar el efecto, hasta el
+ //penúltimo
+ for (Geom::PathVector::const_iterator path_it = original_pathv.begin();
+ path_it != original_pathv.end(); ++path_it) {
+ //Si está vacío...
+ if (path_it->empty())
+ continue;
+ //Itreadores
+
+ Geom::Path::const_iterator curve_it1 = path_it->begin();
+ Geom::Path::const_iterator curve_it2 = ++(path_it->begin());
+ Geom::Path::const_iterator curve_endit = path_it->end_default();
+ SPCurve *nCurve = new SPCurve();
+ Geom::Point previousNode(0, 0);
+ Geom::Point node(0, 0);
+ Geom::Point pointAt1(0, 0);
+ Geom::Point pointAt2(0, 0);
+ Geom::Point nextPointAt1(0, 0);
+ Geom::D2<Geom::SBasis> SBasisIn;
+ Geom::D2<Geom::SBasis> SBasisOut;
+ Geom::D2<Geom::SBasis> SBasisHelper;
+ Geom::CubicBezier const *cubic = NULL;
+ if (path_it->closed()) {
+ const Geom::Curve &closingline =
+ path_it->back_closed(); // the closing line segment is always of type
+ if (are_near(closingline.initialPoint(), closingline.finalPoint())) {
+ curve_endit = path_it->end_open();
+ }
+ }
+ nCurve->moveto(curve_it1->initialPoint());
+ while (curve_it1 != curve_endit) {
+ SPCurve *in = new SPCurve();
+ in->moveto(curve_it1->initialPoint());
+ in->lineto(curve_it1->finalPoint());
+ cubic = dynamic_cast<Geom::CubicBezier const *>(&*curve_it1);
+ if (cubic) {
+ SBasisIn = in->first_segment()->toSBasis();
+ if(are_near((*cubic)[1],(*cubic)[0]) && !are_near((*cubic)[2],(*cubic)[3])) {
+ pointAt1 = SBasisIn.valueAt(0.3334);
+ } else {
+ pointAt1 = SBasisIn.valueAt(Geom::nearest_point((*cubic)[1], *in->first_segment()));
+ }
+ if(are_near((*cubic)[2],(*cubic)[3]) && !are_near((*cubic)[1],(*cubic)[0])) {
+ pointAt2 = SBasisIn.valueAt(0.6667);
+ } else {
+ pointAt2 = SBasisIn.valueAt(Geom::nearest_point((*cubic)[2], *in->first_segment()));
+ }
+ } else {
+ pointAt1 = in->first_segment()->initialPoint();
+ pointAt2 = in->first_segment()->finalPoint();
+ }
+ in->reset();
+ delete in;
+ if ( curve_it2 != curve_endit ) {
+ SPCurve *out = new SPCurve();
+ out->moveto(curve_it2->initialPoint());
+ out->lineto(curve_it2->finalPoint());
+ cubic = dynamic_cast<Geom::CubicBezier const *>(&*curve_it2);
+ if (cubic) {
+ SBasisOut = out->first_segment()->toSBasis();
+ if(are_near((*cubic)[1],(*cubic)[0]) && !are_near((*cubic)[2],(*cubic)[3])) {
+ nextPointAt1 = SBasisIn.valueAt(0.3334);
+ } else {
+ nextPointAt1 = SBasisOut.valueAt(Geom::nearest_point((*cubic)[1], *out->first_segment()));
+ }
+ } else {
+ nextPointAt1 = out->first_segment()->initialPoint();
+ }
+ out->reset();
+ delete out;
+ }
+ Geom::Point startNode = path_it->begin()->initialPoint();
+ if (path_it->closed() && curve_it2 == curve_endit) {
+ SPCurve *start = new SPCurve();
+ start->moveto(path_it->begin()->initialPoint());
+ start->lineto(path_it->begin()->finalPoint());
+ Geom::D2<Geom::SBasis> SBasisStart = start->first_segment()->toSBasis();
+ SPCurve *lineHelper = new SPCurve();
+ cubic = dynamic_cast<Geom::CubicBezier const *>(&*path_it->begin());
+ if (cubic) {
+ lineHelper->moveto(SBasisStart.valueAt(
+ Geom::nearest_point((*cubic)[1], *start->first_segment())));
+ } else {
+ lineHelper->moveto(start->first_segment()->initialPoint());
+ }
+ start->reset();
+ delete start;
+
+ SPCurve *end = new SPCurve();
+ end->moveto(curve_it1->initialPoint());
+ end->lineto(curve_it1->finalPoint());
+ Geom::D2<Geom::SBasis> SBasisEnd = end->first_segment()->toSBasis();
+ cubic = dynamic_cast<Geom::CubicBezier const *>(&*curve_it1);
+ if (cubic) {
+ lineHelper->lineto(SBasisEnd.valueAt(
+ Geom::nearest_point((*cubic)[2], *end->first_segment())));
+ } else {
+ lineHelper->lineto(end->first_segment()->finalPoint());
+ }
+ end->reset();
+ delete end;
+ SBasisHelper = lineHelper->first_segment()->toSBasis();
+ lineHelper->reset();
+ delete lineHelper;
+ startNode = SBasisHelper.valueAt(0.5);
+ nCurve->curveto(pointAt1, pointAt2, startNode);
+ nCurve->move_endpoints(startNode, startNode);
+ } else if ( curve_it2 == curve_endit) {
+ nCurve->curveto(pointAt1, pointAt2, curve_it1->finalPoint());
+ nCurve->move_endpoints(path_it->begin()->initialPoint(), curve_it1->finalPoint());
+ } else {
+ SPCurve *lineHelper = new SPCurve();
+ lineHelper->moveto(pointAt2);
+ lineHelper->lineto(nextPointAt1);
+ SBasisHelper = lineHelper->first_segment()->toSBasis();
+ lineHelper->reset();
+ delete lineHelper;
+ previousNode = node;
+ node = SBasisHelper.valueAt(0.5);
+ Geom::CubicBezier const *cubic2 = dynamic_cast<Geom::CubicBezier const *>(&*curve_it1);
+ if((cubic && are_near((*cubic)[0],(*cubic)[1])) || (cubic2 && are_near((*cubic2)[2],(*cubic2)[3]))) {
+ node = curve_it1->finalPoint();
+ }
+ nCurve->curveto(pointAt1, pointAt2, node);
+ }
+ ++curve_it1;
+ ++curve_it2;
+ }
+ if (path_it->closed()) {
+ nCurve->closepath_current();
+ }
+ curve->append(nCurve, false);
+ nCurve->reset();
+ delete nCurve;
+ }
+}
+
+//Spiro function cloned from lpe-spiro.cpp
+// commenting the function "doEffect" from src/live_effects/lpe-spiro.cpp
+void PenTool::_spiro_doEffect(SPCurve * curve)
+{
+ using Geom::X;
+ using Geom::Y;
+
+ Geom::PathVector const original_pathv = curve->get_pathvector();
+ guint len = curve->get_segment_count() + 2;
+
+ curve->reset();
+ Spiro::spiro_cp *path = g_new (Spiro::spiro_cp, len);
+ int ip = 0;
+
+ for(Geom::PathVector::const_iterator path_it = original_pathv.begin(); path_it != original_pathv.end(); ++path_it) {
+ if (path_it->empty())
+ continue;
+
+ {
+ Geom::Point p = path_it->front().pointAt(0);
+ path[ip].x = p[X];
+ path[ip].y = p[Y];
+ path[ip].ty = '{' ;
+ ip++;
+ }
+
+ Geom::Path::const_iterator curve_it1 = path_it->begin();
+ Geom::Path::const_iterator curve_it2 = ++(path_it->begin());
+
+ Geom::Path::const_iterator curve_endit = path_it->end_default();
+ if (path_it->closed()) {
+ const Geom::Curve &closingline = path_it->back_closed();
+ if (are_near(closingline.initialPoint(), closingline.finalPoint())) {
+ curve_endit = path_it->end_open();
+ }
+ }
+
+ while ( curve_it2 != curve_endit )
+ {
+ Geom::Point p = curve_it1->finalPoint();
+ path[ip].x = p[X];
+ path[ip].y = p[Y];
+
+ bool this_is_line = is_straight_curve(*curve_it1);
+ bool next_is_line = is_straight_curve(*curve_it2);
+
+ Geom::NodeType nodetype = Geom::get_nodetype(*curve_it1, *curve_it2);
+
+ if ( nodetype == Geom::NODE_SMOOTH || nodetype == Geom::NODE_SYMM )
+ {
+ if (this_is_line && !next_is_line) {
+ path[ip].ty = ']';
+ } else if (next_is_line && !this_is_line) {
+ path[ip].ty = '[';
+ } else {
+ path[ip].ty = 'c';
+ }
+ } else {
+ path[ip].ty = 'v';
+ }
+
+ ++curve_it1;
+ ++curve_it2;
+ ip++;
+ }
+
+ Geom::Point p = curve_it1->finalPoint();
+ path[ip].x = p[X];
+ path[ip].y = p[Y];
+ if (path_it->closed()) {
+ Geom::NodeType nodetype = Geom::get_nodetype(*curve_it1, path_it->front());
+ switch (nodetype) {
+ case Geom::NODE_NONE:
+ path[ip].ty = '}';
+ ip++;
+ break;
+ case Geom::NODE_CUSP:
+ path[0].ty = path[ip].ty = 'v';
+ break;
+ case Geom::NODE_SMOOTH:
+ case Geom::NODE_SYMM:
+ path[0].ty = path[ip].ty = 'c';
+ break;
+ }
+ } else {
+ path[ip].ty = '}';
+ ip++;
+ }
+
+ int sp_len = ip;
+ Spiro::spiro_run(path, sp_len, *curve);
+ ip = 0;
+ }
+
+ g_free (path);
}
void PenTool::_setSubsequentPoint(Geom::Point const p, bool statusbar, guint status) {
g_assert( this->npoints != 0 );
+
// todo: Check callers to see whether 2 <= npoints is guaranteed.
this->p[2] = p;
@@ -1172,7 +2070,7 @@ void PenTool::_setSubsequentPoint(Geom::Point const p, bool statusbar, guint sta
// we are drawing horizontal/vertical lines and hit an anchor;
Geom::Point const origin = this->p[0];
// if the previous point and the anchor are not aligned either horizontally or vertically...
- if ((abs(p[Geom::X] - origin[Geom::X]) > 1e-9) && (abs(p[Geom::Y] - origin[Geom::Y]) > 1e-9)) {
+ if ((std::abs(p[Geom::X] - origin[Geom::X]) > 1e-9) && (std::abs(p[Geom::Y] - origin[Geom::Y]) > 1e-9)) {
// ...then we should draw an L-shaped path, consisting of two paraxial segments
Geom::Point intermed = p;
this->_setToNearestHorizVert(intermed, status, false);
@@ -1182,7 +2080,7 @@ void PenTool::_setSubsequentPoint(Geom::Point const p, bool statusbar, guint sta
is_curve = false;
} else {
// one of the 'regular' modes
- if (this->p[1] != this->p[0]) {
+ if (this->p[1] != this->p[0] || this->spiro) {
this->red_curve->curveto(this->p[1], p, p);
is_curve = true;
} else {
@@ -1197,10 +2095,16 @@ void PenTool::_setSubsequentPoint(Geom::Point const p, bool statusbar, guint sta
gchar *message = is_curve ?
_("<b>Curve segment</b>: angle %3.2f&#176;, distance %s; with <b>Ctrl</b> to snap angle, <b>Enter</b> to finish the path" ):
_("<b>Line segment</b>: angle %3.2f&#176;, distance %s; with <b>Ctrl</b> to snap angle, <b>Enter</b> to finish the path");
+ if(this->spiro || this->bspline){
+ message = is_curve ?
+ _("<b>Curve segment</b>: angle %3.2f&#176;, distance %s; with <b>Shift+Click</b> make a cusp node, <b>Enter</b> to finish the path" ):
+ _("<b>Line segment</b>: angle %3.2f&#176;, distance %s; with <b>Shift+Click</b> make a cusp node, <b>Enter</b> to finish the path");
+ }
this->_setAngleDistanceStatusMessage(p, 0, message);
}
}
+
void PenTool::_setCtrl(Geom::Point const p, guint const state) {
sp_canvas_item_show(this->c1);
sp_canvas_item_show(this->cl1);
@@ -1211,7 +2115,6 @@ void PenTool::_setCtrl(Geom::Point const p, guint const state) {
sp_canvas_item_hide(this->cl0);
SP_CTRL(this->c1)->moveto(this->p[1]);
this->cl1->setCoords(this->p[0], this->p[1]);
-
this->_setAngleDistanceStatusMessage(p, 0, _("<b>Curve handle</b>: angle %3.2f&#176;, length %s; with <b>Ctrl</b> to snap angle"));
} else if ( this->npoints == 5 ) {
this->p[4] = p;
@@ -1233,6 +2136,8 @@ void PenTool::_setCtrl(Geom::Point const p, guint const state) {
SP_CTRL(this->c1)->moveto(this->p[4]);
this->cl1->setCoords(this->p[3], this->p[4]);
+
+
gchar *message = is_symm ?
_("<b>Curve handle, symmetric</b>: angle %3.2f&#176;, length %s; with <b>Ctrl</b> to snap angle, with <b>Shift</b> to move this handle only") :
_("<b>Curve handle</b>: angle %3.2f&#176;, length %s; with <b>Ctrl</b> to snap angle, with <b>Shift</b> to move this handle only");
@@ -1247,11 +2152,14 @@ void PenTool::_finishSegment(Geom::Point const p, guint const state) {
pen_last_paraxial_dir = this->nextParaxialDirection(p, this->p[0], state);
}
- ++this->num_clicks;
+ ++num_clicks;
+
if (!this->red_curve->is_empty()) {
+ this->_bspline_spiro(state & GDK_SHIFT_MASK);
this->green_curve->append_continuous(this->red_curve, 0.0625);
SPCurve *curve = this->red_curve->copy();
+
/// \todo fixme:
SPCanvasItem *cshape = sp_canvas_bpath_new(sp_desktop_sketch(this->desktop), curve);
curve->unref();
@@ -1273,15 +2181,19 @@ void PenTool::_finish(gboolean const closed) {
return;
}
+
this->num_clicks = 0;
this->_disableEvents();
this->message_context->clear();
+
desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Drawing finished"));
+ // cancelate line without a created segment
this->red_curve->reset();
spdc_concat_colors_and_flush(this, closed);
+ this->overwriteCurve = NULL;
this->sa = NULL;
this->ea = NULL;
@@ -1330,7 +2242,7 @@ int PenTool::nextParaxialDirection(Geom::Point const &pt, Geom::Point const &ori
//
// num_clicks is not reliable because spdc_pen_finish_segment is sometimes called too early
// (on first mouse release), in which case num_clicks immediately becomes 1.
- // if (pc->num_clicks == 0) {
+ // if (this->num_clicks == 0) {
if (this->green_curve->is_empty()) {
// first mouse click
diff --git a/src/ui/tools/pen-tool.h b/src/ui/tools/pen-tool.h
index 4dec7b4fe..98fd0a43e 100644
--- a/src/ui/tools/pen-tool.h
+++ b/src/ui/tools/pen-tool.h
@@ -49,6 +49,9 @@ public:
bool polylines_only;
bool polylines_paraxial;
+ // propiety which saves if Spiro mode is active or not
+ bool spiro;
+ bool bspline;
int num_clicks;
unsigned int expecting_clicks_for_LPE; // if positive, finish the path after this many clicks
@@ -85,6 +88,34 @@ private:
bool _handleButtonRelease(GdkEventButton const &revent);
bool _handle2ButtonPress(GdkEventButton const &bevent);
bool _handleKeyPress(GdkEvent *event);
+ //adds spiro & bspline modes
+ void _pen_context_set_mode(guint mode);
+ //this function changes the colors red, green and blue making them transparent or not depending on if the function uses spiro
+ void _bspline_spiro_color();
+ //creates a node in bspline or spiro modes
+ void _bspline_spiro(bool shift);
+ //creates a node in bspline or spiro modes
+ void _bspline_spiro_on();
+ //creates a CUSP node
+ void _bspline_spiro_off();
+ //continues the existing curve in bspline or spiro mode
+ void _bspline_spiro_start_anchor(bool shift);
+ //continues the existing curve with the union node in bspline or spiro modes
+ void _bspline_spiro_start_anchor_on();
+ //continues an existing curve with the union node in CUSP mode
+ void _bspline_spiro_start_anchor_off();
+ //modifies the "red_curve" when it detects movement
+ void _bspline_spiro_motion(bool shift);
+ //closes the curve with the last node in bspline or spiro mode
+ void _bspline_spiro_end_anchor_on();
+ //closes the curve with the last node in CUSP mode
+ void _bspline_spiro_end_anchor_off();
+ //CHECK: join all the curves "in game" and we call doEffect function
+ void _bspline_spiro_build();
+ //function bspline cloned from lpe-bspline.cpp
+ void _bspline_doEffect(SPCurve * curve);
+ //function spiro cloned from lpe-spiro.cpp
+ void _spiro_doEffect(SPCurve * curve);
void _setInitialPoint(Geom::Point const p);
void _setSubsequentPoint(Geom::Point const p, bool statusbar, guint status = 0);
diff --git a/src/ui/tools/pencil-tool.cpp b/src/ui/tools/pencil-tool.cpp
index fb4e82c32..3ea2ae843 100644
--- a/src/ui/tools/pencil-tool.cpp
+++ b/src/ui/tools/pencil-tool.cpp
@@ -23,7 +23,7 @@
#include "desktop-handles.h"
#include "selection.h"
#include "selection-chemistry.h"
-#include "draw-anchor.h"
+#include "ui/draw-anchor.h"
#include "message-stack.h"
#include "message-context.h"
#include "sp-path.h"
@@ -43,7 +43,7 @@
#include "display/sp-canvas.h"
#include "display/curve.h"
#include "livarot/Path.h"
-#include "tool-factory.h"
+#include "ui/tool-factory.h"
#include "ui/tool/event-utils.h"
namespace Inkscape {
@@ -200,6 +200,7 @@ bool PencilTool::_handleButtonPress(GdkEventButton const &bevent) {
}
if (anchor) {
p = anchor->dp;
+ this->overwriteCurve = anchor->curve;
desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Continuing selected path"));
} else {
m.setup(desktop);
@@ -301,7 +302,7 @@ bool PencilTool::_handleMotionNotify(GdkEventMotion const &mevent) {
if ( this->npoints != 0) { // buttonpress may have happened before we entered draw context!
if (this->ps.empty()) {
- // Only in freehand mode we have to add the first point also to pc->ps (apparently)
+ // Only in freehand mode we have to add the first point also to this->ps (apparently)
// - We cannot add this point in spdc_set_startpoint, because we only need it for freehand
// - We cannot do this in the button press handler because at that point we don't know yet
// wheter we're going into freehand mode or not
@@ -640,6 +641,9 @@ void PencilTool::_interpolate() {
return;
}
+ using Geom::X;
+ using Geom::Y;
+
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
double const tol = prefs->getDoubleLimited("/tools/freehand/pencil/tolerance", 10.0, 1.0, 100.0) * 0.4;
double const tolerance_sq = 0.02 * square(this->desktop->w2d().descrim() * tol) * exp(0.2 * tol - 2);
@@ -661,10 +665,21 @@ void PencilTool::_interpolate() {
if (n_segs > 0) {
/* Fit and draw and reset state */
- this->green_curve->moveto(b[0]);
+ this->green_curve->moveto(b[0]);
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+ guint mode = prefs->getInt("/tools/freehand/pencil/freehand-mode", 0);
for (int c = 0; c < n_segs; c++) {
- this->green_curve->curveto(b[4 * c + 1], b[4 * c + 2], b[4 * c + 3]);
+ // if we are in BSpline we modify the trace to create adhoc nodes
+ if(mode == 2){
+ Geom::Point BP = b[4*c+0] + (1./3)*(b[4*c+3] - b[4*c+0]);
+ BP = Geom::Point(BP[X] + 0.0001,BP[Y] + 0.0001);
+ Geom::Point CP = b[4*c+3] + (1./3)*(b[4*c+0] - b[4*c+3]);
+ CP = Geom::Point(CP[X] + 0.0001,CP[Y] + 0.0001);
+ this->green_curve->curveto(BP,CP,b[4*c+3]);
+ }else{
+ this->green_curve->curveto(b[4 * c + 1], b[4 * c + 2], b[4 * c + 3]);
+ }
}
sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), this->green_curve);
@@ -788,6 +803,7 @@ void PencilTool::_fitAndSplit() {
g_assert(is_zero(this->req_tangent)
|| is_unit_vector(this->req_tangent));
Geom::Point const tHatEnd(0, 0);
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
int const n_segs = Geom::bezier_fit_cubic_full(b, NULL, this->p, this->npoints,
this->req_tangent, tHatEnd,
tolerance_sq, 1);
@@ -795,9 +811,22 @@ void PencilTool::_fitAndSplit() {
&& unsigned(this->npoints) < G_N_ELEMENTS(this->p) )
{
/* Fit and draw and reset state */
+
this->red_curve->reset();
this->red_curve->moveto(b[0]);
- this->red_curve->curveto(b[1], b[2], b[3]);
+ using Geom::X;
+ using Geom::Y;
+ // if we are in BSpline we modify the trace to create adhoc nodes
+ guint mode = prefs->getInt("/tools/freehand/pencil/freehand-mode", 0);
+ if(mode == 2){
+ Geom::Point B = b[0] + (1./3)*(b[3] - b[0]);
+ B = Geom::Point(B[X] + 0.0001,B[Y] + 0.0001);
+ Geom::Point C = b[3] + (1./3)*(b[0] - b[3]);
+ C = Geom::Point(C[X] + 0.0001,C[Y] + 0.0001);
+ this->red_curve->curveto(B,C,b[3]);
+ }else{
+ this->red_curve->curveto(b[1], b[2], b[3]);
+ }
sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), this->red_curve);
this->red_curve_is_valid = true;
} else {
@@ -826,6 +855,13 @@ void PencilTool::_fitAndSplit() {
/// \todo fixme:
SPCanvasItem *cshape = sp_canvas_bpath_new(sp_desktop_sketch(this->desktop), curve);
curve->unref();
+
+ this->highlight_color = SP_ITEM(this->desktop->currentLayer())->highlight_color();
+ if((unsigned int)prefs->getInt("/tools/nodes/highlight_color", 0xff0000ff) == this->highlight_color){
+ this->green_color = 0x00ff007f;
+ } else {
+ this->green_color = this->highlight_color;
+ }
sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(cshape), this->green_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
this->green_bpaths = g_slist_prepend(this->green_bpaths, cshape);
diff --git a/src/ui/tools/rect-tool.cpp b/src/ui/tools/rect-tool.cpp
index 39f422c1a..de91dcff4 100644
--- a/src/ui/tools/rect-tool.cpp
+++ b/src/ui/tools/rect-tool.cpp
@@ -40,13 +40,13 @@
#include "xml/node-event-vector.h"
#include "preferences.h"
#include "context-fns.h"
-#include "shape-editor.h"
+#include "ui/shape-editor.h"
#include "verbs.h"
#include "display/sp-canvas-item.h"
using Inkscape::DocumentUndo;
-#include "tool-factory.h"
+#include "ui/tool-factory.h"
namespace Inkscape {
namespace UI {
@@ -102,8 +102,8 @@ RectTool::~RectTool() {
* destroys old and creates new knotholder.
*/
void RectTool::selection_changed(Inkscape::Selection* selection) {
- this->shape_editor->unset_item(SH_KNOTHOLDER);
- this->shape_editor->set_item(selection->singleItem(), SH_KNOTHOLDER);
+ this->shape_editor->unset_item();
+ this->shape_editor->set_item(selection->singleItem());
}
void RectTool::setup() {
@@ -113,7 +113,7 @@ void RectTool::setup() {
SPItem *item = sp_desktop_selection(this->desktop)->singleItem();
if (item) {
- this->shape_editor->set_item(item, SH_KNOTHOLDER);
+ this->shape_editor->set_item(item);
}
this->sel_changed_connection.disconnect();
diff --git a/src/ui/tools/rect-tool.h b/src/ui/tools/rect-tool.h
index a50fd7b24..a22f1caa8 100644
--- a/src/ui/tools/rect-tool.h
+++ b/src/ui/tools/rect-tool.h
@@ -6,6 +6,7 @@
*
* Author:
* Lauris Kaplinski <lauris@kaplinski.com>
+ * Jon A. Cruz <jon@joncruz.org>
*
* Copyright (C) 2000 Lauris Kaplinski
* Copyright (C) 2000-2001 Ximian, Inc.
@@ -21,9 +22,6 @@
#include "sp-rect.h"
-#define SP_RECT_CONTEXT(obj) (dynamic_cast<Inkscape::UI::Tools::RectTool*>((Inkscape::UI::Tools::ToolBase*)obj))
-#define SP_IS_RECT_CONTEXT(obj) (dynamic_cast<const Inkscape::UI::Tools::RectTool*>((const Inkscape::UI::Tools::ToolBase*)obj) != NULL)
-
namespace Inkscape {
namespace UI {
namespace Tools {
diff --git a/src/ui/tools/select-tool.cpp b/src/ui/tools/select-tool.cpp
index 83bef17c9..a8267ea1d 100644
--- a/src/ui/tools/select-tool.cpp
+++ b/src/ui/tools/select-tool.cpp
@@ -41,7 +41,7 @@
#include "desktop-handles.h"
#include "sp-root.h"
#include "preferences.h"
-#include "tools-switch.h"
+#include "ui/tools-switch.h"
#include "message-stack.h"
#include "selection-describer.h"
#include "seltrans.h"
@@ -49,7 +49,7 @@
#include "display/sp-canvas.h"
#include "display/sp-canvas-item.h"
#include "display/drawing-item.h"
-#include "tool-factory.h"
+#include "ui/tool-factory.h"
using Inkscape::DocumentUndo;
@@ -264,15 +264,16 @@ sp_select_context_up_one_layer(SPDesktop *desktop)
SPObject *const current_layer = desktop->currentLayer();
if (current_layer) {
SPObject *const parent = current_layer->parent;
+ SPGroup *current_group = dynamic_cast<SPGroup *>(current_layer);
if ( parent
&& ( parent->parent
- || !( SP_IS_GROUP(current_layer)
- && ( SPGroup::LAYER
- == SP_GROUP(current_layer)->layerMode() ) ) ) )
+ || !( current_group
+ && ( SPGroup::LAYER == current_group->layerMode() ) ) ) )
{
desktop->setCurrentLayer(parent);
- if (SP_IS_GROUP(current_layer) && SPGroup::LAYER != SP_GROUP(current_layer)->layerMode())
+ if (current_group && (SPGroup::LAYER != current_group->layerMode())) {
sp_desktop_selection(desktop)->set(current_layer);
+ }
}
}
}
@@ -403,7 +404,8 @@ void SelectTool::sp_select_context_cycle_through_items(Inkscape::Selection *sele
}
Inkscape::DrawingItem *arenaitem;
- SPItem *item = SP_ITEM(this->cycling_cur_item->data);
+ SPItem *item = dynamic_cast<SPItem *>(static_cast<SPObject *>(cycling_cur_item->data));
+ g_assert(item != NULL);
// Deactivate current item
if (!g_list_find(this->cycling_items_selected_before, item) && selection->includes(item)) {
@@ -427,7 +429,8 @@ void SelectTool::sp_select_context_cycle_through_items(Inkscape::Selection *sele
if (next) {
this->cycling_cur_item = next;
- item = SP_ITEM(this->cycling_cur_item->data);
+ item = dynamic_cast<SPItem *>(static_cast<SPObject *>(this->cycling_cur_item->data));
+ g_assert(item != NULL);
}
arenaitem = item->get_arenaitem(desktop->dkey);
@@ -442,8 +445,13 @@ void SelectTool::sp_select_context_cycle_through_items(Inkscape::Selection *sele
void SelectTool::sp_select_context_reset_opacities() {
for (GList *l = this->cycling_items; l != NULL; l = g_list_next(l)) {
- Inkscape::DrawingItem *arenaitem = SP_ITEM(l->data)->get_arenaitem(this->desktop->dkey);
- arenaitem->setOpacity(SP_SCALE24_TO_FLOAT(SP_ITEM(l->data)->style->opacity.value));
+ SPItem *item = dynamic_cast<SPItem *>(static_cast<SPObject *>(l->data));
+ if (item) {
+ Inkscape::DrawingItem *arenaitem = item->get_arenaitem(desktop->dkey);
+ arenaitem->setOpacity(SP_SCALE24_TO_FLOAT(item->style->opacity.value));
+ } else {
+ g_assert_not_reached();
+ }
}
g_list_free(this->cycling_items);
@@ -475,8 +483,8 @@ bool SelectTool::root_handler(GdkEvent* event) {
if (!selection->isEmpty()) {
SPItem *clicked_item = static_cast<SPItem *>(selection->itemList()->data);
- if (SP_IS_GROUP(clicked_item) && !SP_IS_BOX3D(clicked_item)) { // enter group if it's not a 3D box
- desktop->setCurrentLayer(reinterpret_cast<SPObject *>(clicked_item));
+ if (dynamic_cast<SPGroup *>(clicked_item) && !dynamic_cast<SPBox3D *>(clicked_item)) { // enter group if it's not a 3D box
+ desktop->setCurrentLayer(clicked_item);
sp_desktop_selection(desktop)->clear();
this->dragging = false;
sp_event_context_discard_delayed_snap_event(this);
@@ -591,8 +599,11 @@ bool SelectTool::root_handler(GdkEvent* event) {
item_in_group = desktop->getItemAtPoint(Geom::Point(event->button.x, event->button.y), TRUE);
group_at_point = desktop->getGroupAtPoint(Geom::Point(event->button.x, event->button.y));
- if (SP_IS_LAYER(selection->single())) {
- group_at_point = SP_GROUP(selection->single());
+ {
+ SPGroup *selGroup = dynamic_cast<SPGroup *>(selection->single());
+ if (selGroup && (selGroup->layerMode() == SPGroup::LAYER)) {
+ group_at_point = selGroup;
+ }
}
// group-at-point is meant to be topmost item if it's a group,
@@ -673,10 +684,11 @@ bool SelectTool::root_handler(GdkEvent* event) {
selection->toggle(this->item);
} else {
SPObject* single = selection->single();
+ SPGroup *singleGroup = dynamic_cast<SPGroup *>(single);
// without shift, increase state (i.e. toggle scale/rotation handles)
if (selection->includes(this->item)) {
_seltrans->increaseState();
- } else if (SP_IS_LAYER(single) && single->isAncestorOf(this->item)) {
+ } else if (singleGroup && (singleGroup->layerMode() == SPGroup::LAYER) && single->isAncestorOf(this->item)) {
_seltrans->increaseState();
} else {
_seltrans->resetState();
@@ -818,7 +830,7 @@ bool SelectTool::root_handler(GdkEvent* event) {
SPItem *item = desktop->getItemAtPoint(p, true, NULL);
// Save pointer to current cycle-item so that we can find it again later, in the freshly built list
- SPItem *tmp_cur_item = this->cycling_cur_item ? SP_ITEM(this->cycling_cur_item->data) : NULL;
+ SPItem *tmp_cur_item = this->cycling_cur_item ? dynamic_cast<SPItem *>(static_cast<SPObject *>(this->cycling_cur_item->data)) : NULL;
g_list_free(this->cycling_items);
this->cycling_items = NULL;
this->cycling_cur_item = NULL;
@@ -851,11 +863,14 @@ bool SelectTool::root_handler(GdkEvent* event) {
Inkscape::DrawingItem *arenaitem;
for(GList *l = this->cycling_items_cmp; l != NULL; l = l->next) {
- arenaitem = SP_ITEM(l->data)->get_arenaitem(desktop->dkey);
- arenaitem->setOpacity(1.0);
- //if (!shift_pressed && !g_list_find(this->cycling_items_selected_before, SP_ITEM(l->data)) && selection->includes(SP_ITEM(l->data)))
- if (!g_list_find(this->cycling_items_selected_before, SP_ITEM(l->data)) && selection->includes(SP_ITEM(l->data))) {
- selection->remove(SP_ITEM(l->data));
+ SPItem *item = dynamic_cast<SPItem *>(static_cast<SPObject *>(l->data));
+ if (item) {
+ arenaitem = item->get_arenaitem(desktop->dkey);
+ arenaitem->setOpacity(1.0);
+ //if (!shift_pressed && !g_list_find(this->cycling_items_selected_before, item) && selection->includes(item))
+ if (!g_list_find(this->cycling_items_selected_before, item) && selection->includes(item)) {
+ selection->remove(item);
+ }
}
}
@@ -869,16 +884,19 @@ bool SelectTool::root_handler(GdkEvent* event) {
// ... and rebuild them with the new items.
this->cycling_items_cmp = g_list_copy(this->cycling_items);
- SPItem *item;
for(GList *l = this->cycling_items; l != NULL; l = l->next) {
- item = SP_ITEM(l->data);
- arenaitem = item->get_arenaitem(desktop->dkey);
- arenaitem->setOpacity(0.3);
-
- if (selection->includes(item)) {
- // already selected items are stored separately, too
- this->cycling_items_selected_before = g_list_append(this->cycling_items_selected_before, item);
+ SPItem *item = dynamic_cast<SPItem *>(static_cast<SPObject *>(l->data));
+ if (item) {
+ arenaitem = item->get_arenaitem(desktop->dkey);
+ arenaitem->setOpacity(0.3);
+
+ if (selection->includes(item)) {
+ // already selected items are stored separately, too
+ this->cycling_items_selected_before = g_list_append(this->cycling_items_selected_before, item);
+ }
+ } else {
+ g_assert_not_reached();
}
}
@@ -1134,9 +1152,9 @@ bool SelectTool::root_handler(GdkEvent* event) {
if (MOD__CTRL_ONLY(event)) {
if (selection->singleItem()) {
SPItem *clicked_item = selection->singleItem();
-
- if ( SP_IS_GROUP(clicked_item) || SP_IS_BOX3D(clicked_item)) { // enter group or a 3D box
- desktop->setCurrentLayer(reinterpret_cast<SPObject *>(clicked_item));
+ SPGroup *clickedGroup = dynamic_cast<SPGroup *>(clicked_item);
+ if ( (clickedGroup && (clickedGroup->layerMode() != SPGroup::LAYER)) || dynamic_cast<SPBox3D *>(clicked_item)) { // enter group or a 3D box
+ desktop->setCurrentLayer(clicked_item);
sp_desktop_selection(desktop)->clear();
} else {
this->desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Selected object is not a group. Cannot enter."));
diff --git a/src/ui/tools/select-tool.h b/src/ui/tools/select-tool.h
index edc4069a2..5af99a56a 100644
--- a/src/ui/tools/select-tool.h
+++ b/src/ui/tools/select-tool.h
@@ -13,7 +13,6 @@
*/
#include "ui/tools/tool-base.h"
-#include <gtk/gtk.h>
#define SP_SELECT_CONTEXT(obj) (dynamic_cast<Inkscape::UI::Tools::SelectTool*>((Inkscape::UI::Tools::ToolBase*)obj))
#define SP_IS_SELECT_CONTEXT(obj) (dynamic_cast<const Inkscape::UI::Tools::SelectTool*>((const Inkscape::UI::Tools::ToolBase*)obj) != NULL)
diff --git a/src/ui/tools/spiral-tool.cpp b/src/ui/tools/spiral-tool.cpp
index 5ae229df8..18c3e4e2d 100644
--- a/src/ui/tools/spiral-tool.cpp
+++ b/src/ui/tools/spiral-tool.cpp
@@ -39,13 +39,13 @@
#include "xml/node-event-vector.h"
#include "preferences.h"
#include "context-fns.h"
-#include "shape-editor.h"
+#include "ui/shape-editor.h"
#include "verbs.h"
#include "display/sp-canvas-item.h"
using Inkscape::DocumentUndo;
-#include "tool-factory.h"
+#include "ui/tool-factory.h"
namespace Inkscape {
namespace UI {
@@ -104,8 +104,8 @@ SpiralTool::~SpiralTool() {
* destroys old and creates new knotholder.
*/
void SpiralTool::selection_changed(Inkscape::Selection *selection) {
- this->shape_editor->unset_item(SH_KNOTHOLDER);
- this->shape_editor->set_item(selection->singleItem(), SH_KNOTHOLDER);
+ this->shape_editor->unset_item();
+ this->shape_editor->set_item(selection->singleItem());
}
void SpiralTool::setup() {
@@ -119,7 +119,7 @@ void SpiralTool::setup() {
SPItem *item = sp_desktop_selection(this->desktop)->singleItem();
if (item) {
- this->shape_editor->set_item(item, SH_KNOTHOLDER);
+ this->shape_editor->set_item(item);
}
Inkscape::Selection *selection = sp_desktop_selection(this->desktop);
diff --git a/src/ui/tools/spiral-tool.h b/src/ui/tools/spiral-tool.h
index 416aeb7e4..add92342d 100644
--- a/src/ui/tools/spiral-tool.h
+++ b/src/ui/tools/spiral-tool.h
@@ -15,17 +15,15 @@
* Released under GNU GPL
*/
-#include <gtk/gtk.h>
-#include <stddef.h>
-#include <sigc++/sigc++.h>
+#include <sigc++/connection.h>
#include <2geom/point.h>
#include "ui/tools/tool-base.h"
-#include "sp-spiral.h"
-
#define SP_SPIRAL_CONTEXT(obj) (dynamic_cast<Inkscape::UI::Tools::SpiralTool*>((Inkscape::UI::Tools::ToolBase*)obj))
#define SP_IS_SPIRAL_CONTEXT(obj) (dynamic_cast<const Inkscape::UI::Tools::SpiralTool*>((const Inkscape::UI::Tools::ToolBase*)obj) != NULL)
+class SPSpiral;
+
namespace Inkscape {
namespace UI {
namespace Tools {
diff --git a/src/ui/tools/spray-tool.cpp b/src/ui/tools/spray-tool.cpp
index 08d3119a1..cdc608558 100644
--- a/src/ui/tools/spray-tool.cpp
+++ b/src/ui/tools/spray-tool.cpp
@@ -84,7 +84,7 @@ using namespace std;
// Please enable again when working on 1.0
#define ENABLE_SPRAY_MODE_SINGLE_PATH
-#include "tool-factory.h"
+#include "ui/tool-factory.h"
namespace Inkscape {
namespace UI {
@@ -384,11 +384,14 @@ static bool sp_spray_recursive(SPDesktop *desktop,
gint _distrib)
{
bool did = false;
-
- if (SP_IS_BOX3D(item) ) {
- // convert 3D boxes to ordinary groups before spraying their shapes
- item = box3d_convert_to_group(SP_BOX3D(item));
- selection->add(item);
+
+ {
+ SPBox3D *box = dynamic_cast<SPBox3D *>(item);
+ if (box) {
+ // convert 3D boxes to ordinary groups before spraying their shapes
+ item = box3d_convert_to_group(box);
+ selection->add(item);
+ }
}
double _fid = g_random_double_range(0, 1);
@@ -413,7 +416,7 @@ static bool sp_spray_recursive(SPDesktop *desktop,
parent->appendChild(copy);
SPObject *new_obj = doc->getObjectByRepr(copy);
- item_copied = SP_ITEM(new_obj); // Convertion object->item
+ item_copied = dynamic_cast<SPItem *>(new_obj); // Convertion object->item
Geom::Point center=item->getCenter();
sp_spray_scale_rel(center,desktop, item_copied, Geom::Scale(_scale,_scale));
sp_spray_scale_rel(center,desktop, item_copied, Geom::Scale(scale,scale));
@@ -437,7 +440,7 @@ static bool sp_spray_recursive(SPDesktop *desktop,
items != NULL;
items = items->next) {
- SPItem *item1 = SP_ITEM(items->data);
+ SPItem *item1 = dynamic_cast<SPItem *>(static_cast<SPObject *>(items->data));
if (i == 1) {
parent_item = item1;
}
@@ -458,7 +461,7 @@ static bool sp_spray_recursive(SPDesktop *desktop,
Inkscape::XML::Node *copy = old_repr->duplicate(xml_doc);
parent->appendChild(copy);
SPObject *new_obj = doc->getObjectByRepr(copy);
- item_copied = SP_ITEM(new_obj);
+ item_copied = dynamic_cast<SPItem *>(new_obj);
// 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());
@@ -503,7 +506,7 @@ static bool sp_spray_recursive(SPDesktop *desktop,
SPObject *clone_object = doc->getObjectByRepr(clone);
// Conversion object->item
- item_copied = SP_ITEM(clone_object);
+ item_copied = dynamic_cast<SPItem *>(clone_object);
Geom::Point center = item->getCenter();
sp_spray_scale_rel(center, desktop, item_copied, Geom::Scale(_scale, _scale));
sp_spray_scale_rel(center, desktop, item_copied, Geom::Scale(scale, scale));
@@ -554,13 +557,16 @@ static bool sp_spray_dilate(SprayTool *tc, Geom::Point /*event_p*/, Geom::Point
for (GSList *items = original_selection;
items != NULL;
items = items->next) {
- sp_object_ref(SP_ITEM(items->data));
+ SPItem *item = dynamic_cast<SPItem *>(static_cast<SPObject *>(items->data));
+ g_assert(item != NULL);
+ sp_object_ref(item);
}
for (GSList *items = original_selection;
items != NULL;
items = items->next) {
- SPItem *item = SP_ITEM(items->data);
+ SPItem *item = dynamic_cast<SPItem *>(static_cast<SPObject *>(items->data));
+ g_assert(item != NULL);
if (is_transform_modes(tc->mode)) {
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)) {
@@ -576,7 +582,9 @@ static bool sp_spray_dilate(SprayTool *tc, Geom::Point /*event_p*/, Geom::Point
for (GSList *items = original_selection;
items != NULL;
items = items->next) {
- sp_object_unref(SP_ITEM(items->data));
+ SPItem *item = dynamic_cast<SPItem *>(static_cast<SPObject *>(items->data));
+ g_assert(item != NULL);
+ sp_object_unref(item);
}
}
@@ -677,7 +685,7 @@ bool SprayTool::root_handler(GdkEvent* event) {
desktop->setToolboxAdjustmentValue("population", this->population * 100);
Geom::Point const scroll_w(event->button.x, event->button.y);
Geom::Point const scroll_dt = desktop->point();;
- Geom::Point motion_doc(desktop->dt2doc(scroll_dt));
+
switch (event->scroll.direction) {
case GDK_SCROLL_DOWN:
case GDK_SCROLL_UP: {
diff --git a/src/ui/tools/star-tool.cpp b/src/ui/tools/star-tool.cpp
index 68f998920..7604ba04e 100644
--- a/src/ui/tools/star-tool.cpp
+++ b/src/ui/tools/star-tool.cpp
@@ -41,7 +41,7 @@
#include "xml/repr.h"
#include "xml/node-event-vector.h"
#include "context-fns.h"
-#include "shape-editor.h"
+#include "ui/shape-editor.h"
#include "verbs.h"
#include "display/sp-canvas-item.h"
@@ -49,7 +49,7 @@
using Inkscape::DocumentUndo;
-#include "tool-factory.h"
+#include "ui/tool-factory.h"
namespace Inkscape {
namespace UI {
@@ -112,8 +112,8 @@ StarTool::~StarTool() {
void StarTool::selection_changed(Inkscape::Selection* selection) {
g_assert (selection != NULL);
- this->shape_editor->unset_item(SH_KNOTHOLDER);
- this->shape_editor->set_item(selection->singleItem(), SH_KNOTHOLDER);
+ this->shape_editor->unset_item();
+ this->shape_editor->set_item(selection->singleItem());
}
void StarTool::setup() {
@@ -129,7 +129,7 @@ void StarTool::setup() {
SPItem *item = sp_desktop_selection(this->desktop)->singleItem();
if (item) {
- this->shape_editor->set_item(item, SH_KNOTHOLDER);
+ this->shape_editor->set_item(item);
}
Inkscape::Selection *selection = sp_desktop_selection(this->desktop);
diff --git a/src/ui/tools/text-tool.cpp b/src/ui/tools/text-tool.cpp
index ac830fe6b..a72748733 100644
--- a/src/ui/tools/text-tool.cpp
+++ b/src/ui/tools/text-tool.cpp
@@ -40,7 +40,7 @@
#include "rubberband.h"
#include "selection-chemistry.h"
#include "selection.h"
-#include "shape-editor.h"
+#include "ui/shape-editor.h"
#include "sp-flowtext.h"
#include "sp-namedview.h"
#include "sp-text.h"
@@ -52,7 +52,7 @@
#include "xml/node-event-vector.h"
#include "xml/repr.h"
#include <gtk/gtk.h>
-#include "tool-factory.h"
+#include "ui/tool-factory.h"
using Inkscape::ControlManager;
using Inkscape::DocumentUndo;
@@ -177,7 +177,7 @@ void TextTool::setup() {
SPItem *item = sp_desktop_selection(this->desktop)->singleItem();
if (item && SP_IS_FLOWTEXT(item) && SP_FLOWTEXT(item)->has_internal_frame()) {
- this->shape_editor->set_item(item, SH_KNOTHOLDER);
+ this->shape_editor->set_item(item);
}
this->sel_changed_connection = sp_desktop_selection(desktop)->connectChangedFirst(
@@ -1411,10 +1411,10 @@ void TextTool::_selectionChanged(Inkscape::Selection *selection)
ToolBase *ec = SP_EVENT_CONTEXT(this);
- ec->shape_editor->unset_item(SH_KNOTHOLDER);
+ ec->shape_editor->unset_item();
SPItem *item = selection->singleItem();
if (item && SP_IS_FLOWTEXT(item) && SP_FLOWTEXT(item)->has_internal_frame()) {
- ec->shape_editor->set_item(item, SH_KNOTHOLDER);
+ ec->shape_editor->set_item(item);
}
if (this->text && (item != this->text)) {
diff --git a/src/ui/tools/text-tool.h b/src/ui/tools/text-tool.h
index ca2b3d19a..289ee180d 100644
--- a/src/ui/tools/text-tool.h
+++ b/src/ui/tools/text-tool.h
@@ -14,10 +14,7 @@
* Released under GNU GPL, read the file 'COPYING' for more information
*/
-/* #include <gdk/gdkic.h> */
-#include <stddef.h>
-#include <sigc++/sigc++.h>
-#include <gtk/gtk.h>
+#include <sigc++/connection.h>
#include "ui/tools/tool-base.h"
#include <2geom/point.h>
@@ -26,6 +23,8 @@
#define SP_TEXT_CONTEXT(obj) (dynamic_cast<Inkscape::UI::Tools::TextTool*>((Inkscape::UI::Tools::ToolBase*)obj))
#define SP_IS_TEXT_CONTEXT(obj) (dynamic_cast<const Inkscape::UI::Tools::TextTool*>((const Inkscape::UI::Tools::ToolBase*)obj) != NULL)
+typedef struct _GtkIMContext GtkIMContext;
+
struct SPCtrlLine;
namespace Inkscape {
diff --git a/src/ui/tools/tool-base.cpp b/src/ui/tools/tool-base.cpp
index 4195c9eb2..37ca5eeea 100644
--- a/src/ui/tools/tool-base.cpp
+++ b/src/ui/tools/tool-base.cpp
@@ -18,6 +18,8 @@
# include "config.h"
#endif
+#include "widgets/desktop-widget.h"
+
#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
#include <glibmm/threads.h>
#endif
@@ -40,12 +42,11 @@
#include "desktop-handles.h"
#include "desktop-events.h"
#include "desktop-style.h"
-#include "widgets/desktop-widget.h"
#include "sp-namedview.h"
#include "selection.h"
-#include "interface.h"
+#include "ui/interface.h"
#include "macros.h"
-#include "tools-switch.h"
+#include "ui/tools-switch.h"
#include "preferences.h"
#include "message-context.h"
#include "gradient-drag.h"
@@ -54,10 +55,11 @@
#include "selcue.h"
#include "ui/tools/lpe-tool.h"
#include "ui/tool/control-point.h"
-#include "shape-editor.h"
+#include "ui/shape-editor.h"
#include "sp-guide.h"
#include "color.h"
#include "knot.h"
+#include "knot-ptr.h"
// globals for temporary switching to selector by space
static bool selector_toggled = FALSE;
@@ -1289,8 +1291,7 @@ void sp_event_context_snap_delay_handler(ToolBase *ec,
// now, just in case there's no future motion event that drops under the speed limit (when
// stopping abruptly)
delete ec->_delayed_snap_event;
- ec->_delayed_snap_event = new DelayedSnapEvent(ec, dse_item, dse_item2,
- event, origin); // watchdog is reset, i.e. pushed forward in time
+ ec->_delayed_snap_event = new DelayedSnapEvent(ec, dse_item, dse_item2, event, origin); // watchdog is reset, i.e. pushed forward in time
// If the watchdog expires before a new motion event is received, we will snap (as explained
// above). This means however that when the timer is too short, we will always snap and that the
// speed threshold is ineffective. In the extreme case the delay is set to zero, and snapping will
@@ -1301,15 +1302,13 @@ void sp_event_context_snap_delay_handler(ToolBase *ec,
// snap, and set a new watchdog again.
if (ec->_delayed_snap_event == NULL) { // no watchdog has been set
// it might have already expired, so we'll set a new one; the snapping frequency will be limited this way
- ec->_delayed_snap_event = new DelayedSnapEvent(ec, dse_item,
- dse_item2, event, origin);
+ ec->_delayed_snap_event = new DelayedSnapEvent(ec, dse_item, dse_item2, event, origin);
} // else: watchdog has been set before and we'll wait for it to expire
}
} else {
// This is the first GDK_MOTION_NOTIFY event, so postpone snapping and set the watchdog
g_assert(ec->_delayed_snap_event == NULL);
- ec->_delayed_snap_event = new DelayedSnapEvent(ec, dse_item, dse_item2,
- event, origin);
+ ec->_delayed_snap_event = new DelayedSnapEvent(ec, dse_item, dse_item2, event, origin);
}
prev_pos = event_pos;
@@ -1362,6 +1361,7 @@ gboolean sp_event_context_snap_watchdog_callback(gpointer data) {
break;
case DelayedSnapEvent::KNOT_HANDLER: {
gpointer knot = dse->getItem2();
+ check_if_knot_deleted(knot);
if (knot && SP_IS_KNOT(knot)) {
sp_knot_handler_request_position(dse->getEvent(), SP_KNOT(knot));
}
diff --git a/src/ui/tools/tool-base.h b/src/ui/tools/tool-base.h
index b27de9030..7a6ab83e7 100644
--- a/src/ui/tools/tool-base.h
+++ b/src/ui/tools/tool-base.h
@@ -30,7 +30,6 @@ namespace Glib {
class GrDrag;
class SPDesktop;
class SPItem;
-class ShapeEditor;
namespace Inkscape {
class MessageContext;
@@ -42,6 +41,9 @@ namespace Inkscape {
namespace Inkscape {
namespace UI {
+
+class ShapeEditor;
+
namespace Tools {
class ToolBase;
diff --git a/src/ui/tools/tweak-tool.cpp b/src/ui/tools/tweak-tool.cpp
index 75650d3af..f56975de2 100644
--- a/src/ui/tools/tweak-tool.cpp
+++ b/src/ui/tools/tweak-tool.cpp
@@ -91,7 +91,7 @@ using Inkscape::DocumentUndo;
#define DYNA_MIN_WIDTH 1.0e-6
-#include "tool-factory.h"
+#include "ui/tool-factory.h"
namespace Inkscape {
namespace UI {
@@ -372,13 +372,16 @@ sp_tweak_dilate_recursive (Inkscape::Selection *selection, SPItem *item, Geom::P
{
bool did = false;
- if (SP_IS_BOX3D(item) && !is_transform_mode(mode) && !is_color_mode(mode)) {
- // convert 3D boxes to ordinary groups before tweaking their shapes
- item = box3d_convert_to_group(SP_BOX3D(item));
- selection->add(item);
+ {
+ SPBox3D *box = dynamic_cast<SPBox3D *>(item);
+ if (box && !is_transform_mode(mode) && !is_color_mode(mode)) {
+ // convert 3D boxes to ordinary groups before tweaking their shapes
+ item = box3d_convert_to_group(box);
+ selection->add(item);
+ }
}
- if (SP_IS_TEXT(item) || SP_IS_FLOWTEXT(item)) {
+ if (dynamic_cast<SPText *>(item) || dynamic_cast<SPFlowtext *>(item)) {
GSList *items = g_slist_prepend (NULL, item);
GSList *selected = NULL;
GSList *to_select = NULL;
@@ -387,22 +390,25 @@ sp_tweak_dilate_recursive (Inkscape::Selection *selection, SPItem *item, Geom::P
g_slist_free (items);
SPObject* newObj = doc->getObjectByRepr(static_cast<Inkscape::XML::Node *>(to_select->data));
g_slist_free (to_select);
- item = SP_ITEM(newObj);
+ item = dynamic_cast<SPItem *>(newObj);
+ g_assert(item != NULL);
selection->add(item);
}
- if (SP_IS_GROUP(item) && !SP_IS_BOX3D(item)) {
+ if (dynamic_cast<SPGroup *>(item) && !dynamic_cast<SPBox3D *>(item)) {
GSList *children = NULL;
for (SPObject *child = item->firstChild() ; child; child = child->getNext() ) {
- if (SP_IS_ITEM(child)) {
+ if (dynamic_cast<SPItem *>(static_cast<SPObject *>(child))) {
children = g_slist_prepend(children, child);
}
}
for (GSList *i = children; i; i = i->next) {
- SPItem *child = SP_ITEM(i->data);
- if (sp_tweak_dilate_recursive (selection, SP_ITEM(child), p, vector, mode, radius, force, fidelity, reverse))
+ SPItem *child = dynamic_cast<SPItem *>(static_cast<SPObject *>(i->data));
+ g_assert(child != NULL);
+ if (sp_tweak_dilate_recursive (selection, child, p, vector, mode, radius, force, fidelity, reverse)) {
did = true;
+ }
}
g_slist_free(children);
@@ -509,13 +515,13 @@ sp_tweak_dilate_recursive (Inkscape::Selection *selection, SPItem *item, Geom::P
}
}
- } else if (SP_IS_PATH(item) || SP_IS_SHAPE(item)) {
+ } else if (dynamic_cast<SPPath *>(item) || dynamic_cast<SPShape *>(item)) {
Inkscape::XML::Node *newrepr = NULL;
gint pos = 0;
Inkscape::XML::Node *parent = NULL;
char const *id = NULL;
- if (!SP_IS_PATH(item)) {
+ if (!dynamic_cast<SPPath *>(item)) {
newrepr = sp_selected_item_to_curved_repr(item, 0);
if (!newrepr) {
return false;
@@ -631,7 +637,8 @@ sp_tweak_dilate_recursive (Inkscape::Selection *selection, SPItem *item, Geom::P
if (newrepr) {
newrepr->setAttribute("d", str);
} else {
- if (SP_IS_LPE_ITEM(item) && SP_LPE_ITEM(item)->hasPathEffectRecursive()) {
+ SPLPEItem *lpeitem = dynamic_cast<SPLPEItem *>(item);
+ if (lpeitem && lpeitem->hasPathEffectRecursive()) {
item->getRepr()->setAttribute("inkscape:original-d", str);
} else {
item->getRepr()->setAttribute("d", str);
@@ -769,7 +776,7 @@ static void tweak_colors_in_gradient(SPItem *item, Inkscape::PaintTarget fill_or
{
SPGradient *gradient = getGradient(item, fill_or_stroke);
- if (!gradient || !SP_IS_GRADIENT(gradient)) {
+ if (!gradient || !dynamic_cast<SPGradient *>(gradient)) {
return;
}
@@ -780,9 +787,9 @@ static void tweak_colors_in_gradient(SPItem *item, Inkscape::PaintTarget fill_or
double pos = 0;
double r = 0;
- if (SP_IS_LINEARGRADIENT(gradient)) {
- SPLinearGradient *lg = SP_LINEARGRADIENT(gradient);
+ SPLinearGradient *lg = dynamic_cast<SPLinearGradient *>(gradient);
+ if (lg) {
Geom::Point p1(lg->x1.computed, lg->y1.computed);
Geom::Point p2(lg->x2.computed, lg->y2.computed);
Geom::Point pdiff(p2 - p1);
@@ -800,11 +807,13 @@ static void tweak_colors_in_gradient(SPItem *item, Inkscape::PaintTarget fill_or
// Calculate radius in lenfth-of-gradient-line units
r = radius / vl;
- } else if (SP_IS_RADIALGRADIENT(gradient)) {
- SPRadialGradient *rg = SP_RADIALGRADIENT(gradient);
- Geom::Point c (rg->cx.computed, rg->cy.computed);
- pos = Geom::L2(p - c) / rg->r.computed;
- r = radius / rg->r.computed;
+ } else {
+ SPRadialGradient *rg = dynamic_cast<SPRadialGradient *>(gradient);
+ if (rg) {
+ Geom::Point c (rg->cx.computed, rg->cy.computed);
+ pos = Geom::L2(p - c) / rg->r.computed;
+ r = radius / rg->r.computed;
+ }
}
// Normalize pos to 0..1, taking into accound gradient spread:
@@ -836,14 +845,16 @@ static void tweak_colors_in_gradient(SPItem *item, Inkscape::PaintTarget fill_or
double offset_h = 0;
SPObject *child_prev = NULL;
for (SPObject *child = vector->firstChild(); child; child = child->getNext()) {
- if (!SP_IS_STOP(child)) {
+ SPStop *stop = dynamic_cast<SPStop *>(child);
+ if (!stop) {
continue;
}
- SPStop *stop = SP_STOP (child);
offset_h = stop->offset;
if (child_prev) {
+ SPStop *prevStop = dynamic_cast<SPStop *>(child_prev);
+ g_assert(prevStop != NULL);
if (offset_h - offset_l > r && pos_e >= offset_l && pos_e <= offset_h) {
// the summit falls in this interstop, and the radius is small,
@@ -853,9 +864,9 @@ static void tweak_colors_in_gradient(SPItem *item, Inkscape::PaintTarget fill_or
tweak_color (mode, stop->specified_color.v.c, rgb_goal,
force * (pos_e - offset_l) / (offset_h - offset_l),
do_h, do_s, do_l);
- tweak_color (mode, SP_STOP(child_prev)->specified_color.v.c, rgb_goal,
- force * (offset_h - pos_e) / (offset_h - offset_l),
- do_h, do_s, do_l);
+ tweak_color(mode, prevStop->specified_color.v.c, rgb_goal,
+ force * (offset_h - pos_e) / (offset_h - offset_l),
+ do_h, do_s, do_l);
stop->updateRepr();
child_prev->updateRepr();
break;
@@ -863,9 +874,9 @@ static void tweak_colors_in_gradient(SPItem *item, Inkscape::PaintTarget fill_or
// wide brush, may affect more than 2 stops,
// paint each stop by the force from the profile curve
if (offset_l <= pos_e && offset_l > pos_e - r) {
- tweak_color (mode, SP_STOP(child_prev)->specified_color.v.c, rgb_goal,
- force * tweak_profile (fabs (pos_e - offset_l), r),
- do_h, do_s, do_l);
+ tweak_color(mode, prevStop->specified_color.v.c, rgb_goal,
+ force * tweak_profile (fabs (pos_e - offset_l), r),
+ do_h, do_s, do_l);
child_prev->updateRepr();
}
@@ -894,10 +905,11 @@ sp_tweak_color_recursive (guint mode, SPItem *item, SPItem *item_at_point,
{
bool did = false;
- if (SP_IS_GROUP(item)) {
+ if (dynamic_cast<SPGroup *>(item)) {
for (SPObject *child = item->firstChild() ; child; child = child->getNext() ) {
- if (SP_IS_ITEM(child)) {
- if (sp_tweak_color_recursive (mode, SP_ITEM(child), item_at_point,
+ SPItem *childItem = dynamic_cast<SPItem *>(child);
+ if (childItem) {
+ if (sp_tweak_color_recursive (mode, childItem, item_at_point,
fill_goal, do_fill,
stroke_goal, do_stroke,
opacity_goal, do_opacity,
@@ -953,11 +965,11 @@ sp_tweak_color_recursive (guint mode, SPItem *item, SPItem *item_at_point,
//cycle through filter primitives
SPObject *primitive_obj = style->getFilter()->children;
while (primitive_obj) {
- if (SP_IS_FILTER_PRIMITIVE(primitive_obj)) {
- SPFilterPrimitive *primitive = SP_FILTER_PRIMITIVE(primitive_obj);
+ SPFilterPrimitive *primitive = dynamic_cast<SPFilterPrimitive *>(primitive_obj);
+ if (primitive) {
//if primitive is gaussianblur
- if(SP_IS_GAUSSIANBLUR(primitive)) {
- SPGaussianBlur * spblur = SP_GAUSSIANBLUR(primitive);
+ SPGaussianBlur * spblur = dynamic_cast<SPGaussianBlur *>(primitive);
+ if (spblur) {
float num = spblur->stdDeviation.getNumber();
blur_now += num * i2dt.descrim(); // sum all blurs in the filter
}
@@ -1080,7 +1092,7 @@ sp_tweak_dilate (TweakTool *tc, Geom::Point event_p, Geom::Point p, Geom::Point
items != NULL;
items = items->next) {
- SPItem *item = SP_ITEM(items->data);
+ SPItem *item = dynamic_cast<SPItem *>(static_cast<SPObject *>(items->data));
if (is_color_mode (tc->mode)) {
if (do_fill || do_stroke || do_opacity) {
diff --git a/src/ui/tools/zoom-tool.cpp b/src/ui/tools/zoom-tool.cpp
index 9f99cfe2e..b3fb78c8f 100644
--- a/src/ui/tools/zoom-tool.cpp
+++ b/src/ui/tools/zoom-tool.cpp
@@ -25,7 +25,7 @@
#include "selection-chemistry.h"
#include "ui/tools/zoom-tool.h"
-#include "tool-factory.h"
+#include "ui/tool-factory.h"
namespace Inkscape {
namespace UI {