~librecad-dev/librecad/librecad

« back to all changes in this revision

Viewing changes to librecad/src/lib/engine/rs_image.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_IMAGE_H
 
29
#define RS_IMAGE_H
 
30
 
 
31
#include <QImage>
 
32
#include "rs_atomicentity.h"
 
33
 
 
34
/**
 
35
 * Holds the data that defines a line.
 
36
 */
 
37
class RS_ImageData {
 
38
public:
 
39
    /**
 
40
     * Default constructor. Leaves the data object uninitialized.
 
41
     */
 
42
    RS_ImageData() {}
 
43
 
 
44
    RS_ImageData(int handle,
 
45
                                const RS_Vector& insertionPoint,
 
46
                const RS_Vector& uVector,
 
47
                                const RS_Vector& vVector,
 
48
                                const RS_Vector& size,
 
49
                                const QString& file,
 
50
                                int brightness,
 
51
                                int contrast,
 
52
                                int fade) {
 
53
 
 
54
                this->handle = handle;
 
55
        this->insertionPoint = insertionPoint;
 
56
        this->uVector = uVector;
 
57
        this->vVector = vVector;
 
58
        this->size = size;
 
59
        this->file = file;
 
60
                this->brightness = brightness;
 
61
                this->contrast = contrast;
 
62
                this->fade = fade;
 
63
    }
 
64
 
 
65
    friend std::ostream& operator << (std::ostream& os, const RS_ImageData& ld) {
 
66
        os << "(" << ld.insertionPoint << ")";
 
67
        return os;
 
68
    }
 
69
 
 
70
public:
 
71
        /** Handle of image definition. */
 
72
        int handle;
 
73
        /** Insertion point. */
 
74
    RS_Vector insertionPoint;
 
75
        /** u vector. Points along visual bottom of image. */
 
76
    RS_Vector uVector;
 
77
        /** v vector. Points along visual left of image. */
 
78
    RS_Vector vVector;
 
79
        /** Image size in pixel. */
 
80
        RS_Vector size;
 
81
        /** Path to image file. */
 
82
        QString file;
 
83
        /** Brightness (0..100, default: 50). */
 
84
        int brightness;
 
85
        /** Contrast (0..100, default: 50). */
 
86
        int contrast;
 
87
        /** Fade (0..100, default: 0). */
 
88
        int fade;
 
89
};
 
90
 
 
91
 
 
92
 
 
93
/**
 
94
 * Class for a line entity.
 
95
 *
 
96
 * @author Andrew Mustun
 
97
 */
 
