Code

Infrastructure to set direction of infinite VPs (now adjustable by some shortcuts...
[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];
39     gint z_orders[6]; // z_orders[i] holds the ID of the face at position #i in the group (from top to bottom)
41     std::vector<gint> currently_visible_faces;
43     // TODO: Keeping/updating the ratios works reasonably well but is still an ad hoc implementation.
44     //       Use a mathematically correct model to update the boxes.
45     double ratio_x;
46     double ratio_y;
47     double ratio_z;
49     guint front_bits; /* used internally to determine which of two parallel faces is supposed to be the front face */
51     // FIXME: If we only allow a single box to be dragged at a time then we can save memory by storing
52     //        the old positions centrally in SP3DBoxContext (instead of in each box separately)
53     // Also, it may be better not to store the old corners but rather the old lines to which we want to snap
54     NR::Point old_center;
55     NR::Point old_corner2;
56     NR::Point old_corner1;
57     NR::Point old_corner0;
58     NR::Point old_corner3;
59     NR::Point old_corner5;
60     NR::Point old_corner7;
62     gint my_counter; // for testing only
63 };
65 struct SP3DBoxClass {
66         SPGroupClass parent_class;
67 };
69 GType sp_3dbox_get_type (void);
71 void sp_3dbox_position_set (SP3DBoxContext &bc);
72 void sp_3dbox_set_shape(SP3DBox *box3d, bool use_previous_corners = false);
73 void sp_3dbox_recompute_corners (SP3DBox *box, NR::Point const pt1, NR::Point const pt2, NR::Point const pt3);
74 void sp_3dbox_set_z_orders_in_the_first_place (SP3DBox *box);
75 void sp_3dbox_set_z_orders_later_on (SP3DBox *box);
76 void sp_3dbox_update_curves (SP3DBox *box);
77 void sp_3dbox_link_to_existing_paths (SP3DBox *box, Inkscape::XML::Node *repr);
78 void sp_3dbox_set_ratios (SP3DBox *box, Box3D::Axis axes = Box3D::XYZ);
79 void sp_3dbox_switch_front_face (SP3DBox *box, Box3D::Axis axis);
80 void sp_3dbox_reshape_after_VP_rotation (SP3DBox *box, Box3D::Axis axis);
81 void sp_3dbox_move_corner_in_XY_plane (SP3DBox *box, guint id, NR::Point pt, Box3D::Axis axes = Box3D::XY);
82 void sp_3dbox_move_corner_in_Z_direction (SP3DBox *box, guint id, NR::Point pt, bool constrained = true);
83 void sp_3dbox_reshape_after_VP_toggling (SP3DBox *box, Box3D::Axis axis);
84 NR::Maybe<NR::Point> sp_3dbox_get_center (SP3DBox *box);
85 NR::Maybe<NR::Point> sp_3dbox_get_midpoint_between_corners (SP3DBox *box, guint id_corner1, guint id_corner2);
86 void sp_3dbox_recompute_XY_corners_from_new_center (SP3DBox *box, NR::Point const new_center);
87 void sp_3dbox_recompute_Z_corners_from_new_center (SP3DBox *box, NR::Point const new_center);
88 NR::Point sp_3dbox_get_midpoint_in_axis_direction (NR::Point const &C, NR::Point const &D, Box3D::Axis axis, Box3D::Perspective3D *persp);
90 void sp_3dbox_update_perspective_lines();
91 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);
92 guint sp_3dbox_get_corner_id_along_edge (const SP3DBox *box, guint corner, Box3D::Axis axis, Box3D::FrontOrRear rel_pos);
93 NR::Point sp_3dbox_get_corner_along_edge (const SP3DBox *box, guint corner, Box3D::Axis axis, Box3D::FrontOrRear rel_pos);
94 guint sp_3dbox_get_front_corner_id (const SP3DBox *box);
97 gchar * sp_3dbox_get_svg_descr_of_persp (Box3D::Perspective3D *persp);
99 inline NR::Point sp_3dbox_get_corner (SP3DBox *box, guint id) { return box->corners[id]; }
100 inline bool sp_3dbox_corners_are_adjacent (guint id_corner1, guint id_corner2) {
101   return Box3D::is_single_axis_direction ((Box3D::Axis) (id_corner1 ^ id_corner2));
104 #endif