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 RS_Leader::RS_Leader(RS_EntityContainer * parent): RS_EntityContainer(parent)
33 * @param d Leader data
35 RS_Leader::RS_Leader(RS_EntityContainer * parent, const RS_LeaderData & d):
36 RS_EntityContainer(parent), data(d)
44 RS_Leader::~RS_Leader()
48 /*virtual*/ RS_Entity * RS_Leader::clone()
50 RS_Leader * p = new RS_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 RS_Leader::rtti() const
61 return RS2::EntityDimLeader;
65 * Implementation of update. Updates the arrow.
67 void RS_Leader::update()
69 // find and delete arrow:
70 for(RS_Entity * e=firstEntity(); e!=NULL; e=nextEntity())
72 if (e->rtti() == RS2::EntitySolid)
85 RS_Entity * fe = firstEntity();
87 if (fe != NULL && fe->isAtomic())
89 Vector p1 = ((RS_AtomicEntity *)fe)->getStartpoint();
90 Vector p2 = ((RS_AtomicEntity *)fe)->getEndpoint();
92 // first entity must be the line which gets the arrow:
95 RS_Solid * s = new RS_Solid(this, RS_SolidData());
96 s->shapeArrow(p1, p2.angleTo(p1), getGraphicVariableDouble("$DIMASZ", 2.5));
97 s->setPen(RS_Pen(RS2::FlagInvalid));
99 RS_EntityContainer::addEntity(s);
104 /** @return Copy of data that defines the leader. */
105 RS_LeaderData RS_Leader::getData() const
110 /** @return true: if this leader has an arrow at the beginning. */
111 bool RS_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 RS_Entity * RS_Leader::addVertex(const Vector & v)
129 RS_Entity * entity = NULL;
130 static Vector last = Vector(false);
139 // add line to the leader:
140 entity = new RS_Line(this, RS_LineData(last, v));
141 entity->setPen(RS_Pen(RS2::FlagInvalid));
142 entity->setLayer(NULL);
143 RS_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 RS_Leader::addEntity(RS_Entity * entity)
162 RS_DEBUG->print(RS_Debug::D_WARNING, "RS_Leader::addEntity: should never be called");
170 /*virtual*/ double RS_Leader::getLength()
175 void RS_Leader::move(Vector offset)
177 RS_EntityContainer::move(offset);
181 void RS_Leader::rotate(Vector center, double angle)
183 RS_EntityContainer::rotate(center, angle);
187 void RS_Leader::scale(Vector center, Vector factor)
189 RS_EntityContainer::scale(center, factor);
193 void RS_Leader::mirror(Vector axisPoint1, Vector axisPoint2)
195 RS_EntityContainer::mirror(axisPoint1, axisPoint2);
199 void RS_Leader::stretch(Vector firstCorner, Vector secondCorner, Vector offset)
201 RS_EntityContainer::stretch(firstCorner, secondCorner, offset);
206 * Dumps the leader's data to stdout.
208 std::ostream & operator<<(std::ostream & os, const RS_Leader & l)
210 os << " Leader: " << l.getData() << " {\n";
211 os << (RS_EntityContainer &)l;