A seam allowance node angle. Read, write and set in the dialog. Not handled in

seam allowance itself.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2016-11-19 13:44:12 +02:00
parent d38f318569
commit c21aedc541
10 changed files with 132 additions and 4 deletions

View File

@ -751,6 +751,7 @@ void VPattern::ParseDetailNodes(const QDomElement &domElement, VPiece &detail) c
const bool reverse = GetParametrUInt(element, VToolSeamAllowance::AttrNodeReverse, "0"); const bool reverse = GetParametrUInt(element, VToolSeamAllowance::AttrNodeReverse, "0");
const qreal saBefore = GetParametrDouble(element, VToolSeamAllowance::AttrSABefore, "-1"); const qreal saBefore = GetParametrDouble(element, VToolSeamAllowance::AttrSABefore, "-1");
const qreal saAfter = GetParametrDouble(element, VToolSeamAllowance::AttrSAAfter, "-1"); const qreal saAfter = GetParametrDouble(element, VToolSeamAllowance::AttrSAAfter, "-1");
const PieceNodeAngle angle = static_cast<PieceNodeAngle>(GetParametrUInt(element, AttrAngle, "0"));
const QString t = GetParametrString(element, AttrType, VToolSeamAllowance::NodePoint); const QString t = GetParametrString(element, AttrType, VToolSeamAllowance::NodePoint);
Tool tool; Tool tool;
@ -776,6 +777,7 @@ void VPattern::ParseDetailNodes(const QDomElement &domElement, VPiece &detail) c
VPieceNode node(id, tool, reverse); VPieceNode node(id, tool, reverse);
node.SetSABefore(saBefore); node.SetSABefore(saBefore);
node.SetSAAfter(saAfter); node.SetSAAfter(saAfter);
node.SetAngleType(angle);
detail.Append(node); detail.Append(node);
} }
} }

View File

@ -404,6 +404,7 @@
<xs:attribute name="reverse" type="xs:unsignedInt"></xs:attribute> <xs:attribute name="reverse" type="xs:unsignedInt"></xs:attribute>
<xs:attribute name="before" type="xs:double"></xs:attribute> <xs:attribute name="before" type="xs:double"></xs:attribute>
<xs:attribute name="after" type="xs:double"></xs:attribute> <xs:attribute name="after" type="xs:double"></xs:attribute>
<xs:attribute name="angle" type="nodeAngle"></xs:attribute>
</xs:complexType> </xs:complexType>
</xs:element> </xs:element>
</xs:sequence> </xs:sequence>
@ -638,4 +639,14 @@
<xs:enumeration value="2"/><!--New version--> <xs:enumeration value="2"/><!--New version-->
</xs:restriction> </xs:restriction>
</xs:simpleType> </xs:simpleType>
<xs:simpleType name="nodeAngle">
<xs:restriction base="xs:unsignedInt">
<xs:enumeration value="0"/><!--by length-->
<xs:enumeration value="1"/><!--by points intersections-->
<xs:enumeration value="2"/><!--by second edge symmetry-->
<xs:enumeration value="3"/><!--by first edge symmetry-->
<xs:enumeration value="4"/><!--by first edge right angle-->
<xs:enumeration value="5"/><!--by first edge right angle-->
</xs:restriction>
</xs:simpleType>
</xs:schema> </xs:schema>

View File

@ -64,6 +64,16 @@ enum class Source : char { FromGui, FromFile, FromTool };
enum class NodeUsage : bool {NotInUse = false, InUse = true}; enum class NodeUsage : bool {NotInUse = false, InUse = true};
enum class SelectionType : bool {ByMousePress, ByMouseRelease}; enum class SelectionType : bool {ByMousePress, ByMouseRelease};
enum class PieceNodeAngle : unsigned char
{
ByLength = 0,
ByPointsIntersection,
ByFirstEdgeSymmetry,
BySecondEdgeSymmetry,
ByFirstEdgeRightAngle,
BySecondEdgeRightAngle
};
typedef unsigned char ToolVisHolderType; typedef unsigned char ToolVisHolderType;
enum class Tool : ToolVisHolderType enum class Tool : ToolVisHolderType
{ {

View File

@ -150,6 +150,18 @@ void VPieceNode::SetSAAfter(qreal value)
} }
} }
//---------------------------------------------------------------------------------------------------------------------
PieceNodeAngle VPieceNode::GetAngleType() const
{
return d->m_angleType;
}
//---------------------------------------------------------------------------------------------------------------------
void VPieceNode::SetAngleType(PieceNodeAngle type)
{
d->m_angleType = type;
}
// Friend functions // Friend functions
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QDataStream& operator<<(QDataStream& out, const VPieceNode& p) QDataStream& operator<<(QDataStream& out, const VPieceNode& p)

View File

@ -65,6 +65,9 @@ public:
qreal GetSAAfter() const; qreal GetSAAfter() const;
qreal GetSAAfter(Unit unit) const; qreal GetSAAfter(Unit unit) const;
void SetSAAfter(qreal value); void SetSAAfter(qreal value);
PieceNodeAngle GetAngleType() const;
void SetAngleType(PieceNodeAngle type);
private: private:
QSharedDataPointer<VPieceNodeData> d; QSharedDataPointer<VPieceNodeData> d;
}; };

View File

@ -44,7 +44,8 @@ public:
m_typeTool(Tool::NodePoint), m_typeTool(Tool::NodePoint),
m_reverse(false), m_reverse(false),
m_saBefore(-1), m_saBefore(-1),
m_saAfter(-1) m_saAfter(-1),
m_angleType(PieceNodeAngle::ByLength)
{} {}
VPieceNodeData(quint32 id, Tool typeTool, bool reverse) VPieceNodeData(quint32 id, Tool typeTool, bool reverse)
@ -52,7 +53,8 @@ public:
m_typeTool(typeTool), m_typeTool(typeTool),
m_reverse(reverse), m_reverse(reverse),
m_saBefore(-1), m_saBefore(-1),
m_saAfter(-1) m_saAfter(-1),
m_angleType(PieceNodeAngle::ByLength)
{ {
if (m_typeTool == Tool::NodePoint) if (m_typeTool == Tool::NodePoint)
{ {
@ -66,7 +68,8 @@ public:
m_typeTool(node.m_typeTool), m_typeTool(node.m_typeTool),
m_reverse(node.m_reverse), m_reverse(node.m_reverse),
m_saBefore(node.m_saBefore), m_saBefore(node.m_saBefore),
m_saAfter(node.m_saAfter) m_saAfter(node.m_saAfter),
m_angleType(node.m_angleType)
{} {}
~VPieceNodeData(); ~VPieceNodeData();
@ -83,6 +86,8 @@ public:
qreal m_saBefore; qreal m_saBefore;
qreal m_saAfter; qreal m_saAfter;
PieceNodeAngle m_angleType;
private: private:
VPieceNodeData &operator=(const VPieceNodeData &) Q_DECL_EQ_DELETE; VPieceNodeData &operator=(const VPieceNodeData &) Q_DECL_EQ_DELETE;
}; };

View File

@ -87,10 +87,16 @@ DialogSeamAllowance::DialogSeamAllowance(const VContainer *data, const quint32 &
connect(ui->listWidget->model(), &QAbstractItemModel::rowsMoved, this, &DialogSeamAllowance::ListChanged); connect(ui->listWidget->model(), &QAbstractItemModel::rowsMoved, this, &DialogSeamAllowance::ListChanged);
connect(ui->checkBoxSeams, &QCheckBox::toggled, this, &DialogSeamAllowance::EnableSeamAllowance); connect(ui->checkBoxSeams, &QCheckBox::toggled, this, &DialogSeamAllowance::EnableSeamAllowance);
InitNodeAngles();
connect(ui->comboBoxAngle, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
&DialogSeamAllowance::NodeAngleChanged);
if (not applyAllowed) if (not applyAllowed)
{ {
vis = new VisToolPiece(data); vis = new VisToolPiece(data);
} }
ui->tabWidget->setCurrentIndex(1);// Show always first tab active on start.
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -307,9 +313,11 @@ void DialogSeamAllowance::NodeChanged(int index)
ui->doubleSpinBoxSAAfter->setDisabled(true); ui->doubleSpinBoxSAAfter->setDisabled(true);
ui->pushButtonDefBefore->setDisabled(true); ui->pushButtonDefBefore->setDisabled(true);
ui->pushButtonDefAfter->setDisabled(true); ui->pushButtonDefAfter->setDisabled(true);
ui->comboBoxAngle->setDisabled(true);
ui->doubleSpinBoxSABefore->blockSignals(true); ui->doubleSpinBoxSABefore->blockSignals(true);
ui->doubleSpinBoxSAAfter->blockSignals(true); ui->doubleSpinBoxSAAfter->blockSignals(true);
ui->comboBoxAngle->blockSignals(true);
if (index != -1) if (index != -1)
{ {
@ -322,10 +330,11 @@ void DialogSeamAllowance::NodeChanged(int index)
const int nodeIndex = piece.indexOfNode(id); const int nodeIndex = piece.indexOfNode(id);
if (nodeIndex != -1) if (nodeIndex != -1)
{ {
const VPieceNode node = piece.at(nodeIndex); const VPieceNode &node = piece.at(nodeIndex);
ui->doubleSpinBoxSABefore->setEnabled(true); ui->doubleSpinBoxSABefore->setEnabled(true);
ui->doubleSpinBoxSAAfter->setEnabled(true); ui->doubleSpinBoxSAAfter->setEnabled(true);
ui->comboBoxAngle->setEnabled(true);
qreal w1 = node.GetSABefore(); qreal w1 = node.GetSABefore();
if (w1 < 0) if (w1 < 0)
@ -348,16 +357,54 @@ void DialogSeamAllowance::NodeChanged(int index)
ui->pushButtonDefAfter->setEnabled(true); ui->pushButtonDefAfter->setEnabled(true);
} }
ui->doubleSpinBoxSAAfter->setValue(w2); ui->doubleSpinBoxSAAfter->setValue(w2);
const int index = ui->comboBoxAngle->findData(static_cast<unsigned char>(node.GetAngleType()));
if (index != -1)
{
ui->comboBoxAngle->setCurrentIndex(index);
}
} }
} }
else else
{ {
ui->doubleSpinBoxSABefore->setValue(0); ui->doubleSpinBoxSABefore->setValue(0);
ui->doubleSpinBoxSAAfter->setValue(0); ui->doubleSpinBoxSAAfter->setValue(0);
ui->comboBoxAngle->setCurrentIndex(-1);
} }
ui->doubleSpinBoxSABefore->blockSignals(false); ui->doubleSpinBoxSABefore->blockSignals(false);
ui->doubleSpinBoxSAAfter->blockSignals(false); ui->doubleSpinBoxSAAfter->blockSignals(false);
ui->comboBoxAngle->blockSignals(false);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogSeamAllowance::NodeAngleChanged(int index)
{
const int i = ui->comboBoxNodes->currentIndex();
if (i != -1 && index != -1)
{
#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0)
const quint32 id = ui->comboBoxNodes->itemData(i).toUInt();
#else
const quint32 id = ui->comboBoxNodes->currentData().toUInt();
#endif
QListWidgetItem *rowItem = GetItemById(id);
if (rowItem)
{
#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0)
const PieceNodeAngle angle = static_cast<PieceNodeAngle>(ui->comboBoxAngle->itemData(index).toUInt());
#else
const PieceNodeAngle angle = static_cast<PieceNodeAngle>(ui->comboBoxAngle->currentData().toUInt());
#endif
VPieceNode rowNode = qvariant_cast<VPieceNode>(rowItem->data(Qt::UserRole));
rowNode.SetAngleType(angle);
rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode));
ListChanged();
}
}
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -601,6 +648,24 @@ void DialogSeamAllowance::InitNodesList()
} }
} }
//---------------------------------------------------------------------------------------------------------------------
void DialogSeamAllowance::InitNodeAngles()
{
ui->comboBoxAngle->clear();
ui->comboBoxAngle->addItem(tr("by length"), static_cast<unsigned char>(PieceNodeAngle::ByLength));
ui->comboBoxAngle->addItem(tr("by points intersetions"),
static_cast<unsigned char>(PieceNodeAngle::ByPointsIntersection));
ui->comboBoxAngle->addItem(tr("by second edge symmetry"),
static_cast<unsigned char>(PieceNodeAngle::BySecondEdgeSymmetry));
ui->comboBoxAngle->addItem(tr("by first edge symmetry"),
static_cast<unsigned char>(PieceNodeAngle::ByFirstEdgeSymmetry));
ui->comboBoxAngle->addItem(tr("by first edge right angle"),
static_cast<unsigned char>(PieceNodeAngle::ByFirstEdgeRightAngle));
ui->comboBoxAngle->addItem(tr("by second edge right angle"),
static_cast<unsigned char>(PieceNodeAngle::BySecondEdgeRightAngle));
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QListWidgetItem *DialogSeamAllowance::GetItemById(quint32 id) QListWidgetItem *DialogSeamAllowance::GetItemById(quint32 id)
{ {

View File

@ -64,6 +64,7 @@ private slots:
void ListChanged(); void ListChanged();
void EnableSeamAllowance(bool enable); void EnableSeamAllowance(bool enable);
void NodeChanged(int index); void NodeChanged(int index);
void NodeAngleChanged(int index);
void ReturnDefBefore(); void ReturnDefBefore();
void ReturnDefAfter(); void ReturnDefAfter();
void ChangedSABefore(double d); void ChangedSABefore(double d);
@ -87,6 +88,7 @@ private:
bool MainPathIsClockwise() const; bool MainPathIsClockwise() const;
QString GetNodeName(const VPieceNode &node) const; QString GetNodeName(const VPieceNode &node) const;
void InitNodesList(); void InitNodesList();
void InitNodeAngles();
QListWidgetItem *GetItemById(quint32 id); QListWidgetItem *GetItemById(quint32 id);

View File

@ -256,6 +256,16 @@
</item> </item>
</layout> </layout>
</item> </item>
<item row="3" column="0">
<widget class="QLabel" name="labelAngle">
<property name="text">
<string>Angle:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QComboBox" name="comboBoxAngle"/>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>

View File

@ -238,6 +238,14 @@ void VToolSeamAllowance::AddNode(VAbstractPattern *doc, QDomElement &domElement,
qDebug()<<"May be wrong tool type!!! Ignoring."<<Q_FUNC_INFO; qDebug()<<"May be wrong tool type!!! Ignoring."<<Q_FUNC_INFO;
break; break;
} }
const unsigned char angleType = static_cast<unsigned char>(node.GetAngleType());
if (angleType > 0)
{
doc->SetAttribute(nod, AttrAngle, angleType);
}
domElement.appendChild(nod); domElement.appendChild(nod);
} }