Code

revert jasper's way overzealous fix in png-write.cpp rev 13700; new fix in item_rende...
[inkscape.git] / src / box3d-face.cpp
index 02a49b4e40ab5e920eb2334a5d5b163ae71642e7..096e7d7a6bbbd9868bbef2e94c6699f95b1f3178 100644 (file)
@@ -11,8 +11,8 @@
  * Released under GNU GPL, read the file 'COPYING' for more information
  */
 
+#include "svg/svg.h"
 #include "box3d-face.h"
-#include <iostream>
 
 // 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
@@ -64,11 +64,11 @@ void Box3DFace::set_shape(NR::Point const ul, NR::Point const lr,
     } else {
         if (align_along_PL) {
             Box3D::Axis dir3 = Box3D::third_axis_direction (dir1, dir2);
-            Box3D::Line line1(*SP3DBoxContext::current_perspective->get_vanishing_point(dir1), lr);
-            Box3D::Line line2(*pt_align, *SP3DBoxContext::current_perspective->get_vanishing_point(dir3));
+            Box3D::Line line1(*Box3D::Perspective3D::current_perspective->get_vanishing_point(dir1), lr);
+            Box3D::Line line2(*pt_align, *Box3D::Perspective3D::current_perspective->get_vanishing_point(dir3));
             corners[2] = *line1.intersect(line2);
         } else {
-            corners[2] = Box3D::Line(*pt_align, *SP3DBoxContext::current_perspective->get_vanishing_point(dir1)).closest_to(lr);
+            corners[2] = Box3D::Line(*pt_align, *Box3D::Perspective3D::current_perspective->get_vanishing_point(dir1)).closest_to(lr);
         }
     }
 
@@ -121,6 +121,7 @@ Box3DFace::Box3DFace(Box3DFace const &box3dface)
  * 
  * Note that several other functions rely on this precise order.
  */
+/***
 void
 Box3DFace::set_face (NR::Point const A, NR::Point const C, Box3D::Axis const axis1, Box3D::Axis const axis2)
 {
@@ -130,12 +131,12 @@ Box3DFace::set_face (NR::Point const A, NR::Point const C, Box3D::Axis const axi
         return;
     SP3DBoxContext *bc = SP_3DBOX_CONTEXT(inkscape_active_event_context());
     
-    Box3D::PerspectiveLine line1 (A, axis1);
-    Box3D::PerspectiveLine line2 (C, axis2);
+    Box3D::PerspectiveLine line1 (A, axis1, Box3D::Perspective3D::current_perspective);
+    Box3D::PerspectiveLine line2 (C, axis2, Box3D::Perspective3D::current_perspective);
     NR::Maybe<NR::Point> B = line1.intersect(line2);
 
-    Box3D::PerspectiveLine line3 (*corners[0], axis2);
-    Box3D::PerspectiveLine line4 (*corners[2], axis1);
+    Box3D::PerspectiveLine line3 (*corners[0], axis2, Box3D::Perspective3D::current_perspective);
+    Box3D::PerspectiveLine line4 (*corners[2], axis1, Box3D::Perspective3D::current_perspective);
     NR::Maybe<NR::Point> D = line3.intersect(line4);
 
     // FIXME: How to handle the case if one of the intersections doesn't exist?
@@ -149,7 +150,7 @@ Box3DFace::set_face (NR::Point const A, NR::Point const C, Box3D::Axis const axi
     this->dir1 = axis1;
     this->dir2 = axis2;
 }
-
+***/
 
 NR::Point Box3DFace::operator[](unsigned int i)
 {
@@ -191,7 +192,14 @@ void Box3DFace::hook_path_to_3dbox(SPPath * existing_path)
  */
 void Box3DFace::set_path_repr()
 {
-    SP_OBJECT(this->path)->repr->setAttribute("d", svg_repr_string());
+    NR::Matrix const i2d (sp_item_i2d_affine (SP_ITEM (this->parent_box3d)));
+    SPCurve * curve = sp_curve_new();
+    sp_curve_moveto (curve, ((*corners[0]) * i2d)[NR::X], ((*corners[0]) * i2d)[NR::Y]);
+    sp_curve_lineto (curve, ((*corners[1]) * i2d)[NR::X], ((*corners[1]) * i2d)[NR::Y]);
+    sp_curve_lineto (curve, ((*corners[2]) * i2d)[NR::X], ((*corners[2]) * i2d)[NR::Y]);
+    sp_curve_lineto (curve, ((*corners[3]) * i2d)[NR::X], ((*corners[3]) * i2d)[NR::Y]);
+    sp_curve_closepath (curve);
+    SP_OBJECT(this->path)->repr->setAttribute("d", sp_svg_write_path (SP_CURVE_BPATH(curve)));
 }
 
 void Box3DFace::set_curve()
@@ -231,37 +239,6 @@ gchar * Box3DFace::axes_string()
     return pstring->str;
 }
 
-gchar * Box3DFace::svg_repr_string()
-{
-    NR::Matrix const i2d (sp_item_i2d_affine (SP_ITEM (this->parent_box3d)));
-    GString *pstring = g_string_new("");
-    gchar str[G_ASCII_DTOSTR_BUF_SIZE];
-
-    g_string_append_printf (pstring, "M ");
-    g_string_append_printf (pstring, "%s", g_ascii_dtostr (str, sizeof (str), ((*corners[0]) * i2d)[NR::X]));
-    g_string_append_printf (pstring, ",");
-    g_string_append_printf (pstring, "%s", g_ascii_dtostr (str, sizeof (str), ((*corners[0]) * i2d)[NR::Y]));
-
-    g_string_append_printf (pstring, " L ");
-    g_string_append_printf (pstring, "%s", g_ascii_dtostr (str, sizeof (str), ((*corners[1]) * i2d)[NR::X]));
-    g_string_append_printf (pstring, ",");
-    g_string_append_printf (pstring, "%s", g_ascii_dtostr (str, sizeof (str), ((*corners[1]) * i2d)[NR::Y]));
-
-    g_string_append_printf (pstring, " L ");
-    g_string_append_printf (pstring, "%s", g_ascii_dtostr (str, sizeof (str), ((*corners[2]) * i2d)[NR::X]));
-    g_string_append_printf (pstring, ",");
-    g_string_append_printf (pstring, "%s", g_ascii_dtostr (str, sizeof (str), ((*corners[2]) * i2d)[NR::Y]));
-
-    g_string_append_printf (pstring, " L ");
-    g_string_append_printf (pstring, "%s", g_ascii_dtostr (str, sizeof (str), ((*corners[3]) * i2d)[NR::X]));
-    g_string_append_printf (pstring, ",");
-    g_string_append_printf (pstring, "%s", g_ascii_dtostr (str, sizeof (str), ((*corners[3]) * i2d)[NR::Y]));
-
-    g_string_append_printf (pstring, " z");
-
-    return pstring->str;
-}
-
 /*
   Local Variables:
   mode:c++