At least one arrow has to be present on a grainline

--HG--
branch : feature
This commit is contained in:
BojanKverh 2016-10-25 23:00:42 +02:00
parent 21cd56463c
commit 96cfc52202
13 changed files with 129 additions and 98 deletions

View File

@ -730,8 +730,9 @@ void VPattern::ParseDetailElement(const QDomElement &domElement, const Document
detail.GetGrainlineGeometry().SetLength(qsLength); detail.GetGrainlineGeometry().SetLength(qsLength);
QString qsRot = GetParametrString(element, VToolDetail::AttrRotation, "90"); QString qsRot = GetParametrString(element, VToolDetail::AttrRotation, "90");
detail.GetGrainlineGeometry().SetRotation(qsRot); detail.GetGrainlineGeometry().SetRotation(qsRot);
detail.GetGrainlineGeometry().SetFrontArrow(GetParametrBool(element, AttrFront, trueStr)); VGrainlineGeometry::ArrowType eAT =
detail.GetGrainlineGeometry().SetRearArrow(GetParametrBool(element, AttrRear, trueStr)); VGrainlineGeometry::ArrowType(GetParametrUInt(element, AttrArrows, "0"));
detail.GetGrainlineGeometry().SetArrowType(eAT);
} }
} }
} }

View File

@ -384,8 +384,7 @@
<xs:attribute name="my" type="xs:double"></xs:attribute> <xs:attribute name="my" type="xs:double"></xs:attribute>
<xs:attribute name="length" type="xs:string"></xs:attribute> <xs:attribute name="length" type="xs:string"></xs:attribute>
<xs:attribute name="rotation" type="xs:string"></xs:attribute> <xs:attribute name="rotation" type="xs:string"></xs:attribute>
<xs:attribute name="front" type="xs:boolean"></xs:attribute> <xs:attribute name="arrows" type="arrowType"></xs:attribute>
<xs:attribute name="rear" type="xs:boolean"></xs:attribute>
</xs:complexType> </xs:complexType>
</xs:element> </xs:element>
<xs:element name="node" maxOccurs="unbounded"> <xs:element name="node" maxOccurs="unbounded">
@ -600,4 +599,11 @@
<xs:enumeration value="1"/><!--Cut on Fold--> <xs:enumeration value="1"/><!--Cut on Fold-->
</xs:restriction> </xs:restriction>
</xs:simpleType> </xs:simpleType>
<xs:simpleType name="arrowType">
<xs:restriction base="xs:unsignedInt">
<xs:enumeration value="0"/><!--Both-->
<xs:enumeration value="1"/><!--Front-->
<xs:enumeration value="2"/><!--Rear-->
</xs:restriction>
</xs:simpleType>
</xs:schema> </xs:schema>

View File

@ -100,8 +100,7 @@ const QString VAbstractPattern::AttrMaterial = QStringLiteral("material")
const QString VAbstractPattern::AttrUserDefined = QStringLiteral("userDef"); const QString VAbstractPattern::AttrUserDefined = QStringLiteral("userDef");
const QString VAbstractPattern::AttrCutNumber = QStringLiteral("cutNumber"); const QString VAbstractPattern::AttrCutNumber = QStringLiteral("cutNumber");
const QString VAbstractPattern::AttrPlacement = QStringLiteral("placement"); const QString VAbstractPattern::AttrPlacement = QStringLiteral("placement");
const QString VAbstractPattern::AttrFront = QStringLiteral("front"); const QString VAbstractPattern::AttrArrows = QStringLiteral("arrows");
const QString VAbstractPattern::AttrRear = QStringLiteral("rear");
const QString VAbstractPattern::AttrAll = QStringLiteral("all"); const QString VAbstractPattern::AttrAll = QStringLiteral("all");

View File

@ -205,8 +205,7 @@ public:
static const QString AttrUserDefined; static const QString AttrUserDefined;
static const QString AttrCutNumber; static const QString AttrCutNumber;
static const QString AttrPlacement; static const QString AttrPlacement;
static const QString AttrFront; static const QString AttrArrows;
static const QString AttrRear;
static const QString AttrAll; static const QString AttrAll;

View File

