diff --git a/Valentina.pro b/Valentina.pro
index c05bf37e1..74ac8fbca 100644
--- a/Valentina.pro
+++ b/Valentina.pro
@@ -100,7 +100,10 @@ SOURCES += main.cpp\
exception/vexceptionuniqueid.cpp \
tools/drawTools/vtoolheight.cpp \
tools/modelingTools/vmodelingheight.cpp \
- dialogs/dialogheight.cpp
+ dialogs/dialogheight.cpp \
+ tools/drawTools/vtooltriangle.cpp \
+ tools/modelingTools/vmodelingtriangle.cpp \
+ dialogs/dialogtriangle.cpp
HEADERS += mainwindow.h \
widgets/vmaingraphicsscene.h \
@@ -194,7 +197,10 @@ HEADERS += mainwindow.h \
exception/vexceptionuniqueid.h \
tools/drawTools/vtoolheight.h \
tools/modelingTools/vmodelingheight.h \
- dialogs/dialogheight.h
+ dialogs/dialogheight.h \
+ tools/drawTools/vtooltriangle.h \
+ tools/modelingTools/vmodelingtriangle.h \
+ dialogs/dialogtriangle.h
FORMS += mainwindow.ui \
dialogs/dialogsinglepoint.ui \
@@ -213,7 +219,8 @@ FORMS += mainwindow.ui \
dialogs/dialogpointofcontact.ui \
dialogs/dialogdetail.ui \
tablewindow.ui \
- dialogs/dialogheight.ui
+ dialogs/dialogheight.ui \
+ dialogs/dialogtriangle.ui
RESOURCES += \
icon.qrc \
diff --git a/cursor.qrc b/cursor.qrc
index b38ff9e43..a0827a0a2 100644
--- a/cursor.qrc
+++ b/cursor.qrc
@@ -13,5 +13,6 @@
cursor/pointcontact_cursor.png
cursor/new_detail_cursor.png
cursor/height_cursor.png
+ cursor/triangle_cursor.png
diff --git a/cursor/triangle_cursor.png b/cursor/triangle_cursor.png
new file mode 100644
index 000000000..2fc657ce8
Binary files /dev/null and b/cursor/triangle_cursor.png differ
diff --git a/dialogs/dialogheight.cpp b/dialogs/dialogheight.cpp
index dc1002147..fa71daa7c 100644
--- a/dialogs/dialogheight.cpp
+++ b/dialogs/dialogheight.cpp
@@ -6,7 +6,6 @@ DialogHeight::DialogHeight(const VContainer *data, Draw::Draws mode, QWidget *pa
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;
diff --git a/dialogs/dialogheight.ui b/dialogs/dialogheight.ui
index bfb3dab67..9c4900050 100644
--- a/dialogs/dialogheight.ui
+++ b/dialogs/dialogheight.ui
@@ -13,6 +13,9 @@
Dialog
+
+
+
-
diff --git a/dialogs/dialoghistory.cpp b/dialogs/dialoghistory.cpp
index d1b19544a..10df37d63 100644
--- a/dialogs/dialoghistory.cpp
+++ b/dialogs/dialoghistory.cpp
@@ -264,6 +264,21 @@ QString DialogHistory::Record(const VToolRecord &tool){
data->GetPoint(p2LineId).name());
break;
}
+ case Tool::Triangle:{
+ qint64 axisP1Id = 0;
+ qint64 axisP2Id = 0;
+ domElement = doc->elementById(QString().setNum(tool.getId()));
+ if(domElement.isElement()){
+ axisP1Id = domElement.attribute("axisP1", "").toLongLong();
+ axisP2Id = domElement.attribute("axisP2", "").toLongLong();
+ firstPointId = domElement.attribute("firstPoint", "").toLongLong();
+ secondPointId = domElement.attribute("secondPoint", "").toLongLong();
+ }
+ record = QString(tr("Triangle: axis %1_%2, points %3 and %4")).arg(
+ data->GetPoint(axisP1Id).name(),data->GetPoint(axisP2Id).name(),
+ data->GetPoint(firstPointId).name(), data->GetPoint(secondPointId).name());
+ break;
+ }
default:
qWarning()<
setupUi(this);
+ labelEditNamePoint = ui->labelEditNamePoint;
+ bOk = ui->buttonBox->button(QDialogButtonBox::Ok);
+ connect(bOk, &QPushButton::clicked, this, &DialogTriangle::DialogAccepted);
+ flagName = false;
+ CheckState();
+ QPushButton *bCansel = ui->buttonBox->button(QDialogButtonBox::Cancel);
+ connect(bCansel, &QPushButton::clicked, this, &DialogTriangle::DialogRejected);
+ FillComboBoxPoints(ui->comboBoxAxisP1);
+ FillComboBoxPoints(ui->comboBoxAxisP2);
+ FillComboBoxPoints(ui->comboBoxFirstPoint);
+ FillComboBoxPoints(ui->comboBoxSecondPoint);
+ connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogTriangle::NamePointChanged);
+}
+
+DialogTriangle::~DialogTriangle(){
+ delete ui;
+}
+
+void DialogTriangle::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->comboBoxAxisP1, point.name());
+ number++;
+ emit ToolTip(tr("Select second point of axis"));
+ break;
+ case(1):
+ ChangeCurrentText(ui->comboBoxAxisP2, point.name());
+ number++;
+ emit ToolTip(tr("Select first point"));
+ break;
+ case(2):
+ ChangeCurrentText(ui->comboBoxFirstPoint, point.name());
+ number++;
+ emit ToolTip(tr("Select second point"));
+ break;
+ case(3):
+ ChangeCurrentText(ui->comboBoxSecondPoint, point.name());
+ number = 0;
+ emit ToolTip(tr(""));
+ if(!isInitialized){
+ this->show();
+ }
+ break;
+ }
+ }
+}
+
+void DialogTriangle::DialogAccepted(){
+ pointName = ui->lineEditNamePoint->text();
+ firstPointId = getCurrentPointId(ui->comboBoxFirstPoint);
+ secondPointId = getCurrentPointId(ui->comboBoxSecondPoint);
+ axisP1Id = getCurrentPointId(ui->comboBoxAxisP1);
+ axisP2Id = getCurrentPointId(ui->comboBoxAxisP2);
+ emit DialogClosed(QDialog::Accepted);
+}
+QString DialogTriangle::getPointName() const{
+ return pointName;
+}
+
+void DialogTriangle::setPointName(const QString &value){
+ pointName = value;
+ ui->lineEditNamePoint->setText(pointName);
+}
+
+qint64 DialogTriangle::getSecondPointId() const{
+ return secondPointId;
+}
+
+void DialogTriangle::setSecondPointId(const qint64 &value, const qint64 &id){
+ secondPointId = value;
+ setCurrentPointId(ui->comboBoxSecondPoint, secondPointId, value, id);
+}
+
+qint64 DialogTriangle::getFirstPointId() const{
+ return firstPointId;
+}
+
+void DialogTriangle::setFirstPointId(const qint64 &value, const qint64 &id){
+ firstPointId = value;
+ setCurrentPointId(ui->comboBoxFirstPoint, firstPointId, value, id);
+}
+
+qint64 DialogTriangle::getAxisP2Id() const{
+ return axisP2Id;
+}
+
+void DialogTriangle::setAxisP2Id(const qint64 &value, const qint64 &id){
+ axisP2Id = value;
+ setCurrentPointId(ui->comboBoxAxisP2, axisP2Id, value, id);
+}
+
+qint64 DialogTriangle::getAxisP1Id() const{
+ return axisP1Id;
+}
+
+void DialogTriangle::setAxisP1Id(const qint64 &value, const qint64 &id){
+ axisP1Id = value;
+ setCurrentPointId(ui->comboBoxAxisP1, axisP1Id, value, id);
+}
+
diff --git a/dialogs/dialogtriangle.h b/dialogs/dialogtriangle.h
new file mode 100644
index 000000000..74c9bcf3c
--- /dev/null
+++ b/dialogs/dialogtriangle.h
@@ -0,0 +1,42 @@
+#ifndef DIALOGTRIANGLE_H
+#define DIALOGTRIANGLE_H
+
+#include "dialogtool.h"
+
+namespace Ui {
+class DialogTriangle;
+}
+
+class DialogTriangle : public DialogTool
+{
+ Q_OBJECT
+
+public:
+ DialogTriangle(const VContainer *data, Draw::Draws mode = Draw::Calculation,
+ QWidget *parent = 0);
+ ~DialogTriangle();
+ qint64 getAxisP1Id() const;
+ void setAxisP1Id(const qint64 &value, const qint64 &id);
+ qint64 getAxisP2Id() const;
+ void setAxisP2Id(const qint64 &value, const qint64 &id);
+ qint64 getFirstPointId() const;
+ void setFirstPointId(const qint64 &value, const qint64 &id);
+ qint64 getSecondPointId() const;
+ void setSecondPointId(const qint64 &value, const qint64 &id);
+ QString getPointName() const;
+ void setPointName(const QString &value);
+public slots:
+ virtual void ChoosedObject(qint64 id, Scene::Scenes type);
+ virtual void DialogAccepted();
+private:
+ Q_DISABLE_COPY(DialogTriangle)
+ Ui::DialogTriangle *ui;
+ qint32 number;
+ QString pointName;
+ qint64 axisP1Id;
+ qint64 axisP2Id;
+ qint64 firstPointId;
+ qint64 secondPointId;
+};
+
+#endif // DIALOGTRIANGLE_H
diff --git a/dialogs/dialogtriangle.ui b/dialogs/dialogtriangle.ui
new file mode 100644
index 000000000..7e788b2f0
--- /dev/null
+++ b/dialogs/dialogtriangle.ui
@@ -0,0 +1,196 @@
+
+
+ DialogTriangle
+
+
+
+ 0
+ 0
+ 267
+ 220
+
+
+
+ Dialog
+
+
+
+
+
+ -
+
+
-
+
+
+
+ 0
+ 0
+
+
+
+
+
+
+
+
+ 255
+ 0
+ 0
+
+
+
+
+
+
+
+
+ 255
+ 0
+ 0
+
+
+
+
+
+
+
+
+ 159
+ 158
+ 158
+
+
+
+
+
+
+
+ Name new point
+
+
+
+ -
+
+
+
+
+ -
+
+
-
+
+
+ First point of axis
+
+
+
+ -
+
+
+ First point of line
+
+
+
+
+
+ -
+
+
-
+
+
+ Second point of axis
+
+
+
+ -
+
+
+ First point of line
+
+
+
+
+
+ -
+
+
-
+
+
+ First point
+
+
+
+ -
+
+
+ First point of line
+
+
+
+
+
+ -
+
+
-
+
+
+ Second point
+
+
+
+ -
+
+
+ First point of line
+
+
+
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+ QDialogButtonBox::Cancel|QDialogButtonBox::Ok
+
+
+
+
+
+
+
+
+ buttonBox
+ accepted()
+ DialogTriangle
+ accept()
+
+
+ 248
+ 254
+
+
+ 157
+ 274
+
+
+
+
+ buttonBox
+ rejected()
+ DialogTriangle
+ reject()
+
+
+ 316
+ 260
+
+
+ 286
+ 274
+
+
+
+
+
diff --git a/icon.qrc b/icon.qrc
index e5bf6d0ed..520ff398d 100644
--- a/icon.qrc
+++ b/icon.qrc
@@ -35,5 +35,6 @@
icon/32x32/layout.png
icon/16x16/mirror.png
icon/32x32/height.png
+ icon/32x32/triangle.png
diff --git a/icon/32x32/triangle.png b/icon/32x32/triangle.png
new file mode 100644
index 000000000..c409b3b41
Binary files /dev/null and b/icon/32x32/triangle.png differ
diff --git a/mainwindow.cpp b/mainwindow.cpp
index 7befade91..37e1be32c 100644
--- a/mainwindow.cpp
+++ b/mainwindow.cpp
@@ -48,6 +48,7 @@ MainWindow::MainWindow(QWidget *parent) :
dialogArc(QSharedPointer()), dialogSplinePath(QSharedPointer()),
dialogPointOfContact(QSharedPointer()),
dialogDetail(QSharedPointer()), dialogHeight(QSharedPointer()),
+ dialogTriangle(QSharedPointer()),
dialogHistory(0), doc(0), data(0), comboBoxDraws(0), fileName(QString()), changeInFile(false),
mode(Draw::Calculation){
ui->setupUi(this);
@@ -92,6 +93,7 @@ MainWindow::MainWindow(QWidget *parent) :
connect(ui->toolButtonPointOfContact, &QToolButton::clicked, this, &MainWindow::ToolPointOfContact);
connect(ui->toolButtonNewDetail, &QToolButton::clicked, this, &MainWindow::ToolDetail);
connect(ui->toolButtonHeight, &QToolButton::clicked, this, &MainWindow::ToolHeight);
+ connect(ui->toolButtonTriangle, &QToolButton::clicked, this, &MainWindow::ToolTriangle);
data = new VContainer;
@@ -481,6 +483,23 @@ void MainWindow::ClosedDialogHeight(int result){
ArrowTool();
}
+void MainWindow::ToolTriangle(bool checked){
+ SetToolButton(checked, Tool::Triangle, ":/cursor/triangle_cursor.png", tr("Select first point of axis"),
+ dialogTriangle, &MainWindow::ClosedDialogTriangle);
+}
+
+void MainWindow::ClosedDialogTriangle(int result){
+ if(result == QDialog::Accepted){
+ if(mode == Draw::Calculation){
+ VToolTriangle::Create(dialogTriangle, currentScene, doc, data);
+ } else {
+ VModelingTriangle *point = VModelingTriangle::Create(dialogTriangle, doc, data);
+ AddToolToDetail(point, point->getId(), Tool::Triangle, dialogTriangle->getIdDetail());
+ }
+ }
+ ArrowTool();
+}
+
void MainWindow::About(){
QMessageBox::about(this, tr("About Valentina"), tr("Valentina v.0.1.0"));
}
@@ -640,6 +659,7 @@ void MainWindow::CanselTool(){
helpLabel->setText("");
break;
case Tool::SinglePointTool:
+ Q_UNREACHABLE();
//Nothing to do here because we can't create this tool from main window.
break;
case Tool::EndLineTool:
@@ -715,6 +735,14 @@ void MainWindow::CanselTool(){
case Tool::Height:
dialogHeight.clear();
ui->toolButtonHeight->setChecked(false);
+ currentScene->setFocus(Qt::OtherFocusReason);
+ currentScene->clearSelection();
+ break;
+ case Tool::Triangle:
+ dialogTriangle.clear();
+ ui->toolButtonTriangle->setChecked(false);
+ currentScene->setFocus(Qt::OtherFocusReason);
+ currentScene->clearSelection();
break;
default:
qWarning()<<"Get wrong tool type. Ignore.";
@@ -957,6 +985,7 @@ void MainWindow::SetEnableTool(bool enable){
ui->toolButtonPointOfContact->setEnabled(enable);
ui->toolButtonNewDetail->setEnabled(enable);
ui->toolButtonHeight->setEnabled(enable);
+ ui->toolButtonTriangle->setEnabled(enable);
}
void MainWindow::MinimumScrollBar(){
diff --git a/mainwindow.h b/mainwindow.h
index 844052539..2b65763b8 100644
--- a/mainwindow.h
+++ b/mainwindow.h
@@ -41,8 +41,7 @@ namespace Ui {
class MainWindow;
}
-class MainWindow : public QMainWindow
-{
+class MainWindow : public QMainWindow{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
@@ -81,6 +80,7 @@ public slots:
void ToolPointOfContact(bool checked);
void ToolDetail(bool checked);
void ToolHeight(bool checked);
+ void ToolTriangle(bool checked);
void ClosedDialogEndLine(int result);
void ClosedDialogLine(int result);
void ClosedDialogAlongLine(int result);
@@ -94,6 +94,7 @@ public slots:
void ClosedDialogPointOfContact(int result);
void ClosedDialogDetail(int result);
void ClosedDialogHeight(int result);
+ void ClosedDialogTriangle(int result);
void About();
void AboutQt();
void ShowToolTip(const QString &toolTip);
@@ -138,6 +139,7 @@ private:
QSharedPointer dialogPointOfContact;
QSharedPointer dialogDetail;
QSharedPointer dialogHeight;
+ QSharedPointer dialogTriangle;
DialogHistory *dialogHistory;
VDomDocument *doc;
VContainer *data;
diff --git a/mainwindow.ui b/mainwindow.ui
index 0e9a0df8b..920dd684a 100644
--- a/mainwindow.ui
+++ b/mainwindow.ui
@@ -246,6 +246,32 @@
+ -
+
+
+ false
+
+
+ Tool triangle.
+
+
+ ...
+
+
+
+ :/icon/32x32/triangle.png:/icon/32x32/triangle.png
+
+
+
+ 32
+ 32
+
+
+
+ true
+
+
+
@@ -253,7 +279,7 @@
0
0
- 150
+ 100
58
@@ -329,7 +355,7 @@
0
0
- 150
+ 100
58
@@ -405,7 +431,7 @@
0
0
- 150
+ 98
58
@@ -455,7 +481,7 @@
0
0
- 150
+ 98
58
diff --git a/options.h b/options.h
index 28b99f2d9..71aaa9dfd 100644
--- a/options.h
+++ b/options.h
@@ -56,7 +56,8 @@ enum Tool {ArrowTool,
NodeArc,
NodeSpline,
NodeSplinePath,
- Height
+ Height,
+ Triangle
};
Q_DECLARE_FLAGS(Tools, Tool)
diff --git a/tools/drawTools/drawtools.h b/tools/drawTools/drawtools.h
index 58fcbaf08..8051d3641 100644
--- a/tools/drawTools/drawtools.h
+++ b/tools/drawTools/drawtools.h
@@ -35,5 +35,6 @@
#include "vtoolspline.h"
#include "vtoolsplinepath.h"
#include "vtoolheight.h"
+#include "vtooltriangle.h"
#endif // DRAWTOOLS_H
diff --git a/tools/drawTools/vtoolalongline.cpp b/tools/drawTools/vtoolalongline.cpp
index 8d54e14bc..905a5ea98 100644
--- a/tools/drawTools/vtoolalongline.cpp
+++ b/tools/drawTools/vtoolalongline.cpp
@@ -79,8 +79,8 @@ void VToolAlongLine::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/drawTools/vtoolshoulderpoint.cpp b/tools/drawTools/vtoolshoulderpoint.cpp
index 4e3307a51..f1ee18525 100644
--- a/tools/drawTools/vtoolshoulderpoint.cpp
+++ b/tools/drawTools/vtoolshoulderpoint.cpp
@@ -51,22 +51,22 @@ void VToolShoulderPoint::setDialog(){
QPointF VToolShoulderPoint::FindPoint(const QPointF &p1Line, const QPointF &p2Line, const QPointF &pShoulder,
const qreal &length){
QLineF line = QLineF(p1Line, p2Line);
- qreal dist = line.length();
- if(dist>length){
- qDebug()<<"A3П2="<length){
+ qDebug()<<"A3П2="<=length){
return line.p2();
}
- qreal step = 0.01;
- while(1){
- line.setLength(line.length()+step);
- QLineF line2 = QLineF(pShoulder, line.p2());
- if(line2.length()>=length){
- return line.p2();
- }
- }
+ }
}
void VToolShoulderPoint::Create(QSharedPointer &dialog, VMainGraphicsScene *scene,
diff --git a/tools/drawTools/vtooltriangle.cpp b/tools/drawTools/vtooltriangle.cpp
new file mode 100644
index 000000000..5b02c23c3
--- /dev/null
+++ b/tools/drawTools/vtooltriangle.cpp
@@ -0,0 +1,150 @@
+#include "vtooltriangle.h"
+
+VToolTriangle::VToolTriangle(VDomDocument *doc, VContainer *data, const qint64 &id,
+ const qint64 &axisP1Id, const qint64 &axisP2Id, const qint64 &firstPointId,
+ const qint64 &secondPointId, Tool::Sources typeCreation, QGraphicsItem *parent)
+ :VToolPoint(doc, data, id, parent), axisP1Id(axisP1Id), axisP2Id(axisP2Id), firstPointId(firstPointId),
+ secondPointId(secondPointId), dialogTriangle(QSharedPointer()) {
+ if(typeCreation == Tool::FromGui){
+ AddToFile();
+ }
+}
+
+void VToolTriangle::setDialog(){
+ Q_ASSERT(!dialogTriangle.isNull());
+ VPointF p = VAbstractTool::data.GetPoint(id);
+ dialogTriangle->setAxisP1Id(axisP1Id, id);
+ dialogTriangle->setAxisP2Id(axisP2Id, id);
+ dialogTriangle->setFirstPointId(firstPointId, id);
+ dialogTriangle->setSecondPointId(secondPointId, id);
+ dialogTriangle->setPointName(p.name());
+}
+
+void VToolTriangle::Create(QSharedPointer &dialog, VMainGraphicsScene *scene,
+ VDomDocument *doc, VContainer *data){
+ qint64 axisP1Id = dialog->getAxisP1Id();
+ qint64 axisP2Id = dialog->getAxisP2Id();
+ qint64 firstPointId = dialog->getFirstPointId();
+ qint64 secondPointId = dialog->getSecondPointId();
+ QString pointName = dialog->getPointName();
+ Create(0, pointName, axisP1Id, axisP2Id, firstPointId, secondPointId, 5, 10, scene, doc, data,
+ Document::FullParse, Tool::FromGui);
+
+}
+
+void VToolTriangle::Create(const qint64 _id, const QString &pointName, const qint64 &axisP1Id,
+ const qint64 &axisP2Id, const qint64 &firstPointId, const qint64 &secondPointId,
+ const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VDomDocument *doc,
+ VContainer *data, const Document::Documents &parse, Tool::Sources typeCreation){
+ VPointF axisP1 = data->GetPoint(axisP1Id);
+ VPointF axisP2 = data->GetPoint(axisP2Id);
+ VPointF firstPoint = data->GetPoint(firstPointId);
+ VPointF secondPoint = data->GetPoint(secondPointId);
+
+ QPointF point = FindPoint(axisP1.toQPointF(), axisP2.toQPointF(), firstPoint.toQPointF(),
+ secondPoint.toQPointF());
+ qint64 id = _id;
+ if(typeCreation == Tool::FromGui){
+ id = data->AddPoint(VPointF(point.x(), point.y(), pointName, mx, my));
+ } else {
+ data->UpdatePoint(id, VPointF(point.x(), point.y(), pointName, mx, my));
+ if(parse != Document::FullParse){
+ doc->UpdateToolData(id, data);
+ }
+ }
+ VDrawTool::AddRecord(id, Tool::Triangle, doc);
+ if(parse == Document::FullParse){
+ VToolTriangle *point = new VToolTriangle(doc, data, id, axisP1Id, axisP2Id, firstPointId,
+ secondPointId, typeCreation);
+ scene->addItem(point);
+ connect(point, &VToolTriangle::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
+ connect(point, &VToolTriangle::RemoveTool, scene, &VMainGraphicsScene::RemoveTool);
+ connect(scene, &VMainGraphicsScene::NewFactor, point, &VToolTriangle::SetFactor);
+ doc->AddTool(id, point);
+ doc->IncrementReferens(axisP1Id);
+ doc->IncrementReferens(axisP2Id);
+ doc->IncrementReferens(firstPointId);
+ doc->IncrementReferens(secondPointId);
+ }
+}
+
+QPointF VToolTriangle::FindPoint(const QPointF axisP1, const QPointF axisP2, const QPointF firstPoint,
+ const QPointF secondPoint){
+ qreal c = QLineF(firstPoint, secondPoint).length();
+ qreal a = QLineF(axisP2, firstPoint).length();
+ qreal b = QLineF(axisP2, secondPoint).length();
+ if(c*c == a*a + b*b){
+ return axisP2;
+ }
+
+ QLineF line = QLineF(axisP1, axisP2);
+ qreal step = 0.01;
+ while(1){
+ line.setLength(line.length()+step);
+ a = QLineF(line.p2(), firstPoint).length();
+ b = QLineF(line.p2(), secondPoint).length();
+ if(static_cast(c*c) == static_cast(a*a + b*b)){
+ return line.p2();
+ }
+ if(c*c < a*a + b*b){
+ return axisP2;
+ qWarning()<elementById(QString().setNum(id));
+ if(domElement.isElement()){
+ axisP1Id = domElement.attribute("axisP1", "").toLongLong();
+ axisP2Id = domElement.attribute("axisP2", "").toLongLong();
+ firstPointId = domElement.attribute("firstPoint", "").toLongLong();
+ secondPointId = domElement.attribute("secondPoint", "").toLongLong();
+ }
+ VToolPoint::RefreshPointGeometry(VDrawTool::data.GetPoint(id));
+}
+
+void VToolTriangle::FullUpdateFromGui(int result){
+ if(result == QDialog::Accepted){
+ QDomElement domElement = doc->elementById(QString().setNum(id));
+ if(domElement.isElement()){
+ domElement.setAttribute("name", dialogTriangle->getPointName());
+ domElement.setAttribute("axisP1", QString().setNum(dialogTriangle->getAxisP1Id()));
+ domElement.setAttribute("axisP2", QString().setNum(dialogTriangle->getAxisP2Id()));
+ domElement.setAttribute("firstPoint", QString().setNum(dialogTriangle->getFirstPointId()));
+ domElement.setAttribute("secondPoint", QString().setNum(dialogTriangle->getSecondPointId()));
+ emit FullUpdateTree();
+ }
+
+ }
+ dialogTriangle.clear();
+}
+
+void VToolTriangle::RemoveReferens(){
+ doc->DecrementReferens(axisP1Id);
+ doc->DecrementReferens(axisP2Id);
+ doc->DecrementReferens(firstPointId);
+ doc->DecrementReferens(secondPointId);
+}
+
+void VToolTriangle::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){
+ ContextMenu(dialogTriangle, this, event);
+}
+
+void VToolTriangle::AddToFile(){
+ VPointF point = VAbstractTool::data.GetPoint(id);
+ QDomElement domElement = doc->createElement("point");
+
+ AddAttribute(domElement, "id", id);
+ AddAttribute(domElement, "type", "triangle");
+ AddAttribute(domElement, "name", point.name());
+ AddAttribute(domElement, "mx", toMM(point.mx()));
+ AddAttribute(domElement, "my", toMM(point.my()));
+
+ AddAttribute(domElement, "axisP1", axisP1Id);
+ AddAttribute(domElement, "axisP2", axisP2Id);
+ AddAttribute(domElement, "firstPoint", firstPointId);
+ AddAttribute(domElement, "secondPoint", secondPointId);
+
+ AddToCalculation(domElement);
+}
diff --git a/tools/drawTools/vtooltriangle.h b/tools/drawTools/vtooltriangle.h
new file mode 100644
index 000000000..173af52cb
--- /dev/null
+++ b/tools/drawTools/vtooltriangle.h
@@ -0,0 +1,39 @@
+#ifndef VTOOLTRIANGLE_H
+#define VTOOLTRIANGLE_H
+
+#include "vtoolpoint.h"
+#include "dialogs/dialogtriangle.h"
+
+class VToolTriangle : public VToolPoint{
+ Q_OBJECT
+public:
+ VToolTriangle(VDomDocument *doc, VContainer *data, const qint64 &id, const qint64 &axisP1Id,
+ const qint64 &axisP2Id, const qint64 &firstPointId, const qint64 &secondPointId,
+ 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 qint64 &axisP1Id, const qint64 &axisP2Id, const qint64 &firstPointId,
+ const qint64 &secondPointId, const qreal &mx, const qreal &my,
+ VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data,
+ const Document::Documents &parse, Tool::Sources typeCreation);
+ static QPointF FindPoint(const QPointF axisP1, const QPointF axisP2, const QPointF firstPoint,
+ const QPointF secondPoint);
+public slots:
+ virtual void FullUpdateFromFile();
+ virtual void FullUpdateFromGui(int result);
+protected:
+ virtual void RemoveReferens();
+ virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event );
+ virtual void AddToFile();
+private:
+ Q_DISABLE_COPY(VToolTriangle)
+ qint64 axisP1Id;
+ qint64 axisP2Id;
+ qint64 firstPointId;
+ qint64 secondPointId;
+ QSharedPointer dialogTriangle;
+};
+
+#endif // VTOOLTRIANGLE_H
diff --git a/tools/modelingTools/modelingtools.h b/tools/modelingTools/modelingtools.h
index a40cdf15a..bd61fee59 100644
--- a/tools/modelingTools/modelingtools.h
+++ b/tools/modelingTools/modelingtools.h
@@ -35,5 +35,6 @@
#include "vmodelingspline.h"
#include "vmodelingsplinepath.h"
#include "vmodelingheight.h"
+#include "vmodelingtriangle.h"
#endif // MODELINGTOOLS_H
diff --git a/tools/modelingTools/vmodelingtriangle.cpp b/tools/modelingTools/vmodelingtriangle.cpp
new file mode 100644
index 000000000..e2f722a07
--- /dev/null
+++ b/tools/modelingTools/vmodelingtriangle.cpp
@@ -0,0 +1,127 @@
+#include "vmodelingtriangle.h"
+#include "../drawTools/vtooltriangle.h"
+
+VModelingTriangle::VModelingTriangle(VDomDocument *doc, VContainer *data, const qint64 &id,
+ const qint64 &axisP1Id, const qint64 &axisP2Id,
+ const qint64 &firstPointId, const qint64 &secondPointId,
+ Tool::Sources typeCreation, QGraphicsItem *parent)
+ :VModelingPoint(doc, data, id, parent), axisP1Id(axisP1Id), axisP2Id(axisP2Id),
+ firstPointId(firstPointId), secondPointId(secondPointId),
+ dialogTriangle(QSharedPointer()) {
+ if(typeCreation == Tool::FromGui){
+ AddToFile();
+ }
+}
+
+void VModelingTriangle::setDialog(){
+ Q_ASSERT(!dialogTriangle.isNull());
+ VPointF p = VAbstractTool::data.GetPoint(id);
+ dialogTriangle->setAxisP1Id(axisP1Id, id);
+ dialogTriangle->setAxisP2Id(axisP2Id, id);
+ dialogTriangle->setFirstPointId(firstPointId, id);
+ dialogTriangle->setSecondPointId(secondPointId, id);
+ dialogTriangle->setPointName(p.name());
+}
+
+VModelingTriangle *VModelingTriangle::Create(QSharedPointer &dialog, VDomDocument *doc,
+ VContainer *data){
+ qint64 axisP1Id = dialog->getAxisP1Id();
+ qint64 axisP2Id = dialog->getAxisP2Id();
+ qint64 firstPointId = dialog->getFirstPointId();
+ qint64 secondPointId = dialog->getSecondPointId();
+ QString pointName = dialog->getPointName();
+ return Create(0, pointName, axisP1Id, axisP2Id, firstPointId, secondPointId, 5, 10, doc, data,
+ Document::FullParse, Tool::FromGui);
+
+}
+
+VModelingTriangle *VModelingTriangle::Create(const qint64 _id, const QString &pointName,
+ const qint64 &axisP1Id, const qint64 &axisP2Id,
+ const qint64 &firstPointId, const qint64 &secondPointId,
+ const qreal &mx, const qreal &my, VDomDocument *doc,
+ VContainer *data, const Document::Documents &parse,
+ Tool::Sources typeCreation){
+ VModelingTriangle *tool = 0;
+ VPointF axisP1 = data->GetPoint(axisP1Id);
+ VPointF axisP2 = data->GetPoint(axisP2Id);
+ VPointF firstPoint = data->GetPoint(firstPointId);
+ VPointF secondPoint = data->GetPoint(secondPointId);
+
+ QPointF point = VToolTriangle::FindPoint(axisP1.toQPointF(), axisP2.toQPointF(), firstPoint.toQPointF(),
+ secondPoint.toQPointF());
+ qint64 id = _id;
+ if(typeCreation == Tool::FromGui){
+ id = data->AddPoint(VPointF(point.x(), point.y(), pointName, mx, my));
+ } else {
+ data->UpdatePoint(id, VPointF(point.x(), point.y(), pointName, mx, my));
+ if(parse != Document::FullParse){
+ doc->UpdateToolData(id, data);
+ }
+ }
+ if(parse == Document::FullParse){
+ tool = new VModelingTriangle(doc, data, id, axisP1Id, axisP2Id, firstPointId,
+ secondPointId, typeCreation);
+ doc->AddTool(id, tool);
+ doc->IncrementReferens(axisP1Id);
+ doc->IncrementReferens(axisP2Id);
+ doc->IncrementReferens(firstPointId);
+ doc->IncrementReferens(secondPointId);
+ }
+ return tool;
+}
+
+void VModelingTriangle::FullUpdateFromFile(){
+ QDomElement domElement = doc->elementById(QString().setNum(id));
+ if(domElement.isElement()){
+ axisP1Id = domElement.attribute("axisP1", "").toLongLong();
+ axisP2Id = domElement.attribute("axisP2", "").toLongLong();
+ firstPointId = domElement.attribute("firstPoint", "").toLongLong();
+ secondPointId = domElement.attribute("secondPoint", "").toLongLong();
+ }
+ VModelingPoint::RefreshPointGeometry(VModelingTool::data.GetPoint(id));
+}
+
+void VModelingTriangle::FullUpdateFromGui(int result){
+ if(result == QDialog::Accepted){
+ QDomElement domElement = doc->elementById(QString().setNum(id));
+ if(domElement.isElement()){
+ domElement.setAttribute("name", dialogTriangle->getPointName());
+ domElement.setAttribute("axisP1", QString().setNum(dialogTriangle->getAxisP1Id()));
+ domElement.setAttribute("axisP2", QString().setNum(dialogTriangle->getAxisP2Id()));
+ domElement.setAttribute("firstPoint", QString().setNum(dialogTriangle->getFirstPointId()));
+ domElement.setAttribute("secondPoint", QString().setNum(dialogTriangle->getSecondPointId()));
+ emit FullUpdateTree();
+ }
+
+ }
+ dialogTriangle.clear();
+}
+
+void VModelingTriangle::RemoveReferens(){
+ doc->DecrementReferens(axisP1Id);
+ doc->DecrementReferens(axisP2Id);
+ doc->DecrementReferens(firstPointId);
+ doc->DecrementReferens(secondPointId);
+}
+
+void VModelingTriangle::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){
+ ContextMenu(dialogTriangle, this, event);
+}
+
+void VModelingTriangle::AddToFile(){
+ VPointF point = VAbstractTool::data.GetPoint(id);
+ QDomElement domElement = doc->createElement("point");
+
+ AddAttribute(domElement, "id", id);
+ AddAttribute(domElement, "type", "triangle");
+ AddAttribute(domElement, "name", point.name());
+ AddAttribute(domElement, "mx", toMM(point.mx()));
+ AddAttribute(domElement, "my", toMM(point.my()));
+
+ AddAttribute(domElement, "axisP1", axisP1Id);
+ AddAttribute(domElement, "axisP2", axisP2Id);
+ AddAttribute(domElement, "firstPoint", firstPointId);
+ AddAttribute(domElement, "secondPoint", secondPointId);
+
+ AddToModeling(domElement);
+}
diff --git a/tools/modelingTools/vmodelingtriangle.h b/tools/modelingTools/vmodelingtriangle.h
new file mode 100644
index 000000000..a43b73867
--- /dev/null
+++ b/tools/modelingTools/vmodelingtriangle.h
@@ -0,0 +1,39 @@
+#ifndef VMODELINGTRIANGLE_H
+#define VMODELINGTRIANGLE_H
+
+#include "vmodelingpoint.h"
+#include "../drawTools/vtooltriangle.h"
+#include "dialogs/dialogtriangle.h"
+
+class VModelingTriangle : public VModelingPoint{
+ Q_OBJECT
+public:
+ VModelingTriangle(VDomDocument *doc, VContainer *data, const qint64 &id,
+ const qint64 &axisP1Id, const qint64 &axisP2Id,
+ const qint64 &firstPointId, const qint64 &secondPointId,
+ Tool::Sources typeCreation, QGraphicsItem * parent = 0);
+ virtual void setDialog();
+ static VModelingTriangle* Create(QSharedPointer &dialog, VDomDocument *doc,
+ VContainer *data);
+ static VModelingTriangle* Create(const qint64 _id, const QString &pointName, const qint64 &axisP1Id,
+ const qint64 &axisP2Id, const qint64 &firstPointId,
+ const qint64 &secondPointId, const qreal &mx, const qreal &my,
+ VDomDocument *doc, VContainer *data, const Document::Documents &parse,
+ Tool::Sources typeCreation);
+public slots:
+ virtual void FullUpdateFromFile();
+ virtual void FullUpdateFromGui(int result);
+protected:
+ virtual void RemoveReferens();
+ virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event );
+ virtual void AddToFile();
+private:
+ Q_DISABLE_COPY(VModelingTriangle)
+ qint64 axisP1Id;
+ qint64 axisP2Id;
+ qint64 firstPointId;
+ qint64 secondPointId;
+ QSharedPointer dialogTriangle;
+};
+
+#endif // VMODELINGTRIANGLE_H
diff --git a/tools/vtooldetail.cpp b/tools/vtooldetail.cpp
index 8f113e39b..93c1c8f3d 100644
--- a/tools/vtooldetail.cpp
+++ b/tools/vtooldetail.cpp
@@ -150,6 +150,22 @@ VToolDetail::VToolDetail(VDomDocument *doc, VContainer *data, const qint64 &id,
tool->setParentItem(this);
break;
}
+ case(Tool::Height):{
+ VModelingHeight *tool = qobject_cast(tools->value(detail[i].getId()));
+ Q_ASSERT(tool != 0);
+ connect(tool, &VModelingHeight::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
+ connect(tool, &VModelingHeight::RemoveTool, scene, &VMainGraphicsScene::RemoveTool);
+ tool->setParentItem(this);
+ break;
+ }
+ case(Tool::Triangle):{
+ VModelingTriangle *tool = qobject_cast(tools->value(detail[i].getId()));
+ Q_ASSERT(tool != 0);
+ connect(tool, &VModelingTriangle::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
+ connect(tool, &VModelingTriangle::RemoveTool, scene, &VMainGraphicsScene::RemoveTool);
+ tool->setParentItem(this);
+ break;
+ }
default:
qWarning()<<"Get wrong tool type. Ignore.";
break;
diff --git a/xml/vdomdocument.cpp b/xml/vdomdocument.cpp
index 52e42e7ff..e4d31e700 100644
--- a/xml/vdomdocument.cpp
+++ b/xml/vdomdocument.cpp
@@ -831,6 +831,32 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen
throw excep;
}
}
+ if(type == "triangle"){
+ try{
+ qint64 id = GetParametrId(domElement);
+ QString name = GetParametrString(domElement, "name");
+ qreal mx = toPixel(GetParametrDouble(domElement, "mx"));
+ qreal my = toPixel(GetParametrDouble(domElement, "my"));
+ qint64 axisP1Id = GetParametrLongLong(domElement, "axisP1");
+ qint64 axisP2Id = GetParametrLongLong(domElement, "axisP2");
+ qint64 firstPointId = GetParametrLongLong(domElement, "firstPoint");
+ qint64 secondPointId = GetParametrLongLong(domElement, "secondPoint");
+
+ if(mode == Draw::Calculation){
+ VToolTriangle::Create(id, name, axisP1Id, axisP2Id, firstPointId, secondPointId, mx, my,
+ scene, this, data, parse, Tool::FromFile);
+ } else {
+ VModelingTriangle::Create(id, name, axisP1Id, axisP2Id, firstPointId, secondPointId, mx, my,
+ this, data, parse, Tool::FromFile);
+ }
+ return;
+ }
+ catch(const VExceptionBadId &e){
+ VExceptionObjectError excep(tr("Error creating or updating triangle"), domElement);
+ excep.AddMoreInformation(e.ErrorMessage());
+ throw excep;
+ }
+ }
}
void VDomDocument::ParseLineElement(VMainGraphicsScene *scene, const QDomElement &domElement,