1 /****************************************************************************
2 ** $Id: rs_pattern.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_pattern.h"
30 #include "rs_system.h"
31 #include "rs_fileio.h"
32 #include "rs_graphic.h"
37 * @param fileName File name of a DXF file defining the pattern
39 RS_Pattern::RS_Pattern(const QString & fileName): RS_EntityContainer(NULL)
41 RS_DEBUG->print("RS_Pattern::RS_Pattern() ");
43 this->fileName = fileName;
50 * @param fileName File name of a PAT file which defines this
51 * pattern among others.
52 * @param name Pattern name.
55 /*RS_Pattern::RS_Pattern(const QString& fileName, const QString& name)
56 : RS_EntityContainer(NULL) {
57 this->fileName = fileName;
62 RS_Pattern::~RS_Pattern()
67 * Loads the given pattern file into this pattern.
68 * Entities other than lines are ignored.
70 * @param filename File name of the pattern file (without path and
71 * extension or full path.
73 bool RS_Pattern::loadPattern()
78 RS_DEBUG->print("RS_Pattern::loadPattern");
82 // Search for the appropriate pattern if we have only the name of the pattern:
83 if (!fileName.toLower().contains(".dxf"))
85 QStringList patterns = RS_SYSTEM->getPatternList();
88 for(QStringList::Iterator it=patterns.begin(); it!=patterns.end(); it++)
90 if (QFileInfo(*it).baseName().toLower() == fileName.toLower())
93 RS_DEBUG->print("Pattern found: %s", path.toLatin1().data());
98 // We have the full path of the pattern:
104 // No pattern paths found:
107 RS_DEBUG->print("No pattern \"%s\"available.", fileName.toLatin1().data());
111 RS_Graphic * gr = new RS_Graphic();
113 // TODO: Find out why the new dxf filter doesn't work for patterns:
114 RS_FILEIO->fileImport(*gr, path, RS2::FormatDXF1);
116 for(RS_Entity * e=gr->firstEntity(); e!=NULL; e=gr->nextEntity())
118 if (e->rtti() == RS2::EntityLine || e->rtti() == RS2::EntityArc)
120 RS_Layer * l = e->getLayer();
121 RS_Entity * cl = e->clone();
126 cl->setLayer(l->getName());
135 RS_DEBUG->print("RS_Pattern::loadPattern: OK");
140 /** @return the fileName of this pattern. */
141 QString RS_Pattern::getFileName() const