1 /****************************************************************************
2 **
3 ** This file is part of the LibreCAD project, a 2D CAD program
4 **
5 
6 Copyright (C) 2012-2015 Dongxu Li (dongxuli2011@gmail.com)
7 
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
12 
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 
22 **********************************************************************/
23 
24 #include "rs_atomicentity.h"
RS_AtomicEntity(RS_EntityContainer * parent)25 RS_AtomicEntity::RS_AtomicEntity(RS_EntityContainer* parent) : RS_Entity(parent) {}
26 
isContainer() const27 bool RS_AtomicEntity::isContainer() const {
28 	return false;
29 }
30 
31 /**
32  * @return true because entities made from subclasses are
33  *  atomic entities.
34  */
isAtomic() const35 bool RS_AtomicEntity::isAtomic() const {
36 	return true;
37 }
38 
39 /**
40  * @return Always 1 for atomic entities.
41  */
count() const42 unsigned int RS_AtomicEntity::count() const{
43 	return 1;
44 }
45 
46 /**
47  * @return Always 1 for atomic entities.
48  */
countDeep() const49 unsigned int RS_AtomicEntity::countDeep() const{
50 	return 1;
51 }
52 
53 /**
54  * Implementation must return the endpoint of the entity or
55  * an invalid vector if the entity has no endpoint.
56  */
getEndpoint() const57 RS_Vector RS_AtomicEntity::getEndpoint() const {
58 	return RS_Vector(false);
59 }
60 
61 /**
62  * Implementation must return the startpoint of the entity or
63  * an invalid vector if the entity has no startpoint.
64  */
getStartpoint() const65 RS_Vector RS_AtomicEntity::getStartpoint() const {
66 	return RS_Vector(false);
67 }
68 
69 /**
70  * Implementation must return the angle in which direction the entity starts.
71  */
getDirection1() const72 double RS_AtomicEntity::getDirection1() const {
73 	return 0.0;
74 }
75 
76 /**
77  * Implementation must return the angle in which direction the entity starts the opposite way.
78  */
getDirection2() const79 double RS_AtomicEntity::getDirection2() const {
80 	return 0.0;
81 }
getCenter() const82 RS_Vector RS_AtomicEntity::getCenter() const {
83 	return RS_Vector(false);
84 }
getRadius() const85 double RS_AtomicEntity::getRadius() const {
86 	   return 0.;
87    }
88 /**
89 * return the nearest center for snapping
90 * @param coord Coordinate (typically a mouse coordinate)
91 * @param dist Pointer to a value which will contain the measured
92 * distance between 'coord' and the closest center point. The passed
93 * pointer can also be NULL in which case the distance will be
94 * lost.
95 *
96 * @return The closest center point.
97 */
getNearestCenter(const RS_Vector &,double *) const98 RS_Vector RS_AtomicEntity::getNearestCenter(const RS_Vector& /*coord*/,
99 								  double* /*dist*/) const{
100 	return RS_Vector(false);
101 }
102 
103 /**
104  * (De-)selects startpoint.
105  */
setStartpointSelected(bool select)106 void RS_AtomicEntity::setStartpointSelected(bool select) {
107 	if (select) {
108 		setFlag(RS2::FlagSelected1);
109 	} else {
110 		delFlag(RS2::FlagSelected1);
111 	}
112 }
113 
114 /**
115  * (De-)selects endpoint.
116  */
setEndpointSelected(bool select)117 void RS_AtomicEntity::setEndpointSelected(bool select) {
118 	if (select) {
119 		setFlag(RS2::FlagSelected2);
120 	} else {
121 		delFlag(RS2::FlagSelected2);
122 	}
123 }
isTangent(const RS_CircleData &) const124 bool RS_AtomicEntity::isTangent(const RS_CircleData& /* circleData */) const{
125 	return false;
126 }
127 
128 /**
129  * @return True if the entities startpoint is selected.
130  */
isStartpointSelected() const131 bool RS_AtomicEntity::isStartpointSelected() const {
132 	return getFlag(RS2::FlagSelected1);
133 }
134 
135 /**
136  * @return True if the entities endpoint is selected.
137  */
isEndpointSelected() const138 bool RS_AtomicEntity::isEndpointSelected() const {
139 	return getFlag(RS2::FlagSelected2);
140 }
141 
revertDirection()142 void RS_AtomicEntity::revertDirection(){}
143 
144 /**
145  * Implementation must create offset of the entity to
146  * the given direction and distance
147  */
offset(const RS_Vector &,const double &)148 bool RS_AtomicEntity::offset(const RS_Vector& /*position*/, const double& /*distance*/) {return false;}
149 
150 /**
151  * Implementation must move the startpoint of the entity to
152  * the given position.
153  */
moveStartpoint(const RS_Vector &)154 void RS_AtomicEntity::moveStartpoint(const RS_Vector& /*pos*/) {}
155 
156 /**
157  * Implementation must move the endpoint of the entity to
158  * the given position.
159  */
moveEndpoint(const RS_Vector &)160 void RS_AtomicEntity::moveEndpoint(const RS_Vector& /*pos*/) {}
161 
162 /**
163  * Implementation must trim the startpoint of the entity to
164  * the given position.
165  */
trimStartpoint(const RS_Vector & pos)166 void RS_AtomicEntity::trimStartpoint(const RS_Vector& pos) {
167 	moveStartpoint(pos);
168 }
169 
170 /**
171  * Implementation must trim the endpoint of the entity to
172  * the given position.
173  */
trimEndpoint(const RS_Vector & pos)174 void RS_AtomicEntity::trimEndpoint(const RS_Vector& pos) {
175 	moveEndpoint(pos);
176 }
177 
178 /**
179  * Implementation must return which ending of the entity will
180  * be trimmed if 'coord' is the coordinate chosen to indicate the
181  * trim entity and 'trimPoint' is the point to which the entity will
182  * be trimmed.
183  */
getTrimPoint(const RS_Vector &,const RS_Vector &)184 RS2::Ending RS_AtomicEntity::getTrimPoint(const RS_Vector& /*coord*/,
185 								 const RS_Vector& /*trimPoint*/) {
186 	return RS2::EndingNone;
187 }
188 
189 /**
190  * Implementation must trim the entity in the case of multiple
191  * intersections and return the trimPoint
192  * trimCoord indicts the trigger trim position
193  * trimSol contains intersections
194  * */
prepareTrim(const RS_Vector &,const RS_VectorSolutions &)195 RS_Vector RS_AtomicEntity::prepareTrim(const RS_Vector& /*trimCoord*/,
196 							  const RS_VectorSolutions& /*trimSol*/) {
197 	return RS_Vector(false);
198 }
199 
reverse()200 void RS_AtomicEntity::reverse() {}
201 
moveSelectedRef(const RS_Vector & ref,const RS_Vector & offset)202 void RS_AtomicEntity::moveSelectedRef(const RS_Vector& ref, const RS_Vector& offset) {
203 	if (isSelected()) {
204 		moveRef(ref, offset);
205 	}
206 }
207