Refactoring. More switch tests. Added tool button for tool Cubic bezier path.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2016-03-17 20:12:48 +02:00
parent 54294f1a71
commit 56496aaa59
16 changed files with 201 additions and 131 deletions

View File

@ -31,6 +31,7 @@
#include "../vgeometry/varc.h" #include "../vgeometry/varc.h"
#include "../vgeometry/vcubicbezier.h" #include "../vgeometry/vcubicbezier.h"
#include "../vgeometry/vsplinepath.h" #include "../vgeometry/vsplinepath.h"
#include "../vgeometry/vcubicbezierpath.h"
#include "../vgeometry/vpointf.h" #include "../vgeometry/vpointf.h"
#include "../vtools/tools/vabstracttool.h" #include "../vtools/tools/vabstracttool.h"
#include "../vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.h" #include "../vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.h"
@ -194,12 +195,11 @@ void DialogHistory::FillTable()
ui->tableWidget->verticalHeader()->setDefaultSectionSize(20); ui->tableWidget->verticalHeader()->setDefaultSectionSize(20);
} }
//---------------------------------------------------------------------------------------------------------------------
#if defined(Q_CC_GNU) #if defined(Q_CC_GNU)
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wswitch-default" #pragma GCC diagnostic ignored "-Wswitch-default"
#endif #endif
//---------------------------------------------------------------------------------------------------------------------
/** /**
* @brief Record return description for record * @brief Record return description for record
* @param tool record data * @param tool record data
@ -208,7 +208,7 @@ void DialogHistory::FillTable()
QString DialogHistory::Record(const VToolRecord &tool) QString DialogHistory::Record(const VToolRecord &tool)
{ {
// This check helps to find missed tools in the switch // This check helps to find missed tools in the switch
Q_STATIC_ASSERT_X(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 40, "Not all tools was used in history."); Q_STATIC_ASSERT_X(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 41, "Not all tools was used in history.");
const QDomElement domElem = doc->elementById(tool.getId()); const QDomElement domElem = doc->elementById(tool.getId());
if (domElem.isElement() == false) if (domElem.isElement() == false)
@ -268,49 +268,39 @@ QString DialogHistory::Record(const VToolRecord &tool)
{ {
const QSharedPointer<VSpline> spl = data->GeometricObject<VSpline>(tool.getId()); const QSharedPointer<VSpline> spl = data->GeometricObject<VSpline>(tool.getId());
SCASSERT(spl != nullptr); SCASSERT(spl != nullptr);
return QString(tr("Curve %1_%2")).arg(PointName(spl->GetP1().id())).arg(PointName(spl->GetP4().id())); return spl->NameForHistory(tr("Curve"));
} }
case Tool::CubicBezier: case Tool::CubicBezier:
{ {
const QSharedPointer<VCubicBezier> spl = data->GeometricObject<VCubicBezier>(tool.getId()); const QSharedPointer<VCubicBezier> spl = data->GeometricObject<VCubicBezier>(tool.getId());
SCASSERT(spl != nullptr); SCASSERT(spl != nullptr);
return QString(tr("Cubic bezier curve %1_%2")).arg(PointName(spl->GetP1().id())) return spl->NameForHistory(tr("Cubic bezier curve"));
.arg(PointName(spl->GetP4().id()));
} }
case Tool::Arc: case Tool::Arc:
{ {
const QSharedPointer<VArc> arc = data->GeometricObject<VArc>(tool.getId()); const QSharedPointer<VArc> arc = data->GeometricObject<VArc>(tool.getId());
SCASSERT(arc != nullptr); SCASSERT(arc != nullptr);
return QString(tr("Arc with center in point %1")).arg(PointName(arc->GetCenter().id())); return arc->NameForHistory(tr("Arc"));
} }
case Tool::ArcWithLength: case Tool::ArcWithLength:
{ {
const QSharedPointer<VArc> arc = data->GeometricObject<VArc>(tool.getId()); const QSharedPointer<VArc> arc = data->GeometricObject<VArc>(tool.getId());
SCASSERT(arc != nullptr); SCASSERT(arc != nullptr);
return QString(tr("Arc with center in point %1 and length %2")).arg(PointName(arc->GetCenter().id())) return QString(tr("%1 with length %2"))
.arg(arc->NameForHistory(tr("Arc")))
.arg(arc->GetLength()); .arg(arc->GetLength());
} }
case Tool::SplinePath: case Tool::SplinePath:
{ {
const QSharedPointer<VSplinePath> splPath = data->GeometricObject<VSplinePath>(tool.getId()); const QSharedPointer<VSplinePath> splPath = data->GeometricObject<VSplinePath>(tool.getId());
SCASSERT(splPath != nullptr); SCASSERT(splPath != nullptr);
const QVector<VSplinePoint> points = splPath->GetSplinePath(); return splPath->NameForHistory(tr("Spline path"));
QString record; }
if (points.size() != 0 ) case Tool::CubicBezierPath:
{ {
// We use only first and last point name in curve const QSharedPointer<VCubicBezierPath> splPath = data->GeometricObject<VCubicBezierPath>(tool.getId());
record = QString(tr("Curve point %1")).arg(PointName(points.at(0).P().id())); SCASSERT(splPath != nullptr);
if (points.size() > 1) return splPath->NameForHistory(tr("Cubic bezier curve path"));
{
record.append(QString("_%1").arg(PointName(points.last().P().id())));
}
}
else
{
qDebug()<<"Not enough points in splinepath"<<Q_FUNC_INFO;
return tr("Can't create record.");
}
return record;
} }
case Tool::PointOfContact: case Tool::PointOfContact:
return QString(tr("%4 - point of contact of arc with the center in point %1 and line %2_%3")) return QString(tr("%4 - point of contact of arc with the center in point %1 and line %2_%3"))
@ -338,43 +328,27 @@ QString DialogHistory::Record(const VToolRecord &tool)
{ {
const QSharedPointer<VArc> arc = data->GeometricObject<VArc>(AttrUInt(domElem, AttrArc)); const QSharedPointer<VArc> arc = data->GeometricObject<VArc>(AttrUInt(domElem, AttrArc));
SCASSERT(arc != nullptr); SCASSERT(arc != nullptr);
return QString(tr("%1 - cut arc with center %2")) return QString(tr("%1 - cut %2"))
.arg(PointName(tool.getId())) .arg(PointName(tool.getId()))
.arg(PointName(arc->GetCenter().id())); .arg(arc->NameForHistory(tr("arc")));
} }
case Tool::CutSpline: case Tool::CutSpline:
{ {
const quint32 splineId = AttrUInt(domElem, VToolCutSpline::AttrSpline); const quint32 splineId = AttrUInt(domElem, VToolCutSpline::AttrSpline);
const QSharedPointer<VSpline> spl = data->GeometricObject<VSpline>(splineId); const QSharedPointer<VSpline> spl = data->GeometricObject<VSpline>(splineId);
SCASSERT(spl != nullptr); SCASSERT(spl != nullptr);
return QString(tr("%1 - cut curve %2_%3")) return QString(tr("%1 - cut %2"))
.arg(PointName(tool.getId())) .arg(PointName(tool.getId()))
.arg(PointName(spl->GetP1().id())) .arg(spl->NameForHistory(tr("curve")));
.arg(PointName(spl->GetP4().id()));
} }
case Tool::CutSplinePath: case Tool::CutSplinePath:
{ {
const quint32 splinePathId = AttrUInt(domElem, VToolCutSplinePath::AttrSplinePath); const quint32 splinePathId = AttrUInt(domElem, VToolCutSplinePath::AttrSplinePath);
const QSharedPointer<VSplinePath> splPath = data->GeometricObject<VSplinePath>(splinePathId); const QSharedPointer<VSplinePath> splPath = data->GeometricObject<VSplinePath>(splinePathId);
SCASSERT(splPath != nullptr); SCASSERT(splPath != nullptr);
const QVector<VSplinePoint> points = splPath->GetSplinePath(); return QString(tr("%1 - cut %2"))
QString record; .arg(PointName(tool.getId()))
if (points.size() != 0 ) .arg(splPath->NameForHistory(tr("curve path")));
{
record = QString(tr("%1 - cut curve path %2"))
.arg(PointName(tool.getId()))
.arg(PointName(points.at(0).P().id()));
if (points.size() > 1)
{
record.append(QString("_%1").arg(PointName(points.last().P().id())));
}
}
else
{
qDebug()<<"Not enough points in splinepath"<<Q_FUNC_INFO;
return QString(tr("Can't create record."));
}
return record;
} }
case Tool::LineIntersectAxis: case Tool::LineIntersectAxis:
return QString(tr("%1 - point of intersection line %2_%3 and axis through point %4")) return QString(tr("%1 - point of intersection line %2_%3 and axis through point %4"))

View File

@ -830,6 +830,12 @@ void MainWindow::ToolSplinePath(bool checked)
&MainWindow::ApplyDialog<VToolSplinePath>); &MainWindow::ApplyDialog<VToolSplinePath>);
} }
//---------------------------------------------------------------------------------------------------------------------
void MainWindow::ToolCubicBezierPath(bool checked)
{
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
* @brief ToolCutSplinePath handler tool CutSplinePath. * @brief ToolCutSplinePath handler tool CutSplinePath.
@ -1615,6 +1621,7 @@ void MainWindow::InitToolButtons()
connect(ui->toolButtonCubicBezier, &QToolButton::clicked, this, &MainWindow::ToolCubicBezier); connect(ui->toolButtonCubicBezier, &QToolButton::clicked, this, &MainWindow::ToolCubicBezier);
connect(ui->toolButtonArc, &QToolButton::clicked, this, &MainWindow::ToolArc); connect(ui->toolButtonArc, &QToolButton::clicked, this, &MainWindow::ToolArc);
connect(ui->toolButtonSplinePath, &QToolButton::clicked, this, &MainWindow::ToolSplinePath); connect(ui->toolButtonSplinePath, &QToolButton::clicked, this, &MainWindow::ToolSplinePath);
connect(ui->toolButtonCubicBezierPath, &QToolButton::clicked, this, &MainWindow::ToolCubicBezierPath);
connect(ui->toolButtonPointOfContact, &QToolButton::clicked, this, &MainWindow::ToolPointOfContact); connect(ui->toolButtonPointOfContact, &QToolButton::clicked, this, &MainWindow::ToolPointOfContact);
connect(ui->toolButtonNewDetail, &QToolButton::clicked, this, &MainWindow::ToolDetail); connect(ui->toolButtonNewDetail, &QToolButton::clicked, this, &MainWindow::ToolDetail);
connect(ui->toolButtonHeight, &QToolButton::clicked, this, &MainWindow::ToolHeight); connect(ui->toolButtonHeight, &QToolButton::clicked, this, &MainWindow::ToolHeight);
@ -1669,11 +1676,18 @@ void MainWindow::mouseMove(const QPointF &scenePos)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
#if defined(Q_CC_GNU)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wswitch-default"
#endif
/** /**
* @brief CancelTool cancel tool. * @brief CancelTool cancel tool.
*/ */
void MainWindow::CancelTool() void MainWindow::CancelTool()
{ {
// This check helps to find missed tools in the switch
Q_STATIC_ASSERT_X(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 41, "Not all tools was handled.");
qCDebug(vMainWindow, "Canceling tool."); qCDebug(vMainWindow, "Canceling tool.");
delete dialogTool; delete dialogTool;
dialogTool = nullptr; dialogTool = nullptr;
@ -1692,6 +1706,16 @@ void MainWindow::CancelTool()
redoAction->setEnabled(false); redoAction->setEnabled(false);
return; return;
case Tool::BasePoint: case Tool::BasePoint:
case Tool::SinglePoint:
case Tool::DoublePoint:
case Tool::LinePoint:
case Tool::AbstractSpline:
case Tool::Cut:
case Tool::LAST_ONE_DO_NOT_USE:
case Tool::NodePoint:
case Tool::NodeArc:
case Tool::NodeSpline:
case Tool::NodeSplinePath:
Q_UNREACHABLE(); //-V501 Q_UNREACHABLE(); //-V501
//Nothing to do here because we can't create this tool from main window. //Nothing to do here because we can't create this tool from main window.
break; break;
@ -1731,6 +1755,9 @@ void MainWindow::CancelTool()
case Tool::SplinePath: case Tool::SplinePath:
ui->toolButtonSplinePath->setChecked(false); ui->toolButtonSplinePath->setChecked(false);
break; break;
case Tool::CubicBezierPath:
ui->toolButtonCubicBezierPath->setChecked(false);
break;
case Tool::PointOfContact: case Tool::PointOfContact:
ui->toolButtonPointOfContact->setChecked(false); ui->toolButtonPointOfContact->setChecked(false);
break; break;
@ -1783,13 +1810,6 @@ void MainWindow::CancelTool()
case Tool::TrueDarts: case Tool::TrueDarts:
ui->toolButtonTrueDarts->setChecked(false); ui->toolButtonTrueDarts->setChecked(false);
break; break;
case Tool::NodePoint:
case Tool::NodeArc:
case Tool::NodeSpline:
case Tool::NodeSplinePath:
default:
qDebug()<<"Got wrong tool type. Ignored.";
break;
} }
currentScene->setFocus(Qt::OtherFocusReason); currentScene->setFocus(Qt::OtherFocusReason);
currentScene->clearSelection(); currentScene->clearSelection();
@ -1801,6 +1821,10 @@ void MainWindow::CancelTool()
redoAction->setEnabled(qApp->getUndoStack()->canRedo()); redoAction->setEnabled(qApp->getUndoStack()->canRedo());
} }
#if defined(Q_CC_GNU)
#pragma GCC diagnostic pop
#endif
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
* @brief ArrowTool enable arrow tool. * @brief ArrowTool enable arrow tool.
@ -2949,6 +2973,7 @@ void MainWindow::SetEnableTool(bool enable)
ui->toolButtonCubicBezier->setEnabled(drawTools); ui->toolButtonCubicBezier->setEnabled(drawTools);
ui->toolButtonArc->setEnabled(drawTools); ui->toolButtonArc->setEnabled(drawTools);
ui->toolButtonSplinePath->setEnabled(drawTools); ui->toolButtonSplinePath->setEnabled(drawTools);
ui->toolButtonCubicBezierPath->setEnabled(drawTools);
ui->toolButtonPointOfContact->setEnabled(drawTools); ui->toolButtonPointOfContact->setEnabled(drawTools);
ui->toolButtonNewDetail->setEnabled(drawTools); ui->toolButtonNewDetail->setEnabled(drawTools);
ui->toolButtonHeight->setEnabled(drawTools); ui->toolButtonHeight->setEnabled(drawTools);
@ -3233,8 +3258,16 @@ void MainWindow::CreateMenus()
AddDocks(); AddDocks();
} }
//---------------------------------------------------------------------------------------------------------------------
#if defined(Q_CC_GNU)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wswitch-default"
#endif
void MainWindow::LastUsedTool() void MainWindow::LastUsedTool()
{ {
// This check helps to find missed tools in the switch
Q_STATIC_ASSERT_X(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 41, "Not all tools was handled.");
if (currentTool == lastUsedTool) if (currentTool == lastUsedTool)
{ {
return; return;
@ -3247,6 +3280,16 @@ void MainWindow::LastUsedTool()
ArrowTool(); ArrowTool();
break; break;
case Tool::BasePoint: case Tool::BasePoint:
case Tool::SinglePoint:
case Tool::DoublePoint:
case Tool::LinePoint:
case Tool::AbstractSpline:
case Tool::Cut:
case Tool::LAST_ONE_DO_NOT_USE:
case Tool::NodePoint:
case Tool::NodeArc:
case Tool::NodeSpline:
case Tool::NodeSplinePath:
Q_UNREACHABLE(); //-V501 Q_UNREACHABLE(); //-V501
//Nothing to do here because we can't create this tool from main window. //Nothing to do here because we can't create this tool from main window.
break; break;
@ -3282,6 +3325,10 @@ void MainWindow::LastUsedTool()
ui->toolButtonSpline->setChecked(true); ui->toolButtonSpline->setChecked(true);
ToolSpline(true); ToolSpline(true);
break; break;
case Tool::CubicBezier:
ui->toolButtonCubicBezier->setChecked(true);
ToolCubicBezier(true);
break;
case Tool::Arc: case Tool::Arc:
ui->toolButtonArc->setChecked(true); ui->toolButtonArc->setChecked(true);
ToolArc(true); ToolArc(true);
@ -3290,6 +3337,10 @@ void MainWindow::LastUsedTool()
ui->toolButtonSplinePath->setChecked(true); ui->toolButtonSplinePath->setChecked(true);
ToolSplinePath(true); ToolSplinePath(true);
break; break;
case Tool::CubicBezierPath:
ui->toolButtonCubicBezierPath->setChecked(true);
ToolCubicBezierPath(true);
break;
case Tool::PointOfContact: case Tool::PointOfContact:
ui->toolButtonPointOfContact->setChecked(true); ui->toolButtonPointOfContact->setChecked(true);
ToolPointOfContact(true); ToolPointOfContact(true);
@ -3362,16 +3413,13 @@ void MainWindow::LastUsedTool()
ui->toolButtonTrueDarts->setChecked(true); ui->toolButtonTrueDarts->setChecked(true);
ToolTrueDarts(true); ToolTrueDarts(true);
break; break;
case Tool::NodePoint:
case Tool::NodeArc:
case Tool::NodeSpline:
case Tool::NodeSplinePath:
default:
qDebug()<<"Got wrong tool type. Ignored.";
break;
} }
} }
#if defined(Q_CC_GNU)
#pragma GCC diagnostic pop
#endif
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void MainWindow::AddDocks() void MainWindow::AddDocks()
{ {

View File

@ -112,6 +112,7 @@ public slots:
void ToolCutSpline(bool checked); void ToolCutSpline(bool checked);
void ToolArc(bool checked); void ToolArc(bool checked);
void ToolSplinePath(bool checked); void ToolSplinePath(bool checked);
void ToolCubicBezierPath(bool checked);
void ToolCutSplinePath(bool checked); void ToolCutSplinePath(bool checked);
void ToolPointOfContact(bool checked); void ToolPointOfContact(bool checked);
void ToolDetail(bool checked); void ToolDetail(bool checked);

View File

@ -618,7 +618,33 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="1"> <item row="3" column="0">
<widget class="QToolButton" name="toolButtonIntersectionCurves">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Point intersection curves</string>
</property>
<property name="text">
<string notr="true">...</string>
</property>
<property name="icon">
<iconset resource="share/resources/toolicon.qrc">
<normaloff>:/toolicon/32x32/intersection_curves.png</normaloff>:/toolicon/32x32/intersection_curves.png</iconset>
</property>
<property name="iconSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QToolButton" name="toolButtonCurveIntersectAxis"> <widget class="QToolButton" name="toolButtonCurveIntersectAxis">
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>false</bool>
@ -644,20 +670,17 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="0"> <item row="2" column="1">
<widget class="QToolButton" name="toolButtonIntersectionCurves"> <widget class="QToolButton" name="toolButtonCubicBezierPath">
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>false</bool>
</property> </property>
<property name="toolTip">
<string>Point intersection curves</string>
</property>
<property name="text"> <property name="text">
<string notr="true">...</string> <string notr="true">...</string>
</property> </property>
<property name="icon"> <property name="icon">
<iconset resource="share/resources/toolicon.qrc"> <iconset resource="share/resources/toolicon.qrc">
<normaloff>:/toolicon/32x32/intersection_curves.png</normaloff>:/toolicon/32x32/intersection_curves.png</iconset> <normaloff>:/toolicon/32x32/cubic_bezier_path.png</normaloff>:/toolicon/32x32/cubic_bezier_path.png</iconset>
</property> </property>
<property name="iconSize"> <property name="iconSize">
<size> <size>

View File

@ -3036,7 +3036,7 @@ void VPattern::ToolsCommonAttributes(const QDomElement &domElement, quint32 &id)
QRectF VPattern::ActiveDrawBoundingRect() const QRectF VPattern::ActiveDrawBoundingRect() const
{ {
// This check helps to find missed tools in the switch // This check helps to find missed tools in the switch
Q_STATIC_ASSERT_X(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 40, "Not all tools was used."); Q_STATIC_ASSERT_X(static_cast<int>(Tool::LAST_ONE_DO_NOT_USE) == 41, "Not all tools was used.");
QRectF rec; QRectF rec;
@ -3057,91 +3057,37 @@ QRectF VPattern::ActiveDrawBoundingRect() const
Q_UNREACHABLE(); Q_UNREACHABLE();
break; break;
case Tool::BasePoint: case Tool::BasePoint:
rec = ToolBoundingRect<VToolBasePoint>(rec, tool.getId());
break;
case Tool::EndLine: case Tool::EndLine:
rec = ToolBoundingRect<VToolEndLine>(rec, tool.getId());
break;
case Tool::Line: case Tool::Line:
rec = ToolBoundingRect<VToolLine>(rec, tool.getId());
break;
case Tool::AlongLine: case Tool::AlongLine:
rec = ToolBoundingRect<VToolAlongLine>(rec, tool.getId());
break;
case Tool::ShoulderPoint: case Tool::ShoulderPoint:
rec = ToolBoundingRect<VToolShoulderPoint>(rec, tool.getId());
break;
case Tool::Normal: case Tool::Normal:
rec = ToolBoundingRect<VToolNormal>(rec, tool.getId());
break;
case Tool::Bisector: case Tool::Bisector:
rec = ToolBoundingRect<VToolBisector>(rec, tool.getId());
break;
case Tool::LineIntersect: case Tool::LineIntersect:
rec = ToolBoundingRect<VToolLineIntersect>(rec, tool.getId());
break;
case Tool::Spline: case Tool::Spline:
rec = ToolBoundingRect<VToolSpline>(rec, tool.getId());
break;
case Tool::CubicBezier: case Tool::CubicBezier:
rec = ToolBoundingRect<VToolCubicBezier>(rec, tool.getId());
break;
case Tool::Arc: case Tool::Arc:
rec = ToolBoundingRect<VToolArc>(rec, tool.getId());
break;
case Tool::SplinePath: case Tool::SplinePath:
rec = ToolBoundingRect<VToolSplinePath>(rec, tool.getId()); case Tool::CubicBezierPath:
break;
case Tool::PointOfContact: case Tool::PointOfContact:
rec = ToolBoundingRect<VToolPointOfContact>(rec, tool.getId());
break;
case Tool::Height: case Tool::Height:
rec = ToolBoundingRect<VToolHeight>(rec, tool.getId());
break;
case Tool::Triangle: case Tool::Triangle:
rec = ToolBoundingRect<VToolTriangle>(rec, tool.getId());
break;
case Tool::PointOfIntersection: case Tool::PointOfIntersection:
rec = ToolBoundingRect<VToolPointOfIntersection>(rec, tool.getId());
break;
case Tool::CutArc: case Tool::CutArc:
rec = ToolBoundingRect<VToolCutArc>(rec, tool.getId());
break;
case Tool::CutSpline: case Tool::CutSpline:
rec = ToolBoundingRect<VToolCutSpline>(rec, tool.getId());
break;
case Tool::CutSplinePath: case Tool::CutSplinePath:
rec = ToolBoundingRect<VToolCutSplinePath>(rec, tool.getId());
break;
case Tool::ArcWithLength: case Tool::ArcWithLength:
rec = ToolBoundingRect<VToolArcWithLength>(rec, tool.getId());
break;
case Tool::LineIntersectAxis: case Tool::LineIntersectAxis:
rec = ToolBoundingRect<VToolLineIntersectAxis>(rec, tool.getId());
break;
case Tool::PointOfIntersectionArcs: case Tool::PointOfIntersectionArcs:
rec = ToolBoundingRect<VToolPointOfIntersectionArcs>(rec, tool.getId());
break;
case Tool::PointOfIntersectionCircles: case Tool::PointOfIntersectionCircles:
rec = ToolBoundingRect<VToolPointOfIntersectionCircles>(rec, tool.getId());
break;
case Tool::PointOfIntersectionCurves: case Tool::PointOfIntersectionCurves:
rec = ToolBoundingRect<VToolPointOfIntersectionCurves>(rec, tool.getId());
break;
case Tool::CurveIntersectAxis: case Tool::CurveIntersectAxis:
rec = ToolBoundingRect<VToolCurveIntersectAxis>(rec, tool.getId());
break;
case Tool::PointFromCircleAndTangent: case Tool::PointFromCircleAndTangent:
rec = ToolBoundingRect<VToolPointFromCircleAndTangent>(rec, tool.getId());
break;
case Tool::PointFromArcAndTangent: case Tool::PointFromArcAndTangent:
rec = ToolBoundingRect<VToolPointFromArcAndTangent>(rec, tool.getId());
break;
case Tool::TrueDarts: case Tool::TrueDarts:
rec = ToolBoundingRect<VToolTrueDarts>(rec, tool.getId()); rec = ToolBoundingRect(rec, tool.getId());
break; break;
//Because "history" not only show history of pattern, but help restore current data for each pattern's //These tools are not accesseble in Draw mode, but still 'history' contains them.
//piece, we need add record about details and nodes, but don't show them.
case Tool::Detail: case Tool::Detail:
case Tool::UnionDetails: case Tool::UnionDetails:
case Tool::NodeArc: case Tool::NodeArc:
@ -3160,13 +3106,12 @@ QRectF VPattern::ActiveDrawBoundingRect() const
#endif #endif
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
template <typename T>
QRectF VPattern::ToolBoundingRect(const QRectF &rec, const quint32 &id) const QRectF VPattern::ToolBoundingRect(const QRectF &rec, const quint32 &id) const
{ {
QRectF recTool = rec; QRectF recTool = rec;
if (tools.contains(id)) if (tools.contains(id))
{ {
T *vTool = qobject_cast<T *>(tools.value(id)); const QGraphicsItem *vTool = qobject_cast<QGraphicsItem *>(tools.value(id));
SCASSERT(vTool != nullptr); SCASSERT(vTool != nullptr);
QRectF childrenRect = vTool->childrenBoundingRect(); QRectF childrenRect = vTool->childrenBoundingRect();

View File

@ -135,8 +135,7 @@ private:
void PointsCommonAttributes(const QDomElement &domElement, quint32 &id, qreal &mx, qreal &my); void PointsCommonAttributes(const QDomElement &domElement, quint32 &id, qreal &mx, qreal &my);
void SplinesCommonAttributes(const QDomElement &domElement, quint32 &id, quint32 &idObject, void SplinesCommonAttributes(const QDomElement &domElement, quint32 &id, quint32 &idObject,
quint32 &idTool); quint32 &idTool);
template <typename T> QRectF ToolBoundingRect(const QRectF &rec, const quint32 &id) const;
QRectF ToolBoundingRect(const QRectF &rec, const quint32 &id) const;
void ParseCurrentPP(); void ParseCurrentPP();
QString GetLabelBase(quint32 index)const; QString GetLabelBase(quint32 index)const;

View File

@ -126,6 +126,17 @@ QPointF VAbstractCubicBezier::CutSpline(qreal length, QPointF &spl1p2, QPointF &
return p1234; return p1234;
} }
//---------------------------------------------------------------------------------------------------------------------
QString VAbstractCubicBezier::NameForHistory(const QString &toolName) const
{
QString name = toolName + QString(" %1_%2").arg(GetP1().name()).arg(GetP4().name());
if (GetDuplicate() > 0)
{
name += QString("_%1").arg(GetDuplicate());
}
return name;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VAbstractCubicBezier::CreateName() void VAbstractCubicBezier::CreateName()
{ {

View File

@ -46,6 +46,8 @@ public:
QPointF CutSpline ( qreal length, QPointF &spl1p2, QPointF &spl1p3, QPointF &spl2p2, QPointF &spl2p3) const; QPointF CutSpline ( qreal length, QPointF &spl1p2, QPointF &spl1p3, QPointF &spl2p2, QPointF &spl2p3) const;
virtual QString NameForHistory(const QString &toolName) const Q_DECL_OVERRIDE;
protected: protected:
virtual void CreateName() Q_DECL_OVERRIDE; virtual void CreateName() Q_DECL_OVERRIDE;

View File

@ -181,6 +181,31 @@ QPointF VAbstractCubicBezierPath::CutSplinePath(qreal length, qint32 &p1, qint32
return QPointF(); return QPointF();
} }
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief NameForHistory helps to create name for dialog History.
* @param toolName first part of name. Like 'Spline path' or 'Cubic Bezier path'.
* @return name of curve for history records.
*/
QString VAbstractCubicBezierPath::NameForHistory(const QString &toolName) const
{
QString name = toolName;
if (CountPoints() > 0)
{
name += QString(" %1").arg(FirstPoint().name());
if (CountSubSpl() >= 1)
{
name += QString("_%1").arg(LastPoint().name());
}
if (GetDuplicate() > 0)
{
name += QString("_%1").arg(GetDuplicate());
}
}
return name;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VAbstractCubicBezierPath::CreateName() void VAbstractCubicBezierPath::CreateName()
{ {

View File

@ -60,6 +60,8 @@ public:
QPointF CutSplinePath(qreal length, qint32 &p1, qint32 &p2, QPointF &spl1p2, QPointF &spl1p3, QPointF &spl2p2, QPointF CutSplinePath(qreal length, qint32 &p1, qint32 &p2, QPointF &spl1p2, QPointF &spl1p3, QPointF &spl2p2,
QPointF &spl2p3) const; QPointF &spl2p3) const;
virtual QString NameForHistory(const QString &toolName) const Q_DECL_OVERRIDE;
protected: protected:
virtual void CreateName() Q_DECL_OVERRIDE; virtual void CreateName() Q_DECL_OVERRIDE;

View File

@ -65,6 +65,8 @@ public:
void SetDuplicate(quint32 number); void SetDuplicate(quint32 number);
static QVector<QPointF> CurveIntersectLine(const QVector<QPointF> &points, const QLineF &line); static QVector<QPointF> CurveIntersectLine(const QVector<QPointF> &points, const QLineF &line);
virtual QString NameForHistory(const QString &toolName) const=0;
protected: protected:
QPainterPath ShowDirection(const QVector<QPointF> &points) const; QPainterPath ShowDirection(const QVector<QPointF> &points) const;
virtual void CreateName() =0; virtual void CreateName() =0;

View File

@ -315,6 +315,23 @@ void VArc::setId(const quint32 &id)
CreateName(); CreateName();
} }
//---------------------------------------------------------------------------------------------------------------------
QString VArc::NameForHistory(const QString &toolName) const
{
QString name = toolName + QString(" %1").arg(this->GetCenter().name());
if (VAbstractCurve::id() != NULL_ID)
{
name += QString("_%1").arg(VAbstractCurve::id());
}
if (GetDuplicate() > 0)
{
name += QString("_%1").arg(GetDuplicate());
}
return name;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VArc::CreateName() void VArc::CreateName()
{ {

View File

@ -80,6 +80,7 @@ public:
QPointF CutArc (const qreal &length, VArc &arc1, VArc &arc2) const; QPointF CutArc (const qreal &length, VArc &arc1, VArc &arc2) const;
QPointF CutArc (const qreal &length) const; QPointF CutArc (const qreal &length) const;
virtual void setId(const quint32 &id) Q_DECL_OVERRIDE; virtual void setId(const quint32 &id) Q_DECL_OVERRIDE;
virtual QString NameForHistory(const QString &toolName) const Q_DECL_OVERRIDE;
protected: protected:
virtual void CreateName() Q_DECL_OVERRIDE; virtual void CreateName() Q_DECL_OVERRIDE;
private: private:

View File

@ -375,6 +375,23 @@ void VEllipticalArc::setId(const quint32 &id)
CreateName(); CreateName();
} }
//---------------------------------------------------------------------------------------------------------------------
QString VEllipticalArc::NameForHistory(const QString &toolName) const
{
QString name = toolName + QString(" %1").arg(this->GetCenter().name());
if (VAbstractCurve::id() != NULL_ID)
{
name += QString("_%1").arg(VAbstractCurve::id());
}
if (GetDuplicate() > 0)
{
name += QString("_%1").arg(GetDuplicate());
}
return name;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VEllipticalArc::CreateName() void VEllipticalArc::CreateName()
{ {

View File

@ -92,6 +92,7 @@ public:
QPointF CutArc (const qreal &length, VEllipticalArc &arc1, VEllipticalArc &arc2) const; QPointF CutArc (const qreal &length, VEllipticalArc &arc1, VEllipticalArc &arc2) const;
QPointF CutArc (const qreal &length) const; QPointF CutArc (const qreal &length) const;
virtual void setId(const quint32 &id) Q_DECL_OVERRIDE; virtual void setId(const quint32 &id) Q_DECL_OVERRIDE;
virtual QString NameForHistory(const QString &toolName) const Q_DECL_OVERRIDE;
protected: protected:
virtual void CreateName() Q_DECL_OVERRIDE; virtual void CreateName() Q_DECL_OVERRIDE;
private: private:

View File

@ -80,6 +80,7 @@ enum class Tool : ToolVisHolderType
Arc, Arc,
ArcWithLength, ArcWithLength,
SplinePath, SplinePath,
CubicBezierPath,
CutSplinePath, CutSplinePath,
PointOfContact, PointOfContact,
Detail, Detail,
@ -129,6 +130,7 @@ enum class Vis : ToolVisHolderType
ToolShoulderPoint, ToolShoulderPoint,
ToolSpline, ToolSpline,
ToolCubicBezier, ToolCubicBezier,
ToolCubicBezierPath,
ToolTriangle, ToolTriangle,
ToolCutSpline, ToolCutSpline,
ToolSplinePath, ToolSplinePath,