]> Shamusworld >> Repos - architektonas/blob - src/base/block.cpp
Fixed thumbnail rendering in LibraryWidget and DXF detection.
[architektonas] / src / base / block.cpp
1 // block.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  05/21/2010  Added this text. :-)
15 //
16
17 #include "block.h"
18
19 #include <iomanip>
20 #include "drawing.h"
21
22 /**
23  * @param parent The graphic this block belongs to.
24  * @param name The name of the block used as an identifier.
25  * @param basePoint Base point (offset) of the block.
26  */
27 RS_Block::RS_Block(RS_EntityContainer * parent, const RS_BlockData & d):
28         RS_Document(parent), data(d)
29 {
30         pen = RS_Pen(RS_Color(128, 128, 128), RS2::Width01, RS2::SolidLine);
31 }
32
33 RS_Block::~RS_Block()
34 {
35 }
36
37 RS_Entity * RS_Block::clone()
38 {
39         RS_Block * blk = new RS_Block(*this);
40 #warning "!!! Need to port setAutoDelete() behaviour from Qt3 to Qt4 !!!"
41 //      blk->entities.setAutoDelete(entities.autoDelete());
42         blk->detach();
43         blk->initId();
44         return blk;
45 }
46
47 RS_LayerList * RS_Block::getLayerList()
48 {
49         Drawing * g = getGraphic();
50
51         if (g != NULL)
52                 return g->getLayerList();
53
54         return NULL;
55 }
56
57 RS_BlockList * RS_Block::getBlockList()
58 {
59         Drawing * g = getGraphic();
60
61         if (g != NULL)
62                 return g->getBlockList();
63
64         return NULL;
65 }
66
67 bool RS_Block::save()
68 {
69         Drawing * g = getGraphic();
70
71         if (g != NULL)
72                 return g->save();
73
74         return false;
75 }
76
77 bool RS_Block::saveAs(const QString & filename, RS2::FormatType type)
78 {
79         Drawing * g = getGraphic();
80
81         if (g != NULL)
82                 return g->saveAs(filename, type);
83
84         return false;
85 }
86
87 /**
88  * Sets the parent documents modified status to 'm'.
89  */
90 void RS_Block::setModified(bool m)
91 {
92         Drawing * p = getGraphic();
93
94         if (p)
95                 p->setModified(m);
96
97         modified = m;
98 }
99
100 /** @return RS2::EntityBlock */
101 /*virtual*/ RS2::EntityType RS_Block::rtti() const
102 {
103         return RS2::EntityBlock;
104 }
105
106 /**
107  * @return Name of this block (the name is an Id for this block).
108  */
109 QString RS_Block::getName() const
110 {
111         return data.name;
112 }
113
114 /**
115  * @return base point of this block.
116  */
117 Vector RS_Block::getBasePoint() const
118 {
119         return data.basePoint;
120 }
121
122 /**
123  * Reimplementation from RS_Document. Does nothing.
124  */
125 /*virtual*/ void RS_Block::newDoc()
126 {
127         // do nothing
128 }
129
130 /**
131  * Reimplementation from RS_Document. Does nothing.
132  */
133 /*virtual*/ bool RS_Block::open(const QString &, RS2::FormatType)
134 {
135         // do nothing
136         return false;
137 }
138
139 /*friend*/ std::ostream & operator<<(std::ostream & os, const RS_Block & b)
140 {
141         os << " name: " << b.getName().toLatin1().data() << std::endl;
142         os << " entities: " << (RS_EntityContainer &)b << std::endl;
143         return os;
144 }
145
146 /**
147  * sets a new name for the block. Only called by blocklist to
148  * assure that block names stay unique.
149  */
150 void RS_Block::setName(const QString & n)
151 {
152         data.name = n;
153 }
154
155 /**
156  * @retval true if this block is frozen (invisible)
157  * @retval false if this block isn't frozen (visible)
158  */
159 bool RS_Block::isFrozen() const
160 {
161         return data.frozen;
162 }
163
164 /**
165  * Toggles the visibility of this block.
166  * Freezes the block if it's not frozen, thaws the block otherwise
167  */
168 void RS_Block::toggle()
169 {
170         data.frozen = !data.frozen;
171 }
172
173 /**
174  * (De-)freezes this block.
175  *
176  * @param freeze true: freeze, false: defreeze
177  */
178 void RS_Block::freeze(bool freeze)
179 {
180         data.frozen = freeze;
181 }