summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 50eef40)
raw | patch | inline | side by side (parent: 50eef40)
author | cilix42 <cilix42@users.sourceforge.net> | |
Fri, 11 Jan 2008 18:00:46 +0000 (18:00 +0000) | ||
committer | cilix42 <cilix42@users.sourceforge.net> | |
Fri, 11 Jan 2008 18:00:46 +0000 (18:00 +0000) |
src/box3d-context.cpp | patch | blob | history | |
src/document.cpp | patch | blob | history | |
src/persp3d.cpp | patch | blob | history |
diff --git a/src/box3d-context.cpp b/src/box3d-context.cpp
index 78e80be45825f6719b3201d8fc2b399563239197..68480a00d4d3d98de48c4d32ec8836f18f136e68 100644 (file)
--- a/src/box3d-context.cpp
+++ b/src/box3d-context.cpp
@@ -206,6 +206,24 @@ static void sp_box3d_context_selection_changed(Inkscape::Selection *selection, g
}
}
+/* create a default perspective in document defs if none is present
+ (can happen after 'vacuum defs' or when a pre-0.46 file is opened) */
+static void sp_box3d_context_check_for_persp_in_defs(SPDocument *document) {
+ SPDefs *defs = (SPDefs *) SP_DOCUMENT_DEFS(document);
+
+ bool has_persp = false;
+ for (SPObject *child = sp_object_first_child(defs); child != NULL; child = SP_OBJECT_NEXT(child) ) {
+ if (SP_IS_PERSP3D(child)) {
+ has_persp = true;
+ break;
+ }
+ }
+
+ if (!has_persp) {
+ document->current_persp3d = persp3d_create_xml_element (document);
+ }
+}
+
static void sp_box3d_context_setup(SPEventContext *ec)
{
Box3DContext *bc = SP_BOX3D_CONTEXT(ec);
((SPEventContextClass *) parent_class)->setup(ec);
}
+ sp_box3d_context_check_for_persp_in_defs(sp_desktop_document (ec->desktop));
+
SPItem *item = sp_desktop_selection(ec->desktop)->singleItem();
if (item) {
ec->shape_knot_holder = sp_item_knot_holder(item, ec->desktop);
diff --git a/src/document.cpp b/src/document.cpp
index 4b71576096b3ce85f633fa0b7dd76053d980f2c3..bb63db52b31f28557133c94ecc7131ff5c49eb3a 100644 (file)
--- a/src/document.cpp
+++ b/src/document.cpp
inkscape_ref();
}
- /* Create an initial perspective, make it current and append it to the list of existing perspectives */
- /***
- document->current_perspective = new Box3D::Perspective3D (
- // VP in x-direction
- Box3D::VanishingPoint( NR::Point(-50.0, 600.0),
- NR::Point( -1.0, 0.0), Box3D::VP_FINITE),
- // VP in y-direction
- Box3D::VanishingPoint( NR::Point(500.0,1000.0),
- NR::Point( 0.0, 1.0), Box3D::VP_INFINITE),
- // VP in z-direction
- Box3D::VanishingPoint( NR::Point(700.0, 600.0),
- NR::Point(sqrt(3.0),1.0), Box3D::VP_FINITE),
- document);
-
- document->add_perspective (document->current_perspective);
- ***/
-
// Remark: Here, we used to create a "currentpersp3d" element in the document defs.
// But this is probably a bad idea since we need to adapt it for every change of selection, which will
// completely clutter the undo history. Maybe rather save it to prefs on exit and re-read it on startup?
- Proj::Pt2 proj_vp_x = Proj::Pt2 (-50.0, 600.0, 1.0);
- Proj::Pt2 proj_vp_y = Proj::Pt2 ( 0.0,1000.0, 0.0);
- Proj::Pt2 proj_vp_z = Proj::Pt2 (700.0, 600.0, 1.0);
- Proj::Pt2 proj_origin = Proj::Pt2 (300.0, 400.0, 1.0);
-
- document->current_persp3d = (Persp3D *) persp3d_create_xml_element (document);
- Inkscape::XML::Node *repr = SP_OBJECT_REPR(document->current_persp3d);
-
- gchar *str = NULL;
- str = proj_vp_x.coord_string();
- repr->setAttribute("inkscape:vp_x", str);
- g_free (str);
- str = proj_vp_y.coord_string();
- repr->setAttribute("inkscape:vp_y", str);
- g_free (str);
- str = proj_vp_z.coord_string();
- repr->setAttribute("inkscape:vp_z", str);
- g_free (str);
- str = proj_origin.coord_string();
- repr->setAttribute("inkscape:persp3d-origin", str);
- g_free (str);
- Inkscape::GC::release(repr);
-
- /***
- document->current_persp3d = (Persp3D *) sp_object_get_child_by_repr (SP_OBJECT(defs), repr);
- g_assert (document->current_persp3d != NULL);
- persp3d_update_with_point (document->current_persp3d, Proj::X, proj_vp_x);
- persp3d_update_with_point (document->current_persp3d, Proj::Y, proj_vp_y);
- persp3d_update_with_point (document->current_persp3d, Proj::Z, proj_vp_z);
- persp3d_update_with_point (document->current_persp3d, Proj::W, proj_origin);
- ***/
+ document->current_persp3d = persp3d_create_xml_element (document);
sp_document_set_undo_sensitive(document, true);
diff --git a/src/persp3d.cpp b/src/persp3d.cpp
index 82160d46708c7228df710a99491e7aa69f2691ce..41ef4906b57b2b497f84ba526e4ad08e1c6b4260 100644 (file)
--- a/src/persp3d.cpp
+++ b/src/persp3d.cpp
@@ -220,8 +220,29 @@ persp3d_create_xml_element (SPDocument *document, Persp3D *dup) {// if dup is gi
if (dup) {
repr = SP_OBJECT_REPR(dup)->duplicate (xml_doc);
} else {
+ /* if no perspective is given, create a default one */
repr = xml_doc->createElement("inkscape:perspective");
repr->setAttribute("sodipodi:type", "inkscape:persp3d");
+
+ Proj::Pt2 proj_vp_x = Proj::Pt2 (-50.0, 600.0, 1.0);
+ Proj::Pt2 proj_vp_y = Proj::Pt2 ( 0.0,1000.0, 0.0);
+ Proj::Pt2 proj_vp_z = Proj::Pt2 (700.0, 600.0, 1.0);
+ Proj::Pt2 proj_origin = Proj::Pt2 (300.0, 400.0, 1.0);
+
+ gchar *str = NULL;
+ str = proj_vp_x.coord_string();
+ repr->setAttribute("inkscape:vp_x", str);
+ g_free (str);
+ str = proj_vp_y.coord_string();
+ repr->setAttribute("inkscape:vp_y", str);
+ g_free (str);
+ str = proj_vp_z.coord_string();
+ repr->setAttribute("inkscape:vp_z", str);
+ g_free (str);
+ str = proj_origin.coord_string();
+ repr->setAttribute("inkscape:persp3d-origin", str);
+ g_free (str);
+ Inkscape::GC::release(repr);
}
/* Append the new persp3d to defs */