Code

Draw perspective lines; provide shortcuts to toggle their visibility and the corners...
[inkscape.git] / src / box3d.h
1 #ifndef __SP_3DBOX_H__
2 #define __SP_3DBOX_H__
4 /*
5  * SVG <box3d> implementation
6  *
7  * Authors:
8  *   Lauris Kaplinski <lauris@kaplinski.com>
9  *   Maximilian Albert <Anhalter42@gmx.de>
10  *
11  * Copyright (C) 2007      Authors
12  * Copyright (C) 1999-2002 Lauris Kaplinski
13  * Copyright (C) 2000-2001 Ximian, Inc.
14  *
15  * Released under GNU GPL, read the file 'COPYING' for more information
16  */
18 #include "inkscape.h"
19 #include "perspective-line.h"
21 #include "sp-item-group.h"
22 #include "sp-path.h"
23 #include "xml/document.h"
24 #include "xml/repr.h"
25 #include "line-geometry.h"
26 #include "box3d-face.h"
29 #define SP_TYPE_3DBOX            (sp_3dbox_get_type ())
30 #define SP_3DBOX(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), SP_TYPE_3DBOX, SP3DBox))
31 #define SP_3DBOX_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), SP_TYPE_3DBOX, SP3DBoxClass))
32 #define SP_IS_3DBOX(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SP_TYPE_3DBOX))
33 #define SP_IS_3DBOX_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SP_TYPE_3DBOX))
36 struct SP3DBox : public SPGroup {
37     NR::Point corners[8];
38     Box3DFace *faces[6];
40     // TODO: Keeping/updating the ratios works reasonably well but is still an ad hoc implementation.
41     //       Use a mathematically correct model to update the boxes.
42     double ratio_x;
43     double ratio_y;
44     double ratio_z;
46     guint front_bits; /* used internally to determine which of two parallel faces is supposed to be the front face */
48     gint my_counter; // for testing only
49 };
51 struct SP3DBoxClass {
52         SPGroupClass parent_class;
53 };
55 GType sp_3dbox_get_type (void);
57 void sp_3dbox_position_set (SP3DBoxContext &bc);
58 void sp_3dbox_set_shape(SP3DBox *box3d, bool use_previous_corners = false);
59 void sp_3dbox_recompute_corners (SP3DBox *box, NR::Point const pt1, NR::Point const pt2, NR::Point const pt3);
60 void sp_3dbox_update_curves (SP3DBox *box);
61 void sp_3dbox_link_to_existing_paths (SP3DBox *box, Inkscape::XML::Node *repr);
62 void sp_3dbox_set_ratios (SP3DBox *box, Box3D::Axis axes = Box3D::XYZ);
63 void sp_3dbox_switch_front_face (SP3DBox *box, Box3D::Axis axis);
64 void sp_3dbox_move_corner_in_XY_plane (SP3DBox *box, guint id, NR::Point pt, Box3D::Axis axes = Box3D::XY);
65 void sp_3dbox_move_corner_in_Z_direction (SP3DBox *box, guint id, NR::Point pt, bool constrained = true);
66 NR::Maybe<NR::Point> sp_3dbox_get_center (SP3DBox *box);
67 NR::Maybe<NR::Point> sp_3dbox_get_midpoint_between_corners (SP3DBox *box, guint id_corner1, guint id_corner2);
69 void sp_3dbox_update_perspective_lines();
70 void sp_3dbox_corners_for_perspective_lines (const SP3DBox * box, Box3D::Axis axis, NR::Point &corner1, NR::Point &corner2, NR::Point &corner3, NR::Point &corner4);
71 guint sp_3dbox_get_corner_id_along_edge (const SP3DBox *box, guint corner, Box3D::Axis axis, Box3D::FrontOrRear rel_pos);
72 NR::Point sp_3dbox_get_corner_along_edge (const SP3DBox *box, guint corner, Box3D::Axis axis, Box3D::FrontOrRear rel_pos);
74 gchar * sp_3dbox_get_svg_descr_of_persp (Box3D::Perspective3D *persp);
76 inline NR::Point sp_3dbox_get_corner (SP3DBox *box, guint id) { return box->corners[id]; }
77 inline bool sp_3dbox_corners_are_adjacent (guint id_corner1, guint id_corner2) {
78   return Box3D::is_single_axis_direction ((Box3D::Axis) (id_corner1 ^ id_corner2));
79 }
81 #endif