2016-09-13 10:27:44 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file dialogflippingbyline.cpp
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 12 9, 2016
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
2017-10-05 11:20:01 +02:00
|
|
|
** This source code is part of the Valentina project, a pattern making
|
2016-09-13 10:27:44 +02:00
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
|
|
|
** Copyright (C) 2016 Valentina project
|
2020-01-31 07:00:05 +01:00
|
|
|
** <https://gitlab.com/smart-pattern/valentina> All Rights Reserved.
|
2016-09-13 10:27:44 +02:00
|
|
|
**
|
|
|
|
** Valentina is free software: you can redistribute it and/or modify
|
|
|
|
** 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.
|
|
|
|
**
|
|
|
|
** Valentina is distributed in the hope that it will be useful,
|
|
|
|
** 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/>.
|
|
|
|
**
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
#include "dialogflippingbyline.h"
|
|
|
|
|
|
|
|
#include <QColor>
|
|
|
|
#include <QComboBox>
|
2020-03-24 16:31:32 +01:00
|
|
|
#include <QCompleter>
|
2016-09-13 10:27:44 +02:00
|
|
|
#include <QDialog>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QPointF>
|
|
|
|
#include <QPointer>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QRegularExpression>
|
|
|
|
#include <QRegularExpressionMatch>
|
|
|
|
#include <QSharedPointer>
|
|
|
|
#include <QStringList>
|
|
|
|
#include <QToolButton>
|
|
|
|
#include <Qt>
|
|
|
|
#include <new>
|
|
|
|
|
|
|
|
#include "../../visualization/visualization.h"
|
|
|
|
#include "../../visualization/line/operation/vistoolflippingbyline.h"
|
|
|
|
#include "../ifc/xml/vabstractpattern.h"
|
|
|
|
#include "../ifc/xml/vdomdocument.h"
|
|
|
|
#include "../qmuparser/qmudef.h"
|
|
|
|
#include "../vgeometry/vpointf.h"
|
|
|
|
#include "../vmisc/vabstractapplication.h"
|
|
|
|
#include "../vmisc/vcommonsettings.h"
|
2020-01-16 18:20:55 +01:00
|
|
|
#include "../vmisc/compatibility.h"
|
2016-09-13 10:27:44 +02:00
|
|
|
#include "../vpatterndb/vcontainer.h"
|
|
|
|
#include "../vwidgets/vabstractmainwindow.h"
|
|
|
|
#include "../vwidgets/vmaingraphicsscene.h"
|
2018-01-05 21:01:35 +01:00
|
|
|
#include "../vwidgets/vmaingraphicsview.h"
|
2016-09-13 10:27:44 +02:00
|
|
|
#include "ui_dialogflippingbyline.h"
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2019-02-11 12:25:27 +01:00
|
|
|
DialogFlippingByLine::DialogFlippingByLine(const VContainer *data, quint32 toolId, QWidget *parent)
|
2016-09-13 10:27:44 +02:00
|
|
|
: DialogTool(data, toolId, parent),
|
|
|
|
ui(new Ui::DialogFlippingByLine),
|
|
|
|
stage1(true),
|
2019-02-11 12:25:27 +01:00
|
|
|
m_suffix(),
|
2019-02-12 10:08:40 +01:00
|
|
|
flagName(true),
|
2020-03-18 14:22:27 +01:00
|
|
|
flagGroupName(true),
|
2019-02-11 12:25:27 +01:00
|
|
|
flagError(false)
|
2016-09-13 10:27:44 +02:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
|
|
|
ui->lineEditSuffix->setText(qApp->getCurrentDocument()->GenerateSuffix());
|
|
|
|
|
|
|
|
InitOkCancelApply(ui);
|
|
|
|
|
|
|
|
FillComboBoxPoints(ui->comboBoxFirstLinePoint);
|
|
|
|
FillComboBoxPoints(ui->comboBoxSecondLinePoint);
|
|
|
|
|
|
|
|
connect(ui->lineEditSuffix, &QLineEdit::textChanged, this, &DialogFlippingByLine::SuffixChanged);
|
2020-03-18 13:45:47 +01:00
|
|
|
connect(ui->lineEditVisibilityGroup, &QLineEdit::textChanged, this, &DialogFlippingByLine::GroupNameChanged);
|
2019-07-24 15:45:22 +02:00
|
|
|
connect(ui->comboBoxFirstLinePoint, &QComboBox::currentTextChanged,
|
2016-09-13 10:27:44 +02:00
|
|
|
this, &DialogFlippingByLine::PointChanged);
|
2019-07-24 15:45:22 +02:00
|
|
|
connect(ui->comboBoxSecondLinePoint, &QComboBox::currentTextChanged,
|
2016-09-17 11:10:03 +02:00
|
|
|
this, &DialogFlippingByLine::PointChanged);
|
2016-09-13 10:27:44 +02:00
|
|
|
|
|
|
|
vis = new VisToolFlippingByLine(data);
|
2020-10-28 13:09:56 +01:00
|
|
|
|
|
|
|
ui->tabWidget->setCurrentIndex(0);
|
|
|
|
SetTabStopDistance(ui->plainTextEditToolNotes);
|
2016-09-13 10:27:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
DialogFlippingByLine::~DialogFlippingByLine()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
quint32 DialogFlippingByLine::GetFirstLinePointId() const
|
|
|
|
{
|
|
|
|
return getCurrentObjectId(ui->comboBoxFirstLinePoint);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogFlippingByLine::SetFirstLinePointId(quint32 value)
|
|
|
|
{
|
|
|
|
ChangeCurrentData(ui->comboBoxFirstLinePoint, value);
|
|
|
|
VisToolFlippingByLine *operation = qobject_cast<VisToolFlippingByLine *>(vis);
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(operation != nullptr)
|
2016-09-13 10:27:44 +02:00
|
|
|
operation->SetFirstLinePointId(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
quint32 DialogFlippingByLine::GetSecondLinePointId() const
|
|
|
|
{
|
|
|
|
return getCurrentObjectId(ui->comboBoxSecondLinePoint);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogFlippingByLine::SetSecondLinePointId(quint32 value)
|
|
|
|
{
|
|
|
|
ChangeCurrentData(ui->comboBoxSecondLinePoint, value);
|
|
|
|
VisToolFlippingByLine *operation = qobject_cast<VisToolFlippingByLine *>(vis);
|
2016-12-21 16:36:38 +01:00
|
|
|
SCASSERT(operation != nullptr)
|
2016-09-13 10:27:44 +02:00
|
|
|
operation->SetSecondLinePointId(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString DialogFlippingByLine::GetSuffix() const
|
|
|
|
{
|
|
|
|
return m_suffix;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogFlippingByLine::SetSuffix(const QString &value)
|
|
|
|
{
|
|
|
|
m_suffix = value;
|
|
|
|
ui->lineEditSuffix->setText(value);
|
|
|
|
}
|
|
|
|
|
2020-03-18 13:45:47 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString DialogFlippingByLine::GetVisibilityGroupName() const
|
|
|
|
{
|
|
|
|
return ui->lineEditVisibilityGroup->text();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogFlippingByLine::SetVisibilityGroupName(const QString &name)
|
|
|
|
{
|
|
|
|
ui->lineEditVisibilityGroup->setText(name.isEmpty() ? tr("Rotation") : name);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool DialogFlippingByLine::HasLinkedVisibilityGroup() const
|
|
|
|
{
|
|
|
|
return ui->groupBoxVisibilityGroup->isChecked();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogFlippingByLine::SetHasLinkedVisibilityGroup(bool linked)
|
|
|
|
{
|
|
|
|
ui->groupBoxVisibilityGroup->setChecked(linked);
|
|
|
|
}
|
|
|
|
|
2020-03-24 16:31:32 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogFlippingByLine::SetVisibilityGroupTags(const QStringList &tags)
|
|
|
|
{
|
|
|
|
ui->lineEditGroupTags->setText(tags.join(", "));
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QStringList DialogFlippingByLine::GetVisibilityGroupTags() const
|
|
|
|
{
|
|
|
|
return ui->lineEditGroupTags->text().split(',');
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogFlippingByLine::SetGroupCategories(const QStringList &categories)
|
|
|
|
{
|
|
|
|
m_groupTags = categories;
|
|
|
|
ui->lineEditGroupTags->SetCompletion(m_groupTags);
|
|
|
|
}
|
|
|
|
|
2016-09-13 10:27:44 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogFlippingByLine::ShowDialog(bool click)
|
|
|
|
{
|
|
|
|
if (stage1 && not click)
|
|
|
|
{
|
2020-11-07 14:02:30 +01:00
|
|
|
if (sourceObjects.isEmpty())
|
2016-09-13 10:27:44 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
stage1 = false;
|
|
|
|
|
|
|
|
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(scene != nullptr)
|
2016-09-13 10:27:44 +02:00
|
|
|
scene->clearSelection();
|
|
|
|
|
|
|
|
VisToolFlippingByLine *operation = qobject_cast<VisToolFlippingByLine *>(vis);
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(operation != nullptr)
|
2020-11-07 14:02:30 +01:00
|
|
|
operation->SetObjects(SourceToObjects(sourceObjects));
|
2016-09-13 10:27:44 +02:00
|
|
|
operation->VisualMode();
|
|
|
|
|
|
|
|
scene->ToggleArcSelection(false);
|
2016-12-20 16:08:28 +01:00
|
|
|
scene->ToggleElArcSelection(false);
|
2016-09-13 10:27:44 +02:00
|
|
|
scene->ToggleSplineSelection(false);
|
|
|
|
scene->ToggleSplinePathSelection(false);
|
|
|
|
|
|
|
|
scene->ToggleArcHover(false);
|
2016-12-20 16:08:28 +01:00
|
|
|
scene->ToggleElArcHover(false);
|
2016-09-13 10:27:44 +02:00
|
|
|
scene->ToggleSplineHover(false);
|
|
|
|
scene->ToggleSplinePathHover(false);
|
|
|
|
|
2018-01-05 21:01:35 +01:00
|
|
|
qApp->getSceneView()->AllowRubberBand(false);
|
|
|
|
|
2020-11-07 14:02:30 +01:00
|
|
|
FillSourceList();
|
|
|
|
|
2016-09-17 18:18:27 +02:00
|
|
|
emit ToolTip(tr("Select first line point"));
|
2016-09-13 10:27:44 +02:00
|
|
|
}
|
|
|
|
else if (not stage1 && prepare && click)
|
|
|
|
{
|
|
|
|
setModal(true);
|
2018-03-14 15:01:24 +01:00
|
|
|
emit ToolTip(QString());
|
2016-09-13 10:27:44 +02:00
|
|
|
show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-07 14:02:30 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QVector<SourceItem> DialogFlippingByLine::GetSourceObjects() const
|
|
|
|
{
|
|
|
|
return sourceObjects;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogFlippingByLine::SetSourceObjects(const QVector<SourceItem> &value)
|
|
|
|
{
|
|
|
|
sourceObjects = value;
|
|
|
|
FillSourceList();
|
|
|
|
|
|
|
|
VisToolFlippingByLine *operation = qobject_cast<VisToolFlippingByLine *>(vis);
|
|
|
|
SCASSERT(operation != nullptr)
|
|
|
|
operation->SetObjects(SourceToObjects(sourceObjects));
|
|
|
|
}
|
|
|
|
|
2016-09-13 10:27:44 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogFlippingByLine::ChosenObject(quint32 id, const SceneObject &type)
|
|
|
|
{
|
|
|
|
if (not stage1 && not prepare)// After first choose we ignore all objects
|
|
|
|
{
|
|
|
|
if (type == SceneObject::Point)
|
|
|
|
{
|
2020-11-07 14:02:30 +01:00
|
|
|
auto obj = std::find_if(sourceObjects.begin(), sourceObjects.end(),
|
|
|
|
[id](const SourceItem &sItem) { return sItem.id == id; });
|
2016-09-13 10:27:44 +02:00
|
|
|
switch (number)
|
|
|
|
{
|
|
|
|
case 0:
|
2020-11-07 14:02:30 +01:00
|
|
|
if (obj != sourceObjects.end())
|
2016-09-17 18:16:15 +02:00
|
|
|
{
|
2016-09-17 18:18:27 +02:00
|
|
|
emit ToolTip(tr("Select first line point that is not part of the list of objects"));
|
2016-09-17 18:16:15 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-09-13 10:27:44 +02:00
|
|
|
if (SetObject(id, ui->comboBoxFirstLinePoint, tr("Select second line point")))
|
|
|
|
{
|
|
|
|
number++;
|
|
|
|
VisToolFlippingByLine *operation = qobject_cast<VisToolFlippingByLine *>(vis);
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(operation != nullptr)
|
2016-09-13 10:27:44 +02:00
|
|
|
operation->SetFirstLinePointId(id);
|
|
|
|
operation->RefreshGeometry();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
2020-11-07 14:02:30 +01:00
|
|
|
if (obj != sourceObjects.end())
|
2016-09-17 18:16:15 +02:00
|
|
|
{
|
2016-09-17 18:18:27 +02:00
|
|
|
emit ToolTip(tr("Select second line point that is not part of the list of objects"));
|
2016-09-17 18:16:15 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-09-13 10:27:44 +02:00
|
|
|
if (getCurrentObjectId(ui->comboBoxFirstLinePoint) != id)
|
|
|
|
{
|
2018-03-14 15:01:24 +01:00
|
|
|
if (SetObject(id, ui->comboBoxSecondLinePoint, QString()))
|
2016-09-13 10:27:44 +02:00
|
|
|
{
|
|
|
|
if (flagError)
|
|
|
|
{
|
|
|
|
number = 0;
|
|
|
|
prepare = true;
|
|
|
|
|
|
|
|
VisToolFlippingByLine *operation = qobject_cast<VisToolFlippingByLine *>(vis);
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(operation != nullptr)
|
2016-09-13 10:27:44 +02:00
|
|
|
operation->SetSecondLinePointId(id);
|
|
|
|
operation->RefreshGeometry();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogFlippingByLine::SelectedObject(bool selected, quint32 object, quint32 tool)
|
|
|
|
{
|
|
|
|
Q_UNUSED(tool)
|
|
|
|
if (stage1)
|
|
|
|
{
|
2020-11-07 14:02:30 +01:00
|
|
|
auto obj = std::find_if(sourceObjects.begin(), sourceObjects.end(),
|
|
|
|
[object](const SourceItem &sItem) { return sItem.id == object; });
|
2016-09-13 10:27:44 +02:00
|
|
|
if (selected)
|
|
|
|
{
|
2020-11-07 14:02:30 +01:00
|
|
|
if (obj == sourceObjects.cend())
|
2016-09-13 10:27:44 +02:00
|
|
|
{
|
2020-11-07 14:02:30 +01:00
|
|
|
SourceItem item;
|
|
|
|
item.id = object;
|
|
|
|
sourceObjects.append(item);
|
2016-09-13 10:27:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-11-07 14:02:30 +01:00
|
|
|
if (obj != sourceObjects.end())
|
|
|
|
{
|
|
|
|
sourceObjects.erase(obj);
|
|
|
|
}
|
2016-09-13 10:27:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogFlippingByLine::SuffixChanged()
|
|
|
|
{
|
|
|
|
QLineEdit* edit = qobject_cast<QLineEdit*>(sender());
|
|
|
|
if (edit)
|
|
|
|
{
|
|
|
|
const QString suffix = edit->text();
|
|
|
|
if (suffix.isEmpty())
|
|
|
|
{
|
|
|
|
flagName = false;
|
2019-02-11 12:25:27 +01:00
|
|
|
ChangeColor(ui->labelSuffix, errorColor);
|
2020-11-07 14:02:30 +01:00
|
|
|
ui->labelStatus->setText(tr("Invalid suffix"));
|
2016-09-13 10:27:44 +02:00
|
|
|
CheckState();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (m_suffix != suffix)
|
|
|
|
{
|
|
|
|
QRegularExpression rx(NameRegExp());
|
2018-09-18 15:38:16 +02:00
|
|
|
const QStringList uniqueNames = data->AllUniqueNames();
|
2018-04-03 13:36:38 +02:00
|
|
|
for (auto &uniqueName : uniqueNames)
|
2016-09-13 10:27:44 +02:00
|
|
|
{
|
2018-04-03 13:36:38 +02:00
|
|
|
const QString name = uniqueName + suffix;
|
2016-09-13 10:27:44 +02:00
|
|
|
if (not rx.match(name).hasMatch() || not data->IsUnique(name))
|
|
|
|
{
|
|
|
|
flagName = false;
|
2019-02-11 12:25:27 +01:00
|
|
|
ChangeColor(ui->labelSuffix, errorColor);
|
2020-11-07 14:02:30 +01:00
|
|
|
ui->labelStatus->setText(tr("Invalid suffix"));
|
2016-09-13 10:27:44 +02:00
|
|
|
CheckState();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
flagName = true;
|
2019-02-11 12:25:27 +01:00
|
|
|
ChangeColor(ui->labelSuffix, OkColor(this));
|
2016-09-13 10:27:44 +02:00
|
|
|
}
|
|
|
|
CheckState();
|
|
|
|
}
|
|
|
|
|
2020-03-18 13:45:47 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogFlippingByLine::GroupNameChanged()
|
|
|
|
{
|
|
|
|
QLineEdit* edit = qobject_cast<QLineEdit*>(sender());
|
|
|
|
if (edit)
|
|
|
|
{
|
|
|
|
const QString name = edit->text();
|
|
|
|
if (name.isEmpty())
|
|
|
|
{
|
|
|
|
flagGroupName = false;
|
|
|
|
ChangeColor(ui->labelGroupName, errorColor);
|
2020-11-07 14:02:30 +01:00
|
|
|
ui->labelStatus->setText(tr("Invalid group name"));
|
2020-03-18 13:45:47 +01:00
|
|
|
CheckState();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
flagGroupName = true;
|
|
|
|
ChangeColor(ui->labelGroupName, OkColor(this));
|
|
|
|
}
|
|
|
|
CheckState();
|
|
|
|
}
|
|
|
|
|
2020-11-07 14:02:30 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogFlippingByLine::ShowSourceDetails(int row)
|
|
|
|
{
|
|
|
|
ui->lineEditAlias->setDisabled(true);
|
|
|
|
|
|
|
|
if (ui->listWidget->count() == 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto sourceItem = qvariant_cast<SourceItem>(ui->listWidget->item(row)->data(Qt::UserRole));
|
|
|
|
|
|
|
|
const QSharedPointer<VGObject> obj = data->GetGObject(sourceItem.id);
|
|
|
|
|
|
|
|
ui->labelAlias->setText(obj->getType() == GOType::Point ? tr("Label:") : tr("Alias:"));
|
|
|
|
|
|
|
|
ui->lineEditAlias->blockSignals(true);
|
|
|
|
ui->lineEditAlias->setText(sourceItem.alias);
|
|
|
|
ui->lineEditAlias->setEnabled(true);
|
|
|
|
ui->lineEditAlias->blockSignals(false);
|
|
|
|
|
|
|
|
SetAliasValid(sourceItem.id, SourceAliasValid(sourceItem, obj, data,
|
|
|
|
OriginAlias(sourceItem.id, sourceObjects, obj)));
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogFlippingByLine::AliasChanged(const QString &text)
|
|
|
|
{
|
|
|
|
if (ui->listWidget->count() == 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (auto *item = ui->listWidget->currentItem())
|
|
|
|
{
|
|
|
|
auto sourceItem = qvariant_cast<SourceItem>(item->data(Qt::UserRole));
|
|
|
|
sourceItem.alias = text;
|
|
|
|
|
|
|
|
item->setData(Qt::UserRole, QVariant::fromValue(sourceItem));
|
|
|
|
|
|
|
|
ValidateSourceAliases();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-13 10:27:44 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogFlippingByLine::ShowVisualization()
|
|
|
|
{
|
|
|
|
AddVisualization<VisToolFlippingByLine>();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogFlippingByLine::SaveData()
|
|
|
|
{
|
|
|
|
m_suffix = ui->lineEditSuffix->text();
|
|
|
|
|
2020-11-07 14:02:30 +01:00
|
|
|
sourceObjects.clear();
|
|
|
|
sourceObjects.reserve(ui->listWidget->count());
|
|
|
|
|
|
|
|
for (int i=0; i<ui->listWidget->count(); ++i)
|
|
|
|
{
|
|
|
|
if (const QListWidgetItem *item = ui->listWidget->item(i))
|
|
|
|
{
|
|
|
|
auto sourceItem = qvariant_cast<SourceItem>(item->data(Qt::UserRole));
|
|
|
|
sourceObjects.append(sourceItem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-13 10:27:44 +02:00
|
|
|
VisToolFlippingByLine *operation = qobject_cast<VisToolFlippingByLine *>(vis);
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(operation != nullptr)
|
2016-09-13 10:27:44 +02:00
|
|
|
|
2020-11-07 14:02:30 +01:00
|
|
|
operation->SetObjects(SourceToObjects(sourceObjects));
|
2016-09-13 10:27:44 +02:00
|
|
|
operation->SetFirstLinePointId(GetFirstLinePointId());
|
|
|
|
operation->SetSecondLinePointId(GetSecondLinePointId());
|
|
|
|
operation->RefreshGeometry();
|
2020-03-24 16:31:32 +01:00
|
|
|
|
|
|
|
QStringList groupTags = ui->lineEditGroupTags->text().split(',');
|
|
|
|
for (auto &tag : groupTags)
|
|
|
|
{
|
|
|
|
tag = tag.trimmed();
|
|
|
|
if (not m_groupTags.contains(tag))
|
|
|
|
{
|
|
|
|
m_groupTags.append(tag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ui->lineEditGroupTags->SetCompletion(m_groupTags);
|
2016-09-13 10:27:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogFlippingByLine::PointChanged()
|
|
|
|
{
|
2019-02-11 12:25:27 +01:00
|
|
|
QColor color = OkColor(this);
|
2016-09-13 10:27:44 +02:00
|
|
|
flagError = true;
|
|
|
|
ChangeColor(ui->labelFirstLinePoint, color);
|
|
|
|
ChangeColor(ui->labelSecondLinePoint, color);
|
|
|
|
|
2020-11-07 14:02:30 +01:00
|
|
|
quint32 id1 = getCurrentObjectId(ui->comboBoxFirstLinePoint);
|
|
|
|
auto obj1 = std::find_if(sourceObjects.begin(), sourceObjects.end(),
|
|
|
|
[id1](const SourceItem &sItem) { return sItem.id == id1; });
|
|
|
|
|
|
|
|
quint32 id2 = getCurrentObjectId(ui->comboBoxSecondLinePoint);
|
|
|
|
auto obj2 = std::find_if(sourceObjects.begin(), sourceObjects.end(),
|
|
|
|
[id2](const SourceItem &sItem) { return sItem.id == id2; });
|
|
|
|
|
2016-09-13 10:27:44 +02:00
|
|
|
if (getCurrentObjectId(ui->comboBoxFirstLinePoint) == getCurrentObjectId(ui->comboBoxSecondLinePoint))
|
|
|
|
{
|
|
|
|
flagError = false;
|
|
|
|
color = errorColor;
|
|
|
|
ChangeColor(ui->labelFirstLinePoint, color);
|
|
|
|
ChangeColor(ui->labelSecondLinePoint, color);
|
2020-11-07 14:02:30 +01:00
|
|
|
ui->labelStatus->setText(tr("Invalid line points"));
|
2016-09-13 10:27:44 +02:00
|
|
|
}
|
2020-11-07 14:02:30 +01:00
|
|
|
else if (obj1 != sourceObjects.end())
|
2016-09-13 10:27:44 +02:00
|
|
|
{
|
|
|
|
flagError = false;
|
|
|
|
color = errorColor;
|
|
|
|
ChangeColor(ui->labelFirstLinePoint, color);
|
2020-11-07 14:02:30 +01:00
|
|
|
ui->labelStatus->setText(tr("Invalid first line point"));
|
2016-09-13 10:27:44 +02:00
|
|
|
}
|
2020-11-07 14:02:30 +01:00
|
|
|
else if (obj2 != sourceObjects.end())
|
2016-09-13 10:27:44 +02:00
|
|
|
{
|
|
|
|
flagError = false;
|
|
|
|
color = errorColor;
|
|
|
|
ChangeColor(ui->labelSecondLinePoint, color);
|
2020-11-07 14:02:30 +01:00
|
|
|
ui->labelStatus->setText(tr("Invalid second line point"));
|
2016-09-13 10:27:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CheckState();
|
|
|
|
}
|
2020-10-28 13:09:56 +01:00
|
|
|
|
2020-11-07 14:02:30 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogFlippingByLine::FillSourceList()
|
|
|
|
{
|
|
|
|
ui->listWidget->blockSignals(true);
|
|
|
|
|
|
|
|
ui->listWidget->clear();
|
|
|
|
|
|
|
|
int row = -1;
|
|
|
|
|
|
|
|
for (auto &sourceItem : sourceObjects)
|
|
|
|
{
|
|
|
|
const QSharedPointer<VGObject> obj = data->GetGObject(sourceItem.id);
|
|
|
|
bool valid = SourceAliasValid(sourceItem, obj, data, OriginAlias(sourceItem.id, sourceObjects, obj));
|
|
|
|
|
|
|
|
auto *item = new QListWidgetItem(valid ? obj->ObjectName() : obj->ObjectName() + '*');
|
|
|
|
item->setToolTip(obj->ObjectName());
|
|
|
|
item->setData(Qt::UserRole, QVariant::fromValue(sourceItem));
|
|
|
|
ui->listWidget->insertItem(++row, item);
|
|
|
|
}
|
|
|
|
|
|
|
|
ui->listWidget->blockSignals(false);
|
|
|
|
|
|
|
|
if (ui->listWidget->count() > 0)
|
|
|
|
{
|
|
|
|
ui->listWidget->setCurrentRow(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
ValidateSourceAliases();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogFlippingByLine::ValidateSourceAliases()
|
|
|
|
{
|
|
|
|
for (int i=0; i<ui->listWidget->count(); ++i)
|
|
|
|
{
|
|
|
|
if (const QListWidgetItem *item = ui->listWidget->item(i))
|
|
|
|
{
|
|
|
|
auto sourceItem = qvariant_cast<SourceItem>(item->data(Qt::UserRole));
|
|
|
|
|
|
|
|
const QSharedPointer<VGObject> obj = data->GetGObject(sourceItem.id);
|
|
|
|
|
|
|
|
if (not SourceAliasValid(sourceItem, obj, data, OriginAlias(sourceItem.id, sourceObjects, obj)))
|
|
|
|
{
|
|
|
|
flagAlias = false;
|
|
|
|
ui->labelStatus->setText(obj->getType() == GOType::Point ? tr("Invalid label") : tr("Invalid alias"));
|
|
|
|
SetAliasValid(sourceItem.id, false);
|
|
|
|
CheckState();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SetAliasValid(sourceItem.id, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
flagAlias = true;
|
|
|
|
CheckState();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogFlippingByLine::SetAliasValid(quint32 id, bool valid)
|
|
|
|
{
|
|
|
|
if (ui->listWidget->currentRow() != -1)
|
|
|
|
{
|
|
|
|
auto *item = ui->listWidget->item(ui->listWidget->currentRow());
|
|
|
|
const auto sourceItem = qvariant_cast<SourceItem>(item->data(Qt::UserRole));
|
|
|
|
|
|
|
|
if (id == sourceItem.id)
|
|
|
|
{
|
|
|
|
const QSharedPointer<VGObject> obj = data->GetGObject(sourceItem.id);
|
|
|
|
item->setText(valid ? obj->ObjectName() : obj->ObjectName() + '*');
|
|
|
|
|
|
|
|
ChangeColor(ui->labelAlias, valid ? OkColor(this) : errorColor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-28 13:09:56 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogFlippingByLine::SetNotes(const QString ¬es)
|
|
|
|
{
|
|
|
|
ui->plainTextEditToolNotes->setPlainText(notes);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString DialogFlippingByLine::GetNotes() const
|
|
|
|
{
|
|
|
|
return ui->plainTextEditToolNotes->toPlainText();
|
|
|
|
}
|
2020-11-07 14:02:30 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool DialogFlippingByLine::IsValid() const
|
|
|
|
{
|
|
|
|
bool ready = flagError && flagName && flagGroupName && flagAlias;
|
|
|
|
|
|
|
|
if (ready)
|
|
|
|
{
|
|
|
|
ui->labelStatus->setText(tr("Ready"));
|
|
|
|
}
|
|
|
|
|
|
|
|
return ready;
|
|
|
|
}
|