Grainline now can be controlled by center pin point.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2017-03-10 16:22:19 +02:00
parent fb402f84b7
commit af3735ea23
9 changed files with 176 additions and 83 deletions

View File

@ -1907,6 +1907,7 @@ void DialogSeamAllowance::InitPinsTab()
//---------------------------------------------------------------------------------------------------------------------
void DialogSeamAllowance::InitAllPinComboboxes()
{
InitPinPoint(ui->comboBoxGrainlineCenterPin);
InitPinPoint(ui->comboBoxGrainlineTopPin);
InitPinPoint(ui->comboBoxGrainlineBottomPin);

View File

@ -1523,6 +1523,9 @@
</item>
<item>
<layout class="QFormLayout" name="formLayout_8">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::ExpandingFieldsGrow</enum>
</property>
<item row="0" column="0">
<widget class="QLabel" name="labelCenter">
<property name="text">
@ -1544,6 +1547,9 @@
</item>
<item>
<layout class="QFormLayout" name="formLayout_7">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::ExpandingFieldsGrow</enum>
</property>
<item row="0" column="0">
<widget class="QLabel" name="labelGrainlineTopPin">
<property name="text">
@ -1575,6 +1581,9 @@
</item>
<item>
<layout class="QFormLayout" name="formLayout">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::ExpandingFieldsGrow</enum>
</property>
<item row="0" column="0">
<widget class="QLabel" name="labelEditLen_2">
<property name="sizePolicy">

View File

@ -495,7 +495,7 @@ void VToolSeamAllowance::UpdateLabel()
QPointF pos;
qreal labelWidth = 0;
qreal labelHeight = 0;
const VTextGraphicsItem::MoveType type = FindLabelGeometry(labelData, labelWidth, labelHeight, pos);
const VTextGraphicsItem::MoveTypes type = FindLabelGeometry(labelData, labelWidth, labelHeight, pos);
m_dataLabel->SetMoveType(type);
QFont fnt = qApp->font();
@ -544,7 +544,7 @@ void VToolSeamAllowance::UpdatePatternInfo()
QPointF pos;
qreal labelWidth = 0;
qreal labelHeight = 0;
const VTextGraphicsItem::MoveType type = FindLabelGeometry(geom, labelWidth, labelHeight, pos);
const VTextGraphicsItem::MoveTypes type = FindLabelGeometry(geom, labelWidth, labelHeight, pos);
m_patternInfo->SetMoveType(type);
QFont fnt = qApp->font();
@ -596,8 +596,8 @@ void VToolSeamAllowance::UpdateGrainline()
qreal dRotation = 0;
qreal dLength = 0;
const VGrainlineItem::MoveType type = FindGrainlineGeometry(geom, dLength, dRotation, pos);
if (type == VGrainlineItem::Error)
const VGrainlineItem::MoveTypes type = FindGrainlineGeometry(geom, dLength, dRotation, pos);
if (type & VGrainlineItem::Error)
{
m_grainLine->hide();
return;
@ -1167,7 +1167,7 @@ void VToolSeamAllowance::SaveDialogChange()
}
//---------------------------------------------------------------------------------------------------------------------
VPieceItem::MoveType VToolSeamAllowance::FindLabelGeometry(const VPatternLabelData& labelData, qreal &labelWidth,
VPieceItem::MoveTypes VToolSeamAllowance::FindLabelGeometry(const VPatternLabelData& labelData, qreal &labelWidth,
qreal &labelHeight, QPointF &pos)
{
const quint32 topLeftPin = labelData.TopLeftPin();
@ -1186,7 +1186,7 @@ VPieceItem::MoveType VToolSeamAllowance::FindLabelGeometry(const VPatternLabelDa
pos = labelRect.topLeft();
return VTextGraphicsItem::OnlyRotatable;
return VTextGraphicsItem::IsRotatable;
}
catch(const VExceptionBadId &)
{
@ -1201,7 +1201,7 @@ VPieceItem::MoveType VToolSeamAllowance::FindLabelGeometry(const VPatternLabelDa
}
//---------------------------------------------------------------------------------------------------------------------
VPieceItem::MoveType VToolSeamAllowance::FindGrainlineGeometry(const VGrainlineData& geom, qreal &length,
VPieceItem::MoveTypes VToolSeamAllowance::FindGrainlineGeometry(const VGrainlineData& geom, qreal &length,
qreal &rotationAngle, QPointF &pos)
{
const quint32 topPin = geom.TopPin();
@ -1233,16 +1233,21 @@ VPieceItem::MoveType VToolSeamAllowance::FindGrainlineGeometry(const VGrainlineD
}
}
bool isResizable = false;
bool isRotatable = false;
VPieceItem::MoveTypes restrictions = VPieceItem::AllModifications;
try
{
isRotatable = qmu::QmuTokenParser::IsSingle(geom.GetRotation());
if (not qmu::QmuTokenParser::IsSingle(geom.GetRotation()))
{
restrictions &= ~ VPieceItem::IsRotatable;
}
Calculator cal1;
rotationAngle = cal1.EvalFormula(VAbstractTool::data.PlainVariables(), geom.GetRotation());
isResizable = qmu::QmuTokenParser::IsSingle(geom.GetLength());
if (not qmu::QmuTokenParser::IsSingle(geom.GetLength()))
{
restrictions &= ~ VPieceItem::IsResizable;
}
Calculator cal2;
length = cal2.EvalFormula(VAbstractTool::data.PlainVariables(), geom.GetLength());
@ -1253,25 +1258,35 @@ VPieceItem::MoveType VToolSeamAllowance::FindGrainlineGeometry(const VGrainlineD
return VPieceItem::Error;
}
pos = geom.GetPos();
if (isResizable && isRotatable)
const quint32 centerPin = geom.CenterPin();
if (centerPin != NULL_ID)
{
return VPieceItem::AllModifications;
try
{
const auto centerPinPoint = VAbstractTool::data.GeometricObject<VPointF>(centerPin);
const qreal cLength = ToPixel(length, *VDataTool::data.GetPatternUnit());
QLineF grainline(centerPinPoint->x(), centerPinPoint->y(),
centerPinPoint->x() + cLength / 2.0, centerPinPoint->y());
grainline.setAngle(rotationAngle);
grainline = QLineF(grainline.p2(), grainline.p1());
grainline.setLength(cLength);
pos = grainline.p2();
restrictions &= ~ VPieceItem::IsMovable;
}
catch(const VExceptionBadId &)
{
pos = geom.GetPos();
}
}
else
{
if (isResizable)
{
return VPieceItem::OnlyResizable;
}
if (isRotatable)
{
return VPieceItem::OnlyRotatable;
}
pos = geom.GetPos();
}
return VPieceItem::OnlyMovable;
return restrictions;
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -152,10 +152,10 @@ private:
void RefreshGeometry();
void SaveDialogChange();
VPieceItem::MoveType FindLabelGeometry(const VPatternLabelData &labelData, qreal &labelWidth, qreal &labelHeight,
QPointF &pos);
VPieceItem::MoveType FindGrainlineGeometry(const VGrainlineData &geom, qreal &length, qreal &rotationAngle,
QPointF &pos);
VPieceItem::MoveTypes FindLabelGeometry(const VPatternLabelData &labelData, qreal &labelWidth, qreal &labelHeight,
QPointF &pos);
VPieceItem::MoveTypes FindGrainlineGeometry(const VGrainlineData &geom, qreal &length, qreal &rotationAngle,
QPointF &pos);
void InitNodes(const VPiece &detail, VMainGraphicsScene *scene);
void InitCSAPaths(const VPiece &detail);

View File

@ -292,51 +292,66 @@ void VGrainlineItem::mousePressEvent(QGraphicsSceneMouseEvent* pME)
m_dAngle = GetAngle(mapToParent(pME->pos()));
m_ptRotCenter = m_ptCenter;
if (m_moveType == OnlyRotatable)
if ((m_moveType & AllModifications ) == AllModifications)
{
if (m_eMode != mRotate)
AllUserModifications(pME->pos());
setZValue(ACTIVE_Z);
Update();
}
else if (m_moveType & IsRotatable)
{
if (m_moveType & IsResizable)
{
AllUserModifications(pME->pos());
}
else if (m_moveType & IsMovable)
{
UserRotateAndMove();
}
else
{
m_eMode = mRotate;
SetOverrideCursor(cursorArrowCloseHand, 1, 1);
}
setZValue(ACTIVE_Z);
Update();
}
else if (m_moveType & IsResizable)
{
if (m_moveType & IsRotatable)
{
AllUserModifications(pME->pos());
}
else if (m_moveType & IsMovable)
{
UserMoveAndResize(pME->pos());
}
setZValue(ACTIVE_Z);
Update();
}
else if (m_moveType & IsMovable)
{
if (m_moveType & IsRotatable)
{
UserRotateAndMove();
}
else if (m_moveType & IsResizable)
{
UserMoveAndResize(pME->pos());
}
else
{
m_eMode = mMove;
SetOverrideCursor(cursorArrowCloseHand, 1, 1);
}
else
{
SetOverrideCursor(cursorArrowCloseHand, 1, 1);
}
setZValue(ACTIVE_Z);
Update();
}
else if (m_moveType == OnlyMovable)
else
{
m_eMode = mMove;
SetOverrideCursor(cursorArrowCloseHand, 1, 1);
setZValue(ACTIVE_Z);
Update();
}
else // All modifications
{
if (m_eMode != mRotate)
{
if (m_polyResize.containsPoint(pME->pos(), Qt::OddEvenFill) == true)
{
m_eMode = mResize;
SetOverrideCursor(Qt::SizeFDiagCursor);
}
else
{
m_eMode = mMove;
SetOverrideCursor(cursorArrowCloseHand, 1, 1);
}
}
else
{
SetOverrideCursor(cursorArrowCloseHand, 1, 1);
}
setZValue(ACTIVE_Z);
Update();
pME->ignore();
return;
}
}
}
@ -351,7 +366,7 @@ void VGrainlineItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME)
QPointF ptDiff = pME->scenePos() - m_ptStartMove;
qreal dX;
qreal dY;
if (m_eMode == mMove)
if (m_eMode == mMove && m_moveType & IsMovable)
{
QPointF pt = m_ptStartPos + ptDiff;
if (IsContained(pt, m_dRotation, dX, dY) == false)
@ -362,7 +377,7 @@ void VGrainlineItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME)
setPos(pt);
Update();
}
else if (m_eMode == mResize)
else if (m_eMode == mResize && m_moveType & IsResizable)
{
qreal dLen = qSqrt(ptDiff.x()*ptDiff.x() + ptDiff.y()*ptDiff.y());
qreal dAng = qAtan2(-ptDiff.y(), ptDiff.x());
@ -379,7 +394,7 @@ void VGrainlineItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME)
UpdateRectangle();
Update();
}
else if (m_eMode == mRotate)
else if (m_eMode == mRotate && m_moveType & IsRotatable)
{
// prevent strange angle changes due to singularities
qreal dLen = qSqrt(ptDiff.x()*ptDiff.x() + ptDiff.y()*ptDiff.y());
@ -433,7 +448,7 @@ void VGrainlineItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME)
{
if (bShort == true)
{
if (m_bReleased == true && m_moveType != OnlyResizable && m_moveType != OnlyMovable)
if (m_bReleased == true && m_moveType & IsRotatable)
{
m_eMode = mRotate;
Update();
@ -441,11 +456,11 @@ void VGrainlineItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME)
}
else
{
if (m_eMode == mMove)
if (m_eMode == mMove && m_moveType & IsMovable)
{
emit SignalMoved(pos());
}
else
else if (m_moveType & IsResizable)
{
emit SignalResized(m_dLength);
}
@ -458,7 +473,7 @@ void VGrainlineItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME)
{
m_eMode = mMove;
}
else
else if (m_moveType & IsRotatable)
{
emit SignalRotated(m_dRotation, m_ptStart);
}
@ -687,3 +702,41 @@ QPainterPath VGrainlineItem::MainShape() const
}
return path;
}
//---------------------------------------------------------------------------------------------------------------------
void VGrainlineItem::AllUserModifications(const QPointF &pos)
{
if (m_eMode != mRotate)
{
UserMoveAndResize(pos);
}
else
{
SetOverrideCursor(cursorArrowCloseHand, 1, 1);
}
}
//---------------------------------------------------------------------------------------------------------------------
void VGrainlineItem::UserRotateAndMove()
{
if (m_eMode != mRotate)
{
m_eMode = mMove;
}
SetOverrideCursor(cursorArrowCloseHand, 1, 1);
}
//---------------------------------------------------------------------------------------------------------------------
void VGrainlineItem::UserMoveAndResize(const QPointF &pos)
{
if (m_polyResize.containsPoint(pos, Qt::OddEvenFill) == true)
{
m_eMode = mResize;
SetOverrideCursor(Qt::SizeFDiagCursor);
}
else
{
m_eMode = mMove; // block later if need
SetOverrideCursor(cursorArrowCloseHand, 1, 1);
}
}

