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