Code

Changed preference to use file chooser button
[inkscape.git] / src / box3d-face.cpp
index 096e7d7a6bbbd9868bbef2e94c6699f95b1f3178..a1b7ae863c45f6629005f01defada8948d11d493 100644 (file)
@@ -13,6 +13,7 @@
 
 #include "svg/svg.h"
 #include "box3d-face.h"
+#include "prefs-utils.h"
 
 // FIXME: It's quite redundant to pass the box plus the corners plus the axes. At least the corners can
 //        theoretically be reconstructed from the box and the axes, but in order to do this we need
@@ -176,15 +177,45 @@ void Box3DFace::hook_path_to_3dbox(SPPath * existing_path)
         return;
     }
 
-    SPDesktop *desktop = inkscape_active_desktop();
+    /* create new path for face */
     Inkscape::XML::Document *xml_doc = sp_document_repr_doc(SP_OBJECT_DOCUMENT(SP_OBJECT(parent_box3d)));
-    GString *pstring = g_string_new("");
-    g_string_printf (pstring, "tools.shapes.3dbox.%s", axes_string());
 
     Inkscape::XML::Node *repr_face = xml_doc->createElement("svg:path");
-    sp_desktop_apply_style_tool (desktop, repr_face, pstring->str, false);
+    repr_face->setAttribute("inkscape:box3dface", this->axes_string());
     this->path = SP_PATH(SP_OBJECT(parent_box3d)->appendChildRepr(repr_face));
     Inkscape::GC::release(repr_face);
+
+    /* set the correct style */
+    this->set_style (repr_face);
+}
+
+void Box3DFace::set_style(Inkscape::XML::Node *repr_face, bool extruded)
+{
+    if (repr_face == NULL) {
+        repr_face = SP_OBJECT_REPR (this->path);
+    }
+
+    if (!extruded && !strcmp (axes_string (), "XYrear")) {
+        // to avoid "flashing" during the initial dragging process, we make the rear face invisible in this case
+        repr_face->setAttribute("style", "fill:none");
+        return;
+    }
+
+    gchar *descr = g_strconcat ("desktop.", axes_string (), NULL);
+    const gchar * cur_style = prefs_get_string_attribute(descr, "style");
+    g_free (descr);    
+    
+    SPDesktop *desktop = inkscape_active_desktop();
+    bool use_current = prefs_get_int_attribute("tools.shapes.3dbox", "usecurrent", 0);
+    if (use_current && cur_style !=NULL) {
+        /* use last used style */
+        repr_face->setAttribute("style", cur_style);
+    } else {
+        /* use default style */
+        GString *pstring = g_string_new("");
+        g_string_printf (pstring, "tools.shapes.3dbox.%s", axes_string());
+        sp_desktop_apply_style_tool (desktop, repr_face, pstring->str, false);
+    }
 }
 
 /**
@@ -205,7 +236,6 @@ void Box3DFace::set_path_repr()
 void Box3DFace::set_curve()
 {
     if (this->path == NULL) {
-        g_warning("this->path is NULL! \n");
         return;
     }
     NR::Matrix const i2d (sp_item_i2d_affine (SP_ITEM (this->parent_box3d)));
@@ -239,6 +269,19 @@ gchar * Box3DFace::axes_string()
     return pstring->str;
 }
 
+gint Box3DFace::descr_to_id (gchar const *descr)
+{
+    if (!strcmp (descr, "XYrear")) { return 5; }
+    if (!strcmp (descr, "XYfront")) { return 4; }
+    if (!strcmp (descr, "XZbottom")) { return 3; }
+    if (!strcmp (descr, "XZtop")) { return 2; }
+    if (!strcmp (descr, "YZleft")) { return 1; }
+    if (!strcmp (descr, "YZright")) { return 0; }
+
+    g_warning ("Invalid description of 3D box face.\n");
+    return -1;
+}
+
 /*
   Local Variables:
   mode:c++