From: cilix42 Date: Fri, 11 Jan 2008 18:00:46 +0000 (+0000) Subject: Check for perspective in document defs (to avoid hanging/crashes after vacuum defs... X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=aa90355b5205dca29912b439ac9fde6ffa4d8989;p=inkscape.git Check for perspective in document defs (to avoid hanging/crashes after vacuum defs or when opening pre-0.46 documents); partly fixes LP #182031 --- diff --git a/src/box3d-context.cpp b/src/box3d-context.cpp index 78e80be45..68480a00d 100644 --- 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); @@ -214,6 +232,8 @@ static void sp_box3d_context_setup(SPEventContext *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 4b7157609..bb63db52b 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -345,58 +345,11 @@ sp_document_create(Inkscape::XML::Document *rdoc, 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 82160d467..41ef4906b 100644 --- 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 */