]> Shamusworld >> Repos - architektonas/blob - src/base/pen.cpp
Fixed thumbnail rendering in LibraryWidget and DXF detection.
[architektonas] / src / base / pen.cpp
1 // pen.cpp
2 //
3 // Part of the Architektonas Project
4 // Originally part of QCad Community Edition by Andrew Mustun
5 // Extensively rewritten and refactored by James L. Hammons
6 // Portions copyright (C) 2001-2003 RibbonSoft
7 // Copyright (C) 2010 Underground Software
8 // See the README and GPLv2 files for licensing and warranty information
9 //
10 // JLH = James L. Hammons <jlhamm@acm.org>
11 //
12 // Who  When        What
13 // ---  ----------  -----------------------------------------------------------
14 // JLH  08/03/2010  Created this file. :-)
15 //
16
17 #include "pen.h"
18
19 /**
20  * Creates a default pen (black, solid, width 0).
21  */
22 RS_Pen::RS_Pen(): RS_Flags()
23 {
24         setColor(RS_Color(0, 0, 0));
25         setWidth(RS2::Width00);
26         setLineType(RS2::SolidLine);
27         setScreenWidth(0);
28 }
29
30 /**
31  * Creates a pen with the given attributes.
32  */
33 RS_Pen::RS_Pen(const RS_Color & c, RS2::LineWidth w, RS2::LineType t): RS_Flags()
34 {
35         setColor(c);
36         setWidth(w);
37         setLineType(t);
38         setScreenWidth(0);
39 }
40
41 /**
42  * Creates a default pen with the given flags. This is
43  * usually used to create invalid pens.
44  *
45  * e.g.:
46  * <pre>
47  *   RS_Pen p(RS2::FlagInvalid);
48  * </pre>
49  */
50 RS_Pen::RS_Pen(unsigned int f): RS_Flags(f)
51 {
52         setColor(RS_Color(0, 0, 0));
53         setWidth(RS2::Width00);
54         setLineType(RS2::SolidLine);
55         setScreenWidth(0);
56 }
57
58 /*virtual*/ RS_Pen::~RS_Pen()
59 {
60 }
61
62 RS2::LineType RS_Pen::getLineType() const
63 {
64         return lineType;
65 }
66
67 void RS_Pen::setLineType(RS2::LineType t)
68 {
69         lineType = t;
70 }
71
72 RS2::LineWidth RS_Pen::getWidth() const
73 {
74         return width;
75 }
76
77 void RS_Pen::setWidth(RS2::LineWidth w)
78 {
79         width = w;
80 }
81
82 double RS_Pen::getScreenWidth() const
83 {
84         return screenWidth;
85 }
86
87 void RS_Pen::setScreenWidth(double w)
88 {
89         screenWidth = w;
90 }
91
92 const RS_Color & RS_Pen::getColor() const
93 {
94         return color;
95 }
96
97 void RS_Pen::setColor(const RS_Color & c)
98 {
99         color = c;
100 }
101
102 bool RS_Pen::isValid()
103 {
104         return !getFlag(RS2::FlagInvalid);
105 }
106
107 bool RS_Pen::operator==(const RS_Pen & p) const
108 {
109         return (lineType == p.lineType && width == p.width && color == p.color);
110 }
111
112 bool RS_Pen::operator!=(const RS_Pen & p) const
113 {
114         return !(*this == p);
115 }
116
117 /*friend*/ std::ostream & operator<<(std::ostream & os, const RS_Pen & p)
118 {
119         //os << "style: " << p.style << std::endl;
120         os << " pen color: " << p.getColor()
121         << " pen width: " << p.getWidth()
122         << " pen screen width: " << p.getScreenWidth()
123         << " pen line type: " << p.getLineType()
124         << " flags: " << (p.getFlag(RS2::FlagInvalid) ? "INVALID" : "")
125         << std::endl;
126         return os;
127 }