From ab7e48d728d662fc17b5ce6874688c87cf714d2d Mon Sep 17 00:00:00 2001 From: Abhishek Sharma Public Date: Sat, 17 Jul 2010 12:48:31 +0530 Subject: [PATCH] More in XML privatisation with new create3DBox function and other supplements to efficiently hide information. --- src/box3d-context.cpp | 36 ++++++++++++++++++++---------------- src/box3d-side.cpp | 12 ++++++++++++ src/box3d-side.h | 1 + src/box3d.cpp | 12 ++++++++++++ src/box3d.h | 1 + src/desktop.cpp | 22 ++++++++++++++++++++++ src/desktop.h | 2 ++ 7 files changed, 70 insertions(+), 16 deletions(-) diff --git a/src/box3d-context.cpp b/src/box3d-context.cpp index e48f7e17d..99cf28963 100644 --- a/src/box3d-context.cpp +++ b/src/box3d-context.cpp @@ -588,25 +588,28 @@ static void sp_box3d_drag(Box3DContext &bc, guint /*state*/) //Inkscape::XML::Document *xml_doc = sp_document_repr_doc(SP_EVENT_CONTEXT_DOCUMENT(&bc)); /*To be removed for directly accessing the XML Document*/ - Inkscape::XML::Document *xml_doc = desktop->doc()->rdoc; - Inkscape::XML::Node *repr = xml_doc->createElement("svg:g"); - repr->setAttribute("sodipodi:type", "inkscape:box3d"); - + //Inkscape::XML::Document *xml_doc = desktop->doc()->rdoc; + //Inkscape::XML::Node *repr = xml_doc->createElement("svg:g"); + //repr->setAttribute("sodipodi:type", "inkscape:box3d"); + SPBox3D *box3d = 0; + box3d = SPBox3D::createBox3D((SPItem *)desktop->currentLayer()); /* Set style */ - sp_desktop_apply_style_tool (desktop, repr, "/tools/shapes/3dbox", false); - - bc.item = (SPItem *) desktop->currentLayer()->appendChildRepr(repr); - Inkscape::GC::release(repr); - Inkscape::XML::Node *repr_side; + desktop->applyCurrentOrToolStyle(box3d, "/tools/shapes/3dbox", false); + + bc.item = box3d; + //bc.item = (SPItem *) desktop->currentLayer()->appendChildRepr(repr); + //Inkscape::GC::release(repr); + //Inkscape::XML::Node *repr_side; // TODO: Incorporate this in box3d-side.cpp! for (int i = 0; i < 6; ++i) { - repr_side = xml_doc->createElement("svg:path"); - repr_side->setAttribute("sodipodi:type", "inkscape:box3dside"); - repr->addChild(repr_side, NULL); + //repr_side = xml_doc->createElement("svg:path"); + //repr_side->setAttribute("sodipodi:type", "inkscape:box3dside"); + //repr->addChild(repr_side, NULL); //Box3DSide *side = SP_BOX3D_SIDE(inkscape_active_document()->getObjectByRepr (repr_side)); - Box3DSide *side = SP_BOX3D_SIDE(desktop->doc()->getObjectByRepr(repr_side)); - + //Box3DSide *side = SP_BOX3D_SIDE(desktop->doc()->getObjectByRepr(repr_side)); + Box3DSide *side = Box3DSide::createBox3DSide(box3d); + guint desc = Box3D::int_to_face(i); Box3D::Axis plane = (Box3D::Axis) (desc & 0x7); @@ -635,11 +638,12 @@ static void sp_box3d_drag(Box3DContext &bc, guint /*state*/) // use default style GString *pstring = g_string_new(""); g_string_printf (pstring, "/tools/shapes/3dbox/%s", box3d_side_axes_string(side)); - sp_desktop_apply_style_tool (desktop, side->getRepr(), pstring->str, false); + desktop->applyCurrentOrToolStyle (side, pstring->str, false); } - SP_OBJECT(side)->updateRepr(); // calls box3d_side_write() and updates, e.g., the axes string description + //SP_OBJECT(side)->updateRepr(); // calls box3d_side_write() and updates, e.g., the axes string description + side->updateRepr(); // calls box3d_side_write() and updates, e.g., the axes string description } box3d_set_z_orders(SP_BOX3D(bc.item)); diff --git a/src/box3d-side.cpp b/src/box3d-side.cpp index 9059e9705..d6f1f6b42 100644 --- a/src/box3d-side.cpp +++ b/src/box3d-side.cpp @@ -185,6 +185,18 @@ box3d_side_update (SPObject *object, SPCtx *ctx, guint flags) if (((SPObjectClass *) parent_class)->update) ((SPObjectClass *) parent_class)->update (object, ctx, flags); } + +/* Create a new Box3DSide and append it to the parent box */ +Box3DSide * Box3DSide::createBox3DSide(SPBox3D *box) +{ + Box3DSide *box3d_side = 0; + Inkscape::XML::Document *xml_doc = box->document->rdoc; + Inkscape::XML::Node *repr_side = xml_doc->createElement("svg:path"); + repr_side->setAttribute("sodipodi:type", "inkscape:box3dside"); + box3d_side = (Box3DSide *)box->appendChildRepr(repr_side); + return box3d_side; +} + /* * Function which return the type attribute for Box3D. * Acts as a replacement for directly accessing the XML Tree directly. diff --git a/src/box3d-side.h b/src/box3d-side.h index 6014ddaae..29a4a6b00 100644 --- a/src/box3d-side.h +++ b/src/box3d-side.h @@ -32,6 +32,7 @@ struct Box3DSide : public SPPolygon { Box3D::Axis dir2; Box3D::FrontOrRear front_or_rear; long long int getFaceId(); + static Box3DSide * createBox3DSide(SPBox3D *box); }; struct Box3DSideClass { 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)); diff --git a/src/box3d.h b/src/box3d.h index 182a312e1..e313f4285 100644 --- a/src/box3d.h +++ b/src/box3d.h @@ -45,6 +45,7 @@ class SPBox3D : public SPGroup { Box3D::Axis swapped; // to indicate which coordinates are swapped during dragging gint my_counter; // for debugging only + static SPBox3D * createBox3D(SPItem * parent); }; class SPBox3DClass { diff --git a/src/desktop.cpp b/src/desktop.cpp index d5e7974ea..3f9fc7806 100644 --- a/src/desktop.cpp +++ b/src/desktop.cpp @@ -90,6 +90,7 @@ #include "display/canvas-grid.h" #include "widgets/desktop-widget.h" #include "box3d-context.h" +#include "desktop-style.h" // TODO those includes are only for node tool quick zoom. Remove them after fixing it. #include "ui/tool/node-tool.h" @@ -960,6 +961,27 @@ SPDesktop::zoom_absolute_keep_point (double cx, double cy, double px, double py, 0.0); } +/** + * Apply the desktop's current style or the tool style to the object. + */ +void SPDesktop::applyCurrentOrToolStyle(SPObject *obj, Glib::ustring const &tool_path, bool with_text) +{ + SPCSSAttr *css_current = sp_desktop_get_style(this, with_text); + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + + if (prefs->getBool(tool_path + "/usecurrent") && css_current) { + sp_repr_css_set(obj->getRepr(), css_current, "style"); + } else { + SPCSSAttr *css = prefs->getInheritedStyle(tool_path + "/style"); + sp_repr_css_set(obj->getRepr(), css, "style"); + sp_repr_css_attr_unref(css); + } + if (css_current) { + sp_repr_css_attr_unref(css_current); + } + +} + /** * Zoom to center with absolute zoom factor. */ diff --git a/src/desktop.h b/src/desktop.h index 00f6cfdd5..59ba3f957 100644 --- a/src/desktop.h +++ b/src/desktop.h @@ -324,6 +324,8 @@ struct SPDesktop : public Inkscape::UI::View::View virtual bool onDeleteUI (GdkEventAny*); virtual bool onWindowStateEvent (GdkEventWindowState* event); + void applyCurrentOrToolStyle(SPObject *obj, Glib::ustring const &tool_path, bool with_text); + private: Inkscape::UI::View::EditWidgetInterface *_widget; Inkscape::Application *_inkscape; -- 2.30.2