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
|
2013-11-15 13:41:26 +01:00
|
|
|
** <https://bitbucket.org/dismine/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
|
|
|
|
2015-10-28 15:22:36 +01:00
|
|
|
class VContainerData : public QSharedData //-V690
|
2014-08-21 14:44:40 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2015-06-11 19:36:17 +02:00
|
|
|
VContainerData(const VTranslateVars *trVars, const Unit *patternUnit)
|
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),
|
|
|
|
patternUnit(patternUnit)
|
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),
|
|
|
|
patternUnit(data.patternUnit)
|
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
|
|
|
|
|
|
|
private:
|
|
|
|
VContainerData &operator=(const VContainerData &) Q_DECL_EQ_DELETE;
|
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
|
|
|
|
{
|
2013-09-23 14:08:06 +02:00
|
|
|
Q_DECLARE_TR_FUNCTIONS(VContainer)
|
2013-07-13 12:51:31 +02:00
|
|
|
public:
|
2015-06-11 19:36:17 +02:00
|
|
|
VContainer(const VTranslateVars *trVars, const Unit *patternUnit);
|
2014-05-07 18:55:57 +02:00
|
|
|
VContainer(const VContainer &data);
|
|
|
|
~VContainer();
|
2014-07-29 13:28:18 +02:00
|
|
|
|
2017-04-19 12:27:17 +02:00
|
|
|
VContainer &operator=(const VContainer &data);
|
|
|
|
#ifdef Q_COMPILER_RVALUE_REFS
|
|
|
|
VContainer &operator=(VContainer &&data) Q_DECL_NOTHROW { Swap(data); return *this; }
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void Swap(VContainer &data) Q_DECL_NOTHROW
|
|
|
|
{ std::swap(d, data.d); }
|
|
|
|
|
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;
|
2014-07-29 13:28:18 +02:00
|
|
|
template <typename T>
|
2016-05-17 11:35:18 +02:00
|
|
|
QSharedPointer<T> GetVariable(QString name) const;
|
2015-06-04 15:58:38 +02:00
|
|
|
static quint32 getId();
|
2014-07-29 13:28:18 +02:00
|
|
|
static quint32 getNextId();
|
|
|
|
static void UpdateId(quint32 newId);
|
|
|
|
|
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
|
|
|
|
|
|
|
template <typename T>
|
2015-06-04 15:58:38 +02:00
|
|
|
void AddVariable(const QString& name, T *var);
|
2017-04-14 10:30:00 +02:00
|
|
|
template <typename T>
|
|
|
|
void AddVariable(const QString& name, 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);
|
2014-09-04 07:20:41 +02:00
|
|
|
static void ClearUniqueNames();
|
2017-07-23 15:52:57 +02:00
|
|
|
static void ClearUniqueIncrementNames();
|
2014-07-29 13:28:18 +02:00
|
|
|
|
2014-09-11 19:15:07 +02:00
|
|
|
static void SetSize(qreal size);
|
|
|
|
static void SetHeight(qreal height);
|
|
|
|
static qreal size();
|
2015-10-15 12:07:43 +02:00
|
|
|
static qreal *rsize();
|
2014-09-11 19:15:07 +02:00
|
|
|
static qreal height();
|
2015-10-15 12:07:43 +02:00
|
|
|
static qreal *rheight();
|
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;
|
|
|
|
const QMap<QString, QSharedPointer<VIncrement> > DataIncrements() const;
|
|
|
|
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
|
|
|
|
2014-09-04 07:20:41 +02:00
|
|
|
static bool IsUnique(const QString &name);
|
2016-05-18 14:35:07 +02:00
|
|
|
static QStringList AllUniqueNames();
|
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
|
|
|
*/
|
2014-07-29 13:28:18 +02:00
|
|
|
static quint32 _id;
|
2014-08-21 14:44:40 +02:00
|
|
|
static qreal _size;
|
|
|
|
static qreal _height;
|
2016-05-18 14:35:07 +02:00
|
|
|
static QSet<QString> uniqueNames;
|
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);
|
|
|
|
|
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;
|
2014-07-29 13:28:18 +02:00
|
|
|
};
|
2014-02-26 09:18:59 +01:00
|
|
|
|
2015-11-25 19:56:17 +01:00
|
|
|
Q_DECLARE_TYPEINFO(VContainer, Q_MOVABLE_TYPE);
|
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>
|
|
|
|
QSharedPointer<T> VContainer::GetVariable(QString name) const
|
|
|
|
{
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
template <typename T>
|
|
|
|
void VContainer::AddVariable(const QString& name, T *var)
|
2017-04-14 10:30:00 +02:00
|
|
|
{
|
|
|
|
AddVariable(name, QSharedPointer<T>(var));
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
template <typename T>
|
|
|
|
void VContainer::AddVariable(const QString& name, const QSharedPointer<T> &var)
|
2015-06-04 15:58:38 +02:00
|
|
|
{
|
|
|
|
if (d->variables.contains(name))
|
|
|
|
{
|
|
|
|
if (d->variables.value(name)->GetType() == var->GetType())
|
|
|
|
{
|
2017-10-24 18:50:16 +02:00
|
|
|
QSharedPointer<T> v = qSharedPointerDynamicCast<T>(d->variables.value(name));
|
|
|
|
if (v.isNull())
|
|
|
|
{
|
|
|
|
throw VExceptionBadId(tr("Can't cast object."), name);
|
|
|
|
}
|
|
|
|
*v = *var;
|
2015-06-04 15:58:38 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw VExceptionBadId(tr("Can't find object. Type mismatch."), name);
|
|
|
|
}
|
|
|
|
}
|
2017-10-24 18:50:16 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
d->variables.insert(name, var);
|
|
|
|
}
|
|
|
|
|
2015-06-04 15:58:38 +02:00
|
|
|
uniqueNames.insert(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
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);
|
|
|
|
uniqueNames.insert(obj->name());
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @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
|