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 05/21/2010 Added this text. :-)
19 #include "entitycontainer.h"
20 #include "graphicview.h"
21 #include "information.h"
22 #include "paintinterface.h"
28 Preview::Preview(EntityContainer * parent): EntityContainer(parent),
31 settings.beginGroup("Appearance");
32 maxEntities = settings.value("MaxPreview", 100).toInt();
44 * Adds an entity to this preview and removes any attributes / layer
45 * connectsions before that.
47 void Preview::addEntity(Entity * entity)
49 if (entity == NULL || entity->isUndone())
52 // Only border preview for complex entities:
53 bool addBorder = false;
55 if (entity->rtti() == RS2::EntityImage || entity->rtti() == RS2::EntityHatch
56 || entity->rtti() == RS2::EntityInsert)
60 else if (entity->isContainer() && entity->rtti() != RS2::EntitySpline)
62 if (entity->countDeep() > maxEntities - countDeep())
68 Vector min = entity->getMin();
69 Vector max = entity->getMax();
71 Line * l1 = new Line(this, LineData(Vector(min.x, min.y), Vector(max.x, min.y)));
72 Line * l2 = new Line(this, LineData(Vector(max.x, min.y), Vector(max.x, max.y)));
73 Line * l3 = new Line(this, LineData(Vector(max.x, max.y), Vector(min.x, max.y)));
74 Line * l4 = new Line(this, LineData(Vector(min.x, max.y), Vector(min.x, min.y)));
76 EntityContainer::addEntity(l1);
77 EntityContainer::addEntity(l2);
78 EntityContainer::addEntity(l3);
79 EntityContainer::addEntity(l4);
86 entity->setLayer(NULL);
87 entity->setSelected(false);
88 entity->reparent(this);
89 entity->setPen(Pen(Color(255, 255, 255), RS2::Width00, RS2::SolidLine));
90 EntityContainer::addEntity(entity);
95 * Clones the given entity and adds the clone to the preview.
97 void Preview::addCloneOf(Entity * entity)
102 Entity * clone = entity->clone();
107 * Adds all entities from 'container' to the preview (unselected).
109 void Preview::addAllFrom(EntityContainer & container)
113 for(Entity * e=container.firstEntity(); e!=NULL; e=container.nextEntity())
117 Entity * clone = e->clone();
118 clone->setSelected(false);
119 clone->reparent(this);
121 c += clone->countDeep();
123 // clone might be NULL after this point
129 * Adds all selected entities from 'container' to the preview (unselected).
131 void Preview::addSelectionFrom(EntityContainer & container)
135 for(Entity * e=container.firstEntity(); e!=NULL; e=container.nextEntity())
137 if (e->isSelected() && c < maxEntities)
139 Entity * clone = e->clone();
140 clone->setSelected(false);
141 clone->reparent(this);
143 c += clone->countDeep();
145 // clone might be NULL after this point
151 * Adds all entities in the given range and those which have endpoints in the
152 * given range to the preview.
154 void Preview::addStretchablesFrom(EntityContainer & container, const Vector & v1,
159 for(Entity * e=container.firstEntity(); e!=NULL; e=container.nextEntity())
161 if (e->isVisible() && e->rtti() != RS2::EntityHatch && (e->isInWindow(v1, v2)
162 || e->hasEndpointsWithinWindow(v1, v2)) && c < maxEntities)
164 Entity * clone = e->clone();
165 //clone->setSelected(false);
166 clone->reparent(this);
168 c += clone->countDeep();
170 // clone might be NULL after this point
175 void Preview::SetOffset(Vector v)
180 Vector Preview::Offset(void)
185 void Preview::SetVisible(bool visibility/*= true*/)
187 visible = visibility;
190 bool Preview::Visible(void)
195 void Preview::Draw(GraphicView * view, PaintInterface * painter)
200 painter->setPen(Pen(Color(60, 255, 80), RS2::Width00, RS2::SolidLine));
201 painter->setOffset(offset);
203 // We have to traverse the container ourselves, because RS_Container::draw()
204 // uses drawEntity() instead of drawEntityPlain()...
205 for(Entity * e=firstEntity(RS2::ResolveNone); e!=NULL; e=nextEntity(RS2::ResolveNone))
206 view->drawEntityPlain(e);
208 painter->setOffset(Vector(0, 0));