@ -220,7 +220,7 @@ void VLayoutDetail::SetGrainline(const VGrainlineGeometry& geom, const VContaine
v << pt1; v << pt1;
if (geom.HasFrontArrow() == true) { if (geom.GetArrowType() != VGrainlineGeometry::atRear) {
pt.setX(pt1.x() + dArrowLen * qCos(dAng + dArrowAng)); pt.setX(pt1.x() + dArrowLen * qCos(dAng + dArrowAng));
pt.setY(pt1.y() - dArrowLen * qSin(dAng + dArrowAng)); pt.setY(pt1.y() - dArrowLen * qSin(dAng + dArrowAng));
v << pt; v << pt;
@ -233,7 +233,7 @@ void VLayoutDetail::SetGrainline(const VGrainlineGeometry& geom, const VContaine
v << pt2; v << pt2;
if (geom.HasRearArrow() == true) if (geom.GetArrowType() != VGrainlineGeometry::atFront)
{ {
dAng += M_PI; dAng += M_PI;

View File

@ -33,7 +33,7 @@
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VGrainlineGeometry::VGrainlineGeometry() VGrainlineGeometry::VGrainlineGeometry()
:m_ptPos(0, 0), m_qsLength(), m_qsRotation(), m_bVisible(false), m_bFrontArrow(true), m_bRearArrow(true) :m_ptPos(0, 0), m_qsLength(), m_qsRotation(), m_bVisible(false), m_eArrowType(atBoth)
{} {}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -99,30 +99,16 @@ void VGrainlineGeometry::SetVisible(bool bVisible)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
bool VGrainlineGeometry::HasFrontArrow() const VGrainlineGeometry::ArrowType VGrainlineGeometry::GetArrowType() const
{ {
return m_bFrontArrow; return m_eArrowType;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VGrainlineGeometry::SetFrontArrow(bool bVal) void VGrainlineGeometry::SetArrowType(ArrowType eAT)
{ {
m_bFrontArrow = bVal; m_eArrowType = eAT;
}
//---------------------------------------------------------------------------------------------------------------------
bool VGrainlineGeometry::HasRearArrow() const
{
return m_bRearArrow;
}
//---------------------------------------------------------------------------------------------------------------------
void VGrainlineGeometry::SetRearArrow(bool bVal)
{
m_bRearArrow = bVal;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -40,6 +40,15 @@ class QPointF;
*/ */
class VGrainlineGeometry class VGrainlineGeometry
{ {
public:
// denotes the type of arrow for the grainline
enum ArrowType
{
atBoth,
atFront,
atRear
};
public: public:
VGrainlineGeometry(); VGrainlineGeometry();
~VGrainlineGeometry(); ~VGrainlineGeometry();
@ -53,10 +62,8 @@ public:
void SetRotation(const QString& qsRot); void SetRotation(const QString& qsRot);
bool IsVisible() const; bool IsVisible() const;
void SetVisible(bool bVisible); void SetVisible(bool bVisible);
bool HasFrontArrow() const; ArrowType GetArrowType() const;
void SetFrontArrow(bool bVal); void SetArrowType(ArrowType eAT);
bool HasRearArrow() const;
void SetRearArrow(bool bVal);
private: private:
/** /**
@ -76,13 +83,9 @@ private:
*/ */
bool m_bVisible; bool m_bVisible;
/** /**
* @brief m_bFrontArrow front arrow flag * @brief m_eArrowType type of arrow on the grainline
*/ */
bool m_bFrontArrow; ArrowType m_eArrowType;
/**
* @brief m_bRearArrow back arrow flag
*/
bool m_bRearArrow;
}; };
#endif // VGRAINLINEGEOMETRY_H #endif // VGRAINLINEGEOMETRY_H

View File

@ -168,6 +168,10 @@ DialogDetail::DialogDetail(const VContainer *data, const quint32 &toolId, QWidge
SetAddMode(); SetAddMode();
EnableGrainlineRotation(); EnableGrainlineRotation();
ui.comboBoxArrow->addItem(tr("Both"));
ui.comboBoxArrow->addItem(tr("Just front"));
ui.comboBoxArrow->addItem(tr("Just rear"));
ui.tabWidget->setCurrentIndex(0); ui.tabWidget->setCurrentIndex(0);
m_iRotBaseHeight = ui.lineEditRotFormula->height(); m_iRotBaseHeight = ui.lineEditRotFormula->height();
@ -486,11 +490,9 @@ VDetail DialogDetail::CreateDetail() const
detail.GetGrainlineGeometry().SetVisible(ui.checkBoxGrainline->isChecked()); detail.GetGrainlineGeometry().SetVisible(ui.checkBoxGrainline->isChecked());
detail.GetGrainlineGeometry().SetRotation(ui.lineEditRotFormula->toPlainText()); detail.GetGrainlineGeometry().SetRotation(ui.lineEditRotFormula->toPlainText());
detail.GetGrainlineGeometry().SetLength(ui.lineEditLenFormula->toPlainText()); detail.GetGrainlineGeometry().SetLength(ui.lineEditLenFormula->toPlainText());
detail.GetGrainlineGeometry().SetFrontArrow(ui.checkBoxFrontArrow->isChecked()); VGrainlineGeometry::ArrowType eAT = VGrainlineGeometry::ArrowType(ui.comboBoxArrow->currentIndex());
detail.GetGrainlineGeometry().SetRearArrow(ui.checkBoxRearArrow->isChecked()); detail.GetGrainlineGeometry().SetArrowType(eAT);
qDebug() << "DIALOG ARROWS" << detail.GetGrainlineGeometry().HasFrontArrow()
<< detail.GetGrainlineGeometry().HasRearArrow();
return detail; return detail;
} }
@ -564,8 +566,7 @@ void DialogDetail::setDetail(const VDetail &value)
ui.checkBoxGrainline->setChecked(detail.GetGrainlineGeometry().IsVisible()); ui.checkBoxGrainline->setChecked(detail.GetGrainlineGeometry().IsVisible());
ui.lineEditRotFormula->setPlainText(detail.GetGrainlineGeometry().GetRotation()); ui.lineEditRotFormula->setPlainText(detail.GetGrainlineGeometry().GetRotation());
ui.lineEditLenFormula->setPlainText(detail.GetGrainlineGeometry().GetLength()); ui.lineEditLenFormula->setPlainText(detail.GetGrainlineGeometry().GetLength());
ui.checkBoxFrontArrow->setChecked(detail.GetGrainlineGeometry().HasFrontArrow()); ui.comboBoxArrow->setCurrentIndex(int(detail.GetGrainlineGeometry().GetArrowType()));
ui.checkBoxRearArrow->setChecked(detail.GetGrainlineGeometry().HasRearArrow());
m_oldData = detail.GetPatternPieceData(); m_oldData = detail.GetPatternPieceData();
m_oldGeom = detail.GetPatternInfo(); m_oldGeom = detail.GetPatternInfo();

View File

@ -977,30 +977,70 @@
</property> </property>
<layout class="QHBoxLayout" name="horizontalLayout_5"> <layout class="QHBoxLayout" name="horizontalLayout_5">
<item> <item>
<widget class="QCheckBox" name="checkBoxFrontArrow"> <widget class="QLabel" name="labelEditLen_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="palette">
<palette>
<active>
<colorrole role="WindowText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
</active>
<inactive>
<colorrole role="WindowText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
</inactive>
<disabled>
<colorrole role="WindowText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>159</red>
<green>158</green>
<blue>158</blue>
</color>
</brush>
</colorrole>
</disabled>
</palette>
</property>
<property name="text"> <property name="text">
<string>Front arrow</string> <string>Arrows:</string>
</property> </property>
</widget> </widget>
</item> </item>
</layout>
</widget>
<widget class="QWidget" name="horizontalLayoutWidget_3">
<property name="geometry">
<rect>
<x>10</x>
<y>310</y>
<width>541</width>
<height>41</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item> <item>
<widget class="QCheckBox" name="checkBoxRearArrow"> <widget class="QComboBox" name="comboBoxArrow"/>
<property name="text"> </item>
<string>Rear arrow</string> <item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property> </property>
</widget> <property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item> </item>
</layout> </layout>
</widget> </widget>

View File

@ -54,7 +54,7 @@
VGrainlineItem::VGrainlineItem(QGraphicsItem* pParent) VGrainlineItem::VGrainlineItem(QGraphicsItem* pParent)
:QGraphicsObject(pParent), m_eMode(VGrainlineItem::mNormal), m_bReleased(false), m_dRotation(0), m_dStartRotation(0), :QGraphicsObject(pParent), m_eMode(VGrainlineItem::mNormal), m_bReleased(false), m_dRotation(0), m_dStartRotation(0),
m_dLength(0), m_rectBoundingBox(), m_polyBound(), m_ptStartPos(), m_ptStartMove(), m_dScale(1), m_polyResize(), m_dLength(0), m_rectBoundingBox(), m_polyBound(), m_ptStartPos(), m_ptStartMove(), m_dScale(1), m_polyResize(),
m_ptStart(), m_ptFinish(), m_ptCenter(), m_dAngle(0), m_bFrontArrow(false), m_bRearArrow(false) m_ptStart(), m_ptFinish(), m_ptCenter(), m_dAngle(0), m_eArrowType(VGrainlineGeometry::atBoth)
{ {
m_rectBoundingBox.setTopLeft(QPointF(0, 0)); m_rectBoundingBox.setTopLeft(QPointF(0, 0));
setAcceptHoverEvents(true); setAcceptHoverEvents(true);
@ -97,7 +97,7 @@ void VGrainlineItem::paint(QPainter* pP, const QStyleOptionGraphicsItem* pOption
QPolygonF poly; QPolygonF poly;
QPointF ptA; QPointF ptA;
qreal dArrLen = ARROW_LENGTH*m_dScale; qreal dArrLen = ARROW_LENGTH*m_dScale;
if (m_bFrontArrow == true) if (m_eArrowType != VGrainlineGeometry::atRear)
{ {
// first arrow // first arrow
poly << pt1; poly << pt1;
@ -109,7 +109,7 @@ void VGrainlineItem::paint(QPainter* pP, const QStyleOptionGraphicsItem* pOption
poly << ptA; poly << ptA;
pP->drawPolygon(poly); pP->drawPolygon(poly);
} }
if (m_bRearArrow == true) if (m_eArrowType != VGrainlineGeometry::atFront)
{ {
// second arrow // second arrow
poly.clear(); poly.clear();
@ -177,7 +177,8 @@ void VGrainlineItem::paint(QPainter* pP, const QStyleOptionGraphicsItem* pOption
* @param dRotation rotation of the grainline in [degrees] * @param dRotation rotation of the grainline in [degrees]
* @param dLength length of the grainline in user's units * @param dLength length of the grainline in user's units
*/ */
void VGrainlineItem::UpdateGeometry(const QPointF& ptPos, qreal dRotation, qreal dLength, bool bFA, bool bRA) void VGrainlineItem::UpdateGeometry(const QPointF& ptPos, qreal dRotation, qreal dLength,
VGrainlineGeometry::ArrowType eAT)
{ {
m_dRotation = qDegreesToRadians(dRotation); m_dRotation = qDegreesToRadians(dRotation);
m_dLength = dLength; m_dLength = dLength;
@ -191,8 +192,7 @@ void VGrainlineItem::UpdateGeometry(const QPointF& ptPos, qreal dRotation, qreal
pt.setY(pt.y() + dY); pt.setY(pt.y() + dY);
} }
setPos(pt); setPos(pt);
m_bFrontArrow = bFA; m_eArrowType = eAT;
m_bRearArrow = bRA;
UpdateRectangle(); UpdateRectangle();
UpdateBox(); UpdateBox();

View File

@ -54,7 +54,8 @@ public:
virtual ~VGrainlineItem(); virtual ~VGrainlineItem();
void paint(QPainter* pP, const QStyleOptionGraphicsItem* pOption, QWidget* pWidget); void paint(QPainter* pP, const QStyleOptionGraphicsItem* pOption, QWidget* pWidget);
void UpdateGeometry(const QPointF& ptPos, qreal dRotation, qreal dLength, bool bFA, bool bRA); void UpdateGeometry(const QPointF& ptPos, qreal dRotation, qreal dLength,
VGrainlineGeometry::ArrowType eAT);
QRectF boundingRect() const; QRectF boundingRect() const;
void Reset(); void Reset();
@ -96,8 +97,7 @@ private:
QPointF m_ptCenter; QPointF m_ptCenter;
QPointF m_ptRotCenter; QPointF m_ptRotCenter;
qreal m_dAngle; qreal m_dAngle;
bool m_bFrontArrow; VGrainlineGeometry::ArrowType m_eArrowType;
bool m_bRearArrow;
}; };
#endif // VGRAINLINEITEM_H #endif // VGRAINLINEITEM_H

View File

@ -509,8 +509,7 @@ void VToolDetail::AddToFile()
doc->SetAttribute(domData, AttrMy, glGeom.GetPos().y()); doc->SetAttribute(domData, AttrMy, glGeom.GetPos().y());
doc->SetAttribute(domData, AttrLength, glGeom.GetLength()); doc->SetAttribute(domData, AttrLength, glGeom.GetLength());
doc->SetAttribute(domData, AttrRotation, glGeom.GetRotation()); doc->SetAttribute(domData, AttrRotation, glGeom.GetRotation());
doc->SetAttribute(domData, VAbstractPattern::AttrFront, glGeom.HasFrontArrow() == true? trueStr : falseStr); doc->SetAttribute(domData, VAbstractPattern::AttrArrows, int(glGeom.GetArrowType()));
doc->SetAttribute(domData, VAbstractPattern::AttrRear, glGeom.HasRearArrow() == true? trueStr : falseStr);
qDebug() << "XML ROTATION" << glGeom.GetRotation(); qDebug() << "XML ROTATION" << glGeom.GetRotation();
// nodes // nodes
@ -590,8 +589,7 @@ void VToolDetail::RefreshDataInFile()
doc->SetAttribute(domData, AttrMy, glGeom.GetPos().y()); doc->SetAttribute(domData, AttrMy, glGeom.GetPos().y());
doc->SetAttribute(domData, AttrLength, glGeom.GetLength()); doc->SetAttribute(domData, AttrLength, glGeom.GetLength());
doc->SetAttribute(domData, AttrRotation, glGeom.GetRotation()); doc->SetAttribute(domData, AttrRotation, glGeom.GetRotation());
doc->SetAttribute(domData, VAbstractPattern::AttrFront, glGeom.HasFrontArrow() == true? trueStr : falseStr); doc->SetAttribute(domData, VAbstractPattern::AttrArrows, int(glGeom.GetArrowType()));
doc->SetAttribute(domData, VAbstractPattern::AttrRear, glGeom.HasRearArrow() == true? trueStr : falseStr);
// nodes // nodes
for (int i = 0; i < det.CountNode(); ++i) for (int i = 0; i < det.CountNode(); ++i)
@ -954,8 +952,7 @@ void VToolDetail::UpdateGrainline()
} }
grainLine->UpdateGeometry(geom.GetPos(), dRotation, ToPixel(dLength, *VDataTool::data.GetPatternUnit()), grainLine->UpdateGeometry(geom.GetPos(), dRotation, ToPixel(dLength, *VDataTool::data.GetPatternUnit()),
geom.HasFrontArrow(), geom.HasRearArrow()); geom.GetArrowType());
qDebug() << "ARROWS" << geom.HasFrontArrow() << geom.HasRearArrow();
grainLine->show(); grainLine->show();
} }
else else

View File

@ -210,8 +210,7 @@ void SaveDetailOptions::SaveGrainline(QDomElement &domElement, const VDetail &de
doc->SetAttribute(domData, AttrMy, glGeom.GetPos().y()); doc->SetAttribute(domData, AttrMy, glGeom.GetPos().y());
doc->SetAttribute(domData, AttrLength, glGeom.GetLength()); doc->SetAttribute(domData, AttrLength, glGeom.GetLength());
doc->SetAttribute(domData, VToolDetail::AttrRotation, glGeom.GetRotation()); doc->SetAttribute(domData, VToolDetail::AttrRotation, glGeom.GetRotation());
doc->SetAttribute(domData, VAbstractPattern::AttrFront, glGeom.HasFrontArrow() == true? trueStr : falseStr); doc->SetAttribute(domData, VAbstractPattern::AttrArrows, int(glGeom.GetArrowType()));
doc->SetAttribute(domData, VAbstractPattern::AttrRear, glGeom.HasRearArrow() == true? trueStr : falseStr);
domElement.appendChild(domData); domElement.appendChild(domData);
} }