Code

object-snapper.cpp
[inkscape.git] / src / sp-item.h
1 #ifndef __SP_ITEM_H__
2 #define __SP_ITEM_H__
4 /** \file
5  * Some things pertinent to all visible shapes: SPItem, SPItemView, SPItemCtx, SPItemClass, SPEvent.
6  */
8 /*
9  * Authors:
10  *   Lauris Kaplinski <lauris@kaplinski.com>
11  *   bulia byak <buliabyak@users.sf.net>
12  *   Johan Engelen <j.b.c.engelen@ewi.utwente.nl>
13  *
14  * Copyright (C) 1999-2006 authors
15  * Copyright (C) 2001-2002 Ximian, Inc.
16  * Copyright (C) 2004 Monash University
17  *
18  * Released under GNU GPL, read the file 'COPYING' for more information
19  */
20 #include <vector>
22 #include "display/nr-arena-forward.h"
23 #include "sp-object.h"
24 #include <libnr/nr-matrix.h>
25 #include <libnr/nr-rect.h>
26 #include <2geom/forward.h>
27 #include <libnr/nr-convert2geom.h>
28 #include <snap-preferences.h>
30 class SPGuideConstraint;
31 struct SPClipPathReference;
32 struct SPMaskReference;
33 struct SPAvoidRef;
34 struct SPPrintContext;
35 namespace Inkscape { class URIReference; }
36  
37 enum {
38     SP_EVENT_INVALID,
39     SP_EVENT_NONE,
40     SP_EVENT_ACTIVATE,
41     SP_EVENT_MOUSEOVER,
42     SP_EVENT_MOUSEOUT
43 };
45 /**
46  * Event structure.
47  *
48  * \todo This is just placeholder. Plan:
49  * We do extensible event structure, that hold applicable (ui, non-ui)
50  * data pointers. So it is up to given object/arena implementation
51  * to process correct ones in meaningful way.
52  * Also, this probably goes to SPObject base class.
53  *
54  */
55 struct SPEvent {
56     unsigned int type;
57     gpointer data;
58 };
60 class SPItemView;
62 /// SPItemView
63 struct SPItemView {
64     SPItemView *next;
65     unsigned int flags;
66     unsigned int key;
67     NRArenaItem *arenaitem;
68 };
70 /* flags */
72 #define SP_ITEM_BBOX_VISUAL 1
74 #define SP_ITEM_SHOW_DISPLAY (1 << 0)
76 /**
77  * Flag for referenced views (i.e. markers, clippaths, masks and patterns); 
78    currently unused, does the same as DISPLAY
79  */
80 #define SP_ITEM_REFERENCE_FLAGS (1 << 1)
82 class SPItemCtx;
84 /// Contains transformations to document/viewport and the viewport size.
85 struct SPItemCtx {
86     SPCtx ctx;
87     /** Item to document transformation */
88     Geom::Matrix i2doc;
89     /** Viewport size */
90     NRRect vp;
91     /** Item to viewport transformation */
92     Geom::Matrix i2vp;
93 };
95 /** Abstract base class for all visible shapes. */
96 struct SPItem : public SPObject {
97     enum BBoxType {
98         // legacy behavior: includes crude stroke, markers; excludes long miters, blur margin; is known to be wrong for caps
99         APPROXIMATE_BBOX, 
100         // includes only the bare path bbox, no stroke, no nothing
101         GEOMETRIC_BBOX,
102         // includes everything: correctly done stroke (with proper miters and caps), markers, filter margins (e.g. blur)
103         RENDERING_BBOX
104     };
106     unsigned int sensitive : 1;
107     unsigned int stop_paint: 1;
108     double transform_center_x;
109     double transform_center_y;
111     Geom::Matrix transform;
112     
113     SPClipPathReference *clip_ref;
114     SPMaskReference *mask_ref;
115     
116     // Used for object-avoiding connectors
117     SPAvoidRef *avoidRef;
118     
119     SPItemView *display;
120     
121     std::vector<SPGuideConstraint> constraints;
122     
123     sigc::signal<void, Geom::Matrix const *, SPItem *> _transformed_signal;
125     void init();    
126     bool isLocked() const;
127     void setLocked(bool lock);
128     
129     bool isHidden() const;
130     void setHidden(bool hidden);
132     bool isEvaluated() const;
133     void setEvaluated(bool visible);
134     void resetEvaluated();
135     
136     bool isHidden(unsigned display_key) const;
137     
138     bool isExplicitlyHidden() const;
139     
140     void setExplicitlyHidden(bool val);
142     void setCenter(Geom::Point object_centre);
143     void unsetCenter();
144     bool isCenterSet();
145     Geom::Point getCenter() const;
147     bool isVisibleAndUnlocked() const;
148     
149     bool isVisibleAndUnlocked(unsigned display_key) const;
150     
151     Geom::Matrix getRelativeTransform(SPObject const *obj) const;
152     
153     void raiseOne();
154     void lowerOne();
155     void raiseToTop();
156     void lowerToBottom();
158     Geom::OptRect getBounds(Geom::Matrix const &transform, BBoxType type=APPROXIMATE_BBOX, unsigned int dkey=0) const;
160     sigc::connection _clip_ref_connection;
161     sigc::connection _mask_ref_connection;
163     sigc::connection connectTransformed(sigc::slot<void, Geom::Matrix const *, SPItem *> slot)  {
164         return _transformed_signal.connect(slot);
165     }
167 private:
168     enum EvaluatedStatus
169     {
170         StatusUnknown, StatusCalculated, StatusSet
171     };
173     mutable bool _is_evaluated;
174     mutable EvaluatedStatus _evaluated_status;
175 };
177 typedef std::back_insert_iterator<std::vector<Geom::Point> > SnapPointsIter;
179 /// The SPItem vtable.
180 struct SPItemClass {
181     SPObjectClass parent_class;
183     /** BBox union in given coordinate system */
184     void (* bbox) (SPItem const *item, NRRect *bbox, Geom::Matrix const &transform, unsigned const flags);
185     
186     /** Printing method. Assumes ctm is set to item affine matrix */
187     /* \todo Think about it, and maybe implement generic export method instead (Lauris) */
188     void (* print) (SPItem *item, SPPrintContext *ctx);
189     
190     /** Give short description of item (for status display) */
191     gchar * (* description) (SPItem * item);
192     
193     NRArenaItem * (* show) (SPItem *item, NRArena *arena, unsigned int key, unsigned int flags);
194     void (* hide) (SPItem *item, unsigned int key);
195     
196     /** Write to an iterator the points that should be considered for snapping
197      * as the item's `nodes'.
198      */
199     void (* snappoints) (SPItem const *item, SnapPointsIter p, Inkscape::SnapPreferences const *snapprefs);
200     
201     /** Apply the transform optimally, and return any residual transformation */
202     Geom::Matrix (* set_transform)(SPItem *item, Geom::Matrix const &transform);
204     /** Convert the item to guidelines */
205     void (* convert_to_guides)(SPItem *item);
206     
207     /** Emit event, if applicable */
208     gint (* event) (SPItem *item, SPEvent *event);
209 };
211 /* Flag testing macros */
213 #define SP_ITEM_STOP_PAINT(i) (SP_ITEM (i)->stop_paint)
215 /* Methods */
217 void sp_item_invoke_bbox(SPItem const *item, Geom::OptRect &bbox, Geom::Matrix const &transform, unsigned const clear, SPItem::BBoxType type = SPItem::APPROXIMATE_BBOX);
218 void sp_item_invoke_bbox(SPItem const *item, NRRect *bbox, Geom::Matrix const &transform, unsigned const clear, SPItem::BBoxType type = SPItem::APPROXIMATE_BBOX) __attribute__ ((deprecated));
219 void sp_item_invoke_bbox_full(SPItem const *item, Geom::OptRect &bbox, Geom::Matrix const &transform, unsigned const flags, unsigned const clear);
220 void sp_item_invoke_bbox_full(SPItem const *item, NRRect *bbox, Geom::Matrix const &transform, unsigned const flags, unsigned const clear) __attribute__ ((deprecated));
222 unsigned sp_item_pos_in_parent(SPItem *item);
224 gchar *sp_item_description(SPItem * item);
225 void sp_item_invoke_print(SPItem *item, SPPrintContext *ctx);
227 /** Shows/Hides item on given arena display list */
228 unsigned int sp_item_display_key_new(unsigned int numkeys);
229 NRArenaItem *sp_item_invoke_show(SPItem *item, NRArena *arena, unsigned int key, unsigned int flags);
230 void sp_item_invoke_hide(SPItem *item, unsigned int key);
232 void sp_item_snappoints(SPItem const *item, SnapPointsIter p, Inkscape::SnapPreferences const *snapprefs);
234 void sp_item_adjust_pattern(SPItem *item, /* Geom::Matrix const &premul, */ Geom::Matrix const &postmul, bool set = false);
235 void sp_item_adjust_gradient(SPItem *item, /* Geom::Matrix const &premul, */ Geom::Matrix const &postmul, bool set = false);
236 void sp_item_adjust_stroke(SPItem *item, gdouble ex);
237 void sp_item_adjust_stroke_width_recursive(SPItem *item, gdouble ex);
238 void sp_item_adjust_paint_recursive(SPItem *item, Geom::Matrix advertized_transform, Geom::Matrix t_ancestors, bool is_pattern);
239 void sp_item_adjust_livepatheffect(SPItem *item, Geom::Matrix const &postmul, bool set = false);
241 void sp_item_write_transform(SPItem *item, Inkscape::XML::Node *repr, Geom::Matrix const &transform, Geom::Matrix const *adv = NULL, bool compensate = true);
243 void sp_item_set_item_transform(SPItem *item, Geom::Matrix const &transform);
245 void sp_item_convert_item_to_guides(SPItem *item);
247 gint sp_item_event (SPItem *item, SPEvent *event);
249 /* Utility */
251 NRArenaItem *sp_item_get_arenaitem(SPItem *item, unsigned int key);
253 void sp_item_bbox_desktop(SPItem *item, NRRect *bbox, SPItem::BBoxType type = SPItem::APPROXIMATE_BBOX) __attribute__ ((deprecated));
254 Geom::OptRect sp_item_bbox_desktop(SPItem *item, SPItem::BBoxType type = SPItem::APPROXIMATE_BBOX);
256 Geom::Matrix i2anc_affine(SPObject const *item, SPObject const *ancestor);
257 Geom::Matrix i2i_affine(SPObject const *src, SPObject const *dest);
259 Geom::Matrix sp_item_i2doc_affine(SPItem const *item);
261 /* fixme: - these are evil, but OK */
263 /* Fill *TRANSFORM with the item-to-desktop transform.  See doc/coordinates.txt
264  * for a description of `Desktop coordinates'; though see also mental's comment
265  * at the top of that file.
266  *
267  * \return TRANSFORM.
268  */
269 Geom::Matrix sp_item_i2d_affine(SPItem const *item);
270 void sp_item_set_i2d_affine(SPItem *item, Geom::Matrix const &transform);
271 Geom::Matrix sp_item_dt2i_affine(SPItem const *item);
272 int sp_item_repr_compare_position(SPItem *first, SPItem *second);
273 SPItem *sp_item_first_item_child (SPObject *obj);
275 void sp_item_convert_to_guides(SPItem *item);
277 #endif
279 /*
280   Local Variables:
281   mode:c++
282   c-file-style:"stroustrup"
283   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
284   indent-tabs-mode:nil
285   fill-column:99
286   End:
287 */
288 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :