persp3d.cpp revision f4dbc5a10ebf95900d1ef56d74aad0474e159370
/*
* Class modelling a 3D perspective as an SPObject
*
* Authors:
* Maximilian Albert <Anhalter42@gmx.de>
* Jon A. Cruz <jon@joncruz.org>
* Abhishek Sharma
*
* Copyright (C) 2007 authors
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#include "persp3d.h"
#include "perspective-line.h"
#include "attributes.h"
#include "document-private.h"
#include "document-undo.h"
#include "vanishing-point.h"
#include "box3d-context.h"
#include "box3d.h"
#include "xml/document.h"
#include "xml/node-event-vector.h"
#include "desktop-handles.h"
#include "verbs.h"
using Inkscape::DocumentUndo;
static Inkscape::XML::Node *persp3d_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags);
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);
static void persp3d_update_with_point (Persp3DImpl *persp_impl, Proj::Axis const axis, Proj::Pt2 const &new_image);
static SPObjectClass *persp3d_parent_class;
static int global_counter = 0;
/* Constructor/destructor for the internal class */
Persp3DImpl::Persp3DImpl() {
my_counter = global_counter++;
}
/**
* Registers Persp3d class and returns its type.
*/
{
if (!type) {
sizeof(Persp3DClass),
sizeof(Persp3D),
16,
NULL, /* value_table */
};
}
return type;
}
NULL, /* child_added */
NULL, /* child_removed */
NULL, /* content_changed */
NULL /* order_changed */
};
/**
* Callback to initialize Persp3D vtable.
*/
{
//sp_object_class->build = persp3d_build;
}
}
}
/**
* Callback to initialize Persp3D object.
*/
static void
{
}
/**
* Virtual build: set persp3d attributes from its associated XML node.
*/
//static void persp3d_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr)
//{
// if (((SPObjectClass *) persp3d_parent_class)->build)
// (* ((SPObjectClass *) persp3d_parent_class)->build)(object, document, repr);
/* calls sp_object_set for the respective attributes */
// The transformation matrix is updated according to the values we read for the VPs
// object->readAttr( "inkscape:vp_x" );
// object->readAttr( "inkscape:vp_y" );
// object->readAttr( "inkscape:vp_z" );
// object->readAttr( "inkscape:persp3d-origin" );
//
// if (repr) {
// repr->addListener (&persp3d_repr_events, object);
// }
//}
if (repr) {
}
}
/**
* Virtual release of Persp3D members before destruction.
*/
// Persp3D *persp = SP_PERSP3D(object);
// delete persp->perspective_impl;
// object->getRepr()->removeListenerByData(object);
}
delete persp->perspective_impl;
}
/**
* Virtual set: set attribute to value.
*/
// FIXME: Currently we only read the finite positions of vanishing points;
// should we move VPs into their own repr (as it's done for SPStop, e.g.)?
static void
{
// Persp3DImpl *persp_impl = SP_PERSP3D(object)->perspective_impl;
//
// switch (key) {
// case SP_ATTR_INKSCAPE_PERSP3D_VP_X: {
// if (value) {
// Proj::Pt2 new_image (value);
// persp3d_update_with_point (persp_impl, Proj::X, new_image);
// }
// break;
// }
// case SP_ATTR_INKSCAPE_PERSP3D_VP_Y: {
// if (value) {
// Proj::Pt2 new_image (value);
// persp3d_update_with_point (persp_impl, Proj::Y, new_image);
// break;
// }
// }
// case SP_ATTR_INKSCAPE_PERSP3D_VP_Z: {
// if (value) {
// Proj::Pt2 new_image (value);
// persp3d_update_with_point (persp_impl, Proj::Z, new_image);
// break;
// }
// }
// case SP_ATTR_INKSCAPE_PERSP3D_ORIGIN: {
// if (value) {
// Proj::Pt2 new_image (value);
// persp3d_update_with_point (persp_impl, Proj::W, new_image);
// break;
// }
// }
// default: {
// if (((SPObjectClass *) persp3d_parent_class)->set)
// (* ((SPObjectClass *) persp3d_parent_class)->set)(object, key, value);
// break;
// }
// }
//
// // FIXME: Is this the right place for resetting the draggers?
// SPEventContext *ec = inkscape_active_event_context();
// if (SP_IS_BOX3D_CONTEXT(ec)) {
// Box3DContext *bc = SP_BOX3D_CONTEXT(ec);
// bc->_vpdrag->updateDraggers();
// bc->_vpdrag->updateLines();
// bc->_vpdrag->updateBoxHandles();
// bc->_vpdrag->updateBoxReprs();
// }
}
switch (key) {
case SP_ATTR_INKSCAPE_PERSP3D_VP_X: {
if (value) {
}
break;
}
case SP_ATTR_INKSCAPE_PERSP3D_VP_Y: {
if (value) {
break;
}
}
case SP_ATTR_INKSCAPE_PERSP3D_VP_Z: {
if (value) {
break;
}
}
case SP_ATTR_INKSCAPE_PERSP3D_ORIGIN: {
if (value) {
break;
}
}
default: {
// if (((SPObjectClass *) persp3d_parent_class)->set)
// (* ((SPObjectClass *) persp3d_parent_class)->set)(object, key, value);
break;
}
}
// FIXME: Is this the right place for resetting the draggers?
if (SP_IS_BOX3D_CONTEXT(ec)) {
}
}
static void
{
// if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) {
//
// /* TODO: Should we update anything here? */
//
// }
//
// if (((SPObjectClass *) persp3d_parent_class)->update)
// ((SPObjectClass *) persp3d_parent_class)->update(object, ctx, flags);
}
if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) {
/* TODO: Should we update anything here? */
}
// if (((SPObjectClass *) persp3d_parent_class)->update)
// ((SPObjectClass *) persp3d_parent_class)->update(object, ctx, flags);
}
Persp3D *persp3d_create_xml_element(SPDocument *document, Persp3DImpl *dup) {// if dup is given, copy the attributes over
/* if no perspective is given, create a default one */
if (dup) {
}
/* Append the new persp3d to defs */
}
{
for ( SPObject *child = document->getDefs()->firstChild(); child && !first; child = child->getNext() ) {
if (SP_IS_PERSP3D(child)) {
}
}
return first;
}
/**
* Virtual write: write object attributes to repr.
*/
persp3d_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags)
{
// Persp3DImpl *persp_impl = SP_PERSP3D(object)->perspective_impl;
//
// if ((flags & SP_OBJECT_WRITE_BUILD & SP_OBJECT_WRITE_EXT) && !repr) {
// // this is where we end up when saving as plain SVG (also in other circumstances?);
// // hence we don't set the sodipodi:type attribute
// repr = xml_doc->createElement("inkscape:perspective");
// }
//
// if (flags & SP_OBJECT_WRITE_EXT) {
// gchar *str = NULL; // FIXME: Should this be freed each time we set an attribute or only in the end or at all?
// str = persp3d_pt_to_str (persp_impl, Proj::X);
// repr->setAttribute("inkscape:vp_x", str);
//
// str = persp3d_pt_to_str (persp_impl, Proj::Y);
// repr->setAttribute("inkscape:vp_y", str);
//
// str = persp3d_pt_to_str (persp_impl, Proj::Z);
// repr->setAttribute("inkscape:vp_z", str);
//
// str = persp3d_pt_to_str (persp_impl, Proj::W);
// repr->setAttribute("inkscape:persp3d-origin", str);
// }
//
// if (((SPObjectClass *) persp3d_parent_class)->write)
// (* ((SPObjectClass *) persp3d_parent_class)->write)(object, xml_doc, repr, flags);
//
// return repr;
}
Inkscape::XML::Node* CPersp3D::onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) {
// this is where we end up when saving as plain SVG (also in other circumstances?);
// hence we don't set the sodipodi:type attribute
}
if (flags & SP_OBJECT_WRITE_EXT) {
gchar *str = NULL; // FIXME: Should this be freed each time we set an attribute or only in the end or at all?
}
// if (((SPObjectClass *) persp3d_parent_class)->write)
// (* ((SPObjectClass *) persp3d_parent_class)->write)(object, xml_doc, repr, flags);
return repr;
}
/* convenience wrapper around persp3d_get_finite_dir() and persp3d_get_infinite_dir() */
} else {
}
}
}
}
}
double
}
bool
}
void
// FIXME: Remove this repr update and rely on vp_drag_sel_modified() to do this for us
// On the other hand, vp_drag_sel_modified() would update all boxes;
// here we can confine ourselves to the boxes of this particular perspective.
if (set_undo) {
_("Toggle vanishing point"));
}
}
/* toggle VPs for the same axis in all perspectives of a given list */
void
persp3d_toggle_VP((*i), axis, false);
}
_("Toggle multiple vanishing points"));
}
void
}
}
void
persp3d_rotate_VP (Persp3D *persp, Proj::Axis axis, double angle, bool alt_pressed) { // angle is in degrees
// FIXME: Most of this functionality should be moved to trans_mat_3x4.(h|cpp)
// don't rotate anything for finite VPs
return;
}
}
void
persp3d_update_with_point (Persp3DImpl *persp_impl, Proj::Axis const axis, Proj::Pt2 const &new_image) {
}
void
}
gchar *
{
}
void
if (!box) {
return;
}
if (std::find (persp_impl->boxes.begin(), persp_impl->boxes.end(), box) != persp_impl->boxes.end()) {
return;
}
}
void
std::vector<SPBox3D *>::iterator i = std::find (persp_impl->boxes.begin(), persp_impl->boxes.end(), box);
}
bool
// FIXME: For some reason, std::find() does not seem to compare pointers "correctly" (or do we need to
// provide a proper comparison function?), so we manually traverse the list.
for (std::vector<SPBox3D *>::iterator i = persp_impl->boxes.begin(); i != persp_impl->boxes.end(); ++i) {
if ((*i) == box) {
return true;
}
}
return false;
}
void
return;
for (std::vector<SPBox3D *>::iterator i = persp_impl->boxes.begin(); i != persp_impl->boxes.end(); ++i) {
box3d_position_set(*i);
}
}
void
if (!persp) {
// Hmm, is it an error if this happens?
return;
}
return;
for (std::vector<SPBox3D *>::iterator i = persp_impl->boxes.begin(); i != persp_impl->boxes.end(); ++i) {
(*i)->updateRepr(SP_OBJECT_WRITE_EXT);
box3d_set_z_orders(*i);
}
}
void
return;
for (std::vector<SPBox3D *>::iterator i = persp_impl->boxes.begin(); i != persp_impl->boxes.end(); ++i) {
box3d_set_z_orders(*i);
}
}
// FIXME: For some reason we seem to require a vector instead of a list in Persp3D, but in vp_knot_moved_handler()
// we need a list of boxes. If we can store a list in Persp3D right from the start, this function becomes
// obsolete. We should do this.
for (std::vector<SPBox3D *>::iterator i = persp_impl->boxes.begin(); i != persp_impl->boxes.end(); ++i) {
}
return bx_lst;
}
bool
{
}
void
/* double check if we are called in sane situations */
// Note: We first need to copy the boxes of persp2 into a separate list;
// otherwise the loop below gets confused when perspectives are reattached.
}
}
static void
const gchar */*key*/,
const gchar */*oldval*/,
const gchar */*newval*/,
bool /*is_interactive*/,
void * data )
{
if (!data)
return;
}
/* checks whether all boxes linked to this perspective are currently selected */
bool
for (std::vector<SPBox3D *>::iterator i = persp_impl->boxes.begin(); i != persp_impl->boxes.end(); ++i) {
// we have an unselected box in the perspective
return false;
}
}
return true;
}
/* some debugging stuff follows */
void
for (int i = 0; i < 4; ++i) {
}
g_print (" Boxes: ");
for (std::vector<SPBox3D *>::iterator i = persp_impl->boxes.begin(); i != persp_impl->boxes.end(); ++i) {
}
g_print ("\n");
g_print ("========================\n");
}
{
if (SP_IS_PERSP3D(child)) {
}
}
}
void
g_print ("\n======================================\n");
g_print ("Selected perspectives and their boxes:\n");
}
g_print ("\n");
}
g_print ("======================================\n\n");
}
g_print ("%s: current_persp3d is now %s\n",
}
/*
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:fileencoding=utf-8:textwidth=99 :