Exemple #1
0
/**
 * Regenerates the draggers list from the current selection; is called when selection is changed or modified
 */
void
VPDrag::updateDraggers ()
{
    if (this->dragging)
        return;
    // delete old draggers
    for (GList const* i = this->draggers; i != NULL; i = i->next) {
        delete ((VPDragger *) i->data);
    }
    g_list_free (this->draggers);
    this->draggers = NULL;

    g_return_if_fail (this->selection != NULL);

    for (GSList const* i = this->selection->itemList(); i != NULL; i = i->next) {
        SPItem *item = SP_ITEM(i->data);
        if (!SP_IS_BOX3D (item)) continue;
        SPBox3D *box = SP_BOX3D (item);

        VanishingPoint vp;
        for (int i = 0; i < 3; ++i) {
            vp.set(box3d_get_perspective(box), Proj::axes[i]);
            addDragger (vp);
        }
    }
}
std::list<Persp3D *> const Selection::perspList() {
    std::list<Persp3D *> pl;
    for (std::list<SPBox3D *>::iterator i = _3dboxes.begin(); i != _3dboxes.end(); ++i) {
        Persp3D *persp = box3d_get_perspective(*i);
        if (std::find(pl.begin(), pl.end(), persp) == pl.end())
            pl.push_back(persp);
    }
    return pl;
}
std::list<SPBox3D *> const Selection::box3DList(Persp3D *persp) {
    std::list<SPBox3D *> boxes;
    if (persp) {
        for (std::list<SPBox3D *>::iterator i = _3dboxes.begin(); i != _3dboxes.end(); ++i) {
            SPBox3D *box = *i;
            if (persp == box3d_get_perspective(box)) {
                boxes.push_back(box);
            }
        }
    } else {
        boxes = _3dboxes;
    }
    return boxes;
}
Exemple #4
0
/**
 * Depending on the value of all_lines, draw the front and/or rear perspective lines starting from the given corners.
 */
void
VPDrag::drawLinesForFace (const SPBox3D *box, Proj::Axis axis) //, guint corner1, guint corner2, guint corner3, guint corner4)
{
    guint color;
    switch (axis) {
        // TODO: Make color selectable by user
        case Proj::X: color = VP_LINE_COLOR_STROKE_X; break;
        case Proj::Y: color = VP_LINE_COLOR_STROKE_Y; break;
        case Proj::Z: color = VP_LINE_COLOR_STROKE_Z; break;
        default: g_assert_not_reached();
    }

    Geom::Point corner1, corner2, corner3, corner4;
    box3d_corners_for_PLs (box, axis, corner1, corner2, corner3, corner4);

    g_return_if_fail (box3d_get_perspective(box));
    Proj::Pt2 vp = persp3d_get_VP (box3d_get_perspective(box), axis);
    if (vp.is_finite()) {
        // draw perspective lines for finite VPs
        Geom::Point pt = vp.affine();
        if (this->front_or_rear_lines & 0x1) {
            // draw 'front' perspective lines
            this->addLine (corner1, pt, color);
            this->addLine (corner2, pt, color);
        }
        if (this->front_or_rear_lines & 0x2) {
            // draw 'rear' perspective lines
            this->addLine (corner3, pt, color);
            this->addLine (corner4, pt, color);
        }
    } else {
        // draw perspective lines for infinite VPs
        boost::optional<Geom::Point> pt1, pt2, pt3, pt4;
        Persp3D *persp = box3d_get_perspective(box);
        SPDesktop *desktop = inkscape_active_desktop (); // FIXME: Store the desktop in VPDrag
        Box3D::PerspectiveLine pl (corner1, axis, persp);
        pt1 = pl.intersection_with_viewbox(desktop);

        pl = Box3D::PerspectiveLine (corner2, axis, persp);
        pt2 = pl.intersection_with_viewbox(desktop);

        pl = Box3D::PerspectiveLine (corner3, axis, persp);
        pt3 = pl.intersection_with_viewbox(desktop);

        pl = Box3D::PerspectiveLine (corner4, axis, persp);
        pt4 = pl.intersection_with_viewbox(desktop);

        if (!pt1 || !pt2 || !pt3 || !pt4) {
            // some perspective lines s are outside the canvas; currently we don't draw any of them
            return;
        }
        if (this->front_or_rear_lines & 0x1) {
            // draw 'front' perspective lines
            this->addLine (corner1, *pt1, color);
            this->addLine (corner2, *pt2, color);
        }
        if (this->front_or_rear_lines & 0x2) {
            // draw 'rear' perspective lines
            this->addLine (corner3, *pt3, color);
            this->addLine (corner4, *pt4, color);
        }
    }
}