98
class RS_Image : public RS_AtomicEntity {
 
99
public:
 
100
    RS_Image(RS_EntityContainer* parent,
 
101
            const RS_ImageData& d);
 
102
 
 
103
    virtual RS_Entity* clone();
 
104
 
 
105
    virtual ~RS_Image();
 
106
 
 
107
    /** @return RS2::EntityImage */
 
108
    virtual RS2::EntityType rtti() const {
 
109
        return RS2::EntityImage;
 
110
    }
 
111
 
 
112
        virtual void update();
 
113
 
 
114
    /** @return Copy of data that defines the image. */
 
115
    RS_ImageData getData() const {
 
116
        return data;
 
117
    }
 
118
 
 
119
    /** @return Insertion point of the entity */
 
120
    virtual RS_Vector getInsertionPoint() const {
 
121
        return data.insertionPoint;
 
122
    }
 
123
    /** Sets the insertion point for the image. */
 
124
    void setInsertionPoint(RS_Vector ip) {
 
125
        data.insertionPoint = ip;
 
126
        calculateBorders();
 
127
    }
 
128
 
 
129
    /** Update image data ONLY for plugins. */
 
130
    void updateData(RS_Vector size, RS_Vector Uv, RS_Vector Vv);
 
131
 
 
132
        /** @return File name of the image. */
 
133
        QString getFile() const {
 
134
                return data.file;
 
135
        }
 
136
 
 
137
        /** Sets the file name of the image.  */
 
138
        void setFile(const QString& file) {
 
139
                data.file = file;
 
140
        }
 
141
 
 
142
        /** @return u Vector. Points along bottom, 1 pixel long. */
 
143
        RS_Vector getUVector() const {
 
144
                return data.uVector;
 
145
        }
 
146
        /** @return v Vector. Points along left, 1 pixel long. */
 
147
        RS_Vector getVVector() const {
 
148
                return data.vVector;
 
149
        }
 
150
        /** @return Width of image in pixels. */
 
151
        int getWidth() const {
 
152
                return (int)data.size.x;
 
153
        }
 
154
        /** @return Height of image in pixels. */
 
155
        int getHeight() const {
 
156
                return (int)data.size.y;
 
157
        }
 
158
        /** @return Brightness. */
 
159
        int getBrightness() const {
 
160
                return data.brightness;
 
161
        }
 
162
        /** @return Contrast. */
 
163
        int getContrast() const {
 
164
                return data.contrast;
 
165
        }
 
166
        /** @return Fade. */
 
167
        int getFade() const {
 
168
                return data.fade;
 
169
        }
 
170
        /** @return Image definition handle. */
 
171
        int getHandle() const {
 
172
                return data.handle;
 
173
        }
 
174
        /** Sets the image definition handle. */
 
175
        void setHandle(int h) {
 
176
                data.handle = h;
 
177
        }
 
178
 
 
179
 
 
180
        /** @return The four corners. **/
 
181
        RS_VectorSolutions getCorners() const;
 
182
 
 
183
        /**
 
184
         * @return image with in graphic units.
 
185
         */
 
186
        double getImageWidth() {
 
187
                return data.size.x * data.uVector.magnitude();
 
188
        }
 
189
 
 
190
        /**
 
191
         * @return image height in graphic units.
 
192
         */
 
193
        double getImageHeight() {
 
194
                return data.size.y * data.vVector.magnitude();
 
195
        }
 
196
 
 
197
 
 
198
    virtual RS_Vector getNearestEndpoint(const RS_Vector& coord,
 
199
                                         double* dist = NULL)const;
 
200
    virtual RS_Vector getNearestPointOnEntity(const RS_Vector& coord,
 
201
            bool onEntity=true, double* dist = NULL, RS_Entity** entity=NULL)const;
 
202
    virtual RS_Vector getNearestCenter(const RS_Vector& coord,
 
203
                                       double* dist = NULL);
 
204
    virtual RS_Vector getNearestMiddle(const RS_Vector& coord,
 
205
                                       double* dist = NULL,
 
206
                                       int middlePoints=1)const;
 
207
    virtual RS_Vector getNearestDist(double distance,
 
208
                                     const RS_Vector& coord,
 
209
                                     double* dist = NULL);
 
210
    virtual double getDistanceToPoint(const RS_Vector& coord,
 
211
                                      RS_Entity** entity=NULL,
 
212
                                      RS2::ResolveLevel level=RS2::ResolveNone,
 
213
                                                                          double solidDist = RS_MAXDOUBLE) const;
 
214
 
 
215
//        virtual double getLength() const {
 
216
//                return -1.0;
 
217
//        }
 
218
 
 
219
    virtual void move(const RS_Vector& offset);
 
220
    virtual void rotate(const RS_Vector& center, const double& angle);
 
221
    virtual void rotate(const RS_Vector& center, const RS_Vector& angleVector);
 
222
    virtual void scale(const RS_Vector& center, const RS_Vector& factor);
 
223
    virtual void mirror(const RS_Vector& axisPoint1, const RS_Vector& axisPoint2);
 
224
    /*virtual void stretch(RS_Vector firstCorner,
 
225
                         RS_Vector secondCorner,
 
226
                         RS_Vector offset);*/
 
227
 
 
228
    virtual void draw(RS_Painter* painter, RS_GraphicView* view, double& patternOffset);
 
229
 
 
230
    friend std::ostream& operator << (std::ostream& os, const RS_Image& l);
 
231
 
 
232
    virtual void calculateBorders();
 
233
    // whether the the point is within image
 
234
    virtual bool containsPoint(const RS_Vector& coord) const;
 
235
 
 
236
protected:
 
237
    RS_ImageData data;
 
238
        QImage img;
 
239
        //QImage** img;
 
240
        //int nx;
 
241
        //int ny;
 
242
};
 
243
 
 
244
#endif