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 RS_Preview::RS_Preview(RS_EntityContainer * parent): RS_EntityContainer(parent),
31 settings.beginGroup("Appearance");
32 maxEntities = settings.value("MaxPreview", 100).toInt();
39 RS_Preview::~RS_Preview()
44 * Adds an entity to this preview and removes any attributes / layer
45 * connectsions before that.
47 void RS_Preview::addEntity(RS_Entity * entity)
49 if (entity == NULL || entity->isUndone())
52 // only border preview for complex entities:
53 //if ((entity->count() > maxEntities-count()) &&
55 bool addBorder = false;
57 if (entity->rtti() == RS2::EntityImage || entity->rtti() == RS2::EntityHatch
58 || entity->rtti() == RS2::EntityInsert)
64 if (entity->isContainer() && entity->rtti() != RS2::EntitySpline)
66 if (entity->countDeep() > maxEntities-countDeep())
73 Vector min = entity->getMin();
74 Vector max = entity->getMax();
76 RS_Line * l1 = new RS_Line(this, RS_LineData(Vector(min.x, min.y), Vector(max.x, min.y)));
77 RS_Line * l2 = new RS_Line(this, RS_LineData(Vector(max.x, min.y), Vector(max.x, max.y)));
78 RS_Line * l3 = new RS_Line(this, RS_LineData(Vector(max.x, max.y), Vector(min.x, max.y)));
79 RS_Line * l4 = new RS_Line(this, RS_LineData(Vector(min.x, max.y), Vector(min.x, min.y)));
81 RS_EntityContainer::addEntity(l1);
82 RS_EntityContainer::addEntity(l2);
83 RS_EntityContainer::addEntity(l3);
84 RS_EntityContainer::addEntity(l4);
91 entity->setLayer(NULL);
92 entity->setSelected(false);
93 entity->reparent(this);
94 entity->setPen(RS_Pen(RS_Color(255, 255, 255), RS2::Width00, RS2::SolidLine));
95 RS_EntityContainer::addEntity(entity);
100 * Clones the given entity and adds the clone to the preview.
102 void RS_Preview::addCloneOf(RS_Entity * entity)
107 RS_Entity * clone = entity->clone();
112 * Adds all entities from 'container' to the preview (unselected).
114 void RS_Preview::addAllFrom(RS_EntityContainer & container)
118 for(RS_Entity * e=container.firstEntity(); e!=NULL; e=container.nextEntity())
122 RS_Entity * clone = e->clone();
123 clone->setSelected(false);
124 clone->reparent(this);
126 c += clone->countDeep();
128 // clone might be NULL after this point
134 * Adds all selected entities from 'container' to the preview (unselected).
136 void RS_Preview::addSelectionFrom(RS_EntityContainer & container)
140 for(RS_Entity * e=container.firstEntity(); e!=NULL; e=container.nextEntity())
142 if (e->isSelected() && c < maxEntities)
144 RS_Entity * clone = e->clone();
145 clone->setSelected(false);
146 clone->reparent(this);
148 c += clone->countDeep();
150 // clone might be NULL after this point
156 * Adds all entities in the given range and those which have endpoints in the
157 * given range to the preview.
159 void RS_Preview::addStretchablesFrom(RS_EntityContainer & container, const Vector & v1,
164 for(RS_Entity * e=container.firstEntity(); e!=NULL; e=container.nextEntity())
166 if (e->isVisible() && e->rtti() != RS2::EntityHatch && (e->isInWindow(v1, v2)
167 || e->hasEndpointsWithinWindow(v1, v2)) && c < maxEntities)
169 RS_Entity * clone = e->clone();
170 //clone->setSelected(false);
171 clone->reparent(this);
173 c += clone->countDeep();
175 // clone might be NULL after this point
180 void RS_Preview::SetOffset(Vector v)
185 Vector RS_Preview::Offset(void)
190 void RS_Preview::SetVisible(bool visibility/*= true*/)
192 visible = visibility;
195 bool RS_Preview::Visible(void)
200 void RS_Preview::Draw(GraphicView * view, PaintInterface * painter)
205 painter->setPen(RS_Pen(RS_Color(60, 255, 80), RS2::Width00, RS2::SolidLine));
206 painter->setOffset(offset);
208 // We have to traverse the container ourselves, because RS_Container::draw()
209 // uses drawEntity() instead of drawEntityPlain()...
210 for(RS_Entity * e=firstEntity(RS2::ResolveNone); e!=NULL; e=nextEntity(RS2::ResolveNone))
211 view->drawEntityPlain(e);
213 painter->setOffset(Vector(0, 0));