document.cpp revision a2dc6e9e2b5e48766e3334f0af1fdb018dadaff8
#define __SP_DOCUMENT_C__
/** \file
* SPDocument manipulation
*
* Authors:
* Lauris Kaplinski <lauris@kaplinski.com>
* MenTaLguY <mental@rydia.net>
* bulia byak <buliabyak@users.sf.net>
*
* Copyright (C) 2004-2005 MenTaLguY
* Copyright (C) 1999-2002 Lauris Kaplinski
* Copyright (C) 2000-2001 Ximian, Inc.
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
/** \class SPDocument
* SPDocument serves as the container of both model trees (agnostic XML
* and typed object tree), and implements all of the document-level
* functionality used by the program. Many document level operations, like
* load, save, print, export and so on, use SPDocument as their basic datatype.
*
* SPDocument implements undo and redo stacks and an id-based object
* dictionary. Thanks to unique id attributes, the latter can be used to
* map from the XML tree back to the object tree.
*
* SPDocument performs the basic operations needed for asynchronous
* update notification (SPObject ::modified virtual method), and implements
* the 'modified' signal, as well.
*/
#define noSP_DOCUMENT_DEBUG_IDLE
#define noSP_DOCUMENT_DEBUG_UNDO
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <string>
#include <cstring>
#include "application/application.h"
#include "application/editor.h"
#include "desktop.h"
#include "dir-util.h"
#include "display/nr-arena-item.h"
#include "document-private.h"
#include "inkscape-private.h"
#include "inkscape-version.h"
#include "persp3d.h"
#include "preferences.h"
#include "profile-manager.h"
#include "rdf.h"
#include "sp-item-group.h"
#include "sp-namedview.h"
#include "sp-object-repr.h"
#include "transf_mat_3x4.h"
#include "unit-constants.h"
#include "xml/rebase-hrefs.h"
// Higher number means lower priority.
// Should have a lower priority than SP_DOCUMENT_UPDATE_PRIORITY,
// since we want it to happen when there are no more updates.
static unsigned long next_serial = 0;
SPDocument::SPDocument() :
rdoc(0),
rroot(0),
root(0),
uri(0),
base(0),
name(0),
priv(0), // reset in ctor
actionkey(0),
modified_id(0),
profileManager(0), // deferred until after other initialization
oldSignalsConnected(false),
{
// Penalise libavoid for choosing paths with needless extra segments.
// This results in much better looking orthogonal connector paths.
SPDocumentPrivate *p = new SPDocumentPrivate();
p->serial = next_serial++;
p->history_size = 0;
p->seeking = false;
priv = p;
// Once things are set, hook in the manager
// XXX only for testing!
}
SPDocument::~SPDocument() {
if ( profileManager ) {
delete profileManager;
profileManager = 0;
}
if (router) {
delete router;
}
if (priv) {
}
sp_document_clear_redo(this);
sp_document_clear_undo(this);
if (root) {
}
/* Free resources */
delete priv;
}
if (name) {
}
if (base) {
}
if (uri) {
}
if (modified_id) {
modified_id = 0;
}
if (rerouting_handler_id) {
rerouting_handler_id = 0;
}
if (oldSignalsConnected) {
reinterpret_cast<gpointer>(sp_document_reset_key),
static_cast<gpointer>(this));
} else {
}
if (keepalive) {
}
//delete this->_whiteboard_session_manager;
}
Persp3D *
// Check if current_persp3d is still valid
if (current_persp3d == plist[i])
return current_persp3d;
}
// If not, return the first perspective in defs (which may be NULL of none exists)
current_persp3d = persp3d_document_first_persp (this);
return current_persp3d;
}
return current_persp3d_impl;
}
void
//current_persp3d_impl = persp->perspective_impl;
}
void
if (SP_IS_PERSP3D(i))
}
}
/**
void SPDocument::initialize_current_persp3d()
{
this->current_persp3d = persp3d_document_first_persp(this);
if (!this->current_persp3d) {
this->current_persp3d = persp3d_create_xml_element(this);
}
}
**/
unsigned long SPDocument::serial() const {
}
}
void SPDocument::collectOrphans() {
while (_collection_queue) {
object->collectOrphan();
}
}
}
{
}
unsigned int keepalive)
{
document = new SPDocument();
#ifndef WIN32
#else
// FIXME: it may be that prepend_current_dir_if_relative works OK on windows too, test!
#endif
// base is simply the part of the path before filename; e.g. when running "inkscape ../file.svg" the base is "../"
// which is why we use g_get_current_dir() in calculating the abs path above
//This is NULL for a new document
if (base)
else
/* fixme: Not sure about this, but lets assume ::build updates */
/* fixme: Again, I moved these here to allow version determining in ::build (Lauris) */
/* Quick hack 2 - get default image size into document */
/* End of quick hack 2 */
/* Quick hack 3 - Set uri attributes */
if (uri) {
}
/* End of quick hack 3 */
/* Eliminate obsolete sodipodi:docbase, for privacy reasons */
/* Eliminate any claim to adhere to a profile, as we don't try to */
// creating namedview
// if there's none in the document already,
//rnew->setAttribute("id", "base");
// Add namedview data from the preferences
// we can't use getAllEntries because this could produce non-SVG doubles
}
if (!bordercolor.empty()) {
}
// insert into the document
// clean up
}
/* Defs */
}
/* Default RDF */
if (keepalive) {
inkscape_ref();
}
// Check if the document already has a perspective (e.g., when opening an existing
// document). If not, create a new one and set it as the current perspective.
if (!document->getCurrentPersp3D()) {
//document->setCurrentPersp3D(persp3d_create_xml_element (document));
}
// reset undo key when selection changes, so that same-key actions on different objects are not coalesced
document->oldSignalsConnected = true;
} else {
document->_selection_changed_connection = Inkscape::NSApplication::Editor::connectSelectionChanged (sigc::mem_fun (*document, &SPDocument::reset_key));
document->_desktop_activated_connection = Inkscape::NSApplication::Editor::connectDesktopActivated (sigc::mem_fun (*document, &SPDocument::reset_key));
document->oldSignalsConnected = false;
}
return document;
}
/**
* Fetches document from URI, or creates new, if NULL; public document
* appears in document list.
*/
{
if (uri) {
gchar *s, *p;
/* Try to fetch repr from file */
/* If file cannot be loaded, return NULL without warning */
/* If xml file is not svg, return NULL without warning */
/* fixme: destroy document */
p = strrchr(s, '/');
if (p) {
p[1] = '\0';
} else {
}
g_free(s);
} else {
}
if (make_new) {
}
//# These should be set by now
return doc;
}
{
/* If it cannot be loaded, return NULL without warning */
/* If xml file is not svg, return NULL without warning */
/* fixme: destroy document */
return doc;
}
{
return doc;
}
{
return NULL;
}
{
}
void
{
} else { // set to width=
/* SVG does not support meters as a unit, so we must translate meters to
* cm when writing */
} else {
}
if (root->viewBox_set)
root->viewBox.x1 = root->viewBox.x0 + (root->width.computed / old_computed) * (root->viewBox.x1 - root->viewBox.x0);
}
}
{
} else { // set to height=
/* SVG does not support meters as a unit, so we must translate meters to
* cm when writing */
} else {
}
if (root->viewBox_set)
root->viewBox.y1 = root->viewBox.y0 + (root->height.computed / old_computed) * (root->viewBox.y1 - root->viewBox.y0);
}
}
{
}
{
}
/**
* Given a Geom::Rect that may, for example, correspond to the bbox of an object,
* this function fits the canvas to that rect by resizing the canvas
* and translating the document root into position.
*/
{
double const old_height = sp_document_height(this);
sp_document_set_width(this, w, &px);
sp_document_set_height(this, h, &px);
if(nv) {
// update the viewport so the drawing appears to stay where it was
}
}
static void
{
if (filename) {
#ifndef WIN32
#else
// FIXME: it may be that prepend_current_dir_if_relative works OK on windows too, test!
#endif
} else {
}
// Update saveable repr attributes.
// Changing uri in the document repr must not be not undoable.
sp_document_set_undo_sensitive(document, false);
if (rebase) {
}
}
/**
* Sets base, name and uri members of \a document. Doesn't update
* any relative hrefs in the document: thus, this is primarily for
* newly-created documents.
*
* \see sp_document_change_uri_and_hrefs
*/
{
}
/**
* Changes the base, name and uri members of \a document, and updates any
* relative hrefs in the document to be relative to the new base.
*
* \see sp_document_set_uri
*/
{
}
void
{
}
{
}
{
}
{
}
{
}
void
{
// printf("Starting Reconstruction\n");
return;
}
{
}
void
{
// printf("Finishing Reconstruction\n");
/**
// Reference to the old persp3d object is invalid after reconstruction.
initialize_current_persp3d();
return;
**/
}
{
}
void SPDocument::_emitModified() {
static guint const flags = SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG | SP_OBJECT_PARENT_MODIFIED_FLAG;
root->emitModified(0);
}
if (object) {
} else {
}
} else { // discard unused signal
}
}
}
void
{
}
void
{
}
}
{
}
if (object) {
} else {
}
}
}
if (document_language) {
while (isspace(*document_language))
}
if ( !document_language || 0 == *document_language) {
// retrieve system language
}
}
if ( NULL != document_language ) {
}
}
}
if ( NULL == document_language )
return document_language;
}
/* Object modification root handler */
void
{
if (!doc->modified_id) {
}
if (!doc->rerouting_handler_id) {
}
}
void
{
/* Set up viewport in case svg has it defined as percentages */
} else { // as a last resort, set size to A4
}
}
/**
* Tries to update the document state based on the modified and
* "update required" flags, and return true if the document has
* been brought fully up to date.
*/
bool
{
/* Process updates */
sp_document_setup_viewport (this, &ctx);
bool saved = sp_document_get_undo_sensitive(this);
sp_document_set_undo_sensitive(this, false);
sp_document_set_undo_sensitive(this, saved);
}
this->_emitModified();
}
}
/**
* Repeatedly works on getting the document updated, since sometimes
* it takes more than one pass to get the document updated. But it
* usually should not take more than a few loops, and certainly never
* more than 32 iterations. So we bail out if we hit 32 iterations,
* since this typically indicates we're stuck in an update loop.
*/
{
// Bring the document up-to-date, specifically via the following:
// 1a) Process all document updates.
// 1b) When completed, process connector routing changes.
// 2a) Process any updates resulting from connector reroutings.
int counter = 32;
// Process document updates.
while (!doc->_updateDocument()) {
if (counter == 0) {
break;
}
counter--;
}
if (counter == 0)
{
break;
}
// After updates on the first pass we get libavoid to process all the
// changed objects and provide new routings. This may cause some objects
// to be modified, hence the second update pass.
if (pass == 1) {
}
}
if (doc->modified_id) {
/* Remove handler */
doc->modified_id = 0;
}
if (doc->rerouting_handler_id) {
/* Remove handler */
doc->rerouting_handler_id = 0;
}
return counter>0;
}
/**
* An idle handler to update the document. Returns true if
* the document needs further updates.
*/
static gint
{
if (doc->_updateDocument()) {
doc->modified_id = 0;
return false;
} else {
return true;
}
}
/**
* An idle handler to reroute connectors in the document.
*/
static gint
{
// Process any queued movement actions and determine new routings for
// object-avoiding connectors. Callbacks will be used to update and
// redraw affected connectors.
// We don't need to handle rerouting again until there are further
// diagram updates.
doc->rerouting_handler_id = 0;
return false;
}
{
}
{
}
static GSList *find_items_in_area(GSList *s, SPGroup *group, unsigned int dkey, Geom::Rect const &area,
{
if (!SP_IS_ITEM(o)) {
continue;
}
} else {
s = g_slist_append(s, child);
}
}
}
return s;
}
/**
Returns true if an item is among the descendants of group (recursively).
*/
{
if (!SP_IS_ITEM(o)) continue;
return true;
if (SP_IS_GROUP(o))
return true;
}
return false;
}
/**
Returns the bottommost item from the list which is at the point, or NULL if none.
*/
{
if (!SP_IS_ITEM(o)) continue;
return item;
}
if (SP_IS_GROUP(o)) {
SPItem *found = sp_document_item_from_list_at_point_bottom(dkey, SP_GROUP(o), list, p, take_insensitive);
if (found)
return found;
}
}
return NULL;
}
/**
Returns the topmost (in z-order) item from the descendants of group (recursively) which
is at the point p, or NULL if none. Honors into_groups on whether to recurse into
non-layer groups or not. Honors take_insensitive on whether to return insensitive
items. If upto != NULL, then if item upto is encountered (at any level), stops searching
upwards in z-order and returns what it has found so far (i.e. the found item is
guaranteed to be lower than upto).
*/
find_item_at_point(unsigned int dkey, SPGroup *group, Geom::Point const p, gboolean into_groups, bool take_insensitive = false, SPItem *upto = NULL)
{
if (!SP_IS_ITEM(o)) continue;
break;
// if nothing found yet, recurse into the group
if (newseen) {
}
break;
} else {
// seen remembers the last (topmost) of items pickable at this point
}
}
}
return seen;
}
/**
Returns the topmost non-layer group from the descendants of group which is at point
p, or NULL if none. Recurses into layers but not into groups.
*/
{
if (!SP_IS_ITEM(o)) continue;
if (newseen) {
}
}
// seen remembers the last (topmost) of groups pickable at this point
}
}
}
return seen;
}
/*
* Return list of items, contained in box
*
* Assumes box is normalized (and g_asserts it!)
*
*/
{
}
/*
* Return list of items, that the parts of the item contained in box
*
* Assumes box is normalized (and g_asserts it!)
*
*/
GSList *sp_document_partial_items_in_box(SPDocument *document, unsigned int dkey, Geom::Rect const &box)
{
}
GSList *
sp_document_items_at_points(SPDocument *document, unsigned const key, std::vector<Geom::Point> points)
{
// When picking along the path, we don't want small objects close together
// (such as hatching strokes) to obscure each other by their deltas,
// so we temporarily set delta to a small value
false, NULL);
}
// and now we restore it back
return items;
}
SPItem *
{
}
{
}
/* Resource management */
{
if (SP_OBJECT_IS_CLONED(object))
return FALSE;
return TRUE;
}
{
if (SP_OBJECT_IS_CLONED(object))
return FALSE;
return TRUE;
}
GSList const *
{
}
{
}
/* Helpers */
{
return TRUE;
}
unsigned int
{
count++; // obj itself
}
return count;
}
unsigned int
{
}
void
{
if (SP_IS_DEFS(obj)) {
/* fixme: some inkscape-internal nodes in the future might not be collectable */
}
} else {
}
}
}
unsigned int
{
unsigned int end;
unsigned int iterations = 0;
do {
iterations++;
}
bool SPDocument::isSeeking() const {
}
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :