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.h
|
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
|
|
|
#ifndef VCONTAINER_H
|
|
|
|
#define VCONTAINER_H
|
|
|
|
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <qcompilerdetection.h>
|
|
|
|
#include <QCoreApplication>
|
|
|
|
#include <QHash>
|
|
|
|
#include <QMap>
|
|
|
|
#include <QMessageLogger>
|
|
|
|
#include <QSet>
|
|
|
|
#include <QSharedPointer>
|
|
|
|
#include <QSharedData>
|
|
|
|
#include <QSharedDataPointer>
|
|
|
|
#include <QString>
|
|
|
|
#include <QStringList>
|
|
|
|
#include <QTypeInfo>
|
|
|
|
#include <QtGlobal>
|
|
|
|
#include <new>
|
|
|
|
|
2016-08-09 15:55:46 +02:00
|
|
|
#include "../vmisc/def.h"
|
2015-06-12 10:55:44 +02:00
|
|
|
#include "../ifc/exception/vexceptionbadid.h"
|
2016-08-09 15:55:46 +02:00
|
|
|
#include "../ifc/ifcdef.h"
|
2016-04-01 23:15:04 +02:00
|
|
|
#include "../vgeometry/vabstractcubicbezierpath.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "../vgeometry/vabstractcurve.h"
|
|
|
|
#include "../vgeometry/vgobject.h"
|
2016-08-06 20:42:40 +02:00
|
|
|
#include "../vmisc/diagnostic.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "variables.h"
|
|
|
|
#include "variables/vinternalvariable.h"
|
2016-11-08 11:52:07 +01:00
|
|
|
#include "vpiece.h"
|
2016-11-24 20:30:26 +01:00
|
|
|
#include "vpiecepath.h"
|
2015-10-22 11:28:17 +02:00
|
|
|
#include "vtranslatevars.h"
|
2014-07-29 13:28:18 +02:00
|
|
|
|
2016-12-17 02:40:17 +01:00
|
|
|
class VEllipticalArc;
|
2013-07-13 12:51:31 +02:00
|
|
|
|
2016-08-06 20:42:40 +02:00
|
|
|
QT_WARNING_PUSH
|
|
|
|
QT_WARNING_DISABLE_GCC("-Weffc++")
|
|
|
|
QT_WARNING_DISABLE_INTEL(2021)
|
2017-05-30 17:44:16 +02:00
|
|
|
QT_WARNING_DISABLE_GCC("-Wnon-virtual-dtor")
|
2014-08-23 08:18:07 +02:00
|
|
|
|
2021-09-25 10:43:05 +02:00
|
|
|
class VContainerData final : public QSharedData //-V690
|
2014-08-21 14:44:40 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2018-09-18 15:38:16 +02:00
|
|
|
VContainerData(const VTranslateVars *trVars, const Unit *patternUnit, const QString &nspace)
|
2017-10-26 11:54:08 +02:00
|
|
|
: calculationObjects(QHash<quint32, QSharedPointer<VGObject> >()),
|
|
|
|
modelingObjects(QSharedPointer<QHash<quint32, QSharedPointer<VGObject>>>::create()),
|
2016-10-14 19:41:37 +02:00
|
|
|
variables(QHash<QString, QSharedPointer<VInternalVariable> > ()),
|
2017-10-18 10:24:15 +02:00
|
|
|
pieces(QSharedPointer<QHash<quint32, VPiece>>::create()),
|
|
|
|
piecePaths(QSharedPointer<QHash<quint32, VPiecePath>>::create()),
|
2016-11-24 20:30:26 +01:00
|
|
|
trVars(trVars),
|
2018-09-18 15:38:16 +02:00
|
|
|
patternUnit(patternUnit),
|
|
|
|
nspace(nspace)
|
2014-08-21 14:44:40 +02:00
|
|
|
{}
|
|
|
|
|
|
|
|
VContainerData(const VContainerData &data)
|
2016-10-14 19:41:37 +02:00
|
|
|
: QSharedData(data),
|
2017-10-26 11:54:08 +02:00
|
|
|
calculationObjects(data.calculationObjects),
|
|
|
|
modelingObjects(data.modelingObjects),
|
2016-10-14 19:41:37 +02:00
|
|
|
variables(data.variables),
|
2016-11-08 12:07:29 +01:00
|
|
|
pieces(data.pieces),
|
2016-11-28 12:57:28 +01:00
|
|
|
piecePaths(data.piecePaths),
|
2016-10-14 19:41:37 +02:00
|
|
|
trVars(data.trVars),
|
2018-09-18 15:38:16 +02:00
|
|
|
patternUnit(data.patternUnit),
|
|
|
|
nspace(data.nspace)
|
2014-08-21 14:44:40 +02:00
|
|
|
{}
|
|
|
|
|
2014-09-11 18:52:02 +02:00
|
|
|
virtual ~VContainerData();
|
2014-08-21 14:44:40 +02:00
|
|
|
|
2017-10-26 11:54:08 +02:00
|
|
|
QHash<quint32, QSharedPointer<VGObject> > calculationObjects;
|
|
|
|
QSharedPointer<QHash<quint32, QSharedPointer<VGObject>>> modelingObjects;
|
2014-08-21 14:44:40 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief variables container for measurements, increments, lines lengths, lines angles, arcs lengths, curve lengths
|
|
|
|
*/
|
|
|
|
QHash<QString, QSharedPointer<VInternalVariable>> variables;
|
2017-01-21 18:12:57 +01:00
|
|
|
|
2016-11-08 11:52:07 +01:00
|
|
|
QSharedPointer<QHash<quint32, VPiece>> pieces;
|
2016-11-24 20:30:26 +01:00
|
|
|
QSharedPointer<QHash<quint32, VPiecePath>> piecePaths;
|
2015-06-11 14:40:43 +02:00
|
|
|
|
|
|
|
const VTranslateVars *trVars;
|
2015-06-11 19:36:17 +02:00
|
|
|
const Unit *patternUnit;
|
2015-10-31 13:56:28 +01:00
|
|
|
|
2018-09-18 15:38:16 +02:00
|
|
|
/** @brief nspace namespace for static variables */
|
|
|
|
QString nspace;
|
|
|
|
|
2015-10-31 13:56:28 +01:00
|
|
|
private:
|
2019-07-01 10:33:29 +02:00
|
|
|
Q_DISABLE_ASSIGN(VContainerData)
|
2014-08-21 14:44:40 +02:00
|
|
|
};
|
|
|
|
|
2016-08-06 20:42:40 +02:00
|
|
|
QT_WARNING_POP
|
2014-08-23 08:18:07 +02:00
|
|
|
|
2013-08-05 10:37:56 +02:00
|
|
|
/**
|
2013-10-07 17:34:14 +02:00
|
|
|
* @brief The VContainer class container of all variables.
|
2013-08-05 10:37:56 +02:00
|
|
|
*/
|
2013-11-04 21:35:15 +01:00
|
|
|
class VContainer
|
|
|
|
{
|
2022-08-12 17:50:13 +02:00
|
|
|
Q_DECLARE_TR_FUNCTIONS(VContainer) // NOLINT
|
2013-07-13 12:51:31 +02:00
|
|
|
public:
|
2018-09-18 15:38:16 +02:00
|
|
|
VContainer(const VTranslateVars *trVars, const Unit *patternUnit, const QString &nspace);
|
2014-05-07 18:55:57 +02:00
|
|
|
VContainer(const VContainer &data);
|
|
|
|
~VContainer();
|
2014-07-29 13:28:18 +02:00
|
|
|
|
2018-09-18 15:38:16 +02:00
|
|
|
friend class VContainerData;
|
|
|
|
|
2017-04-19 12:27:17 +02:00
|
|
|
VContainer &operator=(const VContainer &data);
|
|
|
|
#ifdef Q_COMPILER_RVALUE_REFS
|
2022-08-12 17:50:13 +02:00
|
|
|
VContainer(VContainer &&data) Q_DECL_NOTHROW;
|
2019-12-30 12:00:57 +01:00
|
|
|
VContainer &operator=(VContainer &&data) Q_DECL_NOTHROW;
|
2017-04-19 12:27:17 +02:00
|
|
|
#endif
|
|
|
|
|
2018-09-18 15:38:16 +02:00
|
|
|
static QString UniqueNamespace();
|
|
|
|
|
2013-12-29 17:48:57 +01:00
|
|
|
template <typename T>
|
2015-06-04 15:58:38 +02:00
|
|
|
const QSharedPointer<T> GeometricObject(const quint32 &id) const;
|
2014-08-21 14:44:40 +02:00
|
|
|
const QSharedPointer<VGObject> GetGObject(quint32 id) const;
|
2015-10-12 13:52:48 +02:00
|
|
|
static const QSharedPointer<VGObject> GetFakeGObject(quint32 id);
|
2016-11-08 11:52:07 +01:00
|
|
|
VPiece GetPiece(quint32 id) const;
|
2016-11-24 20:30:26 +01:00
|
|
|
VPiecePath GetPiecePath(quint32 id) const;
|
2018-07-26 19:00:24 +02:00
|
|
|
quint32 GetPieceForPiecePath(quint32 id) const;
|
2014-07-29 13:28:18 +02:00
|
|
|
template <typename T>
|
2019-11-24 12:09:16 +01:00
|
|
|
QSharedPointer<T> GetVariable(const QString &name) const;
|
2018-09-18 15:38:16 +02:00
|
|
|
quint32 getId() const;
|
|
|
|
quint32 getNextId() const;
|
|
|
|
void UpdateId(quint32 newId) const;
|
|
|
|
static void UpdateId(quint32 newId, const QString &nspace);
|
2014-07-29 13:28:18 +02:00
|
|
|
|
2020-11-07 16:43:49 +01:00
|
|
|
void RegisterUniqueName(VGObject *obj) const;
|
|
|
|
void RegisterUniqueName(const QSharedPointer<VGObject> &obj) const;
|
2020-11-04 17:14:21 +01:00
|
|
|
|
2014-05-21 10:51:16 +02:00
|
|
|
quint32 AddGObject(VGObject *obj);
|
2017-10-15 11:25:20 +02:00
|
|
|
quint32 AddGObject(const QSharedPointer<VGObject> &obj);
|
2016-11-08 11:52:07 +01:00
|
|
|
quint32 AddPiece(const VPiece &detail);
|
2016-11-24 20:30:26 +01:00
|
|
|
quint32 AddPiecePath(const VPiecePath &path);
|
2014-05-21 10:51:16 +02:00
|
|
|
void AddLine(const quint32 &firstPointId, const quint32 &secondPointId);
|
2017-04-06 14:50:15 +02:00
|
|
|
void AddArc(const QSharedPointer<VAbstractCurve> &arc, const quint32 &id,
|
2016-12-20 12:04:56 +01:00
|
|
|
const quint32 &parentId = NULL_ID);
|
2016-09-24 19:44:06 +02:00
|
|
|
void AddSpline(const QSharedPointer<VAbstractBezier> &curve, quint32 id, quint32 parentId = NULL_ID);
|
2016-04-01 23:15:04 +02:00
|
|
|
void AddCurveWithSegments(const QSharedPointer<VAbstractCubicBezierPath> &curve, const quint32 &id,
|
|
|
|
quint32 parentId = NULL_ID);
|
2014-07-29 13:28:18 +02:00
|
|
|
|
2020-01-09 14:14:05 +01:00
|
|
|
template <typename T>
|
|
|
|
void AddUniqueVariable(T *var);
|
|
|
|
template <typename T>
|
|
|
|
void AddUniqueVariable(const QSharedPointer<T> &var);
|
2014-07-29 13:28:18 +02:00
|
|
|
template <typename T>
|
2019-11-24 12:09:16 +01:00
|
|
|
void AddVariable(T *var);
|
2017-04-14 10:30:00 +02:00
|
|
|
template <typename T>
|
2019-11-24 12:09:16 +01:00
|
|
|
void AddVariable(const QSharedPointer<T> &var);
|
2016-06-23 19:20:21 +02:00
|
|
|
void RemoveVariable(const QString& name);
|
2017-01-18 11:22:02 +01:00
|
|
|
void RemovePiece(quint32 id);
|
2014-07-29 13:28:18 +02:00
|
|
|
|
2017-10-24 18:50:16 +02:00
|
|
|
template <class T>
|
|
|
|
void UpdateGObject(quint32 id, T* obj);
|
|
|
|
template <class T>
|
|
|
|
void UpdateGObject(quint32 id, const QSharedPointer<T> &obj);
|
2016-11-08 11:52:07 +01:00
|
|
|
void UpdatePiece(quint32 id, const VPiece &detail);
|
2016-11-24 20:30:26 +01:00
|
|
|
void UpdatePiecePath(quint32 id, const VPiecePath &path);
|
2014-07-29 13:28:18 +02:00
|
|
|
|
2014-05-21 10:51:16 +02:00
|
|
|
void Clear();
|
2015-08-26 20:14:47 +02:00
|
|
|
void ClearForFullParse();
|
2014-05-21 10:51:16 +02:00
|
|
|
void ClearGObjects();
|
|
|
|
void ClearCalculationGObjects();
|
2014-07-29 13:28:18 +02:00
|
|
|
void ClearVariables(const VarType &type = VarType::Unknown);
|
2018-01-20 13:01:35 +01:00
|
|
|
void ClearVariables(const QVector<VarType> &types);
|
2018-09-18 15:38:16 +02:00
|
|
|
void ClearUniqueNames() const;
|
|
|
|
void ClearUniqueIncrementNames() const;
|
2020-01-09 14:14:05 +01:00
|
|
|
void ClearExceptUniqueIncrementNames() const;
|
2014-07-29 13:28:18 +02:00
|
|
|
|
|
|
|
void RemoveIncrement(const QString& name);
|
|
|
|
|
2017-10-26 11:54:08 +02:00
|
|
|
const QHash<quint32, QSharedPointer<VGObject> > *CalculationGObjects() const;
|
2016-11-08 11:52:07 +01:00
|
|
|
const QHash<quint32, VPiece> *DataPieces() const;
|
2014-08-21 14:44:40 +02:00
|
|
|
const QHash<QString, QSharedPointer<VInternalVariable>> *DataVariables() const;
|
2014-07-29 13:28:18 +02:00
|
|
|
|
2016-09-24 19:44:06 +02:00
|
|
|
const QMap<QString, QSharedPointer<VMeasurement> > DataMeasurements() const;
|
2022-02-05 14:00:22 +01:00
|
|
|
const QMap<QString, QSharedPointer<VMeasurement> > DataMeasurementsWithSeparators() const;
|
2016-09-24 19:44:06 +02:00
|
|
|
const QMap<QString, QSharedPointer<VIncrement> > DataIncrements() const;
|
2019-01-16 15:24:41 +01:00
|
|
|
const QMap<QString, QSharedPointer<VIncrement> > DataIncrementsWithSeparators() const;
|
2016-09-24 19:44:06 +02:00
|
|
|
const QMap<QString, QSharedPointer<VLengthLine> > DataLengthLines() const;
|
|
|
|
const QMap<QString, QSharedPointer<VCurveLength> > DataLengthCurves() const;
|
|
|
|
const QMap<QString, QSharedPointer<VCurveCLength> > DataCurvesCLength() const;
|
|
|
|
const QMap<QString, QSharedPointer<VLineAngle> > DataAngleLines() const;
|
|
|
|
const QMap<QString, QSharedPointer<VArcRadius> > DataRadiusesArcs() const;
|
|
|
|
const QMap<QString, QSharedPointer<VCurveAngle> > DataAnglesCurves() const;
|
2014-07-29 13:28:18 +02:00
|
|
|
|
2018-09-18 15:38:16 +02:00
|
|
|
bool IsUnique(const QString &name) const;
|
|
|
|
static bool IsUnique(const QString &name, const QString &nspace);
|
|
|
|
|
|
|
|
QStringList AllUniqueNames() const;
|
|
|
|
static QStringList AllUniqueNames(const QString &nspace);
|
2014-07-29 13:28:18 +02:00
|
|
|
|
2015-06-11 19:36:17 +02:00
|
|
|
const Unit *GetPatternUnit() const;
|
2015-08-17 14:36:55 +02:00
|
|
|
const VTranslateVars *GetTrVars() const;
|
2015-06-11 19:36:17 +02:00
|
|
|
|
2013-07-13 12:51:31 +02:00
|
|
|
private:
|
2013-11-18 17:37:17 +01:00
|
|
|
/**
|
2014-01-07 11:46:23 +01:00
|
|
|
* @brief _id current id. New object will have value +1. For empty class equal 0.
|
2013-11-18 17:37:17 +01:00
|
|
|
*/
|
2018-09-18 15:38:16 +02:00
|
|
|
static QMap<QString, quint32> _id;
|
|
|
|
static QMap<QString, QSet<QString>> uniqueNames;
|
|
|
|
static QMap<QString, quint32> copyCounter;
|
2014-07-29 13:28:18 +02:00
|
|
|
|
2014-08-21 14:44:40 +02:00
|
|
|
QSharedDataPointer<VContainerData> d;
|
|
|
|
|
2016-09-24 19:44:06 +02:00
|
|
|
void AddCurve(const QSharedPointer<VAbstractCurve> &curve, const quint32 &id, quint32 parentId = NULL_ID);
|
|
|
|
|
2020-11-04 09:58:57 +01:00
|
|
|
template <typename T>
|
|
|
|
void AddVariable(const QSharedPointer<T> &var, const QString &name);
|
|
|
|
|
2014-08-21 14:44:40 +02:00
|
|
|
template <class T>
|
2015-06-04 15:58:38 +02:00
|
|
|
uint qHash( const QSharedPointer<T> &p );
|
2014-05-21 10:51:16 +02:00
|
|
|
|
2017-10-24 18:50:16 +02:00
|
|
|
template <typename T>
|
|
|
|
void UpdateObject(const quint32 &id, const QSharedPointer<T> &point);
|
2014-05-21 10:51:16 +02:00
|
|
|
|
2014-07-29 13:28:18 +02:00
|
|
|
template <typename T>
|
2014-08-21 14:44:40 +02:00
|
|
|
const QMap<QString, QSharedPointer<T> > DataVar(const VarType &type) const;
|
2018-09-18 15:38:16 +02:00
|
|
|
|
|
|
|
static void ClearNamespace(const QString &nspace);
|
2014-07-29 13:28:18 +02:00
|
|
|
};
|
2014-02-26 09:18:59 +01:00
|
|
|
|
2022-08-12 17:50:13 +02:00
|
|
|
Q_DECLARE_TYPEINFO(VContainer, Q_MOVABLE_TYPE); // NOLINT
|
2015-06-04 15:58:38 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Defintion of templated member functions of VContainer
|
|
|
|
*/
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
template <typename T>
|
|
|
|
const QSharedPointer<T> VContainer::GeometricObject(const quint32 &id) const
|
|
|
|
{
|
2017-09-16 16:25:14 +02:00
|
|
|
if (id == NULL_ID)
|
|
|
|
{
|
|
|
|
throw VExceptionBadId(tr("Can't find object"), id);
|
|
|
|
}
|
|
|
|
|
2017-10-26 11:54:08 +02:00
|
|
|
QSharedPointer<VGObject> gObj;
|
|
|
|
if (d->calculationObjects.contains(id))
|
2015-06-04 15:58:38 +02:00
|
|
|
{
|
2017-10-26 11:54:08 +02:00
|
|
|
gObj = d->calculationObjects.value(id);
|
2015-06-04 15:58:38 +02:00
|
|
|
}
|
2017-10-26 11:54:08 +02:00
|
|
|
else if (d->modelingObjects->contains(id))
|
2015-06-04 15:58:38 +02:00
|
|
|
{
|
2017-10-26 11:54:08 +02:00
|
|
|
gObj = d->modelingObjects->value(id);
|
2017-01-17 12:49:21 +01:00
|
|
|
}
|
2017-10-26 11:54:08 +02:00
|
|
|
else
|
2017-01-17 12:49:21 +01:00
|
|
|
{
|
2017-10-26 11:54:08 +02:00
|
|
|
throw VExceptionBadId(tr("Can't find object"), id);
|
2017-01-17 12:49:21 +01:00
|
|
|
}
|
2017-10-26 11:54:08 +02:00
|
|
|
|
|
|
|
QSharedPointer<T> obj = qSharedPointerDynamicCast<T>(gObj);
|
|
|
|
SCASSERT(obj.isNull() == false)
|
|
|
|
return obj;
|
2015-06-04 15:58:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief GetVariable return varible by name
|
|
|
|
* @param name variable's name
|
|
|
|
* @return variable
|
|
|
|
*/
|
|
|
|
template <typename T>
|
2019-11-24 12:09:16 +01:00
|
|
|
QSharedPointer<T> VContainer::GetVariable(const QString &name) const
|
2015-06-04 15:58:38 +02:00
|
|
|
{
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(name.isEmpty()==false)
|
2015-06-04 15:58:38 +02:00
|
|
|
if (d->variables.contains(name))
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
QSharedPointer<T> value = qSharedPointerDynamicCast<T>(d->variables.value(name));
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(value.isNull() == false)
|
2015-06-04 15:58:38 +02:00
|
|
|
return value;
|
|
|
|
}
|
|
|
|
catch (const std::bad_alloc &)
|
|
|
|
{
|
|
|
|
throw VExceptionBadId(tr("Can't cast object"), name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw VExceptionBadId(tr("Can't find object"), name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-09 14:14:05 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
template <typename T>
|
|
|
|
void VContainer::AddUniqueVariable(T *var)
|
|
|
|
{
|
|
|
|
AddUniqueVariable(QSharedPointer<T>(var));
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
template <typename T>
|
|
|
|
void VContainer::AddUniqueVariable(const QSharedPointer<T> &var)
|
|
|
|
{
|
|
|
|
AddVariable(var);
|
|
|
|
|
|
|
|
if (d->variables.contains(var->GetName()))
|
|
|
|
{
|
|
|
|
uniqueNames[d->nspace].insert(var->GetName());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-04 15:58:38 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
template <typename T>
|
2019-11-24 12:09:16 +01:00
|
|
|
void VContainer::AddVariable(T *var)
|
2017-04-14 10:30:00 +02:00
|
|
|
{
|
2019-11-24 12:09:16 +01:00
|
|
|
AddVariable(QSharedPointer<T>(var));
|
2017-04-14 10:30:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
template <typename T>
|
2019-11-24 12:09:16 +01:00
|
|
|
void VContainer::AddVariable(const QSharedPointer<T> &var)
|
2015-06-04 15:58:38 +02:00
|
|
|
{
|
2019-11-24 12:09:16 +01:00
|
|
|
SCASSERT(not var->GetName().isEmpty())
|
2020-11-04 09:58:57 +01:00
|
|
|
AddVariable(var, var->GetName());
|
|
|
|
|
|
|
|
if (not var->GetAlias().isEmpty())
|
|
|
|
{
|
|
|
|
AddVariable(var, var->GetAlias());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
template <typename T>
|
|
|
|
void VContainer::AddVariable(const QSharedPointer<T> &var, const QString &name)
|
|
|
|
{
|
|
|
|
if (name.isEmpty())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d->variables.contains(name))
|
2015-06-04 15:58:38 +02:00
|
|
|
{
|
2020-11-04 09:58:57 +01:00
|
|
|
if (d->variables.value(name)->GetType() == var->GetType())
|
2015-06-04 15:58:38 +02:00
|
|
|
{
|
2020-11-04 09:58:57 +01:00
|
|
|
QSharedPointer<T> v = qSharedPointerDynamicCast<T>(d->variables.value(name));
|
2017-10-24 18:50:16 +02:00
|
|
|
if (v.isNull())
|
|
|
|
{
|
2020-11-04 09:58:57 +01:00
|
|
|
throw VExceptionBadId(tr("Can't cast object."), name);
|
2017-10-24 18:50:16 +02:00
|
|
|
}
|
|
|
|
*v = *var;
|
2015-06-04 15:58:38 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-11-04 09:58:57 +01:00
|
|
|
throw VExceptionBadId(tr("Can't find object. Type mismatch."), name);
|
2015-06-04 15:58:38 +02:00
|
|
|
}
|
|
|
|
}
|
2017-10-24 18:50:16 +02:00
|
|
|
else
|
|
|
|
{
|
2020-11-04 09:58:57 +01:00
|
|
|
d->variables.insert(name, var);
|
2017-10-24 18:50:16 +02:00
|
|
|
}
|
2015-06-04 15:58:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
template <class T>
|
|
|
|
uint VContainer::qHash( const QSharedPointer<T> &p )
|
|
|
|
{
|
|
|
|
return qHash( p.data() );
|
|
|
|
}
|
2017-10-24 18:50:16 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief UpdateGObject update GObject by id
|
|
|
|
* @param id id of existing GObject
|
|
|
|
* @param obj object
|
|
|
|
*/
|
|
|
|
template <class T>
|
|
|
|
void VContainer::UpdateGObject(quint32 id, T* obj)
|
|
|
|
{
|
|
|
|
SCASSERT(obj != nullptr)
|
|
|
|
UpdateGObject(id, QSharedPointer<T>(obj));
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
template <class T>
|
|
|
|
void VContainer::UpdateGObject(quint32 id, const QSharedPointer<T> &obj)
|
|
|
|
{
|
|
|
|
SCASSERT(not obj.isNull())
|
|
|
|
UpdateObject(id, obj);
|
2020-11-04 17:14:21 +01:00
|
|
|
RegisterUniqueName(obj);
|
2017-10-24 18:50:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief UpdateObject update object in container
|
|
|
|
* @param id id of existing object
|
|
|
|
* @param point object
|
|
|
|
*/
|
|
|
|
template <typename T>
|
|
|
|
void VContainer::UpdateObject(const quint32 &id, const QSharedPointer<T> &point)
|
|
|
|
{
|
|
|
|
Q_ASSERT_X(id != NULL_ID, Q_FUNC_INFO, "id == 0"); //-V654 //-V712
|
|
|
|
SCASSERT(point.isNull() == false)
|
|
|
|
point->setId(id);
|
2017-10-26 11:54:08 +02:00
|
|
|
|
|
|
|
if (d->calculationObjects.contains(id) && point->getMode() == Draw::Calculation)
|
2017-10-24 18:50:16 +02:00
|
|
|
{
|
2017-10-26 11:54:08 +02:00
|
|
|
QSharedPointer<T> obj = qSharedPointerDynamicCast<T>(d->calculationObjects.value(id));
|
2017-10-24 18:50:16 +02:00
|
|
|
if (obj.isNull())
|
|
|
|
{
|
|
|
|
throw VExceptionBadId(tr("Can't cast object"), id);
|
|
|
|
}
|
|
|
|
*obj = *point;
|
|
|
|
}
|
2017-10-26 11:54:08 +02:00
|
|
|
else if (d->modelingObjects->contains(id) && point->getMode() == Draw::Modeling)
|
|
|
|
{
|
|
|
|
QSharedPointer<T> obj = qSharedPointerDynamicCast<T>(d->modelingObjects->value(id));
|
|
|
|
if (obj.isNull())
|
|
|
|
{
|
|
|
|
throw VExceptionBadId(tr("Can't cast object"), id);
|
|
|
|
}
|
|
|
|
*obj = *point;
|
|
|
|
}
|
|
|
|
else if (point->getMode() == Draw::Calculation)
|
|
|
|
{
|
|
|
|
d->calculationObjects.insert(id, point);
|
|
|
|
}
|
|
|
|
else if (point->getMode() == Draw::Modeling)
|
|
|
|
{
|
|
|
|
d->modelingObjects->insert(id, point);
|
|
|
|
}
|
2017-10-24 18:50:16 +02:00
|
|
|
else
|
|
|
|
{
|
2017-10-26 11:54:08 +02:00
|
|
|
qWarning("Can't update an object with mode 'Layout'");
|
|
|
|
return;
|
2017-10-24 18:50:16 +02:00
|
|
|
}
|
2017-10-26 11:54:08 +02:00
|
|
|
|
2017-10-24 18:50:16 +02:00
|
|
|
UpdateId(id);
|
|
|
|
}
|
2013-07-13 12:51:31 +02:00
|
|
|
#endif // VCONTAINER_H
|