]> git.tdb.fi Git - r2c2.git/blob - source/libr2c2/object.h
33b99a1443acb3b2f7452c8236e91354ab5ed8a4
[r2c2.git] / source / libr2c2 / object.h
1 #ifndef LIBR2C2_OBJECT_H_
2 #define LIBR2C2_OBJECT_H_
3
4 #include "geometry.h"
5 #include "objecttype.h"
6 #include "snap.h"
7
8 namespace R2C2 {
9
10 class Layout;
11
12 class Object
13 {
14 protected:
15         Layout &layout;
16         Vector position;
17         float rotation;
18
19         Object(Layout &l): layout(l) { }
20 public:
21         virtual ~Object() { }
22
23         virtual Object *clone(Layout * = 0) const = 0;
24         virtual const ObjectType &get_type() const = 0;
25         Layout &get_layout() const { return layout; }
26         virtual void set_position(const Vector &) = 0;
27         virtual void set_rotation(float) = 0;
28         const Vector &get_position() const { return position; }
29         float get_rotation() const { return rotation; }
30         virtual Object *get_parent() const { return 0; }
31
32         virtual unsigned get_n_snap_nodes() const { return 0; }
33         virtual Snap get_snap_node(unsigned) const;
34         virtual bool snap(Snap &, float, SnapType = SNAP_DEFAULT) const;
35         virtual bool snap_to(const Object &, float, SnapType = SNAP_DEFAULT);
36 protected:
37         virtual SnapType get_default_snap_type_to(const Object &) const { return NO_SNAP; }
38
39 public:
40         virtual unsigned get_n_link_slots() const { return 0; }
41         virtual Object *get_link(unsigned) const;
42         virtual int get_link_slot(const Object &) const { return -1; }
43         virtual bool link_to(Object &) { return false; }
44         virtual bool break_link(Object &);
45         virtual bool break_link(unsigned) { return false; }
46         virtual void break_links();
47
48         virtual bool collide_ray(const Vector &, const Vector &) const = 0;
49 };
50
51 } // namespace R2C2
52
53 #endif