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"
|
2016-08-08 13:44:49 +02:00
|
|
|
|
|
|
|
#include <limits.h>
|
|
|
|
#include <QVector>
|
|
|
|
#include <QtDebug>
|
|
|
|
|
|
|
|
#include "../ifc/exception/vexception.h"
|
|
|
|
#include "../vgeometry/vabstractcubicbezierpath.h"
|
|
|
|
#include "../vgeometry/vabstractcurve.h"
|
|
|
|
#include "../vgeometry/vgeometrydef.h"
|
|
|
|
#include "../vgeometry/vgobject.h"
|
|
|
|
#include "../vgeometry/vpointf.h"
|
|
|
|
#include "../vgeometry/vspline.h"
|
2015-06-12 10:55:44 +02:00
|
|
|
#include "../vgeometry/varc.h"
|
2016-12-17 02:40:17 +01:00
|
|
|
#include "../vgeometry/vellipticalarc.h"
|
2016-08-09 15:55:46 +02:00
|
|
|
#include "../vmisc/diagnostic.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"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "variables/varcradius.h"
|
|
|
|
#include "variables/vcurveangle.h"
|
|
|
|
#include "variables/vcurvelength.h"
|
2016-09-24 19:44:06 +02:00
|
|
|
#include "variables/vcurveclength.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "variables/vincrement.h"
|
|
|
|
#include "variables/vlineangle.h"
|
|
|
|
#include "variables/vlinelength.h"
|
|
|
|
#include "variables/vmeasurement.h"
|
|
|
|
#include "variables/vvariable.h"
|
2015-06-11 14:40:43 +02:00
|
|
|
#include "vtranslatevars.h"
|
2015-04-01 14:51:54 +02:00
|
|
|
|
2016-08-06 20:42:40 +02:00
|
|
|
QT_WARNING_PUSH
|
|
|
|
QT_WARNING_DISABLE_CLANG("-Wmissing-prototypes")
|
|
|
|
QT_WARNING_DISABLE_INTEL(1418)
|
2015-10-19 15:21:06 +02:00
|
|
|
|
2014-12-25 20:04:10 +01:00
|
|
|
Q_LOGGING_CATEGORY(vCon, "v.container")
|
2013-11-21 13:05:26 +01:00
|
|
|
|
2016-08-06 20:42:40 +02:00
|
|
|
QT_WARNING_POP
|
2015-10-19 15:21:06 +02:00
|
|
|
|
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;
|
2016-05-18 14:35:07 +02:00
|
|
|
QSet<QString> VContainer::uniqueNames = QSet<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
|
|
|
}
|
|
|
|
|
2016-11-08 11:52:07 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VPiece VContainer::GetPiece(quint32 id) const
|
|
|
|
{
|
|
|
|
if (d->pieces->contains(id))
|
|
|
|
{
|
|
|
|
return d->pieces->value(id);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw VExceptionBadId(tr("Can't find object"), id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-24 20:30:26 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VPiecePath VContainer::GetPiecePath(quint32 id) const
|
|
|
|
{
|
|
|
|
if (d->piecePaths->contains(id))
|
|
|
|
{
|
|
|
|
return d->piecePaths->value(id);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw VExceptionBadId(tr("Can't find object"), id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
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
|
|
|
{
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(obj != nullptr)
|
2014-08-21 14:44:40 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-11-08 11:52:07 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
quint32 VContainer::AddPiece(const VPiece &detail)
|
|
|
|
{
|
|
|
|
const quint32 id = getNextId();
|
|
|
|
d->pieces->insert(id, detail);
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2016-11-24 20:30:26 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
quint32 VContainer::AddPiecePath(const VPiecePath &path)
|
|
|
|
{
|
|
|
|
const quint32 id = getNextId();
|
|
|
|
d->piecePaths->insert(id, path);
|
|
|
|
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
|
2016-12-20 19:57:20 +01: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
|
|
|
|
2017-01-18 09:15:51 +01:00
|
|
|
d->pieces->clear();
|
|
|
|
d->piecePaths->clear();
|
2014-07-29 13:28:18 +02:00
|
|
|
ClearVariables();
|
2014-01-02 16:50:01 +01:00
|
|
|
ClearGObjects();
|
2014-09-04 07:20:41 +02:00
|
|
|
ClearUniqueNames();
|
2013-07-17 13:38:11 +02:00
|
|
|
}
|
|
|
|
|
2015-08-26 20:14:47 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VContainer::ClearForFullParse()
|
|
|
|
{
|
|
|
|
qCDebug(vCon, "Clearing container data for full parse.");
|
|
|
|
_id = NULL_ID;
|
|
|
|
|
2016-11-16 08:15:16 +01:00
|
|
|
d->pieces->clear();
|
2016-11-24 20:30:26 +01:00
|
|
|
d->piecePaths->clear();
|
2015-08-26 20:14:47 +02:00
|
|
|
ClearVariables(VarType::Increment);
|
|
|
|
ClearVariables(VarType::LineAngle);
|
|
|
|
ClearVariables(VarType::LineLength);
|
2016-04-01 21:34:57 +02:00
|
|
|
ClearVariables(VarType::CurveLength);
|
2016-09-24 19:44:06 +02:00
|
|
|
ClearVariables(VarType::CurveCLength);
|
2015-08-26 20:14:47 +02:00
|
|
|
ClearVariables(VarType::ArcRadius);
|
2016-04-01 21:34:57 +02:00
|
|
|
ClearVariables(VarType::CurveAngle);
|
2015-08-26 20:14:47 +02:00
|
|
|
ClearGObjects();
|
|
|
|
ClearUniqueNames();
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-05-21 10:51:16 +02:00
|
|
|
/**
|
|
|
|
* @brief ClearObject points, splines, arcs, spline paths will be cleared.
|
|
|
|
*/
|
2014-01-02 16:50:01 +01:00
|
|
|
void VContainer::ClearGObjects()
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2014-08-21 14:44:40 +02:00
|
|
|
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
|
|
|
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
|
|
|
keys.append(i.key());
|
|
|
|
}
|
|
|
|
}
|
2017-08-04 19:46:11 +02:00
|
|
|
|
|
|
|
for (int i = 0; i < keys.size(); ++i)
|
2014-08-21 14:44:40 +02:00
|
|
|
{
|
2017-08-04 19:46:11 +02:00
|
|
|
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
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-12-20 12:04:56 +01:00
|
|
|
void VContainer::AddArc(const QSharedPointer<VAbstractCurve> &arc, const quint32 &id, const quint32 &parentId)
|
2015-05-31 11:17:09 +02:00
|
|
|
{
|
2016-04-01 21:34:57 +02:00
|
|
|
AddCurve(arc, id, parentId);
|
2015-06-02 15:53:19 +02:00
|
|
|
|
2016-12-20 12:04:56 +01:00
|
|
|
if (arc->getType() == GOType::Arc)
|
|
|
|
{
|
|
|
|
const QSharedPointer<VArc> casted = arc.staticCast<VArc>();
|
2016-04-01 21:34:57 +02:00
|
|
|
|
2016-12-20 12:04:56 +01:00
|
|
|
VArcRadius *radius = new VArcRadius(id, parentId, casted.data(), *GetPatternUnit());
|
|
|
|
AddVariable(radius->GetName(), radius);
|
|
|
|
}
|
|
|
|
else if (arc->getType() == GOType::EllipticalArc)
|
|
|
|
{
|
|
|
|
const QSharedPointer<VEllipticalArc> casted = arc.staticCast<VEllipticalArc>();
|
2016-12-17 02:40:17 +01:00
|
|
|
|
2017-02-26 08:00:40 +01:00
|
|
|
VArcRadius *radius1 = new VArcRadius(id, parentId, casted.data(), 1, *GetPatternUnit());
|
2016-12-20 12:04:56 +01:00
|
|
|
AddVariable(radius1->GetName(), radius1);
|
2016-12-17 02:40:17 +01:00
|
|
|
|
2017-02-26 08:00:40 +01:00
|
|
|
VArcRadius *radius2 = new VArcRadius(id, parentId, casted.data(), 2, *GetPatternUnit());
|
2016-12-20 12:04:56 +01:00
|
|
|
AddVariable(radius2->GetName(), radius2);
|
|
|
|
}
|
2016-04-01 21:34:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-04-01 23:15:04 +02:00
|
|
|
void VContainer::AddCurve(const QSharedPointer<VAbstractCurve> &curve, const quint32 &id, quint32 parentId)
|
2016-04-01 21:34:57 +02:00
|
|
|
{
|
|
|
|
const GOType curveType = curve->getType();
|
|
|
|
if (curveType != GOType::Spline && curveType != GOType::SplinePath &&
|
|
|
|
curveType != GOType::CubicBezier && curveType != GOType::CubicBezierPath &&
|
2016-12-17 02:40:17 +01:00
|
|
|
curveType != GOType::Arc && curveType != GOType::EllipticalArc)
|
2016-04-01 21:34:57 +02:00
|
|
|
{
|
|
|
|
throw VException(tr("Can't create a curve with type '%1'").arg(static_cast<int>(curveType)));
|
|
|
|
}
|
|
|
|
|
|
|
|
VCurveLength *length = new VCurveLength(id, parentId, curve.data(), *GetPatternUnit());
|
|
|
|
AddVariable(length->GetName(), length);
|
2015-06-02 15:53:19 +02:00
|
|
|
|
2016-04-01 21:34:57 +02:00
|
|
|
VCurveAngle *startAngle = new VCurveAngle(id, parentId, curve.data(), CurveAngle::StartAngle);
|
2015-06-02 15:53:19 +02:00
|
|
|
AddVariable(startAngle->GetName(), startAngle);
|
|
|
|
|
2016-04-01 21:34:57 +02:00
|
|
|
VCurveAngle *endAngle = new VCurveAngle(id, parentId, curve.data(), CurveAngle::EndAngle);
|
2015-06-02 15:53:19 +02:00
|
|
|
AddVariable(endAngle->GetName(), endAngle);
|
2015-05-31 11:17:09 +02:00
|
|
|
}
|
|
|
|
|
2016-09-24 19:44:06 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VContainer::AddSpline(const QSharedPointer<VAbstractBezier> &curve, quint32 id, quint32 parentId)
|
|
|
|
{
|
|
|
|
AddCurve(curve, id, parentId);
|
|
|
|
|
|
|
|
VCurveCLength *c1Length = new VCurveCLength(id, parentId, curve.data(), CurveCLength::C1, *GetPatternUnit());
|
|
|
|
AddVariable(c1Length->GetName(), c1Length);
|
|
|
|
|
|
|
|
VCurveCLength *c2Length = new VCurveCLength(id, parentId, curve.data(), CurveCLength::C2, *GetPatternUnit());
|
|
|
|
AddVariable(c2Length->GetName(), c2Length);
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-04-01 23:15:04 +02:00
|
|
|
void VContainer::AddCurveWithSegments(const QSharedPointer<VAbstractCubicBezierPath> &curve, const quint32 &id,
|
|
|
|
quint32 parentId)
|
|
|
|
{
|
2016-09-24 19:44:06 +02:00
|
|
|
AddSpline(curve, id, parentId);
|
2016-04-01 23:15:04 +02:00
|
|
|
|
|
|
|
for (qint32 i = 1; i <= curve->CountSubSpl(); ++i)
|
|
|
|
{
|
|
|
|
const VSpline spl = curve->GetSpline(i);
|
|
|
|
|
|
|
|
VCurveLength *length = new VCurveLength(id, parentId, curve->name(), spl, *GetPatternUnit(), i);
|
|
|
|
AddVariable(length->GetName(), length);
|
|
|
|
|
|
|
|
VCurveAngle *startAngle = new VCurveAngle(id, parentId, curve->name(), spl, CurveAngle::StartAngle, i);
|
|
|
|
AddVariable(startAngle->GetName(), startAngle);
|
|
|
|
|
|
|
|
VCurveAngle *endAngle = new VCurveAngle(id, parentId, curve->name(), spl, CurveAngle::EndAngle, i);
|
|
|
|
AddVariable(endAngle->GetName(), endAngle);
|
2016-09-24 19:44:06 +02:00
|
|
|
|
|
|
|
VCurveCLength *c1Length = new VCurveCLength(id, parentId, curve->name(), spl, CurveCLength::C1,
|
|
|
|
*GetPatternUnit(), i);
|
|
|
|
AddVariable(c1Length->GetName(), c1Length);
|
|
|
|
|
|
|
|
VCurveCLength *c2Length = new VCurveCLength(id, parentId, curve->name(), spl, CurveCLength::C2,
|
|
|
|
*GetPatternUnit(), i);
|
|
|
|
AddVariable(c2Length->GetName(), c2Length);
|
2016-04-01 23:15:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-23 19:20:21 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VContainer::RemoveVariable(const QString &name)
|
|
|
|
{
|
|
|
|
d->variables.remove(name);
|
|
|
|
}
|
|
|
|
|
2017-01-18 11:22:02 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VContainer::RemovePiece(quint32 id)
|
|
|
|
{
|
|
|
|
d->pieces->remove(id);
|
|
|
|
}
|
|
|
|
|
2016-04-01 23:15:04 +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
|
|
|
{
|
2016-12-20 19:57:20 +01: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
|
|
|
{
|
2016-12-20 19:57:20 +01: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
|
|
|
}
|
|
|
|
|
2016-11-08 11:52:07 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VContainer::UpdatePiece(quint32 id, const VPiece &detail)
|
|
|
|
{
|
|
|
|
Q_ASSERT_X(id != NULL_ID, Q_FUNC_INFO, "id == 0"); //-V654 //-V712
|
|
|
|
d->pieces->insert(id, detail);
|
|
|
|
UpdateId(id);
|
|
|
|
}
|
|
|
|
|
2016-11-24 20:30:26 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VContainer::UpdatePiecePath(quint32 id, const VPiecePath &path)
|
|
|
|
{
|
|
|
|
Q_ASSERT_X(id != NULL_ID, Q_FUNC_INFO, "id == 0"); //-V654 //-V712
|
|
|
|
d->piecePaths->insert(id, path);
|
|
|
|
UpdateId(id);
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-05-21 10:51:16 +02:00
|
|
|
/**
|
2014-07-29 13:28:18 +02:00
|
|
|
* @brief RemoveIncrement remove increment by name from increment table
|
|
|
|
* @param name name of existing increment
|
2014-05-21 10:51:16 +02:00
|
|
|
*/
|
2014-07-29 13:28:18 +02:00
|
|
|
void VContainer::RemoveIncrement(const QString &name)
|
|
|
|
{
|
2014-08-21 14:44:40 +02:00
|
|
|
d->variables[name].clear();
|
|
|
|
d->variables.remove(name);
|
2014-07-29 13:28:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
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
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-04-01 21:34:57 +02:00
|
|
|
const QMap<QString, QSharedPointer<VCurveLength> > VContainer::DataLengthCurves() const
|
2014-07-29 13:28:18 +02:00
|
|
|
{
|
2016-04-01 21:34:57 +02:00
|
|
|
return DataVar<VCurveLength>(VarType::CurveLength);
|
2014-07-29 13:28:18 +02:00
|
|
|
}
|
|
|
|
|
2016-09-24 19:44:06 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
const QMap<QString, QSharedPointer<VCurveCLength> > VContainer::DataCurvesCLength() const
|
|
|
|
{
|
|
|
|
return DataVar<VCurveCLength>(VarType::CurveCLength);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-04-01 21:34:57 +02:00
|
|
|
const QMap<QString, QSharedPointer<VCurveAngle> > VContainer::DataAnglesCurves() const
|
2015-06-02 15:53:19 +02:00
|
|
|
{
|
2016-04-01 21:34:57 +02:00
|
|
|
return DataVar<VCurveAngle>(VarType::CurveAngle);
|
2015-06-02 15:53:19 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-05-18 14:35:07 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QStringList VContainer::AllUniqueNames()
|
|
|
|
{
|
|
|
|
QStringList names = builInFunctions;
|
|
|
|
names.append(uniqueNames.toList());
|
|
|
|
return names;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
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
|
|
|
|
2014-09-04 07:20:41 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VContainer::ClearUniqueNames()
|
|
|
|
{
|
|
|
|
uniqueNames.clear();
|
|
|
|
}
|
|
|
|
|
2017-07-23 15:52:57 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VContainer::ClearUniqueIncrementNames()
|
|
|
|
{
|
|
|
|
const QList<QString> list = uniqueNames.toList();
|
|
|
|
ClearUniqueNames();
|
|
|
|
|
|
|
|
for(int i = 0; i < list.size(); ++i)
|
|
|
|
{
|
|
|
|
if (not list.at(i).startsWith('#'))
|
|
|
|
{
|
|
|
|
uniqueNames.insert(list.at(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-11-08 11:52:07 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
const QHash<quint32, VPiece> *VContainer::DataPieces() const
|
|
|
|
{
|
|
|
|
return d->pieces.data();
|
|
|
|
}
|
|
|
|
|
2014-08-21 14:44:40 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
const QHash<QString, QSharedPointer<VInternalVariable> > *VContainer::DataVariables() const
|
|
|
|
{
|
|
|
|
return &d->variables;
|
|
|
|
}
|
2014-09-11 18:52:02 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VContainerData::~VContainerData()
|
|
|
|
{}
|