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