~librecad-dev/librecad/librecad

« back to all changes in this revision

Viewing changes to librecad/src/lib/engine/rs_polyline.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_POLYLINE_H
 
29
#define RS_POLYLINE_H
 
30
 
 
31
#include "rs_entity.h"
 
32
#include "rs_entitycontainer.h"
 
33
 
 
34
 
 
35
 
 
36
/**
 
37
 * Holds the data that defines a polyline.
 
38
 */
 
39
class RS_PolylineData : public RS_Flags {
 
40
public:
 
41
    RS_PolylineData() {
 
42
        startpoint = endpoint = RS_Vector(false);
 
43
    }
 
44
    RS_PolylineData(const RS_Vector& startpoint,
 
45
                    const RS_Vector& endpoint,
 
46
                    bool closed) {
 
47
 
 
48
        this->startpoint = startpoint;
 
49
        this->endpoint = endpoint;
 
50
        if (closed==true) {
 
51
            setFlag(RS2::FlagClosed);
 
52
        }
 
53
    }
 
54
 
 
55
    friend class RS_Polyline;
 
56
 
 
57
    friend std::ostream& operator << (std::ostream& os,
 
58
                                      const RS_PolylineData& pd) {
 
59
        os << "(" << pd.startpoint <<
 
60
        "/" << pd.endpoint <<
 
61
        ")";
 
62
        return os;
 
63
    }
 
64
 
 
65
private:
 
66
    RS_Vector startpoint;
 
67
    RS_Vector endpoint;
 
68
};
 
69
 
 
70
 
 
71
 
 
72
/**
 
73
 * Class for a poly line entity (lots of connected lines and arcs).
 
74
 *
 
75
 * @author Andrew Mustun
 
76
 */
 
77
class RS_Polyline : public RS_EntityContainer {
 
78
public:
 
79
    RS_Polyline(RS_EntityContainer* parent=NULL);
 
80
    RS_Polyline(RS_EntityContainer* parent,
 
81
                const RS_PolylineData& d);
 
82
    virtual ~RS_Polyline();
 
83
 
 
84
    virtual RS_Entity* clone() {
 
85
        RS_Polyline* p = new RS_Polyline(*this);
 
86
        p->setOwner(isOwner());
 
87
        p->initId();
 
88
        p->detach();
 
89
        return p;
 
90
    }
 
91
 
 
92
    /** @return RS2::EntityPolyline */
 
93
    virtual RS2::EntityType rtti() const {
 
94
        return RS2::EntityPolyline;
 
95
    }
 
96
 
 
97
    /** @return Copy of data that defines the polyline. */
 
98
    RS_PolylineData getData() const {
 
99
        return data;
 
100
    }
 
101
 
 
102
    /** sets a new start point of the polyline */
 
103
    void setStartpoint(RS_Vector& v) {
 
104
        data.startpoint = v;
 
105
        if (!data.endpoint.valid) {
 
106
            data.endpoint = v;
 
107
        }
 
108
    }
 
109
 
 
110
    /** @return Start point of the entity */
 
111
    virtual RS_Vector getStartpoint() const {
 
112
        return data.startpoint;
 
113
    }
 
114
 
 
115
    /** sets a new end point of the polyline */
 
116
    void setEndpoint(RS_Vector& v) {
 
117
        data.endpoint = v;
 
118
    }
 
119
 
 
120
    /** @return End point of the entity */
 
121
    virtual RS_Vector getEndpoint() const {
 
122
        return data.endpoint;
 
123
    }
 
124
 
 
125
        double getClosingBulge();
 
126
 
 
127
        void updateEndpoints();
 
128
 
 
129
    /** @return true if the polyline is closed. false otherwise */
 
130
    bool isClosed() const {
 
131
        return data.getFlag(RS2::FlagClosed);
 
132
    }
 
133
 
 
134
        void setClosed(bool cl) {
 
135
                if (cl) {
 
136
                        data.setFlag(RS2::FlagClosed);
 
137
                }
 
138
                else {
 
139
                        data.delFlag(RS2::FlagClosed);
 
140
                }
 
141
        }
 
142
 
 
143
    void setClosed(bool cl, double bulge);//RLZ: rewrite this:
 
144
 
 
145
    virtual RS_VectorSolutions getRefPoints();
 
146
    virtual RS_Vector getMiddlePoint(void)const {
 
147
            return RS_Vector(false);
 
148
    }
 
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);
 
153
 
 
154
    virtual RS_Entity* addVertex(const RS_Vector& v,
 
155
                double bulge=0.0, bool prepend=false);
 
156
 
 
157
    void appendVertexs(const QList< QPair<RS_Vector*, double> > vl);
 
158
 
 
159
        virtual void setNextBulge(double bulge) {
 
160
                nextBulge = bulge;
 
161
        }
 
162
    virtual void addEntity(RS_Entity* entity);
 
163
    //virtual void addSegment(RS_Entity* entity);
 
164
    virtual void removeLastVertex();
 
165
    virtual void endPolyline();
 
166
 
 
167
    //virtual void reorder();
 
168
 
 
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);
 
178
 
 
179
    virtual void moveRef(const RS_Vector& ref, const RS_Vector& offset);
 
180
        virtual void revertDirection();
 
181
 
 
182
 
 
183
    virtual void draw(RS_Painter* painter, RS_GraphicView* view,
 
184
                      double& patternOffset);
 
185
 
 
186
    friend std::ostream& operator << (std::ostream& os, const RS_Polyline& l);
 
187
 
 
188
protected:
 
189
    virtual RS_Entity* createVertex(const RS_Vector& v,
 
190
                double bulge=0.0, bool prepend=false);
 
191
 
 
192
protected:
 
193
    RS_PolylineData data;
 
194
    RS_Entity* closingEntity;
 
195
        double nextBulge;
 
196
};
 
197
 
 
198
#endif