]> Shamusworld >> Repos - architektonas/blob - src/base/rs_snapper.h
baceae4dd893aba95259034c76de263c2b179379
[architektonas] / src / base / rs_snapper.h
1 #ifndef RS_SNAPPER_H
2 #define RS_SNAPPER_H
3
4 #include <QtCore>
5
6 #include "rs.h"
7 #include "rs_entitycontainer.h"
8 #include "rs_coordinateevent.h"
9
10 class RS_Entity;
11 class RS_GraphicView;
12 class Vector;
13
14 /**
15  * This class is used for snapping functions in a graphic view.
16  * Actions are usually derrived from this base class if they need
17  * to catch entities or snap to coordinates. Use the methods to
18  * retrieve a graphic coordinate from a mouse coordinate.
19  *
20  * Possible snapping functions are described in RS_SnapMode.
21  *
22  * @author Andrew Mustun
23  */
24 class RS_Snapper
25 {
26         public:
27                 RS_Snapper(RS_EntityContainer & container, RS_GraphicView & graphicView);
28                 virtual ~RS_Snapper();
29
30                 void init();
31                 void finish();
32
33                 RS_Entity * getKeyEntity();
34                 void setSnapMode(RS2::SnapMode snapMode);
35                 void setSnapRestriction(RS2::SnapRestriction snapRes);
36                 void setSnapRange(int r);
37
38                 Vector snapPoint(QMouseEvent * e);
39                 Vector snapFree(Vector coord);
40                 Vector snapEndpoint(Vector coord);
41                 Vector snapGrid(Vector coord);
42                 Vector snapOnEntity(Vector coord);
43                 Vector snapCenter(Vector coord);
44                 Vector snapMiddle(Vector coord);
45                 Vector snapDist(Vector coord);
46                 Vector snapIntersection(Vector coord);
47                 //Vector snapDirect(Vector coord, bool abs);
48
49                 Vector restrictOrthogonal(Vector coord);
50                 Vector restrictHorizontal(Vector coord);
51                 Vector restrictVertical(Vector coord);
52
53                 //RS_Entity* catchLeafEntity(const Vector& pos);
54                 //RS_Entity* catchLeafEntity(QMouseEvent* e);
55                 RS_Entity * catchEntity(const Vector & pos, RS2::ResolveLevel level = RS2::ResolveNone);
56                 RS_Entity * catchEntity(QMouseEvent * e, RS2::ResolveLevel level = RS2::ResolveNone);
57
58                 virtual void suspend();
59                 virtual void resume();
60                 virtual void hideOptions();
61                 virtual void showOptions();
62
63                 void drawSnapper();
64                 void deleteSnapper();
65
66         private:
67                 void xorSnapper();
68
69         protected:
70                 RS_EntityContainer * container;
71                 RS_GraphicView * graphicView;
72                 RS_Entity * keyEntity;
73                 Vector snapCoord;
74                 Vector snapSpot;
75                 RS2::SnapMode snapMode;
76                 RS2::SnapRestriction snapRes;
77                 /**
78                  * Snap distance for snaping to points with a
79                  * given distance from endpoints.
80                  */
81                 double distance;
82                 /**
83                  * Keeps track of the drawings in XOR mode.
84                  */
85                 bool visible;
86                 /**
87                  * Snap range for catching entities.
88                  */
89                 int snapRange;
90                 /**
91                  * Show large cross hairs.
92                  */
93                 bool showCrosshairs;
94                 bool finished;
95 };
96
97 #endif