| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| |
|
| | #include "rs_pattern.h" |
| |
|
| | #include <QFileInfo> |
| |
|
| | #include "rs_debug.h" |
| | #include "rs_fileio.h" |
| | #include "rs_graphic.h" |
| | #include "rs_layer.h" |
| | #include "rs_system.h" |
| |
|
| | |
| | |
| | |
| | |
| | |
| | RS_Pattern::RS_Pattern(const QString& fileName) |
| | : RS_EntityContainer(nullptr) |
| | ,fileName(fileName) |
| | ,loaded(false){ |
| | RS_DEBUG->print("RS_Pattern::RS_Pattern() "); |
| | } |
| |
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | RS_Entity* RS_Pattern::clone() const{ |
| | auto* cloned = new RS_Pattern(fileName); |
| | cloned->loaded = loaded; |
| | if (loaded) { |
| | for (auto* entity : *this) { |
| | cloned->addEntity(isOwner() ? entity->clone() : entity); |
| | } |
| | } |
| | return cloned; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | bool RS_Pattern::loadPattern() { |
| | if (loaded) { |
| | return true; |
| | } |
| |
|
| | RS_DEBUG->print("RS_Pattern::loadPattern"); |
| |
|
| | |
| | QString path; |
| |
|
| | if (!fileName.endsWith(".dxf", Qt::CaseInsensitive)) { |
| | foreach (const QString& path0, RS_SYSTEM->getPatternList()) { |
| | if (QFileInfo(path0).baseName().toLower()==fileName.toLower()) { |
| | path = path0; |
| | RS_DEBUG->print("Pattern found: %s", path.toLatin1().data()); |
| | break; |
| | } |
| | } |
| | if (path.isEmpty()) { |
| | RS_DEBUG->print("Pattern not found: %s", fileName.toLatin1().data()); |
| | } |
| | } |
| |
|
| | |
| | else { |
| | path = fileName; |
| | } |
| |
|
| | |
| | if (path.isEmpty()) { |
| | RS_DEBUG->print("No pattern \"%s\"available.", fileName.toLatin1().data()); |
| | return false; |
| | } |
| |
|
| | RS_Graphic gr; |
| | RS_FileIO::instance()->fileImport(gr, path); |
| | for(const auto* e: gr){ |
| | if (e && (e->rtti() == RS2::EntityLine || |
| | e->rtti() == RS2::EntityArc || |
| | e->rtti() == RS2::EntityEllipse |
| | )) { |
| | RS_Layer* l = e->getLayer(); |
| | RS_Entity* cl = e->clone(); |
| | cl->reparent(this); |
| | if (l) { |
| | cl->setLayer(l->getName()); |
| | } |
| | addEntity(cl); |
| | } |
| | } |
| |
|
| | loaded = true; |
| | RS_DEBUG->print("RS_Pattern::loadPattern: OK"); |
| |
|
| | return true; |
| | } |
| |
|
| | QString RS_Pattern::getFileName() const { |
| | return fileName; |
| | } |
| |
|