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
10 // JLH = James L. Hammons <jlhamm@acm.org>
13 // --- ---------- -----------------------------------------------------------
14 // JLH 06/01/2010 Added this text. :-)
26 Leader::Leader(EntityContainer * parent): EntityContainer(parent)
33 * @param d Leader data
35 Leader::Leader(EntityContainer * parent, const LeaderData & d):
36 EntityContainer(parent), data(d)
48 /*virtual*/ Entity * Leader::clone()
50 Leader * p = new Leader(*this);
51 #warning "!!! Need to deal with setAutoDelete() Qt3->Qt4 !!!"
52 // p->entities.setAutoDelete(entities.autoDelete());
58 /** @return RS2::EntityDimLeader */
59 /*virtual*/ RS2::EntityType Leader::rtti() const
61 return RS2::EntityDimLeader;
65 * Implementation of update. Updates the arrow.
69 // find and delete arrow:
70 for(Entity * e=firstEntity(); e!=NULL; e=nextEntity())
72 if (e->rtti() == RS2::EntitySolid)
85 Entity * fe = firstEntity();
87 if (fe != NULL && fe->isAtomic())
89 Vector p1 = ((AtomicEntity *)fe)->getStartpoint();
90 Vector p2 = ((AtomicEntity *)fe)->getEndpoint();
92 // first entity must be the line which gets the arrow:
95 Solid * s = new Solid(this, SolidData());
96 s->shapeArrow(p1, p2.angleTo(p1), getGraphicVariableDouble("$DIMASZ", 2.5));
97 s->setPen(Pen(RS2::FlagInvalid));
99 EntityContainer::addEntity(s);
104 /** @return Copy of data that defines the leader. */
105 LeaderData Leader::getData() const
110 /** @return true: if this leader has an arrow at the beginning. */
111 bool Leader::hasArrowHead()
113 return data.arrowHead;
117 * Adds a vertex from the endpoint of the last element or
118 * sets the startpoint to the point 'v'.
120 * The very first vertex added is the starting point.
122 * @param v vertex coordinate
124 * @return Pointer to the entity that was addded or NULL if this
125 * was the first vertex added.
127 Entity * Leader::addVertex(const Vector & v)
129 Entity * entity = NULL;
130 static Vector last = Vector(false);
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);
145 if (count() == 1 && hasArrowHead())
155 * Reimplementation of the addEntity method for a normal container.
156 * This reimplementation deletes the given entity!
158 * To add entities use addVertex() instead.
160 void Leader::addEntity(Entity * entity)
162 DEBUG->print(Debug::D_WARNING, "Leader::addEntity: should never be called");
170 /*virtual*/ double Leader::getLength()
175 void Leader::move(Vector offset)
177 EntityContainer::move(offset);
181 void Leader::rotate(Vector center, double angle)
183 EntityContainer::rotate(center, angle);
187 void Leader::scale(Vector center, Vector factor)
189 EntityContainer::scale(center, factor);
193 void Leader::mirror(Vector axisPoint1, Vector axisPoint2)
195 EntityContainer::mirror(axisPoint1, axisPoint2);
199 void Leader::stretch(Vector firstCorner, Vector secondCorner, Vector offset)
201 EntityContainer::stretch(firstCorner, secondCorner, offset);
206 * Dumps the leader's data to stdout.
208 std::ostream & operator<<(std::ostream & os, const Leader & l)
210 os << " Leader: " << l.getData() << " {\n";
211 os << (EntityContainer &)l;