]> Shamusworld >> Repos - architektonas/blob - src/base/rs_snapper.h
Check in prior to mucking around with preview/snapper rendering...
[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 * catchEntity(const Vector & pos, RS2::ResolveLevel level = RS2::ResolveNone);
52                 RS_Entity * catchEntity(QMouseEvent * e, RS2::ResolveLevel level = RS2::ResolveNone);
53
54                 virtual void suspend();
55                 virtual void resume();
56                 virtual void hideOptions();
57                 virtual void showOptions();
58
59                 void drawSnapper();
60                 void deleteSnapper();
61
62 /*
63 How should we handle this? All rendering goes through the GraphicView (QG_GraphicView to be
64 precise, soon to be merged in) as it should. So shouldn't we control the snapper through
65 that class as well? Unfortunately, all actions derive from this class...
66
67 Should they?
68
69 Not 100% sure. It does seem to make more sense to have them be a part of the GraphicView,
70 since snapping is a function of the grid and the entities contained in the view. (This would
71 also hold for the preview as well.)
72
73 On to the interface:
74
75 For allowing the crosshairs to be drawn, we'd have
76 void ShowSnapper(void)
77
78 and
79 void HideSnapper(void)
80
81 to hide it. Maybe
82 void SetSnapperCoords(Vector, Vector)
83
84 for setting the coordinates?
85 */
86         protected:
87 //              void ShowSnapper(void);
88 //              void HideSnapper(void);
89                 void SetSnapperVisible(bool visibility = true);
90                 void SetSnapperCoords(Vector, Vector);
91
92         private:
93                 void xorSnapper();
94
95         protected:
96                 RS_EntityContainer * container;
97                 GraphicView * graphicView;
98                 RS_Entity * keyEntity;
99                 Vector snapCoord;
100                 Vector snapSpot;
101                 RS2::SnapMode snapMode;
102                 RS2::SnapRestriction snapRes;
103                 /**
104                  * Snap distance for snaping to points with a
105                  * given distance from endpoints.
106                  */
107                 double distance;
108                 /**
109                  * Keeps track of the drawings in XOR mode.
110                  */
111                 bool visible;
112                 /**
113                  * Snap range for catching entities.
114                  */
115                 int snapRange;
116                 /**
117                  * Show large cross hairs.
118                  */
119                 bool showCrosshairs;
120                 bool finished;
121 };
122
123 #endif