~librecad-dev/librecad/librecad

« back to all changes in this revision

Viewing changes to librecad/src/lib/engine/rs_atomicentity.h

  • Committer: Scott Howard
  • Date: 2014-02-21 19:07:55 UTC
  • Revision ID: showard@debian.org-20140221190755-csjax9wb146hgdq4
first commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** This file is part of the LibreCAD project, a 2D CAD program
 
4
**
 
5
** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl)
 
6
** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
 
7
**
 
8
**
 
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.
 
13
**
 
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.
 
18
**
 
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
 
22
**
 
23
** This copyright notice MUST APPEAR in all copies of the script!
 
24
**
 
25
**********************************************************************/
 
26
 
 
27
 
 
28
#ifndef RS_ATOMICENTITY_H
 
29
#define RS_ATOMICENTITY_H
 
30
 
 
31
#include "rs_entity.h"
 
32
 
 
33
class RS_CircleData;
 
34
 
 
35
/**
 
36
 * Class representing an atomic entity
 
37
 * Typical atomic entities: RS_Line, RS_Arc, RS_Circle, RS_Ellipse
 
38
 *
 
39
 * @author Andrew Mustun
 
40
 */
 
41
class RS_AtomicEntity : public RS_Entity {
 
42
 
 
43
public:
 
44
    /**
 
45
     * Construtor.
 
46
     */
 
47
    RS_AtomicEntity(RS_EntityContainer* parent=NULL) : RS_Entity(parent) {}
 
48
    /**
 
49
     * Destrutor.
 
50
     */
 
51
    virtual ~RS_AtomicEntity() {}
 
52
 
 
53
    /**
 
54
     * @return false because entities made from subclasses are
 
55
     *  atomic entities.
 
56
     */
 
57
    virtual bool isContainer() const {
 
58
        return false;
 
59
    }
 
60
 
 
61
    /**
 
62
     * @return true because entities made from subclasses are
 
63
     *  atomic entities.
 
64
     */
 
65
    virtual bool isAtomic() const {
 
66
        return true;
 
67
    }
 
68
 
 
69
    /**
 
70
     * @return Always 1 for atomic entities.
 
71
     */
 
72
    virtual unsigned int count() {
 
73
        return 1;
 
74
    }
 
75
 
 
76
    /**
 
77
     * @return Always 1 for atomic entities.
 
78
     */
 
79
    virtual unsigned int countDeep() {
 
80
        return 1;
 
81
    }
 
82
 
 
83
    /**
 
84
     * Implementation must return the endpoint of the entity or
 
85
     * an invalid vector if the entity has no endpoint.
 
86
     */
 
87
    virtual RS_Vector getEndpoint() const {
 
88
        return RS_Vector(false);
 
89
    }
 
90
 
 
91
    /**
 
92
     * Implementation must return the startpoint of the entity or
 
93
     * an invalid vector if the entity has no startpoint.
 
94
     */
 
95
    virtual RS_Vector getStartpoint() const {
 
96
        return RS_Vector(false);
 
97
    }
 
98
 
 
99
    /**
 
100
     * Implementation must return the angle in which direction the entity starts.
 
101
     */
 
102
    virtual double getDirection1() const {
 
103
        return 0.0;
 
104
    }
 
105
 
 
106
    /**
 
107
     * Implementation must return the angle in which direction the entity starts the opposite way.
 
108
     */
 
109
    virtual double getDirection2() const {
 
110
        return 0.0;
 
111
    }
 
112
 virtual RS_Vector getCenter() const {
 
113
        return RS_Vector(false);
 
114
    }
 
115
    virtual double getRadius() const {
 
116
           return 0.;
 
117
       }
 
118
    /**
 
119
    * return the nearest center for snapping
 
120
    * @param coord Coordinate (typically a mouse coordinate)
 
121
    * @param dist Pointer to a value which will contain the measured
 
122
    * distance between 'coord' and the closest center point. The passed
 
123
    * pointer can also be NULL in which case the distance will be
 
124
    * lost.
 
125
    *
 
126
    * @return The closest center point.
 
127
    */
 
128
   virtual RS_Vector getNearestCenter(const RS_Vector& /*coord*/,
 
129
                                      double* /*dist*/) {
 
130
        return RS_Vector(false);
 
131
    }
 
132
 
 
133
    /**
 
134
     * (De-)selects startpoint.
 
135
     */
 
136
    virtual void setStartpointSelected(bool select) {
 
137
        if (select) {
 
138
            setFlag(RS2::FlagSelected1);
 
139
        } else {
 
140
            delFlag(RS2::FlagSelected1);
 
141
        }
 
142
    }
 
143
 
 
144
    /**
 
145
     * (De-)selects endpoint.
 
146
     */
 
147
    virtual void setEndpointSelected(bool select) {
 
148
        if (select) {
 
149
            setFlag(RS2::FlagSelected2);
 
150
        } else {
 
151
            delFlag(RS2::FlagSelected2);
 
152
        }
 
153
    }
 
154
    virtual bool isTangent(const RS_CircleData& /* circleData */) {
 
155
        return false;
 
156
    }
 
157
 
 
158
    /**
 
159
     * @return True if the entities startpoint is selected.
 
160
     */
 
161
    bool isStartpointSelected() const {
 
162
        return getFlag(RS2::FlagSelected1);
 
163
    }
 
164
 
 
165
    /**
 
166
     * @return True if the entities endpoint is selected.
 
167
     */
 
168
    bool isEndpointSelected() const {
 
169
        return getFlag(RS2::FlagSelected2);
 
170
    }
 
171
 
 
172
    virtual void revertDirection(){}
 
173
 
 
174
    /**
 
175
     * Implementation must create offset of the entity to
 
176
     * the given direction and distance
 
177
     */
 
178
    virtual bool offset(const RS_Vector& /*position*/, const double& /*distance*/) {return false;}
 
179
 
 
180
    /**
 
181
     * Implementation must move the startpoint of the entity to
 
182
     * the given position.
 
183
     */
 
184
    virtual void moveStartpoint(const RS_Vector& /*pos*/) {}
 
185
 
 
186
    /**
 
187
     * Implementation must move the endpoint of the entity to
 
188
     * the given position.
 
189
     */
 
190
    virtual void moveEndpoint(const RS_Vector& /*pos*/) {}
 
191
 
 
192
    /**
 
193
     * Implementation must trim the startpoint of the entity to
 
194
     * the given position.
 
195
     */
 
196
    virtual void trimStartpoint(const RS_Vector& pos) {
 
197
        moveStartpoint(pos);
 
198
    }
 
199
 
 
200
    /**
 
201
     * Implementation must trim the endpoint of the entity to
 
202
     * the given position.
 
203
     */
 
204
    virtual void trimEndpoint(const RS_Vector& pos) {
 
205
        moveEndpoint(pos);
 
206
    }
 
207
 
 
208
    /**
 
209
     * Implementation must return which ending of the entity will
 
210
     * be trimmed if 'coord' is the coordinate chosen to indicate the
 
211
     * trim entity and 'trimPoint' is the point to which the entity will
 
212
     * be trimmed.
 
213
     */
 
214
    virtual RS2::Ending getTrimPoint(const RS_Vector& /*coord*/,
 
215
                                     const RS_Vector& /*trimPoint*/) {
 
216
        return RS2::EndingNone;
 
217
    }
 
218
 
 
219
    /**
 
220
     * Implementation must trim the entity in the case of multiple
 
221
     * intersections and return the trimPoint
 
222
     * trimCoord indicts the trigger trim position
 
223
     * trimSol contains intersections
 
224
     * */
 
225
    virtual RS_Vector prepareTrim(const RS_Vector& /*trimCoord*/,
 
226
                                  const RS_VectorSolutions& /*trimSol*/) {
 
227
        return RS_Vector(false);
 
228
    }
 
229
 
 
230
    virtual void reverse() { }
 
231
 
 
232
    virtual void moveSelectedRef(const RS_Vector& ref, const RS_Vector& offset) {
 
233
        if (isSelected()) {
 
234
            moveRef(ref, offset);
 
235
        }
 
236
    }
 
237
}
 
238
;
 
239
 
 
240
 
 
241
#endif