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