summaryrefslogtreecommitdiffstats
path: root/src/box3d.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/box3d.cpp')
-rw-r--r--src/box3d.cpp91
1 files changed, 37 insertions, 54 deletions
diff --git a/src/box3d.cpp b/src/box3d.cpp
index 13a8d0e3e..3c0cbb675 100644
--- a/src/box3d.cpp
+++ b/src/box3d.cpp
@@ -6,6 +6,7 @@
* Lauris Kaplinski <lauris@kaplinski.com>
* bulia byak <buliabyak@users.sf.net>
* Abhishek Sharma
+ * Jon A. Cruz <jon@joncruz.org>
*
* Copyright (C) 2007 Authors
* Copyright (C) 1999-2002 Lauris Kaplinski
@@ -65,27 +66,23 @@ SPBox3D::~SPBox3D() {
}
void SPBox3D::build(SPDocument *document, Inkscape::XML::Node *repr) {
- SPBox3D* object = this;
-
SPGroup::build(document, repr);
- SPBox3D *box = SP_BOX3D (object);
- box->my_counter = counter++;
+ my_counter = counter++;
/* we initialize the z-orders to zero so that they are updated during dragging */
for (int i = 0; i < 6; ++i) {
- box->z_orders[i] = 0;
+ z_orders[i] = 0;
}
// TODO: Create/link to the correct perspective
- SPDocument *doc = box->document;
- if ( doc ) {
- box->persp_ref->changedSignal().connect(sigc::bind(sigc::ptr_fun(box3d_ref_changed), box));
+ if ( document ) {
+ persp_ref->changedSignal().connect(sigc::bind(sigc::ptr_fun(box3d_ref_changed), this));
- object->readAttr( "inkscape:perspectiveID" );
- object->readAttr( "inkscape:corner0" );
- object->readAttr( "inkscape:corner7" );
+ readAttr( "inkscape:perspectiveID" );
+ readAttr( "inkscape:corner0" );
+ readAttr( "inkscape:corner7" );
}
}
@@ -187,11 +184,15 @@ box3d_ref_changed(SPObject *old_ref, SPObject *ref, SPBox3D *box)
{
if (old_ref) {
sp_signal_disconnect_by_data(old_ref, box);
- persp3d_remove_box (SP_PERSP3D(old_ref), box);
+ Persp3D *oldPersp = dynamic_cast<Persp3D *>(old_ref);
+ if (oldPersp) {
+ persp3d_remove_box(oldPersp, box);
+ }
}
- if ( SP_IS_PERSP3D(ref) && ref != box ) // FIXME: Comparisons sane?
+ Persp3D *persp = dynamic_cast<Persp3D *>(ref);
+ if ( persp && (ref != box) ) // FIXME: Comparisons sane?
{
- persp3d_add_box (SP_PERSP3D(ref), box);
+ persp3d_add_box(persp, box);
}
}
@@ -263,17 +264,15 @@ void box3d_position_set(SPBox3D *box)
{
/* This draws the curve and calls requestDisplayUpdate() for each side (the latter is done in
box3d_side_position_set() to avoid update conflicts with the parent box) */
- for ( SPObject *child = box->firstChild(); child; child = child->getNext() ) {
- if (SP_IS_BOX3D_SIDE(child)) {
- box3d_side_position_set(SP_BOX3D_SIDE(child));
+ for ( SPObject *obj = box->firstChild(); obj; obj = obj->getNext() ) {
+ Box3DSide *side = dynamic_cast<Box3DSide *>(obj);
+ if (side) {
+ box3d_side_position_set(side);
}
}
}
Geom::Affine SPBox3D::set_transform(Geom::Affine const &xform) {
- SPBox3D* item = this;
- SPBox3D *box = item;
-
// We don't apply the transform to the box directly but instead to its perspective (which is
// done in sp_selection_apply_affine). Here we only adjust strokes, patterns, etc.
@@ -281,10 +280,9 @@ Geom::Affine SPBox3D::set_transform(Geom::Affine const &xform) {
gdouble const sw = hypot(ret[0], ret[1]);
gdouble const sh = hypot(ret[2], ret[3]);
- for ( SPObject *child = box->firstChild(); child; child = child->getNext() ) {
- if (SP_IS_ITEM(child)) {
- SPItem *childitem = SP_ITEM(child);
-
+ for ( SPObject *child = firstChild(); child; child = child->getNext() ) {
+ SPItem *childitem = dynamic_cast<SPItem *>(child);
+ if (childitem) {
// Adjust stroke width
childitem->adjust_stroke(sqrt(fabs(sw * sh)));
@@ -672,15 +670,6 @@ box3d_aux_set_z_orders (int z_orders[6], int a, int b, int c, int d, int e, int
z_orders[5] = f;
}
-static inline void
-box3d_swap_z_orders (int z_orders[6]) {
- int tmp;
- for (int i = 0; i < 3; ++i) {
- tmp = z_orders[i];
- z_orders[i] = z_orders[5-i];
- z_orders[5-i] = tmp;
- }
-}
/*
* In standard perspective we have:
@@ -695,11 +684,6 @@ box3d_swap_z_orders (int z_orders[6]) {
/* All VPs infinite */
static void
box3d_set_new_z_orders_case0 (SPBox3D *box, int z_orders[6], Box3D::Axis central_axis) {
- Persp3D *persp = box3d_get_perspective(box);
- Geom::Point xdir(persp3d_get_infinite_dir(persp, Proj::X));
- Geom::Point ydir(persp3d_get_infinite_dir(persp, Proj::Y));
- Geom::Point zdir(persp3d_get_infinite_dir(persp, Proj::Z));
-
bool swapped = box3d_XY_axes_are_swapped(box);
switch(central_axis) {
@@ -811,12 +795,7 @@ box3d_set_new_z_orders_case1 (SPBox3D *box, int z_orders[6], Box3D::Axis central
/* Precisely 2 finite VPs */
static void
box3d_set_new_z_orders_case2 (SPBox3D *box, int z_orders[6], Box3D::Axis central_axis, Box3D::Axis /*infinite_axis*/) {
- Persp3D *persp = box3d_get_perspective(box);
-
Geom::Point c3(box3d_get_corner_screen(box, 3, false));
- Geom::Point xdir(persp3d_get_PL_dir_from_pt(persp, c3, Proj::X));
- Geom::Point ydir(persp3d_get_PL_dir_from_pt(persp, c3, Proj::Y));
- Geom::Point zdir(persp3d_get_PL_dir_from_pt(persp, c3, Proj::Z));
bool swapped = box3d_XY_axes_are_swapped(box);
@@ -1098,10 +1077,10 @@ box3d_recompute_z_orders (SPBox3D *box) {
static std::map<int, Box3DSide *> box3d_get_sides(SPBox3D *box)
{
std::map<int, Box3DSide *> sides;
- for ( SPObject *side = box->firstChild(); side; side = side->getNext() ) {
- if (SP_IS_BOX3D_SIDE(side)){
- Box3DSide *bside = SP_BOX3D_SIDE(side);
- sides[Box3D::face_to_int(bside->getFaceId())] = bside;
+ for ( SPObject *obj = box->firstChild(); obj; obj = obj->getNext() ) {
+ Box3DSide *side = dynamic_cast<Box3DSide *>(obj);
+ if (side) {
+ sides[Box3D::face_to_int(side->getFaceId())] = side;
}
}
sides.erase(-1);
@@ -1237,9 +1216,10 @@ box3d_check_for_swapped_coords(SPBox3D *box) {
}
static void box3d_extract_boxes_rec(SPObject *obj, std::list<SPBox3D *> &boxes) {
- if (SP_IS_BOX3D(obj)) {
- boxes.push_back(SP_BOX3D(obj));
- } else if (SP_IS_GROUP(obj)) {
+ SPBox3D *box = dynamic_cast<SPBox3D *>(obj);
+ if (box) {
+ boxes.push_back(box);
+ } else if (dynamic_cast<SPGroup *>(obj)) {
for ( SPObject *child = obj->firstChild(); child; child = child->getNext() ) {
box3d_extract_boxes_rec(child, boxes);
}
@@ -1299,9 +1279,10 @@ SPGroup *box3d_convert_to_group(SPBox3D *box)
// create a new group and add the sides (converted to ordinary paths) as its children
Inkscape::XML::Node *grepr = xml_doc->createElement("svg:g");
- for ( SPObject *child = box->firstChild(); child; child = child->getNext() ) {
- if (SP_IS_BOX3D_SIDE(child)) {
- Inkscape::XML::Node *repr = box3d_side_convert_to_path(SP_BOX3D_SIDE(child));
+ for ( SPObject *obj = box->firstChild(); obj; obj = obj->getNext() ) {
+ Box3DSide *side = dynamic_cast<Box3DSide *>(obj);
+ if (side) {
+ Inkscape::XML::Node *repr = box3d_side_convert_to_path(side);
grepr->appendChild(repr);
} else {
g_warning("Non-side item encountered as child of a 3D box.");
@@ -1322,7 +1303,9 @@ SPGroup *box3d_convert_to_group(SPBox3D *box)
grepr->setAttribute("id", id);
- return SP_GROUP(doc->getObjectByRepr(grepr));
+ SPGroup *group = dynamic_cast<SPGroup *>(doc->getObjectByRepr(grepr));
+ g_assert(group != NULL);
+ return group;
}
const char *SPBox3D::displayName() const {