1 /****************************************************************************
2 ** $Id: rs_leader.cpp 1938 2004-12-09 23:09:53Z andrew $
4 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
6 ** This file is part of the qcadlib Library project.
8 ** This file may be distributed and/or modified under the terms of the
9 ** GNU General Public License version 2 as published by the Free Software
10 ** Foundation and appearing in the file LICENSE.GPL included in the
11 ** packaging of this file.
13 ** Licensees holding valid qcadlib Professional Edition licenses may use
14 ** this file in accordance with the qcadlib Commercial License
15 ** Agreement provided with the Software.
17 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
18 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 ** See http://www.ribbonsoft.com for further details.
22 ** Contact info@ribbonsoft.com if any conditions of this licensing are
25 **********************************************************************/
27 #include "rs_leader.h"
36 RS_Leader::RS_Leader(RS_EntityContainer * parent): RS_EntityContainer(parent)
43 * @param d Leader data
45 RS_Leader::RS_Leader(RS_EntityContainer * parent, const RS_LeaderData & d):
46 RS_EntityContainer(parent), data(d)
54 RS_Leader::~RS_Leader()
58 /*virtual*/ RS_Entity * RS_Leader::clone()
60 RS_Leader * p = new RS_Leader(*this);
61 #warning "!!! Need to deal with setAutoDelete() Qt3->Qt4 !!!"
62 // p->entities.setAutoDelete(entities.autoDelete());
68 /** @return RS2::EntityDimLeader */
69 /*virtual*/ RS2::EntityType RS_Leader::rtti() const
71 return RS2::EntityDimLeader;
75 * Implementation of update. Updates the arrow.
77 void RS_Leader::update()
79 // find and delete arrow:
80 for(RS_Entity * e=firstEntity(); e!=NULL; e=nextEntity())
82 if (e->rtti() == RS2::EntitySolid)
95 RS_Entity * fe = firstEntity();
97 if (fe != NULL && fe->isAtomic())
99 Vector p1 = ((RS_AtomicEntity *)fe)->getStartpoint();
100 Vector p2 = ((RS_AtomicEntity *)fe)->getEndpoint();
102 // first entity must be the line which gets the arrow:
105 RS_Solid * s = new RS_Solid(this, RS_SolidData());
106 s->shapeArrow(p1, p2.angleTo(p1), getGraphicVariableDouble("$DIMASZ", 2.5));
107 s->setPen(RS_Pen(RS2::FlagInvalid));
109 RS_EntityContainer::addEntity(s);
114 /** @return Copy of data that defines the leader. */
115 RS_LeaderData RS_Leader::getData() const
120 /** @return true: if this leader has an arrow at the beginning. */
121 bool RS_Leader::hasArrowHead()
123 return data.arrowHead;
127 * Adds a vertex from the endpoint of the last element or
128 * sets the startpoint to the point 'v'.
130 * The very first vertex added is the starting point.
132 * @param v vertex coordinate
134 * @return Pointer to the entity that was addded or NULL if this
135 * was the first vertex added.
137 RS_Entity * RS_Leader::addVertex(const Vector & v)
139 RS_Entity * entity = NULL;
140 static Vector last = Vector(false);
149 // add line to the leader:
150 entity = new RS_Line(this, RS_LineData(last, v));
151 entity->setPen(RS_Pen(RS2::FlagInvalid));
152 entity->setLayer(NULL);
153 RS_EntityContainer::addEntity(entity);
155 if (count() == 1 && hasArrowHead())
165 * Reimplementation of the addEntity method for a normal container.
166 * This reimplementation deletes the given entity!
168 * To add entities use addVertex() instead.
170 void RS_Leader::addEntity(RS_Entity * entity)
172 RS_DEBUG->print(RS_Debug::D_WARNING, "RS_Leader::addEntity: should never be called");
180 /*virtual*/ double RS_Leader::getLength()
185 void RS_Leader::move(Vector offset)
187 RS_EntityContainer::move(offset);
191 void RS_Leader::rotate(Vector center, double angle)
193 RS_EntityContainer::rotate(center, angle);
197 void RS_Leader::scale(Vector center, Vector factor)
199 RS_EntityContainer::scale(center, factor);
203 void RS_Leader::mirror(Vector axisPoint1, Vector axisPoint2)
205 RS_EntityContainer::mirror(axisPoint1, axisPoint2);
209 void RS_Leader::stretch(Vector firstCorner, Vector secondCorner, Vector offset)
211 RS_EntityContainer::stretch(firstCorner, secondCorner, offset);
216 * Dumps the leader's data to stdout.
218 std::ostream & operator<<(std::ostream & os, const RS_Leader & l)
220 os << " Leader: " << l.getData() << " {\n";
221 os << (RS_EntityContainer &)l;