Added new tool Insert node.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2017-03-22 12:05:53 +02:00
parent 20ccbaae01
commit e995f6f68a
14 changed files with 204 additions and 34 deletions

View File

@ -666,7 +666,7 @@ VPieceNode VAbstractPattern::ParseSANode(const QDomElement &domElement)
{
const quint32 id = VDomDocument::GetParametrUInt(domElement, AttrIdObject, NULL_ID_STR);
const bool reverse = VDomDocument::GetParametrUInt(domElement, VAbstractPattern::AttrNodeReverse, "0");
const bool excluded = VDomDocument::GetParametrUInt(domElement, VAbstractPattern::AttrNodeExcluded, "0");
const bool excluded = VDomDocument::GetParametrBool(domElement, VAbstractPattern::AttrNodeExcluded, falseStr);
const QString saBefore = VDomDocument::GetParametrString(domElement, VAbstractPattern::AttrSABefore,
currentSeamAllowance);
const QString saAfter = VDomDocument::GetParametrString(domElement, VAbstractPattern::AttrSAAfter,

View File

@ -58,8 +58,8 @@ class QDomElement;
*/
const QString VPatternConverter::PatternMinVerStr = QStringLiteral("0.1.0");
const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.4.4");
const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.4.4.xsd");
const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.4.5");
const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.4.5.xsd");
//VPatternConverter::PatternMinVer; // <== DON'T FORGET TO UPDATE TOO!!!!
//VPatternConverter::PatternMaxVer; // <== DON'T FORGET TO UPDATE TOO!!!!

View File

@ -121,9 +121,9 @@ QVector<QPointF> VPiece::MainPathPoints(const VContainer *data) const
}
//---------------------------------------------------------------------------------------------------------------------
QVector<VPointF> VPiece::MainPathNodePoints(const VContainer *data) const
QVector<VPointF> VPiece::MainPathNodePoints(const VContainer *data, bool showExcluded) const
{
return GetPath().PathNodePoints(data);
return GetPath().PathNodePoints(data, showExcluded);
}
//---------------------------------------------------------------------------------------------------------------------
@ -146,6 +146,11 @@ QVector<QPointF> VPiece::SeamAllowancePoints(const VContainer *data) const
for (int i = 0; i< d->m_path.CountNodes(); ++i)
{
const VPieceNode &node = d->m_path.at(i);
if (node.IsExcluded())
{
continue;// skip excluded node
}
switch (node.GetTypeTool())
{
case (Tool::NodePoint):
@ -491,12 +496,16 @@ QVector<CustomSARecord> VPiece::GetValidRecords() const
for (int i = 0; i < d->m_customSARecords.size(); ++i)
{
const CustomSARecord &record = d->m_customSARecords.at(i);
const int indexStartPoint = d->m_path.indexOfNode(record.startPoint);
const int indexEndPoint = d->m_path.indexOfNode(record.endPoint);
if (record.startPoint > NULL_ID
&& record.path > NULL_ID
&& record.endPoint > NULL_ID
&& d->m_path.indexOfNode(record.startPoint) != -1
&& d->m_path.indexOfNode(record.endPoint) != -1)
&& indexStartPoint != -1
&& not d->m_path.at(indexStartPoint).IsExcluded()
&& indexEndPoint != -1
&& not d->m_path.at(indexEndPoint).IsExcluded())
{
records.append(record);
}

View File

@ -59,7 +59,7 @@ public:
void SetPath(const VPiecePath &path);
QVector<QPointF> MainPathPoints(const VContainer *data) const;
QVector<VPointF> MainPathNodePoints(const VContainer *data) const;
QVector<VPointF> MainPathNodePoints(const VContainer *data, bool showExcluded = false) const;
QVector<QPointF> SeamAllowancePoints(const VContainer *data) const;
QPainterPath MainPathPath(const VContainer *data) const;

View File

@ -243,6 +243,11 @@ QVector<QPointF> VPiecePath::PathPoints(const VContainer *data) const
QVector<QPointF> points;
for (int i = 0; i < CountNodes(); ++i)
{
if (at(i).IsExcluded())
{
continue;// skip excluded node
}
switch (at(i).GetTypeTool())
{
case (Tool::NodePoint):
@ -274,7 +279,7 @@ QVector<QPointF> VPiecePath::PathPoints(const VContainer *data) const
}
//---------------------------------------------------------------------------------------------------------------------
QVector<VPointF> VPiecePath::PathNodePoints(const VContainer *data) const
QVector<VPointF> VPiecePath::PathNodePoints(const VContainer *data, bool showExcluded) const
{
QVector<VPointF> points;
for (int i = 0; i < CountNodes(); ++i)
@ -283,8 +288,11 @@ QVector<VPointF> VPiecePath::PathNodePoints(const VContainer *data) const
{
case Tool::NodePoint:
{
const QSharedPointer<VPointF> point = data->GeometricObject<VPointF>(at(i).GetId());
points.append(*point);
if (showExcluded || not at(i).IsExcluded())
{
const QSharedPointer<VPointF> point = data->GeometricObject<VPointF>(at(i).GetId());
points.append(*point);
}
}
break;
case Tool::NodeArc:

View File

@ -71,7 +71,7 @@ public:
void SetPenType(const Qt::PenStyle &type);
QVector<QPointF> PathPoints(const VContainer *data) const;
QVector<VPointF> PathNodePoints(const VContainer *data) const;
QVector<VPointF> PathNodePoints(const VContainer *data, bool showExcluded = true) const;
QVector<VSAPoint> SeamAllowancePoints(const VContainer *data, qreal width, bool reverse) const;
QPainterPath PainterPath(const VContainer *data) const;

View File

@ -79,6 +79,25 @@ Q_LOGGING_CATEGORY(vDialog, "v.dialog")
#define DIALOG_MAX_FORMULA_HEIGHT 64
namespace
{
//---------------------------------------------------------------------------------------------------------------------
quint32 RowId(QListWidget *listWidget, int i)
{
SCASSERT(listWidget != nullptr);
if (i < 0 || i >= listWidget->count())
{
return NULL_ID;
}
const QListWidgetItem *rowItem = listWidget->item(i);
SCASSERT(rowItem != nullptr);
const VPieceNode rowNode = qvariant_cast<VPieceNode>(rowItem->data(Qt::UserRole));
return rowNode.GetId();
}
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief DialogTool create dialog
@ -411,13 +430,65 @@ quint32 DialogTool::DNumber(const QString &baseName) const
}
//---------------------------------------------------------------------------------------------------------------------
quint32 DialogTool::RowId(QListWidget *listWidget, int i)
quint32 DialogTool::FindNotExcludedNodeDown(QListWidget *listWidget, int candidate)
{
SCASSERT(listWidget != nullptr);
const QListWidgetItem *rowItem = listWidget->item(i);
SCASSERT(rowItem != nullptr);
const VPieceNode rowNode = qvariant_cast<VPieceNode>(rowItem->data(Qt::UserRole));
return rowNode.GetId();
quint32 id = NULL_ID;
if (candidate < 0 || candidate >= listWidget->count())
{
return id;
}
int i = candidate;
VPieceNode rowNode;
do
{
const QListWidgetItem *rowItem = listWidget->item(i);
SCASSERT(rowItem != nullptr);
rowNode = qvariant_cast<VPieceNode>(rowItem->data(Qt::UserRole));
if (not rowNode.IsExcluded())
{
id = rowNode.GetId();
}
++i;
}
while (rowNode.IsExcluded() && i < listWidget->count());
return id;
}
//---------------------------------------------------------------------------------------------------------------------
quint32 DialogTool::FindNotExcludedNodeUp(QListWidget *listWidget, int candidate)
{
SCASSERT(listWidget != nullptr);
quint32 id = NULL_ID;
if (candidate < 0 || candidate >= listWidget->count())
{
return id;
}
int i = candidate;
VPieceNode rowNode;
do
{
const QListWidgetItem *rowItem = listWidget->item(i);
SCASSERT(rowItem != nullptr);
rowNode = qvariant_cast<VPieceNode>(rowItem->data(Qt::UserRole));
if (not rowNode.IsExcluded())
{
id = rowNode.GetId();
}
--i;
}
while (rowNode.IsExcluded() && i > -1);
return id;
}
//---------------------------------------------------------------------------------------------------------------------
@ -426,7 +497,9 @@ bool DialogTool::FirstPointEqualLast(QListWidget *listWidget)
SCASSERT(listWidget != nullptr);
if (listWidget->count() > 1)
{
return RowId(listWidget, 0) == RowId(listWidget, listWidget->count()-1);
const quint32 topId = FindNotExcludedNodeDown(listWidget, 0);
const quint32 bottomId = FindNotExcludedNodeUp(listWidget, listWidget->count()-1);
return topId == bottomId;
}
return false;
}
@ -437,7 +510,10 @@ bool DialogTool::DoublePoints(QListWidget *listWidget)
SCASSERT(listWidget != nullptr);
for (int i=0, sz = listWidget->count()-1; i<sz; ++i)
{
if (RowId(listWidget, i) == RowId(listWidget, i+1))
const quint32 firstId = FindNotExcludedNodeDown(listWidget, i);
const quint32 secondId = FindNotExcludedNodeDown(listWidget, firstId+1);
if (firstId == secondId)
{
return true;
}
@ -459,6 +535,14 @@ QString DialogTool::DialogWarningIcon()
return url;
}
//---------------------------------------------------------------------------------------------------------------------
QFont DialogTool::NodeFont(bool nodeExcluded)
{
QFont font("Times", 12, QFont::Bold);
font.setStrikeOut(nodeExcluded);
return font;
}
//---------------------------------------------------------------------------------------------------------------------
QString DialogTool::GetNodeName(const VPieceNode &node) const
{
@ -516,7 +600,7 @@ void DialogTool::NewNodeItem(QListWidget *listWidget, const VPieceNode &node)
if(canAddNewPoint)
{
QListWidgetItem *item = new QListWidgetItem(name);
item->setFont(QFont("Times", 12, QFont::Bold));
item->setFont(NodeFont(node.IsExcluded()));
item->setData(Qt::UserRole, QVariant::fromValue(node));
listWidget->addItem(item);
listWidget->setCurrentRow(listWidget->count()-1);

View File

@ -266,10 +266,12 @@ protected:
virtual bool eventFilter(QObject *object, QEvent *event) Q_DECL_OVERRIDE;
quint32 DNumber(const QString &baseName) const;
static quint32 RowId(QListWidget *listWidget, int i);
static quint32 FindNotExcludedNodeDown(QListWidget *listWidget, int candidate);
static quint32 FindNotExcludedNodeUp(QListWidget *listWidget, int candidate);
static bool FirstPointEqualLast(QListWidget *listWidget);
static bool DoublePoints(QListWidget *listWidget);
static QString DialogWarningIcon();
static QFont NodeFont(bool nodeExcluded);
QString GetNodeName(const VPieceNode &node) const;
void NewNodeItem(QListWidget *listWidget, const VPieceNode &node);

View File

@ -587,6 +587,10 @@ void DialogSeamAllowance::ShowMainPathContextMenu(const QPoint &pos)
actionReverse->setChecked(rowNode.GetReverse());
}
QAction *actionExcluded = menu->addAction(tr("Excluded"));
actionExcluded->setCheckable(true);
actionExcluded->setChecked(rowNode.IsExcluded());
QAction *actionDelete = menu->addAction(QIcon::fromTheme("edit-delete"), tr("Delete"));
QAction *selectedAction = menu->exec(uiTabPaths->listWidgetMainPath->viewport()->mapToGlobal(pos));
@ -602,6 +606,14 @@ void DialogSeamAllowance::ShowMainPathContextMenu(const QPoint &pos)
rowItem->setText(GetNodeName(rowNode));
ValidObjects(MainPathIsValid());
}
else if (selectedAction == actionExcluded)
{
rowNode.SetExcluded(not rowNode.IsExcluded());
rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode));
rowItem->setText(GetNodeName(rowNode));
rowItem->setFont(NodeFont(rowNode.IsExcluded()));
ValidObjects(MainPathIsValid());
}
ListChanged();
}
@ -1989,12 +2001,13 @@ QString DialogSeamAllowance::GetPathName(quint32 path, bool reverse) const
bool DialogSeamAllowance::MainPathIsValid() const
{
QString url = DialogWarningIcon();
bool valid = true;
if(CreatePiece().MainPathPoints(data).count() < 3)
{
url += tr("You need more points!");
uiTabPaths->helpLabel->setText(url);
return false;
valid = false;
}
else
{
@ -2002,23 +2015,33 @@ bool DialogSeamAllowance::MainPathIsValid() const
{
url += tr("You have to choose points in a clockwise direction!");
uiTabPaths->helpLabel->setText(url);
return false;
valid = false;
}
if (FirstPointEqualLast(uiTabPaths->listWidgetMainPath))
{
url += tr("First point cannot be equal to the last point!");
uiTabPaths->helpLabel->setText(url);
return false;
valid = false;
}
else if (DoublePoints(uiTabPaths->listWidgetMainPath))
{
url += tr("You have double points!");
uiTabPaths->helpLabel->setText(url);
return false;
valid = false;
}
}
uiTabPaths->helpLabel->setText(tr("Ready!"));
return true;
if (valid)
{
m_ftb->SetTabText(TabOrder::Paths, tr("Paths"));
uiTabPaths->helpLabel->setText(tr("Ready!"));
}
else
{
m_ftb->SetTabText(TabOrder::Paths, tr("Paths") + QLatin1String("*"));
}
return valid;
}
//---------------------------------------------------------------------------------------------------------------------
@ -2059,7 +2082,7 @@ void DialogSeamAllowance::InitNodesList()
for (int i = 0; i < nodes.size(); ++i)
{
const VPieceNode node = nodes.at(i);
if (node.GetTypeTool() == Tool::NodePoint)
if (node.GetTypeTool() == Tool::NodePoint && not node.IsExcluded())
{
const QString name = GetNodeName(node);
@ -2283,7 +2306,7 @@ void DialogSeamAllowance::InitCSAPoint(QComboBox *box)
for (int i = 0; i < nodes.size(); ++i)
{
const VPieceNode &node = nodes.at(i);
if (node.GetTypeTool() == Tool::NodePoint)
if (node.GetTypeTool() == Tool::NodePoint && not node.IsExcluded())
{
const QString name = GetNodeName(node);
box->addItem(name, node.GetId());

View File

@ -58,8 +58,13 @@ const QString VAbstractNode::AttrIdTool = QStringLiteral("idTool");
*/
VAbstractNode::VAbstractNode(VAbstractPattern *doc, VContainer *data, const quint32 &id, const quint32 &idNode,
const QString &drawName, const quint32 &idTool, QObject *parent)
: VAbstractTool(doc, data, id, parent), parentType(ParentType::Item), idNode(idNode), idTool(idTool),
currentColor(Qt::black), m_drawName(drawName)
: VAbstractTool(doc, data, id, parent),
parentType(ParentType::Item),
idNode(idNode),
idTool(idTool),
currentColor(Qt::black),
m_drawName(drawName),
m_exluded(false)
{
_referens = 0;
}
@ -140,6 +145,18 @@ void VAbstractNode::GroupVisibility(quint32 object, bool visible)
Q_UNUSED(visible)
}
//---------------------------------------------------------------------------------------------------------------------
bool VAbstractNode::IsExluded() const
{
return m_exluded;
}
//---------------------------------------------------------------------------------------------------------------------
void VAbstractNode::SetExluded(bool exluded)
{
m_exluded = exluded;
}
//---------------------------------------------------------------------------------------------------------------------
void VAbstractNode::ToolCreation(const Source &typeCreation)
{

View File

@ -61,11 +61,12 @@ public:
virtual void GroupVisibility(quint32 object, bool visible) Q_DECL_OVERRIDE;
bool IsExluded() const;
void SetExluded(bool exluded);
protected:
ParentType parentType;
virtual void ToolCreation(const Source &typeCreation) Q_DECL_OVERRIDE;
protected:
/** @brief idNodenode id. */
quint32 idNode;
@ -77,11 +78,16 @@ protected:
QString m_drawName;
bool m_exluded;
void AddToModeling(const QDomElement &domElement);
virtual void ToolCreation(const Source &typeCreation) Q_DECL_OVERRIDE;
virtual void SetVisualization() Q_DECL_OVERRIDE {}
virtual void ShowNode()=0;
virtual void HideNode()=0;
private:
Q_DISABLE_COPY(VAbstractNode)
};
#endif // VABSTRACTNODE_H

View File

@ -321,7 +321,7 @@ void VNodePoint::RefreshLine()
//---------------------------------------------------------------------------------------------------------------------
void VNodePoint::ShowNode()
{
if (parentType != ParentType::Scene)
if (parentType != ParentType::Scene && not m_exluded)
{
show();
}

View File

@ -453,6 +453,7 @@ void VToolSeamAllowance::GroupVisibility(quint32 object, bool visible)
//---------------------------------------------------------------------------------------------------------------------
void VToolSeamAllowance::FullUpdateFromFile()
{
UpdateExcludeState();
RefreshGeometry();
}
@ -1207,6 +1208,24 @@ VToolSeamAllowance::VToolSeamAllowance(VAbstractPattern *doc, VContainer *data,
UpdateGrainline();
}
//---------------------------------------------------------------------------------------------------------------------
void VToolSeamAllowance::UpdateExcludeState()
{
const VPiece detail = VAbstractTool::data.GetPiece(id);
for (int i = 0; i< detail.GetPath().CountNodes(); ++i)
{
const VPieceNode &node = detail.GetPath().at(i);
if (node.GetTypeTool() == Tool::NodePoint)
{
VNodePoint *tool = qobject_cast<VNodePoint*>(doc->getTool(node.GetId()));
SCASSERT(tool != nullptr);
tool->SetExluded(node.IsExcluded());
tool->setVisible(not node.IsExcluded());//Hide excluded point
}
}
}
//---------------------------------------------------------------------------------------------------------------------
void VToolSeamAllowance::RefreshGeometry()
{
@ -1462,6 +1481,7 @@ void VToolSeamAllowance::InitNode(const VPieceNode &node, VMainGraphicsScene *sc
connect(tool, &VNodePoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
tool->setParentItem(parent);
tool->SetParentType(ParentType::Item);
tool->SetExluded(node.IsExcluded());
tool->setVisible(not node.IsExcluded());//Hide excluded point
doc->IncrementReferens(node.GetId());
break;

View File

@ -153,6 +153,7 @@ private:
VToolSeamAllowance(VAbstractPattern *doc, VContainer *data, const quint32 &id, const Source &typeCreation,
VMainGraphicsScene *scene, const QString &m_drawName, QGraphicsItem * parent = nullptr);
void UpdateExcludeState();
void RefreshGeometry();
void SaveDialogChange();
VPieceItem::MoveTypes FindLabelGeometry(const VPatternLabelData &labelData, qreal &rotationAngle, qreal &labelWidth,