persp3d.cpp revision af2cf4c771e17608937d35438c0bb76df8783863
/*
* 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 "ui/tools/box3d-tool.h"
#include "box3d.h"
#include "svg/stringstream.h"
#include "xml/document.h"
#include "xml/node-event-vector.h"
#include "desktop-handles.h"
#include "verbs.h"
using Inkscape::DocumentUndo;
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 int global_counter = 0;
#include "sp-factory.h"
namespace {
SPObject* createPersp3D() {
return new Persp3D();
}
}
/* Constructor/destructor for the internal class */
Persp3DImpl::Persp3DImpl() {
my_counter = global_counter++;
}
NULL, /* child_added */
NULL, /* child_removed */
NULL, /* content_changed */
NULL /* order_changed */
};
this->perspective_impl = new Persp3DImpl();
}
}
/**
* Virtual build: set persp3d attributes from its associated XML node.
*/
this->readAttr( "inkscape:vp_x" );
this->readAttr( "inkscape:vp_y" );
this->readAttr( "inkscape:vp_z" );
this->readAttr( "inkscape:persp3d-origin" );
if (repr) {
}
}
/**
* Virtual release of Persp3D members before destruction.
*/
delete this->perspective_impl;
this->getRepr()->removeListenerByData(this);
}
/**
* 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.)?
// Read values are in 'user units'.
double scale_x = 1.0;
double scale_y = 1.0;
if( root->viewBox_set ) {
}
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)) {
}
}
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, Persp3DImpl *dup) {// if dup is given, copy the attributes over
/* if no perspective is given, create a default one */
// Use 'user-units'
}
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.
*/
Inkscape::XML::Node* Persp3D::write(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) {
// Written values are in 'user units'.
double scale_x = 1.0;
double scale_y = 1.0;
if( root->viewBox_set ) {
}
{
}
{
}
{
}
{
}
}
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
}
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 :