| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | #include "lc_dimstyleslist.h" |
| |
|
| | #include "lc_dimstyle.h" |
| |
|
| | LC_DimStylesList::LC_DimStylesList() { |
| | m_fallbackDimStyleFromVars = std::make_unique<LC_DimStyle>(); |
| | m_fallbackDimStyleFromVars->setFromVars(true); |
| | } |
| |
|
| | LC_DimStylesList::~LC_DimStylesList() { |
| | qDeleteAll(m_stylesList); |
| | } |
| |
|
| | LC_DimStyle *LC_DimStylesList::findByName(const QString &name) const { |
| | |
| | for (auto v: m_stylesList){ |
| | if (v->getName().compare(name, Qt::CaseInsensitive) == 0){ |
| | return v; |
| | } |
| | } |
| | return nullptr; |
| | } |
| |
|
| | LC_DimStyle *LC_DimStylesList::findByBaseNameAndType(const QString &name, RS2::EntityType dimType) const { |
| | if (dimType == RS2::EntityUnknown) { |
| | return findByName(name); |
| | } |
| | QString nameSuffix = LC_DimStyle::getDimStyleNameSuffixForType(dimType); |
| | QString nameToFind = name + nameSuffix; |
| | auto result = findByName(nameToFind); |
| | if (result == nullptr) { |
| | if (dimType == RS2::EntityDimAligned) { |
| | |
| | nameToFind = LC_DimStyle::getStyleNameForBaseAndType(name, RS2::EntityDimLinear); |
| | return findByName(nameToFind); |
| | } |
| | if (dimType == RS2::EntityTolerance) { |
| | |
| | nameToFind = LC_DimStyle::getStyleNameForBaseAndType(name, RS2::EntityDimLeader); |
| | return findByName(nameToFind); |
| | } |
| | } |
| | return nullptr; |
| | } |
| |
|
| |
|
| | LC_DimStyle* LC_DimStylesList::resolveByBaseName(const QString& name, RS2::EntityType dimType) const { |
| | QString nameSuffix = LC_DimStyle::getDimStyleNameSuffixForType(dimType); |
| | if (nameSuffix.isEmpty()) { |
| | return findByName(name); |
| | } |
| |
|
| | QString nameForType = name + nameSuffix; |
| | LC_DimStyle* res = findByName(nameForType); |
| | if (res == nullptr) { |
| | if (dimType == RS2::EntityDimAligned) { |
| | |
| | nameForType = LC_DimStyle::getStyleNameForBaseAndType(name, RS2::EntityDimLinear); |
| | res = findByName(nameForType); |
| | if (res != nullptr) { |
| | return res; |
| | } |
| | } |
| | else if (dimType == RS2::EntityTolerance) { |
| | |
| | nameForType = LC_DimStyle::getStyleNameForBaseAndType(name, RS2::EntityDimLeader); |
| | res = findByName(nameForType); |
| | if (res != nullptr) { |
| | return res; |
| | } |
| | } |
| | return findByName(name); |
| | } |
| | return res; |
| | } |
| |
|
| | LC_DimStyle* LC_DimStylesList::resolveByName(const QString& name, RS2::EntityType dimType) const { |
| | LC_DimStyle* res = nullptr; |
| |
|
| | |
| | if (name.contains(LC_DimStyle::NAME_SEPARATOR)) { |
| | res = findByName(name); |
| | if (res != nullptr) { |
| | return res; |
| | } |
| | |
| | QString baseName; |
| | RS2::EntityType type; |
| | LC_DimStyle::parseStyleName(name, baseName, type); |
| | return resolveByBaseName(baseName, dimType); |
| | } |
| | return resolveByBaseName(name, dimType); |
| | } |
| |
|
| |
|
| | void LC_DimStylesList::addDimStyle(LC_DimStyle *style) { |
| | |
| | m_stylesList.append(style); |
| | setModified(true); |
| | } |
| |
|
| | void LC_DimStylesList::deleteDimStyle([[maybe_unused]]QString &name) { |
| | |
| | setModified(true); |
| | } |
| |
|
| | void LC_DimStylesList::clear() { |
| | m_stylesList.clear(); |
| | setModified(true); |
| | } |
| |
|
| | void LC_DimStylesList::mergeStyles() { |
| |
|
| | QMap<QString, LC_DimStyle*> baseStyles; |
| | QList<LC_DimStyle*> entityTypeStyles; |
| | for (auto ds: m_stylesList) { |
| | QString baseName; |
| | RS2::EntityType entityType; |
| | LC_DimStyle::parseStyleName(ds->getName(), baseName, entityType); |
| | if (entityType == RS2::EntityUnknown) { |
| | baseStyles[baseName] = ds; |
| | } |
| | else { |
| | entityTypeStyles.append(ds); |
| | } |
| | } |
| |
|
| | for (auto typeSpecificStyle: entityTypeStyles) { |
| | QString baseName; |
| | RS2::EntityType entityType; |
| | LC_DimStyle::parseStyleName(typeSpecificStyle->getName(), baseName, entityType); |
| |
|
| | if (baseStyles.contains(baseName)) { |
| | auto baseStyle = baseStyles[baseName]; |
| | auto savedCheckMode = typeSpecificStyle->getModifyCheckMode(); |
| |
|
| | |
| | |
| | typeSpecificStyle->mergeWith(baseStyle, LC_DimStyle::ModificationAware::UNSET, savedCheckMode); |
| | } |
| | } |
| | } |
| |
|
| | void LC_DimStylesList::replaceStyles(const QList<LC_DimStyle*>& list) { |
| | qDeleteAll(m_stylesList); |
| | m_stylesList.clear(); |
| | m_stylesList.append(list); |
| | mergeStyles(); |
| | setModified(true); |
| | } |
| |
|