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
|
|
|
|
** This source code is part of the Valentine project, a pattern making
|
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
|
|
|
** Copyright (C) 2013 Valentina project
|
|
|
|
** <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
|
|
|
|
|
2014-07-29 13:28:18 +02:00
|
|
|
#include "variables.h"
|
2013-11-06 18:06:00 +01:00
|
|
|
#include "../geometry/vdetail.h"
|
2013-12-29 17:48:57 +01:00
|
|
|
#include "../geometry/vgobject.h"
|
2013-12-30 12:28:33 +01:00
|
|
|
#include "../exception/vexceptionbadid.h"
|
2014-08-15 19:07:26 +02:00
|
|
|
#include "../geometry/vabstractcurve.h"
|
2014-07-29 13:28:18 +02:00
|
|
|
|
2014-06-17 11:50:11 +02:00
|
|
|
#include <QCoreApplication>
|
|
|
|
#include <QHash>
|
2013-07-13 12:51:31 +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:
|
2014-05-07 18:55:57 +02:00
|
|
|
VContainer();
|
|
|
|
VContainer &operator=(const VContainer &data);
|
|
|
|
VContainer(const VContainer &data);
|
|
|
|
~VContainer();
|
2014-07-29 13:28:18 +02:00
|
|
|
|
2014-05-21 10:51:16 +02:00
|
|
|
void setData(const VContainer &data);
|
2014-07-29 13:28:18 +02:00
|
|
|
|
2013-12-29 17:48:57 +01:00
|
|
|
template <typename T>
|
2014-03-02 19:32:54 +01:00
|
|
|
const T GeometricObject(const quint32 &id) const
|
2013-12-29 17:48:57 +01:00
|
|
|
{
|
2014-02-26 10:22:05 +01:00
|
|
|
VGObject *gObj = nullptr;
|
2013-12-30 12:28:33 +01:00
|
|
|
if (gObjects.contains(id))
|
|
|
|
{
|
|
|
|
gObj = gObjects.value(id);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw VExceptionBadId(tr("Can't find object"), id);
|
2014-03-02 19:32:54 +01:00
|
|
|
return nullptr;
|
2013-12-30 12:28:33 +01:00
|
|
|
}
|
2014-03-02 19:32:54 +01:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
T obj = dynamic_cast<T>(gObj);
|
2014-05-30 21:56:05 +02:00
|
|
|
SCASSERT(obj != nullptr);
|
2014-03-02 19:32:54 +01:00
|
|
|
return obj;
|
|
|
|
}
|
2014-03-06 16:35:24 +01:00
|
|
|
catch (const std::bad_alloc &)
|
2014-03-02 19:32:54 +01:00
|
|
|
{
|
|
|
|
throw VExceptionBadId(tr("Can't cast object"), id);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return nullptr;
|
2013-12-29 17:48:57 +01:00
|
|
|
}
|
|
|
|
|
2014-05-21 10:51:16 +02:00
|
|
|
const VGObject *GetGObject(quint32 id) const;
|
|
|
|
const VDetail GetDetail(quint32 id) const;
|
2014-07-29 13:28:18 +02:00
|
|
|
qreal GetTableValue(const QString& name) const;
|
|
|
|
template <typename T>
|
|
|
|
/**
|
|
|
|
* @brief GetVariable return varible by name
|
|
|
|
* @param name variable's name
|
|
|
|
* @return variable
|
|
|
|
*/
|
|
|
|
T GetVariable(QString name) const
|
|
|
|
{
|
|
|
|
SCASSERT(name.isEmpty()==false);
|
|
|
|
if (variables.contains(name))
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
T value = dynamic_cast<T>(variables.value(name));
|
|
|
|
SCASSERT(value != nullptr);
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
catch (const std::bad_alloc &)
|
|
|
|
{
|
|
|
|
throw VExceptionBadId(tr("Can't cast object"), name);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw VExceptionBadId(tr("Can't find object"), name);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-21 10:51:16 +02:00
|
|
|
static quint32 getId(){return _id;}
|
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);
|
|
|
|
quint32 AddDetail(VDetail detail);
|
|
|
|
void AddLine(const quint32 &firstPointId, const quint32 &secondPointId);
|
2014-07-29 13:28:18 +02:00
|
|
|
|
2014-08-15 19:07:26 +02:00
|
|
|
template <typename TLength>
|
|
|
|
/**
|
|
|
|
* @brief AddCurveLength add length of curve type to the container
|
|
|
|
* @param id id of variables
|
|
|
|
* @param parentId if of parent object.
|
|
|
|
*
|
|
|
|
* Parent id - id of cutting point
|
|
|
|
*/
|
|
|
|
void AddCurveLength(const quint32 &id, const quint32 &parentId = 0)
|
|
|
|
{
|
|
|
|
const VAbstractCurve *var = GeometricObject<const VAbstractCurve *>(id);
|
|
|
|
AddVariable(var->name(), new TLength(id, parentId, var));
|
|
|
|
}
|
|
|
|
|
2014-07-29 13:28:18 +02:00
|
|
|
template <typename T>
|
|
|
|
void AddVariable(const QString& name, T var)
|
|
|
|
{
|
|
|
|
if(variables.contains(name))
|
|
|
|
{
|
|
|
|
if(variables.value(name)->GetType() == var->GetType())
|
|
|
|
{
|
|
|
|
T v = dynamic_cast<T>(variables.value(name));
|
|
|
|
SCASSERT(v != nullptr);
|
|
|
|
*v = *var;
|
|
|
|
delete var;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw VExceptionBadId(tr("Can't find object. Type mismatch."), name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
variables[name] = var;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-21 10:51:16 +02:00
|
|
|
void UpdateGObject(quint32 id, VGObject* obj);
|
|
|
|
void UpdateDetail(quint32 id, const VDetail &detail);
|
2014-07-29 13:28:18 +02:00
|
|
|
|
2014-05-21 10:51:16 +02:00
|
|
|
void Clear();
|
|
|
|
void ClearGObjects();
|
|
|
|
void ClearCalculationGObjects();
|
2014-07-29 13:28:18 +02:00
|
|
|
void ClearVariables(const VarType &type = VarType::Unknown);
|
2014-05-21 10:51:16 +02:00
|
|
|
void ClearDetails();
|
2014-07-29 13:28:18 +02:00
|
|
|
|
2014-05-21 10:51:16 +02:00
|
|
|
void SetSize(qreal size);
|
|
|
|
void SetSizeName(const QString &name);
|
|
|
|
void SetHeight(qreal height);
|
|
|
|
void SetHeightName(const QString &name);
|
|
|
|
qreal size() const;
|
|
|
|
QString SizeName()const;
|
|
|
|
qreal height() const;
|
|
|
|
QString HeightName()const;
|
2014-07-29 13:28:18 +02:00
|
|
|
|
2014-07-30 11:51:22 +02:00
|
|
|
bool VariableExist(const QString& name);
|
2014-07-29 13:28:18 +02:00
|
|
|
|
|
|
|
void RemoveIncrement(const QString& name);
|
|
|
|
|
|
|
|
const QHash<quint32, VGObject*> *DataGObjects() const;
|
|
|
|
const QHash<quint32, VDetail> *DataDetails() const;
|
|
|
|
const QHash<QString, VInternalVariable*> *DataVariables() const;
|
|
|
|
|
2014-07-29 14:19:11 +02:00
|
|
|
const QMap<QString, VMeasurement *> DataMeasurements() const;
|
|
|
|
const QMap<QString, VIncrement *> DataIncrements() const;
|
|
|
|
const QMap<QString, VLengthLine *> DataLengthLines() const;
|
|
|
|
const QMap<QString, VLengthSpline *> DataLengthSplines() const;
|
|
|
|
const QMap<QString, VLengthArc *> DataLengthArcs() const;
|
2014-08-11 16:41:17 +02:00
|
|
|
const QMap<QString, VLineAngle *> DataAngleLines() const;
|
2014-07-29 13:28:18 +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;
|
|
|
|
qreal _size;
|
|
|
|
QString sizeName;
|
|
|
|
qreal _height;
|
|
|
|
QString heightName;
|
2013-11-18 17:37:17 +01:00
|
|
|
/**
|
2013-12-29 17:48:57 +01:00
|
|
|
* @brief gObjects graphicals objects of pattern.
|
2013-11-18 17:37:17 +01:00
|
|
|
*/
|
2014-02-25 15:40:24 +01:00
|
|
|
QHash<quint32, VGObject*> gObjects;
|
2014-07-29 13:28:18 +02:00
|
|
|
|
2013-11-18 17:37:17 +01:00
|
|
|
/**
|
2014-07-29 13:28:18 +02:00
|
|
|
* @brief variables container for measurements, increments, lines lengths, lines angles, arcs lengths, curve lengths
|
2013-11-18 17:37:17 +01:00
|
|
|
*/
|
2014-07-29 13:28:18 +02:00
|
|
|
QHash<QString, VInternalVariable*> variables;
|
2013-11-18 17:37:17 +01:00
|
|
|
/**
|
|
|
|
* @brief details container of details
|
|
|
|
*/
|
2014-02-25 15:40:24 +01:00
|
|
|
QHash<quint32, VDetail> details;
|
2014-05-21 10:51:16 +02:00
|
|
|
|
2013-11-18 17:37:17 +01:00
|
|
|
template <typename key, typename val>
|
2014-01-27 16:48:11 +01:00
|
|
|
// cppcheck-suppress functionStatic
|
2013-12-30 12:28:33 +01:00
|
|
|
const val GetObject(const QHash<key, val> &obj, key id) const;
|
2014-05-21 10:51:16 +02:00
|
|
|
|
2013-11-18 17:37:17 +01:00
|
|
|
template <typename val>
|
2014-02-25 15:40:24 +01:00
|
|
|
void UpdateObject(QHash<quint32, val > &obj, const quint32 &id, val point);
|
2014-05-21 10:51:16 +02:00
|
|
|
|
2013-11-18 17:37:17 +01:00
|
|
|
template <typename key, typename val>
|
2014-02-25 15:40:24 +01:00
|
|
|
static quint32 AddObject(QHash<key, val> &obj, val value);
|
2014-02-26 09:18:59 +01:00
|
|
|
|
2014-07-29 13:28:18 +02:00
|
|
|
template <typename T>
|
|
|
|
void CopyGObject(const VContainer &data, const quint32 &id);
|
2014-03-28 14:11:46 +01:00
|
|
|
|
2014-07-29 13:28:18 +02:00
|
|
|
template <typename T>
|
|
|
|
void CopyVar(const VContainer &data, const QString &name);
|
2014-02-26 09:18:59 +01:00
|
|
|
|
2014-07-29 13:28:18 +02:00
|
|
|
template <typename T>
|
2014-07-29 14:19:11 +02:00
|
|
|
const QMap<QString, T*> DataVar(const VarType &type) const;
|
2014-07-29 13:28:18 +02:00
|
|
|
};
|
2014-02-26 09:18:59 +01:00
|
|
|
|
2014-05-21 10:51:16 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-02-26 09:18:59 +01:00
|
|
|
inline void VContainer::ClearDetails()
|
|
|
|
{
|
|
|
|
details.clear();
|
|
|
|
}
|
|
|
|
|
2014-05-21 10:51:16 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief SetSize set value of size
|
|
|
|
* @param size value of size
|
|
|
|
*/
|
2014-03-11 21:19:13 +01:00
|
|
|
inline void VContainer::SetSize(qreal size)
|
|
|
|
{
|
|
|
|
_size = size;
|
|
|
|
}
|
|
|
|
|
2014-05-21 10:51:16 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-03-11 21:19:13 +01:00
|
|
|
inline void VContainer::SetSizeName(const QString &name)
|
2014-02-26 09:18:59 +01:00
|
|
|
{
|
2014-03-11 21:19:13 +01:00
|
|
|
sizeName = name;
|
2014-02-26 09:18:59 +01:00
|
|
|
}
|
|
|
|
|
2014-05-21 10:51:16 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief SetGrowth set value of growth
|
2014-06-01 12:18:55 +02:00
|
|
|
* @param height value of height
|
2014-05-21 10:51:16 +02:00
|
|
|
*/
|
2014-03-11 21:19:13 +01:00
|
|
|
inline void VContainer::SetHeight(qreal height)
|
2014-02-26 09:18:59 +01:00
|
|
|
{
|
2014-03-11 21:19:13 +01:00
|
|
|
_height = height;
|
2014-02-26 09:18:59 +01:00
|
|
|
}
|
|
|
|
|
2014-05-21 10:51:16 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-03-11 21:19:13 +01:00
|
|
|
inline void VContainer::SetHeightName(const QString &name)
|
2014-02-26 09:18:59 +01:00
|
|
|
{
|
2014-03-11 21:19:13 +01:00
|
|
|
heightName = name;
|
2014-02-26 09:18:59 +01:00
|
|
|
}
|
|
|
|
|
2014-05-21 10:51:16 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief size return size
|
|
|
|
* @return size in mm
|
|
|
|
*/
|
2014-03-11 21:19:13 +01:00
|
|
|
inline qreal VContainer::size() const
|
2014-02-26 09:18:59 +01:00
|
|
|
{
|
2014-03-11 21:19:13 +01:00
|
|
|
return _size;
|
|
|
|
}
|
|
|
|
|
2014-05-21 10:51:16 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-03-11 21:19:13 +01:00
|
|
|
inline QString VContainer::SizeName() const
|
|
|
|
{
|
|
|
|
return sizeName;
|
|
|
|
}
|
|
|
|
|
2014-05-21 10:51:16 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief height return height
|
|
|
|
* @return height in pattern units
|
|
|
|
*/
|
2014-03-11 21:19:13 +01:00
|
|
|
inline qreal VContainer::height() const
|
|
|
|
{
|
|
|
|
return _height;
|
|
|
|
}
|
|
|
|
|
2014-05-21 10:51:16 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-03-11 21:19:13 +01:00
|
|
|
inline QString VContainer::HeightName() const
|
|
|
|
{
|
|
|
|
return heightName;
|
2014-02-26 09:18:59 +01:00
|
|
|
}
|
|
|
|
|
2014-05-21 10:51:16 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief data container with datagObjects return container of gObjects
|
|
|
|
* @return pointer on container of gObjects
|
|
|
|
*/
|
2014-02-26 09:18:59 +01:00
|
|
|
inline const QHash<quint32, VGObject *> *VContainer::DataGObjects() const
|
|
|
|
{
|
|
|
|
return &gObjects;
|
|
|
|
}
|
|
|
|
|
2014-05-21 10:51:16 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief data container with dataDetails return container of details
|
|
|
|
* @return pointer on container of details
|
|
|
|
*/
|
2014-02-26 09:18:59 +01:00
|
|
|
inline const QHash<quint32, VDetail> *VContainer::DataDetails() const
|
|
|
|
{
|
|
|
|
return &details;
|
|
|
|
}
|
|
|
|
|
2014-07-29 13:28:18 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline const QHash<QString, VInternalVariable *> *VContainer::DataVariables() const
|
|
|
|
{
|
|
|
|
return &variables;
|
|
|
|
}
|
|
|
|
|
2013-07-13 12:51:31 +02:00
|
|
|
#endif // VCONTAINER_H
|