View File

@ -89,6 +89,10 @@ private:
QPolygonF SecondArrow(qreal dArrLen) const;
QPainterPath MainShape() const;
void AllUserModifications(const QPointF &pos);
void UserRotateAndMove();
void UserMoveAndResize(const QPointF &pos);
};
#endif // VGRAINLINEITEM_H

View File

@ -108,13 +108,13 @@ double VPieceItem::GetAngle(const QPointF &pt) const
}
//---------------------------------------------------------------------------------------------------------------------
VPieceItem::MoveType VPieceItem::GetMoveType() const
VPieceItem::MoveTypes VPieceItem::GetMoveType() const
{
return m_moveType;
}
//---------------------------------------------------------------------------------------------------------------------
void VPieceItem::SetMoveType(const MoveType &moveType)
void VPieceItem::SetMoveType(const VPieceItem::MoveTypes &moveType)
{
m_moveType = moveType;
setAcceptHoverEvents(m_moveType != NotMovable);

View File

@ -36,7 +36,16 @@ class VPieceItem : public QGraphicsObject
{
Q_OBJECT
public:
enum MoveType {AllModifications, OnlyResizable, OnlyRotatable, OnlyMovable, NotMovable, Error};
enum MoveType
{
NotMovable = 0x0,
IsRotatable = 0x1, // 0001
IsResizable = 0x2, // 0010
IsMovable = 0x4, // 0100
AllModifications = IsRotatable | IsResizable | IsMovable,
Error = 0x8 // 1000
};
Q_DECLARE_FLAGS(MoveTypes, MoveType)
explicit VPieceItem(QGraphicsItem* pParent = nullptr);
virtual ~VPieceItem();
@ -48,8 +57,8 @@ public:
void Reset();
bool IsIdle() const;
MoveType GetMoveType() const;
void SetMoveType(const MoveType &moveType);
VPieceItem::MoveTypes GetMoveType() const;
void SetMoveType(const VPieceItem::MoveTypes &moveType);
signals:
void SignalMoved(const QPointF &ptPos);
@ -62,11 +71,11 @@ protected:
mResize,
mRotate
};
QRectF m_rectBoundingBox;
Mode m_eMode;
bool m_bReleased;
QPointF m_ptRotCenter;
MoveType m_moveType;
QRectF m_rectBoundingBox;
Mode m_eMode;
bool m_bReleased;
QPointF m_ptRotCenter;
VPieceItem::MoveTypes m_moveType;
qreal m_inactiveZ;
@ -76,4 +85,6 @@ private:
Q_DISABLE_COPY(VPieceItem)
};
Q_DECLARE_OPERATORS_FOR_FLAGS(VPieceItem::MoveTypes)
#endif // VPIECEITEM_H

View File

@ -414,7 +414,7 @@ void VTextGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *pME)
// in rotation mode, do not do any changes here, because user might want to
// rotate the label more.
if (m_moveType == OnlyRotatable)
if (m_moveType & IsRotatable)
{
if (m_eMode != mRotate)
{
@ -572,7 +572,7 @@ void VTextGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME)
{ // in rotate mode, if user did just press/release, switch to move mode
if (bShort == true)
{
if (m_moveType != OnlyRotatable)
if (not (m_moveType & IsRotatable))
{
m_eMode = mMove;
}