persp3d.cpp revision aa90355b5205dca29912b439ac9fde6ffa4d8989
#define __PERSP3D_C__
/*
* Class modelling a 3D perspective as an SPObject
*
* Authors:
* Maximilian Albert <Anhalter42@gmx.de>
*
* 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 "vanishing-point.h"
#include "box3d-context.h"
#include "box3d.h"
#include "xml/document.h"
#include "xml/node-event-vector.h"
#include "desktop-handles.h"
static Inkscape::XML::Node *persp3d_write(SPObject *object, 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 SPObjectClass *persp3d_parent_class;
static int global_counter = 0;
/**
* 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.
*/
{
}
/**
* Callback to initialize Persp3D object.
*/
static void
{
//persp->boxes = NULL;
}
/**
* Virtual build: set persp3d attributes from its associated XML node.
*/
{
/* calls sp_object_set for the respective attributes */
// The transformation matrix is updated according to the values we read for the VPs
if (repr) {
}
// FIXME: What precisely does this do and is it necessary for perspectives?
/* Register ourselves */
//sp_document_add_resource(document, "persp3d", object);
}
/**
* Virtual release of Persp3D members before destruction.
*/
//Persp3D *persp = (Persp3D *) object;
// FIXME: What precisely does this do and is it necessary for perspectives?
/**
if (SP_OBJECT_DOCUMENT(object)) {
// Unregister ourselves
sp_document_remove_resource(SP_OBJECT_DOCUMENT(object), "persp3d", SP_OBJECT(object));
}
**/
}
/**
* 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
{
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: {
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? */
}
}
Persp3D *
persp3d_create_xml_element (SPDocument *document, Persp3D *dup) {// if dup is given, copy the attributes over
if (dup) {
} else {
/* if no perspective is given, create a default one */
}
/* Append the new persp3d to defs */
}
/**
* Virtual write: write object attributes to 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
}
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?
}
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.
//persp3d_update_z_orders (persp);
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;
}
//persp3d_update_z_orders (persp);
}
void
}
void
}
gchar *
{
}
void
if (!box) {
//g_warning ("Trying to add NULL box to perspective.\n");
return;
}
//g_warning ("Attempting to add already existent box to perspective.\n");
return;
}
//SP_OBJECT_REPR(box)->setAttribute("inkscape:perspectiveID", SP_OBJECT_REPR(persp)->attribute("id"));
}
void
}
}
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.
if ((*i) == box) {
return true;
}
}
return false;
}
void
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);
return;
}
}
void
}
void
g_print ("Warning! In %s (%d): trying to set transform status for box %d, but it is not listed in the perspective!! Aborting.\n",
box->my_counter);
return;
}
}
bool
/* either the transform has not been applied to the single box associated to this perspective yet
or the transform was already reset; in both cases we need to return false because upcoming
transforms need to be applied */
(*persp->boxes_transformed.begin()).second = false; // make sure the box is marked as untransformed (in case more boxes are added later)
return false;
}
if ((*i).second == true) {
// at least one of the boxes in the perspective has already been transformed;
return true;
}
}
return false; // all boxes in the perspective are still untransformed; a pending transformation should be applied
}
bool
if ((*i).second == false) {
return false;
}
}
return true;
}
void
(*i).second = false;
}
}
void
return;
//g_print ("Requesting display update for %d boxes in the perspective.\n", persp->boxes.size());
box3d_position_set(*i);
}
}
void
return;
//g_print ("Requesting repr update for %d boxes in the perspective.\n", persp->boxes.size());
box3d_set_z_orders(*i);
}
}
void
return;
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.
}
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 )
{
//g_print("persp3d_on_repr_attr_changed!!!! TODO: Do we need to trigger any further updates than the box reprs?");
if (!data)
return;
//lpeobj->requestModified(SP_OBJECT_MODIFIED_FLAG);
}
/* returns a std::set() of all perspectives of the currently selected boxes */
if (SP_IS_BOX3D (i->data)) {
}
}
return p;
}
/* checks whether all boxes linked to this perspective are currently selected */
bool
// we have an unselected box in the perspective
return false;
}
}
return true;
}
}
}
return sel;
}
void
for (int i = 0; i < 4; ++i) {
}
g_print (" Boxes: ");
}
g_print ("\n");
g_print ("========================\n");
}
void
for (SPObject *child = sp_object_first_child(defs); child != NULL; child = SP_OBJECT_NEXT(child) ) {
if (SP_IS_PERSP3D(child)) {
}
}
}
void
/**
if (persp3d->boxes_transformed.empty()) {
g_print ("No selected perspectives in document\n");
return;
}
**/
g_print ("\n======================================\n");
g_print ("Selected perspectives and their boxes:\n");
std::set<Persp3D *> sel_persps = persp3d_currently_selected_persps (inkscape_active_event_context());
}
g_print ("\n");
}
g_print ("======================================\n\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:encoding=utf-8:textwidth=99 :