diff --git a/src/container/vcontainer.cpp b/src/container/vcontainer.cpp index 8a34a120b..c83d2f3fe 100644 --- a/src/container/vcontainer.cpp +++ b/src/container/vcontainer.cpp @@ -609,8 +609,7 @@ void VContainer::AddLengthSpline(const QString &name, const qreal &value) void VContainer::AddLengthArc(const qint64 &id) { const VArc * arc = GeometricObject(id); - QString name = QString("%1_%2").arg(arc->name()).arg(id); - lengthArcs[name] = toMM(arc->GetLength()); + lengthArcs[arc->name()] = toMM(arc->GetLength()); } void VContainer::AddLineAngle(const QString &name, const qreal &value) diff --git a/src/geometry/varc.cpp b/src/geometry/varc.cpp index d4264272f..8276bc95e 100644 --- a/src/geometry/varc.cpp +++ b/src/geometry/varc.cpp @@ -66,6 +66,11 @@ VArc &VArc::operator =(const VArc &arc) return *this; } +qreal VArc::GetLength() const +{ + return (M_PI * radius)/180 * AngleArc(); +} + QPointF VArc::GetP1() const { QPointF p1 ( GetCenter().x () + radius, GetCenter().y () ); @@ -84,13 +89,22 @@ QPointF VArc::GetP2 () const QPainterPath VArc::GetPath() const { - QPainterPath Path; - QPointF center = GetCenter().toQPointF(); - QRectF rect(center.x()-radius, center.y()-radius, radius*2, radius*2); - Path.moveTo(GetP1()); - qreal angle = QLineF(center, GetP1()).angleTo(QLineF(center, GetP2())); - Path.arcTo(rect, GetF1(), angle); - return Path; + QPainterPath path; + + QVector points = GetPoints(); + if (points.count() >= 2) + { + for (qint32 i = 0; i < points.count()-1; ++i) + { + path.moveTo(points[i]); + path.lineTo(points[i+1]); + } + } + else + { + qWarning()<<"points.count() < 2"< (AngleArc ()); - switch ( angArc ) - { - case 0: - { - QString error = QString(tr("Angle of arc can't be 0 degree.")); - throw VException(error); - } - case 90: - return 1; - case 180: - return 2; - case 270: - return 3; - case 360: - return 4; - default: - return static_cast (AngleArc ( ) / 90 + 1); - } -} - QVector VArc::GetPoints() const { QVector points; - qint32 numberSpl = NumberSplOfArc(); - for (qint32 i = 1; i <= numberSpl; ++i) + qreal i = 0; + qreal angle = qRound(AngleArc()); + do { - points< VArc::SplOfArc(qint32 number) const +QString VArc::name() const { - qint32 n = NumberSplOfArc (); - if ( number > n ) - { - QString error = QString(tr("Arc has not this number of parts.")); - throw VException(error); - } - qreal f1 = GetF1 (); - qreal f2 = GetF2 (); - qint32 i; - for ( i = 0; i < n; ++i ) - { - if ( i == n - 1 ) - { - f2 = GetF2 (); - } - else - { - if ( f1 + 90 > 360 ) - { - f2 = f1 + 90 - 360; - } - else - { - f2 = f1 + 90; - } - } - qreal anglF1, anglF2; - if ( f1 + 90 > 360 ) - { - anglF1 = f1 + 90 - 360; - } - else - { - anglF1 = f1 + 90; - } - if ( f2 - 90 < 0 ) - { - anglF2 = 360 + f2 - 90; - } - else - { - anglF2 = f2 - 90; - } - if ( i + 1 == number ) - { - f1 = f2; - return VSpline::SplinePoints(GetP1 (), GetP2 (), anglF1, anglF2, 1., 1., 1.); - } - } - return QVector(); + return _name; } QPointF VArc::CutArc(const qreal &length, VArc &arc1, VArc &arc2) const @@ -205,19 +152,22 @@ QPointF VArc::CutArc(const qreal &length, VArc &arc1, VArc &arc2) const else { len = length; - qDebug()< GetPoints () const; - /** - * @brief SplOfArc - * @param number - * @return - */ - QVector SplOfArc( qint32 number ) const; - virtual QString name() const{return _name;} + virtual QString name() const; QPointF CutArc (const qreal &length, VArc &arc1, VArc &arc2) const; + virtual void setId(const qint64 &id); private: /** * @brief f1 початковий кут в градусах diff --git a/src/geometry/vgobject.h b/src/geometry/vgobject.h index eb904c072..dab8c3fc0 100644 --- a/src/geometry/vgobject.h +++ b/src/geometry/vgobject.h @@ -61,7 +61,7 @@ public: void setMode(const Draw::Draws &value); GObject::Type getType() const; qint64 id() const; - void setId(const qint64 &id); + virtual void setId(const qint64 &id); protected: /** * @brief _id id in container. Ned for arcs, spline and spline paths. diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 4a6a513d1..86215350f 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -706,8 +706,11 @@ void MainWindow::currentDrawChanged( int index ) doc->setCurrentData(); doc->ChangeActivDraw(comboBoxDraws->itemText(index)); qint64 id = doc->SPointActiveDraw(); - const VPointF *p = pattern->GeometricObject(id); - view->centerOn(p->toQPointF()); + if (id != 0) + { + const VPointF *p = pattern->GeometricObject(id); + view->centerOn(p->toQPointF()); + } } } diff --git a/src/tools/drawTools/vtoolcutarc.cpp b/src/tools/drawTools/vtoolcutarc.cpp index 7b3afb47a..ef24503c6 100644 --- a/src/tools/drawTools/vtoolcutarc.cpp +++ b/src/tools/drawTools/vtoolcutarc.cpp @@ -208,6 +208,11 @@ void VToolCutArc::ChangedActivDraw(const QString &newName) VToolPoint::ChangedActivDraw(newName); } +void VToolCutArc::ShowContextMenu(QGraphicsSceneContextMenuEvent *event) +{ + ContextMenu(dialogCutArc, this, event); +} + void VToolCutArc::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { ContextMenu(dialogCutArc, this, event); diff --git a/src/tools/drawTools/vtoolcutarc.h b/src/tools/drawTools/vtoolcutarc.h index 06c98660e..d4b90cc16 100644 --- a/src/tools/drawTools/vtoolcutarc.h +++ b/src/tools/drawTools/vtoolcutarc.h @@ -74,6 +74,7 @@ public slots: * @param newName */ virtual void ChangedActivDraw(const QString &newName); + virtual void ShowContextMenu(QGraphicsSceneContextMenuEvent *event); protected: /** * @brief contextMenuEvent diff --git a/src/tools/drawTools/vtoolcutspline.cpp b/src/tools/drawTools/vtoolcutspline.cpp index 8a5e243aa..86cbe343d 100644 --- a/src/tools/drawTools/vtoolcutspline.cpp +++ b/src/tools/drawTools/vtoolcutspline.cpp @@ -209,6 +209,11 @@ void VToolCutSpline::ChangedActivDraw(const QString &newName) VToolPoint::ChangedActivDraw(newName); } +void VToolCutSpline::ShowContextMenu(QGraphicsSceneContextMenuEvent *event) +{ + ContextMenu(dialogCutSpline, this, event); +} + void VToolCutSpline::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { ContextMenu(dialogCutSpline, this, event); diff --git a/src/tools/drawTools/vtoolcutspline.h b/src/tools/drawTools/vtoolcutspline.h index 317d00ad1..428d91461 100644 --- a/src/tools/drawTools/vtoolcutspline.h +++ b/src/tools/drawTools/vtoolcutspline.h @@ -109,6 +109,7 @@ public slots: * @param newName */ virtual void ChangedActivDraw(const QString &newName); + virtual void ShowContextMenu(QGraphicsSceneContextMenuEvent *event); protected: /** * @brief contextMenuEvent diff --git a/src/tools/drawTools/vtoolcutsplinepath.cpp b/src/tools/drawTools/vtoolcutsplinepath.cpp index 1ad5f457d..d6698e907 100644 --- a/src/tools/drawTools/vtoolcutsplinepath.cpp +++ b/src/tools/drawTools/vtoolcutsplinepath.cpp @@ -286,6 +286,11 @@ void VToolCutSplinePath::ChangedActivDraw(const QString &newName) VToolPoint::ChangedActivDraw(newName); } +void VToolCutSplinePath::ShowContextMenu(QGraphicsSceneContextMenuEvent *event) +{ + ContextMenu(dialogCutSplinePath, this, event); +} + void VToolCutSplinePath::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { ContextMenu(dialogCutSplinePath, this, event); diff --git a/src/tools/drawTools/vtoolcutsplinepath.h b/src/tools/drawTools/vtoolcutsplinepath.h index 8ffce813b..afb32a115 100644 --- a/src/tools/drawTools/vtoolcutsplinepath.h +++ b/src/tools/drawTools/vtoolcutsplinepath.h @@ -99,6 +99,7 @@ public slots: * @param newName */ virtual void ChangedActivDraw(const QString &newName); + virtual void ShowContextMenu(QGraphicsSceneContextMenuEvent *event); protected: /** * @brief contextMenuEvent