From 8867de5daf309e4cdd3fce177b408618490be4f3 Mon Sep 17 00:00:00 2001 From: Abhishek Sharma Public Date: Tue, 29 Jun 2010 23:35:42 +0530 Subject: This is the first c++ification commit from me. It handles sp-line, sp-polyline, sp-item and marks the onset of document c++ification as well. Users can check performace increase with [/usr/bin/time -v inkscape_binary_with_commandline_options]. (bzr r9546.1.1) --- src/box3d.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/box3d.cpp') diff --git a/src/box3d.cpp b/src/box3d.cpp index aa2dc55e3..bdbbbfa7e 100644 --- a/src/box3d.cpp +++ b/src/box3d.cpp @@ -355,16 +355,16 @@ box3d_set_transform(SPItem *item, Geom::Matrix const &xform) SPItem *childitem = SP_ITEM(child); // Adjust stroke width - sp_item_adjust_stroke(childitem, sqrt(fabs(sw * sh))); + childitem->adjust_stroke(sqrt(fabs(sw * sh))); // Adjust pattern fill - sp_item_adjust_pattern(childitem, xform); + childitem->adjust_pattern(xform); // Adjust gradient fill - sp_item_adjust_gradient(childitem, xform); + childitem->adjust_gradient(xform); // Adjust LPE - sp_item_adjust_livepatheffect(childitem, xform); + childitem->adjust_livepatheffect(xform); } } @@ -393,7 +393,7 @@ box3d_get_corner_screen (SPBox3D const *box, guint id, bool item_coords) { if (!box3d_get_perspective(box)) { return Geom::Point (NR_HUGE, NR_HUGE); } - Geom::Matrix const i2d (sp_item_i2d_affine (SP_ITEM(box))); + Geom::Matrix const i2d (SP_ITEM(box)->i2d_affine ()); if (item_coords) { return box3d_get_perspective(box)->perspective_impl->tmat.image(proj_corner).affine() * i2d.inverse(); } else { @@ -417,7 +417,7 @@ box3d_get_center_screen (SPBox3D *box) { if (!box3d_get_perspective(box)) { return Geom::Point (NR_HUGE, NR_HUGE); } - Geom::Matrix const i2d (sp_item_i2d_affine (SP_ITEM(box))); + Geom::Matrix const i2d (SP_ITEM(box)->i2d_affine ()); return box3d_get_perspective(box)->perspective_impl->tmat.image(proj_center).affine() * i2d.inverse(); } @@ -1392,7 +1392,7 @@ box3d_convert_to_guides(SPItem *item) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); if (!prefs->getBool("/tools/shapes/3dbox/convertguides", true)) { - sp_item_convert_to_guides(SP_ITEM(box)); + SP_ITEM(box)->convert_to_guides(); return; } -- cgit v1.2.3 From 1aad26aea24f62b63c992118f36b12483f9a5414 Mon Sep 17 00:00:00 2001 From: Abhishek Sharma Public Date: Sat, 3 Jul 2010 22:50:36 +0530 Subject: another c++ification for sp-object.h/cpp and still in progress... (bzr r9546.1.4) --- src/box3d.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/box3d.cpp') diff --git a/src/box3d.cpp b/src/box3d.cpp index bdbbbfa7e..7985640cd 100644 --- a/src/box3d.cpp +++ b/src/box3d.cpp @@ -332,7 +332,7 @@ box3d_position_set (SPBox3D *box) { /* This draws the curve and calls requestDisplayUpdate() for each side (the latter is done in box3d_side_position_set() to avoid update conflicts with the parent box) */ - for (SPObject *child = sp_object_first_child(SP_OBJECT (box)); child != NULL; child = SP_OBJECT_NEXT(child) ) { + for (SPObject *child = SP_OBJECT (box)->first_child(); child != NULL; child = SP_OBJECT_NEXT(child) ) { if (SP_IS_BOX3D_SIDE(child)) box3d_side_position_set(SP_BOX3D_SIDE(child)); } @@ -350,7 +350,7 @@ box3d_set_transform(SPItem *item, Geom::Matrix const &xform) gdouble const sw = hypot(ret[0], ret[1]); gdouble const sh = hypot(ret[2], ret[3]); - for (SPObject *child = sp_object_first_child(box); child != NULL; child = SP_OBJECT_NEXT(child)) { + for (SPObject *child = box->first_child(); child != NULL; child = SP_OBJECT_NEXT(child)) { if (SP_IS_ITEM(child)) { SPItem *childitem = SP_ITEM(child); @@ -1151,7 +1151,7 @@ box3d_recompute_z_orders (SPBox3D *box) { static std::map box3d_get_sides (SPBox3D *box) { std::map sides; - for (SPObject *side = sp_object_first_child(box); side != NULL; side = SP_OBJECT_NEXT(side)) { + for (SPObject *side = box->first_child(); side != NULL; side = SP_OBJECT_NEXT(side)) { if (SP_IS_BOX3D_SIDE(side)) sides[Box3D::face_to_int(sp_repr_get_int_attribute(SP_OBJECT_REPR(side), "inkscape:box3dsidetype", -1))] = SP_BOX3D_SIDE(side); @@ -1293,7 +1293,7 @@ box3d_extract_boxes_rec(SPObject *obj, std::list &boxes) { if (SP_IS_BOX3D(obj)) { boxes.push_back(SP_BOX3D(obj)); } else if (SP_IS_GROUP(obj)) { - for (SPObject *child = sp_object_first_child(obj); child != NULL; child = SP_OBJECT_NEXT(child) ) { + for (SPObject *child = obj->first_child(); child != NULL; child = SP_OBJECT_NEXT(child) ) { box3d_extract_boxes_rec(child, boxes); } } @@ -1354,7 +1354,7 @@ box3d_convert_to_group(SPBox3D *box) { Inkscape::XML::Node *grepr = xml_doc->createElement("svg:g"); Inkscape::XML::Node *repr; - for (SPObject *child = sp_object_first_child(SP_OBJECT(box)); child != NULL; child = SP_OBJECT_NEXT(child) ) { + for (SPObject *child = SP_OBJECT(box)->first_child(); child != NULL; child = SP_OBJECT_NEXT(child) ) { if (SP_IS_BOX3D_SIDE(child)) { repr = box3d_side_convert_to_path(SP_BOX3D_SIDE(child)); grepr->appendChild(repr); -- cgit v1.2.3 From 6cc35b45eab6422a6b6f67d621aa259a0a73786f Mon Sep 17 00:00:00 2001 From: Abhishek Sharma Public Date: Mon, 12 Jul 2010 22:06:46 +0530 Subject: SPObject c++ification finalized along with the beginning of XML Privatisation tweaks (bzr r9546.1.6) --- src/box3d.cpp | 51 +++++++++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 22 deletions(-) (limited to 'src/box3d.cpp') diff --git a/src/box3d.cpp b/src/box3d.cpp index 7985640cd..1facf2c0c 100644 --- a/src/box3d.cpp +++ b/src/box3d.cpp @@ -132,9 +132,9 @@ box3d_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) box->persp_ref->changedSignal().connect(sigc::bind(sigc::ptr_fun(box3d_ref_changed), box)); - sp_object_read_attr(object, "inkscape:perspectiveID"); - sp_object_read_attr(object, "inkscape:corner0"); - sp_object_read_attr(object, "inkscape:corner7"); + object->readAttr( "inkscape:perspectiveID"); + object->readAttr( "inkscape:corner0"); + object->readAttr( "inkscape:corner7"); } /** @@ -268,7 +268,7 @@ box3d_update(SPObject *object, SPCtx *ctx, guint flags) } -static Inkscape::XML::Node *box3d_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) +static Inkscape::XML::Node * box3d_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { SPBox3D *box = SP_BOX3D(object); @@ -290,11 +290,13 @@ static Inkscape::XML::Node *box3d_write(SPObject *object, Inkscape::XML::Documen repr->setAttribute("inkscape:perspectiveID", uri_string); g_free(uri_string); } else { - Inkscape::XML::Node *persp_repr = SP_OBJECT_REPR(doc->getCurrentPersp3D()); - const gchar *persp_id = persp_repr->attribute("id"); - gchar *href = g_strdup_printf("#%s", persp_id); - repr->setAttribute("inkscape:perspectiveID", href); - g_free(href); + //Inkscape::XML::Node *persp_repr = SP_OBJECT_REPR(doc->getCurrentPersp3D()); + //const gchar *persp_id = persp_repr->attribute("id"); + //gchar *href = g_strdup_printf("#%s", persp_id); + Glib::ustring href = "#"; + href += doc->getCurrentPersp3D()->getId(); + repr->setAttribute("inkscape:perspectiveID", href.c_str()); + //g_free(href); } } @@ -1152,9 +1154,11 @@ static std::map box3d_get_sides (SPBox3D *box) { std::map sides; for (SPObject *side = box->first_child(); side != NULL; side = SP_OBJECT_NEXT(side)) { - if (SP_IS_BOX3D_SIDE(side)) - sides[Box3D::face_to_int(sp_repr_get_int_attribute(SP_OBJECT_REPR(side), - "inkscape:box3dsidetype", -1))] = SP_BOX3D_SIDE(side); + + if (SP_IS_BOX3D_SIDE(side)){ + Box3DSide *bside = SP_BOX3D_SIDE(side); + sides[Box3D::face_to_int(bside->getFaceId())] = bside; + } } sides.erase(-1); return sides; @@ -1328,9 +1332,12 @@ box3d_switch_perspectives(SPBox3D *box, Persp3D *old_persp, Persp3D *new_persp, persp3d_remove_box (old_persp, box); persp3d_add_box (new_persp, box); - gchar *href = g_strdup_printf("#%s", SP_OBJECT_REPR(new_persp)->attribute("id")); - SP_OBJECT_REPR(box)->setAttribute("inkscape:perspectiveID", href); - g_free(href); + //gchar *href = g_strdup_printf("#%s", SP_OBJECT_REPR(new_persp)->attribute("id")); + Glib::ustring href = "#"; + href += new_persp->getId(); + //SP_OBJECT_REPR(box)->setAttribute("inkscape:perspectiveID", href.c_str()); + static_cast(box)->setAttribute("inkscape:perspectiveID", href.c_str()); + //g_free(href); } /* Converts the 3D box to an ordinary SPGroup, adds it to the XML tree at the same position as @@ -1341,14 +1348,14 @@ box3d_convert_to_group(SPBox3D *box) { Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc); // remember position of the box - int pos = SP_OBJECT_REPR(box)->position(); + int pos = static_cast(box)->getPosition(); // remember important attributes - Inkscape::XML::Node *repr_source = SP_OBJECT_REPR(box); - gchar const *id = repr_source->attribute("id"); - gchar const *style = repr_source->attribute("style"); - gchar const *mask = repr_source->attribute("mask"); - gchar const *clip_path = repr_source->attribute("clip-path"); + //Inkscape::XML::Node *repr_source = SP_OBJECT_REPR(box); + gchar const *id = static_cast(box)->getAttribute("id"); + gchar const *style = static_cast(box)->getAttribute("style"); + gchar const *mask = static_cast(box)->getAttribute("mask"); + gchar const *clip_path = static_cast(box)->getAttribute("clip-path"); // create a new group and add the sides (converted to ordinary paths) as its children Inkscape::XML::Node *grepr = xml_doc->createElement("svg:g"); @@ -1365,7 +1372,7 @@ box3d_convert_to_group(SPBox3D *box) { // add the new group to the box's parent and set remembered position SPObject *parent = SP_OBJECT_PARENT(box); - SP_OBJECT_REPR(parent)->appendChild(grepr); + parent->appendChild(grepr); grepr->setPosition(pos); grepr->setAttribute("style", style); if (mask) -- cgit v1.2.3 From 150ac8ed3274e060e3349b5c0901ec8c7c7e3d4e Mon Sep 17 00:00:00 2001 From: Abhishek Sharma Public Date: Sat, 17 Jul 2010 12:48:31 +0530 Subject: More in XML privatisation with new create3DBox function and other supplements to efficiently hide information. (bzr r9546.1.8) --- src/box3d.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/box3d.cpp') diff --git a/src/box3d.cpp b/src/box3d.cpp index 1facf2c0c..250c1f500 100644 --- a/src/box3d.cpp +++ b/src/box3d.cpp @@ -511,6 +511,18 @@ box3d_snap (SPBox3D *box, int id, Proj::Pt3 const &pt_proj, Proj::Pt3 const &sta return box3d_get_perspective(box)->perspective_impl->tmat.preimage (result, z_coord, Proj::Z); } +/*create a SPBox3D and append it to the parent*/ + +SPBox3D * SPBox3D::createBox3D(SPItem * parent) +{ + SPBox3D *box3d = 0; + Inkscape::XML::Document *xml_doc = parent->document->rdoc; + Inkscape::XML::Node *repr = xml_doc->createElement("svg:g"); + repr->setAttribute("sodipodi:type", "inkscape:box3d"); + box3d = (SPBox3D *)parent->appendChildRepr(repr); + return box3d; +} + void box3d_set_corner (SPBox3D *box, const guint id, Geom::Point const &new_pos, const Box3D::Axis movement, bool constrained) { g_return_if_fail ((movement != Box3D::NONE) && (movement != Box3D::XYZ)); -- cgit v1.2.3