Compare commits

..

5 commits

Author SHA1 Message Date
Roman Telezhynskyi 9b925dd996 Fix float-point accuracy issue in multisize measurements dimensions. 2023-03-23 08:39:31 +02:00
Roman Telezhynskyi 2334a04fbd Validate dimensions while reading multisize measurements. 2023-03-23 08:36:11 +02:00
Roman Telezhynskyi 3f2806a695 Refactoring. 2023-03-23 08:21:02 +02:00
Roman Telezhynskyi f247a1e895 Clean stale artifacts. 2023-03-11 13:55:40 +02:00
Roman Telezhynskyi 740f70c030 Refactoring. 2023-03-11 13:43:50 +02:00
11 changed files with 283 additions and 82 deletions

View file

@ -17,6 +17,7 @@
- Improve labels for V notch.
- Fix QT issue on MacOS version 11.0 "Big Sur".
- Fix excluding objects in internal path.
- Fix float-point accuracy issue in multisize measurements dimensions.
# Valentina 0.7.52 September 12, 2022
- Fix crash when default locale is ru.

View file

@ -17,6 +17,15 @@ if($env:DEPLOY -eq "true") {
Write-Host "[CI] Done." -ForegroundColor Green;
}
Write-Host "[CI] Starting cleaning." -ForegroundColor Green;
& $env:PYTHON\python.exe "$env:APPVEYOR_BUILD_FOLDER\scripts\deploy.py" clean $env:ACCESS_TOKEN;
if ($LastExitCode -ne 0) {
Write-Error -Message "[CI] Error cleaning stale artifacts." -Category InvalidResult;
exit 1;
} else {
Write-Host "[CI] Cleaning done." -ForegroundColor Green;
}
Write-Host "[CI] Uploading." -ForegroundColor Green;
& $env:PYTHON\python.exe "$env:APPVEYOR_BUILD_FOLDER\scripts\deploy.py" upload $env:ACCESS_TOKEN "$env:INSTALL_ROOT\$file_name" "/0.7.x/Windows/$file_name";
if ($LastExitCode -ne 0) {

View file

@ -32,6 +32,10 @@ if [[ "$DEPLOY" == "true" ]]; then
check_failure "Unable to create an archive for Puzzle bundle.";
fi
print_info "Start cleaning.";
python3 $CIRRUS_WORKING_DIR/scripts/deploy.py clean $ACCESS_TOKEN;
check_failure "Unable to clean stale artifacts.";
print_info "Start uploading.";
if [[ "$MULTI_BUNDLE" == "false" ]]; then
python3 $CIRRUS_WORKING_DIR/scripts/deploy.py upload $ACCESS_TOKEN $CIRRUS_WORKING_DIR/valentina-${PLATFORM}-${QT_VERSION}-${ARCH}-${CIRRUS_BRANCH}-${CIRRUS_CHANGE_IN_REPO}.tar.xz "/0.7.x/Mac OS X/valentina-${PLATFORM}-${QT_VERSION}-${ARCH}-${CIRRUS_CHANGE_IN_REPO}.tar.xz";

View file

@ -1,6 +1,8 @@
import argparse
import datetime
import os
import pathlib
import re
import shutil
import sys
@ -19,7 +21,7 @@ def run_auth():
auth_flow = DropboxOAuth2FlowNoRedirect(APP_KEY, use_pkce=True, token_access_type='offline')
authorize_url = auth_flow.start()
print("1. Go to: " + authorize_url)
print(f"1. Go to: {authorize_url}")
print("2. Click \"Allow\" (you might have to log in first).")
print("3. Copy the authorization code.")
auth_code = input("Enter the authorization code here: ").strip()
@ -27,10 +29,10 @@ def run_auth():
try:
oauth_result = auth_flow.finish(auth_code)
except Exception as e:
print('Error: %s' % (e,))
print(f'Error: {e}')
exit(1)
print("Refresh token: %s" % oauth_result.refresh_token)
print(f"Refresh token: {oauth_result.refresh_token}")
def run_pack(source, destination):
@ -48,12 +50,12 @@ def run_pack(source, destination):
".tar.xz": "xztar"
}
suffix = ''.join(pathlib.Path(base).suffixes)
format = formats.get(suffix, None)
format = formats.get(suffix)
archive_from = pathlib.Path(source).parent
archive_to = os.path.basename(source.strip(os.sep))
print(source, destination, archive_from)
shutil.make_archive(name, format, archive_from, archive_to)
shutil.move('%s%s' % (name, suffix), destination)
shutil.move(f'{name}{suffix}', destination)
def run_upload(refresh_token, file, path):
@ -65,7 +67,7 @@ def run_upload(refresh_token, file, path):
sys.exit("ERROR: Invalid access token; try re-generating an "
"access token from the app console on the web.")
print("Uploading " + file + " to Dropbox as " + path + "...")
print(f"Uploading {file} to Dropbox as {path}...")
try:
with open(file, "rb") as f:
dbx.files_upload(f.read(), path, mode=WriteMode('overwrite'))
@ -83,6 +85,95 @@ def run_upload(refresh_token, file, path):
sys.exit()
print("Successfully uploaded")
def folder_mod_time(dbx, folder):
folder_mod_times = []
entries = dbx.files_list_folder(folder.path_display)
# Loop through each item in the folder list
for result in entries.entries:
# Check if the item is a file
if isinstance(result, dropbox.files.FileMetadata):
# Get the parent folder path of the file
parent_folder_path = result.path_display.rsplit('/', 1)[0]
# Get the modification time of the file
file_mod_time = result.client_modified
# Add the file modification time to the dictionary for the parent folder
folder_mod_times.append(file_mod_time)
folder_mod_times.append(datetime.datetime(1900, 1, 1, 0, 0, 0))
# Compute the maximum modification time across all files in each folder
max_mod_time = max(folder_mod_times)
return max_mod_time
# Define a function to delete a file or folder recursively
def delete_file_or_folder(dbx, item):
try:
# Check if the path is a file
if isinstance(item, dropbox.files.FileMetadata):
dbx.files_delete_v2(item.path_display)
print(f"Deleted file: {item.path_display}")
# Check if the path is a folder
elif isinstance(item, dropbox.files.FolderMetadata):
# Recursively delete all files and subfolders inside the folder
for entry in dbx.files_list_folder(item.path_display).entries:
delete_file_or_folder(dbx, entry)
# Delete the folder itself
dbx.files_delete_v2(item.path_display)
print(f"Deleted folder: {item.path_display}")
except dropbox.exceptions.ApiError as e:
print(f"Error deleting {item.path_display}: {e}")
def run_clean(refresh_token):
with dropbox.Dropbox(oauth2_refresh_token=refresh_token, app_key=APP_KEY) as dbx:
# Check that the access token is valid
try:
dbx.users_get_current_account()
except AuthError:
sys.exit("ERROR: Invalid access token; try re-generating an "
"access token from the app console on the web.")
clean_folders = ["/0.7.x/Mac OS X", "/0.7.x/Windows"]
arhive_types = [r'^valentina-Windows7\+-mingw-x86-Qt5_15-develop-[a-f0-9]{40}\.tar\.xz$',
r'^valentina-Windows10\+-mingw-x64-Qt6_4-develop-[a-f0-9]{40}\.tar\.xz$',
r'^valentina-WindowsXP\+-mingw-x86-Qt5_6-develop-[a-f0-9]{40}\.tar\.xz$',
r'^valentina-macOS_11\+-Qt6_4-x64-develop-[a-f0-9]{40}\.tar\.xz$',
r'^valentina-macOS_11\+-Qt6-arm64-[a-f0-9]{7,40}\.tar\.xz$',
r'^valentina-macOS_11\+-Qt6_4-x64-multibundle-[a-f0-9]{40}$',
r'^valentina-macOS_11\+-Qt6-arm64-multibundle-[a-f0-9]{40}$',
r'^valentina-macOS10.13\+-Qt5_15-x64-multibundle-[a-f0-9]{40}$',
r'^valentina-macOS10.13\+-Qt5_15-x64-develop-[a-f0-9]{40}\.tar\.xz$']
item_types = {}
for path in clean_folders:
result = dbx.files_list_folder(path)
for entry in result.entries:
for archive_type in arhive_types:
if re.search(archive_type, entry.name):
if archive_type not in item_types:
item_types[archive_type] = []
item_types[archive_type].append(entry)
break
# Keep only the first two files of each type
to_delete = []
for items in item_types.values():
# Separate files and folders
files = [item for item in items if isinstance(item, dropbox.files.FileMetadata)]
folders = [item for item in items if isinstance(item, dropbox.files.FolderMetadata)]
# Sort files by modification time
files = sorted(files, key=lambda f: f.client_modified)
# Sort folders by last modified time on server
folders = sorted(folders, key=lambda f: folder_mod_time(dbx, f))
# Keep only the first two items of each type
to_delete += files[:-2] + folders[:-2]
# Delete the remaining items
for item in to_delete:
delete_file_or_folder(dbx, item)
def parse_args(args=None):
parser = argparse.ArgumentParser(prog='app')
@ -118,6 +209,12 @@ def parse_args(args=None):
run_upload(a.refresh_token, a.file, a.path)
))
cmd('clean', help='Clean stale artifacts') \
.arg('refresh_token', type=str, help='Refresh token') \
.exe(lambda a: (
run_clean(a.refresh_token)
))
args = parser.parse_args(args)
if not hasattr(args, 'exe'):
parser.print_usage()
@ -127,3 +224,4 @@ def parse_args(args=None):
if __name__ == '__main__':
parse_args()

