Code

More in XML privatisation with new create3DBox function and other supplements to...
authorAbhishek Sharma Public <spyzerdotabhishek0at-signgmaildotcom>
Sat, 17 Jul 2010 07:18:31 +0000 (12:48 +0530)
committerAbhishek Sharma Public <spyzerdotabhishek0at-signgmaildotcom>
Sat, 17 Jul 2010 07:18:31 +0000 (12:48 +0530)
src/box3d-context.cpp
src/box3d-side.cpp
src/box3d-side.h
src/box3d.cpp
src/box3d.h
src/desktop.cpp
src/desktop.h

index e48f7e17d044e46d571e57b10fb92fc97322c430..99cf28963e9ae2bd9179dd1b36a7bfbb292c3dd0 100644 (file)
@@ -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));
index 9059e97056a1526ef9e48bb23c8dc5527cd2ca8e..d6f1f6b426cca8fa4d6c93d8abf1b95bd3608bbf 100644 (file)
@@ -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.
index 6014ddaae72b4fab2815fa94bedc45a290b030dd..29a4a6b00c0f5b7dc82fdecc62e5c73696c09190 100644 (file)
@@ -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 {
index 1facf2c0c3500841a54972dcde1d68a4a825045d..250c1f5004b132029fa93034087a84070f3a72fc 100644 (file)
@@ -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));
index 182a312e13b9ffdcb989302cfdff2b5bb73358df..e313f428521cdcbbbbb6884f1d13ec875f24465b 100644 (file)
@@ -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 {
index d5e7974ea75a5f86839b796b62ba0e5ba67a7e19..3f9fc7806a0b98a9a97e65f057d3181e27695aa6 100644 (file)
@@ -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.
  */
index 00f6cfdd57c6e4ce9a700ffcb5c17196fc795493..59ba3f957d14ae7d603faca46bedb31d5c2faa23 100644 (file)
@@ -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;