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
|
|
|
|
** This source code is part of the Valentine project, a pattern making
|
|
|
|
** 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
|
|
|
#include "vcontainer.h"
|
2015-06-12 10:55:44 +02:00
|
|
|
#include "../vgeometry/varc.h"
|
|
|
|
#include "../vgeometry/vsplinepath.h"
|
2015-06-15 13:43:41 +02:00
|
|
|
#include "../vmisc/logging.h"
|
2015-10-15 11:49:15 +02:00
|
|
|
#include "../vmisc/vabstractapplication.h"
|
2015-06-11 14:40:43 +02:00
|
|
|
#include "vtranslatevars.h"
|
2015-04-01 14:51:54 +02:00
|
|
|
|
2014-06-17 11:50:11 +02:00
|
|
|
#include <QLineF>
|
|
|
|
#include <QtAlgorithms>
|
2015-04-01 14:51:54 +02:00
|
|
|
#include <QDebug>
|
2014-12-25 20:04:10 +01:00
|
|
|
|
2015-10-20 16:32:01 +02:00
|
|
|
#if defined(Q_CC_CLANG)
|
2015-10-19 15:21:06 +02:00
|
|
|
#pragma clang diagnostic push
|
|
|
|
#pragma clang diagnostic ignored "-Wmissing-prototypes"
|
2015-10-20 16:32:01 +02:00
|
|
|
#elif defined(Q_CC_INTEL)
|
|
|
|
#pragma warning( push )
|
|
|
|
#pragma warning( disable: 1418 )
|
2015-10-19 15:21:06 +02:00
|
|
|
#endif
|
|
|
|
|
2014-12-25 20:04:10 +01:00
|
|
|
Q_LOGGING_CATEGORY(vCon, "v.container")
|
2013-11-21 13:05:26 +01:00
|
|
|
|
2015-10-20 16:32:01 +02:00
|
|
|
#if defined(Q_CC_CLANG)
|
2015-10-19 15:21:06 +02:00
|
|
|
#pragma clang diagnostic pop
|
2015-10-20 16:32:01 +02:00
|
|
|
#elif defined(Q_CC_INTEL)
|
|
|
|
#pragma warning( pop )
|
2015-10-19 15:21:06 +02:00
|
|
|
#endif
|
|
|
|
|
2014-08-17 17:20:55 +02:00
|
|
|
quint32 VContainer::_id = NULL_ID;
|
2014-08-21 14:44:40 +02:00
|
|
|
qreal VContainer::_size = 50;
|
|
|
|
qreal VContainer::_height = 176;
|
2014-09-04 07:20:41 +02:00
|
|
|
QSet<const QString> VContainer::uniqueNames = QSet<const QString>();
|
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
|
|
|
|
*/
|
2015-06-11 19:36:17 +02:00
|
|
|
VContainer::VContainer(const VTranslateVars *trVars, const Unit *patternUnit)
|
|
|
|
:d(new VContainerData(trVars, patternUnit))
|
2014-08-21 14:44:40 +02:00
|
|
|
{}
|
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
|
|
|
|
*/
|
2013-11-04 21:35:15 +01:00
|
|
|
VContainer &VContainer::operator =(const VContainer &data)
|
|
|
|
{
|
2014-07-27 14:30:28 +02:00
|
|
|
if ( &data == this )
|
|
|
|
{
|
|
|
|
return *this;
|
|
|
|
}
|
2014-08-21 14:44:40 +02:00
|
|
|
d = data.d;
|
2013-08-15 22:39:00 +02:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
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)
|
2014-08-21 14:44:40 +02:00
|
|
|
:d(data.d)
|
|
|
|
{}
|
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()
|
|
|
|
{
|
2014-07-29 13:28:18 +02:00
|
|
|
ClearGObjects();
|
|
|
|
ClearVariables();
|
2013-12-30 19:59:33 +01:00
|
|
|
}
|
|
|
|
|
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
|
2014-08-21 14:44:40 +02:00
|
|
|
const QSharedPointer<VGObject> VContainer::GetGObject(quint32 id)const
|
2013-11-15 18:38:29 +01:00
|
|
|
{
|
2014-08-21 14:44:40 +02:00
|
|
|
return GetObject(d->gObjects, id);
|
2013-11-15 18:38:29 +01:00
|
|
|
}
|
|
|
|
|
2015-06-20 18:14:04 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-10-12 13:52:48 +02:00
|
|
|
const QSharedPointer<VGObject> VContainer::GetFakeGObject(quint32 id)
|
2015-06-20 18:14:04 +02:00
|
|
|
{
|
|
|
|
VGObject *obj = new VGObject();
|
|
|
|
obj->setId(id);
|
|
|
|
QSharedPointer<VGObject> pointer(obj);
|
|
|
|
return pointer;
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-05-21 10:51:16 +02:00
|
|
|
/**
|
|
|
|
* @brief GetObject return object from container
|
|
|
|
* @param obj container
|
|
|
|
* @param id id of object
|
|
|
|
* @return Object
|
|
|
|
*/
|
2013-08-13 18:48:36 +02:00
|
|
|
template <typename key, typename val>
|
2013-12-30 12:28:33 +01:00
|
|
|
const val VContainer::GetObject(const QHash<key, val> &obj, key id) const
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
|
|
|
if (obj.contains(id))
|
|
|
|
{
|
2013-08-13 18:48:36 +02:00
|
|
|
return obj.value(id);
|
2013-11-04 21:35:15 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-09-23 14:08:06 +02:00
|
|
|
throw VExceptionBadId(tr("Can't find object"), id);
|
2013-07-13 12:51:31 +02:00
|
|
|
}
|
2013-08-13 18:48:36 +02:00
|
|
|
}
|
|
|
|
|
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 GetDetail return detail by id
|
|
|
|
* @param id id of detail
|
|
|
|
* @return detail
|
2014-05-21 10:51:16 +02:00
|
|
|
*/
|
2014-07-29 13:28:18 +02:00
|
|
|
const VDetail VContainer::GetDetail(quint32 id) const
|
2013-12-29 17:48:57 +01:00
|
|
|
{
|
2014-08-21 14:44:40 +02:00
|
|
|
if (d->details.contains(id))
|
2013-12-29 17:48:57 +01:00
|
|
|
{
|
2014-08-21 14:44:40 +02:00
|
|
|
return d->details.value(id);
|
2013-12-29 17:48:57 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw VExceptionBadId(tr("Can't find object"), id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +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
|
|
|
*/
|
2014-02-25 15:40:24 +01:00
|
|
|
quint32 VContainer::AddGObject(VGObject *obj)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2014-08-21 14:44:40 +02:00
|
|
|
SCASSERT(obj != nullptr);
|
|
|
|
QSharedPointer<VGObject> pointer(obj);
|
2014-09-04 07:20:41 +02:00
|
|
|
uniqueNames.insert(obj->name());
|
2014-08-21 14:44:40 +02:00
|
|
|
return AddObject(d->gObjects, pointer);
|
2013-07-17 13:38:11 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-05-21 10:51:16 +02:00
|
|
|
/**
|
|
|
|
* @brief AddDetail add new detail to container
|
|
|
|
* @param detail new detail
|
|
|
|
* @return return id of new detail in container
|
|
|
|
*/
|
2015-10-28 15:22:36 +01:00
|
|
|
quint32 VContainer::AddDetail(const VDetail &detail)
|
2013-12-30 19:59:33 +01:00
|
|
|
{
|
2014-02-25 15:40:24 +01:00
|
|
|
quint32 id = getNextId();
|
2014-08-21 14:44:40 +02:00
|
|
|
d->details[id] = detail;
|
2013-12-30 19:59:33 +01:00
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2015-06-04 15:58:38 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
quint32 VContainer::getId()
|
|
|
|
{
|
|
|
|
return _id;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
*/
|
2014-02-25 15:40:24 +01:00
|
|
|
quint32 VContainer::getNextId()
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2016-03-19 15:54:27 +01: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.
|
|
|
|
if (_id == UINT_MAX)
|
|
|
|
{
|
|
|
|
qCritical()<<(tr("Number of free id exhausted."));
|
|
|
|
}
|
2013-09-12 16:18:31 +02:00
|
|
|
_id++;
|
2013-07-13 12:51:31 +02:00
|
|
|
return _id;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
*/
|
2014-02-25 15:40:24 +01:00
|
|
|
void VContainer::UpdateId(quint32 newId)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
|
|
|
if (newId > _id)
|
|
|
|
{
|
2013-09-12 16:18:31 +02:00
|
|
|
_id = newId;
|
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 UpdateObject update object in container
|
|
|
|
* @param obj container
|
|
|
|
* @param id id of existing object
|
|
|
|
* @param point object
|
|
|
|
*/
|
2013-08-13 18:48:36 +02:00
|
|
|
template <typename val>
|
2014-02-25 15:40:24 +01:00
|
|
|
void VContainer::UpdateObject(QHash<quint32, val> &obj, const quint32 &id, val point)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2015-10-28 15:22:36 +01:00
|
|
|
Q_ASSERT_X(id != NULL_ID, Q_FUNC_INFO, "id == 0"); //-V654 //-V712
|
2014-08-21 14:44:40 +02:00
|
|
|
SCASSERT(point.isNull() == false);
|
2013-12-31 09:44:54 +01:00
|
|
|
point->setId(id);
|
2014-08-21 14:44:40 +02:00
|
|
|
if (d->gObjects.contains(id))
|
2014-01-02 16:50:01 +01:00
|
|
|
{
|
2014-08-21 14:44:40 +02:00
|
|
|
d->gObjects[id].clear();
|
2014-01-02 16:50:01 +01:00
|
|
|
}
|
2013-08-13 18:48:36 +02:00
|
|
|
obj[id] = point;
|
|
|
|
UpdateId(id);
|
|
|
|
}
|
|
|
|
|
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.");
|
2014-08-17 17:20:55 +02:00
|
|
|
_id = NULL_ID;
|
2014-07-29 13:28:18 +02:00
|
|
|
|
2014-08-21 14:44:40 +02:00
|
|
|
d->details.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.");
|
|
|
|
_id = NULL_ID;
|
|
|
|
|
|
|
|
d->details.clear();
|
|
|
|
ClearVariables(VarType::Increment);
|
|
|
|
ClearVariables(VarType::ArcLength);
|
|
|
|
ClearVariables(VarType::LineAngle);
|
|
|
|
ClearVariables(VarType::LineLength);
|
|
|
|
ClearVariables(VarType::SplineLength);
|
|
|
|
ClearVariables(VarType::ArcRadius);
|
|
|
|
ClearVariables(VarType::ArcAngle);
|
|
|
|
ClearVariables(VarType::SplineAngle);
|
|
|
|
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
|
|
|
{
|
2014-08-21 14:44:40 +02:00
|
|
|
QHash<quint32, QSharedPointer<VGObject> >::iterator i;
|
2015-10-28 15:22:36 +01:00
|
|
|
for (i = d->gObjects.begin(); i != d->gObjects.end(); ++i) //-V807
|
2014-08-21 14:44:40 +02:00
|
|
|
{
|
|
|
|
i.value().clear();
|
|
|
|
}
|
|
|
|
d->gObjects.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()
|
|
|
|
{
|
2015-10-28 15:22:36 +01:00
|
|
|
if (not d->gObjects.isEmpty()) //-V807
|
2014-01-02 16:50:01 +01:00
|
|
|
{
|
2014-08-21 14:44:40 +02:00
|
|
|
QVector<quint32> keys;
|
|
|
|
QHash<quint32, QSharedPointer<VGObject> >::iterator i;
|
|
|
|
for (i = d->gObjects.begin(); i != d->gObjects.end(); ++i)
|
2014-01-02 16:50:01 +01:00
|
|
|
{
|
2014-06-12 09:22:29 +02:00
|
|
|
if (i.value()->getMode() == Draw::Calculation)
|
2014-01-02 16:50:01 +01:00
|
|
|
{
|
2014-08-21 14:44:40 +02:00
|
|
|
i.value().clear();
|
|
|
|
keys.append(i.key());
|
|
|
|
}
|
|
|
|
}
|
2015-03-31 12:39:10 +02:00
|
|
|
// We can't delete objects in previous loop it will destroy the iterator.
|
|
|
|
if (not keys.isEmpty())
|
2014-08-21 14:44:40 +02:00
|
|
|
{
|
|
|
|
for (int i = 0; i < keys.size(); ++i)
|
|
|
|
{
|
|
|
|
d->gObjects.remove(keys.at(i));
|
2014-01-02 16:50:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-29 13:28:18 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VContainer::ClearVariables(const VarType &type)
|
|
|
|
{
|
2015-10-28 15:22:36 +01:00
|
|
|
if (d->variables.size()>0) //-V807
|
2014-07-29 13:28:18 +02:00
|
|
|
{
|
|
|
|
if (type == VarType::Unknown)
|
|
|
|
{
|
2014-08-21 14:44:40 +02:00
|
|
|
QHash<QString, QSharedPointer<VInternalVariable> >::iterator i;
|
|
|
|
for (i = d->variables.begin(); i != d->variables.end(); ++i)
|
|
|
|
{
|
|
|
|
i.value().clear();
|
|
|
|
}
|
|
|
|
d->variables.clear();
|
2014-07-29 13:28:18 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-08-21 14:44:40 +02:00
|
|
|
QVector<QString> keys;
|
|
|
|
QHash<QString, QSharedPointer<VInternalVariable> >::iterator i;
|
|
|
|
for (i = d->variables.begin(); i != d->variables.end(); ++i)
|
2014-07-29 13:28:18 +02:00
|
|
|
{
|
|
|
|
if (i.value()->GetType() == type)
|
|
|
|
{
|
2014-08-21 14:44:40 +02:00
|
|
|
i.value().clear();
|
|
|
|
keys.append(i.key());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (keys.size()>0)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < keys.size(); ++i)
|
|
|
|
{
|
|
|
|
d->variables.remove(keys.at(i));
|
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
|
|
|
|
2015-06-12 10:55:44 +02:00
|
|
|
VLengthLine *length = new VLengthLine(first.data(), firstPointId, second.data(), secondPointId, *GetPatternUnit());
|
2014-07-29 13:28:18 +02:00
|
|
|
AddVariable(length->GetName(), length);
|
|
|
|
|
2014-08-21 14:44:40 +02:00
|
|
|
VLineAngle *angle = new VLineAngle(first.data(), firstPointId, second.data(), secondPointId);
|
2014-07-29 13:28:18 +02:00
|
|
|
AddVariable(angle->GetName(), angle);
|
2013-07-30 15:09:34 +02:00
|
|
|
}
|
|
|
|
|
2015-05-31 11:17:09 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-06-02 15:53:19 +02:00
|
|
|
void VContainer::AddArc(const quint32 &id, const quint32 &parentId)
|
2015-05-31 11:17:09 +02:00
|
|
|
{
|
2015-06-02 15:53:19 +02:00
|
|
|
const QSharedPointer<VArc> arc = GeometricObject<VArc>(id);
|
2015-05-31 11:17:09 +02:00
|
|
|
|
2015-06-12 10:55:44 +02:00
|
|
|
VArcLength *length = new VArcLength(id, parentId, arc.data(), *GetPatternUnit());
|
2015-06-02 15:53:19 +02:00
|
|
|
AddVariable(length->GetName(), length);
|
|
|
|
|
2015-06-12 10:55:44 +02:00
|
|
|
VArcRadius *radius = new VArcRadius(id, parentId, arc.data(), *GetPatternUnit());
|
2015-05-31 11:17:09 +02:00
|
|
|
AddVariable(radius->GetName(), radius);
|
2015-06-02 15:53:19 +02:00
|
|
|
|
|
|
|
VArcAngle *startAngle = new VArcAngle(id, parentId, arc.data(), CurveAngle::StartAngle);
|
|
|
|
AddVariable(startAngle->GetName(), startAngle);
|
|
|
|
|
|
|
|
VArcAngle *endAngle = new VArcAngle(id, parentId, arc.data(), CurveAngle::EndAngle);
|
|
|
|
AddVariable(endAngle->GetName(), endAngle);
|
2015-05-31 11:17:09 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-05-21 10:51:16 +02:00
|
|
|
/**
|
|
|
|
* @brief AddObject add object to container
|
|
|
|
* @param obj container
|
|
|
|
* @param value object
|
|
|
|
* @return id of object in container
|
|
|
|
*/
|
2013-10-27 11:22:44 +01:00
|
|
|
template <typename key, typename val>
|
2014-02-25 15:40:24 +01:00
|
|
|
quint32 VContainer::AddObject(QHash<key, val> &obj, val value)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2014-05-30 21:56:05 +02:00
|
|
|
SCASSERT(value != nullptr);
|
2015-03-31 12:39:10 +02:00
|
|
|
const quint32 id = getNextId();
|
2013-12-29 17:48:57 +01:00
|
|
|
value->setId(id);
|
2013-10-27 11:22:44 +01:00
|
|
|
obj[id] = value;
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-05-21 10:51:16 +02:00
|
|
|
/**
|
2014-06-02 09:43:27 +02:00
|
|
|
* @brief UpdateGObject update GObject by id
|
|
|
|
* @param id id of existing GObject
|
|
|
|
* @param obj object
|
2014-05-21 10:51:16 +02:00
|
|
|
*/
|
2014-02-25 15:40:24 +01:00
|
|
|
void VContainer::UpdateGObject(quint32 id, VGObject* obj)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2014-07-11 16:22:00 +02:00
|
|
|
SCASSERT(obj != nullptr);
|
2014-08-21 14:44:40 +02:00
|
|
|
QSharedPointer<VGObject> pointer(obj);
|
|
|
|
UpdateObject(d->gObjects, id, pointer);
|
2014-09-04 07:20:41 +02:00
|
|
|
uniqueNames.insert(obj->name());
|
2013-10-27 11:22:44 +01:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-05-21 10:51:16 +02:00
|
|
|
/**
|
|
|
|
* @brief UpdateDetail update detail by id
|
|
|
|
* @param id id of existing detail
|
|
|
|
* @param detail detail
|
|
|
|
*/
|
2014-02-25 15:40:24 +01:00
|
|
|
void VContainer::UpdateDetail(quint32 id, const VDetail &detail)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2015-10-28 15:22:36 +01:00
|
|
|
Q_ASSERT_X(id != NULL_ID, Q_FUNC_INFO, "id == 0"); //-V654 //-V712
|
2014-08-21 14:44:40 +02:00
|
|
|
d->details[id] = detail;
|
2013-12-30 19:59:33 +01:00
|
|
|
UpdateId(id);
|
2013-10-27 11:22:44 +01:00
|
|
|
}
|
|
|
|
|
2014-07-29 13:28:18 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-06-11 14:40:43 +02:00
|
|
|
qreal VContainer::GetTableValue(const QString &name, MeasurementsType patternType) const
|
2014-07-29 13:28:18 +02:00
|
|
|
{
|
2014-08-21 14:44:40 +02:00
|
|
|
QSharedPointer<VVariable> m = GetVariable<VVariable>(name);
|
2015-06-11 14:40:43 +02:00
|
|
|
if (patternType == MeasurementsType::Standard)
|
2014-07-29 13:28:18 +02:00
|
|
|
{
|
2015-06-12 10:55:44 +02:00
|
|
|
m->SetValue(size(), height(), *GetPatternUnit());
|
2014-07-29 13:28:18 +02:00
|
|
|
}
|
|
|
|
return *m->GetValue();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-08-21 14:44:40 +02:00
|
|
|
const QMap<QString, QSharedPointer<VMeasurement> > VContainer::DataMeasurements() const
|
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
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-08-21 14:44:40 +02:00
|
|
|
const QMap<QString, QSharedPointer<VIncrement> > VContainer::DataIncrements() const
|
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
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-08-21 14:44:40 +02:00
|
|
|
const QMap<QString, QSharedPointer<VLengthLine> > VContainer::DataLengthLines() const
|
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
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-08-21 14:44:40 +02:00
|
|
|
const QMap<QString, QSharedPointer<VSplineLength> > VContainer::DataLengthSplines() const
|
2014-07-29 13:28:18 +02:00
|
|
|
{
|
2014-08-15 19:27:30 +02:00
|
|
|
return DataVar<VSplineLength>(VarType::SplineLength);
|
2014-07-29 13:28:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-08-21 14:44:40 +02:00
|
|
|
const QMap<QString, QSharedPointer<VArcLength> > VContainer::DataLengthArcs() const
|
2014-07-29 13:28:18 +02:00
|
|
|
{
|
2014-08-15 19:27:30 +02:00
|
|
|
return DataVar<VArcLength>(VarType::ArcLength);
|
2014-07-29 13:28:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-08-21 14:44:40 +02:00
|
|
|
const QMap<QString, QSharedPointer<VLineAngle> > VContainer::DataAngleLines() const
|
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
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
const QMap<QString, QSharedPointer<VArcRadius> > VContainer::DataRadiusesArcs() const
|
|
|
|
{
|
|
|
|
return DataVar<VArcRadius>(VarType::ArcRadius);
|
|
|
|
}
|
|
|
|
|
2015-06-02 15:53:19 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
const QMap<QString, QSharedPointer<VArcAngle> > VContainer::DataAnglesArcs() const
|
|
|
|
{
|
|
|
|
return DataVar<VArcAngle>(VarType::ArcAngle);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-06-18 19:23:24 +02:00
|
|
|
const QMap<QString, QSharedPointer<VSplineAngle> > VContainer::DataAnglesCurves() const
|
2015-06-02 15:53:19 +02:00
|
|
|
{
|
2015-06-18 19:23:24 +02:00
|
|
|
return DataVar<VSplineAngle>(VarType::SplineAngle);
|
2015-06-02 15:53:19 +02:00
|
|
|
}
|
|
|
|
|
2015-10-15 11:49:15 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-10-15 12:07:43 +02:00
|
|
|
const QHash<QString, qreal *> VContainer::PlainVariables() const
|
2015-10-15 11:49:15 +02:00
|
|
|
{
|
2015-10-15 12:07:43 +02:00
|
|
|
QHash<QString, qreal *> vars;
|
2015-10-15 11:49:15 +02:00
|
|
|
|
2015-11-11 19:52:25 +01:00
|
|
|
auto i = d->variables.constBegin();
|
2015-10-15 11:49:15 +02:00
|
|
|
while (i != d->variables.constEnd())
|
|
|
|
{
|
|
|
|
QSharedPointer<VInternalVariable> var = i.value();
|
|
|
|
if ((qApp->patternType() == MeasurementsType::Standard) &&
|
|
|
|
(var->GetType() == VarType::Measurement || var->GetType() == VarType::Increment))
|
|
|
|
{
|
|
|
|
QSharedPointer<VVariable> m = GetVariable<VVariable>(i.key());
|
|
|
|
m->SetValue(size(), height(), qApp->patternUnit());
|
|
|
|
}
|
|
|
|
vars.insert(i.key(), var->GetValue());
|
2015-10-15 12:07:43 +02:00
|
|
|
|
|
|
|
++i;
|
2015-10-15 11:49:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return vars;
|
|
|
|
}
|
|
|
|
|
2014-09-04 07:20:41 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool VContainer::IsUnique(const QString &name)
|
|
|
|
{
|
2014-10-02 11:46:24 +02:00
|
|
|
return (!uniqueNames.contains(name) && !builInFunctions.contains(name));
|
2014-09-04 07:20:41 +02:00
|
|
|
}
|
|
|
|
|
2015-06-11 19:36:17 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
const Unit *VContainer::GetPatternUnit() const
|
|
|
|
{
|
|
|
|
return d->patternUnit;
|
|
|
|
}
|
|
|
|
|
2015-08-17 14:36:55 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
const VTranslateVars *VContainer::GetTrVars() const
|
|
|
|
{
|
|
|
|
return d->trVars;
|
|
|
|
}
|
|
|
|
|
2014-07-29 13:28:18 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
2014-07-30 11:51:22 +02:00
|
|
|
* @brief VariableExist check if exist variable this same name.
|
2014-07-29 13:28:18 +02:00
|
|
|
* @param name name of row
|
|
|
|
* @return true if contains
|
|
|
|
*/
|
2015-04-15 14:44:57 +02:00
|
|
|
// cppcheck-suppress unusedFunction
|
2014-07-30 11:51:22 +02:00
|
|
|
bool VContainer::VariableExist(const QString &name)
|
2014-07-29 13:28:18 +02:00
|
|
|
{
|
2014-08-21 14:44:40 +02:00
|
|
|
return d->variables.contains(name);
|
2014-07-29 13:28:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
template <typename T>
|
2014-08-21 14:44:40 +02:00
|
|
|
const QMap<QString, QSharedPointer<T> > VContainer::DataVar(const VarType &type) const
|
2014-07-29 13:28:18 +02:00
|
|
|
{
|
2014-08-21 14:44:40 +02:00
|
|
|
QMap<QString, QSharedPointer<T> > map;
|
2014-07-29 13:28:18 +02:00
|
|
|
//Sorting QHash by id
|
2014-08-21 14:44:40 +02:00
|
|
|
QHash<QString, QSharedPointer<VInternalVariable> >::const_iterator i;
|
|
|
|
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
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-04-15 14:44:57 +02:00
|
|
|
// cppcheck-suppress unusedFunction
|
2014-08-21 14:44:40 +02:00
|
|
|
void VContainer::ClearDetails()
|
|
|
|
{
|
|
|
|
d->details.clear();
|
|
|
|
}
|
|
|
|
|
2014-09-04 07:20:41 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VContainer::ClearUniqueNames()
|
|
|
|
{
|
|
|
|
uniqueNames.clear();
|
|
|
|
}
|
|
|
|
|
2014-08-21 14:44:40 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief SetSize set value of size
|
|
|
|
* @param size value of size
|
|
|
|
*/
|
|
|
|
void VContainer::SetSize(qreal size)
|
|
|
|
{
|
|
|
|
_size = size;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief SetGrowth set value of growth
|
|
|
|
* @param height value of height
|
|
|
|
*/
|
|
|
|
void VContainer::SetHeight(qreal height)
|
|
|
|
{
|
|
|
|
_height = height;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief size return size
|
|
|
|
* @return size in mm
|
|
|
|
*/
|
2014-09-11 19:15:07 +02:00
|
|
|
qreal VContainer::size()
|
2014-08-21 14:44:40 +02:00
|
|
|
{
|
|
|
|
return _size;
|
|
|
|
}
|
|
|
|
|
2015-10-15 11:49:15 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-10-15 12:07:43 +02:00
|
|
|
qreal *VContainer::rsize()
|
2015-10-15 11:49:15 +02:00
|
|
|
{
|
|
|
|
return &_size;
|
|
|
|
}
|
|
|
|
|
2014-08-21 14:44:40 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief height return height
|
|
|
|
* @return height in pattern units
|
|
|
|
*/
|
2014-09-11 19:15:07 +02:00
|
|
|
qreal VContainer::height()
|
2014-08-21 14:44:40 +02:00
|
|
|
{
|
|
|
|
return _height;
|
|
|
|
}
|
|
|
|
|
2015-10-15 11:49:15 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-10-15 12:07:43 +02:00
|
|
|
qreal *VContainer::rheight()
|
2015-10-15 11:49:15 +02:00
|
|
|
{
|
|
|
|
return &_height;
|
|
|
|
}
|
|
|
|
|
2014-08-21 14:44:40 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief data container with datagObjects return container of gObjects
|
|
|
|
* @return pointer on container of gObjects
|
|
|
|
*/
|
|
|
|
const QHash<quint32, QSharedPointer<VGObject> > *VContainer::DataGObjects() const
|
|
|
|
{
|
|
|
|
return &d->gObjects;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief data container with dataDetails return container of details
|
|
|
|
* @return pointer on container of details
|
|
|
|
*/
|
|
|
|
const QHash<quint32, VDetail> *VContainer::DataDetails() const
|
|
|
|
{
|
|
|
|
return &d->details;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
const QHash<QString, QSharedPointer<VInternalVariable> > *VContainer::DataVariables() const
|
|
|
|
{
|
|
|
|
return &d->variables;
|
|
|
|
}
|
2014-09-11 18:52:02 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VContainerData::~VContainerData()
|
|
|
|
{}
|