53
55
#include "libavoid/router.h"
54
56
#include "libnr/nr-rect.h"
55
57
#include "sp-item-group.h"
58
#include "profile-manager.h"
57
61
#include "display/nr-arena-item.h"
59
63
#include "dialogs/rdf.h"
65
#include "transf_mat_3x4.h"
61
67
#define A4_WIDTH_STR "210mm"
62
68
#define A4_HEIGHT_STR "297mm"
94
102
// Don't use the Consolidate moves optimisation.
95
103
router->ConsolidateMoves = false;
97
107
p = new SPDocumentPrivate();
109
p->serial = next_serial++;
99
111
p->iddef = g_hash_table_new(g_direct_hash, g_direct_equal);
100
112
p->reprdef = g_hash_table_new(g_direct_hash, g_direct_equal);
183
203
//delete this->_whiteboard_session_manager;
207
void SPDocument::add_persp3d (Persp3D * const persp)
209
SPDefs *defs = SP_ROOT(this->root)->defs;
210
for (SPObject *i = sp_object_first_child(SP_OBJECT(defs)); i != NULL; i = SP_OBJECT_NEXT(i) ) {
211
if (SP_IS_PERSP3D(i)) {
212
g_print ("Encountered a Persp3D in defs\n");
216
g_print ("Adding Persp3D to defs\n");
217
persp3d_create_xml_element (this);
220
void SPDocument::remove_persp3d (Persp3D * const persp)
222
// TODO: Delete the repr, maybe perform a check if any boxes are still linked to the perspective.
224
g_print ("Please implement deletion of perspectives here.\n");
227
unsigned long SPDocument::serial() const {
186
231
void SPDocument::queueForOrphanCollection(SPObject *object) {
262
307
/* Quick hack 3 - Set uri attributes */
264
/* fixme: Think, what this means for images (Lauris) */
265
309
rroot->setAttribute("sodipodi:docname", uri);
267
rroot->setAttribute("sodipodi:docbase", document->base);
269
311
/* End of quick hack 3 */
277
319
// see if there's a template with id="base" in the preferences
279
321
// if there's none, create an empty element
280
rnew = sp_repr_new("sodipodi:namedview");
322
rnew = rdoc->createElement("sodipodi:namedview");
281
323
rnew->setAttribute("id", "base");
283
325
// otherwise, take from preferences
284
rnew = r->duplicate();
326
rnew = r->duplicate(rroot->document());
286
328
// insert into the document
287
329
rroot->addChild(rnew, NULL);
293
335
if (!SP_ROOT(document->root)->defs) {
294
336
Inkscape::XML::Node *r;
295
r = sp_repr_new("svg:defs");
337
r = rdoc->createElement("svg:defs");
296
338
rroot->addChild(r, NULL);
297
339
Inkscape::GC::release(r);
298
340
g_assert(SP_ROOT(document->root)->defs);
350
// Remark: Here, we used to create a "currentpersp3d" element in the document defs.
351
// But this is probably a bad idea since we need to adapt it for every change of selection, which will
352
// completely clutter the undo history. Maybe rather save it to prefs on exit and re-read it on startup?
354
document->current_persp3d = persp3d_create_xml_element (document);
308
356
sp_document_set_undo_sensitive(document, true);
310
358
// reset undo key when selection changes, so that same-key actions on different objects are not coalesced
317
365
document->_selection_changed_connection = Inkscape::NSApplication::Editor::connectSelectionChanged (sigc::mem_fun (*document, &SPDocument::reset_key));
318
366
document->_desktop_activated_connection = Inkscape::NSApplication::Editor::connectDesktopActivated (sigc::mem_fun (*document, &SPDocument::reset_key));
320
inkscape_add_document(document);
341
388
rdoc = sp_repr_read_file(uri, SP_SVG_NS_URI);
342
389
/* If file cannot be loaded, return NULL without warning */
343
390
if (rdoc == NULL) return NULL;
344
rroot = sp_repr_document_root(rdoc);
391
rroot = rdoc->root();
345
392
/* If xml file is not svg, return NULL without warning */
346
393
/* fixme: destroy document */
347
394
if (strcmp(rroot->name(), "svg:svg") != 0) return NULL;
390
437
/* If it cannot be loaded, return NULL without warning */
391
438
if (rdoc == NULL) return NULL;
393
rroot = sp_repr_document_root(rdoc);
440
rroot = rdoc->root();
394
441
/* If xml file is not svg, return NULL without warning */
395
442
/* fixme: destroy document */
396
443
if (strcmp(rroot->name(), "svg:svg") != 0) return NULL;
491
* Given an NRRect that may, for example, correspond to the bbox of an object
532
* Given an NR::Rect that may, for example, correspond to the bbox of an object,
492
533
* this function fits the canvas to that rect by resizing the canvas
493
534
* and translating the document root into position.
495
void SPDocument::fitToRect(NRRect const & rect)
536
void SPDocument::fitToRect(NR::Rect const &rect)
497
g_return_if_fail(!empty(rect));
499
gdouble w = rect.x1 - rect.x0;
500
gdouble h = rect.y1 - rect.y0;
501
gdouble old_height = sp_document_height(this);
502
SPUnit unit = sp_unit_get_by_id(SP_UNIT_PX);
503
sp_document_set_width(this, w, &unit);
504
sp_document_set_height(this, h, &unit);
506
NR::translate tr = NR::translate::translate(-rect.x0,-(rect.y0 + (h - old_height)));
507
static_cast<SPGroup *>(root)->translateChildItems(tr);
538
g_return_if_fail(!rect.isEmpty());
540
using NR::X; using NR::Y;
541
double const w = rect.extent(X);
542
double const h = rect.extent(Y);
544
double const old_height = sp_document_height(this);
545
SPUnit const &px(sp_unit_get_by_id(SP_UNIT_PX));
546
sp_document_set_width(this, w, &px);
547
sp_document_set_height(this, h, &px);
549
NR::translate const tr(NR::Point(0, (old_height - h))
551
SP_GROUP(root)->translateChildItems(tr);
510
554
void sp_document_set_uri(SPDocument *document, gchar const *uri)
548
592
// changing uri in the document repr must not be not undoable
549
593
bool saved = sp_document_get_undo_sensitive(document);
550
594
sp_document_set_undo_sensitive(document, false);
552
repr->setAttribute("sodipodi:docbase", document->base);
554
596
repr->setAttribute("sodipodi:docname", document->name);
555
597
sp_document_set_undo_sensitive(document, saved);
837
879
s = find_items_in_area(s, SP_GROUP(o), dkey, area, test);
839
881
SPItem *child = SP_ITEM(o);
840
NR::Rect box = sp_item_bbox_desktop(child);
841
if (test(area, box) && (take_insensitive || child->isVisibleAndUnlocked(dkey))) {
882
NR::Maybe<NR::Rect> box = sp_item_bbox_desktop(child);
883
if ( box && test(area, *box) && (take_insensitive || child->isVisibleAndUnlocked(dkey))) {
842
884
s = g_slist_append(s, child);
1004
1046
return find_items_in_area(NULL, SP_GROUP(document->root), dkey, box, overlaps);
1050
sp_document_items_at_points(SPDocument *document, unsigned const key, std::vector<NR::Point> points)
1052
GSList *items = NULL;
1054
// When picking along the path, we don't want small objects close together
1055
// (such as hatching strokes) to obscure each other by their deltas,
1056
// so we temporarily set delta to a small value
1057
gdouble saved_delta = prefs_get_double_attribute ("options.cursortolerance", "value", 1.0);
1058
prefs_set_double_attribute ("options.cursortolerance", "value", 0.25);
1060
for(unsigned int i = 0; i < points.size(); i++) {
1061
SPItem *item = sp_document_item_at_point(document, key, points[i],
1063
if (item && !g_slist_find(items, item))
1064
items = g_slist_prepend (items, item);
1067
// and now we restore it back
1068
prefs_set_double_attribute ("options.cursortolerance", "value", saved_delta);
1008
1074
sp_document_item_at_point(SPDocument *document, unsigned const key, NR::Point const p,
1009
1075
gboolean const into_groups, SPItem *upto)
1101
sp_document_resource_list_free(gpointer key, gpointer value, gpointer data)
1167
sp_document_resource_list_free(gpointer /*key*/, gpointer value, gpointer /*data*/)
1103
1169
g_slist_free((GSList *) value);