1
/****************************************************************************
3
** This file is part of the LibreCAD project, a 2D CAD program
5
** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl)
6
** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
9
** This file may be distributed and/or modified under the terms of the
10
** GNU General Public License version 2 as published by the Free Software
11
** Foundation and appearing in the file gpl-2.0.txt included in the
12
** packaging of this file.
14
** This program is distributed in the hope that it will be useful,
15
** but WITHOUT ANY WARRANTY; without even the implied warranty of
16
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
** GNU General Public License for more details.
19
** You should have received a copy of the GNU General Public License
20
** along with this program; if not, write to the Free Software
21
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23
** This copyright notice MUST APPEAR in all copies of the script!
25
**********************************************************************/
28
//#ifndef RS_SNAPPER_H
29
//#define RS_SNAPPER_H
31
#include "rs_entitycontainer.h"
34
#include "rs_coordinateevent.h"
43
* This class holds information on how to snap the mouse.
49
bool snapFree; /// Whether to snap freely
50
bool snapGrid; /// Whether to snap to grid or not.
51
bool snapEndpoint; /// Whether to snap to endpoints or not.
52
bool snapMiddle; /// Whether to snap to midpoints or not.
53
bool snapDistance; /// Whether to snap to distance from endpoints or not.
54
bool snapCenter; /// Whether to snap to centers or not.
55
bool snapIntersection; /// Whether to snap to intersections or not.
57
bool snapOnEntity; /// Whether to snap to entities or not.
59
RS2::SnapRestriction restriction; /// The restriction on the free snap.
61
double distance; /// The distance to snap before defaulting to free snaping.
66
* Creates a RS_SnapMode that specifies only free snapping.
69
RS_SnapMode() { hardReset(); }
72
* Disable all snapping.
74
* This effectivly puts the object into free snap mode.
76
* @returns A refrence to itself.
78
RS_SnapMode &clear(void) {
86
snapIntersection = false;
88
restriction = RS2::RestrictNothing;
94
* Reset to default settings
96
* @returns A refrence to itself.
98
RS_SnapMode &hardReset(void) {
101
snapEndpoint = false;
103
snapDistance = false;
105
snapOnEntity = false;
106
snapIntersection = false;
108
restriction = RS2::RestrictNothing;
117
* This class is used for snapping functions in a graphic view.
118
* Actions are usually derrived from this base class if they need
119
* to catch entities or snap to coordinates. Use the methods to
120
* retrieve a graphic coordinate from a mouse coordinate.
122
* Possible snapping functions are described in RS_SnapMode.
124
* @author Andrew Mustun
128
RS_Snapper(RS_EntityContainer& container, RS_GraphicView& graphicView);
129
virtual ~RS_Snapper();
135
* @return Pointer to the entity which was the key entity for the
136
* last successful snapping action. If the snap mode is "end point"
137
* the key entity is the entity whos end point was caught.
138
* If the snap mode didn't require an entity (e.g. free, grid) this
139
* method will return NULL.
141
RS_Entity* getKeyEntity() {
145
/** Sets a new snap mode. */
146
void setSnapMode(const RS_SnapMode& snapMode);
148
RS_SnapMode *getSnapMode(void) {
149
return &this->snapMode;
151
/** Sets a new snap restriction. */
152
void setSnapRestriction(RS2::SnapRestriction /*snapRes*/) {
153
//this->snapRes = snapRes;
157
* Sets the snap range in pixels for catchEntity().
161
void setSnapRange(int r) {
165
/**manually set snapPoint*/
166
RS_Vector snapPoint(const RS_Vector& coord, bool setSpot = false);
167
RS_Vector snapPoint(QMouseEvent* e);
168
RS_Vector snapFree(QMouseEvent* e);
170
RS_Vector snapFree(const RS_Vector& coord);
171
RS_Vector snapGrid(const RS_Vector& coord);
172
RS_Vector snapEndpoint(const RS_Vector& coord);
173
RS_Vector snapOnEntity(const RS_Vector& coord);
174
RS_Vector snapCenter(const RS_Vector& coord);
175
RS_Vector snapMiddle(const RS_Vector& coord);
176
RS_Vector snapDist(const RS_Vector& coord);
177
RS_Vector snapIntersection(const RS_Vector& coord);
178
//RS_Vector snapDirect(RS_Vector coord, bool abs);
180
RS_Vector restrictOrthogonal(const RS_Vector& coord);
181
RS_Vector restrictHorizontal(const RS_Vector& coord);
182
RS_Vector restrictVertical(const RS_Vector& coord);
185
//RS_Entity* catchLeafEntity(const RS_Vector& pos);
186
//RS_Entity* catchLeafEntity(QMouseEvent* e);
187
RS_Entity* catchEntity(const RS_Vector& pos,
188
RS2::ResolveLevel level=RS2::ResolveNone);
189
RS_Entity* catchEntity(QMouseEvent* e,
190
RS2::ResolveLevel level=RS2::ResolveNone);
191
// catch Entity closest to pos and of the given entity type of enType, only search for a particular entity type
192
RS_Entity* catchEntity(const RS_Vector& pos, RS2::EntityType enType,
193
RS2::ResolveLevel level=RS2::ResolveNone);
194
RS_Entity* catchEntity(QMouseEvent* e, RS2::EntityType enType,
195
RS2::ResolveLevel level=RS2::ResolveNone);
196
RS_Entity* catchEntity(QMouseEvent* e, const QVector<RS2::EntityType>& enTypeList,
197
RS2::ResolveLevel level=RS2::ResolveNone);
200
* Suspends this snapper while another action takes place.
202
virtual void suspend() {
203
// RVT Don't delete the snapper here!
204
// RVT_PORT (can be deleted)();
205
snapSpot = snapCoord = RS_Vector(false);
209
* Resumes this snapper after it has been suspended.
211
virtual void resume() {
215
virtual void hideOptions();
216
virtual void showOptions();
219
static unsigned int snapModeToInt(const RS_SnapMode& s);
220
static RS_SnapMode intToSnapMode(unsigned int);
223
void deleteSnapper();
224
double getSnapRange() const;
225
RS_EntityContainer* container;
226
RS_GraphicView* graphicView;
227
RS_Entity* keyEntity;
230
RS_SnapMode snapMode;
231
//RS2::SnapRestriction snapRes;
233
* Snap distance for snaping to points with a
234
* given distance from endpoints.
238
* Snap to equidistant middle points
239
* default to 1, i.e., equidistant to start/end points
243
* Snap range for catching entities.
247
* Show large cross hairs.