* Loads the given pattern file into this pattern. * Entities other than lines are ignored. * * @param filename File name of the pattern file (without path and * extension or full path. */
| 68 | * extension or full path. |
| 69 | */ |
| 70 | bool RS_Pattern::loadPattern() { |
| 71 | if (loaded) { |
| 72 | return true; |
| 73 | } |
| 74 | |
| 75 | RS_DEBUG->print("RS_Pattern::loadPattern"); |
| 76 | |
| 77 | // Search for the appropriate pattern if we have only the name of the pattern: |
| 78 | QString path; |
| 79 | |
| 80 | if (!fileName.endsWith(".dxf", Qt::CaseInsensitive)) { |
| 81 | QStringList patterns = RS_SYSTEM->getPatternList(); |
| 82 | foreach (const QString& path0, RS_SYSTEM->getPatternList()) { |
| 83 | if (QFileInfo(path0).baseName().toLower()==fileName.toLower()) { |
| 84 | path = path0; |
| 85 | RS_DEBUG->print("Pattern found: %s", path.toLatin1().data()); |
| 86 | break; |
| 87 | } |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | // We have the full path of the pattern: |
| 92 | else { |
| 93 | path = fileName; |
| 94 | } |
| 95 | |
| 96 | // No pattern paths found: |
| 97 | if (path.isEmpty()) { |
| 98 | RS_DEBUG->print("No pattern \"%s\"available.", fileName.toLatin1().data()); |
| 99 | return false; |
| 100 | } |
| 101 | |
| 102 | RS_Graphic gr; |
| 103 | RS_FileIO::instance()->fileImport(gr, path); |
| 104 | for(auto e: gr){ |
| 105 | if (e->rtti()==RS2::EntityLine || |
| 106 | e->rtti()==RS2::EntityArc|| |
| 107 | e->rtti()==RS2::EntityEllipse |
| 108 | ) { |
| 109 | RS_Layer* l = e->getLayer(); |
| 110 | RS_Entity* cl = e->clone(); |
| 111 | cl->reparent(this); |
| 112 | if (l) { |
| 113 | cl->setLayer(l->getName()); |
| 114 | } |
| 115 | addEntity(cl); |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | loaded = true; |
| 120 | RS_DEBUG->print("RS_Pattern::loadPattern: OK"); |
| 121 | |
| 122 | return true; |
| 123 | } |
| 124 | |
| 125 | QString RS_Pattern::getFileName() const { |
| 126 | return fileName; |
no test coverage detected