2013-11-15 13:41:26 +01:00
|
|
|
/************************************************************************
|
2013-09-18 21:16:19 +02:00
|
|
|
**
|
2013-11-15 13:50:05 +01:00
|
|
|
** @file vcontainer.cpp
|
2014-04-30 07:38:52 +02:00
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
2013-11-15 13:50:05 +01:00
|
|
|
** @date November 15, 2013
|
2013-09-18 21:16:19 +02:00
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
** @brief
|
|
|
|
** @copyright
|
2017-10-05 11:20:01 +02:00
|
|
|
** This source code is part of the Valentina project, a pattern making
|
2013-11-15 13:41:26 +01:00
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
2015-02-27 11:27:48 +01:00
|
|
|
** Copyright (C) 2013-2015 Valentina project
|
2020-01-31 07:00:05 +01:00
|
|
|
** <https://gitlab.com/smart-pattern/valentina> All Rights Reserved.
|
2013-09-18 21:16:19 +02:00
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
** Valentina is free software: you can redistribute it and/or modify
|
2013-09-18 21:16:19 +02:00
|
|
|
** it under the terms of the GNU General Public License as published by
|
|
|
|
** the Free Software Foundation, either version 3 of the License, or
|
|
|
|
** (at your option) any later version.
|
|
|
|
**
|
2013-10-27 13:36:29 +01:00
|
|
|
** Valentina is distributed in the hope that it will be useful,
|
2013-09-18 21:16:19 +02:00
|
|
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
** GNU General Public License for more details.
|
|
|
|
**
|
|
|
|
** You should have received a copy of the GNU General Public License
|
|
|
|
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
*************************************************************************/
|
2013-09-18 21:16:19 +02:00
|
|
|
|
2013-07-13 12:51:31 +02:00
|
|
|
#include "vcontainer.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
|
2023-05-16 18:20:49 +02:00
|
|
|
#include <QLoggingCategory>
|
|
|
|
#include <QUuid>
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <QVector>
|
|
|
|
#include <QtDebug>
|
2023-05-16 18:20:49 +02:00
|
|
|
#include <climits>
|
2016-08-08 13:44:49 +02:00
|
|
|
|
|
|
|
#include "../ifc/exception/vexception.h"
|
|
|
|
#include "../vgeometry/vabstractcubicbezierpath.h"
|
|
|
|
#include "../vgeometry/vabstractcurve.h"
|
2023-05-16 18:20:49 +02:00
|
|
|
#include "../vgeometry/varc.h"
|
|
|
|
#include "../vgeometry/vellipticalarc.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "../vgeometry/vgeometrydef.h"
|
|
|
|
#include "../vgeometry/vgobject.h"
|
|
|
|
#include "../vgeometry/vpointf.h"
|
|
|
|
#include "../vgeometry/vspline.h"
|
2022-02-18 09:36:38 +01:00
|
|
|
#include "../vmisc/literals.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "variables/varcradius.h"
|
|
|
|
#include "variables/vcurveangle.h"
|
2016-09-24 19:44:06 +02:00
|
|
|
#include "variables/vcurveclength.h"
|
2023-05-16 18:20:49 +02:00
|
|
|
#include "variables/vcurvelength.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "variables/vincrement.h"
|
|
|
|
#include "variables/vlineangle.h"
|
|
|
|
#include "variables/vlinelength.h"
|
|
|
|
#include "variables/vmeasurement.h"
|
2022-11-10 10:30:08 +01:00
|
|
|
#include "variables/vpiecearea.h"
|
2015-06-11 14:40:43 +02:00
|
|
|
#include "vtranslatevars.h"
|
2015-04-01 14:51:54 +02:00
|
|
|
|
2016-08-06 20:42:40 +02:00
|
|
|
QT_WARNING_PUSH
|
|
|
|
QT_WARNING_DISABLE_CLANG("-Wmissing-prototypes")
|
|
|
|
QT_WARNING_DISABLE_INTEL(1418)
|
2015-10-19 15:21:06 +02:00
|
|
|
|
2022-08-12 17:50:13 +02:00
|
|
|
Q_LOGGING_CATEGORY(vCon, "v.container") // NOLINT
|
2013-11-21 13:05:26 +01:00
|
|
|
|
2016-08-06 20:42:40 +02:00
|
|
|
QT_WARNING_POP
|
2015-10-19 15:21:06 +02:00
|
|
|
|
2018-09-18 15:38:16 +02:00
|
|
|
QMap<QString, quint32> VContainer::_id = QMap<QString, quint32>();
|
|
|
|
QMap<QString, QSet<QString>> VContainer::uniqueNames = QMap<QString, QSet<QString>>();
|
|
|
|
QMap<QString, quint32> VContainer::copyCounter = QMap<QString, quint32>();
|
2013-08-15 22:39:00 +02:00
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-05-21 10:51:16 +02:00
|
|
|
/**
|
|
|
|
* @brief VContainer create empty container
|
|
|
|
*/
|
2018-09-18 15:38:16 +02:00
|
|
|
VContainer::VContainer(const VTranslateVars *trVars, const Unit *patternUnit, const QString &nspace)
|
2023-05-16 18:20:49 +02:00
|
|
|
: d(new VContainerData(trVars, patternUnit, nspace))
|
2018-09-18 15:38:16 +02:00
|
|
|
{
|
|
|
|
if (nspace.isEmpty())
|
|
|
|
{
|
|
|
|
qFatal("Namesapce is empty.");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (VContainer::_id.contains(nspace))
|
|
|
|
{
|
|
|
|
qFatal("Namespace is not unique.");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (not _id.contains(d->nspace))
|
|
|
|
{
|
|
|
|
_id[d->nspace] = NULL_ID;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (not uniqueNames.contains(d->nspace))
|
|
|
|
{
|
|
|
|
uniqueNames[d->nspace] = QSet<QString>();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (not copyCounter.contains(d->nspace))
|
|
|
|
{
|
|
|
|
copyCounter[d->nspace] = 1;
|
|
|
|
}
|
|
|
|
}
|
2013-07-13 12:51:31 +02:00
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-05-21 10:51:16 +02:00
|
|
|
/**
|
|
|
|
* @brief operator = copy constructor
|
|
|
|
* @param data container
|
|
|
|
* @return copy container
|
|
|
|
*/
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VContainer::operator=(const VContainer &data) -> VContainer &
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2023-05-16 18:20:49 +02:00
|
|
|
if (&data == this)
|
2014-07-27 14:30:28 +02:00
|
|
|
{
|
|
|
|
return *this;
|
|
|
|
}
|
2014-08-21 14:44:40 +02:00
|
|
|
d = data.d;
|
2018-09-18 15:38:16 +02:00
|
|
|
++copyCounter[d->nspace];
|
2013-08-15 22:39:00 +02:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2019-12-30 12:00:57 +01:00
|
|
|
#ifdef Q_COMPILER_RVALUE_REFS
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-07-13 16:49:20 +02:00
|
|
|
VContainer::VContainer(VContainer &&data) noexcept
|
|
|
|
: d(std::move(data.d))
|
2023-05-16 18:20:49 +02:00
|
|
|
{
|
|
|
|
}
|
2019-12-30 12:00:57 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-07-13 16:49:20 +02:00
|
|
|
auto VContainer::operator=(VContainer &&data) noexcept -> VContainer &
|
2019-12-30 12:00:57 +01:00
|
|
|
{
|
|
|
|
std::swap(d, data.d);
|
2019-12-30 16:13:18 +01:00
|
|
|
return *this;
|
2019-12-30 12:00:57 +01:00
|
|
|
}
|
2019-12-30 16:13:18 +01:00
|
|
|
#endif
|
2019-12-30 12:00:57 +01:00
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-05-21 10:51:16 +02:00
|
|
|
/**
|
|
|
|
* @brief VContainer create container from another container
|
|
|
|
* @param data container
|
|
|
|
*/
|
2013-11-04 21:35:15 +01:00
|
|
|
VContainer::VContainer(const VContainer &data)
|
2023-05-16 18:20:49 +02:00
|
|
|
: d(data.d)
|
2018-09-18 15:38:16 +02:00
|
|
|
{
|
|
|
|
++copyCounter[d->nspace];
|
|
|
|
}
|
2013-08-29 12:31:50 +02:00
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2013-12-30 19:59:33 +01:00
|
|
|
VContainer::~VContainer()
|
2023-05-16 18:20:49 +02:00
|
|
|
{
|
|
|
|
}
|
2013-12-30 19:59:33 +01:00
|
|
|
|
2018-09-18 15:38:16 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VContainer::UniqueNamespace() -> QString
|
2018-09-18 15:38:16 +02:00
|
|
|
{
|
|
|
|
QString candidate;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
candidate = QUuid::createUuid().toString();
|
2023-05-16 18:20:49 +02:00
|
|
|
} while (_id.contains(candidate));
|
2018-09-18 15:38:16 +02:00
|
|
|
|
|
|
|
return candidate;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VContainer::ClearNamespace(const QString &nspace)
|
|
|
|
{
|
|
|
|
_id.remove(nspace);
|
|
|
|
uniqueNames.remove(nspace);
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-05-21 10:51:16 +02:00
|
|
|
/**
|
|
|
|
* @brief GetGObject returns a point by id
|
|
|
|
* @param id id of point
|
|
|
|
* @return point
|
|
|
|
*/
|
2014-05-02 10:09:10 +02:00
|
|
|
// cppcheck-suppress unusedFunction
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VContainer::GetGObject(quint32 id) const -> const QSharedPointer<VGObject>
|
2013-11-15 18:38:29 +01:00
|
|
|
{
|
2017-10-26 11:54:08 +02:00
|
|
|
if (d->calculationObjects.contains(id))
|
|
|
|
{
|
|
|
|
return d->calculationObjects.value(id);
|
|
|
|
}
|
2023-05-08 16:50:22 +02:00
|
|
|
|
|
|
|
if (d->modelingObjects->contains(id))
|
2017-10-26 11:54:08 +02:00
|
|
|
{
|
|
|
|
return d->modelingObjects->value(id);
|
|
|
|
}
|
2023-05-08 16:50:22 +02:00
|
|
|
|
2023-05-08 16:50:58 +02:00
|
|
|
throw VExceptionBadId(QCoreApplication::translate("VContainer", "Can't find object"), id);
|
2013-11-15 18:38:29 +01:00
|
|
|
}
|
|
|
|
|
2015-06-20 18:14:04 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VContainer::GetFakeGObject(quint32 id) -> const QSharedPointer<VGObject>
|
2015-06-20 18:14:04 +02:00
|
|
|
{
|
2022-02-05 11:22:49 +01:00
|
|
|
auto *obj = new VGObject();
|
2015-06-20 18:14:04 +02:00
|
|
|
obj->setId(id);
|
|
|
|
QSharedPointer<VGObject> pointer(obj);
|
|
|
|
return pointer;
|
|
|
|
}
|
|
|
|
|
2016-11-08 11:52:07 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VContainer::GetPiece(quint32 id) const -> VPiece
|
2016-11-08 11:52:07 +01:00
|
|
|
{
|
|
|
|
if (d->pieces->contains(id))
|
|
|
|
{
|
|
|
|
return d->pieces->value(id);
|
|
|
|
}
|
2023-05-16 18:20:49 +02:00
|
|
|
|
|
|
|
throw VExceptionBadId(tr("Can't find object"), id);
|
2016-11-08 11:52:07 +01:00
|
|
|
}
|
|
|
|
|
2016-11-24 20:30:26 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VContainer::GetPiecePath(quint32 id) const -> VPiecePath
|
2016-11-24 20:30:26 +01:00
|
|
|
{
|
|
|
|
if (d->piecePaths->contains(id))
|
|
|
|
{
|
|
|
|
return d->piecePaths->value(id);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw VExceptionBadId(tr("Can't find object"), id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VContainer::GetPieceForPiecePath(quint32 id) const -> quint32
|
2018-07-26 19:00:24 +02:00
|
|
|
{
|
|
|
|
auto i = d->pieces->constBegin();
|
|
|
|
while (i != d->pieces->constEnd())
|
|
|
|
{
|
|
|
|
if (i.value().GetInternalPaths().contains(id))
|
|
|
|
{
|
|
|
|
return i.key();
|
|
|
|
}
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL_ID;
|
|
|
|
}
|
|
|
|
|
2020-11-04 16:58:06 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-11-07 16:43:49 +01:00
|
|
|
void VContainer::RegisterUniqueName(VGObject *obj) const
|
2020-11-04 16:58:06 +01:00
|
|
|
{
|
|
|
|
SCASSERT(obj != nullptr)
|
|
|
|
QSharedPointer<VGObject> pointer(obj);
|
|
|
|
RegisterUniqueName(pointer);
|
|
|
|
}
|
|
|
|
|
2020-11-04 17:14:21 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-11-07 16:43:49 +01:00
|
|
|
void VContainer::RegisterUniqueName(const QSharedPointer<VGObject> &obj) const
|
2020-11-04 17:14:21 +01:00
|
|
|
{
|
|
|
|
SCASSERT(not obj.isNull())
|
|
|
|
|
|
|
|
uniqueNames[d->nspace].insert(obj->name());
|
|
|
|
|
|
|
|
if (not obj->GetAlias().isEmpty())
|
|
|
|
{
|
|
|
|
uniqueNames[d->nspace].insert(obj->GetAlias());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-26 19:00:24 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-05-21 10:51:16 +02:00
|
|
|
/**
|
2014-06-02 09:43:27 +02:00
|
|
|
* @brief AddGObject add new GObject to container
|
|
|
|
* @param obj new object
|
|
|
|
* @return return id of new object in container
|
2014-05-21 10:51:16 +02:00
|
|
|
*/
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VContainer::AddGObject(VGObject *obj) -> quint32
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(obj != nullptr)
|
2014-08-21 14:44:40 +02:00
|
|
|
QSharedPointer<VGObject> pointer(obj);
|
2017-10-15 11:25:20 +02:00
|
|
|
return AddGObject(pointer);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VContainer::AddGObject(const QSharedPointer<VGObject> &obj) -> quint32
|
2017-10-15 11:25:20 +02:00
|
|
|
{
|
|
|
|
SCASSERT(not obj.isNull())
|
2017-10-26 11:54:08 +02:00
|
|
|
|
|
|
|
if (obj->getMode() == Draw::Layout)
|
|
|
|
{
|
|
|
|
qWarning("Can't add an object with mode 'Layout'");
|
|
|
|
return NULL_ID;
|
|
|
|
}
|
|
|
|
|
2020-11-04 17:14:21 +01:00
|
|
|
RegisterUniqueName(obj);
|
2020-11-04 16:36:40 +01:00
|
|
|
|
2017-10-26 11:54:08 +02:00
|
|
|
const quint32 id = getNextId();
|
|
|
|
obj->setId(id);
|
|
|
|
|
|
|
|
if (obj->getMode() == Draw::Calculation)
|
|
|
|
{
|
|
|
|
d->calculationObjects.insert(id, obj);
|
|
|
|
}
|
|
|
|
else if (obj->getMode() == Draw::Modeling)
|
|
|
|
{
|
|
|
|
d->modelingObjects->insert(id, obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
return id;
|
2013-07-17 13:38:11 +02:00
|
|
|
}
|
|
|
|
|
2016-11-08 11:52:07 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VContainer::AddPiece(const VPiece &detail) -> quint32
|
2016-11-08 11:52:07 +01:00
|
|
|
{
|
|
|
|
const quint32 id = getNextId();
|
|
|
|
d->pieces->insert(id, detail);
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2016-11-24 20:30:26 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VContainer::AddPiecePath(const VPiecePath &path) -> quint32
|
2016-11-24 20:30:26 +01:00
|
|
|
{
|
|
|
|
const quint32 id = getNextId();
|
|
|
|
d->piecePaths->insert(id, path);
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2015-06-04 15:58:38 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VContainer::getId() const -> quint32
|
2015-06-04 15:58:38 +02:00
|
|
|
{
|
2018-09-18 15:38:16 +02:00
|
|
|
return _id.value(d->nspace);
|
2015-06-04 15:58:38 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-05-21 10:51:16 +02:00
|
|
|
/**
|
|
|
|
* @brief getNextId generate next unique id
|
|
|
|
* @return next unique id
|
|
|
|
*/
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VContainer::getNextId() const -> quint32
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2023-05-16 18:20:49 +02:00
|
|
|
// TODO. Current count of ids are very big and allow us save time before someone will reach its max value.
|
|
|
|
// Better way, of cource, is to seek free ids inside the set of values and reuse them.
|
|
|
|
// But for now better to keep it as it is now.
|
2018-09-18 15:38:16 +02:00
|
|
|
if (_id.value(d->nspace) == UINT_MAX)
|
2016-03-19 15:54:27 +01:00
|
|
|
{
|
2023-05-16 18:20:49 +02:00
|
|
|
qCritical() << (tr("Number of free id exhausted."));
|
2016-03-19 15:54:27 +01:00
|
|
|
}
|
2018-09-18 15:38:16 +02:00
|
|
|
_id[d->nspace]++;
|
|
|
|
return _id.value(d->nspace);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VContainer::UpdateId(quint32 newId, const QString &nspace)
|
|
|
|
{
|
|
|
|
if (_id.contains(nspace))
|
|
|
|
{
|
|
|
|
if (newId > _id.value(nspace))
|
|
|
|
{
|
2023-05-16 18:20:49 +02:00
|
|
|
_id[nspace] = newId;
|
2018-09-18 15:38:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw VException(QStringLiteral("Unknown namespace"));
|
|
|
|
}
|
2013-07-13 12:51:31 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-05-21 10:51:16 +02:00
|
|
|
/**
|
|
|
|
* @brief UpdateId update id. If new id bigger when current save new like current.
|
|
|
|
* @param newId id
|
|
|
|
*/
|
2018-09-18 15:38:16 +02:00
|
|
|
void VContainer::UpdateId(quint32 newId) const
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2018-09-18 15:38:16 +02:00
|
|
|
VContainer::UpdateId(newId, d->nspace);
|
2013-08-13 18:48:36 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-05-21 10:51:16 +02:00
|
|
|
/**
|
|
|
|
* @brief Clear clear data in container. Id will be 0.
|
|
|
|
*/
|
2013-11-04 21:35:15 +01:00
|
|
|
void VContainer::Clear()
|
|
|
|
{
|
2015-04-01 19:08:35 +02:00
|
|
|
qCDebug(vCon, "Clearing container data.");
|
2018-09-18 15:38:16 +02:00
|
|
|
_id[d->nspace] = NULL_ID;
|
2014-07-29 13:28:18 +02:00
|
|
|
|
2017-01-18 09:15:51 +01:00
|
|
|
d->pieces->clear();
|
|
|
|
d->piecePaths->clear();
|
2014-07-29 13:28:18 +02:00
|
|
|
ClearVariables();
|
2014-01-02 16:50:01 +01:00
|
|
|
ClearGObjects();
|
2014-09-04 07:20:41 +02:00
|
|
|
ClearUniqueNames();
|
2013-07-17 13:38:11 +02:00
|
|
|
}
|
|
|
|
|
2015-08-26 20:14:47 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VContainer::ClearForFullParse()
|
|
|
|
{
|
|
|
|
qCDebug(vCon, "Clearing container data for full parse.");
|
2018-09-18 15:38:16 +02:00
|
|
|
_id[d->nspace] = NULL_ID;
|
2015-08-26 20:14:47 +02:00
|
|
|
|
2016-11-16 08:15:16 +01:00
|
|
|
d->pieces->clear();
|
2016-11-24 20:30:26 +01:00
|
|
|
d->piecePaths->clear();
|
2022-12-31 13:46:01 +01:00
|
|
|
Q_STATIC_ASSERT_X(static_cast<int>(VarType::Unknown) == 12, "Check that you used all types");
|
2023-05-16 18:20:49 +02:00
|
|
|
ClearVariables(QVector<VarType>{VarType::Increment, VarType::IncrementSeparator, VarType::LineAngle,
|
|
|
|
VarType::LineLength, VarType::CurveLength, VarType::CurveCLength,
|
|
|
|
VarType::ArcRadius, VarType::CurveAngle, VarType::PieceExternalArea,
|
2022-12-31 13:46:01 +01:00
|
|
|
VarType::PieceSeamLineArea});
|
2015-08-26 20:14:47 +02:00
|
|
|
ClearGObjects();
|
|
|
|
ClearUniqueNames();
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-05-21 10:51:16 +02:00
|
|
|
/**
|
|
|
|
* @brief ClearObject points, splines, arcs, spline paths will be cleared.
|
|
|
|
*/
|
2014-01-02 16:50:01 +01:00
|
|
|
void VContainer::ClearGObjects()
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2017-10-26 11:54:08 +02:00
|
|
|
d->calculationObjects.clear();
|
|
|
|
d->modelingObjects->clear();
|
2013-08-15 22:39:00 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-01-02 16:50:01 +01:00
|
|
|
void VContainer::ClearCalculationGObjects()
|
|
|
|
{
|
2017-10-26 11:54:08 +02:00
|
|
|
d->calculationObjects.clear();
|
2014-01-02 16:50:01 +01:00
|
|
|
}
|
|
|
|
|
2014-07-29 13:28:18 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VContainer::ClearVariables(const VarType &type)
|
|
|
|
{
|
2018-01-20 13:01:35 +01:00
|
|
|
ClearVariables(QVector<VarType>({type}));
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VContainer::ClearVariables(const QVector<VarType> &types)
|
|
|
|
{
|
|
|
|
if (not d->variables.isEmpty()) //-V807
|
2014-07-29 13:28:18 +02:00
|
|
|
{
|
2018-01-20 13:01:35 +01:00
|
|
|
if (types.isEmpty() || types.contains(VarType::Unknown))
|
2014-07-29 13:28:18 +02:00
|
|
|
{
|
2014-08-21 14:44:40 +02:00
|
|
|
d->variables.clear();
|
2014-07-29 13:28:18 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-05-16 18:20:49 +02:00
|
|
|
QHash<QString, QSharedPointer<VInternalVariable>>::iterator i;
|
2018-01-20 13:01:35 +01:00
|
|
|
for (i = d->variables.begin(); i != d->variables.end();)
|
2014-07-29 13:28:18 +02:00
|
|
|
{
|
2018-01-20 13:01:35 +01:00
|
|
|
if (types.contains(i.value()->GetType()))
|
2014-07-29 13:28:18 +02:00
|
|
|
{
|
2018-01-20 13:01:35 +01:00
|
|
|
i = d->variables.erase(i);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
++i;
|
2014-08-21 14:44:40 +02:00
|
|
|
}
|
2014-07-29 13:28:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-05-21 10:51:16 +02:00
|
|
|
/**
|
|
|
|
* @brief AddLine add line to container
|
|
|
|
* @param firstPointId id of first point of line
|
|
|
|
* @param secondPointId id of second point of line
|
|
|
|
*/
|
2014-02-25 15:40:24 +01:00
|
|
|
void VContainer::AddLine(const quint32 &firstPointId, const quint32 &secondPointId)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2014-08-21 14:44:40 +02:00
|
|
|
const QSharedPointer<VPointF> first = GeometricObject<VPointF>(firstPointId);
|
|
|
|
const QSharedPointer<VPointF> second = GeometricObject<VPointF>(secondPointId);
|
2014-07-29 13:28:18 +02:00
|
|
|
|
2019-11-24 12:09:16 +01:00
|
|
|
AddVariable(new VLengthLine(first.data(), firstPointId, second.data(), secondPointId, *GetPatternUnit()));
|
|
|
|
AddVariable(new VLineAngle(first.data(), firstPointId, second.data(), secondPointId));
|
2013-07-30 15:09:34 +02:00
|
|
|
}
|
|
|
|
|
2015-05-31 11:17:09 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-12-20 12:04:56 +01:00
|
|
|
void VContainer::AddArc(const QSharedPointer<VAbstractCurve> &arc, const quint32 &id, const quint32 &parentId)
|
2015-05-31 11:17:09 +02:00
|
|
|
{
|
2016-04-01 21:34:57 +02:00
|
|
|
AddCurve(arc, id, parentId);
|
2015-06-02 15:53:19 +02:00
|
|
|
|
2016-12-20 12:04:56 +01:00
|
|
|
if (arc->getType() == GOType::Arc)
|
|
|
|
{
|
|
|
|
const QSharedPointer<VArc> casted = arc.staticCast<VArc>();
|
2016-04-01 21:34:57 +02:00
|
|
|
|
2019-11-24 12:09:16 +01:00
|
|
|
AddVariable(new VArcRadius(id, parentId, casted.data(), *GetPatternUnit()));
|
2016-12-20 12:04:56 +01:00
|
|
|
}
|
|
|
|
else if (arc->getType() == GOType::EllipticalArc)
|
|
|
|
{
|
|
|
|
const QSharedPointer<VEllipticalArc> casted = arc.staticCast<VEllipticalArc>();
|
2016-12-17 02:40:17 +01:00
|
|
|
|
2019-11-24 12:09:16 +01:00
|
|
|
AddVariable(new VArcRadius(id, parentId, casted.data(), 1, *GetPatternUnit()));
|
|
|
|
AddVariable(new VArcRadius(id, parentId, casted.data(), 2, *GetPatternUnit()));
|
|
|
|
AddVariable(new VEllipticalArcRotation(id, parentId, casted.data()));
|
2016-12-20 12:04:56 +01:00
|
|
|
}
|
2016-04-01 21:34:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-04-01 23:15:04 +02:00
|
|
|
void VContainer::AddCurve(const QSharedPointer<VAbstractCurve> &curve, const quint32 &id, quint32 parentId)
|
2016-04-01 21:34:57 +02:00
|
|
|
{
|
|
|
|
const GOType curveType = curve->getType();
|
2023-05-16 18:20:49 +02:00
|
|
|
if (curveType != GOType::Spline && curveType != GOType::SplinePath && curveType != GOType::CubicBezier &&
|
|
|
|
curveType != GOType::CubicBezierPath && curveType != GOType::Arc && curveType != GOType::EllipticalArc)
|
2016-04-01 21:34:57 +02:00
|
|
|
{
|
|
|
|
throw VException(tr("Can't create a curve with type '%1'").arg(static_cast<int>(curveType)));
|
|
|
|
}
|
|
|
|
|
2019-11-24 12:09:16 +01:00
|
|
|
AddVariable(new VCurveLength(id, parentId, curve.data(), *GetPatternUnit()));
|
|
|
|
AddVariable(new VCurveAngle(id, parentId, curve.data(), CurveAngle::StartAngle));
|
|
|
|
AddVariable(new VCurveAngle(id, parentId, curve.data(), CurveAngle::EndAngle));
|
2015-05-31 11:17:09 +02:00
|
|
|
}
|
|
|
|
|
2016-09-24 19:44:06 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VContainer::AddSpline(const QSharedPointer<VAbstractBezier> &curve, quint32 id, quint32 parentId)
|
|
|
|
{
|
|
|
|
AddCurve(curve, id, parentId);
|
2019-11-24 12:09:16 +01:00
|
|
|
AddVariable(new VCurveCLength(id, parentId, curve.data(), CurveCLength::C1, *GetPatternUnit()));
|
|
|
|
AddVariable(new VCurveCLength(id, parentId, curve.data(), CurveCLength::C2, *GetPatternUnit()));
|
2016-09-24 19:44:06 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-04-01 23:15:04 +02:00
|
|
|
void VContainer::AddCurveWithSegments(const QSharedPointer<VAbstractCubicBezierPath> &curve, const quint32 &id,
|
|
|
|
quint32 parentId)
|
|
|
|
{
|
2016-09-24 19:44:06 +02:00
|
|
|
AddSpline(curve, id, parentId);
|
2016-04-01 23:15:04 +02:00
|
|
|
|
|
|
|
for (qint32 i = 1; i <= curve->CountSubSpl(); ++i)
|
|
|
|
{
|
|
|
|
const VSpline spl = curve->GetSpline(i);
|
|
|
|
|
2020-11-04 14:26:22 +01:00
|
|
|
AddVariable(new VCurveLength(id, parentId, curve.data(), spl, *GetPatternUnit(), i));
|
|
|
|
AddVariable(new VCurveAngle(id, parentId, curve.data(), spl, CurveAngle::StartAngle, i));
|
|
|
|
AddVariable(new VCurveAngle(id, parentId, curve.data(), spl, CurveAngle::EndAngle, i));
|
|
|
|
AddVariable(new VCurveCLength(id, parentId, curve.data(), spl, CurveCLength::C1, *GetPatternUnit(), i));
|
|
|
|
AddVariable(new VCurveCLength(id, parentId, curve.data(), spl, CurveCLength::C2, *GetPatternUnit(), i));
|
2016-04-01 23:15:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-23 19:20:21 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VContainer::RemoveVariable(const QString &name)
|
|
|
|
{
|
|
|
|
d->variables.remove(name);
|
|
|
|
}
|
|
|
|
|
2017-01-18 11:22:02 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VContainer::RemovePiece(quint32 id)
|
|
|
|
{
|
|
|
|
d->pieces->remove(id);
|
|
|
|
}
|
|
|
|
|
2016-11-08 11:52:07 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VContainer::UpdatePiece(quint32 id, const VPiece &detail)
|
|
|
|
{
|
|
|
|
Q_ASSERT_X(id != NULL_ID, Q_FUNC_INFO, "id == 0"); //-V654 //-V712
|
|
|
|
d->pieces->insert(id, detail);
|
|
|
|
UpdateId(id);
|
|
|
|
}
|
|
|
|
|
2016-11-24 20:30:26 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VContainer::UpdatePiecePath(quint32 id, const VPiecePath &path)
|
|
|
|
{
|
|
|
|
Q_ASSERT_X(id != NULL_ID, Q_FUNC_INFO, "id == 0"); //-V654 //-V712
|
|
|
|
d->piecePaths->insert(id, path);
|
|
|
|
UpdateId(id);
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-05-21 10:51:16 +02:00
|
|
|
/**
|
2014-07-29 13:28:18 +02:00
|
|
|
* @brief RemoveIncrement remove increment by name from increment table
|
|
|
|
* @param name name of existing increment
|
2014-05-21 10:51:16 +02:00
|
|
|
*/
|
2014-07-29 13:28:18 +02:00
|
|
|
void VContainer::RemoveIncrement(const QString &name)
|
|
|
|
{
|
2014-08-21 14:44:40 +02:00
|
|
|
d->variables[name].clear();
|
|
|
|
d->variables.remove(name);
|
2014-07-29 13:28:18 +02:00
|
|
|
}
|
|
|
|
|
2022-11-10 10:30:08 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VContainer::FillPiecesAreas(Unit unit)
|
|
|
|
{
|
|
|
|
QHash<quint32, VPiece> *pieces = d->pieces.data();
|
|
|
|
|
|
|
|
auto i = pieces->constBegin();
|
|
|
|
while (i != pieces->constEnd())
|
|
|
|
{
|
2022-12-31 13:46:01 +01:00
|
|
|
AddVariable(QSharedPointer<VPieceArea>::create(PieceAreaType::External, i.key(), i.value(), this, unit));
|
|
|
|
AddVariable(QSharedPointer<VPieceArea>::create(PieceAreaType::SeamLine, i.key(), i.value(), this, unit));
|
2022-11-10 10:30:08 +01:00
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-29 13:28:18 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VContainer::DataMeasurements() const -> const QMap<QString, QSharedPointer<VMeasurement>>
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2014-07-29 14:19:11 +02:00
|
|
|
return DataVar<VMeasurement>(VarType::Measurement);
|
2014-07-29 13:28:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VContainer::DataMeasurementsWithSeparators() const -> const QMap<QString, QSharedPointer<VMeasurement>>
|
2022-02-05 14:00:22 +01:00
|
|
|
{
|
2023-05-16 18:20:49 +02:00
|
|
|
QMap<QString, QSharedPointer<VMeasurement>> measurements = DataVar<VMeasurement>(VarType::Measurement);
|
|
|
|
QMap<QString, QSharedPointer<VMeasurement>> separators = DataVar<VMeasurement>(VarType::MeasurementSeparator);
|
2022-02-05 14:00:22 +01:00
|
|
|
|
2022-12-31 13:41:10 +01:00
|
|
|
Insert(measurements, separators);
|
2022-02-05 14:00:22 +01:00
|
|
|
|
|
|
|
return measurements;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VContainer::DataIncrements() const -> const QMap<QString, QSharedPointer<VIncrement>>
|
2014-07-29 13:28:18 +02:00
|
|
|
{
|
2014-07-29 14:19:11 +02:00
|
|
|
return DataVar<VIncrement>(VarType::Increment);
|
2014-07-29 13:28:18 +02:00
|
|
|
}
|
|
|
|
|
2019-01-16 15:24:41 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VContainer::DataIncrementsWithSeparators() const -> const QMap<QString, QSharedPointer<VIncrement>>
|
2019-01-16 15:24:41 +01:00
|
|
|
{
|
2023-05-16 18:20:49 +02:00
|
|
|
QMap<QString, QSharedPointer<VIncrement>> increments = DataVar<VIncrement>(VarType::Increment);
|
|
|
|
QMap<QString, QSharedPointer<VIncrement>> separators = DataVar<VIncrement>(VarType::IncrementSeparator);
|
2019-01-16 15:24:41 +01:00
|
|
|
|
2022-12-31 13:41:10 +01:00
|
|
|
Insert(increments, separators);
|
2019-01-16 15:24:41 +01:00
|
|
|
|
|
|
|
return increments;
|
|
|
|
}
|
|
|
|
|
2014-07-29 13:28:18 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VContainer::DataLengthLines() const -> const QMap<QString, QSharedPointer<VLengthLine>>
|
2014-07-29 13:28:18 +02:00
|
|
|
{
|
2014-08-15 19:27:30 +02:00
|
|
|
return DataVar<VLengthLine>(VarType::LineLength);
|
2014-07-29 13:28:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VContainer::DataLengthCurves() const -> const QMap<QString, QSharedPointer<VCurveLength>>
|
2014-07-29 13:28:18 +02:00
|
|
|
{
|
2016-04-01 21:34:57 +02:00
|
|
|
return DataVar<VCurveLength>(VarType::CurveLength);
|
2014-07-29 13:28:18 +02:00
|
|
|
}
|
|
|
|
|
2016-09-24 19:44:06 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VContainer::DataCurvesCLength() const -> const QMap<QString, QSharedPointer<VCurveCLength>>
|
2016-09-24 19:44:06 +02:00
|
|
|
{
|
|
|
|
return DataVar<VCurveCLength>(VarType::CurveCLength);
|
|
|
|
}
|
|
|
|
|
2014-07-29 13:28:18 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VContainer::DataAngleLines() const -> const QMap<QString, QSharedPointer<VLineAngle>>
|
2014-07-29 13:28:18 +02:00
|
|
|
{
|
2014-07-29 14:19:11 +02:00
|
|
|
return DataVar<VLineAngle>(VarType::LineAngle);
|
2014-07-29 13:28:18 +02:00
|
|
|
}
|
|
|
|
|
2015-05-31 11:17:09 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VContainer::DataRadiusesArcs() const -> const QMap<QString, QSharedPointer<VArcRadius>>
|
2015-05-31 11:17:09 +02:00
|
|
|
{
|
|
|
|
return DataVar<VArcRadius>(VarType::ArcRadius);
|
|
|
|
}
|
|
|
|
|
2015-06-02 15:53:19 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VContainer::DataAnglesCurves() const -> const QMap<QString, QSharedPointer<VCurveAngle>>
|
2015-06-02 15:53:19 +02:00
|
|
|
{
|
2016-04-01 21:34:57 +02:00
|
|
|
return DataVar<VCurveAngle>(VarType::CurveAngle);
|
2015-06-02 15:53:19 +02:00
|
|
|
}
|
|
|
|
|
2022-11-10 10:30:08 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VContainer::DataPieceArea() const -> const QMap<QString, QSharedPointer<VPieceArea>>
|
2022-11-10 10:30:08 +01:00
|
|
|
{
|
2023-05-16 18:20:49 +02:00
|
|
|
QMap<QString, QSharedPointer<VPieceArea>> externalAreas = DataVar<VPieceArea>(VarType::PieceExternalArea);
|
|
|
|
QMap<QString, QSharedPointer<VPieceArea>> seamLineAreas = DataVar<VPieceArea>(VarType::PieceSeamLineArea);
|
2022-12-31 13:46:01 +01:00
|
|
|
|
|
|
|
Insert(externalAreas, seamLineAreas);
|
|
|
|
|
|
|
|
return externalAreas;
|
2022-11-10 10:30:08 +01:00
|
|
|
}
|
|
|
|
|
2014-09-04 07:20:41 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VContainer::IsUnique(const QString &name) const -> bool
|
2018-09-18 15:38:16 +02:00
|
|
|
{
|
|
|
|
return VContainer::IsUnique(name, d->nspace);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VContainer::IsUnique(const QString &name, const QString &nspace) -> bool
|
2014-09-04 07:20:41 +02:00
|
|
|
{
|
2018-09-18 15:38:16 +02:00
|
|
|
if (uniqueNames.contains(nspace))
|
|
|
|
{
|
|
|
|
return (!uniqueNames.value(nspace).contains(name) && !builInFunctions.contains(name));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw VException(QStringLiteral("Unknown namespace"));
|
|
|
|
}
|
2014-09-04 07:20:41 +02:00
|
|
|
}
|
|
|
|
|
2016-05-18 14:35:07 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VContainer::AllUniqueNames() const -> QStringList
|
2016-05-18 14:35:07 +02:00
|
|
|
{
|
2018-09-18 15:38:16 +02:00
|
|
|
return AllUniqueNames(d->nspace);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VContainer::AllUniqueNames(const QString &nspace) -> QStringList
|
2018-09-18 15:38:16 +02:00
|
|
|
{
|
|
|
|
if (uniqueNames.contains(nspace))
|
|
|
|
{
|
|
|
|
QStringList names = builInFunctions;
|
2020-01-06 19:10:09 +01:00
|
|
|
names.append(uniqueNames.value(nspace).values());
|
2018-09-18 15:38:16 +02:00
|
|
|
return names;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw VException(QStringLiteral("Unknown namespace"));
|
|
|
|
}
|
2016-05-18 14:35:07 +02:00
|
|
|
}
|
|
|
|
|
2015-06-11 19:36:17 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VContainer::GetPatternUnit() const -> const Unit *
|
2015-06-11 19:36:17 +02:00
|
|
|
{
|
|
|
|
return d->patternUnit;
|
|
|
|
}
|
|
|
|
|
2015-08-17 14:36:55 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VContainer::GetTrVars() const -> const VTranslateVars *
|
2015-08-17 14:36:55 +02:00
|
|
|
{
|
|
|
|
return d->trVars;
|
|
|
|
}
|
|
|
|
|
2014-07-29 13:28:18 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
template <typename T> auto VContainer::DataVar(const VarType &type) const -> const QMap<QString, QSharedPointer<T>>
|
2014-07-29 13:28:18 +02:00
|
|
|
{
|
2023-05-16 18:20:49 +02:00
|
|
|
QMap<QString, QSharedPointer<T>> map;
|
|
|
|
// Sorting QHash by id
|
|
|
|
QHash<QString, QSharedPointer<VInternalVariable>>::const_iterator i;
|
2014-08-21 14:44:40 +02:00
|
|
|
for (i = d->variables.constBegin(); i != d->variables.constEnd(); ++i)
|
2014-07-29 13:28:18 +02:00
|
|
|
{
|
2014-09-10 19:57:08 +02:00
|
|
|
if (i.value()->GetType() == type)
|
2014-07-29 13:28:18 +02:00
|
|
|
{
|
2014-08-21 14:44:40 +02:00
|
|
|
QSharedPointer<T> var = GetVariable<T>(i.key());
|
2015-06-11 14:40:43 +02:00
|
|
|
map.insert(d->trVars->VarToUser(i.key()), var);
|
2014-07-29 13:28:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return map;
|
2013-07-17 13:38:11 +02:00
|
|
|
}
|
2014-08-21 14:44:40 +02:00
|
|
|
|
2014-09-04 07:20:41 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2018-09-18 15:38:16 +02:00
|
|
|
void VContainer::ClearUniqueNames() const
|
2014-09-04 07:20:41 +02:00
|
|
|
{
|
2018-09-18 15:38:16 +02:00
|
|
|
uniqueNames[d->nspace].clear();
|
2014-09-04 07:20:41 +02:00
|
|
|
}
|
|
|
|
|
2017-07-23 15:52:57 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2018-09-18 15:38:16 +02:00
|
|
|
void VContainer::ClearUniqueIncrementNames() const
|
2017-07-23 15:52:57 +02:00
|
|
|
{
|
2020-01-06 19:10:09 +01:00
|
|
|
const QList<QString> list = uniqueNames.value(d->nspace).values();
|
2017-07-23 15:52:57 +02:00
|
|
|
ClearUniqueNames();
|
|
|
|
|
2023-05-03 13:07:02 +02:00
|
|
|
for (const auto &name : list)
|
2017-07-23 15:52:57 +02:00
|
|
|
{
|
2018-04-02 19:38:56 +02:00
|
|
|
if (not name.startsWith('#'))
|
2017-07-23 15:52:57 +02:00
|
|
|
{
|
2018-09-18 15:38:16 +02:00
|
|
|
uniqueNames[d->nspace].insert(name);
|
2020-01-09 14:14:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VContainer::ClearExceptUniqueIncrementNames() const
|
|
|
|
{
|
|
|
|
const QList<QString> list = uniqueNames.value(d->nspace).values();
|
|
|
|
ClearUniqueNames();
|
|
|
|
|
2023-05-03 13:07:02 +02:00
|
|
|
for (const auto &name : list)
|
2020-01-09 14:14:05 +01:00
|
|
|
{
|
|
|
|
if (name.startsWith('#'))
|
|
|
|
{
|
|
|
|
uniqueNames[d->nspace].insert(name);
|
2017-07-23 15:52:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-21 14:44:40 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief data container with datagObjects return container of gObjects
|
|
|
|
* @return pointer on container of gObjects
|
|
|
|
*/
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VContainer::CalculationGObjects() const -> const QHash<quint32, QSharedPointer<VGObject>> *
|
2014-08-21 14:44:40 +02:00
|
|
|
{
|
2017-10-26 11:54:08 +02:00
|
|
|
return &d->calculationObjects;
|
2014-08-21 14:44:40 +02:00
|
|
|
}
|
|
|
|
|
2016-11-08 11:52:07 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VContainer::DataPieces() const -> const QHash<quint32, VPiece> *
|
2016-11-08 11:52:07 +01:00
|
|
|
{
|
|
|
|
return d->pieces.data();
|
|
|
|
}
|
|
|
|
|
2014-08-21 14:44:40 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VContainer::DataVariables() const -> const QHash<QString, QSharedPointer<VInternalVariable>> *
|
2014-08-21 14:44:40 +02:00
|
|
|
{
|
|
|
|
return &d->variables;
|
|
|
|
}
|
2014-09-11 18:52:02 +02:00
|
|
|
|
2023-07-13 16:49:20 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VContainerData::VContainerData(const VTranslateVars *trVars, const Unit *patternUnit, const QString &nspace)
|
|
|
|
: trVars(trVars),
|
|
|
|
patternUnit(patternUnit),
|
|
|
|
nspace(nspace)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-09-11 18:52:02 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VContainerData::~VContainerData()
|
2018-09-18 15:38:16 +02:00
|
|
|
{
|
2020-01-06 19:10:09 +01:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
|
|
|
if (ref.loadRelaxed() == 0)
|
|
|
|
#else
|
2018-09-18 16:24:00 +02:00
|
|
|
if (ref.load() == 0)
|
2020-01-06 19:10:09 +01:00
|
|
|
#endif
|
2018-09-18 15:38:16 +02:00
|
|
|
{
|
|
|
|
--VContainer::copyCounter[nspace];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (VContainer::copyCounter.value(nspace) == 0)
|
|
|
|
{
|
|
|
|
VContainer::ClearNamespace(nspace);
|
|
|
|
}
|
|
|
|
}
|