/** * @brief AddRecord add record about tool in history. * @param id object id in container * @param toolType tool type * @param doc dom document container */ void VAbstractTool::AddRecord(const quint32 id, const Tool &toolType, VPattern *doc) { QVector<VToolRecord> *history = doc->getHistory(); VToolRecord record = VToolRecord(id, toolType, doc->GetNameActivPP()); if (history->contains(record)) { return; } quint32 cursor = doc->getCursor(); if (cursor <= 0) { history->append(record); } else { qint32 index = 0; for (qint32 i = 0; i<history->size(); ++i) { VToolRecord rec = history->at(i); if (rec.getId() == cursor) { index = i; break; } } history->insert(index+1, record); } }
/** * @brief FillTable fill table */ void DialogHistory::FillTable() { ui->tableWidget->clear(); const QVector<VToolRecord> *history = doc->getHistory(); SCASSERT(history != nullptr); qint32 currentRow = -1; qint32 count = 0; ui->tableWidget->setRowCount(history->size()); for (qint32 i = 0; i< history->size(); ++i) { const VToolRecord tool = history->at(i); if (tool.getNameDraw() != doc->GetNameActivDraw()) { continue; } const QString historyRecord = Record(tool); if (historyRecord.isEmpty() ==false) { currentRow++; { QTableWidgetItem *item = new QTableWidgetItem(QString()); item->setTextAlignment(Qt::AlignHCenter); item->setData(Qt::UserRole, tool.getId()); ui->tableWidget->setItem(currentRow, 0, item); } QTableWidgetItem *item = new QTableWidgetItem(historyRecord); item->setFont(QFont("Times", 12, QFont::Bold)); item->setFlags(item->flags() ^ Qt::ItemIsEditable); ui->tableWidget->setItem(currentRow, 1, item); ++count; } } ui->tableWidget->setRowCount(count); if (history->size()>0) { cursorRow = currentRow; QTableWidgetItem *item = ui->tableWidget->item(cursorRow, 0); SCASSERT(item != nullptr); item->setIcon(QIcon("://icon/32x32/put_after.png")); } ui->tableWidget->resizeColumnsToContents(); ui->tableWidget->resizeRowsToContents(); ui->tableWidget->verticalHeader()->setDefaultSectionSize(20); }
/** * @brief Record return description for record * @param tool record data * @return description */ QString DialogHistory::Record(const VToolRecord &tool) { const QDomElement domElement = doc->elementById(QString().setNum(tool.getId())); if (domElement.isElement() == false) { qDebug()<<"Can't find element by id"<<Q_FUNC_INFO; return QString(tr("Can't create record.")); } try { switch ( tool.getTypeTool() ) { case Tool::ArrowTool: Q_UNREACHABLE(); break; case Tool::SinglePointTool: { const QString name = data->GeometricObject<const VPointF *>(tool.getId())->name(); return QString(tr("%1 - Base point")).arg(name); } case Tool::EndLineTool: { const quint32 basePointId = doc->GetParametrUInt(domElement, VAbstractTool::AttrBasePoint, "0"); const QString basePointIdName = data->GeometricObject<const VPointF *>(basePointId)->name(); const QString toolIdName = data->GeometricObject<const VPointF *>(tool.getId())->name(); return QString(tr("%1_%2 - Line from point %1 to point %2")).arg(basePointIdName, toolIdName); } case Tool::LineTool: { const quint32 firstPointId = doc->GetParametrUInt(domElement, VAbstractTool::AttrFirstPoint, "0"); const quint32 secondPointId = doc->GetParametrUInt(domElement, VAbstractTool::AttrSecondPoint, "0"); const QString firstPointIdName = data->GeometricObject<const VPointF *>(firstPointId)->name(); const QString secondPointIdName = data->GeometricObject<const VPointF *>(secondPointId)->name(); return QString(tr("%1_%2 - Line from point %1 to point %2")).arg(firstPointIdName, secondPointIdName); } case Tool::AlongLineTool: { const quint32 basePointId = doc->GetParametrUInt(domElement, VAbstractTool::AttrFirstPoint, "0"); const quint32 secondPointId = doc->GetParametrUInt(domElement, VAbstractTool::AttrSecondPoint, "0"); const QString basePointIdName = data->GeometricObject<const VPointF *>(basePointId)->name(); const QString secondPointIdName = data->GeometricObject<const VPointF *>(secondPointId)->name(); const QString toolIdName = data->GeometricObject<const VPointF *>(tool.getId())->name(); return QString(tr("%3 - Point along line %1_%2")).arg(basePointIdName, secondPointIdName, toolIdName); } case Tool::ShoulderPointTool: { const QString name = data->GeometricObject<const VPointF *>(tool.getId())->name(); return QString(tr("%1 - Point of shoulder")).arg(name); } case Tool::NormalTool: { const quint32 basePointId = doc->GetParametrUInt(domElement, VAbstractTool::AttrFirstPoint, "0"); const quint32 secondPointId = doc->GetParametrUInt(domElement, VAbstractTool::AttrSecondPoint, "0"); const QString basePointIdName = data->GeometricObject<const VPointF *>(basePointId)->name(); const QString secondPointIdName = data->GeometricObject<const VPointF *>(secondPointId)->name(); const QString toolIdName = data->GeometricObject<const VPointF *>(tool.getId())->name(); return QString(tr("%3 - normal to line %1_%2")).arg(basePointIdName, secondPointIdName, toolIdName); } case Tool::BisectorTool: { const quint32 firstPointId = doc->GetParametrUInt(domElement, VAbstractTool::AttrFirstPoint, "0"); const quint32 secondPointId = doc->GetParametrUInt(domElement, VAbstractTool::AttrSecondPoint, "0"); const quint32 thirdPointId = doc->GetParametrUInt(domElement, VAbstractTool::AttrThirdPoint, "0"); const QString firstPointIdName = data->GeometricObject<const VPointF *>(firstPointId)->name(); const QString secondPointIdName = data->GeometricObject<const VPointF *>(secondPointId)->name(); const QString thirdPointIdName = data->GeometricObject<const VPointF *>(thirdPointId)->name(); const QString toolIdName = data->GeometricObject<const VPointF *>(tool.getId())->name(); return QString(tr("%4 - bisector of angle %1_%2_%3")).arg(firstPointIdName, secondPointIdName, thirdPointIdName, toolIdName); } case Tool::LineIntersectTool: { const quint32 p1Line1 = doc->GetParametrUInt(domElement, VAbstractTool::AttrP1Line1, "0"); const quint32 p2Line1 = doc->GetParametrUInt(domElement, VAbstractTool::AttrP2Line1, "0"); const quint32 p1Line2 = doc->GetParametrUInt(domElement, VAbstractTool::AttrP1Line2, "0"); const quint32 p2Line2 = doc->GetParametrUInt(domElement, VAbstractTool::AttrP2Line2, "0"); const QString p1Line1Name = data->GeometricObject<const VPointF *>(p1Line1)->name(); const QString p2Line1Name = data->GeometricObject<const VPointF *>(p2Line1)->name(); const QString p1Line2Name = data->GeometricObject<const VPointF *>(p1Line2)->name(); const QString p2Line2Name = data->GeometricObject<const VPointF *>(p2Line2)->name(); const QString toolIdName = data->GeometricObject<const VPointF *>(tool.getId())->name(); return QString(tr("%5 - intersection of lines %1_%2 and %3_%4")).arg(p1Line1Name, p2Line1Name, p1Line2Name, p2Line2Name, toolIdName); } case Tool::SplineTool: { const VSpline *spl = data->GeometricObject<const VSpline *>(tool.getId()); SCASSERT(spl != nullptr); const QString splP1Name = data->GeometricObject<const VPointF *>(spl->GetP1().id())->name(); const QString splP4Name = data->GeometricObject<const VPointF *>(spl->GetP4().id())->name(); return QString(tr("Curve %1_%2")).arg(splP1Name, splP4Name); } case Tool::ArcTool: { const VArc *arc = data->GeometricObject<const VArc *>(tool.getId()); SCASSERT(arc != nullptr); const QString arcCenterName = data->GeometricObject<const VArc *>(arc->GetCenter().id())->name(); return QString(tr("Arc with center in point %1")).arg(arcCenterName); } case Tool::SplinePathTool: { const VSplinePath *splPath = data->GeometricObject<const VSplinePath *>(tool.getId()); SCASSERT(splPath != nullptr); const QVector<VSplinePoint> points = splPath->GetSplinePath(); QString record; if (points.size() != 0 ) { const QString pName = data->GeometricObject<const VPointF *>(points.at(0).P().id())->name(); record = QString(tr("Curve point %1")).arg(pName); if (points.size() > 1) { const QString pName = data->GeometricObject<const VPointF *>(points.last().P().id())->name(); record.append(QString("_%1").arg(pName)); } } else { qDebug()<<"Not enough points in splinepath"<<Q_FUNC_INFO; return QString(tr("Can't create record.")); } return record; } case Tool::PointOfContact: { const quint32 center = doc->GetParametrUInt(domElement, VAbstractTool::AttrCenter, "0"); const quint32 firstPointId = doc->GetParametrUInt(domElement, VAbstractTool::AttrFirstPoint, "0"); const quint32 secondPointId = doc->GetParametrUInt(domElement, VAbstractTool::AttrSecondPoint, "0"); const QString firstPointIdName = data->GeometricObject<const VPointF *>(firstPointId)->name(); const QString centerName = data->GeometricObject<const VPointF *>(center)->name(); const QString secondPointIdName = data->GeometricObject<const VPointF *>(secondPointId)->name(); const QString toolIdName = data->GeometricObject<const VPointF *>(tool.getId())->name(); return QString(tr("%4 - point of contact of arc with the center in point %1 and line %2_%3")).arg( centerName, firstPointIdName, secondPointIdName, toolIdName); } case Tool::Height: { const quint32 basePointId = doc->GetParametrUInt(domElement, VAbstractTool::AttrBasePoint, "0"); const quint32 p1LineId = doc->GetParametrUInt(domElement, VAbstractTool::AttrP1Line, "0"); const quint32 p2LineId = doc->GetParametrUInt(domElement, VAbstractTool::AttrP2Line, "0"); const QString basePointIdName = data->GeometricObject<const VPointF *>(basePointId)->name(); const QString p1LineIdName = data->GeometricObject<const VPointF *>(p1LineId)->name(); const QString p2LineIdName = data->GeometricObject<const VPointF *>(p2LineId)->name(); return QString(tr("Point of perpendicular from point %1 to line %2_%3")).arg(basePointIdName, p1LineIdName, p2LineIdName); } case Tool::Triangle: { const quint32 axisP1Id = doc->GetParametrUInt(domElement, VAbstractTool::AttrAxisP1, "0"); const quint32 axisP2Id = doc->GetParametrUInt(domElement, VAbstractTool::AttrAxisP2, "0"); const quint32 firstPointId = doc->GetParametrUInt(domElement, VAbstractTool::AttrFirstPoint, "0"); const quint32 secondPointId = doc->GetParametrUInt(domElement, VAbstractTool::AttrSecondPoint, "0"); const QString axisP1IdName = data->GeometricObject<const VPointF *>(axisP1Id)->name(); const QString axisP2IdName = data->GeometricObject<const VPointF *>(axisP2Id)->name(); const QString firstPointIdName = data->GeometricObject<const VPointF *>(firstPointId)->name(); const QString secondPointIdName = data->GeometricObject<const VPointF *>(secondPointId)->name(); return QString(tr("Triangle: axis %1_%2, points %3 and %4")).arg(axisP1IdName, axisP2IdName, firstPointIdName, secondPointIdName); } case Tool::PointOfIntersection: { const quint32 firstPointId = doc->GetParametrUInt(domElement, VAbstractTool::AttrFirstPoint, "0"); const quint32 secondPointId = doc->GetParametrUInt(domElement, VAbstractTool::AttrSecondPoint, "0"); const QString firstPointIdName = data->GeometricObject<const VPointF *>(firstPointId)->name(); const QString secondPointIdName = data->GeometricObject<const VPointF *>(secondPointId)->name(); const QString toolIdName = data->GeometricObject<const VPointF *>(tool.getId())->name(); return QString(tr("%1 - point of intersection %2 and %3")).arg(toolIdName, firstPointIdName, secondPointIdName); } case Tool::CutArcTool: { const quint32 arcId = doc->GetParametrUInt(domElement, VToolCutArc::AttrArc, "0"); const VArc *arc = data->GeometricObject<const VArc *>(arcId); SCASSERT(arc != nullptr); const QString arcCenterName = data->GeometricObject<const VArc *>(arc->GetCenter().id())->name(); const QString toolIdName = data->GeometricObject<const VPointF *>(tool.getId())->name(); return QString(tr("%1 - cut arc with center %2")).arg(toolIdName, arcCenterName); } case Tool::CutSplineTool: { const quint32 splineId = doc->GetParametrUInt(domElement, VToolCutSpline::AttrSpline, "0"); const VSpline *spl = data->GeometricObject<const VSpline *>(splineId); SCASSERT(spl != nullptr); const QString toolIdName = data->GeometricObject<const VPointF *>(tool.getId())->name(); const QString splP1Name = data->GeometricObject<const VPointF *>(spl->GetP1().id())->name(); const QString splP4Name = data->GeometricObject<const VPointF *>(spl->GetP4().id())->name(); return QString(tr("%1 - cut curve %2_%3")).arg(toolIdName, splP1Name, splP4Name); } case Tool::CutSplinePathTool: { const quint32 splinePathId = doc->GetParametrUInt(domElement, VToolCutSplinePath::AttrSplinePath, "0"); const VSplinePath *splPath = data->GeometricObject<const VSplinePath *>(splinePathId); SCASSERT(splPath != nullptr); const QVector<VSplinePoint> points = splPath->GetSplinePath(); QString record; if (points.size() != 0 ) { const QString toolIdName = data->GeometricObject<const VPointF *>(tool.getId())->name(); const QString pName = data->GeometricObject<const VPointF *>(points.at(0).P().id())->name(); record = QString(tr("%1 - cut curve path %2")).arg(toolIdName, pName); if (points.size() > 1) { const QString pName = data->GeometricObject<const VPointF *>(points.last().P().id())->name(); const QString name = QString("_%1").arg(pName); record.append(name); } } else { qDebug()<<"Not enough points in splinepath"<<Q_FUNC_INFO; return QString(tr("Can't create record.")); } return record; } //Because "history" not only show history of pattern, but help restore current data for each pattern's //piece, we need add record about details and nodes, but don't show them. case Tool::DetailTool: break; case Tool::UnionDetails: break; case Tool::NodeArc: break; case Tool::NodePoint: break; case Tool::NodeSpline: break; case Tool::NodeSplinePath: break; default: qDebug()<<"Got wrong tool type. Ignore."; break; } } catch (const VExceptionBadId &e) { qDebug()<<e.ErrorMessage()<<Q_FUNC_INFO; return QString(tr("Can't create record.")); } return QString(); }
/** * @brief Record return description for record * @param tool record data * @return description */ QString DialogHistory::Record(const VToolRecord &tool) { const QDomElement domElem = doc->elementById(QString().setNum(tool.getId())); if (domElem.isElement() == false) { qDebug()<<"Can't find element by id"<<Q_FUNC_INFO; return QString(tr("Can't create record.")); } try { switch ( tool.getTypeTool() ) { case Tool::Arrow: Q_UNREACHABLE(); break; case Tool::SinglePoint: { return QString(tr("%1 - Base point")).arg(PointName(tool.getId())); } case Tool::EndLine: { return QString(tr("%1_%2 - Line from point %1 to point %2")) .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrBasePoint))) .arg(PointName(tool.getId())); } case Tool::Line: { return QString(tr("%1_%2 - Line from point %1 to point %2")) .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrFirstPoint))) .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrSecondPoint))); } case Tool::AlongLine: { return QString(tr("%3 - Point along line %1_%2")) .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrFirstPoint))) .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrSecondPoint))) .arg(PointName(tool.getId())); } case Tool::ShoulderPoint: { return QString(tr("%1 - Point of shoulder")).arg(PointName(tool.getId())); } case Tool::Normal: { return QString(tr("%3 - normal to line %1_%2")) .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrFirstPoint))) .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrSecondPoint))) .arg(PointName(tool.getId())); } case Tool::Bisector: { return QString(tr("%4 - bisector of angle %1_%2_%3")) .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrFirstPoint))) .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrSecondPoint))) .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrThirdPoint))) .arg(PointName(tool.getId())); } case Tool::LineIntersect: { return QString(tr("%5 - intersection of lines %1_%2 and %3_%4")) .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrP1Line1))) .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrP2Line1))) .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrP1Line2))) .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrP2Line2))) .arg(PointName(tool.getId())); } case Tool::Spline: { const QSharedPointer<VSpline> spl = data->GeometricObject<VSpline>(tool.getId()); SCASSERT(spl != nullptr); return QString(tr("Curve %1_%2")).arg(PointName(spl->GetP1().id())).arg(PointName(spl->GetP4().id())); } case Tool::Arc: { const QSharedPointer<VArc> arc = data->GeometricObject<VArc>(tool.getId()); SCASSERT(arc != nullptr); return QString(tr("Arc with center in point %1")).arg(PointName(arc->GetCenter().id())); } case Tool::SplinePath: { const QSharedPointer<VSplinePath> splPath = data->GeometricObject<VSplinePath>(tool.getId()); SCASSERT(splPath != nullptr); const QVector<VSplinePoint> points = splPath->GetSplinePath(); QString record; if (points.size() != 0 ) { // We use only first and last point name in curve record = QString(tr("Curve point %1")).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::PointOfContact: { return QString(tr("%4 - point of contact of arc with the center in point %1 and line %2_%3")) .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrCenter))) .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrFirstPoint))) .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrSecondPoint))) .arg(PointName(tool.getId())); } case Tool::Height: { return QString(tr("Point of perpendicular from point %1 to line %2_%3")) .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrBasePoint))) .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrP1Line))) .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrP2Line))); } case Tool::Triangle: { return QString(tr("Triangle: axis %1_%2, points %3 and %4")) .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrAxisP1))) .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrAxisP2))) .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrFirstPoint))) .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrSecondPoint))); } case Tool::PointOfIntersection: { return QString(tr("%1 - point of intersection %2 and %3")) .arg(PointName(tool.getId())) .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrFirstPoint))) .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrSecondPoint))); } case Tool::CutArc: { const QSharedPointer<VArc> arc = data->GeometricObject<VArc>(AttrUInt(domElem, VToolCutArc::AttrArc)); SCASSERT(arc != nullptr); return QString(tr("%1 - cut arc with center %2")) .arg(PointName(tool.getId())) .arg(PointName(arc->GetCenter().id())); } case Tool::CutSpline: { const quint32 splineId = AttrUInt(domElem, VToolCutSpline::AttrSpline); const QSharedPointer<VSpline> spl = data->GeometricObject<VSpline>(splineId); SCASSERT(spl != nullptr); return QString(tr("%1 - cut curve %2_%3")) .arg(PointName(tool.getId())) .arg(PointName(spl->GetP1().id())) .arg(PointName(spl->GetP4().id())); } case Tool::CutSplinePath: { const quint32 splinePathId = AttrUInt(domElem, VToolCutSplinePath::AttrSplinePath); const QSharedPointer<VSplinePath> splPath = data->GeometricObject<VSplinePath>(splinePathId); SCASSERT(splPath != nullptr); const QVector<VSplinePoint> points = splPath->GetSplinePath(); QString record; if (points.size() != 0 ) { 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: { return QString(tr("%1 - point of intersection line %2_%3 and axis through point %4")) .arg(PointName(tool.getId())) .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrP1Line))) .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrP2Line))) .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrBasePoint))); } case Tool::CurveIntersectAxis: { return QString(tr("%1 - point of intersection curve and axis through point %2")) .arg(PointName(tool.getId())) .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrBasePoint))); } //Because "history" not only show history of pattern, but help restore current data for each pattern's //piece, we need add record about details and nodes, but don't show them. case Tool::Detail: break; case Tool::UnionDetails: break; case Tool::NodeArc: break; case Tool::NodePoint: break; case Tool::NodeSpline: break; case Tool::NodeSplinePath: break; default: qDebug()<<"Got wrong tool type. Ignore."; return QString(tr("Can't create record.")); break; } } catch (const VExceptionBadId &e) { qDebug()<<e.ErrorMessage()<<Q_FUNC_INFO; return QString(tr("Can't create record.")); } return QString(); }