1 #define __PERSP3D_C__
3 /*
4 * Class modelling a 3D perspective as an SPObject
5 *
6 * Authors:
7 * Maximilian Albert <Anhalter42@gmx.de>
8 *
9 * Copyright (C) 2007 authors
10 *
11 * Released under GNU GPL, read the file 'COPYING' for more information
12 */
14 #include "persp3d.h"
15 #include "perspective-line.h"
16 #include "attributes.h"
17 #include "document-private.h"
18 #include "vanishing-point.h"
19 #include "box3d-context.h"
20 #include "box3d.h"
21 #include "xml/document.h"
22 #include "xml/node-event-vector.h"
23 #include "desktop-handles.h"
24 #include <glibmm/i18n.h>
26 static void persp3d_class_init(Persp3DClass *klass);
27 static void persp3d_init(Persp3D *stop);
29 static void persp3d_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr);
30 static void persp3d_release(SPObject *object);
31 static void persp3d_set(SPObject *object, unsigned key, gchar const *value);
32 static void persp3d_update(SPObject *object, SPCtx *ctx, guint flags);
33 static Inkscape::XML::Node *persp3d_write(SPObject *object, Inkscape::XML::Node *repr, guint flags);
35 static void persp3d_on_repr_attr_changed (Inkscape::XML::Node * repr, const gchar *key, const gchar *oldval, const gchar *newval, bool is_interactive, void * data);
37 static SPObjectClass *persp3d_parent_class;
39 static int global_counter = 0;
41 /**
42 * Registers Persp3d class and returns its type.
43 */
44 GType
45 persp3d_get_type()
46 {
47 static GType type = 0;
48 if (!type) {
49 GTypeInfo info = {
50 sizeof(Persp3DClass),
51 NULL, NULL,
52 (GClassInitFunc) persp3d_class_init,
53 NULL, NULL,
54 sizeof(Persp3D),
55 16,
56 (GInstanceInitFunc) persp3d_init,
57 NULL, /* value_table */
58 };
59 type = g_type_register_static(SP_TYPE_OBJECT, "Persp3D", &info, (GTypeFlags)0);
60 }
61 return type;
62 }
64 static Inkscape::XML::NodeEventVector const persp3d_repr_events = {
65 NULL, /* child_added */
66 NULL, /* child_removed */
67 persp3d_on_repr_attr_changed,
68 NULL, /* content_changed */
69 NULL /* order_changed */
70 };
72 /**
73 * Callback to initialize Persp3D vtable.
74 */
75 static void persp3d_class_init(Persp3DClass *klass)
76 {
77 SPObjectClass *sp_object_class = (SPObjectClass *) klass;
79 persp3d_parent_class = (SPObjectClass *) g_type_class_ref(SP_TYPE_OBJECT);
81 sp_object_class->build = persp3d_build;
82 sp_object_class->release = persp3d_release;
83 sp_object_class->set = persp3d_set;
84 sp_object_class->update = persp3d_update;
85 sp_object_class->write = persp3d_write;
86 }
88 /**
89 * Callback to initialize Persp3D object.
90 */
91 static void
92 persp3d_init(Persp3D *persp)
93 {
94 persp->tmat = Proj::TransfMat3x4 ();
96 persp->boxes_transformed.clear();
97 persp->document = NULL;
99 persp->my_counter = global_counter++;
100 }
102 /**
103 * Virtual build: set persp3d attributes from its associated XML node.
104 */
105 static void persp3d_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr)
106 {
107 if (((SPObjectClass *) persp3d_parent_class)->build)
108 (* ((SPObjectClass *) persp3d_parent_class)->build)(object, document, repr);
110 /* calls sp_object_set for the respective attributes */
111 // The transformation matrix is updated according to the values we read for the VPs
112 sp_object_read_attr(object, "inkscape:vp_x");
113 sp_object_read_attr(object, "inkscape:vp_y");
114 sp_object_read_attr(object, "inkscape:vp_z");
115 sp_object_read_attr(object, "inkscape:persp3d-origin");
117 if (repr) {
118 repr->addListener (&persp3d_repr_events, object);
119 }
120 }
122 /**
123 * Virtual release of Persp3D members before destruction.
124 */
125 static void persp3d_release(SPObject *object) {
126 SP_OBJECT_REPR(object)->removeListenerByData(object);
127 }
130 /**
131 * Virtual set: set attribute to value.
132 */
133 // FIXME: Currently we only read the finite positions of vanishing points;
134 // should we move VPs into their own repr (as it's done for SPStop, e.g.)?
135 static void
136 persp3d_set(SPObject *object, unsigned key, gchar const *value)
137 {
138 Persp3D *persp = SP_PERSP3D (object);
140 switch (key) {
141 case SP_ATTR_INKSCAPE_PERSP3D_VP_X: {
142 if (value) {
143 Proj::Pt2 new_image (value);
144 persp3d_update_with_point (persp, Proj::X, new_image);
145 }
146 break;
147 }
148 case SP_ATTR_INKSCAPE_PERSP3D_VP_Y: {
149 if (value) {
150 Proj::Pt2 new_image (value);
151 persp3d_update_with_point (persp, Proj::Y, new_image);
152 break;
153 }
154 }
155 case SP_ATTR_INKSCAPE_PERSP3D_VP_Z: {
156 if (value) {
157 Proj::Pt2 new_image (value);
158 persp3d_update_with_point (persp, Proj::Z, new_image);
159 break;
160 }
161 }
162 case SP_ATTR_INKSCAPE_PERSP3D_ORIGIN: {
163 if (value) {
164 Proj::Pt2 new_image (value);
165 persp3d_update_with_point (persp, Proj::W, new_image);
166 break;
167 }
168 }
169 default: {
170 if (((SPObjectClass *) persp3d_parent_class)->set)
171 (* ((SPObjectClass *) persp3d_parent_class)->set)(object, key, value);
172 break;
173 }
174 }
176 // FIXME: Is this the right place for resetting the draggers?
177 SPEventContext *ec = inkscape_active_event_context();
178 if (SP_IS_BOX3D_CONTEXT(ec)) {
179 Box3DContext *bc = SP_BOX3D_CONTEXT(ec);
180 bc->_vpdrag->updateDraggers();
181 bc->_vpdrag->updateLines();
182 bc->_vpdrag->updateBoxHandles();
183 bc->_vpdrag->updateBoxReprs();
184 }
185 }
187 static void
188 persp3d_update(SPObject *object, SPCtx *ctx, guint flags)
189 {
190 if (flags & SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG) {
192 /* TODO: Should we update anything here? */
194 }
196 if (((SPObjectClass *) persp3d_parent_class)->update)
197 ((SPObjectClass *) persp3d_parent_class)->update(object, ctx, flags);
198 }
200 Persp3D *
201 persp3d_create_xml_element (SPDocument *document, Persp3D *dup) {// if dup is given, copy the attributes over
202 SPDefs *defs = (SPDefs *) SP_DOCUMENT_DEFS(document);
203 Inkscape::XML::Document *xml_doc = sp_document_repr_doc(document);
204 Inkscape::XML::Node *repr;
205 if (dup) {
206 repr = SP_OBJECT_REPR(dup)->duplicate (xml_doc);
207 } else {
208 /* if no perspective is given, create a default one */
209 repr = xml_doc->createElement("inkscape:perspective");
210 repr->setAttribute("sodipodi:type", "inkscape:persp3d");
212 Proj::Pt2 proj_vp_x = Proj::Pt2 (0.0, sp_document_height(document)/2, 1.0);
213 Proj::Pt2 proj_vp_y = Proj::Pt2 ( 0.0,1000.0, 0.0);
214 Proj::Pt2 proj_vp_z = Proj::Pt2 (sp_document_width(document), sp_document_height(document)/2, 1.0);
215 Proj::Pt2 proj_origin = Proj::Pt2 (sp_document_width(document)/2, sp_document_height(document)/3, 1.0);
217 gchar *str = NULL;
218 str = proj_vp_x.coord_string();
219 repr->setAttribute("inkscape:vp_x", str);
220 g_free (str);
221 str = proj_vp_y.coord_string();
222 repr->setAttribute("inkscape:vp_y", str);
223 g_free (str);
224 str = proj_vp_z.coord_string();
225 repr->setAttribute("inkscape:vp_z", str);
226 g_free (str);
227 str = proj_origin.coord_string();
228 repr->setAttribute("inkscape:persp3d-origin", str);
229 g_free (str);
230 Inkscape::GC::release(repr);
231 }
233 /* Append the new persp3d to defs */
234 SP_OBJECT_REPR(defs)->addChild(repr, NULL);
235 Inkscape::GC::release(repr);
237 return (Persp3D *) sp_object_get_child_by_repr (SP_OBJECT(defs), repr);
238 }
240 Persp3D *
241 persp3d_document_first_persp (SPDocument *document) {
242 SPDefs *defs = (SPDefs *) SP_DOCUMENT_DEFS(document);
243 Inkscape::XML::Node *repr;
244 for (SPObject *child = sp_object_first_child(defs); child != NULL; child = SP_OBJECT_NEXT(child) ) {
245 repr = SP_OBJECT_REPR(child);
246 if (SP_IS_PERSP3D(child)) {
247 return SP_PERSP3D(child);
248 }
249 }
250 return NULL;
251 }
253 /**
254 * Virtual write: write object attributes to repr.
255 */
256 static Inkscape::XML::Node *
257 persp3d_write(SPObject *object, Inkscape::XML::Node *repr, guint flags)
258 {
259 Persp3D *persp = SP_PERSP3D(object);
261 if ((flags & SP_OBJECT_WRITE_BUILD & SP_OBJECT_WRITE_EXT) && !repr) {
262 // this is where we end up when saving as plain SVG (also in other circumstances?);
263 // hence we don't set the sodipodi:type attribute
264 Inkscape::XML::Document *xml_doc = sp_document_repr_doc(SP_OBJECT_DOCUMENT(object));
265 repr = xml_doc->createElement("inkscape:perspective");
266 }
268 if (flags & SP_OBJECT_WRITE_EXT) {
269 gchar *str = NULL; // FIXME: Should this be freed each time we set an attribute or only in the end or at all?
270 str = persp3d_pt_to_str (persp, Proj::X);
271 repr->setAttribute("inkscape:vp_x", str);
273 str = persp3d_pt_to_str (persp, Proj::Y);
274 repr->setAttribute("inkscape:vp_y", str);
276 str = persp3d_pt_to_str (persp, Proj::Z);
277 repr->setAttribute("inkscape:vp_z", str);
279 str = persp3d_pt_to_str (persp, Proj::W);
280 repr->setAttribute("inkscape:persp3d-origin", str);
281 }
283 if (((SPObjectClass *) persp3d_parent_class)->write)
284 (* ((SPObjectClass *) persp3d_parent_class)->write)(object, repr, flags);
286 return repr;
287 }
289 /* convenience wrapper around persp3d_get_finite_dir() and persp3d_get_infinite_dir() */
290 NR::Point persp3d_get_PL_dir_from_pt (Persp3D *persp, NR::Point const &pt, Proj::Axis axis) {
291 if (persp3d_VP_is_finite(persp, axis)) {
292 return persp3d_get_finite_dir(persp, pt, axis);
293 } else {
294 return persp3d_get_infinite_dir(persp, axis);
295 }
296 }
298 NR::Point
299 persp3d_get_finite_dir (Persp3D *persp, NR::Point const &pt, Proj::Axis axis) {
300 Box3D::PerspectiveLine pl(pt, axis, persp);
301 return pl.direction();
302 }
304 NR::Point
305 persp3d_get_infinite_dir (Persp3D *persp, Proj::Axis axis) {
306 Proj::Pt2 vp(persp3d_get_VP(persp, axis));
307 if (vp[2] != 0.0) {
308 g_print ("VP should be infinite but is (%f : %f : %f)\n", vp[0], vp[1], vp[2]);
309 g_return_val_if_fail(vp[2] != 0.0, NR::Point(0.0, 0.0));
310 }
311 return NR::Point(vp[0], vp[1]);
312 }
314 double
315 persp3d_get_infinite_angle (Persp3D *persp, Proj::Axis axis) {
316 return persp->tmat.get_infinite_angle(axis);
317 }
319 bool
320 persp3d_VP_is_finite (Persp3D *persp, Proj::Axis axis) {
321 return persp->tmat.has_finite_image(axis);
322 }
324 void
325 persp3d_toggle_VP (Persp3D *persp, Proj::Axis axis, bool set_undo) {
326 persp->tmat.toggle_finite(axis);
327 // FIXME: Remove this repr update and rely on vp_drag_sel_modified() to do this for us
328 // On the other hand, vp_drag_sel_modified() would update all boxes;
329 // here we can confine ourselves to the boxes of this particular perspective.
330 persp3d_update_box_reprs (persp);
331 SP_OBJECT(persp)->updateRepr(SP_OBJECT_WRITE_EXT);
332 if (set_undo) {
333 sp_document_done(sp_desktop_document(inkscape_active_desktop()), SP_VERB_CONTEXT_3DBOX,
334 _("Toggle vanishing point"));
335 }
336 }
338 /* toggle VPs for the same axis in all perspectives of a given list */
339 void
340 persp3d_toggle_VPs (std::set<Persp3D *> p, Proj::Axis axis) {
341 for (std::set<Persp3D *>::iterator i = p.begin(); i != p.end(); ++i) {
342 persp3d_toggle_VP((*i), axis, false);
343 }
344 sp_document_done(sp_desktop_document(inkscape_active_desktop()), SP_VERB_CONTEXT_3DBOX,
345 _("Toggle multiple vanishing points"));
346 }
348 void
349 persp3d_set_VP_state (Persp3D *persp, Proj::Axis axis, Proj::VPState state) {
350 if (persp3d_VP_is_finite(persp, axis) != (state == Proj::VP_FINITE)) {
351 persp3d_toggle_VP(persp, axis);
352 }
353 }
355 void
356 persp3d_rotate_VP (Persp3D *persp, Proj::Axis axis, double angle, bool alt_pressed) { // angle is in degrees
357 // FIXME: Most of this functionality should be moved to trans_mat_3x4.(h|cpp)
358 if (persp->tmat.has_finite_image(axis)) {
359 // don't rotate anything for finite VPs
360 return;
361 }
362 Proj::Pt2 v_dir_proj (persp->tmat.column(axis));
363 NR::Point v_dir (v_dir_proj[0], v_dir_proj[1]);
364 double a = NR::atan2 (v_dir) * 180/M_PI;
365 a += alt_pressed ? 0.5 * ((angle > 0 ) - (angle < 0)) : angle; // the r.h.s. yields +/-0.5 or angle
366 persp->tmat.set_infinite_direction (axis, a);
368 persp3d_update_box_reprs (persp);
369 SP_OBJECT(persp)->updateRepr(SP_OBJECT_WRITE_EXT);
370 }
372 void
373 persp3d_update_with_point (Persp3D *persp, Proj::Axis const axis, Proj::Pt2 const &new_image) {
374 persp->tmat.set_image_pt (axis, new_image);
375 }
377 void
378 persp3d_apply_affine_transformation (Persp3D *persp, NR::Matrix const &xform) {
379 persp->tmat *= xform;
380 persp3d_update_box_reprs(persp);
381 SP_OBJECT(persp)->updateRepr(SP_OBJECT_WRITE_EXT);
382 }
384 gchar *
385 persp3d_pt_to_str (Persp3D *persp, Proj::Axis const axis)
386 {
387 return persp->tmat.pt_to_str(axis);
388 }
390 void
391 persp3d_add_box (Persp3D *persp, SPBox3D *box) {
392 if (!box) {
393 return;
394 }
395 if (std::find (persp->boxes.begin(), persp->boxes.end(), box) != persp->boxes.end()) {
396 return;
397 }
398 persp->boxes.push_back(box);
399 }
401 void
402 persp3d_remove_box (Persp3D *persp, SPBox3D *box) {
403 std::vector<SPBox3D *>::iterator i = std::find (persp->boxes.begin(), persp->boxes.end(), box);
404 if (i != persp->boxes.end()) {
405 persp->boxes.erase(i);
406 }
407 }
409 bool
410 persp3d_has_box (Persp3D *persp, SPBox3D *box) {
411 // FIXME: For some reason, std::find() does not seem to compare pointers "correctly" (or do we need to
412 // provide a proper comparison function?), so we manually traverse the list.
413 for (std::vector<SPBox3D *>::iterator i = persp->boxes.begin(); i != persp->boxes.end(); ++i) {
414 if ((*i) == box) {
415 return true;
416 }
417 }
418 return false;
419 }
421 void
422 persp3d_add_box_transform (Persp3D *persp, SPBox3D *box) {
423 std::map<SPBox3D *, bool>::iterator i = persp->boxes_transformed.find(box);
424 if (i != persp->boxes_transformed.end() && (*i).second == true) {
425 g_print ("Warning! In %s (%d): trying to add transform status for box %d twice when it's already listed as true.\n", SP_OBJECT_REPR(persp)->attribute("id"), persp->my_counter, box->my_counter);
426 return;
427 }
429 persp->boxes_transformed[box] = false;
430 }
432 void
433 persp3d_remove_box_transform (Persp3D *persp, SPBox3D *box) {
434 persp->boxes_transformed.erase(box);
435 }
437 void
438 persp3d_set_box_transformed (Persp3D *persp, SPBox3D *box, bool transformed) {
439 if (persp->boxes_transformed.find(box) == persp->boxes_transformed.end()) {
440 g_print ("Warning! In %s (%d): trying to set transform status for box %d, but it is not listed in the perspective!! Aborting.\n",
441 SP_OBJECT_REPR(persp)->attribute("id"), persp->my_counter,
442 box->my_counter);
443 return;
444 }
446 persp->boxes_transformed[box] = transformed;
447 }
449 bool
450 persp3d_was_transformed (Persp3D *persp) {
451 if (persp->boxes_transformed.size() == 1) {
452 /* either the transform has not been applied to the single box associated to this perspective yet
453 or the transform was already reset; in both cases we need to return false because upcoming
454 transforms need to be applied */
455 (*persp->boxes_transformed.begin()).second = false; // make sure the box is marked as untransformed (in case more boxes are added later)
456 return false;
457 }
459 for (std::map<SPBox3D *, bool>::iterator i = persp->boxes_transformed.begin();
460 i != persp->boxes_transformed.end(); ++i) {
461 if ((*i).second == true) {
462 // at least one of the boxes in the perspective has already been transformed;
463 return true;
464 }
465 }
466 return false; // all boxes in the perspective are still untransformed; a pending transformation should be applied
467 }
469 bool
470 persp3d_all_transformed(Persp3D *persp) {
471 for (std::map<SPBox3D *, bool>::iterator i = persp->boxes_transformed.begin();
472 i != persp->boxes_transformed.end(); ++i) {
473 if ((*i).second == false) {
474 return false;
475 }
476 }
477 return true;
478 }
480 void
481 persp3d_unset_transforms(Persp3D *persp) {
482 for (std::map<SPBox3D *, bool>::iterator i = persp->boxes_transformed.begin();
483 i != persp->boxes_transformed.end(); ++i) {
484 (*i).second = false;
485 }
486 }
488 void
489 persp3d_update_box_displays (Persp3D *persp) {
490 if (persp->boxes.empty())
491 return;
492 for (std::vector<SPBox3D *>::iterator i = persp->boxes.begin(); i != persp->boxes.end(); ++i) {
493 box3d_position_set(*i);
494 }
495 }
497 void
498 persp3d_update_box_reprs (Persp3D *persp) {
499 if (persp->boxes.empty())
500 return;
501 for (std::vector<SPBox3D *>::iterator i = persp->boxes.begin(); i != persp->boxes.end(); ++i) {
502 SP_OBJECT(*i)->updateRepr(SP_OBJECT_WRITE_EXT);
503 box3d_set_z_orders(*i);
504 }
505 }
507 void
508 persp3d_update_z_orders (Persp3D *persp) {
509 if (persp->boxes.empty())
510 return;
511 for (std::vector<SPBox3D *>::iterator i = persp->boxes.begin(); i != persp->boxes.end(); ++i) {
512 box3d_set_z_orders(*i);
513 }
514 }
516 // FIXME: For some reason we seem to require a vector instead of a list in Persp3D, but in vp_knot_moved_handler()
517 // we need a list of boxes. If we can store a list in Persp3D right from the start, this function becomes
518 // obsolete. We should do this.
519 std::list<SPBox3D *>
520 persp3d_list_of_boxes(Persp3D *persp) {
521 std::list<SPBox3D *> bx_lst;
522 for (std::vector<SPBox3D *>::iterator i = persp->boxes.begin(); i != persp->boxes.end(); ++i) {
523 bx_lst.push_back(*i);
524 }
525 return bx_lst;
526 }
528 bool
529 persp3d_perspectives_coincide(const Persp3D *lhs, const Persp3D *rhs)
530 {
531 return lhs->tmat == rhs->tmat;
532 }
534 void
535 persp3d_absorb(Persp3D *persp1, Persp3D *persp2) {
536 /* double check if we are called in sane situations */
537 g_return_if_fail (persp3d_perspectives_coincide(persp1, persp2) && persp1 != persp2);
539 std::vector<SPBox3D *>::iterator boxes;
541 // Note: We first need to copy the boxes of persp2 into a separate list;
542 // otherwise the loop below gets confused when perspectives are reattached.
543 std::list<SPBox3D *> boxes_of_persp2 = persp3d_list_of_boxes(persp2);
545 for (std::list<SPBox3D *>::iterator i = boxes_of_persp2.begin(); i != boxes_of_persp2.end(); ++i) {
546 box3d_switch_perspectives((*i), persp2, persp1, true);
547 SP_OBJECT(*i)->updateRepr(SP_OBJECT_WRITE_EXT); // so that undo/redo can do its job properly
548 }
549 }
551 static void
552 persp3d_on_repr_attr_changed ( Inkscape::XML::Node * /*repr*/,
553 const gchar */*key*/,
554 const gchar */*oldval*/,
555 const gchar */*newval*/,
556 bool /*is_interactive*/,
557 void * data )
558 {
559 if (!data)
560 return;
562 Persp3D *persp = (Persp3D*) data;
563 persp3d_update_box_displays (persp);
564 }
566 /* returns a std::set() of all perspectives of the currently selected boxes */
567 std::set<Persp3D *>
568 persp3d_currently_selected_persps () {
569 Inkscape::Selection *selection = sp_desktop_selection(inkscape_active_desktop());
571 std::set<Persp3D *> p;
572 for (GSList *i = (GSList *) selection->itemList(); i != NULL; i = i->next) {
573 if (SP_IS_BOX3D (i->data)) {
574 p.insert(box3d_get_perspective(SP_BOX3D(i->data)));
575 }
576 }
577 return p;
578 }
580 /* checks whether all boxes linked to this perspective are currently selected */
581 bool
582 persp3d_has_all_boxes_in_selection (Persp3D *persp) {
583 const GSList *selection = sp_desktop_selection (inkscape_active_desktop())->itemList();
585 for (std::vector<SPBox3D *>::iterator i = persp->boxes.begin(); i != persp->boxes.end(); ++i) {
586 if (g_slist_find((GSList *) selection, *i) == NULL) {
587 // we have an unselected box in the perspective
588 return false;
589 }
590 }
591 return true;
592 }
594 std::list<SPBox3D *>
595 persp3d_selected_boxes (Persp3D *persp) {
596 const GSList *selection = sp_desktop_selection (inkscape_active_desktop())->itemList();
597 std::list<SPBox3D *> sel;
599 for (std::vector<SPBox3D *>::iterator i = persp->boxes.begin(); i != persp->boxes.end(); ++i) {
600 if (g_slist_find((GSList *) selection, *i) != NULL) {
601 sel.push_back(SP_BOX3D(*i));
602 }
603 }
604 return sel;
605 }
607 /* some debugging stuff follows */
609 void
610 persp3d_print_debugging_info (Persp3D *persp) {
611 g_print ("=== Info for Persp3D %d ===\n", persp->my_counter);
612 gchar * cstr;
613 for (int i = 0; i < 4; ++i) {
614 cstr = persp3d_get_VP(persp, Proj::axes[i]).coord_string();
615 g_print (" VP %s: %s\n", Proj::string_from_axis(Proj::axes[i]), cstr);
616 g_free(cstr);
617 }
618 cstr = persp3d_get_VP(persp, Proj::W).coord_string();
619 g_print (" Origin: %s\n", cstr);
620 g_free(cstr);
622 g_print (" Boxes: ");
623 for (std::vector<SPBox3D *>::iterator i = persp->boxes.begin(); i != persp->boxes.end(); ++i) {
624 g_print ("%d (%d) ", (*i)->my_counter, box3d_get_perspective(*i)->my_counter);
625 }
626 g_print ("\n");
627 g_print ("========================\n");
628 }
630 void
631 persp3d_print_debugging_info_all(SPDocument *document) {
632 SPDefs *defs = (SPDefs *) SP_DOCUMENT_DEFS(document);
633 Inkscape::XML::Node *repr;
634 for (SPObject *child = sp_object_first_child(defs); child != NULL; child = SP_OBJECT_NEXT(child) ) {
635 repr = SP_OBJECT_REPR(child);
636 if (SP_IS_PERSP3D(child)) {
637 persp3d_print_debugging_info(SP_PERSP3D(child));
638 }
639 }
640 persp3d_print_all_selected();
641 }
643 void
644 persp3d_print_all_selected() {
645 g_print ("\n======================================\n");
646 g_print ("Selected perspectives and their boxes:\n");
648 std::set<Persp3D *> sel_persps = persp3d_currently_selected_persps();
650 for (std::set<Persp3D *>::iterator j = sel_persps.begin(); j != sel_persps.end(); ++j) {
651 Persp3D *persp = SP_PERSP3D(*j);
652 g_print (" %s (%d): ", SP_OBJECT_REPR(persp)->attribute("id"), persp->my_counter);
653 for (std::map<SPBox3D *, bool>::iterator i = persp->boxes_transformed.begin();
654 i != persp->boxes_transformed.end(); ++i) {
655 g_print ("<%d,%d> ", (*i).first->my_counter, (*i).second);
656 }
657 g_print ("\n");
658 }
659 g_print ("======================================\n\n");
660 }
662 /*
663 Local Variables:
664 mode:c++
665 c-file-style:"stroustrup"
666 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
667 indent-tabs-mode:nil
668 fill-column:99
669 End:
670 */
671 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :