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
**********************************************************************/
31
#include "rs_entity.h"
32
#include "rs_entitycontainer.h"
37
* Holds the data that defines a polyline.
39
class RS_PolylineData : public RS_Flags {
42
startpoint = endpoint = RS_Vector(false);
44
RS_PolylineData(const RS_Vector& startpoint,
45
const RS_Vector& endpoint,
48
this->startpoint = startpoint;
49
this->endpoint = endpoint;
51
setFlag(RS2::FlagClosed);
55
friend class RS_Polyline;
57
friend std::ostream& operator << (std::ostream& os,
58
const RS_PolylineData& pd) {
59
os << "(" << pd.startpoint <<
73
* Class for a poly line entity (lots of connected lines and arcs).
75
* @author Andrew Mustun
77
class RS_Polyline : public RS_EntityContainer {
79
RS_Polyline(RS_EntityContainer* parent=NULL);
80
RS_Polyline(RS_EntityContainer* parent,
81
const RS_PolylineData& d);
82
virtual ~RS_Polyline();
84
virtual RS_Entity* clone() {
85
RS_Polyline* p = new RS_Polyline(*this);
86
p->setOwner(isOwner());
92
/** @return RS2::EntityPolyline */
93
virtual RS2::EntityType rtti() const {
94
return RS2::EntityPolyline;
97
/** @return Copy of data that defines the polyline. */
98
RS_PolylineData getData() const {
102
/** sets a new start point of the polyline */
103
void setStartpoint(RS_Vector& v) {
105
if (!data.endpoint.valid) {
110
/** @return Start point of the entity */
111
virtual RS_Vector getStartpoint() const {
112
return data.startpoint;
115
/** sets a new end point of the polyline */
116
void setEndpoint(RS_Vector& v) {
120
/** @return End point of the entity */
121
virtual RS_Vector getEndpoint() const {
122
return data.endpoint;
125
double getClosingBulge();
127
void updateEndpoints();
129
/** @return true if the polyline is closed. false otherwise */
130
bool isClosed() const {
131
return data.getFlag(RS2::FlagClosed);
134
void setClosed(bool cl) {
136
data.setFlag(RS2::FlagClosed);
139
data.delFlag(RS2::FlagClosed);
143
void setClosed(bool cl, double bulge);//RLZ: rewrite this:
145
virtual RS_VectorSolutions getRefPoints();
146
virtual RS_Vector getMiddlePoint(void)const {
147
return RS_Vector(false);
149
virtual RS_Vector getNearestRef(const RS_Vector& coord,
150
double* dist = NULL);
151
virtual RS_Vector getNearestSelectedRef(const RS_Vector& coord,
152
double* dist = NULL);
154
virtual RS_Entity* addVertex(const RS_Vector& v,
155
double bulge=0.0, bool prepend=false);
157
void appendVertexs(const QList< QPair<RS_Vector*, double> > vl);
159
virtual void setNextBulge(double bulge) {
162
virtual void addEntity(RS_Entity* entity);
163
//virtual void addSegment(RS_Entity* entity);
164
virtual void removeLastVertex();
165
virtual void endPolyline();
167
//virtual void reorder();
169
virtual bool offset(const RS_Vector& coord, const double& distance);
170
virtual void move(const RS_Vector& offset);
171
virtual void rotate(const RS_Vector& center, const double& angle);
172
virtual void rotate(const RS_Vector& center, const RS_Vector& angleVector);
173
virtual void scale(const RS_Vector& center, const RS_Vector& factor);
174
virtual void mirror(const RS_Vector& axisPoint1, const RS_Vector& axisPoint2);
175
virtual void stretch(const RS_Vector& firstCorner,
176
const RS_Vector& secondCorner,
177
const RS_Vector& offset);
179
virtual void moveRef(const RS_Vector& ref, const RS_Vector& offset);
180
virtual void revertDirection();
183
virtual void draw(RS_Painter* painter, RS_GraphicView* view,
184
double& patternOffset);
186
friend std::ostream& operator << (std::ostream& os, const RS_Polyline& l);
189
virtual RS_Entity* createVertex(const RS_Vector& v,
190
double bulge=0.0, bool prepend=false);
193
RS_PolylineData data;
194
RS_Entity* closingEntity;