1 /****************************************************************************
2 **
3 ** This file is part of the LibreCAD project, a 2D CAD program
4 **
5 ** Copyright (C) 2015 A. Stebich (librecad@mail.lordofbikes.de)
6 ** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl)
7 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
8 **
9 **
10 ** This file may be distributed and/or modified under the terms of the
11 ** GNU General Public License version 2 as published by the Free Software
12 ** Foundation and appearing in the file gpl-2.0.txt included in the
13 ** packaging of this file.
14 **
15 ** This program is distributed in the hope that it will be useful,
16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ** GNU General Public License for more details.
19 **
20 ** You should have received a copy of the GNU General Public License
21 ** along with this program; if not, write to the Free Software
22 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
23 **
24 ** This copyright notice MUST APPEAR in all copies of the script!
25 **
26 **********************************************************************/
27 
28 #include <iostream>
29 #include <QString>
30 #include "rs_layer.h"
31 
RS_LayerData(const QString & name,const RS_Pen & pen,bool frozen,bool locked)32 RS_LayerData::RS_LayerData(const QString& name,
33 						   const RS_Pen& pen,
34 						   bool frozen,
35 						   bool locked):
36 	name(name)
37   ,pen(pen)
38   ,frozen(frozen)
39   ,locked(locked)
40 {
41 }
42 
43 /**
44  * Constructor.
45  */
RS_Layer(const QString & name)46 RS_Layer::RS_Layer(const QString& name):
47 	data(name, RS_Pen(Qt::black, RS2::Width00,RS2::SolidLine), false, false)
48 {
49 }
50 
clone() const51 RS_Layer* RS_Layer::clone() const{
52 	return new RS_Layer(*this);
53 }
54 
55 /** sets a new name for this layer. */
setName(const QString & name)56 void RS_Layer::setName(const QString& name) {
57 	data.name = name;
58 }
59 
60 /** @return the name of this layer. */
getName() const61 QString RS_Layer::getName() const {
62 	return data.name;
63 }
64 
65 /** sets the default pen for this layer. */
setPen(const RS_Pen & pen)66 void RS_Layer::setPen(const RS_Pen& pen) {
67 	data.pen = pen;
68 }
69 
70 /** @return default pen for this layer. */
getPen() const71 RS_Pen RS_Layer::getPen() const {
72 	return data.pen;
73 }
74 
75 /**
76  * @retval true if this layer is frozen (invisible)
77  * @retval false if this layer isn't frozen (visible)
78  */
isFrozen() const79 bool RS_Layer::isFrozen() const {
80 	return data.frozen;
81 	//getFlag(RS2::FlagFrozen);
82 }
83 
84 /**
85  * @retval true the layer has been converted already
86  * @retval false the layer still needs to be converted
87  */
isConverted() const88 bool RS_Layer::isConverted() const {
89 	return data.converted;
90 }
91 
92 /**
93  * Sets the converted flag
94  */
setConverted(bool c)95 void RS_Layer::setConverted(bool c) {
96 	data.converted = c;
97 }
98 
99 /**
100  * Toggles the visibility of this layer.
101  * Freezes the layer if it's not frozen, thaws the layer otherwise
102  */
toggle()103 void RS_Layer::toggle() {
104 	//toggleFlag(RS2::FlagFrozen);
105 	data.frozen = !data.frozen;
106 }
107 
108 /**
109  * (De-)freezes this layer.
110  *
111  * @param freeze true: freeze, false: defreeze
112  */
freeze(bool freeze)113 void RS_Layer::freeze(bool freeze) {
114 	data.frozen = freeze;
115 }
116 
117 /**
118  * Toggles the lock of this layer.
119  */
toggleLock()120 void RS_Layer::toggleLock() {
121 	//toggleFlag(RS2::FlagFrozen);
122 	data.locked = !data.locked;
123 }
124 
125 /**
126  * Toggles printing of this layer on / off.
127  */
togglePrint()128 void RS_Layer::togglePrint() {
129 	data.print = !data.print;
130 }
131 
132 /**
133  * Toggles construction attribute of this layer on / off.
134  */
toggleConstruction()135 void RS_Layer::toggleConstruction() {
136 	data.construction = !data.construction;
137 }
138 
139 /**
140  * Locks/Unlocks this layer.
141  *
142  * @param l true: lock, false: unlock
143  */
lock(bool l)144 void RS_Layer::lock(bool l) {
145 	data.locked = l;
146 }
147 
148 /**
149  * return the LOCK state of the Layer
150  */
isLocked() const151 bool RS_Layer::isLocked() const{
152 	return data.locked;
153 }
154 
155 /**
156  * set visibility of layer in layer list
157  *
158  * @param l true: visible, false: invisible
159  */
visibleInLayerList(bool l)160 void RS_Layer::visibleInLayerList(bool l) {
161 	data.visibleInLayerList = l;
162 }
163 
164 /**
165  * return the visibility of the Layer in layer list
166  */
isVisibleInLayerList() const167 bool RS_Layer::isVisibleInLayerList() const{
168 	return data.visibleInLayerList;
169 }
170 
171 /**
172  * set selection state of the layer in layer list
173  *
174  * @param val true: selected, false: deselected
175  */
selectedInLayerList(bool val)176 void RS_Layer::selectedInLayerList(bool val) {
177 	data.selectedInLayerList = val;
178 }
179 
180 /**
181  * return selection state of the layer in layer list
182  */
isSelectedInLayerList() const183 bool RS_Layer::isSelectedInLayerList() const {
184 	return data.selectedInLayerList;
185 }
186 
187 /**
188  * set the PRINT state of the Layer
189  *
190  * @param print true: print layer, false: don't print layer
191  */
setPrint(const bool print)192 bool RS_Layer::setPrint( const bool print) {
193 	return data.print = print;
194 }
195 
196 /**
197  * return the PRINT state of the Layer
198  */
isPrint() const199 bool RS_Layer::isPrint() const{
200 	return data.print;
201 }
202 
203 /**
204  * whether the layer is a construction layer
205  * The construction layer property is stored
206  * in extended data in the DXF layer table
207  */
isConstruction() const208 bool RS_Layer::isConstruction() const{
209 	return data.construction;
210 }
211 
212 /**
213  * set the construction attribute for the layer
214  *
215  * @param construction true: infinite lines, false: normal layer
216  */
setConstruction(const bool construction)217 bool RS_Layer::setConstruction( const bool construction){
218 	data.construction = construction;
219 	return construction;
220 }
221 
222 /**
223  * Dumps the layers data to stdout.
224  */
operator <<(std::ostream & os,const RS_Layer & l)225 std::ostream& operator << (std::ostream& os, const RS_Layer& l) {
226     os << " name: " << l.getName().toLatin1().data()
227     << " pen: " << l.getPen()
228     << " frozen: " << (int)l.isFrozen()
229     << " address: " << &l
230     << std::endl;
231     return os;
232 }
233 
234