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
**********************************************************************/
32
#include "rs_atomicentity.h"
35
* Holds the data that defines a line.
40
* Default constructor. Leaves the data object uninitialized.
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,
54
this->handle = handle;
55
this->insertionPoint = insertionPoint;
56
this->uVector = uVector;
57
this->vVector = vVector;
60
this->brightness = brightness;
61
this->contrast = contrast;
65
friend std::ostream& operator << (std::ostream& os, const RS_ImageData& ld) {
66
os << "(" << ld.insertionPoint << ")";
71
/** Handle of image definition. */
73
/** Insertion point. */
74
RS_Vector insertionPoint;
75
/** u vector. Points along visual bottom of image. */
77
/** v vector. Points along visual left of image. */
79
/** Image size in pixel. */
81
/** Path to image file. */
83
/** Brightness (0..100, default: 50). */
85
/** Contrast (0..100, default: 50). */
87
/** Fade (0..100, default: 0). */
94
* Class for a line entity.
96
* @author Andrew Mustun
98
class RS_Image : public RS_AtomicEntity {
100
RS_Image(RS_EntityContainer* parent,
101
const RS_ImageData& d);
103
virtual RS_Entity* clone();
107
/** @return RS2::EntityImage */
108
virtual RS2::EntityType rtti() const {
109
return RS2::EntityImage;
112
virtual void update();
114
/** @return Copy of data that defines the image. */
115
RS_ImageData getData() const {
119
/** @return Insertion point of the entity */
120
virtual RS_Vector getInsertionPoint() const {
121
return data.insertionPoint;
123
/** Sets the insertion point for the image. */
124
void setInsertionPoint(RS_Vector ip) {
125
data.insertionPoint = ip;
129
/** Update image data ONLY for plugins. */
130
void updateData(RS_Vector size, RS_Vector Uv, RS_Vector Vv);
132
/** @return File name of the image. */
133
QString getFile() const {
137
/** Sets the file name of the image. */
138
void setFile(const QString& file) {
142
/** @return u Vector. Points along bottom, 1 pixel long. */
143
RS_Vector getUVector() const {
146
/** @return v Vector. Points along left, 1 pixel long. */
147
RS_Vector getVVector() const {
150
/** @return Width of image in pixels. */
151
int getWidth() const {
152
return (int)data.size.x;
154
/** @return Height of image in pixels. */
155
int getHeight() const {
156
return (int)data.size.y;
158
/** @return Brightness. */
159
int getBrightness() const {
160
return data.brightness;
162
/** @return Contrast. */
163
int getContrast() const {
164
return data.contrast;
167
int getFade() const {
170
/** @return Image definition handle. */
171
int getHandle() const {
174
/** Sets the image definition handle. */
175
void setHandle(int h) {
180
/** @return The four corners. **/
181
RS_VectorSolutions getCorners() const;
184
* @return image with in graphic units.
186
double getImageWidth() {
187
return data.size.x * data.uVector.magnitude();
191
* @return image height in graphic units.
193
double getImageHeight() {
194
return data.size.y * data.vVector.magnitude();
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,
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;
215
// virtual double getLength() const {
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,
228
virtual void draw(RS_Painter* painter, RS_GraphicView* view, double& patternOffset);
230
friend std::ostream& operator << (std::ostream& os, const RS_Image& l);
232
virtual void calculateBorders();
233
// whether the the point is within image
234
virtual bool containsPoint(const RS_Vector& coord) const;