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