]> Shamusworld >> Repos - architektonas/blob - src/base/leader.cpp
Fixed problem with MDI activation.
[architektonas] / src / base / leader.cpp
1 // leader.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  06/01/2010  Added this text. :-)
15 //
16
17 #include "leader.h"
18
19 #include "debug.h"
20 #include "line.h"
21 #include "solid.h"
22
23 /**
24  * Constructor.
25  */
26 Leader::Leader(EntityContainer * parent): EntityContainer(parent)
27 {
28     empty = true;
29 }
30
31 /**
32  * Constructor.
33  * @param d Leader data
34  */
35 Leader::Leader(EntityContainer * parent, const LeaderData & d):
36         EntityContainer(parent), data(d)
37 {
38     empty = true;
39 }
40
41 /**
42  * Destructor
43  */
44 Leader::~Leader()
45 {
46 }
47
48 /*virtual*/ Entity * Leader::clone()
49 {
50         Leader * p = new Leader(*this);
51 #warning "!!! Need to deal with setAutoDelete() Qt3->Qt4 !!!"
52 //      p->entities.setAutoDelete(entities.autoDelete());
53         p->initId();
54         p->detach();
55         return p;
56 }
57
58 /**     @return RS2::EntityDimLeader */
59 /*virtual*/ RS2::EntityType Leader::rtti() const
60 {
61         return RS2::EntityDimLeader;
62 }
63
64 /**
65  * Implementation of update. Updates the arrow.
66  */
67 void Leader::update()
68 {
69         // find and delete arrow:
70         for(Entity * e=firstEntity(); e!=NULL; e=nextEntity())
71         {
72                 if (e->rtti() == RS2::EntitySolid)
73                 {
74                         removeEntity(e);
75                         break;
76                 }
77         }
78
79         if (isUndone())
80         {
81                 setVisible(false);
82                 return;
83         }
84
85         Entity * fe = firstEntity();
86
87         if (fe != NULL && fe->isAtomic())
88         {
89                 Vector p1 = ((AtomicEntity *)fe)->getStartpoint();
90                 Vector p2 = ((AtomicEntity *)fe)->getEndpoint();
91
92                 // first entity must be the line which gets the arrow:
93                 if (hasArrowHead())
94                 {
95                         Solid * s = new Solid(this, SolidData());
96                         s->shapeArrow(p1, p2.angleTo(p1), getGraphicVariableDouble("$DIMASZ", 2.5));
97                         s->setPen(Pen(RS2::FlagInvalid));
98                         s->setLayer(NULL);
99                         EntityContainer::addEntity(s);
100                 }
101         }
102 }
103
104 /** @return Copy of data that defines the leader. */
105 LeaderData Leader::getData() const
106 {
107         return data;
108 }
109
110 /** @return true: if this leader has an arrow at the beginning. */
111 bool Leader::hasArrowHead()
112 {
113         return data.arrowHead;
114 }
115
116 /**
117  * Adds a vertex from the endpoint of the last element or
118  * sets the startpoint to the point 'v'.
119  *
120  * The very first vertex added is the starting point.
121  *
122  * @param v vertex coordinate
123  *
124  * @return Pointer to the entity that was addded or NULL if this
125  *         was the first vertex added.
126  */
127 Entity * Leader::addVertex(const Vector & v)
128 {
129         Entity * entity = NULL;
130         static Vector last = Vector(false);
131
132         if (empty)
133         {
134                 last = v;
135                 empty = false;
136         }
137         else
138         {
139                 // add line to the leader:
140                 entity = new Line(this, LineData(last, v));
141                 entity->setPen(Pen(RS2::FlagInvalid));
142                 entity->setLayer(NULL);
143                 EntityContainer::addEntity(entity);
144
145                 if (count() == 1 && hasArrowHead())
146                         update();
147
148                 last = v;
149         }
150
151         return entity;
152 }
153
154 /**
155  * Reimplementation of the addEntity method for a normal container.
156  * This reimplementation deletes the given entity!
157  *
158  * To add entities use addVertex() instead.
159  */
160 void Leader::addEntity(Entity * entity)
161 {
162         DEBUG->print(Debug::D_WARNING, "Leader::addEntity: should never be called");
163
164         if (entity == NULL)
165                 return;
166
167         delete entity;
168 }
169
170 /*virtual*/ double Leader::getLength()
171 {
172         return -1.0;
173 }
174
175 void Leader::move(Vector offset)
176 {
177         EntityContainer::move(offset);
178         update();
179 }
180
181 void Leader::rotate(Vector center, double angle)
182 {
183         EntityContainer::rotate(center, angle);
184         update();
185 }
186
187 void Leader::scale(Vector center, Vector factor)
188 {
189         EntityContainer::scale(center, factor);
190         update();
191 }
192
193 void Leader::mirror(Vector axisPoint1, Vector axisPoint2)
194 {
195         EntityContainer::mirror(axisPoint1, axisPoint2);
196         update();
197 }
198
199 void Leader::stretch(Vector firstCorner, Vector secondCorner, Vector offset)
200 {
201         EntityContainer::stretch(firstCorner, secondCorner, offset);
202         update();
203 }
204
205 /**
206  * Dumps the leader's data to stdout.
207  */
208 std::ostream & operator<<(std::ostream & os, const Leader & l)
209 {
210         os << " Leader: " << l.getData() << " {\n";
211         os << (EntityContainer &)l;
212         os << "\n}\n";
213
214         return os;
215 }