OpenASIP 2.2
Loading...
Searching...
No Matches
EPSDC.cc
Go to the documentation of this file.
1/*
2 Copyright (c) 2002-2009 Tampere University.
3
4 This file is part of TTA-Based Codesign Environment (TCE).
5
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 and/or sell copies of the Software, and to permit persons to whom the
11 Software is furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
23 */
24/**
25 * @file EPSDC.cc
26 *
27 * Implementation of EPSDC class.
28 *
29 * @author Veli-Pekka Jääskeläinen 2005 (vjaaskel-no.spam-cs.tut.fi)
30 * @note rating: red
31 */
32
33#include "EPSDC.hh"
34#include "WxConversion.hh"
35#include "VertexList.hh"
36#include "Conversion.hh"
37
38#if !wxCHECK_VERSION(3, 0, 0)
39/**
40 * The Constructor.
41 */
42EPSDC::EPSDC() : wxDC(), fill_(false), fontSize_(0) {
43}
44
45/**
46 * The Destructor.
47 */
50
51/**
52 * Returns true, if the DC is ok to use.
53 *
54 * @return always true
55 */
56bool
57EPSDC::Ok() const {
58 return true;
59}
60
61/**
62 * Draws a line on the dc.
63 *
64 * @param x1 x-coordinate of the first end of the line.
65 * @param y1 y-coordinate of the first end of the line.
66 * @param x2 x-coordinate of the second end of the line.
67 * @param y2 y-coordinate of the second end of the line.
68 */
69void
70EPSDC::DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) {
71 eps_.drawLine(x1, -1 * y1, x2, -1 * y2);
72}
73
74/**
75 * Draws a polygon on the dc.
76 *
77 * @param n Number of vertices.
78 * @param vertices Vertices.
79 * @param xOffset Offset for x-coordinates.
80 * @param yOffset Offset for y-coordinates.
81 */
82void
84 int n,
85 wxPoint vertices[],
86 wxCoord xOffset,
87 wxCoord yOffset,
88 int /* fillStyle */) {
89
90 // Create VertexList of the vertices.
91 VertexList list;
92 for (int i = 0; i < n; i++) {
93 list.addVertex(vertices[i].x + xOffset, -1 * (vertices[i].y + yOffset));
94 }
95
96 if (fill_) {
98 } else {
99 eps_.drawPolygon(list);
100 }
101
102}
103
104/**
105 * Draws a rectangle on the dc.
106 *
107 * @param x Lower left corner x-coordinate of the canvas.
108 * @param y Lower left corner y-coordinate of the canvas.
109 */
110void
111EPSDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) {
112 if (fill_) {
113 eps_.drawFilledRectangle(x, (-1 * y - height), width, height);
114 } else {
115 eps_.drawRectangle(x, (-1 * y - height), width, height);
116 }
117}
118
119/**
120 * Draws text on the dc.
121 *
122 * @param text Text to draw.
123 * @param x x-coordinate of the lower left corner of the text.
124 * @param y y-coordinate of the lower left corner of the text.
125 */
126void
127EPSDC::DoDrawText(const wxString& text, wxCoord x, wxCoord y) {
128 std::string textStr = WxConversion::toString(text);
129 eps_.drawText(x, -1 * y - 12, textStr);
130}
131
132/**
133 * Clears all drawings on the canvas.
134 */
135void
139
140/**
141 * Sets the dc font.
142 *
143 * Only font size is currently set.
144 *
145 * @param font Font to set.
146 */
147void
148EPSDC::SetFont(const wxFont& font) {
149 fontSize_ = font.GetPointSize();
151}
152
153
154/**
155 * NOT IMPLEMENTED
156 */
157void
158EPSDC::SetPen(const wxPen& pen) {
159 wxColour lineColour = pen.GetColour();
160 eps_.setLineWidth(pen.GetWidth());
161 setLineColour(lineColour);
162}
163
164/**
165 * Sets the brush used for filling shapes with colour.
166 *
167 * Only solid and transparent brushes are supported. Everything else
168 * is interpreted as transparent brush.
169 */
170void
171EPSDC::SetBrush(const wxBrush& brush) {
172 if (brush.GetStyle() == wxSOLID) {
173 fill_ = true;
174 wxColour fillColour = brush.GetColour();
175 setFillColour(fillColour);
176 } else {
177 fill_ = false;
178 }
179}
180
181
182
183/**
184 * Sets the eps-file title.
185 *
186 * @param title String which will be set as the eps file title.
187 */
188void
189EPSDC::setTitle(const std::string& title) {
190 eps_.setTitle(title);
191}
192
193/**
194 * Sets the eps-file creator string.
195 *
196 * @param creator String describin the eps file creator.
197 */
198void
199EPSDC::setCreator(const std::string& creator) {
200 eps_.setCreator(creator);
201}
202
203/**
204 * Writes the generated eps file to an output stream.
205 *
206 * @param stream Output stream where the eps file contents will be written.
207 */
208void
209EPSDC::writeToStream(std::ostream& stream) {
210 eps_.writeEPS(stream);
211}
212
213
214/**
215 * Bitmap drawing not implemented.
216 *
217 * @return Always false.
218 */
219bool
221 return false;
222}
223
224
225/**
226 * Called by the device context client before the drawing is started.
227 *
228 * @return Always true.
229 */
230bool
231EPSDC::StartDoc(const wxString& /* message */) {
232 return true;
233}
234
235
236/**
237 * NOT IMPLEMENTED.
238 */
239void
241 const wxString& /* text */, wxCoord, wxCoord, double) {
242}
243
244/**
245 * NOT IMPLEMENTED.
246 */
247void
248EPSDC::DoDrawPoint(wxCoord, wxCoord) {
249}
250
251/**
252 * NOT IMPLEMENTED
253 */
254bool
255EPSDC::DoFloodFill(wxCoord, wxCoord, const wxColour&, int) {
256 return false;
257}
258
259
260/**
261 * NOT IMPLEMENTED
262 */
263void
264EPSDC::DoGetSize(wxCoord*, wxCoord*) const {
265}
266
267/**
268 * NOT IMPLEMENTED
269 */
270void
271EPSDC::DoDrawArc(wxCoord, wxCoord, wxCoord, wxCoord, wxCoord, wxCoord) {
272}
273
274/**
275 * NOT IMPLEMENTED
276 */
277void
278EPSDC::DoDrawIcon(const wxIcon&, wxCoord, wxCoord) {
279}
280
281/**
282 * NOT IMPLEMENTED
283 */
284void
285EPSDC::DoCrossHair(wxCoord, wxCoord) {
286}
287
288
289/**
290 * NOT IMPLEMENTED
291 */
292void
293EPSDC::DoDrawBitmap(const wxBitmap&, wxCoord, wxCoord, bool) {
294}
295
296/**
297 * Called before the drawing ends.
298 */
299void
301 // Do nothing.
302}
303
304/**
305 * Called when the drawing ends.
306 */
307void
309 // Do nothing.
310}
311
312
313
314/**
315 * NOT IMPLEMENTED
316 */
317void
319 int,
320 wxPoint[] /* points[] */,
321 wxCoord,
322 wxCoord) {
323}
324
325
326/**
327 * NOT IMPLEMENTED
328 */
329void
331 wxCoord,
332 wxCoord,
333 wxCoord,
334 wxCoord,
335 double,
336 double) {
337}
338
339/**
340 * Not implemented, falls back to a rectangle.
341 */
342void
344 wxCoord x,
345 wxCoord y,
346 wxCoord width,
347 wxCoord height,
348 double) {
349 DoDrawRectangle(x, y, width, height);
350}
351
352/**
353 * Draws an ellipse on the dc.
354 *
355 * @param x Ellipse bounding box lower left corner x-coordinate.
356 * @param y Ellipse bounding box lower left corner y-coordinate.
357 * @param width Ellipse width.
358 * @param height Ellipse height.
359 */
360void
361EPSDC::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height) {
362
363 y = -1 * y -height;
364
365 // Check if the ellipse is actually circle, which will generated more
366 // simple postscript-code.
367 if (width == height) {
368 x += width / 2;
369 y += width / 2;
370 drawCircle(x, y, width / 2);
371 return;
372 }
373
374 if (fill_) {
375 eps_.drawFilledEllipse(x, y, width, height);
376 } else {
377 eps_.drawEllipse(x, y, width, height);
378 }
379}
380
381
382/**
383 * NOT IMPLEMENTED
384 */
385bool
387 wxCoord,
388 wxCoord,
389 wxCoord,
390 wxCoord,
391 wxDC*,
392 wxCoord,
393 wxCoord,
394 int,
395 bool,
396 wxCoord,
397 wxCoord) {
398
399 return false;
400}
401
402/**
403 * Sets the line drawing colour of the eps generator.
404 *
405 * @param colour New line drawing colour.
406 */
407void
408EPSDC::setLineColour(const wxColour& colour) {
409 double redC = (double)colour.Red() / 255;
410 double greenC = (double)colour.Green() / 255;
411 double blueC = (double)colour.Blue() / 255;
412 eps_.setLineColour(redC, greenC, blueC);
413}
414
415/**
416 * Sets the filling colour of the eps generator.
417 *
418 * @param colour New filing colour.
419 */
420void
421EPSDC::setFillColour(const wxColour& colour) {
422 double redC = (double)colour.Red() / 255;
423 double greenC = (double)colour.Green() / 255;
424 double blueC = (double)colour.Blue() / 255;
425 eps_.setFillColour(redC, greenC, blueC);
426}
427
428
429/**
430 * Draws a circle.
431 *
432 * @param x X-coordinate of the circle centre.
433 * @param y Y-coordinate of the circle centre.
434 * @param radius Radius of the circle.
435 */
436void
437EPSDC::drawCircle(int x, int y, unsigned radius) {
438
439 if (fill_) {
440 eps_.drawFilledCircle(x, y, radius);
441 } else {
442 eps_.drawCircle(x, y, radius);
443 }
444}
445
446/**
447 * Returns crude approximation of the width and height of a text on the dc.
448 *
449 * @param w Approximation of width is set as the value of w.
450 * @param h Approximation of height is set as the value of h.
451 */
452void
454 const wxString& text,
455 wxCoord* w,
456 wxCoord* h,
457 wxCoord*,
458 wxCoord*,
459 wxFont*) const {
460
461 // TODO: find a better way to approximate text extent.
462 *h = fontSize_;
463 *w = Conversion::toInt((fontSize_ * 72.0 / 120) * text.Length());
464}
465
466/**
467 * NOT IMPLEMENTED
468 *
469 * @return Always false.
470 */
471bool
472EPSDC::DoGetPixel(wxCoord, wxCoord, wxColour*) const {
473 return false;
474}
475
476/**
477 * NOT IMPLEMENTED
478 */
479void
482
483
484/**
485 * NOT IMPLEMENTED
486 *
487 * @return Always false.
488 */
489bool
491 return false;
492}
493
494
495/**
496 * NOT IMPLEMENTED
497 */
498void
499EPSDC::SetBackground(const wxBrush&) {
500}
501
502
503/**
504 * NOT IMPLEMENTED
505 */
506void
509
510
511/**
512 * NOT IMPLEMENTED
513 */
514void
515EPSDC::SetPalette(const wxPalette&) {
516}
517
518/**
519 * NOT IMPLEMENTED
520 */
521void
524
525
526/**
527 * NOT IMPLEMENTED
528 *
529 * @return Always zero.
530 */
531wxCoord
533 return 0;
534}
535
536/**
537 * NOT IMPLEMENTED
538 *
539 * @return Always zero.
540 */
541wxCoord
543 return 0;
544}
545
546/**
547 * NOT IMPLEMENTED
548 *
549 * @return Always zero.
550 */
551int
553 return 0;
554}
555
556/**
557 * Starts a new page in the document.
558 */
559void
561 // Do nothing.
562}
563
564/**
565 * Ends current page.
566 */
567void
569 // Do nothing.
570}
571
572/**
573 * Ends the document that is being drawn on.
574 */
575void
577 // Do nothing.
578}
579#endif
find Finds info of the inner loops in the false
static int toInt(const T &source)
virtual void DoGetSize(wxCoord *width, wxCoord *height) const
Definition EPSDC.cc:264
void writeToStream(std::ostream &stream)
Definition EPSDC.cc:209
virtual void DoGetTextExtent(const wxString &text, wxCoord *w, wxCoord *h, wxCoord *descent=NULL, wxCoord *externalLeading=NULL, wxFont *font=NULL) const
Definition EPSDC.cc:453
virtual bool DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height, wxDC *source, wxCoord xsrc, wxCoord ysrc, int logicalFunc=wxCOPY, bool useMask=false, wxCoord xsrcMask=-1, wxCoord ysrcMask=-1)
Definition EPSDC.cc:386
virtual void DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
Definition EPSDC.cc:361
bool fill_
True, if background brush is set to fill the shapes.
Definition EPSDC.hh:191
virtual void DoDrawText(const wxString &text, wxCoord x, wxCoord y)
Definition EPSDC.cc:127
virtual void EndDrawing()
Definition EPSDC.cc:308
virtual void DoDrawLines(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset)
Definition EPSDC.cc:318
virtual wxCoord GetCharHeight() const
Definition EPSDC.cc:532
virtual void DoDrawArc(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2, wxCoord xc, wxCoord yc)
Definition EPSDC.cc:271
virtual void SetPen(const wxPen &pen)
Definition EPSDC.cc:158
EPSGenerator eps_
EPSGenerator generating the postscript code.
Definition EPSDC.hh:189
virtual void EndPage()
Definition EPSDC.cc:568
virtual void DoDrawRotatedText(const wxString &text, wxCoord x, wxCoord y, double angle)
Definition EPSDC.cc:240
virtual void DoDrawIcon(const wxIcon &icon, wxCoord x, wxCoord y)
Definition EPSDC.cc:278
virtual void SetLogicalFunction(int function)
Definition EPSDC.cc:522
EPSDC()
Definition EPSDC.cc:42
virtual void DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double start, double end)
Definition EPSDC.cc:330
virtual void SetFont(const wxFont &font)
Definition EPSDC.cc:148
virtual void DoDrawPolygon(int n, wxPoint points[], wxCoord xoffset=0, wxCoord yoffset=0, int fillStyle=wxODDEVEN_RULE)
Definition EPSDC.cc:83
void drawCircle(int x, int y, unsigned radius)
Definition EPSDC.cc:437
virtual bool CanGetTextExtent() const
Definition EPSDC.cc:490
virtual bool CanDrawBitmap() const
Definition EPSDC.cc:220
virtual void StartPage()
Definition EPSDC.cc:560
virtual void Clear()
Definition EPSDC.cc:136
virtual void SetPalette(const wxPalette &palette)
Definition EPSDC.cc:515
virtual ~EPSDC()
Definition EPSDC.cc:48
virtual void DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
Definition EPSDC.cc:111
virtual void DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius=20)
Definition EPSDC.cc:343
virtual void DoDrawPoint(wxCoord x, wxCoord y)
Definition EPSDC.cc:248
virtual void DoSetClippingRegionAsRegion(const wxRegion &region)
Definition EPSDC.cc:480
unsigned fontSize_
Current font size.
Definition EPSDC.hh:193
void setLineColour(const wxColour &colour)
Definition EPSDC.cc:408
virtual int GetDepth() const
Definition EPSDC.cc:552
virtual bool DoGetPixel(wxCoord x, wxCoord y, wxColour *colour) const
Definition EPSDC.cc:472
virtual void DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
Definition EPSDC.cc:70
void setCreator(const std::string &creator)
Definition EPSDC.cc:199
virtual void EndDoc()
Definition EPSDC.cc:576
virtual bool Ok() const
Definition EPSDC.cc:57
void setTitle(const std::string &title)
Definition EPSDC.cc:189
virtual bool DoFloodFill(wxCoord x, wxCoord y, const wxColour &colour, int style)
Definition EPSDC.cc:255
virtual wxCoord GetCharWidth() const
Definition EPSDC.cc:542
virtual void SetBackgroundMode(int mode)
Definition EPSDC.cc:507
virtual void SetBrush(const wxBrush &brush)
Definition EPSDC.cc:171
virtual void BeginDrawing()
Definition EPSDC.cc:300
virtual void DoCrossHair(wxCoord x, wxCoord y)
Definition EPSDC.cc:285
virtual bool StartDoc(const wxString &message)
Definition EPSDC.cc:231
virtual void SetBackground(const wxBrush &brush)
Definition EPSDC.cc:499
virtual void DoDrawBitmap(const wxBitmap &bitmap, wxCoord x, wxCoord y, bool transparent)
Definition EPSDC.cc:293
void setFillColour(const wxColour &colour)
Definition EPSDC.cc:421
void setTitle(std::string title)
void drawLine(int llx, int lly, int urx, int ury)
void drawRectangle(int x, int y, unsigned width, unsigned height)
void drawPolygon(const VertexList &vertices)
void drawFilledCircle(int x, int y, unsigned radius)
void drawFilledRectangle(int x, int y, unsigned width, unsigned height)
void drawFilledPolygon(const VertexList &vertices)
void drawText(int x, int y, std::string text)
void setFont(unsigned size, std::string fontName="Courier-Bold")
void drawCircle(int x, int y, unsigned radius)
void drawEllipse(int x, int y, unsigned width, unsigned height)
void drawFilledEllipse(int x, int y, unsigned width, unsigned height)
void setLineColour(double r, double g, double b)
void writeEPS(std::ostream &stream)
void setLineWidth(unsigned width)
void setFillColour(double r, double g, double b)
void setCreator(std::string creator)
void addVertex(int x, int y)
Definition VertexList.cc:57
static std::string toString(const wxString &source)