| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | #include<iostream> |
| | #include "rs_patternlist.h" |
| |
|
| | #include <QFileInfo> |
| | #include <QStringList> |
| |
|
| | #include "rs_debug.h" |
| | #include "rs_dialogfactory.h" |
| | #include "rs_dialogfactoryinterface.h" |
| | #include "rs_pattern.h" |
| | #include "rs_system.h" |
| |
|
| | RS_PatternList* RS_PatternList::instance() { |
| | static RS_PatternList instance; |
| | return &instance; |
| | } |
| |
|
| | RS_PatternList::~RS_PatternList() = default; |
| |
|
| | |
| | |
| | |
| | |
| | void RS_PatternList::init() { |
| | RS_DEBUG->print("RS_PatternList::initPatterns"); |
| |
|
| | QStringList list = RS_SYSTEM->getPatternList(); |
| |
|
| | patterns.clear(); |
| |
|
| | foreach(auto const& s, list) { |
| | RS_DEBUG->print("pattern: %s:", s.toLatin1().data()); |
| |
|
| | QString const name = QFileInfo(s).baseName().toLower(); |
| | patterns.emplace(name, std::unique_ptr<RS_Pattern>{}); |
| |
|
| | RS_DEBUG->print("base: %s", name.toLatin1().data()); |
| | } |
| | if (patterns.empty()) |
| | RS_DIALOGFACTORY->commandMessage(QObject::tr("Hatch:: no pattern found. Please set pattern path in application preferences")); |
| | } |
| |
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | std::unique_ptr<RS_Pattern> RS_PatternList::requestPattern(const QString& name) { |
| | RS_DEBUG->print("RS_PatternList::requestPattern %s", name.toLatin1().data()); |
| |
|
| | QString name2 = name.toLower(); |
| | RS_DEBUG->print("Pattern: name2: %s", name2.toLatin1().data()); |
| | if (patterns.count(name2) == 0 || patterns.at(name2) == nullptr) { |
| | auto p = std::make_unique<RS_Pattern>(name2); |
| | if (p!=nullptr) { |
| | if (p->loadPattern()) { |
| | patterns.emplace(name2, std::unique_ptr<RS_Pattern>{}); |
| | patterns[name2].swap(p); |
| | } |
| | else { |
| | patterns.erase(name2); |
| | } |
| | } |
| | else { |
| | LC_ERR<<"RS_PatternList::"<<__func__<<"(): loading pattern failed: "<<name2; |
| | RS_DIALOGFACTORY->commandMessage(QObject::tr("Hatch:: loading pattern failed: %1").arg(name2)); |
| | return {}; |
| | } |
| | } |
| |
|
| | if (patterns.count(name2) == 1) { |
| | RS_DEBUG->print("name2: %s, size= %d", name2.toLatin1().data(), |
| | patterns[name2]->countDeep()); |
| | return std::unique_ptr<RS_Pattern>{static_cast<RS_Pattern*>(patterns[name2]->clone())}; |
| | } |
| |
|
| | return {}; |
| |
|
| | } |
| |
|
| | |
| | bool RS_PatternList::contains(const QString& name) const { |
| |
|
| | return patterns.count(name.toLower()); |
| |
|
| | } |
| |
|
| |
|
| | |
| | |
| | |
| | std::ostream& operator << (std::ostream& os, RS_PatternList& l) { |
| |
|
| | os << "Patternlist: \n"; |
| | for (auto const& pa: l.patterns) |
| | if (pa.second) |
| | os<< *pa.second << '\n'; |
| |
|
| | return os; |
| | } |
| |
|