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_pattern.h"
18 #include "rs_system.h"
19 #include "rs_fileio.h"
25 * @param fileName File name of a DXF file defining the pattern
27 RS_Pattern::RS_Pattern(const QString & fileName): RS_EntityContainer(NULL)
29 RS_DEBUG->print("RS_Pattern::RS_Pattern() ");
31 this->fileName = fileName;
38 * @param fileName File name of a PAT file which defines this
39 * pattern among others.
40 * @param name Pattern name.
43 /*RS_Pattern::RS_Pattern(const QString& fileName, const QString& name)
44 : RS_EntityContainer(NULL) {
45 this->fileName = fileName;
50 RS_Pattern::~RS_Pattern()
55 * Loads the given pattern file into this pattern.
56 * Entities other than lines are ignored.
58 * @param filename File name of the pattern file (without path and
59 * extension or full path.
61 bool RS_Pattern::loadPattern()
66 RS_DEBUG->print("RS_Pattern::loadPattern");
70 // Search for the appropriate pattern if we have only the name of the pattern:
71 if (!fileName.toLower().contains(".dxf"))
73 QStringList patterns = RS_SYSTEM->getPatternList();
76 for(QStringList::Iterator it=patterns.begin(); it!=patterns.end(); it++)
78 if (QFileInfo(*it).baseName().toLower() == fileName.toLower())
81 RS_DEBUG->print("Pattern found: %s", path.toLatin1().data());
86 // We have the full path of the pattern:
92 // No pattern paths found:
95 RS_DEBUG->print("No pattern \"%s\"available.", fileName.toLatin1().data());
99 Drawing * gr = new Drawing();
101 // TODO: Find out why the new dxf filter doesn't work for patterns:
102 RS_FILEIO->fileImport(*gr, path, RS2::FormatDXF1);
104 for(RS_Entity * e=gr->firstEntity(); e!=NULL; e=gr->nextEntity())
106 if (e->rtti() == RS2::EntityLine || e->rtti() == RS2::EntityArc)
108 RS_Layer * l = e->getLayer();
109 RS_Entity * cl = e->clone();
114 cl->setLayer(l->getName());
123 RS_DEBUG->print("RS_Pattern::loadPattern: OK");
128 /** @return the fileName of this pattern. */
129 QString RS_Pattern::getFileName() const