valentina/container/vcontainer.cpp

393 lines
11 KiB
C++
Raw Normal View History

2013-07-13 12:51:31 +02:00
#include "vcontainer.h"
#include <QDebug>
2013-07-17 13:38:11 +02:00
#include "../options.h"
2013-07-13 12:51:31 +02:00
VContainer::VContainer(){
_id = 0;
2013-07-17 13:38:11 +02:00
SetSize(500);
SetGrowth(1760);
2013-07-13 12:51:31 +02:00
}
VPointF VContainer::GetPoint(qint64 id) const{
if(points.contains(id)){
return points.value(id);
} else {
qCritical()<<"Не можу знайти id = "<<id<<" в таблиці.";
throw"Не можу знайти точку за id.";
}
return VPointF();
}
2013-07-17 13:38:11 +02:00
VStandartTableCell VContainer::GetStandartTableCell(const QString &name) const{
if(standartTable.contains(name)){
return standartTable.value(name);
} else {
qCritical()<<"Не можу знайти змінну за імям = "<<name<<" в таблиці.";
throw"Не можу знайти змінну в стандартній таблиці вимірів за ім'ям.";
}
return VStandartTableCell();
}
VIncrementTableRow VContainer::GetIncrementTableRow(const QString& name) const{
if(incrementTable.contains(name)){
return incrementTable.value(name);
} else {
qCritical()<<"Не можу знайти змінну за імям = "<<name<<" в таблиці.";
throw"Не можу знайти змінну в таблиці прибавок за ім'ям.";
}
return VIncrementTableRow();
}
2013-07-13 12:51:31 +02:00
qint64 VContainer::AddPoint(const VPointF& point){
qint64 id = getNextId();
points[id] = point;
return id;
}
2013-07-17 13:38:11 +02:00
void VContainer::AddStandartTableCell(const QString& name, const VStandartTableCell& cell){
standartTable[name] = cell;
}
void VContainer::AddIncrementTableRow(const QString& name, const VIncrementTableRow& cell){
incrementTable[name] = cell;
}
2013-07-13 12:51:31 +02:00
qint64 VContainer::getId(){
return _id;
}
qint64 VContainer::getNextId(){
++_id;
return _id;
}
2013-07-17 13:38:11 +02:00
void VContainer::RemoveIncrementTableRow(const QString& name){
incrementTable.remove(name);
}
2013-07-13 12:51:31 +02:00
void VContainer::UpdatePoint(qint64 id, const VPointF& point){
points[id] = point;
if(id > _id){
_id = id;
}
}
2013-08-05 10:37:56 +02:00
void VContainer::UpdateSpline(qint64 id, const VSpline &spl){
splines[id] = spl;
if(id > _id){
_id = id;
}
}
2013-08-09 08:49:34 +02:00
void VContainer::UpdateSplinePath(qint64 id, const VSplinePath &splPath){
splinePaths[id] = splPath;
if(id > _id){
_id = id;
}
}
2013-08-05 10:37:56 +02:00
void VContainer::UpdateArc(qint64 id, const VArc &arc){
arcs[id] = arc;
if(id > _id){
_id = id;
}
}
2013-07-17 13:38:11 +02:00
void VContainer::UpdateStandartTableCell(const QString& name, const VStandartTableCell& cell){
standartTable[name] = cell;
}
void VContainer::UpdateIncrementTableRow(const QString& name, const VIncrementTableRow& cell){
incrementTable[name] = cell;
}
qreal VContainer::GetValueStandartTableCell(const QString& name) const{
VStandartTableCell cell = GetStandartTableCell(name);
qreal k_size = ( ( qreal ) (size()/10) - 50.0 ) / 2;
qreal k_growth = ( ( qreal ) (growth()/10) - 176.0 ) / 6;
qreal value = cell.GetBase() + k_size*cell.GetKsize() + k_growth*cell.GetKgrowth();
return value;
}
qreal VContainer::GetValueIncrementTableRow(const QString& name) const{
VIncrementTableRow cell = GetIncrementTableRow(name);
qreal k_size = ( ( qreal ) (size()/10) - 50.0 ) / 2;
qreal k_growth = ( ( qreal ) (growth()/10) - 176.0 ) / 6;
qreal value = cell.getBase() + k_size*cell.getKsize() + k_growth*cell.getKgrowth();
return value;
}
2013-07-13 12:51:31 +02:00
void VContainer::Clear(){
_id = 0;
points.clear();
2013-07-17 13:38:11 +02:00
standartTable.clear();
incrementTable.clear();
2013-07-25 14:00:51 +02:00
lengthLines.clear();
2013-08-05 10:37:56 +02:00
splines.clear();
arcs.clear();
lengthArcs.clear();
2013-08-06 09:56:09 +02:00
lineArcs.clear();
2013-07-17 13:38:11 +02:00
}
void VContainer::ClearIncrementTable(){
incrementTable.clear();
}
2013-07-25 14:00:51 +02:00
void VContainer::ClearLengthLines(){
lengthLines.clear();
}
2013-08-05 10:37:56 +02:00
void VContainer::ClearLengthSplines(){
lengthSplines.clear();
}
void VContainer::ClearLengthArcs(){
lengthArcs.clear();
}
2013-08-06 09:56:09 +02:00
void VContainer::ClearLineArcs(){
lineArcs.clear();
}
2013-07-17 13:38:11 +02:00
void VContainer::SetSize(qint32 size){
base["Сг"] = size;
}
void VContainer::SetGrowth(qint32 growth){
base["Р"] = growth;
}
qint32 VContainer::size() const{
return base.value("Сг");
}
qint32 VContainer::growth() const{
return base.value("Р");
}
bool VContainer::IncrementTableContains(const QString& name){
return incrementTable.contains(name);
}
qreal VContainer::FindVar(const QString &name, bool *ok)const{
if(base.contains(name)){
*ok = true;
2013-07-25 14:00:51 +02:00
return base.value(name);
2013-07-17 13:38:11 +02:00
}
if(standartTable.contains(name)){
*ok = true;
2013-07-25 14:00:51 +02:00
return GetValueStandartTableCell(name);
2013-07-17 13:38:11 +02:00
}
if(incrementTable.contains(name)){
*ok = true;
2013-07-25 14:00:51 +02:00
return GetValueIncrementTableRow(name);
}
if(lengthLines.contains(name)){
*ok = true;
return lengthLines.value(name);
2013-07-17 13:38:11 +02:00
}
2013-08-06 09:56:09 +02:00
if(lengthArcs.contains(name)){
*ok = true;
return lengthArcs.value(name);
}
if(lineArcs.contains(name)){
*ok = true;
return lineArcs.value(name);
}
2013-07-17 13:38:11 +02:00
*ok = false;
return 0;
}
2013-07-25 14:00:51 +02:00
const QMap<qint64, VPointF> *VContainer::DataPoints() const{
return &points;
}
2013-07-17 13:38:11 +02:00
2013-08-05 10:37:56 +02:00
const QMap<qint64, VSpline> *VContainer::DataSplines() const{
return &splines;
}
const QMap<qint64, VArc> *VContainer::DataArcs() const{
return &arcs;
}
2013-07-25 14:00:51 +02:00
const QMap<QString, qint32> *VContainer::DataBase() const{
return &base;
}
2013-07-17 13:38:11 +02:00
2013-07-25 14:00:51 +02:00
const QMap<QString, VStandartTableCell> *VContainer::DataStandartTable() const{
return &standartTable;
}
2013-07-17 13:38:11 +02:00
2013-07-25 14:00:51 +02:00
const QMap<QString, VIncrementTableRow> *VContainer::DataIncrementTable() const{
return &incrementTable;
}
2013-07-17 13:38:11 +02:00
2013-07-25 14:00:51 +02:00
const QMap<QString, qreal> *VContainer::DataLengthLines() const{
return &lengthLines;
}
2013-07-17 13:38:11 +02:00
2013-08-05 10:37:56 +02:00
const QMap<QString, qreal> *VContainer::DataLengthSplines() const{
return &lengthSplines;
}
2013-07-30 15:09:34 +02:00
void VContainer::AddLine(const qint64 &firstPointId, const qint64 &secondPointId){
QString nameLine = GetNameLine(firstPointId, secondPointId);
VPointF firstPoint = GetPoint(firstPointId);
VPointF secondPoint = GetPoint(secondPointId);
2013-08-05 10:37:56 +02:00
AddLengthLine(nameLine, QLineF(firstPoint.toQPointF(), secondPoint.toQPointF()).length());
}
qint64 VContainer::AddSpline(const VSpline &spl){
qint64 id = getNextId();
splines[id] = spl;
return id;
}
2013-08-09 08:49:34 +02:00
qint64 VContainer::AddSplinePath(const VSplinePath &splPath){
qint64 id = getNextId();
splinePaths[id] = splPath;
return id;
}
2013-08-05 10:37:56 +02:00
qint64 VContainer::AddArc(const VArc &arc){
qint64 id = getNextId();
arcs[id] = arc;
return id;
2013-07-30 15:09:34 +02:00
}
QString VContainer::GetNameLine(const qint64 &firstPoint, const qint64 &secondPoint) const{
VPointF first = GetPoint(firstPoint);
VPointF second = GetPoint(secondPoint);
return QString("Line_%1_%2").arg(first.name(), second.name());
}
2013-08-06 09:56:09 +02:00
QString VContainer::GetNameLineArc(const qint64 &firstPoint, const qint64 &secondPoint) const{
2013-08-05 10:37:56 +02:00
VPointF first = GetPoint(firstPoint);
VPointF second = GetPoint(secondPoint);
2013-08-06 09:56:09 +02:00
return QString("ArcLine_%1_%2").arg(first.name(), second.name());
2013-08-05 10:37:56 +02:00
}
2013-08-06 09:56:09 +02:00
QString VContainer::GetNameSpline(const qint64 &firstPoint, const qint64 &secondPoint) const{
2013-08-05 10:37:56 +02:00
VPointF first = GetPoint(firstPoint);
VPointF second = GetPoint(secondPoint);
2013-08-06 09:56:09 +02:00
return QString("Spl_%1_%2").arg(first.name(), second.name());
}
2013-08-09 08:49:34 +02:00
QString VContainer::GetNameSplinePath(const VSplinePath &path) const{
if(path.Count() == 0){
return QString();
}
QString name("SplPath");
for(qint32 i = 1; i <= path.Count(); ++i){
VSpline spl = path.GetSpline(i);
VPointF first = GetPoint(spl.GetP1());
VPointF second = GetPoint(spl.GetP4());
QString splName = QString("_%1_%2").arg(first.name(), second.name());
name.append(splName);
}
return name;
}
2013-08-06 09:56:09 +02:00
QString VContainer::GetNameArc(const qint64 &center, const qint64 &id) const{
VPointF centerPoint = GetPoint(center);
return QString ("Arc(%1)%2").arg(centerPoint.name(), id);
2013-08-05 10:37:56 +02:00
}
void VContainer::AddLengthLine(const QString &name, const qreal &value){
2013-07-25 14:00:51 +02:00
Q_ASSERT(!name.isEmpty());
2013-08-06 09:56:09 +02:00
lengthLines[name] = value;
2013-07-17 13:38:11 +02:00
}
2013-08-05 10:37:56 +02:00
void VContainer::AddLengthSpline(const qint64 &firstPointId, const qint64 &secondPointId){
QString nameLine = GetNameSpline(firstPointId, secondPointId);
VPointF firstPoint = GetPoint(firstPointId);
VPointF secondPoint = GetPoint(secondPointId);
AddLengthSpline(nameLine, QLineF(firstPoint.toQPointF(), secondPoint.toQPointF()).length());
}
void VContainer::AddLengthSpline(const QString &name, const qreal &value){
Q_ASSERT(!name.isEmpty());
2013-08-06 09:56:09 +02:00
lengthSplines[name] = value;
2013-08-05 10:37:56 +02:00
}
2013-08-06 09:56:09 +02:00
void VContainer::AddLengthArc(const qint64 &center, const qint64 &id){
AddLengthArc(GetNameArc(center, id), GetArc(id).GetLength());
2013-08-05 10:37:56 +02:00
}
void VContainer::AddLengthArc(const QString &name, const qreal &value){
Q_ASSERT(!name.isEmpty());
2013-08-06 09:56:09 +02:00
lengthArcs[name] = value;
}
void VContainer::AddLineArc(const QString &name, const qint32 &value){
Q_ASSERT(!name.isEmpty());
lineArcs[name] = value;
2013-08-05 10:37:56 +02:00
}
2013-07-25 14:00:51 +02:00
qreal VContainer::GetLine(const QString &name) const{
Q_ASSERT(!name.isEmpty());
if(lengthLines.contains(name)){
return lengthLines.value(name);
} else {
qCritical()<<"Не можу знайти лінію за імям = "<<name<<" в таблиці.";
2013-08-06 09:56:09 +02:00
throw"Не можу знайти лінію в таблиці.";
}
return 0;
}
qint32 VContainer::GetLineArc(const QString &name) const{
Q_ASSERT(!name.isEmpty());
if(lineArcs.contains(name)){
return lineArcs.value(name);
} else {
qCritical()<<"Не можу знайти кут за імям = "<<name<<" в таблиці.";
throw"Не можу знайти кут в таблиці.";
2013-07-17 13:38:11 +02:00
}
2013-07-25 14:00:51 +02:00
return 0;
2013-07-13 12:51:31 +02:00
}
2013-08-05 10:37:56 +02:00
VSpline VContainer::GetSpline(qint64 id) const{
if(splines.contains(id)){
return splines.value(id);
} else {
qCritical()<<"Не можу знайти id = "<<id<<" в таблиці.";
throw"Не можу знайти сплайн за id.";
}
return VSpline();
}
VArc VContainer::GetArc(qint64 id) const{
if(arcs.contains(id)){
return arcs.value(id);
} else {
qCritical()<<"Не можу знайти id = "<<id<<" в таблиці.";
throw"Не можу знайти дугу за id.";
}
return VArc();
}
2013-08-09 08:49:34 +02:00
VSplinePath VContainer::GetSplinePath(qint64 id) const{
if(splinePaths.contains(id)){
return splinePaths.value(id);
} else {
qCritical()<<"Не можу знайти id = "<<id<<" в таблиці.";
throw"Не можу знайти дугу за id.";
}
return VSplinePath();
}
2013-08-05 10:37:56 +02:00
const QMap<QString, qreal> *VContainer::DataLengthArcs() const{
return &lengthArcs;
}
2013-08-06 09:56:09 +02:00
const QMap<QString, qreal> *VContainer::DataLineArcs() const{
return &lineArcs;
}
2013-08-09 08:49:34 +02:00
const QMap<qint64, VSplinePath> *VContainer::DataSplinePaths() const{
return &splinePaths;
}