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 05/21/2010 Added this text. :-)
15 #include "rs_preview.h"
17 #include "rs_entitycontainer.h"
18 #include "rs_graphicview.h"
19 #include "rs_information.h"
25 RS_Preview::RS_Preview(RS_EntityContainer * parent): RS_EntityContainer(parent)
27 settings.beginGroup("Appearance");
28 maxEntities = settings.value("MaxPreview", 100).toInt();
35 RS_Preview::~RS_Preview()
40 * Adds an entity to this preview and removes any attributes / layer
41 * connectsions before that.
43 void RS_Preview::addEntity(RS_Entity * entity)
45 if (entity == NULL || entity->isUndone())
48 // only border preview for complex entities:
49 //if ((entity->count() > maxEntities-count()) &&
51 bool addBorder = false;
53 if (entity->rtti() == RS2::EntityImage || entity->rtti() == RS2::EntityHatch
54 || entity->rtti() == RS2::EntityInsert)
60 if (entity->isContainer() && entity->rtti() != RS2::EntitySpline)
62 if (entity->countDeep() > maxEntities-countDeep())
69 Vector min = entity->getMin();
70 Vector max = entity->getMax();
72 RS_Line * l1 = new RS_Line(this, RS_LineData(Vector(min.x, min.y), Vector(max.x, min.y)));
73 RS_Line * l2 = new RS_Line(this, RS_LineData(Vector(max.x, min.y), Vector(max.x, max.y)));
74 RS_Line * l3 = new RS_Line(this, RS_LineData(Vector(max.x, max.y), Vector(min.x, max.y)));
75 RS_Line * l4 = new RS_Line(this, RS_LineData(Vector(min.x, max.y), Vector(min.x, min.y)));
77 RS_EntityContainer::addEntity(l1);
78 RS_EntityContainer::addEntity(l2);
79 RS_EntityContainer::addEntity(l3);
80 RS_EntityContainer::addEntity(l4);
87 entity->setLayer(NULL);
88 entity->setSelected(false);
89 entity->reparent(this);
90 entity->setPen(RS_Pen(RS_Color(255, 255, 255), RS2::Width00, RS2::SolidLine));
91 RS_EntityContainer::addEntity(entity);
96 * Clones the given entity and adds the clone to the preview.
98 void RS_Preview::addCloneOf(RS_Entity* entity)
103 RS_Entity * clone = entity->clone();
108 * Adds all entities from 'container' to the preview (unselected).
110 void RS_Preview::addAllFrom(RS_EntityContainer & container)
114 for(RS_Entity * e=container.firstEntity(); e!=NULL; e=container.nextEntity())
118 RS_Entity * clone = e->clone();
119 clone->setSelected(false);
120 clone->reparent(this);
122 c += clone->countDeep();
124 // clone might be NULL after this point
130 * Adds all selected entities from 'container' to the preview (unselected).
132 void RS_Preview::addSelectionFrom(RS_EntityContainer & container)
136 for(RS_Entity * e=container.firstEntity(); e!=NULL; e=container.nextEntity())
138 if (e->isSelected() && c < maxEntities)
140 RS_Entity * clone = e->clone();
141 clone->setSelected(false);
142 clone->reparent(this);
144 c += clone->countDeep();
146 // clone might be NULL after this point
152 * Adds all entities in the given range and those which have endpoints
153 * in the given range to the preview.
155 void RS_Preview::addStretchablesFrom(RS_EntityContainer & container, const Vector & v1,
160 for(RS_Entity * e=container.firstEntity(); e!=NULL; e=container.nextEntity())
162 if (e->isVisible() && e->rtti() != RS2::EntityHatch && (e->isInWindow(v1, v2)
163 || e->hasEndpointsWithinWindow(v1, v2)) && c < maxEntities)
165 RS_Entity * clone = e->clone();
166 //clone->setSelected(false);
167 clone->reparent(this);
169 c += clone->countDeep();
171 // clone might be NULL after this point