summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJabier Arraiza Cenoz <jabier.arraiza@marker.es>2016-05-02 07:47:14 +0000
committerJabiertxof <jtx@jtx.marker.es>2016-05-02 07:47:14 +0000
commit2a3581c9a5e6d18b3cd0ea2fe523063a116af8f8 (patch)
treeb32781f707e90c5e93d606879e31081e7086db20 /src
parentTranslations. Italian translation update. (diff)
downloadinkscape-2a3581c9a5e6d18b3cd0ea2fe523063a116af8f8.tar.gz
inkscape-2a3581c9a5e6d18b3cd0ea2fe523063a116af8f8.zip
Working on clip erase basic work done but broken
(bzr r14865.1.1)
Diffstat (limited to 'src')
-rw-r--r--src/sp-lpe-item.cpp36
-rw-r--r--src/ui/tools/eraser-tool.cpp109
-rw-r--r--src/widgets/eraser-toolbar.cpp30
3 files changed, 134 insertions, 41 deletions
diff --git a/src/sp-lpe-item.cpp b/src/sp-lpe-item.cpp
index fdc2949d5..5753e9307 100644
--- a/src/sp-lpe-item.cpp
+++ b/src/sp-lpe-item.cpp
@@ -349,10 +349,10 @@ sp_lpe_item_create_original_path_recursive(SPLPEItem *lpeitem)
{
sp_lpe_item_create_original_path_recursive(SP_LPE_ITEM(mask->firstChild()));
}
- SPClipPath * clipPath = lpeitem->clip_ref->getObject();
- if(clipPath)
+ SPClipPath * clip_path = lpeitem->clip_ref->getObject();
+ if(clip_path)
{
- sp_lpe_item_create_original_path_recursive(SP_LPE_ITEM(clipPath->firstChild()));
+ sp_lpe_item_create_original_path_recursive(SP_LPE_ITEM(clip_path->firstChild()));
}
if (SP_IS_GROUP(lpeitem)) {
std::vector<SPItem*> item_list = sp_item_group_item_list(SP_GROUP(lpeitem));
@@ -383,10 +383,10 @@ sp_lpe_item_cleanup_original_path_recursive(SPLPEItem *lpeitem)
{
sp_lpe_item_cleanup_original_path_recursive(SP_LPE_ITEM(mask->firstChild()));
}
- SPClipPath * clipPath = lpeitem->clip_ref->getObject();
- if(clipPath)
+ SPClipPath * clip_path = lpeitem->clip_ref->getObject();
+ if(clip_path)
{
- sp_lpe_item_cleanup_original_path_recursive(SP_LPE_ITEM(clipPath->firstChild()));
+ sp_lpe_item_cleanup_original_path_recursive(SP_LPE_ITEM(clip_path->firstChild()));
}
}
std::vector<SPItem*> item_list = sp_item_group_item_list(SP_GROUP(lpeitem));
@@ -405,10 +405,10 @@ sp_lpe_item_cleanup_original_path_recursive(SPLPEItem *lpeitem)
{
sp_lpe_item_cleanup_original_path_recursive(SP_LPE_ITEM(mask->firstChild()));
}
- SPClipPath * clipPath = lpeitem->clip_ref->getObject();
- if(clipPath)
+ SPClipPath * clip_path = lpeitem->clip_ref->getObject();
+ if(clip_path)
{
- sp_lpe_item_cleanup_original_path_recursive(SP_LPE_ITEM(clipPath->firstChild()));
+ sp_lpe_item_cleanup_original_path_recursive(SP_LPE_ITEM(clip_path->firstChild()));
}
repr->setAttribute("d", repr->attribute("inkscape:original-d"));
repr->setAttribute("inkscape:original-d", NULL);
@@ -640,10 +640,13 @@ bool SPLPEItem::hasPathEffectRecursive() const
void
SPLPEItem::apply_to_clippath(SPItem *item)
{
- SPClipPath *clipPath = item->clip_ref->getObject();
- if(clipPath) {
- SPObject * clip_data = clipPath->firstChild();
- apply_to_clip_or_mask(SP_ITEM(clip_data), item);
+ SPClipPath *clip_path = item->clip_ref->getObject();
+ if(clip_path) {
+ std::vector<SPObject*> clip_path_list = clip_path->childList(true);
+ for ( std::vector<SPObject*>::const_iterator iter=clip_path_list.begin();iter!=clip_path_list.end();++iter) {
+ SPObject * clip_data = *iter;
+ apply_to_clip_or_mask(SP_ITEM(clip_data), item);
+ }
}
if(SP_IS_GROUP(item)){
std::vector<SPItem*> item_list = sp_item_group_item_list(SP_GROUP(item));
@@ -659,8 +662,11 @@ SPLPEItem::apply_to_mask(SPItem *item)
{
SPMask *mask = item->mask_ref->getObject();
if(mask) {
- SPObject *mask_data = mask->firstChild();
- apply_to_clip_or_mask(SP_ITEM(mask_data), item);
+ std::vector<SPObject*> mask_list = mask->childList(true);
+ for ( std::vector<SPObject*>::const_iterator iter=mask_list.begin();iter!=mask_list.end();++iter) {
+ SPObject * mask_data = *iter;
+ apply_to_clip_or_mask(SP_ITEM(mask_data), item);
+ }
}
if(SP_IS_GROUP(item)){
std::vector<SPItem*> item_list = sp_item_group_item_list(SP_GROUP(item));
diff --git a/src/ui/tools/eraser-tool.cpp b/src/ui/tools/eraser-tool.cpp
index 6b32b5901..38e599c05 100644
--- a/src/ui/tools/eraser-tool.cpp
+++ b/src/ui/tools/eraser-tool.cpp
@@ -58,6 +58,8 @@
#include "sp-item-group.h"
#include "sp-shape.h"
#include "sp-path.h"
+#include "sp-clippath.h"
+#include "sp-rect.h"
#include "sp-text.h"
#include "display/canvas-bpath.h"
#include "display/canvas-arena.h"
@@ -69,6 +71,7 @@
#include <2geom/math-utils.h>
#include <2geom/pathvector.h>
#include "path-chemistry.h"
+#include "selection-chemistry.h"
#include "display/curve.h"
#include "ui/tools/eraser-tool.h"
@@ -380,7 +383,7 @@ void EraserTool::cancel() {
bool EraserTool::root_handler(GdkEvent* event) {
gint ret = FALSE;
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
- gint eraserMode = prefs->getBool("/tools/eraser/mode") ? 1 : 0;
+ gint eraser_mode = prefs->getInt("/tools/eraser/mode", 2);
switch (event->type) {
case GDK_BUTTON_PRESS:
if (event->button.button == 1 && !this->space_panning) {
@@ -400,7 +403,7 @@ bool EraserTool::root_handler(GdkEvent* event) {
if (this->repr) {
this->repr = NULL;
}
- if ( ! eraserMode ) {
+ if ( eraser_mode == 0 ) {
Inkscape::Rubberband::get(desktop)->start(desktop, button_dt);
Inkscape::Rubberband::get(desktop)->setMode(RUBBERBAND_MODE_TOUCHPATH);
}
@@ -448,7 +451,7 @@ bool EraserTool::root_handler(GdkEvent* event) {
ret = TRUE;
}
- if ( !eraserMode ) {
+ if ( eraser_mode == 0 ) {
this->accumulated->reset();
Inkscape::Rubberband::get(desktop)->move(motion_dt);
}
@@ -491,7 +494,7 @@ bool EraserTool::root_handler(GdkEvent* event) {
ret = TRUE;
}
- if (!eraserMode && Inkscape::Rubberband::get(desktop)->is_started()) {
+ if (eraser_mode == 0 && Inkscape::Rubberband::get(desktop)->is_started()) {
Inkscape::Rubberband::get(desktop)->stop();
}
@@ -578,7 +581,7 @@ bool EraserTool::root_handler(GdkEvent* event) {
break;
case GDK_KEY_Escape:
- if ( !eraserMode ) {
+ if ( eraser_mode == 0 ) {
Inkscape::Rubberband::get(desktop)->stop();
}
if (this->is_drawing) {
@@ -640,7 +643,9 @@ void EraserTool::clear_current() {
void EraserTool::set_to_accumulated() {
bool workDone = false;
-
+ SPDocument *document = this->desktop->doc();
+// bool has_undo_sensitive = DocumentUndo::getUndoSensitive(document);
+// DocumentUndo::setUndoSensitive(document, false);
if (!this->accumulated->is_empty()) {
if (!this->repr) {
/* Create object */
@@ -666,7 +671,7 @@ void EraserTool::set_to_accumulated() {
bool wasSelection = false;
Inkscape::Selection *selection = desktop->getSelection();
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
- gint eraserMode = prefs->getBool("/tools/eraser/mode") ? 1 : 0;
+ gint eraser_mode = prefs->getInt("/tools/eraser/mode", 2);
Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc();
SPItem* acid = SP_ITEM(desktop->doc()->getObjectByRepr(this->repr));
@@ -674,7 +679,7 @@ void EraserTool::set_to_accumulated() {
std::vector<SPItem*> remainingItems;
std::vector<SPItem*> toWorkOn;
if (selection->isEmpty()) {
- if ( eraserMode ) {
+ if ( eraser_mode == 1 || eraser_mode == 2) {
toWorkOn = desktop->getDocument()->getItemsPartiallyInBox(desktop->dkey, *eraserBbox);
} else {
Inkscape::Rubberband *r = Inkscape::Rubberband::get(desktop);
@@ -682,7 +687,7 @@ void EraserTool::set_to_accumulated() {
}
toWorkOn.erase(std::remove(toWorkOn.begin(), toWorkOn.end(), acid), toWorkOn.end());
} else {
- if ( !eraserMode ) {
+ if ( eraser_mode == 0 ) {
Inkscape::Rubberband *r = Inkscape::Rubberband::get(desktop);
std::vector<SPItem*> touched;
touched = desktop->getDocument()->getItemsAtPoints(desktop->dkey, r->getPoints());
@@ -698,7 +703,7 @@ void EraserTool::set_to_accumulated() {
}
if ( !toWorkOn.empty() ) {
- if ( eraserMode ) {
+ if ( eraser_mode == 1 ) {
for (std::vector<SPItem*>::const_iterator i = toWorkOn.begin(); i != toWorkOn.end(); ++i){
SPItem *item = *i;
SPUse *use = dynamic_cast<SPUse *>(item);
@@ -708,7 +713,6 @@ void EraserTool::set_to_accumulated() {
item->deleteObject(true);
sp_object_unref(item);
workDone = true;
- workDone = true;
} else if (SP_IS_GROUP(item) || use ) {
/*Do nothing*/
} else {
@@ -755,6 +759,81 @@ void EraserTool::set_to_accumulated() {
}
}
}
+ } else if ( eraser_mode == 2 ) {
+ for (std::vector<SPItem*>::const_iterator i = toWorkOn.begin(); i != toWorkOn.end(); ++i){
+ selection->clear();
+ SPItem *item = *i;
+ Geom::OptRect bbox = item->desktopVisualBounds();
+ Inkscape::XML::Document *xml_doc = this->desktop->doc()->getReprDoc();
+ Inkscape::XML::Node *rect_repr = xml_doc->createElement("svg:rect");
+ SPRect * rect = SP_RECT(this->desktop->currentLayer()->appendChildRepr(rect_repr));
+ rect->updateRepr();
+ rect->setPosition (bbox.min()[Geom::X], bbox.min()[Geom::Y], bbox.dimensions()[Geom::X], bbox.dimensions()[Geom::Y]);
+ rect->doWriteTransform(rect_repr, SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse() * this->desktop->dt2doc());
+ Inkscape::GC::release(rect_repr);
+
+
+ Inkscape::XML::Node *rect_repr2 = xml_doc->createElement("svg:rect");
+ SPRect * rect2 = SP_RECT(this->desktop->currentLayer()->appendChildRepr(rect_repr2));
+ rect2->updateRepr();
+ sp_desktop_apply_style_tool (desktop, rect_repr2, "/tools/shapes/rect", false);
+ rect2->setPosition (bbox->left(), bbox->top(), bbox->width(), bbox->height());
+ rect->doWriteTransform(rect_repr, SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse() * this->desktop->dt2doc());
+ Inkscape::GC::release(rect_repr2);
+
+
+ Inkscape::XML::Node *rect_repr3 = xml_doc->createElement("svg:rect");
+ SPRect * rect3 = SP_RECT(this->desktop->currentLayer()->appendChildRepr(rect_repr3));
+ rect3->updateRepr();
+ sp_desktop_apply_style_tool (desktop, rect_repr3, "/tools/shapes/rect", false);
+ rect3->setPosition (bbox->left(), bbox->top(), bbox->width(), bbox->height());
+ rect->doWriteTransform(rect_repr3, SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse() * this->desktop->doc2dt());
+ Inkscape::GC::release(rect_repr3);
+
+
+
+
+
+ Inkscape::XML::Node* dup = this->repr->duplicate(xml_doc);
+ this->repr->parent()->appendChild(dup);
+ Inkscape::GC::release(dup); // parent takes over
+ selection->set(dup);
+ sp_selected_path_union_skip_undo(selection, this->desktop);
+ sp_selection_raise_to_top(selection, this->desktop);
+ if (bbox && bbox->intersects(*eraserBbox)) {
+ SPClipPath *clip_path = item->clip_ref->getObject();
+ if (clip_path) {
+ SPObject *clip_data = clip_path->firstChild();
+ Inkscape::XML::Node *dup_clip = clip_data->getRepr()->duplicate(xml_doc);
+ if (dup_clip) {
+ this->repr->parent()->appendChild(dup_clip);
+ sp_object_ref(clip_data, 0);
+ clip_data->deleteObject(true);
+ sp_object_unref(clip_data);
+ sp_selection_raise_to_top(selection, this->desktop);
+ selection->add(dup_clip);
+ }
+ } else {
+ selection->add(rect);
+ }
+ sp_selected_path_diff_skip_undo(selection, this->desktop);
+ sp_selection_raise_to_top(selection, this->desktop);
+ selection->add(item);
+ sp_selection_set_mask(this->desktop, true, false);
+ } else {
+ SPItem *erase_clip = selection->singleItem();
+ if (erase_clip) {
+ sp_object_ref(erase_clip, 0);
+ erase_clip->deleteObject(true);
+ sp_object_unref(erase_clip);
+ }
+ }
+ workDone = true;
+ }
+ selection->clear();
+ if (wasSelection) {
+ selection->setList(toWorkOn);
+ }
} else {
for (std::vector<SPItem*> ::const_iterator i = toWorkOn.begin();i!=toWorkOn.end();++i) {
sp_object_ref( *i, 0 );
@@ -768,7 +847,7 @@ void EraserTool::set_to_accumulated() {
}
}
- if ( !eraserMode ) {
+ if ( eraser_mode == 0 ) {
//sp_selection_delete(desktop);
remainingItems.clear();
}
@@ -792,7 +871,7 @@ void EraserTool::set_to_accumulated() {
}
}
-
+// DocumentUndo::setUndoSensitive(document, has_undo_sensitive);
if ( workDone ) {
DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_ERASER, _("Draw eraser stroke"));
} else {
@@ -987,7 +1066,7 @@ void EraserTool::fit_and_split(bool release) {
g_print("[%d]Yup\n", this->npoints);
#endif
if (!release) {
- gint eraserMode = prefs->getBool("/tools/eraser/mode") ? 1 : 0;
+ gint eraser_mode = prefs->getInt("/tools/eraser/mode",2);
g_assert(!this->currentcurve->is_empty());
SPCanvasItem *cbp = sp_canvas_item_new(desktop->getSketch(), SP_TYPE_CANVAS_BPATH, NULL);
@@ -1009,7 +1088,7 @@ void EraserTool::fit_and_split(bool release) {
this->segments = g_slist_prepend(this->segments, cbp);
- if ( !eraserMode ) {
+ if ( eraser_mode == 0 ) {
sp_canvas_item_hide(cbp);
sp_canvas_item_hide(this->currentshape);
}
diff --git a/src/widgets/eraser-toolbar.cpp b/src/widgets/eraser-toolbar.cpp
index 45989936f..5b883905b 100644
--- a/src/widgets/eraser-toolbar.cpp
+++ b/src/widgets/eraser-toolbar.cpp
@@ -67,15 +67,15 @@ static void sp_erc_mass_value_changed( GtkAdjustment *adj, GObject* tbl )
static void sp_erasertb_mode_changed( EgeSelectOneAction *act, GObject *tbl )
{
SPDesktop *desktop = static_cast<SPDesktop *>(g_object_get_data( tbl, "desktop" ));
- bool eraserMode = ege_select_one_action_get_active( act ) != 0;
+ guint eraser_mode = ege_select_one_action_get_active( act );
if (DocumentUndo::getUndoSensitive(desktop->getDocument())) {
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
- prefs->setBool( "/tools/eraser/mode", eraserMode );
+ prefs->setInt( "/tools/eraser/mode", eraser_mode );
}
GtkAction *split = GTK_ACTION( g_object_get_data(tbl, "split") );
GtkAction *mass = GTK_ACTION( g_object_get_data(tbl, "mass") );
GtkAction *width = GTK_ACTION( g_object_get_data(tbl, "width") );
- if(eraserMode == TRUE){
+ if(eraser_mode != 0){
gtk_action_set_visible( split, TRUE );
gtk_action_set_visible( mass, TRUE );
gtk_action_set_visible( width, TRUE );
@@ -90,7 +90,7 @@ static void sp_erasertb_mode_changed( EgeSelectOneAction *act, GObject *tbl )
g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE) );
/*
- if ( eraserMode != 0 ) {
+ if ( eraser_mode != 0 ) {
} else {
}
*/
@@ -111,7 +111,7 @@ void sp_eraser_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GOb
{
Inkscape::IconSize secondarySize = ToolboxFactory::prefToSize("/toolbox/secondary", 1);
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
- gint eraserMode = FALSE;
+ gint eraser_mode = FALSE;
{
GtkListStore* model = gtk_list_store_new( 3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING );
GtkTreeIter iter;
@@ -125,10 +125,17 @@ void sp_eraser_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GOb
gtk_list_store_append( model, &iter );
gtk_list_store_set( model, &iter,
0, _("Cut"),
- 1, _("Cut out from objects"),
+ 1, _("Cut out from paths and shapes"),
2, INKSCAPE_ICON("path-difference"),
-1 );
+ gtk_list_store_append( model, &iter );
+ gtk_list_store_set( model, &iter,
+ 0, _("Clip"),
+ 1, _("Clip from objects"),
+ 2, INKSCAPE_ICON("path-intersection"),
+ -1 );
+
EgeSelectOneAction* act = ege_select_one_action_new( "EraserModeAction", (""), (""), NULL, GTK_TREE_MODEL(model) );
g_object_set( act, "short_label", _("Mode:"), NULL );
gtk_action_group_add_action( mainActions, GTK_ACTION(act) );
@@ -137,12 +144,13 @@ void sp_eraser_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GOb
ege_select_one_action_set_appearance( act, "full" );
ege_select_one_action_set_radio_action_type( act, INK_RADIO_ACTION_TYPE );
g_object_set( G_OBJECT(act), "icon-property", "iconId", NULL );
- ege_select_one_action_set_icon_column( act, 2 );
- ege_select_one_action_set_tooltip_column( act, 1 );
+ ege_select_one_action_set_icon_column( act, 2);
+ ege_select_one_action_set_icon_size( act, secondarySize );
+ ege_select_one_action_set_tooltip_column( act, 1);
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
- eraserMode = prefs->getBool("/tools/eraser/mode") ? TRUE : FALSE;
- ege_select_one_action_set_active( act, eraserMode );
+ eraser_mode = prefs->getInt("/tools/eraser/mode", 2);
+ ege_select_one_action_set_active( act, eraser_mode );
g_signal_connect_after( G_OBJECT(act), "changed", G_CALLBACK(sp_erasertb_mode_changed), holder );
}
@@ -195,7 +203,7 @@ void sp_eraser_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GOb
GtkAction *split = GTK_ACTION( g_object_get_data(holder, "split") );
GtkAction *mass = GTK_ACTION( g_object_get_data(holder, "mass") );
GtkAction *width = GTK_ACTION( g_object_get_data(holder, "width") );
- if(eraserMode == TRUE){
+ if (eraser_mode != 0) {
gtk_action_set_visible( split, TRUE );
gtk_action_set_visible( mass, TRUE );
gtk_action_set_visible( width, TRUE );