diff --git a/Valentina.pro b/Valentina.pro index ee7b1ec2b..c05bf37e1 100644 --- a/Valentina.pro +++ b/Valentina.pro @@ -97,7 +97,10 @@ SOURCES += main.cpp\ exception/vexceptionemptyparameter.cpp \ exception/vexceptionobjecterror.cpp \ widgets/vapplication.cpp \ - exception/vexceptionuniqueid.cpp + exception/vexceptionuniqueid.cpp \ + tools/drawTools/vtoolheight.cpp \ + tools/modelingTools/vmodelingheight.cpp \ + dialogs/dialogheight.cpp HEADERS += mainwindow.h \ widgets/vmaingraphicsscene.h \ @@ -188,7 +191,10 @@ HEADERS += mainwindow.h \ exception/vexceptionemptyparameter.h \ exception/vexceptionobjecterror.h \ widgets/vapplication.h \ - exception/vexceptionuniqueid.h + exception/vexceptionuniqueid.h \ + tools/drawTools/vtoolheight.h \ + tools/modelingTools/vmodelingheight.h \ + dialogs/dialogheight.h FORMS += mainwindow.ui \ dialogs/dialogsinglepoint.ui \ @@ -206,7 +212,8 @@ FORMS += mainwindow.ui \ dialogs/dialoghistory.ui \ dialogs/dialogpointofcontact.ui \ dialogs/dialogdetail.ui \ - tablewindow.ui + tablewindow.ui \ + dialogs/dialogheight.ui RESOURCES += \ icon.qrc \ diff --git a/cursor.qrc b/cursor.qrc index ece04dd88..b38ff9e43 100644 --- a/cursor.qrc +++ b/cursor.qrc @@ -12,5 +12,6 @@ cursor/splinepath_cursor.png cursor/pointcontact_cursor.png cursor/new_detail_cursor.png + cursor/height_cursor.png diff --git a/cursor/height_cursor.png b/cursor/height_cursor.png new file mode 100644 index 000000000..05da2a5ae Binary files /dev/null and b/cursor/height_cursor.png differ diff --git a/dialogs/dialogendline.h b/dialogs/dialogendline.h index 5053e6462..b07701169 100644 --- a/dialogs/dialogendline.h +++ b/dialogs/dialogendline.h @@ -30,8 +30,7 @@ namespace Ui { class DialogEndLine; } -class DialogEndLine : public DialogTool -{ +class DialogEndLine : public DialogTool{ Q_OBJECT public: explicit DialogEndLine(const VContainer *data, Draw::Draws mode = Draw::Calculation, diff --git a/dialogs/dialogheight.cpp b/dialogs/dialogheight.cpp new file mode 100644 index 000000000..dc1002147 --- /dev/null +++ b/dialogs/dialogheight.cpp @@ -0,0 +1,122 @@ +#include "dialogheight.h" +#include "ui_dialogheight.h" + +DialogHeight::DialogHeight(const VContainer *data, Draw::Draws mode, QWidget *parent) : + DialogTool(data, mode, parent), ui(new Ui::DialogHeight), number(0), pointName(QString()), + typeLine(QString()), basePointId(0), p1LineId(0), p2LineId(0){ + ui->setupUi(this); + labelEditNamePoint = ui->labelEditNamePoint; + flagFormula = true; + bOk = ui->buttonBox->button(QDialogButtonBox::Ok); + connect(bOk, &QPushButton::clicked, this, &DialogHeight::DialogAccepted); + flagName = false; + CheckState(); + QPushButton *bCansel = ui->buttonBox->button(QDialogButtonBox::Cancel); + connect(bCansel, &QPushButton::clicked, this, &DialogHeight::DialogRejected); + FillComboBoxPoints(ui->comboBoxBasePoint); + FillComboBoxPoints(ui->comboBoxP1Line); + FillComboBoxPoints(ui->comboBoxP2Line); + FillComboBoxTypeLine(ui->comboBoxLineType); + connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogHeight::NamePointChanged); +} + +DialogHeight::~DialogHeight(){ + delete ui; +} + +QString DialogHeight::getPointName() const{ + return pointName; +} + +void DialogHeight::setPointName(const QString &value){ + pointName = value; + ui->lineEditNamePoint->setText(pointName); +} + +QString DialogHeight::getTypeLine() const{ + return typeLine; +} + +void DialogHeight::setTypeLine(const QString &value){ + typeLine = value; + SetupTypeLine(ui->comboBoxLineType, value); +} + +qint64 DialogHeight::getBasePointId() const{ + return basePointId; +} + +void DialogHeight::setBasePointId(const qint64 &value, const qint64 &id){ + basePointId = value; + setCurrentPointId(ui->comboBoxBasePoint, basePointId, value, id); +} + +qint64 DialogHeight::getP1LineId() const{ + return p1LineId; +} + +void DialogHeight::setP1LineId(const qint64 &value, const qint64 &id){ + p1LineId = value; + setCurrentPointId(ui->comboBoxP1Line, p1LineId, value, id); +} + +qint64 DialogHeight::getP2LineId() const{ + return p2LineId; +} + +void DialogHeight::setP2LineId(const qint64 &value, const qint64 &id){ + p2LineId = value; + setCurrentPointId(ui->comboBoxP2Line, p2LineId, value, id); +} + +void DialogHeight::ChoosedObject(qint64 id, Scene::Scenes type){ + if(idDetail == 0 && mode == Draw::Modeling){ + if(type == Scene::Detail){ + idDetail = id; + return; + } + } + if(mode == Draw::Modeling){ + if(!CheckObject(id)){ + return; + } + } + if(type == Scene::Point){ + VPointF point; + if(mode == Draw::Calculation){ + point = data->GetPoint(id); + } else { + point = data->GetModelingPoint(id); + } + switch(number){ + case(0): + ChangeCurrentText(ui->comboBoxBasePoint, point.name()); + number++; + emit ToolTip(tr("Select first point of line")); + break; + case(1): + ChangeCurrentText(ui->comboBoxP1Line, point.name()); + number++; + emit ToolTip(tr("Select second point of line")); + break; + case(2): + ChangeCurrentText(ui->comboBoxP2Line, point.name()); + number = 0; + emit ToolTip(tr("")); + if(!isInitialized){ + this->show(); + } + break; + } + } +} + +void DialogHeight::DialogAccepted(){ + pointName = ui->lineEditNamePoint->text(); + typeLine = GetTypeLine(ui->comboBoxLineType); + basePointId = getCurrentPointId(ui->comboBoxBasePoint); + p1LineId = getCurrentPointId(ui->comboBoxP1Line); + p2LineId = getCurrentPointId(ui->comboBoxP2Line); + emit DialogClosed(QDialog::Accepted); +} + diff --git a/dialogs/dialogheight.h b/dialogs/dialogheight.h new file mode 100644 index 000000000..b4e4c05b6 --- /dev/null +++ b/dialogs/dialogheight.h @@ -0,0 +1,40 @@ +#ifndef DIALOGHEIGHT_H +#define DIALOGHEIGHT_H + +#include "dialogtool.h" + +namespace Ui { +class DialogHeight; +} + +class DialogHeight : public DialogTool{ + Q_OBJECT +public: + explicit DialogHeight(const VContainer *data, Draw::Draws mode = Draw::Calculation, + QWidget *parent = 0); + ~DialogHeight(); + QString getPointName() const; + void setPointName(const QString &value); + QString getTypeLine() const; + void setTypeLine(const QString &value); + qint64 getBasePointId() const; + void setBasePointId(const qint64 &value, const qint64 &id); + qint64 getP1LineId() const; + void setP1LineId(const qint64 &value, const qint64 &id); + qint64 getP2LineId() const; + void setP2LineId(const qint64 &value, const qint64 &id); +public slots: + virtual void ChoosedObject(qint64 id, Scene::Scenes type); + virtual void DialogAccepted(); +private: + Q_DISABLE_COPY(DialogHeight) + Ui::DialogHeight *ui; + qint32 number; + QString pointName; + QString typeLine; + qint64 basePointId; + qint64 p1LineId; + qint64 p2LineId; +}; + +#endif // DIALOGHEIGHT_H diff --git a/dialogs/dialogheight.ui b/dialogs/dialogheight.ui new file mode 100644 index 000000000..bfb3dab67 --- /dev/null +++ b/dialogs/dialogheight.ui @@ -0,0 +1,211 @@ + + + DialogHeight + + + + 0 + 0 + 247 + 220 + + + + Dialog + + + + + + + + + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 159 + 158 + 158 + + + + + + + + Name new point + + + + + + + + + + + + + + + 0 + 0 + + + + Base point + + + + + + + First point of line + + + + + + + + + + + + 0 + 0 + + + + First point of line + + + + + + + First point of line + + + + + + + + + + + + 0 + 0 + + + + Second point of line + + + + + + + First point of line + + + + + + + + + + + Type line + + + + + + + Show line from first point to our point + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + DialogHeight + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + DialogHeight + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/dialogs/dialoghistory.cpp b/dialogs/dialoghistory.cpp index 8e59671a3..d1b19544a 100644 --- a/dialogs/dialoghistory.cpp +++ b/dialogs/dialoghistory.cpp @@ -250,6 +250,20 @@ QString DialogHistory::Record(const VToolRecord &tool){ data->GetPoint(secondPointId).name(), data->GetPoint(tool.getId()).name()); break; + case Tool::Height:{ + qint64 p1LineId = 0; + qint64 p2LineId = 0; + domElement = doc->elementById(QString().setNum(tool.getId())); + if(domElement.isElement()){ + basePointId = domElement.attribute("basePoint", "").toLongLong(); + p1LineId = domElement.attribute("p1Line", "").toLongLong(); + p2LineId = domElement.attribute("p2Line", "").toLongLong(); + } + record = QString(tr("Point of perpendical from point %1 to line %2_%3")).arg(data->GetPoint(basePointId).name(), + data->GetPoint(p1LineId).name(), + data->GetPoint(p2LineId).name()); + break; + } default: qWarning()<findText(value); if(index != -1){ box->setCurrentIndex(index); + } else { + qWarning()<icon/32x32/new_detail.png icon/32x32/layout.png icon/16x16/mirror.png + icon/32x32/height.png diff --git a/icon/32x32/height.png b/icon/32x32/height.png new file mode 100644 index 000000000..c44de68bc Binary files /dev/null and b/icon/32x32/height.png differ diff --git a/mainwindow.cpp b/mainwindow.cpp index 19ae78c59..7befade91 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -44,10 +44,10 @@ MainWindow::MainWindow(QWidget *parent) : dialogAlongLine(QSharedPointer()), dialogShoulderPoint(QSharedPointer()), dialogNormal(QSharedPointer()), dialogBisector(QSharedPointer()), - dialogLineIntersect(QSharedPointer()), - dialogSpline(QSharedPointer()), + dialogLineIntersect(QSharedPointer()), dialogSpline(QSharedPointer()), dialogArc(QSharedPointer()), dialogSplinePath(QSharedPointer()), - dialogPointOfContact(QSharedPointer()), dialogDetail(QSharedPointer()), + dialogPointOfContact(QSharedPointer()), + dialogDetail(QSharedPointer()), dialogHeight(QSharedPointer()), dialogHistory(0), doc(0), data(0), comboBoxDraws(0), fileName(QString()), changeInFile(false), mode(Draw::Calculation){ ui->setupUi(this); @@ -91,6 +91,7 @@ MainWindow::MainWindow(QWidget *parent) : connect(ui->toolButtonSplinePath, &QToolButton::clicked, this, &MainWindow::ToolSplinePath); connect(ui->toolButtonPointOfContact, &QToolButton::clicked, this, &MainWindow::ToolPointOfContact); connect(ui->toolButtonNewDetail, &QToolButton::clicked, this, &MainWindow::ToolDetail); + connect(ui->toolButtonHeight, &QToolButton::clicked, this, &MainWindow::ToolHeight); data = new VContainer; @@ -463,6 +464,23 @@ void MainWindow::ClosedDialogDetail(int result){ ArrowTool(); } +void MainWindow::ToolHeight(bool checked){ + SetToolButton(checked, Tool::Height, ":/cursor/height_cursor.png", tr("Select base point"), + dialogHeight, &MainWindow::ClosedDialogHeight); +} + +void MainWindow::ClosedDialogHeight(int result){ + if(result == QDialog::Accepted){ + if(mode == Draw::Calculation){ + VToolHeight::Create(dialogHeight, currentScene, doc, data); + } else { + VModelingHeight *point = VModelingHeight::Create(dialogHeight, doc, data); + AddToolToDetail(point, point->getId(), Tool::Height, dialogHeight->getIdDetail()); + } + } + ArrowTool(); +} + void MainWindow::About(){ QMessageBox::about(this, tr("About Valentina"), tr("Valentina v.0.1.0")); } @@ -616,88 +634,91 @@ void MainWindow::mouseMove(QPointF scenePos){ } void MainWindow::CanselTool(){ - switch( tool ) - { - case Tool::ArrowTool: - ui->actionArrowTool->setChecked(false); - helpLabel->setText(""); - break; - case Tool::SinglePointTool: - //Nothing to do here because we can't create this tool from main window. - break; - case Tool::EndLineTool: - dialogEndLine.clear(); - ui->toolButtonEndLine->setChecked(false); - currentScene->setFocus(Qt::OtherFocusReason); - currentScene->clearSelection(); - break; - case Tool::LineTool: - dialogLine.clear(); - ui->toolButtonLine->setChecked(false); - currentScene->setFocus(Qt::OtherFocusReason); - currentScene->clearFocus(); - break; - case Tool::AlongLineTool: - dialogAlongLine.clear(); - ui->toolButtonAlongLine->setChecked(false); - currentScene->setFocus(Qt::OtherFocusReason); - currentScene->clearSelection(); - break; - case Tool::ShoulderPointTool: - dialogShoulderPoint.clear(); - ui->toolButtonShoulderPoint->setChecked(false); - currentScene->setFocus(Qt::OtherFocusReason); - currentScene->clearSelection(); - break; - case Tool::NormalTool: - dialogNormal.clear(); - ui->toolButtonNormal->setChecked(false); - currentScene->setFocus(Qt::OtherFocusReason); - currentScene->clearSelection(); - break; - case Tool::BisectorTool: - dialogBisector.clear(); - ui->toolButtonBisector->setChecked(false); - currentScene->setFocus(Qt::OtherFocusReason); - currentScene->clearSelection(); - break; - case Tool::LineIntersectTool: - dialogLineIntersect.clear(); - ui->toolButtonLineIntersect->setChecked(false); - currentScene->setFocus(Qt::OtherFocusReason); - currentScene->clearSelection(); - break; - case Tool::SplineTool: - dialogSpline.clear(); - ui->toolButtonSpline->setChecked(false); - currentScene->setFocus(Qt::OtherFocusReason); - currentScene->clearSelection(); - break; - case Tool::ArcTool: - dialogArc.clear(); - ui->toolButtonArc->setChecked(false); - currentScene->setFocus(Qt::OtherFocusReason); - currentScene->clearSelection(); - break; - case Tool::SplinePathTool: - dialogSplinePath.clear(); - ui->toolButtonSplinePath->setChecked(false); - currentScene->setFocus(Qt::OtherFocusReason); - currentScene->clearSelection(); - break; - case Tool::PointOfContact: - dialogPointOfContact.clear(); - ui->toolButtonPointOfContact->setChecked(false); - currentScene->setFocus(Qt::OtherFocusReason); - currentScene->clearSelection(); - break; - case Tool::Detail: - dialogDetail.clear(); - ui->toolButtonNewDetail->setChecked(false); - break; - default: - qWarning()<<"Get wrong tool type. Ignore."; - break; + switch( tool ){ + case Tool::ArrowTool: + ui->actionArrowTool->setChecked(false); + helpLabel->setText(""); + break; + case Tool::SinglePointTool: + //Nothing to do here because we can't create this tool from main window. + break; + case Tool::EndLineTool: + dialogEndLine.clear(); + ui->toolButtonEndLine->setChecked(false); + currentScene->setFocus(Qt::OtherFocusReason); + currentScene->clearSelection(); + break; + case Tool::LineTool: + dialogLine.clear(); + ui->toolButtonLine->setChecked(false); + currentScene->setFocus(Qt::OtherFocusReason); + currentScene->clearFocus(); + break; + case Tool::AlongLineTool: + dialogAlongLine.clear(); + ui->toolButtonAlongLine->setChecked(false); + currentScene->setFocus(Qt::OtherFocusReason); + currentScene->clearSelection(); + break; + case Tool::ShoulderPointTool: + dialogShoulderPoint.clear(); + ui->toolButtonShoulderPoint->setChecked(false); + currentScene->setFocus(Qt::OtherFocusReason); + currentScene->clearSelection(); + break; + case Tool::NormalTool: + dialogNormal.clear(); + ui->toolButtonNormal->setChecked(false); + currentScene->setFocus(Qt::OtherFocusReason); + currentScene->clearSelection(); + break; + case Tool::BisectorTool: + dialogBisector.clear(); + ui->toolButtonBisector->setChecked(false); + currentScene->setFocus(Qt::OtherFocusReason); + currentScene->clearSelection(); + break; + case Tool::LineIntersectTool: + dialogLineIntersect.clear(); + ui->toolButtonLineIntersect->setChecked(false); + currentScene->setFocus(Qt::OtherFocusReason); + currentScene->clearSelection(); + break; + case Tool::SplineTool: + dialogSpline.clear(); + ui->toolButtonSpline->setChecked(false); + currentScene->setFocus(Qt::OtherFocusReason); + currentScene->clearSelection(); + break; + case Tool::ArcTool: + dialogArc.clear(); + ui->toolButtonArc->setChecked(false); + currentScene->setFocus(Qt::OtherFocusReason); + currentScene->clearSelection(); + break; + case Tool::SplinePathTool: + dialogSplinePath.clear(); + ui->toolButtonSplinePath->setChecked(false); + currentScene->setFocus(Qt::OtherFocusReason); + currentScene->clearSelection(); + break; + case Tool::PointOfContact: + dialogPointOfContact.clear(); + ui->toolButtonPointOfContact->setChecked(false); + currentScene->setFocus(Qt::OtherFocusReason); + currentScene->clearSelection(); + break; + case Tool::Detail: + dialogDetail.clear(); + ui->toolButtonNewDetail->setChecked(false); + break; + case Tool::Height: + dialogHeight.clear(); + ui->toolButtonHeight->setChecked(false); + break; + default: + qWarning()<<"Get wrong tool type. Ignore."; + break; } } @@ -935,6 +956,7 @@ void MainWindow::SetEnableTool(bool enable){ ui->toolButtonSplinePath->setEnabled(enable); ui->toolButtonPointOfContact->setEnabled(enable); ui->toolButtonNewDetail->setEnabled(enable); + ui->toolButtonHeight->setEnabled(enable); } void MainWindow::MinimumScrollBar(){ diff --git a/mainwindow.h b/mainwindow.h index 3d55ab212..844052539 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -80,6 +80,7 @@ public slots: void ToolSplinePath(bool checked); void ToolPointOfContact(bool checked); void ToolDetail(bool checked); + void ToolHeight(bool checked); void ClosedDialogEndLine(int result); void ClosedDialogLine(int result); void ClosedDialogAlongLine(int result); @@ -92,6 +93,7 @@ public slots: void ClosedDialogSplinePath(int result); void ClosedDialogPointOfContact(int result); void ClosedDialogDetail(int result); + void ClosedDialogHeight(int result); void About(); void AboutQt(); void ShowToolTip(const QString &toolTip); @@ -135,6 +137,7 @@ private: QSharedPointer dialogSplinePath; QSharedPointer dialogPointOfContact; QSharedPointer dialogDetail; + QSharedPointer dialogHeight; DialogHistory *dialogHistory; VDomDocument *doc; VContainer *data; diff --git a/mainwindow.ui b/mainwindow.ui index b842a4655..0e9a0df8b 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -48,7 +48,7 @@ 0 0 150 - 104 + 150 @@ -64,20 +64,20 @@ Point - - + + false - Tool point of normal. + Tool point on the end line. ... - :/icon/32x32/normal.png:/icon/32x32/normal.png + :/icon/32x32/segment.png:/icon/32x32/segment.png @@ -116,46 +116,20 @@ - - + + false - Tool point on the end line. + Tool point of contact. ... - :/icon/32x32/segment.png:/icon/32x32/segment.png - - - - 32 - 32 - - - - true - - - - - - - false - - - Tool point along line. - - - ... - - - - :/icon/32x32/along_line.png:/icon/32x32/along_line.png + :/icon/32x32/point_of_contact.png:/icon/32x32/point_of_contact.png @@ -194,20 +168,72 @@ - - + + false - Tool point of contact. + Tool point of normal. ... - :/icon/32x32/point_of_contact.png:/icon/32x32/point_of_contact.png + :/icon/32x32/normal.png:/icon/32x32/normal.png + + + + 32 + 32 + + + + true + + + + + + + false + + + Tool point along line. + + + ... + + + + :/icon/32x32/along_line.png:/icon/32x32/along_line.png + + + + 32 + 32 + + + + true + + + + + + + false + + + Tool point of height. + + + ... + + + + :/icon/32x32/height.png:/icon/32x32/height.png diff --git a/options.h b/options.h index 1d04de588..28b99f2d9 100644 --- a/options.h +++ b/options.h @@ -55,7 +55,8 @@ enum Tool {ArrowTool, NodePoint, NodeArc, NodeSpline, - NodeSplinePath + NodeSplinePath, + Height }; Q_DECLARE_FLAGS(Tools, Tool) diff --git a/tools/drawTools/drawtools.h b/tools/drawTools/drawtools.h index 0d2c5b613..58fcbaf08 100644 --- a/tools/drawTools/drawtools.h +++ b/tools/drawTools/drawtools.h @@ -34,5 +34,6 @@ #include "vtoolsinglepoint.h" #include "vtoolspline.h" #include "vtoolsplinepath.h" +#include "vtoolheight.h" #endif // DRAWTOOLS_H diff --git a/tools/drawTools/vdrawtool.cpp b/tools/drawTools/vdrawtool.cpp index 197d800b9..0e622413b 100644 --- a/tools/drawTools/vdrawtool.cpp +++ b/tools/drawTools/vdrawtool.cpp @@ -25,7 +25,7 @@ qreal VDrawTool::factor = 1; VDrawTool::VDrawTool(VDomDocument *doc, VContainer *data, qint64 id, QObject *parent) : - VAbstractTool(doc, data, id, parent), ignoreContextMenuEvent(false), + VAbstractTool(doc, data, id, parent), ignoreContextMenuEvent(false), ignoreFullUpdate(false), nameActivDraw(doc->GetNameActivDraw()){ connect(this->doc, &VDomDocument::ChangedActivDraw, this, &VDrawTool::ChangedActivDraw); connect(this->doc, &VDomDocument::ChangedNameDraw, this, &VDrawTool::ChangedNameDraw); diff --git a/tools/drawTools/vdrawtool.h b/tools/drawTools/vdrawtool.h index 91a7a4527..4ef092514 100644 --- a/tools/drawTools/vdrawtool.h +++ b/tools/drawTools/vdrawtool.h @@ -43,6 +43,7 @@ signals: void RemoveTool(QGraphicsItem *tool); protected: bool ignoreContextMenuEvent; + bool ignoreFullUpdate; QString nameActivDraw; static qreal factor; void AddToCalculation(const QDomElement &domElement); @@ -67,11 +68,12 @@ protected: if(selectedAction == actionOption){ dialog = QSharedPointer(new Dialog(getData())); - connect(qobject_cast< VMainGraphicsScene * >(tool->scene()), &VMainGraphicsScene::ChoosedObject, - dialog.data(), &Dialog::ChoosedObject); - connect(dialog.data(), &Dialog::DialogClosed, tool, - &Tool::FullUpdateFromGui); - connect(doc, &VDomDocument::FullUpdateFromFile, dialog.data(), &Dialog::UpdateList); + connect(qobject_cast< VMainGraphicsScene * >(tool->scene()), + &VMainGraphicsScene::ChoosedObject, dialog.data(), &Dialog::ChoosedObject); + connect(dialog.data(), &Dialog::DialogClosed, tool, &Tool::FullUpdateFromGui); + if(!ignoreFullUpdate){ + connect(doc, &VDomDocument::FullUpdateFromFile, dialog.data(), &Dialog::UpdateList); + } tool->setDialog(); diff --git a/tools/drawTools/vtoolendline.cpp b/tools/drawTools/vtoolendline.cpp index 2e0d24abb..3bfd214a0 100644 --- a/tools/drawTools/vtoolendline.cpp +++ b/tools/drawTools/vtoolendline.cpp @@ -37,14 +37,12 @@ VToolEndLine::VToolEndLine(VDomDocument *doc, VContainer *data, const qint64 &id void VToolEndLine::setDialog(){ Q_ASSERT(!dialogEndLine.isNull()); - if(!dialogEndLine.isNull()){ - VPointF p = VAbstractTool::data.GetPoint(id); - dialogEndLine->setTypeLine(typeLine); - dialogEndLine->setFormula(formula); - dialogEndLine->setAngle(angle); - dialogEndLine->setBasePointId(basePointId, id); - dialogEndLine->setPointName(p.name()); - } + VPointF p = VAbstractTool::data.GetPoint(id); + dialogEndLine->setTypeLine(typeLine); + dialogEndLine->setFormula(formula); + dialogEndLine->setAngle(angle); + dialogEndLine->setBasePointId(basePointId, id); + dialogEndLine->setPointName(p.name()); } void VToolEndLine::Create(QSharedPointer &dialog, VMainGraphicsScene *scene, diff --git a/tools/drawTools/vtoolheight.cpp b/tools/drawTools/vtoolheight.cpp new file mode 100644 index 000000000..3779eebfe --- /dev/null +++ b/tools/drawTools/vtoolheight.cpp @@ -0,0 +1,138 @@ +#include "vtoolheight.h" + +VToolHeight::VToolHeight(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &typeLine, + const qint64 &basePointId, const qint64 &p1LineId, const qint64 &p2LineId, + Tool::Sources typeCreation, QGraphicsItem * parent) + :VToolLinePoint(doc, data, id, typeLine, QString(), basePointId, 0, parent), + dialogHeight(QSharedPointer()), p1LineId(p1LineId), p2LineId(p2LineId){ + ignoreFullUpdate = true; + if(typeCreation == Tool::FromGui){ + AddToFile(); + } +} + +void VToolHeight::setDialog(){ + Q_ASSERT(!dialogHeight.isNull()); + VPointF p = VAbstractTool::data.GetPoint(id); + dialogHeight->setTypeLine(typeLine); + dialogHeight->setBasePointId(basePointId, id); + dialogHeight->setP1LineId(p1LineId, id); + dialogHeight->setP2LineId(p2LineId, id); + dialogHeight->setPointName(p.name()); +} + +void VToolHeight::Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, + VContainer *data){ + disconnect(doc, &VDomDocument::FullUpdateFromFile, dialog.data(), &DialogHeight::UpdateList); + QString pointName = dialog->getPointName(); + QString typeLine = dialog->getTypeLine(); + qint64 basePointId = dialog->getBasePointId(); + qint64 p1LineId = dialog->getP1LineId(); + qint64 p2LineId = dialog->getP2LineId(); + Create(0, pointName, typeLine, basePointId, p1LineId, p2LineId, 5, 10, scene, doc, data, + Document::FullParse, Tool::FromGui); +} + +void VToolHeight::Create(const qint64 _id, const QString &pointName, const QString &typeLine, + const qint64 &basePointId, const qint64 &p1LineId, const qint64 &p2LineId, + const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VDomDocument *doc, + VContainer *data, const Document::Documents &parse, Tool::Sources typeCreation){ + VPointF basePoint = data->GetPoint(basePointId); + VPointF p1Line = data->GetPoint(p1LineId); + VPointF p2Line = data->GetPoint(p2LineId); + + QPointF pHeight = FindPoint(QLineF(p1Line.toQPointF(), p2Line.toQPointF()), basePoint.toQPointF()); + qint64 id = _id; + if(typeCreation == Tool::FromGui){ + id = data->AddPoint(VPointF(pHeight.x(), pHeight.y(), pointName, mx, my)); + data->AddLine(basePointId, id); + data->AddLine(p1LineId, id); + data->AddLine(p2LineId, id); + } else { + data->UpdatePoint(id, VPointF(pHeight.x(), pHeight.y(), pointName, mx, my)); + data->AddLine(basePointId, id); + data->AddLine(p1LineId, id); + data->AddLine(p2LineId, id); + if(parse != Document::FullParse){ + doc->UpdateToolData(id, data); + } + } + VDrawTool::AddRecord(id, Tool::Height, doc); + if(parse == Document::FullParse){ + VToolHeight *point = new VToolHeight(doc, data, id, typeLine, basePointId, p1LineId, p2LineId, + typeCreation); + scene->addItem(point); + connect(point, &VToolPoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); + connect(point, &VToolPoint::RemoveTool, scene, &VMainGraphicsScene::RemoveTool); + connect(scene, &VMainGraphicsScene::NewFactor, point, &VToolPoint::SetFactor); + doc->AddTool(id, point); + doc->IncrementReferens(basePointId); + doc->IncrementReferens(p1LineId); + doc->IncrementReferens(p2LineId); + } +} + +QPointF VToolHeight::FindPoint(const QLineF &line, const QPointF &point){ + qreal a = 0, b = 0, c = 0; + LineCoefficients(line, &a, &b, &c); + qreal x = point.x() + a; + qreal y = b + point.y(); + QLineF l (point, QPointF(x, y)); + QPointF p; + QLineF::IntersectType intersect = line.intersect(l, &p); + if(intersect == QLineF::UnboundedIntersection || intersect == QLineF::BoundedIntersection){ + return p; + } else { + return QPointF(); + } +} + +void VToolHeight::FullUpdateFromFile(){ + QDomElement domElement = doc->elementById(QString().setNum(id)); + if(domElement.isElement()){ + typeLine = domElement.attribute("typeLine", ""); + basePointId = domElement.attribute("basePoint", "").toLongLong(); + p1LineId = domElement.attribute("p1Line", "").toLongLong(); + p2LineId = domElement.attribute("p2Line", "").toLongLong(); + } + RefreshGeometry(); + +} + +void VToolHeight::FullUpdateFromGui(int result){ + if(result == QDialog::Accepted){ + QDomElement domElement = doc->elementById(QString().setNum(id)); + if(domElement.isElement()){ + domElement.setAttribute("name", dialogHeight->getPointName()); + domElement.setAttribute("typeLine", dialogHeight->getTypeLine()); + domElement.setAttribute("basePoint", QString().setNum(dialogHeight->getBasePointId())); + domElement.setAttribute("p1Line", QString().setNum(dialogHeight->getP1LineId())); + domElement.setAttribute("p2Line", QString().setNum(dialogHeight->getP2LineId())); + emit FullUpdateTree(); + } + } + dialogHeight.clear(); +} + +void VToolHeight::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ + ContextMenu(dialogHeight, this, event); +} + +void VToolHeight::AddToFile(){ + VPointF point = VAbstractTool::data.GetPoint(id); + QDomElement domElement = doc->createElement("point"); + + AddAttribute(domElement, "id", id); + AddAttribute(domElement, "type", "height"); + AddAttribute(domElement, "name", point.name()); + AddAttribute(domElement, "mx", toMM(point.mx())); + AddAttribute(domElement, "my", toMM(point.my())); + + AddAttribute(domElement, "typeLine", typeLine); + AddAttribute(domElement, "basePoint", basePointId); + AddAttribute(domElement, "p1Line", p1LineId); + AddAttribute(domElement, "p2Line", p2LineId); + + AddToCalculation(domElement); + +} diff --git a/tools/drawTools/vtoolheight.h b/tools/drawTools/vtoolheight.h new file mode 100644 index 000000000..c3ab6d02f --- /dev/null +++ b/tools/drawTools/vtoolheight.h @@ -0,0 +1,34 @@ +#ifndef VTOOLHEIGHT_H +#define VTOOLHEIGHT_H + +#include "vtoollinepoint.h" +#include "dialogs/dialogheight.h" +#include + +class VToolHeight: public VToolLinePoint{ + Q_OBJECT +public: + VToolHeight(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &typeLine, + const qint64 &basePointId, const qint64 &p1LineId, const qint64 &p2LineId, + Tool::Sources typeCreation, QGraphicsItem * parent = 0); + virtual void setDialog(); + static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, + VDomDocument *doc, VContainer *data); + static void Create(const qint64 _id, const QString &pointName, const QString &typeLine, + const qint64 &basePointId, const qint64 &p1LineId, const qint64 &p2LineId, + const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VDomDocument *doc, + VContainer *data, const Document::Documents &parse, Tool::Sources typeCreation); + static QPointF FindPoint(const QLineF &line, const QPointF &point); +public slots: + virtual void FullUpdateFromFile(); + virtual void FullUpdateFromGui(int result); +protected: + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void AddToFile(); +private: + QSharedPointer dialogHeight; + qint64 p1LineId; + qint64 p2LineId; +}; + +#endif // VTOOLHEIGHT_H diff --git a/tools/modelingTools/modelingtools.h b/tools/modelingTools/modelingtools.h index 2a051f87a..a40cdf15a 100644 --- a/tools/modelingTools/modelingtools.h +++ b/tools/modelingTools/modelingtools.h @@ -34,5 +34,6 @@ #include "vmodelingsinglepoint.h" #include "vmodelingspline.h" #include "vmodelingsplinepath.h" +#include "vmodelingheight.h" #endif // MODELINGTOOLS_H diff --git a/tools/modelingTools/vmodelingalongline.cpp b/tools/modelingTools/vmodelingalongline.cpp index 76d448dad..096ad37aa 100644 --- a/tools/modelingTools/vmodelingalongline.cpp +++ b/tools/modelingTools/vmodelingalongline.cpp @@ -74,8 +74,8 @@ void VModelingAlongLine::AddToFile(){ AddAttribute(domElement, "id", id); AddAttribute(domElement, "type", "alongLine"); AddAttribute(domElement, "name", point.name()); - AddAttribute(domElement, "mx", point.mx()/PrintDPI*25.4); - AddAttribute(domElement, "my", point.my()/PrintDPI*25.4); + AddAttribute(domElement, "mx", toMM(point.mx())); + AddAttribute(domElement, "my", toMM(point.my())); AddAttribute(domElement, "typeLine", typeLine); AddAttribute(domElement, "length", formula); diff --git a/tools/modelingTools/vmodelingendline.cpp b/tools/modelingTools/vmodelingendline.cpp index 17021859d..f13768c51 100644 --- a/tools/modelingTools/vmodelingendline.cpp +++ b/tools/modelingTools/vmodelingendline.cpp @@ -24,9 +24,10 @@ #include #include "widgets/vmaingraphicsscene.h" -VModelingEndLine::VModelingEndLine(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &typeLine, - const QString &formula, const qreal &angle, const qint64 &basePointId, - Tool::Sources typeCreation, QGraphicsItem *parent): +VModelingEndLine::VModelingEndLine(VDomDocument *doc, VContainer *data, const qint64 &id, + const QString &typeLine, const QString &formula, const qreal &angle, + const qint64 &basePointId, Tool::Sources typeCreation, + QGraphicsItem *parent): VModelingLinePoint(doc, data, id, typeLine, formula, basePointId, angle, parent), dialogEndLine(QSharedPointer()){ @@ -37,18 +38,16 @@ VModelingEndLine::VModelingEndLine(VDomDocument *doc, VContainer *data, const qi void VModelingEndLine::setDialog(){ Q_ASSERT(!dialogEndLine.isNull()); - if(!dialogEndLine.isNull()){ - VPointF p = VAbstractTool::data.GetModelingPoint(id); - dialogEndLine->setTypeLine(typeLine); - dialogEndLine->setFormula(formula); - dialogEndLine->setAngle(angle); - dialogEndLine->setBasePointId(basePointId, id); - dialogEndLine->setPointName(p.name()); - } + VPointF p = VAbstractTool::data.GetModelingPoint(id); + dialogEndLine->setTypeLine(typeLine); + dialogEndLine->setFormula(formula); + dialogEndLine->setAngle(angle); + dialogEndLine->setBasePointId(basePointId, id); + dialogEndLine->setPointName(p.name()); } VModelingEndLine *VModelingEndLine::Create(QSharedPointer &dialog, VDomDocument *doc, - VContainer *data){ + VContainer *data){ QString pointName = dialog->getPointName(); QString typeLine = dialog->getTypeLine(); QString formula = dialog->getFormula(); @@ -70,7 +69,7 @@ VModelingEndLine *VModelingEndLine::Create(const qint64 _id, const QString &poin QString errorMsg; qreal result = cal.eval(formula, &errorMsg); if(errorMsg.isEmpty()){ - line.setLength(result*PrintDPI/25.4); + line.setLength(toPixel(result)); line.setAngle(angle); qint64 id = _id; if(typeCreation == Tool::FromGui){ @@ -97,7 +96,7 @@ void VModelingEndLine::FullUpdateFromFile(){ typeLine = domElement.attribute("typeLine", ""); formula = domElement.attribute("length", ""); basePointId = domElement.attribute("basePoint", "").toLongLong(); - angle = domElement.attribute("angle", "").toInt(); + angle = domElement.attribute("angle", "").toDouble(); } RefreshGeometry(); } diff --git a/tools/modelingTools/vmodelingheight.cpp b/tools/modelingTools/vmodelingheight.cpp new file mode 100644 index 000000000..d4d6ef1bc --- /dev/null +++ b/tools/modelingTools/vmodelingheight.cpp @@ -0,0 +1,130 @@ +#include "vmodelingheight.h" + +VModelingHeight::VModelingHeight(VDomDocument *doc, VContainer *data, const qint64 &id, + const QString &typeLine, const qint64 &basePointId, const qint64 &p1LineId, + const qint64 &p2LineId, Tool::Sources typeCreation, + QGraphicsItem * parent) + :VModelingLinePoint(doc, data, id, typeLine, QString(), basePointId, 0, parent), + dialogHeight(QSharedPointer()), p1LineId(p1LineId), p2LineId(p2LineId){ + ignoreFullUpdate = true; + if(typeCreation == Tool::FromGui){ + AddToFile(); + } +} + +void VModelingHeight::setDialog(){ + Q_ASSERT(!dialogHeight.isNull()); + VPointF p = VAbstractTool::data.GetModelingPoint(id); + dialogHeight->setTypeLine(typeLine); + dialogHeight->setBasePointId(basePointId, id); + dialogHeight->setP1LineId(p1LineId, id); + dialogHeight->setP2LineId(p2LineId, id); + dialogHeight->setPointName(p.name()); +} + +VModelingHeight *VModelingHeight::Create(QSharedPointer &dialog, VDomDocument *doc, + VContainer *data){ + disconnect(doc, &VDomDocument::FullUpdateFromFile, dialog.data(), &DialogHeight::UpdateList); + QString pointName = dialog->getPointName(); + QString typeLine = dialog->getTypeLine(); + qint64 basePointId = dialog->getBasePointId(); + qint64 p1LineId = dialog->getP1LineId(); + qint64 p2LineId = dialog->getP2LineId(); + return Create(0, pointName, typeLine, basePointId, p1LineId, p2LineId, 5, 10, doc, data, + Document::FullParse, Tool::FromGui); +} + +VModelingHeight *VModelingHeight::Create(const qint64 _id, const QString &pointName, const QString &typeLine, + const qint64 &basePointId, const qint64 &p1LineId, + const qint64 &p2LineId, const qreal &mx, const qreal &my, + VDomDocument *doc, VContainer *data, + const Document::Documents &parse, Tool::Sources typeCreation){ + VModelingHeight *point = 0; + VPointF basePoint = data->GetModelingPoint(basePointId); + VPointF p1Line = data->GetModelingPoint(p1LineId); + VPointF p2Line = data->GetModelingPoint(p2LineId); + + QPointF pHeight = FindPoint(QLineF(p1Line.toQPointF(), p2Line.toQPointF()), basePoint.toQPointF()); + QLineF line = QLineF(basePoint.toQPointF(), pHeight); + qint64 id = _id; + if(typeCreation == Tool::FromGui){ + id = data->AddModelingPoint(VPointF(line.p2().x(), line.p2().y(), pointName, mx, my)); + } else { + data->UpdateModelingPoint(id, VPointF(line.p2().x(), line.p2().y(), pointName, mx, my)); + if(parse != Document::FullParse){ + doc->UpdateToolData(id, data); + } + } + data->AddLine(basePointId, id, Draw::Modeling); + if(parse == Document::FullParse){ + point = new VModelingHeight(doc, data, id, typeLine, basePointId, p1LineId, p2LineId, typeCreation); + doc->AddTool(id, point); + doc->IncrementReferens(basePointId); + doc->IncrementReferens(p1LineId); + doc->IncrementReferens(p2LineId); + } + return point; +} + +void VModelingHeight::FullUpdateFromFile(){ + QDomElement domElement = doc->elementById(QString().setNum(id)); + if(domElement.isElement()){ + typeLine = domElement.attribute("typeLine", ""); + basePointId = domElement.attribute("basePoint", "").toLongLong(); + p1LineId = domElement.attribute("p1Line", "").toLongLong(); + p2LineId = domElement.attribute("p2Line", "").toLongLong(); + } + RefreshGeometry(); +} + +void VModelingHeight::FullUpdateFromGui(int result){ + if(result == QDialog::Accepted){ + QDomElement domElement = doc->elementById(QString().setNum(id)); + if(domElement.isElement()){ + domElement.setAttribute("name", dialogHeight->getPointName()); + domElement.setAttribute("typeLine", dialogHeight->getTypeLine()); + domElement.setAttribute("basePoint", QString().setNum(dialogHeight->getBasePointId())); + domElement.setAttribute("p1Line", QString().setNum(dialogHeight->getP1LineId())); + domElement.setAttribute("p2Line", QString().setNum(dialogHeight->getP2LineId())); + emit FullUpdateTree(); + } + } + dialogHeight.clear(); +} + +void VModelingHeight::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ + ContextMenu(dialogHeight, this, event); +} + +void VModelingHeight::AddToFile(){ + VPointF point = VAbstractTool::data.GetModelingPoint(id); + QDomElement domElement = doc->createElement("point"); + + AddAttribute(domElement, "id", id); + AddAttribute(domElement, "type", "endLine"); + AddAttribute(domElement, "name", point.name()); + AddAttribute(domElement, "mx", toMM(point.mx())); + AddAttribute(domElement, "my", toMM(point.my())); + + AddAttribute(domElement, "typeLine", typeLine); + AddAttribute(domElement, "basePoint", basePointId); + AddAttribute(domElement, "p1Line", p1LineId); + AddAttribute(domElement, "p2Line", p2LineId); + + AddToModeling(domElement); +} + +QPointF VModelingHeight::FindPoint(const QLineF &line, const QPointF &point){ + qreal a = 0, b = 0, c = 0; + LineCoefficients(line, &a, &b, &c); + qreal x = point.x() - b; + qreal y = -a + point.y(); + QLineF l (point, QPointF(x, y)); + QPointF p; + QLineF::IntersectType intersect = line.intersect(l, &p); + if(intersect == QLineF::UnboundedIntersection || intersect == QLineF::BoundedIntersection){ + return p; + } else { + return QPointF(); + } +} diff --git a/tools/modelingTools/vmodelingheight.h b/tools/modelingTools/vmodelingheight.h new file mode 100644 index 000000000..8d02dd8fd --- /dev/null +++ b/tools/modelingTools/vmodelingheight.h @@ -0,0 +1,34 @@ +#ifndef VMODELINGHEIGHT_H +#define VMODELINGHEIGHT_H + +#include "vmodelinglinepoint.h" +#include "dialogs/dialogheight.h" + +class VModelingHeight : public VModelingLinePoint{ + Q_OBJECT +public: + VModelingHeight(VDomDocument *doc, VContainer *data, const qint64 &id, + const QString &typeLine, const qint64 &basePointId, + const qint64 &p1LineId, const qint64 &p2LineId, + Tool::Sources typeCreation, QGraphicsItem * parent = 0); +virtual void setDialog(); + static VModelingHeight* Create(QSharedPointer &dialog, VDomDocument *doc, + VContainer *data); + static VModelingHeight* Create(const qint64 _id, const QString &pointName, const QString &typeLine, + const qint64 &basePointId, const qint64 &p1LineId, const qint64 &p2LineId, + const qreal &mx, const qreal &my, VDomDocument *doc, VContainer *data, + const Document::Documents &parse, Tool::Sources typeCreation); + static QPointF FindPoint(const QLineF &line, const QPointF &point); +public slots: + virtual void FullUpdateFromFile(); + virtual void FullUpdateFromGui(int result); +protected: + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void AddToFile(); +private: + QSharedPointer dialogHeight; + qint64 p1LineId; + qint64 p2LineId; +}; + +#endif // VMODELINGHEIGHT_H diff --git a/tools/modelingTools/vmodelingtool.cpp b/tools/modelingTools/vmodelingtool.cpp index c651880dd..2dc6b5ad4 100644 --- a/tools/modelingTools/vmodelingtool.cpp +++ b/tools/modelingTools/vmodelingtool.cpp @@ -23,7 +23,7 @@ #include VModelingTool::VModelingTool(VDomDocument *doc, VContainer *data, qint64 id, QObject *parent): -VAbstractTool(doc, data, id, parent), ignoreContextMenuEvent(false){ +VAbstractTool(doc, data, id, parent), ignoreContextMenuEvent(false), ignoreFullUpdate(false) { _referens = 0; } diff --git a/tools/modelingTools/vmodelingtool.h b/tools/modelingTools/vmodelingtool.h index f5bb4bbc7..69a4814e6 100644 --- a/tools/modelingTools/vmodelingtool.h +++ b/tools/modelingTools/vmodelingtool.h @@ -39,6 +39,7 @@ signals: void RemoveTool(QGraphicsItem *tool); protected: bool ignoreContextMenuEvent; + bool ignoreFullUpdate; void AddToModeling(const QDomElement &domElement); virtual void decrementReferens(); template @@ -46,39 +47,44 @@ protected: bool showRemove = true){ if(!ignoreContextMenuEvent){ QMenu menu; - QAction *actionOption = menu.addAction("Властивості"); - QAction *actionRemove; + QAction *actionOption = menu.addAction(tr("Option")); + QAction *actionRemove = 0; if(showRemove){ - actionRemove = menu.addAction("Видалити"); + actionRemove = menu.addAction(tr("Delete")); } QAction *selectedAction = menu.exec(event->screenPos()); if(selectedAction == actionOption){ - dialog = QSharedPointer(new Dialog(getData())); + dialog = QSharedPointer(new Dialog(getData())); - connect(qobject_cast< VMainGraphicsScene * >(tool->scene()), &VMainGraphicsScene::ChoosedObject, - dialog.data(), &Dialog::ChoosedObject); - connect(dialog.data(), &Dialog::DialogClosed, tool, - &Tool::FullUpdateFromGui); - connect(doc, &VDomDocument::FullUpdateFromFile, dialog.data(), &Dialog::UpdateList); + connect(qobject_cast< VMainGraphicsScene * >(tool->scene()), + &VMainGraphicsScene::ChoosedObject, dialog.data(), &Dialog::ChoosedObject); + connect(dialog.data(), &Dialog::DialogClosed, tool, &Tool::FullUpdateFromGui); + if(!ignoreFullUpdate){ + connect(doc, &VDomDocument::FullUpdateFromFile, dialog.data(), &Dialog::UpdateList); + } tool->setDialog(); dialog->show(); } - if(selectedAction == actionRemove){ - //remove form xml file - QDomElement domElement = doc->elementById(QString().setNum(id)); - if(domElement.isElement()){ - QDomElement element; - bool ok = doc->GetActivCalculationElement(element); - if(ok){ - element.removeChild(domElement); - //update xml file - emit FullUpdateTree(); - //remove form scene - emit RemoveTool(tool); - } - } + if(showRemove){ + if(selectedAction == actionRemove){ + //deincrement referens + RemoveReferens(); + //remove form xml file + QDomElement domElement = doc->elementById(QString().setNum(id)); + if(domElement.isElement()){ + QDomElement element; + bool ok = doc->GetActivCalculationElement(element); + if(ok){ + element.removeChild(domElement); + //update xml file + emit FullUpdateTree(); + //remove form scene + emit RemoveTool(tool); + } + } + } } } } diff --git a/tools/vabstracttool.cpp b/tools/vabstracttool.cpp index 50838f4d7..e6b656efc 100644 --- a/tools/vabstracttool.cpp +++ b/tools/vabstracttool.cpp @@ -85,10 +85,8 @@ qint32 VAbstractTool::LineIntersectCircle(QPointF center, qreal radius, QLineF l QPointF &p2){ const qreal eps = 1e-8; //коефіцієнти для рівняння відрізку - qreal a = line.p2().y() - line.p1().y(); - qreal b = line.p1().x() - line.p2().x(); - // В даному випадку не використовується. - //qreal c = - a * line.p1().x() - b * line.p1().y(); + qreal a = 0, b = 0, c = 0; + LineCoefficients(line, &a, &b, &c); // проекция центра окружности на прямую QPointF p = ClosestPoint (line, center); // сколько всего решений? @@ -138,6 +136,13 @@ const VContainer *VAbstractTool::getData()const{ return &data; } +void VAbstractTool::LineCoefficients(const QLineF &line, qreal *a, qreal *b, qreal *c){ + //коефіцієнти для рівняння відрізку + *a = line.p2().y() - line.p1().y(); + *b = line.p1().x() - line.p2().x(); + *c = - *a * line.p1().x() - *b * line.p1().y(); +} + qint64 VAbstractTool::getId() const{ return id; } diff --git a/tools/vabstracttool.h b/tools/vabstracttool.h index 2391e053b..0982bc64c 100644 --- a/tools/vabstracttool.h +++ b/tools/vabstracttool.h @@ -35,8 +35,8 @@ public: QPointF &p2); static QPointF ClosestPoint(QLineF line, QPointF p); static QPointF addVector (QPointF p, QPointF p1, QPointF p2, qreal k); - qint64 getId() const; - + qint64 getId() const; + static void LineCoefficients(const QLineF &line, qreal *a, qreal *b, qreal *c); public slots: virtual void FullUpdateFromFile()=0; signals: diff --git a/xml/vdomdocument.cpp b/xml/vdomdocument.cpp index 8c7118c84..52e42e7ff 100644 --- a/xml/vdomdocument.cpp +++ b/xml/vdomdocument.cpp @@ -806,6 +806,31 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen throw excep; } } + if(type == "height"){ + try{ + qint64 id = GetParametrId(domElement); + QString name = GetParametrString(domElement, "name"); + qreal mx = toPixel(GetParametrDouble(domElement, "mx")); + qreal my = toPixel(GetParametrDouble(domElement, "my")); + QString typeLine = GetParametrString(domElement, "typeLine"); + qint64 basePointId = GetParametrLongLong(domElement, "basePoint"); + qint64 p1LineId = GetParametrLongLong(domElement, "p1Line"); + qint64 p2LineId = GetParametrLongLong(domElement, "p2Line"); + if(mode == Draw::Calculation){ + VToolHeight::Create(id, name, typeLine, basePointId, p1LineId, p2LineId, mx, my, scene, + this, data, parse, Tool::FromFile); + } else { + VModelingHeight::Create(id, name, typeLine, basePointId, p1LineId, p2LineId, mx, my, this, + data, parse, Tool::FromFile); + } + return; + } + catch(const VExceptionBadId &e){ + VExceptionObjectError excep(tr("Error creating or updating height"), domElement); + excep.AddMoreInformation(e.ErrorMessage()); + throw excep; + } + } } void VDomDocument::ParseLineElement(VMainGraphicsScene *scene, const QDomElement &domElement,