View file

@ -184,7 +184,7 @@ void DialogDimensionLabels::InitTable()
}
{
auto *itemLabel = new QTableWidgetItem(labels.value(base));
auto *itemLabel = new QTableWidgetItem(VFuzzyValue(labels, base));
itemLabel->setData(Qt::UserRole, base);
itemLabel->setTextAlignment(Qt::AlignHCenter | Qt::AlignCenter);

View file

@ -51,7 +51,7 @@ auto FilterByMinimum(const QVector<qreal> &base, qreal restriction) -> QVector<q
filtered.reserve(base.size());
for(const auto &b : base)
{
if (b >= restriction)
if (b > restriction || VFuzzyComparePossibleNulls(b, restriction))
{
filtered.append(b);
}
@ -71,7 +71,7 @@ auto FilterByMaximum(const QVector<qreal> &base, qreal restriction) -> QVector<q
filtered.reserve(base.size());
for(const auto &b : base)
{
if (b <= restriction)
if (b < restriction || VFuzzyComparePossibleNulls(b, restriction))
{
filtered.append(b);
}
@ -85,8 +85,8 @@ void InitMinMax(qreal &min, qreal &max, const MeasurementDimension_p &dimension,
{
if (not dimension.isNull())
{
min = bases.indexOf(restriction.GetMin()) != -1 ? restriction.GetMin() : dimension->MinValue();
max = bases.indexOf(restriction.GetMax()) != -1 ? restriction.GetMax() : dimension->MaxValue();
min = VFuzzyIndexOf(bases, restriction.GetMin()) != -1 ? restriction.GetMin() : dimension->MinValue();
max = VFuzzyIndexOf(bases, restriction.GetMax()) != -1 ? restriction.GetMax() : dimension->MaxValue();
if (max < min)
{
@ -100,14 +100,14 @@ void InitMinMax(qreal &min, qreal &max, const MeasurementDimension_p &dimension,
void SetCellIcon(QTableWidgetItem *item, const QVector<qreal> &validRows, qreal rowValue, qreal columnValue,
const VDimensionRestriction &restriction, qreal min, qreal max)
{
if (validRows.contains(rowValue))
if (VFuzzyContains(validRows, rowValue))
{
const bool leftRestriction = columnValue >= min;
const bool rightRestriction = columnValue <= max;
const bool leftRestriction = columnValue > min || VFuzzyComparePossibleNulls(columnValue, min);
const bool rightRestriction = columnValue < max || VFuzzyComparePossibleNulls(columnValue, max);
if (leftRestriction && rightRestriction)
{
item->setIcon(QIcon(restriction.GetExcludeValues().contains(columnValue)
item->setIcon(QIcon(VFuzzyContains(restriction.GetExcludeValues(), columnValue)
? QStringLiteral("://icon/24x24/close.png")
: QStringLiteral("://icon/24x24/star.png")));
}
@ -246,7 +246,7 @@ void DialogRestrictDimension::RowSelected()
ui->comboBoxMin->blockSignals(true);
ui->comboBoxMin->clear();
QVector<qreal> filtered = FilterByMaximum(bases, restriction.GetMax());
QVector<qreal> filtered = FilterByMinimum(FilterByMaximum(bases, restriction.GetMax()), restriction.GetMin());
FillBases(filtered, dimension, ui->comboBoxMin);
int index = ui->comboBoxMin->findData(restriction.GetMin());
ui->comboBoxMin->setCurrentIndex(index != -1 ? index : 0);
@ -254,8 +254,7 @@ void DialogRestrictDimension::RowSelected()
ui->comboBoxMax->blockSignals(true);
ui->comboBoxMax->clear();
filtered = FilterByMinimum(bases, restriction.GetMin());
FillBases(FilterByMinimum(bases, restriction.GetMin()), dimension, ui->comboBoxMax);
FillBases(filtered, dimension, ui->comboBoxMax);
index = ui->comboBoxMax->findData(restriction.GetMax());
ui->comboBoxMax->setCurrentIndex(index != -1 ? index : ui->comboBoxMax->count() - 1);
ui->comboBoxMax->blockSignals(false);
@ -394,7 +393,7 @@ void DialogRestrictDimension::CellContextMenu(QPoint pos)
}
VDimensionRestriction restriction = m_restrictions.value(coordinates);
bool exclude = not restriction.GetExcludeValues().contains(columnValue);
bool exclude = not VFuzzyContains(restriction.GetExcludeValues(), columnValue);
QScopedPointer<QMenu> menu(new QMenu());
QAction *actionExclude = menu->addAction(exclude ? tr("Exclude") : tr("Include"));
@ -650,7 +649,7 @@ void DialogRestrictDimension::AddCell(int row, int column, qreal rowValue, qreal
if (m_restrictionType == RestrictDimension::First)
{
VDimensionRestriction restriction = m_restrictions.value(QChar('0'));
item->setIcon(QIcon(restriction.GetExcludeValues().contains(columnValue)
item->setIcon(QIcon(VFuzzyContains(restriction.GetExcludeValues(), columnValue)
? QStringLiteral("://icon/24x24/close.png")
: QStringLiteral("://icon/24x24/star.png")));
}
@ -732,9 +731,9 @@ void DialogRestrictDimension::FillBases(const QVector<qreal> &bases, const Measu
{
for(auto base : bases)
{
if (labels.contains(base) && not labels.value(base).isEmpty())
if (VFuzzyContains(labels, base) && not VFuzzyValue(labels, base).isEmpty())
{
control->addItem(labels.value(base), base);
control->addItem(VFuzzyValue(labels, base), base);
}
else
{
@ -746,9 +745,9 @@ void DialogRestrictDimension::FillBases(const QVector<qreal> &bases, const Measu
{
for(auto base : bases)
{
if (labels.contains(base) && not labels.value(base).isEmpty())
if (VFuzzyContains(labels, base) && not VFuzzyValue(labels, base).isEmpty())
{
control->addItem(labels.value(base), base);
control->addItem(VFuzzyValue(labels, base), base);
}
else
{
@ -767,9 +766,9 @@ void DialogRestrictDimension::FillBases(const QVector<qreal> &bases, const Measu
{
for(auto base : bases)
{
if (labels.contains(base) && not labels.value(base).isEmpty())
if (VFuzzyContains(labels, base) && not VFuzzyValue(labels, base).isEmpty())
{
control->addItem(labels.value(base), base);
control->addItem(VFuzzyValue(labels, base), base);
}
else
{
@ -791,9 +790,9 @@ auto DialogRestrictDimension::FillDimensionXBases(const QVector<qreal> &bases,
for(auto base : bases)
{
if (dimensionLabels.contains(base) && not dimensionLabels.value(base).isEmpty())
if (VFuzzyContains(dimensionLabels, base) && not VFuzzyValue(dimensionLabels, base).isEmpty())
{
labels.append(dimensionLabels.value(base));
labels.append(VFuzzyValue(dimensionLabels, base));
}
else
{
@ -816,9 +815,9 @@ auto DialogRestrictDimension::FillDimensionYBases(const QVector<qreal> &bases,
for(auto base : bases)
{
if (dimensionLabels.contains(base) && not dimensionLabels.value(base).isEmpty())
if (VFuzzyContains(dimensionLabels, base) && not VFuzzyValue(dimensionLabels, base).isEmpty())
{
labels.append(dimensionLabels.value(base));
labels.append(VFuzzyValue(dimensionLabels, base));
}
else
{
@ -848,9 +847,9 @@ auto DialogRestrictDimension::FillDimensionWZBases(const QVector<qreal> &bases,
for(auto base : bases)
{
if (dimensionLabels.contains(base) && not dimensionLabels.value(base).isEmpty())
if (VFuzzyContains(dimensionLabels, base) && not VFuzzyValue(dimensionLabels, base).isEmpty())
{
labels.append(dimensionLabels.value(base));
labels.append(VFuzzyValue(dimensionLabels, base));
}
else
{
@ -904,8 +903,8 @@ auto DialogRestrictDimension::DimensionRestrictedValues(const MeasurementDimensi
const QVector<qreal> bases = dimension->ValidBases();
qreal min = bases.indexOf(restriction.GetMin()) != -1 ? restriction.GetMin() : dimension->MinValue();
qreal max = bases.indexOf(restriction.GetMax()) != -1 ? restriction.GetMax() : dimension->MaxValue();
qreal min = VFuzzyIndexOf(bases, restriction.GetMin()) != -1 ? restriction.GetMin() : dimension->MinValue();
qreal max = VFuzzyIndexOf(bases, restriction.GetMax()) != -1 ? restriction.GetMax() : dimension->MaxValue();
if (min > max)
{
@ -935,7 +934,7 @@ auto DialogRestrictDimension::StartRow() const -> int
for(int i=0; i < basesRow.size(); ++i)
{
if (validRows.contains(basesRow.at(i)))
if (VFuzzyContains(validRows, basesRow.at(i)))
{
return i;
}

View file

@ -142,9 +142,9 @@ void InitDimensionXItems(const QVector<qreal> &bases, const DimesionLabels &labe
for(auto base : bases)
{
if (labels.contains(base) && not labels.value(base).isEmpty())
if (VFuzzyContains(labels, base) && not VFuzzyValue(labels, base).isEmpty())
{
control->addItem(labels.value(base), base);
control->addItem(VFuzzyValue(labels, base), base);
}
else
{
@ -159,9 +159,9 @@ void InitDimensionYWZItems(const QVector<qreal> &bases, const DimesionLabels &la
{
for(auto base : bases)
{
if (labels.contains(base) && not labels.value(base).isEmpty())
if (VFuzzyContains(labels, base) && not VFuzzyValue(labels, base).isEmpty())
{
control->addItem(labels.value(base), base);
control->addItem(VFuzzyValue(labels, base), base);
}
else
{
@ -2844,9 +2844,10 @@ void TMainWindow::InitDimensionsBaseValue()
DimesionLabels labels = dimension->Labels();
if (labels.contains(dimension->BaseValue()) && not labels.value(dimension->BaseValue()).isEmpty())
if (VFuzzyContains(labels, dimension->BaseValue())
&& not VFuzzyValue(labels, dimension->BaseValue()).isEmpty())
{
base->setText(labels.value(dimension->BaseValue()));
base->setText(VFuzzyValue(labels, dimension->BaseValue()));
}
else
{
@ -4300,8 +4301,8 @@ auto TMainWindow::DimensionRestrictedValues(int index, const MeasurementDimensio
const QVector<qreal> bases = dimension->ValidBases();
qreal min = bases.indexOf(restriction.GetMin()) != -1 ? restriction.GetMin() : dimension->MinValue();
qreal max = bases.indexOf(restriction.GetMax()) != -1 ? restriction.GetMax() : dimension->MaxValue();
qreal min = VFuzzyIndexOf(bases, restriction.GetMin()) != -1 ? restriction.GetMin() : dimension->MinValue();
qreal max = VFuzzyIndexOf(bases, restriction.GetMax()) != -1 ? restriction.GetMax() : dimension->MaxValue();
if (min > max)
{

View file

@ -2335,14 +2335,14 @@ void MainWindow::StoreMultisizeMDimension(const QList<MeasurementDimension_p> &d
case MeasurementDimension::X:
VAbstractValApplication::VApp()->SetDimensionHeight(currentBase);
VAbstractValApplication::VApp()->SetDimensionHeightLabel(
labels.value(currentBase, QString::number(currentBase)));
VFuzzyValue(labels, currentBase, QString::number(currentBase)));
break;
case MeasurementDimension::Y:
{
const bool fc = m_m->IsFullCircumference();
VAbstractValApplication::VApp()->SetDimensionSize(fc ? currentBase*2 : currentBase);
VAbstractValApplication::VApp()->SetDimensionSizeLabel(
labels.value(currentBase, QString::number(fc ? currentBase*2 : currentBase)));
VFuzzyValue(labels, currentBase, QString::number(fc ? currentBase*2 : currentBase)));
const bool measurement = dimension->IsBodyMeasurement();
VAbstractValApplication::VApp()
->SetDimensionSizeUnits(measurement ? m_m->Units() : Unit::LAST_UNIT_DO_NOT_USE);
@ -2353,7 +2353,7 @@ void MainWindow::StoreMultisizeMDimension(const QList<MeasurementDimension_p> &d
const bool fc = m_m->IsFullCircumference();
VAbstractValApplication::VApp()->SetDimensionWaist(fc ? currentBase*2 : currentBase);
VAbstractValApplication::VApp()->SetDimensionWaistLabel(
labels.value(currentBase, QString::number(fc ? currentBase*2 : currentBase)));
VFuzzyValue(labels, currentBase, QString::number(fc ? currentBase*2 : currentBase)));
break;
}
case MeasurementDimension::Z:
@ -2361,7 +2361,7 @@ void MainWindow::StoreMultisizeMDimension(const QList<MeasurementDimension_p> &d
const bool fc = m_m->IsFullCircumference();
VAbstractValApplication::VApp()->SetDimensionHip(fc ? currentBase*2 : currentBase);
VAbstractValApplication::VApp()->SetDimensionHipLabel(
labels.value(currentBase, QString::number(fc ? currentBase*2 : currentBase)));
VFuzzyValue(labels, currentBase, QString::number(fc ? currentBase*2 : currentBase)));
break;
}
default:
@ -2419,8 +2419,8 @@ auto MainWindow::DimensionRestrictedValues(int index, const MeasurementDimension
const QVector<qreal> bases = dimension->ValidBases();
qreal min = bases.indexOf(restriction.GetMin()) != -1 ? restriction.GetMin() : dimension->MinValue();
qreal max = bases.indexOf(restriction.GetMax()) != -1 ? restriction.GetMax() : dimension->MaxValue();
qreal min = VFuzzyIndexOf(bases, restriction.GetMin()) != -1 ? restriction.GetMin() : dimension->MinValue();
qreal max = VFuzzyIndexOf(bases, restriction.GetMax()) != -1 ? restriction.GetMax() : dimension->MaxValue();
if (min > max)
{
@ -4943,9 +4943,9 @@ void MainWindow::InitDimensionXGradation(const QVector<qreal> &bases, const Dime
for(auto base : bases)
{
if (labels.contains(base) && not labels.value(base).isEmpty())
if (VFuzzyContains(labels, base) && not VFuzzyValue(labels, base).isEmpty())
{
control->addItem(labels.value(base), base);
control->addItem(VFuzzyValue(labels, base), base);
}
else
{
@ -4963,9 +4963,9 @@ void MainWindow::InitDimensionYWZGradation(const QVector<qreal> &bases, const Di
for(auto base : bases)
{
if (labels.contains(base) && not labels.value(base).isEmpty())
if (VFuzzyContains(labels, base) && not VFuzzyValue(labels, base).isEmpty())
{
control->addItem(labels.value(base), base);
control->addItem(VFuzzyValue(labels, base), base);
}
else
{

View file

@ -110,8 +110,8 @@ auto VAbstartMeasurementDimension::Name() const -> QString
//---------------------------------------------------------------------------------------------------------------------
auto VAbstartMeasurementDimension::ValidSteps() const -> QVector<qreal>
{
const qreal stepBarrier = 8.5;
const qreal s = 0.5;
const qreal stepBarrier = 50;
const qreal s = 0.1;
QVector<qreal> steps;
steps.reserve(qRound((stepBarrier - s) * 2 - 1));
@ -124,6 +124,7 @@ auto VAbstartMeasurementDimension::ValidSteps() const -> QVector<qreal>
else if (diff > 0)
{
qreal candidate = 1;
int i = 1;
do
{
const qreal step = (m_units == Unit::Mm ? candidate * 10 : candidate);
@ -132,7 +133,8 @@ auto VAbstartMeasurementDimension::ValidSteps() const -> QVector<qreal>
{
steps.append(step);
}
candidate += s;
candidate = 1 + s * i;
++i;
}
while(candidate < stepBarrier);
}
@ -179,23 +181,27 @@ auto VAbstartMeasurementDimension::ValidBases(qreal min, qreal max, qreal step,
validBases.reserve(qRound((max - min) / step));
qreal value = min;
int i = 1;
do
{
if (not exclude.contains(value))
if (not VFuzzyContains(exclude, value))
{
validBases.append(value);
}
value += step;
value = min + step * i;
++i;
}
while(value < max + step);
if (validBases.isEmpty())
{
value = min;
int i = 1;
do
{
validBases.append(value);
value += step;
value = min + step * i;
++i;
}
while(value < max + step);
}
@ -204,10 +210,12 @@ auto VAbstartMeasurementDimension::ValidBases(qreal min, qreal max, qreal step,
}
//---------------------------------------------------------------------------------------------------------------------
auto VAbstartMeasurementDimension::IsRangeValid() -> bool
auto VAbstartMeasurementDimension::IsRangeValid() const -> bool
{
bool valid = m_minValue > 0 && m_maxValue > 0 && m_minValue >= RangeMin() && m_minValue <= RangeMax()
&& m_minValue <= m_maxValue;
bool valid = m_minValue > 0 && m_maxValue > 0 &&
(m_minValue > RangeMin() || VFuzzyComparePossibleNulls(m_minValue, RangeMin())) &&
(m_maxValue < RangeMax() || VFuzzyComparePossibleNulls(m_maxValue, RangeMax())) &&
(m_minValue < m_maxValue || VFuzzyComparePossibleNulls(m_minValue, m_maxValue));
if (not valid)
{
@ -218,9 +226,9 @@ auto VAbstartMeasurementDimension::IsRangeValid() -> bool
}
//---------------------------------------------------------------------------------------------------------------------
auto VAbstartMeasurementDimension::IsStepValid() -> bool
auto VAbstartMeasurementDimension::IsStepValid() const -> bool
{
bool valid = ValidSteps().indexOf(m_step) != -1;
bool valid = VFuzzyIndexOf(ValidSteps(), m_step) != -1;
if (not valid)
{
m_error = QCoreApplication::translate("VAbstartMeasurementDimension", "Invalid step");
@ -230,9 +238,9 @@ auto VAbstartMeasurementDimension::IsStepValid() -> bool
}
//---------------------------------------------------------------------------------------------------------------------
auto VAbstartMeasurementDimension::IsBaseValid() -> bool
auto VAbstartMeasurementDimension::IsBaseValid() const -> bool
{
bool valid = ValidBases().indexOf(m_baseValue) != -1;
bool valid = VFuzzyIndexOf(ValidBases(), m_baseValue) != -1;
if (not valid)
{
m_error = QCoreApplication::translate("VAbstartMeasurementDimension", "Base value invalid");
@ -244,7 +252,14 @@ auto VAbstartMeasurementDimension::IsBaseValid() -> bool
//---------------------------------------------------------------------------------------------------------------------
auto VAbstartMeasurementDimension::IsUnitsValid() const -> bool
{
return m_units == Unit::Cm || m_units == Unit::Mm || m_units == Unit::Inch;
bool valid = (m_units == Unit::Cm || m_units == Unit::Mm || m_units == Unit::Inch);
if (not valid)
{
m_error = QCoreApplication::translate("VAbstartMeasurementDimension", "Units are invalid");
}
return valid;
}
//---------------------------------------------------------------------------------------------------------------------

View file

@ -53,6 +53,66 @@ template <class T> class QSharedPointer;
using MeasurementDimension_p = QSharedPointer<VAbstartMeasurementDimension>;
using DimesionLabels = QMap<qreal, QString>;
//---------------------------------------------------------------------------------------------------------------------
template <typename T>
inline bool VFuzzyContains(const QMap<qreal, T> &c, qreal value)
{
auto i = c.constBegin();
while (i != c.constEnd())
{
if (VFuzzyComparePossibleNulls(i.key(), value))
{
return true;
}
++i;
}
return false;
}
//---------------------------------------------------------------------------------------------------------------------
template <template <typename> class Cont>
inline bool VFuzzyContains(const Cont<qreal> &c, qreal value)
{
for (auto val : c)
{
if (VFuzzyComparePossibleNulls(val, value))
{
return true;
}
}
return false;
}
//---------------------------------------------------------------------------------------------------------------------
template <template <typename> class Cont>
inline vsizetype VFuzzyIndexOf(const Cont<qreal> &c, qreal value)
{
for (int i = 0; i < c.size(); ++i)
{
if (VFuzzyComparePossibleNulls(c.at(i), value))
{
return i;
}
}
return -1;
}
//---------------------------------------------------------------------------------------------------------------------
template <typename T>
inline T VFuzzyValue(const QMap<qreal, T> &c, qreal value, const T &defaultValue = T())
{
auto i = c.constBegin();
while (i != c.constEnd())
{
if (VFuzzyComparePossibleNulls(i.key(), value))
{
return i.value();
}
++i;
}
return defaultValue;
}
class VAbstartMeasurementDimension
{
Q_DECLARE_TR_FUNCTIONS(VAbstartMeasurementDimension) // NOLINT
@ -107,23 +167,23 @@ public:
void SetCustomName(const QString &newCustomName);
protected:
auto IsRangeValid() -> bool;
auto IsStepValid() -> bool;
auto IsBaseValid() -> bool;
auto IsRangeValid() const -> bool;
auto IsStepValid() const -> bool;
auto IsBaseValid() const -> bool;
auto IsUnitsValid() const -> bool;
private:
Q_DISABLE_COPY_MOVE(VAbstartMeasurementDimension) // NOLINT
Unit m_units{Unit::Cm};
qreal m_minValue{0};
qreal m_maxValue{0};
qreal m_step{-1};
qreal m_baseValue{0};
QString m_error{};
DimesionLabels m_labels{};
bool m_measurement{true};
QString m_customName{};
Unit m_units{Unit::Cm};
qreal m_minValue{0};
qreal m_maxValue{0};
qreal m_step{-1};
qreal m_baseValue{0};
mutable QString m_error{};
DimesionLabels m_labels{};
bool m_measurement{true};
QString m_customName{};
};
//---------------------------------------------------------------------------------------------------------------------

View file

@ -41,6 +41,7 @@
#include <QGlobalStatic>
#include "../ifc/exception/vexceptionemptyparameter.h"
#include "../ifc/exception/vexceptionobjecterror.h"
#include "../ifc/xml/vvitconverter.h"
#include "../ifc/xml/vvstconverter.h"
#include "../ifc/ifcdef.h"
@ -153,7 +154,12 @@ void VMeasurements::setXMLContent(const QString &fileName)
VDomDocument::setXMLContent(fileName);
type = ReadType();
m_units = ReadUnits();
m_dimensions = ReadDimensions();
if (type == MeasurementsType::Multisize &&
VVSTConverter::MeasurementMaxVer == GetFormatVersion(GetFormatVersionStr()))
{
m_dimensions = ReadDimensions();
}
}
//---------------------------------------------------------------------------------------------------------------------
@ -1427,6 +1433,14 @@ auto VMeasurements::ReadDimensions() const -> VDimensions
dimension->SetBodyMeasurement(GetParametrBool(dom, AttrMeasurement, trueStr));
dimension->SetCustomName(GetParametrEmptyString(dom, AttrCustomName));
dimension->SetLabels(ReadDimensionLabels(dom));
if (not dimension->IsValid())
{
VExceptionObjectError excep(tr("Dimension is not valid"), dom);
excep.AddMoreInformation(dimension->Error());
throw excep;
}
dimensions.insert(type, dimension);
}
@ -1592,13 +1606,13 @@ DimesionLabels VMeasurements::ReadDimensionLabels(const QDomElement &dElement) c
{
if (dElement.isNull())
{
return DimesionLabels();
return {};
}
QDomElement labelsTag = dElement.firstChildElement(TagLabels);
if (labelsTag.isNull())
{
return DimesionLabels();
return {};
}
DimesionLabels labels;