]> Shamusworld >> Repos - architektonas/blob - src/base/rs_snapper.h
In the middle of major refactoring...
[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 class PaintInterface;
12
13 /**
14  * This class is used for snapping functions in a graphic view.
15  * Actions are usually derrived from this base class if they need
16  * to catch entities or snap to coordinates. Use the methods to
17  * retrieve a graphic coordinate from a mouse coordinate.
18  *
19  * Possible snapping functions are described in RS_SnapMode.
20  *
21  * @author Andrew Mustun
22  */
23 class RS_Snapper
24 {
25         public:
26                 RS_Snapper(RS_EntityContainer & container, GraphicView & graphicView);
27                 RS_Snapper();
28                 virtual ~RS_Snapper();
29
30                 void init();
31                 void finish();
32
33                 void SetContainer(RS_EntityContainer *);
34                 void SetGraphicView(GraphicView *);
35                 RS_Entity * getKeyEntity();
36                 void setSnapMode(RS2::SnapMode snapMode);
37                 void setSnapRestriction(RS2::SnapRestriction snapRes);
38                 void setSnapRange(int r);
39
40                 Vector snapPoint(QMouseEvent * e);
41                 Vector snapFree(Vector coord);
42                 Vector snapEndpoint(Vector coord);
43                 Vector snapGrid(Vector coord);
44                 Vector snapOnEntity(Vector coord);
45                 Vector snapCenter(Vector coord);
46                 Vector snapMiddle(Vector coord);
47                 Vector snapDist(Vector coord);
48                 Vector snapIntersection(Vector coord);
49                 //Vector snapDirect(Vector coord, bool abs);
50
51                 Vector restrictOrthogonal(Vector coord);
52                 Vector restrictHorizontal(Vector coord);
53                 Vector restrictVertical(Vector coord);
54
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 /*
67 How should we handle this? All rendering goes through the GraphicView (QG_GraphicView to be
68 precise, soon to be merged in) as it should. So shouldn't we control the snapper through
69 that class as well? Unfortunately, all actions derive from this class...
70
71 Should they?
72
73 Not 100% sure. It does seem to make more sense to have them be a part of the GraphicView,
74 since snapping is a function of the grid and the entities contained in the view. (This would
75 also hold for the preview as well.)
76
77 On to the interface:
78
79 For allowing the crosshairs to be drawn, we'd have
80 void ShowSnapper(void)
81
82 and
83 void HideSnapper(void)
84
85 to hide it. Maybe
86 void SetSnapperCoords(Vector, Vector)
87
88 for setting the coordinates?
89 */
90         public://for now
91                 void SetVisible(bool visibility = true);
92                 bool Visible(void);
93                 void Draw(GraphicView *, PaintInterface *);
94
95         private:
96                 void xorSnapper();
97
98         protected:
99                 RS_EntityContainer * container;
100                 GraphicView * graphicView;
101                 RS_Entity * keyEntity;
102                 Vector snapCoord;
103                 Vector snapSpot;
104                 RS2::SnapMode snapMode;
105                 RS2::SnapRestriction snapRes;
106                 /**
107                  * Snap distance for snaping to points with a
108                  * given distance from endpoints.
109                  */
110                 double distance;
111                 /**
112                  * Keeps track of the drawings in XOR mode.
113                  */
114                 bool visible;
115                 /**
116                  * Snap range for catching entities.
117                  */
118                 int snapRange;
119                 /**
120                  * Show large cross hairs.
121                  */
122                 bool showCrosshairs;
123                 bool finished;
124 };
125
126 #endif