summaryrefslogtreecommitdiffstats
path: root/src/splivarot.cpp
diff options
context:
space:
mode:
authorMarc Jeanmougin <mc@localhost.localdomain>2015-02-17 02:00:37 +0000
committerMarc Jeanmougin <mc@localhost.localdomain>2015-02-17 02:00:37 +0000
commita7f2b2ba3f13ceb60376802f4a31e104153839e8 (patch)
tree6db393e9e5a0a9ab7916a0e7ed29d875efa39ea1 /src/splivarot.cpp
parentdevice-manager: Get rid of GLists (diff)
downloadinkscape-a7f2b2ba3f13ceb60376802f4a31e104153839e8.tar.gz
inkscape-a7f2b2ba3f13ceb60376802f4a31e104153839e8.zip
At first, I was thinking "I just have to go to the selection file, and change that GSList* with a std::list, then resolve the few problems"
So, i tried that. And I will continue tomorrow, and the days after, on and on. (bzr r13922.1.1)
Diffstat (limited to 'src/splivarot.cpp')
-rw-r--r--src/splivarot.cpp102
1 files changed, 47 insertions, 55 deletions
diff --git a/src/splivarot.cpp b/src/splivarot.cpp
index 8bb3e9897..aec7051e0 100644
--- a/src/splivarot.cpp
+++ b/src/splivarot.cpp
@@ -60,6 +60,11 @@ using Inkscape::DocumentUndo;
bool Ancetre(Inkscape::XML::Node *a, Inkscape::XML::Node *who);
+//SHOULD DISAPPEAR
+bool sp_repr_compare_position_obj(SPObject* &a,SPObject* &b){
+ return sp_repr_compare_position(dynamic_cast<Inkscape::XML::Node*>(a),dynamic_cast<Inkscape::XML::Node*>(b));
+}
+
void sp_selected_path_boolop(Inkscape::Selection *selection, SPDesktop *desktop, bool_op bop, const unsigned int verb=SP_VERB_NONE, const Glib::ustring description="");
void sp_selected_path_do_offset(SPDesktop *desktop, bool expand, double prefOffset);
void sp_selected_path_create_offset_object(SPDesktop *desktop, int expand, bool updating);
@@ -326,21 +331,21 @@ void
sp_selected_path_boolop(Inkscape::Selection *selection, SPDesktop *desktop, bool_op bop, const unsigned int verb, const Glib::ustring description)
{
SPDocument *doc = selection->layers()->getDocument();
- GSList *il = (GSList *) selection->itemList();
+ SelContainer il= selection->itemList();
// allow union on a single object for the purpose of removing self overlapse (svn log, revision 13334)
- if ( (g_slist_length(il) < 2) && (bop != bool_op_union)) {
+ if ( (il.size() < 2) && (bop != bool_op_union)) {
boolop_display_error_message(desktop, _("Select <b>at least 2 paths</b> to perform a boolean operation."));
return;
}
- else if ( g_slist_length(il) < 1 ) {
+ else if ( il.size() < 1 ) {
boolop_display_error_message(desktop, _("Select <b>at least 1 path</b> to perform a boolean union."));
return;
}
- g_assert(il != NULL);
+ g_assert(!il.empty());
- if (g_slist_length(il) > 2) {
+ if (il.size() > 2) {
if (bop == bool_op_diff || bop == bool_op_cut || bop == bool_op_slice ) {
boolop_display_error_message(desktop, _("Select <b>exactly 2 paths</b> to perform difference, division, or path cut."));
return;
@@ -354,8 +359,8 @@ sp_selected_path_boolop(Inkscape::Selection *selection, SPDesktop *desktop, bool
if (bop == bool_op_diff || bop == bool_op_cut || bop == bool_op_slice) {
// check in the tree to find which element of the selection list is topmost (for 2-operand commands only)
- Inkscape::XML::Node *a = SP_OBJECT(il->data)->getRepr();
- Inkscape::XML::Node *b = SP_OBJECT(il->next->data)->getRepr();
+ Inkscape::XML::Node *a = SP_OBJECT(il.front())->getRepr();
+ Inkscape::XML::Node *b = SP_OBJECT(il.back())->getRepr();
if (a == NULL || b == NULL) {
boolop_display_error_message(desktop, _("Unable to determine the <b>z-order</b> of the objects selected for difference, XOR, division, or path cut."));
@@ -394,38 +399,36 @@ sp_selected_path_boolop(Inkscape::Selection *selection, SPDesktop *desktop, bool
}
}
- il = g_slist_copy(il);
- g_assert(il != NULL);
+ g_assert(!il.empty());
// first check if all the input objects have shapes
// otherwise bail out
- for (GSList *l = il; l != NULL; l = l->next)
+ for (SelContainer::const_iterator l = il.begin(); l != il.end(); l++)
{
- SPItem *item = SP_ITEM(l->data);
+ SPItem *item = SP_ITEM(*l);
if (!SP_IS_SHAPE(item) && !SP_IS_TEXT(item) && !SP_IS_FLOWTEXT(item))
{
boolop_display_error_message(desktop, _("One of the objects is <b>not a path</b>, cannot perform boolean operation."));
- g_slist_free(il);
return;
}
}
// extract the livarot Paths from the source objects
// also get the winding rule specified in the style
- int nbOriginaux = g_slist_length(il);
+ int nbOriginaux = il.size();
std::vector<Path *> originaux(nbOriginaux);
std::vector<FillRule> origWind(nbOriginaux);
int curOrig;
{
curOrig = 0;
- for (GSList *l = il; l != NULL; l = l->next)
+ for (SelContainer::const_iterator l = il.begin(); l != il.end(); l++)
{
// apply live path effects prior to performing boolean operation
- if (SP_IS_LPE_ITEM(l->data)) {
- SP_LPE_ITEM(l->data)->removeAllPathEffects(true);
+ if (SP_IS_LPE_ITEM(*l)) {
+ SP_LPE_ITEM(*l)->removeAllPathEffects(true);
}
- SPCSSAttr *css = sp_repr_css_attr(reinterpret_cast<SPObject *>(il->data)->getRepr(), "style");
+ SPCSSAttr *css = sp_repr_css_attr(reinterpret_cast<SPObject *>(il.front())->getRepr(), "style");
gchar const *val = sp_repr_css_property(css, "fill-rule", NULL);
if (val && strcmp(val, "nonzero") == 0) {
origWind[curOrig]= fill_nonZero;
@@ -435,11 +438,10 @@ sp_selected_path_boolop(Inkscape::Selection *selection, SPDesktop *desktop, bool
origWind[curOrig]= fill_nonZero;
}
- originaux[curOrig] = Path_for_item((SPItem *) l->data, true, true);
+ originaux[curOrig] = Path_for_item((SPItem *) (*l), true, true);
if (originaux[curOrig] == NULL || originaux[curOrig]->descr_cmd.size() <= 1)
{
for (int i = curOrig; i >= 0; i--) delete originaux[i];
- g_slist_free(il);
return;
}
curOrig++;
@@ -472,7 +474,8 @@ sp_selected_path_boolop(Inkscape::Selection *selection, SPDesktop *desktop, bool
theShapeA->ConvertToShape(theShape, origWind[0]);
curOrig = 1;
- for (GSList *l = il->next; l != NULL; l = l->next) {
+ for (SelContainer::const_iterator l = il.begin(); l != il.end(); l++){
+ if(*l==il.front())continue;
originaux[curOrig]->ConvertWithBackData(0.1);
originaux[curOrig]->Fill(theShape, curOrig);
@@ -668,15 +671,13 @@ sp_selected_path_boolop(Inkscape::Selection *selection, SPDesktop *desktop, bool
if (res->descr_cmd.size() <= 1)
{
// only one command, presumably a moveto: it isn't a path
- for (GSList *l = il; l != NULL; l = l->next)
- {
- SP_OBJECT(l->data)->deleteObject();
+ for (SelContainer::const_iterator l = il.begin(); l != il.end(); l++){
+ SP_OBJECT(*l)->deleteObject();
}
DocumentUndo::done(doc, SP_VERB_NONE, description);
selection->clear();
delete res;
- g_slist_free(il);
return;
}
@@ -684,19 +685,17 @@ sp_selected_path_boolop(Inkscape::Selection *selection, SPDesktop *desktop, bool
SPObject *source;
if ( bop == bool_op_diff || bop == bool_op_cut || bop == bool_op_slice ) {
if (reverseOrderForOp) {
- source = SP_OBJECT(il->data);
+ source = SP_OBJECT(il.front());
} else {
- source = SP_OBJECT(il->next->data);
+ source = SP_OBJECT(il.back());
}
} else {
// find out the bottom object
- GSList *sorted = g_slist_copy((GSList *) selection->reprList());
-
- sorted = g_slist_sort(sorted, (GCompareFunc) sp_repr_compare_position);
+ SelContainer sorted(selection->reprList());
- source = doc->getObjectByRepr((Inkscape::XML::Node *)sorted->data);
+ sorted.sort(sp_repr_compare_position_obj);
- g_slist_free(sorted);
+ source = doc->getObjectByRepr((Inkscape::XML::Node *)sorted.front());
}
// adjust style properties that depend on a possible transform in the source object in order
@@ -721,17 +720,16 @@ sp_selected_path_boolop(Inkscape::Selection *selection, SPDesktop *desktop, bool
gchar *desc = source->desc();
// remove source paths
selection->clear();
- for (GSList *l = il; l != NULL; l = l->next) {
+ for (SelContainer::const_iterator l = il.begin(); l != il.end(); l++){
// if this is the bottommost object,
- if (!strcmp(reinterpret_cast<SPObject *>(l->data)->getRepr()->attribute("id"), id)) {
+ if (!strcmp(reinterpret_cast<SPObject *>(*l)->getRepr()->attribute("id"), id)) {
// delete it so that its clones don't get alerted; this object will be restored shortly, with the same id
- SP_OBJECT(l->data)->deleteObject(false);
+ SP_OBJECT(*l)->deleteObject(false);
} else {
// delete the object for real, so that its clones can take appropriate action
- SP_OBJECT(l->data)->deleteObject();
+ SP_OBJECT(*l)->deleteObject();
}
}
- g_slist_free(il);
// premultiply by the inverse of parent's repr
SPItem *parent_item = SP_ITEM(doc->getObjectByRepr(parent));
@@ -1159,12 +1157,9 @@ sp_selected_path_outline(SPDesktop *desktop)
}
bool did = false;
-
- for (GSList *items = g_slist_copy((GSList *) selection->itemList());
- items != NULL;
- items = items->next) {
-
- SPItem *item = SP_ITEM(items->data);
+ SelContainer il(selection->itemList());
+ for (SelContainer::const_iterator l = il.begin(); l != il.end(); l++){
+ SPItem *item = SP_ITEM(*l);
if (!SP_IS_SHAPE(item) && !SP_IS_TEXT(item))
continue;
@@ -1774,12 +1769,9 @@ sp_selected_path_do_offset(SPDesktop *desktop, bool expand, double prefOffset)
}
bool did = false;
-
- for (GSList *items = g_slist_copy((GSList *) selection->itemList());
- items != NULL;
- items = items->next) {
-
- SPItem *item = SP_ITEM(items->data);
+ SelContainer il(selection->itemList());
+ for (SelContainer::const_iterator l = il.begin(); l != il.end(); l++){
+ SPItem *item = SP_ITEM(*l);
SPCurve *curve = NULL;
if (!SP_IS_SHAPE(item) && !SP_IS_TEXT(item))
@@ -1975,7 +1967,7 @@ sp_selected_path_do_offset(SPDesktop *desktop, bool expand, double prefOffset)
static bool
sp_selected_path_simplify_items(SPDesktop *desktop,
- Inkscape::Selection *selection, GSList *items,
+ Inkscape::Selection *selection, SelContainer &items,
float threshold, bool justCoalesce,
float angleLimit, bool breakableAngles,
bool modifySelection);
@@ -1994,7 +1986,7 @@ sp_selected_path_simplify_item(SPDesktop *desktop,
//If this is a group, do the children instead
if (SP_IS_GROUP(item)) {
- GSList *items = sp_item_group_item_list(SP_GROUP(item));
+ SelContainer items = sp_item_group_item_list(SP_GROUP(item));
return sp_selected_path_simplify_items(desktop, selection, items,
threshold, justCoalesce,
@@ -2119,7 +2111,7 @@ sp_selected_path_simplify_item(SPDesktop *desktop,
bool
sp_selected_path_simplify_items(SPDesktop *desktop,
- Inkscape::Selection *selection, GSList *items,
+ Inkscape::Selection *selection, SelContainer &items,
float threshold, bool justCoalesce,
float angleLimit, bool breakableAngles,
bool modifySelection)
@@ -2145,13 +2137,13 @@ sp_selected_path_simplify_items(SPDesktop *desktop,
gdouble simplifySize = selectionSize;
int pathsSimplified = 0;
- int totalPathCount = g_slist_length(items);
+ int totalPathCount = items.size();
// set "busy" cursor
desktop->setWaitingCursor();
- for (; items != NULL; items = items->next) {
- SPItem *item = (SPItem *) items->data;
+ for (SelContainer::const_iterator l = items.begin(); l != items.end(); l++){
+ SPItem *item = SP_ITEM(*l);
if (!(SP_IS_GROUP(item) || SP_IS_SHAPE(item) || SP_IS_TEXT(item)))
continue;
@@ -2199,7 +2191,7 @@ sp_selected_path_simplify_selection(SPDesktop *desktop, float threshold, bool ju
return;
}
- GSList *items = g_slist_copy((GSList *) selection->itemList());
+ SelContainer items(selection->itemList());
bool didSomething = sp_selected_path_simplify_items(desktop, selection,
items, threshold,