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
8 // JLH = James L. Hammons <jlhamm@acm.org>
11 // --- ---------- -----------------------------------------------------------
12 // JLH 06/01/2010 Added this text. :-)
15 #include "rs_leader.h"
24 RS_Leader::RS_Leader(RS_EntityContainer * parent): RS_EntityContainer(parent)
31 * @param d Leader data
33 RS_Leader::RS_Leader(RS_EntityContainer * parent, const RS_LeaderData & d):
34 RS_EntityContainer(parent), data(d)
42 RS_Leader::~RS_Leader()
46 /*virtual*/ RS_Entity * RS_Leader::clone()
48 RS_Leader * p = new RS_Leader(*this);
49 #warning "!!! Need to deal with setAutoDelete() Qt3->Qt4 !!!"
50 // p->entities.setAutoDelete(entities.autoDelete());
56 /** @return RS2::EntityDimLeader */
57 /*virtual*/ RS2::EntityType RS_Leader::rtti() const
59 return RS2::EntityDimLeader;
63 * Implementation of update. Updates the arrow.
65 void RS_Leader::update()
67 // find and delete arrow:
68 for(RS_Entity * e=firstEntity(); e!=NULL; e=nextEntity())
70 if (e->rtti() == RS2::EntitySolid)
83 RS_Entity * fe = firstEntity();
85 if (fe != NULL && fe->isAtomic())
87 Vector p1 = ((RS_AtomicEntity *)fe)->getStartpoint();
88 Vector p2 = ((RS_AtomicEntity *)fe)->getEndpoint();
90 // first entity must be the line which gets the arrow:
93 RS_Solid * s = new RS_Solid(this, RS_SolidData());
94 s->shapeArrow(p1, p2.angleTo(p1), getGraphicVariableDouble("$DIMASZ", 2.5));
95 s->setPen(RS_Pen(RS2::FlagInvalid));
97 RS_EntityContainer::addEntity(s);
102 /** @return Copy of data that defines the leader. */
103 RS_LeaderData RS_Leader::getData() const
108 /** @return true: if this leader has an arrow at the beginning. */
109 bool RS_Leader::hasArrowHead()
111 return data.arrowHead;
115 * Adds a vertex from the endpoint of the last element or
116 * sets the startpoint to the point 'v'.
118 * The very first vertex added is the starting point.
120 * @param v vertex coordinate
122 * @return Pointer to the entity that was addded or NULL if this
123 * was the first vertex added.
125 RS_Entity * RS_Leader::addVertex(const Vector & v)
127 RS_Entity * entity = NULL;
128 static Vector last = Vector(false);
137 // add line to the leader:
138 entity = new RS_Line(this, RS_LineData(last, v));
139 entity->setPen(RS_Pen(RS2::FlagInvalid));
140 entity->setLayer(NULL);
141 RS_EntityContainer::addEntity(entity);
143 if (count() == 1 && hasArrowHead())
153 * Reimplementation of the addEntity method for a normal container.
154 * This reimplementation deletes the given entity!
156 * To add entities use addVertex() instead.
158 void RS_Leader::addEntity(RS_Entity * entity)
160 RS_DEBUG->print(RS_Debug::D_WARNING, "RS_Leader::addEntity: should never be called");
168 /*virtual*/ double RS_Leader::getLength()
173 void RS_Leader::move(Vector offset)
175 RS_EntityContainer::move(offset);
179 void RS_Leader::rotate(Vector center, double angle)
181 RS_EntityContainer::rotate(center, angle);
185 void RS_Leader::scale(Vector center, Vector factor)
187 RS_EntityContainer::scale(center, factor);
191 void RS_Leader::mirror(Vector axisPoint1, Vector axisPoint2)
193 RS_EntityContainer::mirror(axisPoint1, axisPoint2);
197 void RS_Leader::stretch(Vector firstCorner, Vector secondCorner, Vector offset)
199 RS_EntityContainer::stretch(firstCorner, secondCorner, offset);
204 * Dumps the leader's data to stdout.
206 std::ostream & operator<<(std::ostream & os, const RS_Leader & l)
208 os << " Leader: " << l.getData() << " {\n";
209 os << (RS_EntityContainer &)l;