Fix bugs.

* * *
Fix tool union bugs.
* * *
Fix preparing pieces for layout.
* * *
Fix bug with formulas.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2017-10-23 10:45:58 +03:00
parent 2a3d52ba88
commit 660efa3844
55 changed files with 615 additions and 157 deletions

View File

@ -850,7 +850,7 @@ void VPattern::ParseDetailElement(QDomElement &domElement, const Document &parse
initData.width = GetParametrString(domElement, AttrWidth, "0.0");
const QString w = initData.width;//need for saving fixed formula;
const uint version = GetParametrUInt(domElement, VToolSeamAllowance::AttrVersion, "1");
const uint version = GetParametrUInt(domElement, AttrVersion, "1");
const QStringList tags = QStringList() << TagNodes
<< TagData
@ -1721,7 +1721,7 @@ void VPattern::ParsePlaceLabel(QDomElement &domElement, const Document &parse)
initData.centerPoint = GetParametrUInt(domElement, AttrIdObject, NULL_ID_STR);
initData.idTool = GetParametrUInt(domElement, VAbstractNode::AttrIdTool, NULL_ID_STR);
initData.width = GetParametrString(domElement, AttrLength, "1.0");
initData.width = GetParametrString(domElement, AttrWidth, "1.0");
const QString w = initData.width;//need for saving fixed formula;
initData.height = GetParametrString(domElement, AttrHeight, "1.0");
@ -3550,6 +3550,7 @@ void VPattern::ParseToolsElement(VMainGraphicsScene *scene, const QDomElement &d
VToolUnionDetailsInitData initData;
initData.indexD1 = GetParametrUInt(domElement, VToolUnionDetails::AttrIndexD1, "-1");
initData.indexD2 = GetParametrUInt(domElement, VToolUnionDetails::AttrIndexD2, "-1");
initData.version = GetParametrUInt(domElement, AttrVersion, "1");
initData.scene = scene;
initData.doc = this;
initData.data = data;

View File

@ -43,8 +43,6 @@
const QString CustomMSign = QStringLiteral("@");
const QString CustomIncrSign = QStringLiteral("#");
const QString AttrType = QStringLiteral("type");
const QString AttrMx = QStringLiteral("mx");
const QString AttrMy = QStringLiteral("my");
@ -129,6 +127,7 @@ const QString AttrShowLabel2 = QStringLiteral("showLabel2");
const QString AttrWidth = QStringLiteral("width");
const QString AttrHeight = QStringLiteral("height");
const QString AttrPlaceLabelType = QStringLiteral("placeLabelType");
const QString AttrVersion = QStringLiteral("version");
const QString TypeLineNone = QStringLiteral("none");
const QString TypeLineLine = QStringLiteral("hair");

View File

@ -148,6 +148,7 @@ extern const QString AttrShowLabel2;
extern const QString AttrWidth;
extern const QString AttrHeight;
extern const QString AttrPlaceLabelType;
extern const QString AttrVersion;
extern const QString TypeLineNone;
extern const QString TypeLineLine;

View File

@ -548,6 +548,7 @@
<xs:attribute name="indexD1" type="xs:unsignedInt"/>
<xs:attribute name="indexD2" type="xs:unsignedInt"/>
<xs:attribute name="inUse" type="xs:boolean"/>
<xs:attribute name="version" type="unionVersion"/>
</xs:complexType>
</xs:element>
</xs:choice>
@ -1030,4 +1031,12 @@
<xs:enumeration value="8"/><!--Button-->
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="unionVersion">
<xs:restriction base="xs:unsignedInt">
<xs:enumeration value="1"/>
<!--Old version-->
<xs:enumeration value="2"/>
<!--New version-->
</xs:restriction>
</xs:simpleType>
</xs:schema>

View File

@ -266,8 +266,16 @@ QVector<QPointF> VEllipticalArc::GetPoints() const
path = t.map(path);
QPolygonF polygon = path.toSubpathPolygons().first();
polygon.removeFirst(); // remove point (0;0)
QPolygonF polygon;
const QList<QPolygonF> sub = path.toSubpathPolygons();
if (not sub.isEmpty())
{
polygon = path.toSubpathPolygons().first();
if (not polygon.isEmpty())
{
polygon.removeFirst(); // remove point (0;0)
}
}
return polygon;
}

View File

@ -180,7 +180,7 @@ PlaceLabelImg VPlaceLabelItem::LabelShape(const VContainer *data) const
QTransform t;
t.translate(center->x(), center->y());
t.rotate(-d->aValue+d->correctionAngle);
t.rotate(-(d->aValue+d->correctionAngle));
t.translate(-center->x(), -center->y());
auto SegmentShape = [center, t, this]()

View File

@ -350,8 +350,8 @@ QVector<VLayoutPlaceLabel> ConvertPlaceLabels(const VPiece &piece, const VContai
{
const auto label = pattern->GeometricObject<VPlaceLabelItem>(piece.GetPlaceLabels().at(i));
VLayoutPlaceLabel layoutLabel;
layoutLabel.shape = label->LabelShape(pattern);
layoutLabel.center = pattern->GeometricObject<VPointF>(label->GetCenterPoint())->toQPointF();
layoutLabel.shape = label->LabelShape();
layoutLabel.center = label->toQPointF();
layoutLabel.type = label->GetLabelType();
labels.append(layoutLabel);
}

View File

@ -662,6 +662,34 @@ void VPiece::SetPlaceLabels(const QVector<quint32> &labels)
d->m_placeLabels = labels;
}
//---------------------------------------------------------------------------------------------------------------------
QList<quint32> VPiece::Dependencies() const
{
QList<quint32> list = d->m_path.Dependencies();
foreach (const CustomSARecord &record, d->m_customSARecords)
{
list.append(record.path);
}
foreach (const quint32 &value, d->m_internalPaths)
{
list.append(value);
}
foreach (const quint32 &value, d->m_pins)
{
list.append(value);
}
foreach (const quint32 &value, d->m_placeLabels)
{
list.append(value);
}
return list;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief MissingNodes find missing nodes in detail. When we deleted object in detail and return this detail need

View File

@ -106,6 +106,7 @@ public:
QVector<quint32> &GetPlaceLabels();
void SetPlaceLabels(const QVector<quint32> &labels);
QList<quint32> Dependencies() const;
QVector<quint32> MissingNodes(const VPiece &det) const;
QVector<quint32> MissingCSAPath(const VPiece &det) const;
QVector<quint32> MissingInternalPaths(const VPiece &det) const;

View File

@ -435,6 +435,17 @@ VSAPoint VPiecePath::EndSegment(const VContainer *data, const QVector<VPieceNode
return end;
}
//---------------------------------------------------------------------------------------------------------------------
QList<quint32> VPiecePath::Dependencies() const
{
QList<quint32> list;
foreach (const VPieceNode &node, d->m_nodes)
{
list.append(node.GetId());
}
return list;
}
//---------------------------------------------------------------------------------------------------------------------
QVector<quint32> VPiecePath::MissingNodes(const VPiecePath &path) const
{

View File

@ -87,6 +87,7 @@ public:
QPainterPath PainterPath(const VContainer *data) const;
QList<quint32> Dependencies() const;
QVector<quint32> MissingNodes(const VPiecePath &path) const;
int indexOfNode(quint32 id) const;

View File

@ -112,6 +112,7 @@ void DialogPlaceLabel::EnbleShowMode(bool disable)
{
m_showMode = disable;
ui->comboBoxPiece->setDisabled(m_showMode);
ui->comboBoxPoint->setDisabled(m_showMode);
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -457,10 +457,10 @@ VSpline DialogSpline::CurrentSpline() const
const QHash<QString, QSharedPointer<VInternalVariable> > *vars = data->DataVariables();
const qreal angle1 = Visualization::FindVal(angle1F, vars);
const qreal angle2 = Visualization::FindVal(angle2F, vars);
const qreal length1 = Visualization::FindLength(length1F, vars);
const qreal length2 = Visualization::FindLength(length2F, vars);
const qreal angle1 = Visualization::FindValFromUser(angle1F, vars);
const qreal angle2 = Visualization::FindValFromUser(angle2F, vars);
const qreal length1 = Visualization::FindLengthFromUser(length1F, vars);
const qreal length2 = Visualization::FindLengthFromUser(length2F, vars);
const bool separator = qApp->Settings()->GetOsSeparator();

View File

@ -307,7 +307,7 @@ void DialogSplinePath::Angle1Changed()
VSplinePoint p = qvariant_cast<VSplinePoint>(item->data(Qt::UserRole));
const QString angle1F = ui->plainTextEditAngle1F->toPlainText().replace("\n", " ");
const qreal angle1 = Visualization::FindVal(angle1F, data->DataVariables());
const qreal angle1 = Visualization::FindValFromUser(angle1F, data->DataVariables());
p.SetAngle1(angle1, VTranslateVars::TryFormulaFromUser(angle1F, qApp->Settings()->GetOsSeparator()));
item->setData(Qt::UserRole, QVariant::fromValue(p));
@ -341,7 +341,7 @@ void DialogSplinePath::Angle2Changed()
VSplinePoint p = qvariant_cast<VSplinePoint>(item->data(Qt::UserRole));
const QString angle2F = ui->plainTextEditAngle2F->toPlainText().replace("\n", " ");
const qreal angle2 = Visualization::FindVal(angle2F, data->DataVariables());
const qreal angle2 = Visualization::FindValFromUser(angle2F, data->DataVariables());
p.SetAngle2(angle2, VTranslateVars::TryFormulaFromUser(angle2F, qApp->Settings()->GetOsSeparator()));
item->setData(Qt::UserRole, QVariant::fromValue(p));
@ -375,7 +375,7 @@ void DialogSplinePath::Length1Changed()
VSplinePoint p = qvariant_cast<VSplinePoint>(item->data(Qt::UserRole));
const QString length1F = ui->plainTextEditLength1F->toPlainText().replace("\n", " ");
const qreal length1 = Visualization::FindLength(length1F, data->DataVariables());
const qreal length1 = Visualization::FindLengthFromUser(length1F, data->DataVariables());
p.SetLength1(length1, VTranslateVars::TryFormulaFromUser(length1F, qApp->Settings()->GetOsSeparator()));
item->setData(Qt::UserRole, QVariant::fromValue(p));
@ -400,7 +400,7 @@ void DialogSplinePath::Length2Changed()
VSplinePoint p = qvariant_cast<VSplinePoint>(item->data(Qt::UserRole));
const QString length2F = ui->plainTextEditLength2F->toPlainText().replace("\n", " ");
const qreal length2 = Visualization::FindLength(length2F, data->DataVariables());
const qreal length2 = Visualization::FindLengthFromUser(length2F, data->DataVariables());
p.SetLength2(length2, VTranslateVars::TryFormulaFromUser(length2F, qApp->Settings()->GetOsSeparator()));
item->setData(Qt::UserRole, QVariant::fromValue(p));

View File

@ -128,7 +128,10 @@ DialogSeamAllowance::DialogSeamAllowance(const VContainer *data, const quint32 &
m_timerWidthBefore(nullptr),
m_timerWidthAfter(nullptr),
m_saWidth(0),
m_templateLines()
m_templateLines(),
m_undoStack(),
m_newPlaceLabels(),
m_newPaths()
{
ui->setupUi(this);
@ -641,7 +644,7 @@ void DialogSeamAllowance::ShowCustomSAContextMenu(const QPoint &pos)
else if (selectedAction == actionOption)
{
auto *dialog = new DialogPiecePath(data, record.path, this);
dialog->SetPiecePath(data->GetPiecePath(record.path));
dialog->SetPiecePath(CurrentPath(record.path));
dialog->SetPieceId(toolId);
if (record.includeType == PiecePathIncludeType::AsMainPath)
{
@ -681,7 +684,7 @@ void DialogSeamAllowance::ShowInternalPathsContextMenu(const QPoint &pos)
const quint32 pathId = qvariant_cast<quint32>(rowItem->data(Qt::UserRole));
auto *dialog = new DialogPiecePath(data, pathId, this);
dialog->SetPiecePath(data->GetPiecePath(pathId));
dialog->SetPiecePath(CurrentPath(pathId));
dialog->SetPieceId(toolId);
dialog->EnbleShowMode(true);
m_dialog = dialog;
@ -726,26 +729,28 @@ void DialogSeamAllowance::ShowPlaceLabelsContextMenu(const QPoint &pos)
QListWidgetItem *rowItem = uiTabPlaceLabels->listWidgetPlaceLabels->item(row);
SCASSERT(rowItem != nullptr);
const quint32 labelId = qvariant_cast<quint32>(rowItem->data(Qt::UserRole));
const auto label = data->GeometricObject<VPlaceLabelItem>(labelId);
VPlaceLabelItem currentLabel = CurrentPlaceLabel(labelId);
QScopedPointer<QMenu> menu(new QMenu());
auto InitAction = [&menu, label](const QString &text, PlaceLabelType type)
auto InitAction = [currentLabel, &menu](const QString &text, PlaceLabelType type)
{
QAction *action = menu->addAction(text);
action->setCheckable(true);
action->setChecked(label->GetLabelType() == type);
action->setChecked(currentLabel.GetLabelType() == type);
return action;
};
auto SaveType = [this, label, labelId](PlaceLabelType type)
auto SaveType = [this, currentLabel, labelId](PlaceLabelType type)
{
VPlaceLabelItem newLabel = VPlaceLabelItem(*label);
VPlaceLabelItem newLabel = VPlaceLabelItem(currentLabel);
newLabel.SetLabelType(type);
m_newPlaceLabels.insert(labelId, newLabel);
SavePlaceLabelOptions *saveCommand = new SavePlaceLabelOptions(*label, newLabel, qApp->getCurrentDocument(),
SavePlaceLabelOptions *saveCommand = new SavePlaceLabelOptions(toolId, currentLabel, newLabel,
qApp->getCurrentDocument(),
const_cast<VContainer *>(data), labelId);
qApp->getUndoStack()->push(saveCommand);
m_undoStack.append(saveCommand);
UpdateCurrentPlaceLabelRecords();
};
@ -772,11 +777,11 @@ void DialogSeamAllowance::ShowPlaceLabelsContextMenu(const QPoint &pos)
else if (selectedAction == actionOption)
{
auto *dialog = new DialogPlaceLabel(data, labelId, this);
dialog->SetCenterPoint(label->GetCenterPoint());
dialog->SetLabelType(label->GetLabelType());
dialog->SetWidth(label->GetWidthFormula());
dialog->SetHeight(label->GetHeightFormula());
dialog->SetAngle(label->GetAngleFormula());
dialog->SetCenterPoint(labelId);
dialog->SetLabelType(currentLabel.GetLabelType());
dialog->SetWidth(currentLabel.GetWidthFormula());
dialog->SetHeight(currentLabel.GetHeightFormula());
dialog->SetAngle(currentLabel.GetAngleFormula());
dialog->SetPieceId(toolId);
dialog->EnbleShowMode(true);
m_dialog = dialog;
@ -1175,13 +1180,15 @@ void DialogSeamAllowance::PathDialogClosed(int result)
SCASSERT(dialogTool != nullptr);
try
{
const VPiecePath newPath = dialogTool->GetPiecePath();
const VPiecePath oldPath = data->GetPiecePath(dialogTool->GetToolId());
VPiecePath currentPath = CurrentPath(dialogTool->GetToolId());
VPiecePath newPath = dialogTool->GetPiecePath();
m_newPaths.insert(dialogTool->GetToolId(), newPath);
SavePiecePathOptions *saveCommand = new SavePiecePathOptions(oldPath, newPath, qApp->getCurrentDocument(),
SavePiecePathOptions *saveCommand = new SavePiecePathOptions(toolId, currentPath, newPath,
qApp->getCurrentDocument(),
const_cast<VContainer *>(data),
dialogTool->GetToolId());
qApp->getUndoStack()->push(saveCommand);
m_undoStack.append(saveCommand);
UpdateCurrentCustomSARecord();
UpdateCurrentInternalPathRecord();
}
@ -1204,34 +1211,35 @@ void DialogSeamAllowance::PlaceLabelDialogClosed(int result)
SCASSERT(dialogTool != nullptr);
try
{
auto oldLabel = data->GeometricObject<VPlaceLabelItem>(dialogTool->GetToolId());
auto point = data->GeometricObject<VPointF>(dialogTool->GetCenterPoint());
VPlaceLabelItem currentLabel = CurrentPlaceLabel(dialogTool->GetToolId());
const QHash<QString, QSharedPointer<VInternalVariable> > *vars = data->DataVariables();
const qreal w = qAbs(Visualization::FindLength(dialogTool->GetWidth(), vars));
const qreal h = qAbs(Visualization::FindLength(dialogTool->GetHeight(), vars));
const qreal a = Visualization::FindVal(dialogTool->GetAngle(), vars);
const qreal w = qAbs(Visualization::FindLengthFromUser(dialogTool->GetWidth(), vars, false));
const qreal h = qAbs(Visualization::FindLengthFromUser(dialogTool->GetHeight(), vars, false));
const qreal a = Visualization::FindValFromUser(dialogTool->GetAngle(), vars, false);
qDebug() << w << h << a;
VPlaceLabelItem newLabel = VPlaceLabelItem();
newLabel.setName(point->name());
newLabel.setX(point->x());
newLabel.setY(point->y());
newLabel.setMx(point->mx());
newLabel.setMy(point->my());
VPlaceLabelItem newLabel = VPlaceLabelItem();
newLabel.setName(currentLabel.name());
newLabel.setX(currentLabel.x());
newLabel.setY(currentLabel.y());
newLabel.setMx(currentLabel.mx());
newLabel.setMy(currentLabel.my());
newLabel.SetWidth(w, dialogTool->GetWidth());
newLabel.SetHeight(h, dialogTool->GetHeight());
newLabel.SetAngle(a, dialogTool->GetAngle());
newLabel.SetLabelType(dialogTool->GetLabelType());
newLabel.SetCenterPoint(dialogTool->GetCenterPoint());
newLabel.SetCorrectionAngle(oldLabel->GetCorrectionAngle());
newLabel.SetCenterPoint(currentLabel.GetCenterPoint());
newLabel.SetCorrectionAngle(currentLabel.GetCorrectionAngle());
SavePlaceLabelOptions *saveCommand = new SavePlaceLabelOptions(*oldLabel, newLabel,
m_newPlaceLabels.insert(dialogTool->GetToolId(), newLabel);
SavePlaceLabelOptions *saveCommand = new SavePlaceLabelOptions(toolId, currentLabel, newLabel,
qApp->getCurrentDocument(),
const_cast<VContainer *>(data),
dialogTool->GetToolId());
qApp->getUndoStack()->push(saveCommand);
m_undoStack.append(saveCommand);
UpdateCurrentPlaceLabelRecords();
}
catch (const VExceptionBadId &e)
@ -2271,7 +2279,7 @@ QString DialogSeamAllowance::GetPathName(quint32 path, bool reverse) const
if (path > NULL_ID)
{
name = data->GetPiecePath(path).GetName();
name = CurrentPath(path).GetName();
if (reverse)
{
@ -2883,6 +2891,12 @@ QString DialogSeamAllowance::GetFormulaSAWidth() const
return qApp->TrVars()->TryFormulaFromUser(width, qApp->Settings()->GetOsSeparator());
}
//---------------------------------------------------------------------------------------------------------------------
QVector<QUndoCommand *> &DialogSeamAllowance::UndoStack()
{
return m_undoStack;
}
//---------------------------------------------------------------------------------------------------------------------
void DialogSeamAllowance::SetFormulaSAWidth(const QString &formula)
{
@ -2943,9 +2957,8 @@ void DialogSeamAllowance::UpdateCurrentPlaceLabelRecords()
QListWidgetItem *item = uiTabPlaceLabels->listWidgetPlaceLabels->item(row);
SCASSERT(item != nullptr);
const quint32 pointId = qvariant_cast<quint32>(item->data(Qt::UserRole));
auto point = data->GeometricObject<VPointF>(pointId);
item->setText(point->name());
const quint32 labelId = qvariant_cast<quint32>(item->data(Qt::UserRole));
item->setText(CurrentPlaceLabel(labelId).name());
}
//---------------------------------------------------------------------------------------------------------------------
@ -3131,3 +3144,15 @@ void DialogSeamAllowance::ShowPieceSpecialPoints(const QListWidget *list)
m_visSpecialPoints->RefreshGeometry();
}
}
//---------------------------------------------------------------------------------------------------------------------
VPiecePath DialogSeamAllowance::CurrentPath(quint32 id) const
{
return m_newPaths.contains(id) ? m_newPaths.value(id) : data->GetPiecePath(id);
}
//---------------------------------------------------------------------------------------------------------------------
VPlaceLabelItem DialogSeamAllowance::CurrentPlaceLabel(quint32 id) const
{
return m_newPlaceLabels.contains(id) ? m_newPlaceLabels.value(id) : *data->GeometricObject<VPlaceLabelItem>(id);
}

View File

@ -48,6 +48,8 @@ namespace Ui
class VisPieceSpecialPoints;
class FancyTabBar;
class VPlaceLabelItem;
class QUndoCommand;
class DialogSeamAllowance : public DialogTool
{
@ -64,6 +66,8 @@ public:
QString GetFormulaSAWidth() const;
QVector<QUndoCommand*> &UndoStack();
public slots:
virtual void ChosenObject(quint32 id, const SceneObject &type) Q_DECL_OVERRIDE;
virtual void ShowDialog(bool click) Q_DECL_OVERRIDE;
@ -209,6 +213,10 @@ private:
QVector<VLabelTemplateLine> m_templateLines;
QVector<QUndoCommand*> m_undoStack;
QHash<quint32, VPlaceLabelItem> m_newPlaceLabels;
QHash<quint32, VPiecePath> m_newPaths;
VPiece CreatePiece() const;
void NewMainPathItem(const VPieceNode &node);
@ -261,6 +269,9 @@ private:
void SetPLAngle(QString angleFormula);
void ShowPieceSpecialPoints(const QListWidget *list);
VPiecePath CurrentPath(quint32 id) const;
VPlaceLabelItem CurrentPlaceLabel(quint32 id) const;
};
#endif // DIALOGSEAMALLOWANCE_H

View File

@ -251,7 +251,7 @@ QString VToolCutArc::MakeToolTip() const
const QSharedPointer<VArc> arc = VAbstractTool::data.GeometricObject<VArc>(curveCutId);
const QString expression = qApp->TrVars()->FormulaToUser(formula, qApp->Settings()->GetOsSeparator());
const qreal length = Visualization::FindVal(expression, VAbstractTool::data.DataVariables());
const qreal length = Visualization::FindValFromUser(expression, VAbstractTool::data.DataVariables());
const QString arcStr = tr("Arc");
const QString lengthStr = tr("length");

View File

@ -250,7 +250,7 @@ QString VToolCutSpline::MakeToolTip() const
const auto spl = VAbstractTool::data.GeometricObject<VAbstractCubicBezier>(curveCutId);
const QString expression = qApp->TrVars()->FormulaToUser(formula, qApp->Settings()->GetOsSeparator());
const qreal length = Visualization::FindVal(expression, VAbstractTool::data.DataVariables());
const qreal length = Visualization::FindValFromUser(expression, VAbstractTool::data.DataVariables());
QPointF spl1p2, spl1p3, spl2p2, spl2p3;
QPointF point = spl->CutSpline(qApp->toPixel(length), spl1p2, spl1p3, spl2p2, spl2p3);

View File

@ -339,7 +339,7 @@ QString VToolCutSplinePath::MakeToolTip() const
const auto splPath = VAbstractTool::data.GeometricObject<VAbstractCubicBezierPath>(curveCutId);
const QString expression = qApp->TrVars()->FormulaToUser(formula, qApp->Settings()->GetOsSeparator());
const qreal length = Visualization::FindVal(expression, VAbstractTool::data.DataVariables());
const qreal length = Visualization::FindValFromUser(expression, VAbstractTool::data.DataVariables());
VSplinePath *splPath1 = nullptr;
VSplinePath *splPath2 = nullptr;

View File

@ -103,8 +103,9 @@ void VDrawTool::ChangedNameDraw(const QString &oldName, const QString &newName)
}
//---------------------------------------------------------------------------------------------------------------------
void VDrawTool::SaveDialogChange()
void VDrawTool::SaveDialogChange(const QString &undoText)
{
Q_UNUSED(undoText)
qCDebug(vTool, "Saving tool options after using dialog");
QDomElement oldDomElement = doc->elementById(m_id, getTagName());
if (oldDomElement.isElement())

View File

@ -100,7 +100,7 @@ protected:
/** @brief SaveDialog save options into file after change in dialog. */
virtual void SaveDialog(QDomElement &domElement, QList<quint32> &oldDependencies,
QList<quint32> &newDependencies)=0;
virtual void SaveDialogChange() Q_DECL_FINAL;
virtual void SaveDialogChange(const QString &undoText = QString()) Q_DECL_FINAL;
virtual void AddToFile() Q_DECL_OVERRIDE;
void SaveOption(QSharedPointer<VGObject> &obj);
virtual void SaveOptions(QDomElement &tag, QSharedPointer<VGObject> &obj);

View File

@ -102,7 +102,7 @@ VToolPlaceLabel *VToolPlaceLabel::Create(VToolPlaceLabelInitData &initData)
node->setMx(point->mx());
node->setMy(point->my());
if (initData.typeCreation == Source::FromTool)
if (initData.idTool != NULL_ID)
{
QSharedPointer<VPlaceLabelItem> label = qSharedPointerDynamicCast<VPlaceLabelItem>(point);
SCASSERT(label.isNull() == false)

View File

@ -46,8 +46,8 @@ public:
static bool m_suppressContextMenu;
public slots:
void FullUpdateFromGuiOk(int result);
void FullUpdateFromGuiApply();
virtual void FullUpdateFromGuiOk(int result);
virtual void FullUpdateFromGuiApply();
protected:
/** @brief m_dialog tool's dialog options.*/
@ -55,7 +55,7 @@ protected:
/** @brief setDialog set dialog when user want change tool option. */
virtual void setDialog() {/*do nothing by default*/}
virtual void SaveDialogChange()=0;
virtual void SaveDialogChange(const QString &undoText = QString())=0;
private:
Q_DISABLE_COPY(VInteractiveTool)

View File

@ -71,7 +71,6 @@ const QString VToolSeamAllowance::TagIPaths = QStringLiteral("iPaths");
const QString VToolSeamAllowance::TagPins = QStringLiteral("pins");
const QString VToolSeamAllowance::TagPlaceLabels = QStringLiteral("placeLabels");
const QString VToolSeamAllowance::AttrVersion = QStringLiteral("version");
const QString VToolSeamAllowance::AttrForbidFlipping = QStringLiteral("forbidFlipping");
const QString VToolSeamAllowance::AttrSeamAllowance = QStringLiteral("seamAllowance");
const QString VToolSeamAllowance::AttrHideMainPath = QStringLiteral("hideMainPath");
@ -900,6 +899,12 @@ QPainterPath VToolSeamAllowance::shape() const
}
}
//---------------------------------------------------------------------------------------------------------------------
void VToolSeamAllowance::FullUpdateFromGuiApply()
{
SaveDialogChange(tr("apply save detail options"));
}
//---------------------------------------------------------------------------------------------------------------------
void VToolSeamAllowance::AddToFile()
{
@ -935,7 +940,7 @@ void VToolSeamAllowance::RefreshDataInFile()
Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 4, 0),
"Time to refactor the code.");
const uint version = doc->GetParametrUInt(domElement, VToolSeamAllowance::AttrVersion, "1");
const uint version = doc->GetParametrUInt(domElement, AttrVersion, "1");
if (version == 1)
{
const VPiece piece = VAbstractTool::data.GetPiece(m_id);
@ -1221,10 +1226,6 @@ VToolSeamAllowance::VToolSeamAllowance(const VToolSeamAllowanceInitData &initDat
connect(this, &VToolSeamAllowance::ChoosedTool, m_sceneDetails, &VMainGraphicsScene::ChoosedItem);
ConnectOutsideSignals();
UpdateDetailLabel();
UpdatePatternInfo();
UpdateGrainline();
}
//---------------------------------------------------------------------------------------------------------------------
@ -1302,7 +1303,7 @@ void VToolSeamAllowance::RefreshGeometry()
}
//---------------------------------------------------------------------------------------------------------------------
void VToolSeamAllowance::SaveDialogChange()
void VToolSeamAllowance::SaveDialogChange(const QString &undoText)
{
SCASSERT(not m_dialog.isNull());
DialogSeamAllowance *dialogTool = qobject_cast<DialogSeamAllowance*>(m_dialog.data());
@ -1310,8 +1311,28 @@ void VToolSeamAllowance::SaveDialogChange()
const VPiece newDet = dialogTool->GetPiece();
const VPiece oldDet = VAbstractTool::data.GetPiece(m_id);
qApp->getUndoStack()->push(new SavePieceOptions(oldDet, newDet, doc, m_id));
UpdateDetailLabel();
QVector<QUndoCommand*> &undocommands = dialogTool->UndoStack();
const bool groupChange = not undocommands.isEmpty();
SavePieceOptions *saveCommand = new SavePieceOptions(oldDet, newDet, doc, m_id);
if (groupChange)
{
qApp->getUndoStack()->beginMacro(undoText.isEmpty() ? saveCommand->text(): undoText);
foreach (QUndoCommand* command, undocommands)
{
qApp->getUndoStack()->push(command);
}
undocommands.clear();
}
qApp->getUndoStack()->push(saveCommand);
if (groupChange)
{
qApp->getUndoStack()->endMacro();
}
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -73,7 +73,6 @@ public:
static const QString TagPins;
static const QString TagPlaceLabels;
static const QString AttrVersion;
static const QString AttrForbidFlipping;
static const QString AttrSeamAllowance;
static const QString AttrHideMainPath;
@ -106,6 +105,7 @@ public:
void DisconnectOutsideSignals();
void ConnectOutsideSignals();
void ReinitInternals(const VPiece &detail, VMainGraphicsScene *scene);
void RefreshGeometry();
virtual int type() const Q_DECL_OVERRIDE {return Type;}
enum { Type = UserType + static_cast<int>(Tool::Piece)};
@ -118,6 +118,7 @@ public:
virtual QRectF boundingRect() const Q_DECL_OVERRIDE;
virtual QPainterPath shape() const Q_DECL_OVERRIDE;
public slots:
virtual void FullUpdateFromGuiApply() Q_DECL_OVERRIDE;
virtual void FullUpdateFromFile () Q_DECL_OVERRIDE;
void EnableToolMove(bool move);
virtual void AllowHover(bool enabled) Q_DECL_OVERRIDE;
@ -153,7 +154,7 @@ protected:
virtual void DeleteToolWithConfirm(bool ask = true) Q_DECL_OVERRIDE;
virtual void ToolCreation(const Source &typeCreation) Q_DECL_OVERRIDE;
virtual void SetDialog() Q_DECL_FINAL;
virtual void SaveDialogChange() Q_DECL_FINAL;
virtual void SaveDialogChange(const QString &undoText = QString()) Q_DECL_FINAL;
private:
Q_DISABLE_COPY(VToolSeamAllowance)
@ -175,7 +176,6 @@ private:
VToolSeamAllowance(const VToolSeamAllowanceInitData &initData, QGraphicsItem * parent = nullptr);
void UpdateExcludeState();
void RefreshGeometry();
VPieceItem::MoveTypes FindLabelGeometry(const VPatternLabelData &labelData, qreal &rotationAngle, qreal &labelWidth,
qreal &labelHeight, QPointF &pos);

View File

@ -86,6 +86,9 @@ const QString VToolUnionDetails::AttrNodeType = QStringLiteral("nodeType");
const QString VToolUnionDetails::NodeTypeContour = QStringLiteral("Contour");
const QString VToolUnionDetails::NodeTypeModeling = QStringLiteral("Modeling");
// Current version of union tag need for backward compatibility
const quint8 VToolUnionDetails::unionVersion = UNION_VERSSION;
QT_WARNING_PUSH
QT_WARNING_DISABLE_CLANG("-Wmissing-prototypes")
QT_WARNING_DISABLE_INTEL(1418)
@ -232,6 +235,37 @@ QVector<quint32> GetPiece2Pins(VAbstractPattern *doc, quint32 id)
return QVector<quint32>();
}
//---------------------------------------------------------------------------------------------------------------------
QVector<quint32> GetPiece2PlaceLabels(VAbstractPattern *doc, quint32 id)
{
const QDomElement tool = doc->elementById(id, VAbstractPattern::TagTools);
if (tool.isNull())
{
VException e(QString("Can't get tool by id='%1'.").arg(id));
throw e;
}
const QDomNodeList nodesList = tool.childNodes();
for (qint32 i = 0; i < nodesList.size(); ++i)
{
const QDomElement element = nodesList.at(i).toElement();
if (not element.isNull() && element.tagName() == VToolUnionDetails::TagDetail && i+1 == 2)
{
const QDomNodeList detList = element.childNodes();
for (qint32 j = 0; j < detList.size(); ++j)
{
const QDomElement element = detList.at(j).toElement();
if (not element.isNull() && element.tagName() == VToolSeamAllowance::TagPlaceLabels)
{
return VAbstractPattern::ParsePiecePointRecords(element);
}
}
}
}
return QVector<quint32>();
}
//---------------------------------------------------------------------------------------------------------------------
QString DrawName(VAbstractPattern *doc, quint32 d1id, quint32 d2id)
{
@ -390,6 +424,7 @@ quint32 AddNodePoint(const VPieceNode &node, const VToolUnionDetailsInitData &in
initNodeData.typeCreation = Source::FromTool;
initNodeData.idTool = initData.id;
initNodeData.drawName = drawName;
initNodeData.scene = initData.scene;
VNodePoint::Create(initNodeData);
return id;
@ -443,15 +478,8 @@ quint32 AddPlaceLabel(quint32 id, const VToolUnionDetailsInitData &initData, QVe
}
label->SetCorrectionAngle(label->GetCorrectionAngle() + angle);
QScopedPointer<VPlaceLabelItem> label1(new VPlaceLabelItem(*label));
const quint32 idObject = initData.data->AddGObject(label.take());
children.append(idObject);
const quint32 idLabel = initData.data->AddGObject(label1.take());
VToolPlaceLabelInitData initNodeData;
initNodeData.id = idLabel;
initNodeData.centerPoint = idObject;
initNodeData.idObject = NULL_ID;
initNodeData.doc = initData.doc;
initNodeData.data = initData.data;
@ -459,6 +487,18 @@ quint32 AddPlaceLabel(quint32 id, const VToolUnionDetailsInitData &initData, QVe
initNodeData.typeCreation = Source::FromTool;
initNodeData.idTool = initData.id;
initNodeData.drawName = drawName;
initNodeData.width = label->GetWidthFormula();
initNodeData.height = label->GetHeightFormula();
initNodeData.angle = label->GetAngleFormula();
initNodeData.type = label->GetLabelType();
QScopedPointer<VPlaceLabelItem> label1(new VPlaceLabelItem(*label));
initNodeData.centerPoint = initData.data->AddGObject(label.take());
children.append(initNodeData.centerPoint);
const quint32 idLabel = initData.data->AddGObject(label1.take());
initNodeData.id = idLabel;
VToolPlaceLabel::Create(initNodeData);
return idLabel;
@ -1148,7 +1188,14 @@ void CreateUnitedDetailCSA(VPiece &newDetail, const VPiece &d, QVector<quint32>
VToolPiecePath::Create(initNodeData);
record.path = idPath;
newDetail.GetCustomSARecords().append(record);
nodeChildren.prepend(idPath);
if (initData.version == 1)
{
// TODO. Delete if minimal supported version is 0.7.0
Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 7, 0),
"Time to refactor the code.");
nodeChildren.prepend(idPath);
}
}
children += nodeChildren;
}
@ -1199,7 +1246,14 @@ void CreateUnitedDetailInternalPaths(VPiece &newDetail, const VPiece &d, QVector
VToolPiecePath::Create(initNodeData);
newDetail.GetInternalPaths().append(idPath);
nodeChildren.prepend(idPath);
if (initData.version == 1)
{
// TODO. Delete if minimal supported version is 0.7.0
Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 7, 0),
"Time to refactor the code.");
nodeChildren.prepend(idPath);
}
}
children += nodeChildren;
}
@ -1230,7 +1284,6 @@ void CreateUnitedDetailPins(VPiece &newDetail, const VPiece &d, QVector<quint32>
{
const quint32 id = AddPin(d.GetPins().at(i), initData, children, drawName, dx, dy, pRotate, angle);
newDetail.GetPins().append(id);
nodeChildren.prepend(id);
}
children += nodeChildren;
}
@ -1246,7 +1299,6 @@ void CreateUnitedDetailPlaceLabels(VPiece &newDetail, const VPiece &d, QVector<q
const quint32 id = AddPlaceLabel(d.GetPlaceLabels().at(i), initData, children, drawName, dx, dy, pRotate,
angle);
newDetail.GetPlaceLabels().append(id);
nodeChildren.prepend(id);
}
children += nodeChildren;
}
@ -1351,20 +1403,37 @@ void UpdateUnitedDetailPaths(const VToolUnionDetailsInitData &initData, qreal dx
for (int i=0; i < records.size(); ++i)
{
const VPiecePath path = initData.data->GetPiecePath(records.at(i));
const quint32 updatedId = TakeNextId(children);
VPiecePath updatedPath(path);
updatedPath.Clear();
for (int j=0; j < path.CountNodes(); ++j)
if (initData.version == 1)
{
const VPieceNode &node = path.at(j);
const quint32 id = TakeNextId(children);
updatedPath.Append(VPieceNode(id, node.GetTypeTool(), node.GetReverse()));
QVector<quint32> nodeChildren = {id};
UpdatePathNode(initData.data, path.at(j), nodeChildren, dx, dy, pRotate, angle);
// TODO. Delete if minimal supported version is 0.7.0
Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 7, 0),
"Time to refactor the code.");
const quint32 updatedId = TakeNextId(children);
VPiecePath updatedPath(path);
updatedPath.Clear();
for (int j=0; j < path.CountNodes(); ++j)
{
const VPieceNode &node = path.at(j);
const quint32 id = TakeNextId(children);
updatedPath.Append(VPieceNode(id, node.GetTypeTool(), node.GetReverse()));
QVector<quint32> nodeChildren = {id};
UpdatePathNode(initData.data, path.at(j), nodeChildren, dx, dy, pRotate, angle);
}
initData.data->UpdatePiecePath(updatedId, updatedPath);
}
else
{
for (int j=0; j < path.CountNodes(); ++j)
{
const quint32 id = TakeNextId(children);
QVector<quint32> nodeChildren = {id};
UpdatePathNode(initData.data, path.at(j), nodeChildren, dx, dy, pRotate, angle);
}
}
initData.data->UpdatePiecePath(updatedId, updatedPath);
}
}
@ -1415,14 +1484,20 @@ void UpdateUnitedDetailPlaceLabels(const VToolUnionDetailsInitData &initData, qr
for (int i = 0; i < records.size(); ++i)
{
QScopedPointer<VPlaceLabelItem>
label(new VPlaceLabelItem(*initData.data->GeometricObject<VPlaceLabelItem>(records.at(i))));
QSharedPointer<VPlaceLabelItem> parentLabel = initData.data->GeometricObject<VPlaceLabelItem>(records.at(i));
if (not qFuzzyIsNull(dx) || not qFuzzyIsNull(dy) || pRotate != NULL_ID)
{
BiasRotatePoint(label.data(), dx, dy,
BiasRotatePoint(parentLabel.data(), dx, dy,
static_cast<QPointF>(*initData.data->GeometricObject<VPointF>(pRotate)), angle);
}
label->SetCorrectionAngle(label->GetCorrectionAngle()+angle);
QScopedPointer<VPlaceLabelItem> label(new VPlaceLabelItem());
label->setName(parentLabel->name());
label->setX(parentLabel->x());
label->setY(parentLabel->y());
label->setMx(parentLabel->mx());
label->setMy(parentLabel->my());
label->SetCorrectionAngle(parentLabel->GetCorrectionAngle()+angle);
initData.data->UpdateGObject(TakeNextId(children), label.take());
}
}
@ -1486,7 +1561,7 @@ void UpdateUnitedDetail(const VToolUnionDetailsInitData &initData, qreal dx, qre
UpdateUnitedDetailInternalPaths(initData, dx, dy, pRotate, angle,
GetPiece2InternalPaths(initData.doc, initData.id));
UpdateUnitedDetailPins(initData, dx, dy, pRotate, angle, GetPiece2Pins(initData.doc, initData.id));
UpdateUnitedDetailPlaceLabels(initData, dx, dy, pRotate, angle, GetPiece2Pins(initData.doc, initData.id));
UpdateUnitedDetailPlaceLabels(initData, dx, dy, pRotate, angle, GetPiece2PlaceLabels(initData.doc, initData.id));
}
//---------------------------------------------------------------------------------------------------------------------
@ -1525,7 +1600,8 @@ VToolUnionDetails::VToolUnionDetails(const VToolUnionDetailsInitData &initData,
d1id(initData.d1id),
d2id(initData.d2id),
indexD1(initData.indexD1),
indexD2(initData.indexD2)
indexD2(initData.indexD2),
version(initData.version)
{
_referens = 0;
ToolCreation(initData.typeCreation);
@ -1668,6 +1744,7 @@ void VToolUnionDetails::AddToFile()
doc->SetAttribute(domElement, AttrType, ToolType);
doc->SetAttribute(domElement, AttrIndexD1, indexD1);
doc->SetAttribute(domElement, AttrIndexD2, indexD2);
doc->SetAttribute(domElement, AttrVersion, unionVersion);
AddDetail(domElement, data.GetPiece(d1id));
AddDetail(domElement, data.GetPiece(d2id));
@ -1691,6 +1768,7 @@ void VToolUnionDetails::AddDetail(QDomElement &domElement, const VPiece &d) cons
VToolSeamAllowance::AddCSARecords(doc, det, d.GetCustomSARecords());
VToolSeamAllowance::AddInternalPaths(doc, det, d.GetInternalPaths());
VToolSeamAllowance::AddPins(doc, det, d.GetPins());
VToolSeamAllowance::AddPlaceLabels(doc, det, d.GetPlaceLabels());
domElement.appendChild(det);
}
@ -1726,10 +1804,11 @@ QVector<quint32> VToolUnionDetails::GetReferenceObjects() const
return list;
}
const QStringList parts = QStringList() << VAbstractPattern::TagNodes /*0*/
<< VToolSeamAllowance::TagCSA /*1*/
<< VToolSeamAllowance::TagIPaths /*2*/
<< VToolSeamAllowance::TagPins; /*3*/
const QStringList parts = QStringList() << VAbstractPattern::TagNodes /*0*/
<< VToolSeamAllowance::TagCSA /*1*/
<< VToolSeamAllowance::TagIPaths /*2*/
<< VToolSeamAllowance::TagPins /*3*/
<< VToolSeamAllowance::TagPlaceLabels; /*4*/
const QDomNodeList nodesList = tool.childNodes();
for (qint32 i = 0; i < nodesList.size(); ++i)
@ -1754,6 +1833,7 @@ QVector<quint32> VToolUnionDetails::GetReferenceObjects() const
VAbstractPattern::AttrPath);
break;
case 3://VToolSeamAllowance::TagPins
case 4://VToolSeamAllowance::TagPlaceLabels
{
const QDomNodeList children = element.childNodes();
for (qint32 i = 0; i < children.size(); ++i)

View File

@ -47,6 +47,8 @@
class DialogTool;
#define UNION_VERSSION 2
struct VToolUnionDetailsInitData : VAbstractToolInitData
{
VToolUnionDetailsInitData()
@ -55,7 +57,8 @@ struct VToolUnionDetailsInitData : VAbstractToolInitData
d2id(NULL_ID),
indexD1(NULL_ID),
indexD2(NULL_ID),
retainPieces(false)
retainPieces(false),
version(UNION_VERSSION)
{}
quint32 d1id;
@ -63,6 +66,7 @@ struct VToolUnionDetailsInitData : VAbstractToolInitData
quint32 indexD1;
quint32 indexD2;
bool retainPieces;
uint version;
};
/**
@ -88,6 +92,8 @@ public:
static const QString NodeTypeContour;
static const QString NodeTypeModeling;
static const quint8 unionVersion;
virtual QString getTagName() const Q_DECL_OVERRIDE;
virtual void ShowVisualization(bool show) Q_DECL_OVERRIDE;
virtual void incrementReferens() Q_DECL_OVERRIDE;
@ -120,6 +126,8 @@ private:
/** @brief indexD2 index edge in second detail. */
quint32 indexD2;
uint version;
VToolUnionDetails(const VToolUnionDetailsInitData &initData, QObject *parent = nullptr);
void AddDetail(QDomElement &domElement, const VPiece &d) const;

View File

@ -51,7 +51,7 @@ SavePieceOptions::SavePieceOptions(const VPiece &oldDet, const VPiece &newDet, V
m_oldDet(oldDet),
m_newDet(newDet)
{
setText(tr("save detail option"));
setText(tr("save detail options"));
nodeId = id;
}
@ -144,3 +144,38 @@ void SavePieceOptions::redo()
qCDebug(vUndo, "Can't find detail with id = %u.", nodeId);
}
}
//---------------------------------------------------------------------------------------------------------------------
bool SavePieceOptions::mergeWith(const QUndoCommand *command)
{
const SavePieceOptions *saveCommand = static_cast<const SavePieceOptions *>(command);
SCASSERT(saveCommand != nullptr);
if (saveCommand->DetId() != nodeId)
{
return false;
}
else
{
const QSet<quint32> currentSet;
currentSet.fromList(m_newDet.Dependencies());
const VPiece candidate = saveCommand->NewDet();
const QSet<quint32> candidateSet;
candidateSet.fromList(candidate.Dependencies());
if (currentSet != candidateSet)
{
return false;
}
}
m_newDet = saveCommand->NewDet();
return true;
}
//---------------------------------------------------------------------------------------------------------------------
int SavePieceOptions::id() const
{
return static_cast<int>(UndoCommand::SavePieceOptions);
}

View File

@ -43,6 +43,10 @@ public:
virtual void undo() Q_DECL_OVERRIDE;
virtual void redo() Q_DECL_OVERRIDE;
virtual bool mergeWith(const QUndoCommand *command) Q_DECL_OVERRIDE;
virtual int id() const Q_DECL_OVERRIDE;
quint32 DetId() const;
VPiece NewDet() const;
private:
Q_DISABLE_COPY(SavePieceOptions)
@ -50,4 +54,16 @@ private:
VPiece m_newDet;
};
//---------------------------------------------------------------------------------------------------------------------
inline quint32 SavePieceOptions::DetId() const
{
return nodeId;
}
//---------------------------------------------------------------------------------------------------------------------
inline VPiece SavePieceOptions::NewDet() const
{
return m_newDet;
}
#endif // SAVEPIECEOPTIONS_H

View File

@ -35,15 +35,17 @@
#include "../ifc/xml/vabstractpattern.h"
#include "../vmisc/logging.h"
#include "../tools/nodeDetails/vtoolpiecepath.h"
#include "../tools/vtoolseamallowance.h"
//---------------------------------------------------------------------------------------------------------------------
SavePiecePathOptions::SavePiecePathOptions(const VPiecePath &oldPath, const VPiecePath &newPath,
SavePiecePathOptions::SavePiecePathOptions(quint32 pieceId, const VPiecePath &oldPath, const VPiecePath &newPath,
VAbstractPattern *doc, VContainer *data, quint32 id,
QUndoCommand *parent)
: VUndoCommand(QDomElement(), doc, parent),
m_oldPath(oldPath),
m_newPath(newPath),
m_data(data)
m_data(data),
m_pieceId(pieceId)
{
setText(tr("save path options"));
nodeId = id;
@ -66,6 +68,14 @@ void SavePiecePathOptions::undo()
SCASSERT(m_data);
m_data->UpdatePiecePath(nodeId, m_oldPath);
if (m_pieceId != NULL_ID)
{
if (VToolSeamAllowance *tool = qobject_cast<VToolSeamAllowance *>(VAbstractPattern::getTool(m_pieceId)))
{
tool->RefreshGeometry();
}
}
}
else
{
@ -90,9 +100,46 @@ void SavePiecePathOptions::redo()
SCASSERT(m_data);
m_data->UpdatePiecePath(nodeId, m_newPath);
if (m_pieceId != NULL_ID)
{
if (VToolSeamAllowance *tool = qobject_cast<VToolSeamAllowance *>(VAbstractPattern::getTool(m_pieceId)))
{
tool->RefreshGeometry();
}
}
}
else
{
qCDebug(vUndo, "Can't find path with id = %u.", nodeId);
}
}
//---------------------------------------------------------------------------------------------------------------------
bool SavePiecePathOptions::mergeWith(const QUndoCommand *command)
{
const SavePiecePathOptions *saveCommand = static_cast<const SavePiecePathOptions *>(command);
SCASSERT(saveCommand != nullptr);
if (saveCommand->PathId() != nodeId)
{
return false;
}
else
{
const QSet<quint32> currentSet;
currentSet.fromList(m_newPath.Dependencies());
const VPiecePath candidate = saveCommand->NewPath();
const QSet<quint32> candidateSet;
candidateSet.fromList(candidate.Dependencies());
if (currentSet != candidateSet)
{
return false;
}
}
m_newPath = saveCommand->NewPath();
return true;
}

View File

@ -37,12 +37,16 @@
class SavePiecePathOptions : public VUndoCommand
{
public:
SavePiecePathOptions(const VPiecePath &oldPath, const VPiecePath &newPath, VAbstractPattern *doc,
SavePiecePathOptions(quint32 pieceId, const VPiecePath &oldPath, const VPiecePath &newPath, VAbstractPattern *doc,
VContainer *data, quint32 id, QUndoCommand *parent = nullptr);
virtual ~SavePiecePathOptions() = default;
virtual void undo() Q_DECL_OVERRIDE;
virtual void redo() Q_DECL_OVERRIDE;
virtual bool mergeWith(const QUndoCommand *command) Q_DECL_OVERRIDE;
virtual int id() const Q_DECL_OVERRIDE;
quint32 PathId() const;
VPiecePath NewPath() const;
private:
Q_DISABLE_COPY(SavePiecePathOptions)
@ -50,6 +54,25 @@ private:
VPiecePath m_newPath;
VContainer *m_data;
quint32 m_pieceId;
};
//---------------------------------------------------------------------------------------------------------------------
inline int SavePiecePathOptions::id() const
{
return static_cast<int>(UndoCommand::SavePiecePathOptions);
}
//---------------------------------------------------------------------------------------------------------------------
inline quint32 SavePiecePathOptions::PathId() const
{
return nodeId;
}
//---------------------------------------------------------------------------------------------------------------------
inline VPiecePath SavePiecePathOptions::NewPath() const
{
return m_newPath;
}
#endif // SAVEPIECEPATHOPTIONS_H

View File

@ -27,14 +27,17 @@
*************************************************************************/
#include "saveplacelabeloptions.h"
#include "../tools/nodeDetails/vtoolplacelabel.h"
#include "../tools/vtoolseamallowance.h"
//---------------------------------------------------------------------------------------------------------------------
SavePlaceLabelOptions::SavePlaceLabelOptions(const VPlaceLabelItem &oldLabel, const VPlaceLabelItem &newLabel,
VAbstractPattern *doc, VContainer *data, quint32 id, QUndoCommand *parent)
SavePlaceLabelOptions::SavePlaceLabelOptions(quint32 pieceId, const VPlaceLabelItem &oldLabel,
const VPlaceLabelItem &newLabel, VAbstractPattern *doc, VContainer *data,
quint32 id, QUndoCommand *parent)
: VUndoCommand(QDomElement(), doc, parent),
m_oldLabel(oldLabel),
m_newLabel(newLabel),
m_data(data)
m_data(data),
m_pieceId(pieceId)
{
setText(tr("save place label options"));
nodeId = id;
@ -58,6 +61,14 @@ void SavePlaceLabelOptions::undo()
SCASSERT(m_data);
m_data->UpdateGObject(nodeId, new VPlaceLabelItem(m_oldLabel));
if (m_pieceId != NULL_ID)
{
if (VToolSeamAllowance *tool = qobject_cast<VToolSeamAllowance *>(VAbstractPattern::getTool(m_pieceId)))
{
tool->RefreshGeometry();
}
}
}
else
{
@ -83,9 +94,41 @@ void SavePlaceLabelOptions::redo()
SCASSERT(m_data);
m_data->UpdateGObject(nodeId, new VPlaceLabelItem(m_newLabel));
if (m_pieceId != NULL_ID)
{
if (VToolSeamAllowance *tool = qobject_cast<VToolSeamAllowance *>(VAbstractPattern::getTool(m_pieceId)))
{
tool->RefreshGeometry();
}
}
}
else
{
qCDebug(vUndo, "Can't find path with id = %u.", nodeId);
}
}
//---------------------------------------------------------------------------------------------------------------------
bool SavePlaceLabelOptions::mergeWith(const QUndoCommand *command)
{
const SavePlaceLabelOptions *saveCommand = static_cast<const SavePlaceLabelOptions *>(command);
SCASSERT(saveCommand != nullptr);
if (saveCommand->LabelId() != nodeId)
{
return false;
}
else
{
const VPlaceLabelItem candidate = saveCommand->NewLabel();
if (m_newLabel.GetCenterPoint() != candidate.GetCenterPoint())
{
return false;
}
}
m_newLabel = saveCommand->NewLabel();
return true;
}

View File

@ -34,12 +34,17 @@
class SavePlaceLabelOptions : public VUndoCommand
{
public:
SavePlaceLabelOptions(const VPlaceLabelItem &oldLabel, const VPlaceLabelItem &newLabel, VAbstractPattern *doc,
VContainer *data, quint32 id, QUndoCommand *parent = nullptr);
SavePlaceLabelOptions(quint32 pieceId, const VPlaceLabelItem &oldLabel, const VPlaceLabelItem &newLabel,
VAbstractPattern *doc, VContainer *data, quint32 id, QUndoCommand *parent = nullptr);
virtual ~SavePlaceLabelOptions()=default;
virtual void undo() Q_DECL_OVERRIDE;
virtual void redo() Q_DECL_OVERRIDE;
virtual bool mergeWith(const QUndoCommand *command) Q_DECL_OVERRIDE;
virtual int id() const Q_DECL_OVERRIDE;
quint32 LabelId() const;
VPlaceLabelItem NewLabel() const;
private:
Q_DISABLE_COPY(SavePlaceLabelOptions)
@ -47,6 +52,25 @@ private:
VPlaceLabelItem m_newLabel;
VContainer *m_data;
quint32 m_pieceId;
};
//---------------------------------------------------------------------------------------------------------------------
inline int SavePlaceLabelOptions::id() const
{
return static_cast<int>(UndoCommand::SavePlaceLabelOptions);
}
//---------------------------------------------------------------------------------------------------------------------
inline quint32 SavePlaceLabelOptions::LabelId() const
{
return nodeId;
}
//---------------------------------------------------------------------------------------------------------------------
inline VPlaceLabelItem SavePlaceLabelOptions::NewLabel() const
{
return m_newLabel;
}
#endif // SAVEPLACELABELOPTIONS_H

View File

@ -98,3 +98,31 @@ QVector<quint32> SaveToolOptions::Missing(const QList<quint32> &list1, const QLi
QSet<quint32> set2 = QSet<quint32>::fromList(list2);
return set1.subtract(set2).toList().toVector();
}
//---------------------------------------------------------------------------------------------------------------------
bool SaveToolOptions::mergeWith(const QUndoCommand *command)
{
const SaveToolOptions *saveCommand = static_cast<const SaveToolOptions *>(command);
SCASSERT(saveCommand != nullptr)
if (saveCommand->getToolId() != nodeId)
{
return false;
}
else
{
const QSet<quint32> currentSet;
currentSet.fromList(newDependencies);
const QSet<quint32> candidateSet;
candidateSet.fromList(saveCommand->NewDependencies());
if (currentSet != candidateSet)
{
return false;
}
}
newXml = saveCommand->getNewXml();
return true;
}

View File

@ -48,14 +48,44 @@ public:
virtual ~SaveToolOptions() = default;
virtual void undo() Q_DECL_OVERRIDE;
virtual void redo() Q_DECL_OVERRIDE;
virtual bool mergeWith(const QUndoCommand *command) Q_DECL_OVERRIDE;
virtual int id() const Q_DECL_OVERRIDE;
QDomElement getNewXml() const;
quint32 getToolId() const;
QList<quint32> NewDependencies() const;
private:
Q_DISABLE_COPY(SaveToolOptions)
const QDomElement oldXml;
const QDomElement newXml;
QDomElement newXml;
const QList<quint32> oldDependencies;
const QList<quint32> newDependencies;
QVector<quint32> Missing(const QList<quint32> &list1, const QList<quint32> &list2) const;
};
//---------------------------------------------------------------------------------------------------------------------
inline int SaveToolOptions::id() const
{
return static_cast<int>(UndoCommand::SaveToolOptions);
}
//---------------------------------------------------------------------------------------------------------------------
inline QDomElement SaveToolOptions::getNewXml() const
{
return newXml;
}
//---------------------------------------------------------------------------------------------------------------------
inline quint32 SaveToolOptions::getToolId() const
{
return nodeId;
}
//---------------------------------------------------------------------------------------------------------------------
inline QList<quint32> SaveToolOptions::NewDependencies() const
{
return newDependencies;
}
#endif // SAVETOOLOPTIONS_H

View File

@ -137,7 +137,7 @@ QString VisToolMove::Angle() const
//---------------------------------------------------------------------------------------------------------------------
void VisToolMove::SetAngle(const QString &expression)
{
angle = FindVal(expression, Visualization::data->DataVariables());
angle = FindValFromUser(expression, Visualization::data->DataVariables());
}
//---------------------------------------------------------------------------------------------------------------------
@ -155,7 +155,7 @@ qreal VisToolMove::LengthValue() const
//---------------------------------------------------------------------------------------------------------------------
void VisToolMove::SetLength(const QString &expression)
{
length = FindLength(expression, Visualization::data->DataVariables());
length = FindLengthFromUser(expression, Visualization::data->DataVariables());
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -207,7 +207,7 @@ QString VisToolRotation::Angle() const
//---------------------------------------------------------------------------------------------------------------------
void VisToolRotation::SetAngle(const QString &expression)
{
angle = FindVal(expression, Visualization::data->DataVariables());
angle = FindValFromUser(expression, Visualization::data->DataVariables());
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -66,7 +66,7 @@ void VisToolAlongLine::setObject2Id(const quint32 &value)
//---------------------------------------------------------------------------------------------------------------------
void VisToolAlongLine::setLength(const QString &expression)
{
length = FindLength(expression, Visualization::data->DataVariables());
length = FindLengthFromUser(expression, Visualization::data->DataVariables());
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -72,7 +72,7 @@ void VisToolBisector::setObject3Id(const quint32 &value)
//---------------------------------------------------------------------------------------------------------------------
void VisToolBisector::setLength(const QString &expression)
{
length = FindLength(expression, Visualization::data->DataVariables());
length = FindLengthFromUser(expression, Visualization::data->DataVariables());
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -105,7 +105,7 @@ QString VisToolCurveIntersectAxis::Angle() const
//---------------------------------------------------------------------------------------------------------------------
void VisToolCurveIntersectAxis::SetAngle(const QString &expression)
{
angle = FindVal(expression, Visualization::data->DataVariables());
angle = FindValFromUser(expression, Visualization::data->DataVariables());
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -96,7 +96,7 @@ QString VisToolEndLine::Angle() const
//---------------------------------------------------------------------------------------------------------------------
void VisToolEndLine::SetAngle(const QString &expression)
{
angle = FindVal(expression, Visualization::data->DataVariables());
angle = FindValFromUser(expression, Visualization::data->DataVariables());
}
//---------------------------------------------------------------------------------------------------------------------
@ -108,5 +108,5 @@ QString VisToolEndLine::Length() const
//---------------------------------------------------------------------------------------------------------------------
void VisToolEndLine::setLength(const QString &expression)
{
length = FindLength(expression, Visualization::data->DataVariables());
length = FindLengthFromUser(expression, Visualization::data->DataVariables());
}

View File

@ -118,7 +118,7 @@ QString VisToolLineIntersectAxis::Angle() const
//---------------------------------------------------------------------------------------------------------------------
void VisToolLineIntersectAxis::SetAngle(const QString &expression)
{
angle = FindVal(expression, Visualization::data->DataVariables());
angle = FindValFromUser(expression, Visualization::data->DataVariables());
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -110,7 +110,7 @@ void VisToolNormal::setObject2Id(const quint32 &value)
//---------------------------------------------------------------------------------------------------------------------
void VisToolNormal::setLength(const QString &expression)
{
length = FindLength(expression, Visualization::data->DataVariables());
length = FindLengthFromUser(expression, Visualization::data->DataVariables());
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -92,7 +92,7 @@ void VisToolPointFromCircleAndTangent::setObject2Id(const quint32 &value)
//---------------------------------------------------------------------------------------------------------------------
void VisToolPointFromCircleAndTangent::setCRadius(const QString &value)
{
cRadius = FindLength(value, Visualization::data->DataVariables());
cRadius = FindLengthFromUser(value, Visualization::data->DataVariables());
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -108,5 +108,5 @@ void VisToolPointOfContact::setRadiusId(const quint32 &value)
//---------------------------------------------------------------------------------------------------------------------
void VisToolPointOfContact::setRadius(const QString &expression)
{
radius = FindLength(expression, Visualization::data->DataVariables());
radius = FindLengthFromUser(expression, Visualization::data->DataVariables());
}

View File

@ -111,13 +111,13 @@ void VisToolPointOfIntersectionCircles::setObject2Id(const quint32 &value)
//---------------------------------------------------------------------------------------------------------------------
void VisToolPointOfIntersectionCircles::setC1Radius(const QString &value)
{
c1Radius = FindLength(value, Visualization::data->DataVariables());
c1Radius = FindLengthFromUser(value, Visualization::data->DataVariables());
}
//---------------------------------------------------------------------------------------------------------------------
void VisToolPointOfIntersectionCircles::setC2Radius(const QString &value)
{
c2Radius = FindLength(value, Visualization::data->DataVariables());
c2Radius = FindLengthFromUser(value, Visualization::data->DataVariables());
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -129,5 +129,5 @@ void VisToolShoulderPoint::setLineP2Id(const quint32 &value)
//---------------------------------------------------------------------------------------------------------------------
void VisToolShoulderPoint::setLength(const QString &expression)
{
length = FindLength(expression, Visualization::data->DataVariables());
length = FindLengthFromUser(expression, Visualization::data->DataVariables());
}

View File

@ -70,17 +70,17 @@ void VisToolArc::RefreshGeometry()
//---------------------------------------------------------------------------------------------------------------------
void VisToolArc::setRadius(const QString &expression)
{
radius = FindLength(expression, Visualization::data->DataVariables());
radius = FindLengthFromUser(expression, Visualization::data->DataVariables());
}
//---------------------------------------------------------------------------------------------------------------------
void VisToolArc::setF1(const QString &expression)
{
f1 = FindVal(expression, Visualization::data->DataVariables());
f1 = FindValFromUser(expression, Visualization::data->DataVariables());
}
//---------------------------------------------------------------------------------------------------------------------
void VisToolArc::setF2(const QString &expression)
{
f2 = FindVal(expression, Visualization::data->DataVariables());
f2 = FindValFromUser(expression, Visualization::data->DataVariables());
}

View File

@ -69,17 +69,17 @@ void VisToolArcWithLength::RefreshGeometry()
//---------------------------------------------------------------------------------------------------------------------
void VisToolArcWithLength::setRadius(const QString &expression)
{
radius = FindLength(expression, Visualization::data->DataVariables());
radius = FindLengthFromUser(expression, Visualization::data->DataVariables());
}
//---------------------------------------------------------------------------------------------------------------------
void VisToolArcWithLength::setF1(const QString &expression)
{
f1 = FindVal(expression, Visualization::data->DataVariables());
f1 = FindValFromUser(expression, Visualization::data->DataVariables());
}
//---------------------------------------------------------------------------------------------------------------------
void VisToolArcWithLength::setLength(const QString &expression)
{
length = FindLength(expression, Visualization::data->DataVariables());
length = FindLengthFromUser(expression, Visualization::data->DataVariables());
}

View File

@ -82,5 +82,5 @@ void VisToolCutArc::RefreshGeometry()
//---------------------------------------------------------------------------------------------------------------------
void VisToolCutArc::setLength(const QString &expression)
{
length = FindLength(expression, Visualization::data->DataVariables());
length = FindLengthFromUser(expression, Visualization::data->DataVariables());
}

View File

@ -90,5 +90,5 @@ void VisToolCutSpline::RefreshGeometry()
//---------------------------------------------------------------------------------------------------------------------
void VisToolCutSpline::setLength(const QString &expression)
{
length = FindLength(expression, Visualization::data->DataVariables());
length = FindLengthFromUser(expression, Visualization::data->DataVariables());
}

View File

@ -91,5 +91,5 @@ void VisToolCutSplinePath::RefreshGeometry()
//---------------------------------------------------------------------------------------------------------------------
void VisToolCutSplinePath::setLength(const QString &expression)
{
length = FindLength(expression, Visualization::data->DataVariables());
length = FindLengthFromUser(expression, Visualization::data->DataVariables());
}

View File

@ -65,29 +65,29 @@ void VisToolEllipticalArc::RefreshGeometry()
//---------------------------------------------------------------------------------------------------------------------
void VisToolEllipticalArc::setRadius1(const QString &expression)
{
radius1 = FindLength(expression, Visualization::data->DataVariables());
radius1 = FindLengthFromUser(expression, Visualization::data->DataVariables());
}
//---------------------------------------------------------------------------------------------------------------------
void VisToolEllipticalArc::setRadius2(const QString &expression)
{
radius2 = FindLength(expression, Visualization::data->DataVariables());
radius2 = FindLengthFromUser(expression, Visualization::data->DataVariables());
}
//---------------------------------------------------------------------------------------------------------------------
void VisToolEllipticalArc::setF1(const QString &expression)
{
f1 = FindVal(expression, Visualization::data->DataVariables());
f1 = FindValFromUser(expression, Visualization::data->DataVariables());
}
//---------------------------------------------------------------------------------------------------------------------
void VisToolEllipticalArc::setF2(const QString &expression)
{
f2 = FindVal(expression, Visualization::data->DataVariables());
f2 = FindValFromUser(expression, Visualization::data->DataVariables());
}
//---------------------------------------------------------------------------------------------------------------------
void VisToolEllipticalArc::setRotationAngle(const QString &expression)
{
rotationAngle = FindVal(expression, Visualization::data->DataVariables());
rotationAngle = FindValFromUser(expression, Visualization::data->DataVariables());
}

View File

@ -143,15 +143,15 @@ VScaledEllipse *Visualization::InitPoint(const QColor &color, QGraphicsItem *par
}
//---------------------------------------------------------------------------------------------------------------------
qreal Visualization::FindLength(const QString &expression,
const QHash<QString, QSharedPointer<VInternalVariable> > *vars)
qreal Visualization::FindLengthFromUser(const QString &expression,
const QHash<QString, QSharedPointer<VInternalVariable> > *vars, bool fromUser)
{
return qApp->toPixel(FindVal(expression, vars));
return qApp->toPixel(FindValFromUser(expression, vars, fromUser));
}
//---------------------------------------------------------------------------------------------------------------------
qreal Visualization::FindVal(const QString &expression,
const QHash<QString, QSharedPointer<VInternalVariable> > *vars)
qreal Visualization::FindValFromUser(const QString &expression,
const QHash<QString, QSharedPointer<VInternalVariable> > *vars, bool fromUser)
{
qreal val = 0;
if (expression.isEmpty())
@ -165,7 +165,11 @@ qreal Visualization::FindVal(const QString &expression,
// Replace line return with spaces for calc if exist
QString formula = expression;
formula.replace("\n", " ");
formula = qApp->TrVars()->FormulaFromUser(formula, qApp->Settings()->GetOsSeparator());
if (fromUser)
{
formula = qApp->TrVars()->FormulaFromUser(formula, qApp->Settings()->GetOsSeparator());
}
QScopedPointer<Calculator> cal(new Calculator());
val = cal->EvalFormula(vars, formula);

View File

@ -72,8 +72,10 @@ public:
Mode GetMode() const;
void SetMode(const Mode &value);
static qreal FindLength(const QString &expression, const QHash<QString, QSharedPointer<VInternalVariable> > *vars);
static qreal FindVal(const QString &expression, const QHash<QString, QSharedPointer<VInternalVariable> > *vars);
static qreal FindLengthFromUser(const QString &expression, const QHash<QString,
QSharedPointer<VInternalVariable> > *vars, bool fromUser = true);
static qreal FindValFromUser(const QString &expression, const QHash<QString,
QSharedPointer<VInternalVariable> > *vars, bool fromUser = true);
signals:
void ToolTip(const QString &toolTip);
public slots: