Add tool LineIntersect

This commit is contained in:
dismine 2013-07-31 14:34:39 +03:00
parent f25d3e7f7f
commit 066432c980
30 changed files with 728 additions and 297 deletions

View File

@ -40,7 +40,10 @@ SOURCES += main.cpp\
tools/vtoolnormal.cpp \
dialogs/dialognormal.cpp \
tools/vtoolbisector.cpp \
dialogs/dialogbisector.cpp
dialogs/dialogbisector.cpp \
tools/vtoollinepoint.cpp \
tools/vtoollineintersect.cpp \
dialogs/dialoglineintersect.cpp
HEADERS += mainwindow.h \
widgets/vmaingraphicsscene.h \
@ -71,7 +74,10 @@ HEADERS += mainwindow.h \
tools/vtoolnormal.h \
dialogs/dialognormal.h \
tools/vtoolbisector.h \
dialogs/dialogbisector.h
dialogs/dialogbisector.h \
tools/vtoollinepoint.h \
tools/vtoollineintersect.h \
dialogs/dialoglineintersect.h
FORMS += mainwindow.ui \
dialogs/dialogsinglepoint.ui \
@ -81,7 +87,8 @@ FORMS += mainwindow.ui \
dialogs/dialogalongline.ui \
dialogs/dialogshoulderpoint.ui \
dialogs/dialognormal.ui \
dialogs/dialogbisector.ui
dialogs/dialogbisector.ui \
dialogs/dialoglineintersect.ui
RESOURCES += \
icon.qrc \

View File

@ -7,5 +7,6 @@
<file>cursor/shoulder_cursor.png</file>
<file>cursor/normal_cursor.png</file>
<file>cursor/bisector_cursor.png</file>
<file>cursor/intersect_cursor.png</file>
</qresource>
</RCC>

BIN
cursor/intersect_cursor.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@ -0,0 +1,188 @@
#include "dialoglineintersect.h"
#include "ui_dialoglineintersect.h"
DialogLineIntersect::DialogLineIntersect(const VContainer *data, QWidget *parent) :
DialogTool(data, parent), ui(new Ui::DialogLineIntersect)
{
ui->setupUi(this);
number = 0;
bOk = ui->buttonBox->button(QDialogButtonBox::Ok);
connect(bOk, &QPushButton::clicked, this, &DialogLineIntersect::DialogAccepted);
flagName = false;
flagPoint = true;
QPushButton *bCansel = ui->buttonBox->button(QDialogButtonBox::Cancel);
connect(bCansel, &QPushButton::clicked, this, &DialogLineIntersect::DialogRejected);
FillComboBoxPoints(ui->comboBoxP1Line1);
FillComboBoxPoints(ui->comboBoxP2Line1);
FillComboBoxPoints(ui->comboBoxP1Line2);
FillComboBoxPoints(ui->comboBoxP2Line2);
connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogLineIntersect::NamePointChanged);
}
DialogLineIntersect::~DialogLineIntersect()
{
delete ui;
}
void DialogLineIntersect::ChoosedPoint(qint64 id, Scene::Type type){
if(type == Scene::Point){
VPointF point = data->GetPoint(id);
if(number == 0){
qint32 index = ui->comboBoxP1Line1->findText(point.name());
if ( index != -1 ) { // -1 for not found
ui->comboBoxP1Line1->setCurrentIndex(index);
p1Line1 = id;
number++;
return;
}
}
if(number == 1){
qint32 index = ui->comboBoxP2Line1->findText(point.name());
if ( index != -1 ) { // -1 for not found
ui->comboBoxP2Line1->setCurrentIndex(index);
p2Line1 = id;
number++;
return;
}
}
if(number == 2){
qint32 index = ui->comboBoxP1Line2->findText(point.name());
if ( index != -1 ) { // -1 for not found
ui->comboBoxP1Line2->setCurrentIndex(index);
p1Line2 = id;
number++;
return;
}
}
if(number == 3){
qint32 index = ui->comboBoxP2Line2->findText(point.name());
if ( index != -1 ) { // -1 for not found
ui->comboBoxP2Line2->setCurrentIndex(index);
p2Line2 = id;
number = 0;
}
if(!isInitialized){
flagPoint = CheckIntersecion();
CheckState();
this->show();
connect(ui->comboBoxP1Line1,
static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
&DialogLineIntersect::P1Line1Changed);
connect(ui->comboBoxP2Line1,
static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
&DialogLineIntersect::P2Line1Changed);
connect(ui->comboBoxP1Line2,
static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
&DialogLineIntersect::P1Line2Changed);
connect(ui->comboBoxP2Line2,
static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
&DialogLineIntersect::P2Line2Changed);
}
}
}
}
void DialogLineIntersect::DialogAccepted(){
pointName = ui->lineEditNamePoint->text();
qint32 index = ui->comboBoxP1Line1->currentIndex();
p1Line1 = qvariant_cast<qint64>(ui->comboBoxP1Line1->itemData(index));
index = ui->comboBoxP2Line1->currentIndex();
p2Line1 = qvariant_cast<qint64>(ui->comboBoxP2Line1->itemData(index));
index = ui->comboBoxP1Line2->currentIndex();
p1Line2 = qvariant_cast<qint64>(ui->comboBoxP1Line2->itemData(index));
index = ui->comboBoxP2Line2->currentIndex();
p2Line2 = qvariant_cast<qint64>(ui->comboBoxP2Line2->itemData(index));
emit DialogClosed(QDialog::Accepted);
}
void DialogLineIntersect::P1Line1Changed( int index){
p1Line1 = qvariant_cast<qint64>(ui->comboBoxP1Line1->itemData(index));
flagPoint = CheckIntersecion();
CheckState();
}
void DialogLineIntersect::P2Line1Changed(int index){
p2Line1 = qvariant_cast<qint64>(ui->comboBoxP2Line1->itemData(index));
flagPoint = CheckIntersecion();
CheckState();
}
void DialogLineIntersect::P1Line2Changed(int index){
p1Line2 = qvariant_cast<qint64>(ui->comboBoxP1Line2->itemData(index));
flagPoint = CheckIntersecion();
CheckState();
}
void DialogLineIntersect::P2Line2Changed(int index){
p2Line2 = qvariant_cast<qint64>(ui->comboBoxP2Line2->itemData(index));
flagPoint = CheckIntersecion();
CheckState();
}
void DialogLineIntersect::CheckState(){
Q_CHECK_PTR(bOk);
bOk->setEnabled(flagName & flagPoint);
}
bool DialogLineIntersect::CheckIntersecion(){
VPointF p1L1 = data->GetPoint(p1Line1);
VPointF p2L1 = data->GetPoint(p2Line1);
VPointF p1L2 = data->GetPoint(p1Line2);
VPointF p2L2 = data->GetPoint(p2Line2);
QLineF line1(p1L1, p2L1);
QLineF line2(p1L2, p2L2);
QPointF fPoint;
QLineF::IntersectType intersect = line1.intersect(line2, &fPoint);
if(intersect == QLineF::UnboundedIntersection || intersect == QLineF::BoundedIntersection){
return true;
} else {
return false;
}
}
qint64 DialogLineIntersect::getP2Line2() const{
return p2Line2;
}
void DialogLineIntersect::setP2Line2(const qint64 &value){
p2Line2 = value;
ChangeCurrentData(ui->comboBoxP2Line2, value);
}
qint64 DialogLineIntersect::getP1Line2() const{
return p1Line2;
}
void DialogLineIntersect::setP1Line2(const qint64 &value){
p1Line2 = value;
ChangeCurrentData(ui->comboBoxP1Line2, value);
}
qint64 DialogLineIntersect::getP2Line1() const{
return p2Line1;
}
void DialogLineIntersect::setP2Line1(const qint64 &value){
p2Line1 = value;
ChangeCurrentData(ui->comboBoxP2Line1, value);
}
qint64 DialogLineIntersect::getP1Line1() const{
return p1Line1;
}
void DialogLineIntersect::setP1Line1(const qint64 &value){
p1Line1 = value;
ChangeCurrentData(ui->comboBoxP1Line1, value);
}
QString DialogLineIntersect::getPointName() const{
return pointName;
}
void DialogLineIntersect::setPointName(const QString &value){
pointName = value;
ui->lineEditNamePoint->setText(pointName);
}

View File

@ -0,0 +1,46 @@
#ifndef DIALOGLINEINTERSECT_H
#define DIALOGLINEINTERSECT_H
#include "dialogtool.h"
namespace Ui {
class DialogLineIntersect;
}
class DialogLineIntersect : public DialogTool
{
Q_OBJECT
public:
explicit DialogLineIntersect(const VContainer *data, QWidget *parent = 0);
~DialogLineIntersect();
qint64 getP1Line1() const;
void setP1Line1(const qint64 &value);
qint64 getP2Line1() const;
void setP2Line1(const qint64 &value);
qint64 getP1Line2() const;
void setP1Line2(const qint64 &value);
qint64 getP2Line2() const;
void setP2Line2(const qint64 &value);
QString getPointName() const;
void setPointName(const QString &value);
public slots:
virtual void ChoosedPoint(qint64 id, Scene::Type type);
virtual void DialogAccepted();
void P1Line1Changed( int index);
void P2Line1Changed( int index);
void P1Line2Changed( int index);
void P2Line2Changed( int index);
private:
Ui::DialogLineIntersect *ui;
qint32 number;
QString pointName;
qint64 p1Line1;
qint64 p2Line1;
qint64 p1Line2;
qint64 p2Line2;
bool flagPoint;
virtual void CheckState();
bool CheckIntersecion();
};
#endif // DIALOGLINEINTERSECT_H

View File

@ -0,0 +1,158 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DialogLineIntersect</class>
<widget class="QDialog" name="DialogLineIntersect">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>366</width>
<height>196</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="label_4">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Ім'я нової точки</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEditNamePoint"/>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Перша лінія</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="label_3">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Перша точка</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBoxP1Line1"/>
</item>
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>Друга точка</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBoxP2Line1"/>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Друга лінія</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QLabel" name="label_6">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Перша точка</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBoxP1Line2"/>
</item>
<item>
<widget class="QLabel" name="label_7">
<property name="text">
<string>Друга точка</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBoxP2Line2"/>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>DialogLineIntersect</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>DialogLineIntersect</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -64,7 +64,7 @@ protected:
void showEvent( QShowEvent *event );
void FillComboBoxPoints(QComboBox *box)const;
void FillComboBoxTypeLine(QComboBox *box) const;
void CheckState();
virtual void CheckState();
QString GetTypeLine(const QComboBox *box)const;
void ShowBase();
void ShowStandartTable();

View File

@ -24,5 +24,6 @@
<file>icon/32x32/shoulder.png</file>
<file>icon/32x32/normal.png</file>
<file>icon/32x32/bisector.png</file>
<file>icon/32x32/intersect.png</file>
</qresource>
</RCC>

BIN
icon/32x32/intersect.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 603 B

View File

@ -17,6 +17,7 @@
#include "tools/vtoolshoulderpoint.h"
#include "tools/vtoolnormal.h"
#include "tools/vtoolbisector.h"
#include "tools/vtoollineintersect.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent), ui(new Ui::MainWindow)
@ -58,6 +59,8 @@ MainWindow::MainWindow(QWidget *parent) :
&MainWindow::ToolNormal);
connect(ui->toolButtonBisector, &QToolButton::clicked, this,
&MainWindow::ToolBisector);
connect(ui->toolButtonLineIntersect, &QToolButton::clicked, this,
&MainWindow::ToolLineIntersect);
data = new VContainer;
CreateManTableIGroup ();
@ -434,6 +437,57 @@ void MainWindow::ClosedDialogBisector(int result){
ArrowTool();
}
void MainWindow::ToolLineIntersect(bool checked){
if(checked){
CanselTool();
tool = Tools::LineIntersectTool;
QPixmap pixmap(":/cursor/intersect_cursor.png");
QCursor cur(pixmap, 2, 3);
ui->graphicsView->setCursor(cur);
helpLabel->setText("Виберіть точки.");
dialogLineIntersect = new DialogLineIntersect(data, this);
connect(scene, &VMainGraphicsScene::ChoosedObject, dialogLineIntersect,
&DialogLineIntersect::ChoosedPoint);
connect(dialogLineIntersect, &DialogLineIntersect::DialogClosed, this,
&MainWindow::ClosedDialogLineIntersect);
} else {
ui->toolButtonLineIntersect->setChecked(true);
}
}
void MainWindow::ClosedDialogLineIntersect(int result){
if(result == QDialog::Accepted){
qint64 p1Line1Id = dialogLineIntersect->getP1Line1();
qint64 p2Line1Id = dialogLineIntersect->getP2Line1();
qint64 p1Line2Id = dialogLineIntersect->getP1Line2();
qint64 p2Line2Id = dialogLineIntersect->getP2Line2();
QString pointName = dialogLineIntersect->getPointName();
VPointF p1Line1 = data->GetPoint(p1Line1Id);
VPointF p2Line1 = data->GetPoint(p2Line1Id);
VPointF p1Line2 = data->GetPoint(p1Line2Id);
VPointF p2Line2 = data->GetPoint(p2Line2Id);
QLineF line1(p1Line1, p2Line1);
QLineF line2(p1Line2, p2Line2);
QPointF fPoint;
QLineF::IntersectType intersect = line1.intersect(line2, &fPoint);
if(intersect == QLineF::UnboundedIntersection || intersect == QLineF::BoundedIntersection){
qint64 id = data->AddPoint(VPointF(fPoint.x(), fPoint.y(), pointName, 5, 10));
data->AddLine(p1Line1Id, id);
data->AddLine(id, p2Line1Id);
data->AddLine(p1Line2Id, id);
data->AddLine(id, p2Line2Id);
VToolLineIntersect *point = new VToolLineIntersect(doc, data, id, p1Line1Id,
p2Line1Id, p1Line2Id,
p2Line2Id, Tool::FromFile);
scene->addItem(point);
connect(point, &VToolLineIntersect::ChoosedPoint, scene, &VMainGraphicsScene::ChoosedItem);
}
}
ArrowTool();
}
void MainWindow::showEvent( QShowEvent *event ){
QMainWindow::showEvent( event );
if( event->spontaneous() ){
@ -578,6 +632,12 @@ void MainWindow::CanselTool(){
scene->setFocus(Qt::OtherFocusReason);
scene->clearSelection();
break;
case Tools::LineIntersectTool:
delete dialogLineIntersect;
ui->toolButtonLineIntersect->setChecked(false);
scene->setFocus(Qt::OtherFocusReason);
scene->clearSelection();
break;
}
}
@ -839,6 +899,7 @@ void MainWindow::SetEnableTool(bool enable){
ui->toolButtonShoulderPoint->setEnabled(enable);
ui->toolButtonNormal->setEnabled(enable);
ui->toolButtonBisector->setEnabled(enable);
ui->toolButtonLineIntersect->setEnabled(enable);
}
MainWindow::~MainWindow(){

View File

@ -16,6 +16,7 @@
#include "dialogs/dialogendline.h"
#include "dialogs/dialognormal.h"
#include "dialogs/dialogbisector.h"
#include "dialogs/dialoglineintersect.h"
#include "tools/vtoolsimplepoint.h"
#include "xml/vdomdocument.h"
#include "container/vcontainer.h"
@ -34,7 +35,8 @@ namespace Tools{
AlongLineTool,
ShoulderPointTool,
NormalTool,
BisectorTool
BisectorTool,
LineIntersectTool
};
}
@ -75,6 +77,8 @@ public slots:
void ClosedDialogNormal(int result);
void ToolBisector(bool checked);
void ClosedDialogBisector(int result);
void ToolLineIntersect(bool checked);
void ClosedDialogLineIntersect(int result);
protected:
virtual void keyPressEvent ( QKeyEvent * event );
virtual void showEvent( QShowEvent *event );
@ -93,6 +97,7 @@ private:
DialogShoulderPoint *dialogShoulderPoint;
DialogNormal *dialogNormal;
DialogBisector *dialogBisector;
DialogLineIntersect *dialogLineIntersect;
VDomDocument *doc;
VContainer *data;
QComboBox *comboBoxDraws;

View File

@ -57,7 +57,7 @@
</sizepolicy>
</property>
<property name="currentIndex">
<number>0</number>
<number>1</number>
</property>
<widget class="QWidget" name="page">
<property name="geometry">
@ -230,7 +230,7 @@
<x>0</x>
<y>0</y>
<width>154</width>
<height>50</height>
<height>58</height>
</rect>
</property>
<property name="sizePolicy">
@ -257,8 +257,31 @@
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
<width>32</width>
<height>32</height>
</size>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QToolButton" name="toolButtonLineIntersect">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="icon.qrc">
<normaloff>:/icon/32x32/intersect.png</normaloff>:/icon/32x32/intersect.png</iconset>
</property>
<property name="iconSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
<property name="checkable">

View File

@ -7,68 +7,24 @@
VToolAlongLine::VToolAlongLine(VDomDocument *doc, VContainer *data, qint64 id, const QString &formula,
const qint64 &firstPointId, const qint64 &secondPointId,
const QString &typeLine, Tool::Enum typeCreation,
QGraphicsItem *parent):VToolPoint(doc, data, id, parent){
this->typeLine = typeLine;
this->formula = formula;
this->firstPointId = firstPointId;
QGraphicsItem *parent):
VToolLinePoint(doc, data, id, typeLine, formula, firstPointId, 0, parent){
this->secondPointId = secondPointId;
//Лінія, якщо потрібно.
VPointF firstPoint = data->GetPoint(firstPointId);
VPointF secondPoint = data->GetPoint(secondPointId);
QLineF line = QLineF(firstPoint.toQPointF(), secondPoint.toQPointF());
Calculator cal(data);
QString errorMsg;
qreal result = cal.eval(formula, &errorMsg);
if(errorMsg.isEmpty()){
line.setLength(result*PrintDPI/25.4);
mainLine = new QGraphicsLineItem(line, this);
mainLine->setFlag(QGraphicsItem::ItemStacksBehindParent, true);
if(typeLine == "none"){
mainLine->setVisible(false);
} else {
mainLine->setVisible(true);
}
if(typeCreation == Tool::FromGui){
AddToFile();
}
}
}
void VToolAlongLine::FullUpdateFromFile(){
QString name;
qreal mx, my;
QDomElement domElement = doc->elementById(QString().setNum(id));
if(domElement.isElement()){
name = domElement.attribute("name", "");
mx = domElement.attribute("mx", "").toDouble()*PrintDPI/25.4;
my = domElement.attribute("my", "").toDouble()*PrintDPI/25.4;
typeLine = domElement.attribute("typeLine", "");
formula = domElement.attribute("length", "");
firstPointId = domElement.attribute("firstPoint", "").toLongLong();
basePointId = domElement.attribute("firstPoint", "").toLongLong();
secondPointId = domElement.attribute("secondPoint", "").toLongLong();
}
VPointF point = VAbstractTool::data->GetPoint(id);
RefreshGeometry(name, point.x(), point.y(), mx, my);
VPointF firstPoint = VAbstractTool::data->GetPoint(firstPointId);
VPointF secondPoint = VAbstractTool::data->GetPoint(secondPointId);
mainLine->setLine(QLineF(firstPoint.toQPointF(), secondPoint.toQPointF()));
if(typeLine == "none"){
mainLine->setVisible(false);
} else {
mainLine->setVisible(true);
}
}
void VToolAlongLine::ChangedActivDraw(const QString newName){
if(nameActivDraw == newName){
mainLine->setPen(QPen(Qt::black, widthHairLine));
VToolPoint::ChangedActivDraw(newName);
} else {
mainLine->setPen(QPen(Qt::gray, widthHairLine));
VToolPoint::ChangedActivDraw(newName);
}
RefreshGeometry();
}
void VToolAlongLine::FullUpdateFromGui(int result){
@ -106,7 +62,7 @@ void VToolAlongLine::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){
dialogAlongLine->setTypeLine(typeLine);
dialogAlongLine->setFormula(formula);
dialogAlongLine->setFirstPointId(firstPointId);
dialogAlongLine->setFirstPointId(basePointId);
dialogAlongLine->setSecondPointId(secondPointId);
dialogAlongLine->setPointName(p.name());
@ -127,7 +83,7 @@ void VToolAlongLine::AddToFile(){
AddAttribute(domElement, "typeLine", typeLine);
AddAttribute(domElement, "length", formula);
AddAttribute(domElement, "firstPoint", firstPointId);
AddAttribute(domElement, "firstPoint", basePointId);
AddAttribute(domElement, "secondPoint", secondPointId);
AddToCalculation(domElement);

View File

@ -1,10 +1,10 @@
#ifndef VTOOLALONGLINE_H
#define VTOOLALONGLINE_H
#include "vtoolpoint.h"
#include "vtoollinepoint.h"
#include "../dialogs/dialogalongline.h"
class VToolAlongLine : public VToolPoint
class VToolAlongLine : public VToolLinePoint
{
Q_OBJECT
public:
@ -13,17 +13,12 @@ public:
Tool::Enum typeCreation, QGraphicsItem * parent = 0);
public slots:
virtual void FullUpdateFromFile();
virtual void ChangedActivDraw(const QString newName);
virtual void FullUpdateFromGui(int result);
protected:
virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event );
virtual void AddToFile();
private:
QString typeLine;
QString formula;
qint64 firstPointId;
qint64 secondPointId;
QGraphicsLineItem *mainLine;
QSharedPointer<DialogAlongLine> dialogAlongLine;
};

View File

@ -4,25 +4,10 @@
VToolBisector::VToolBisector(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &typeLine,
const QString &formula, const qint64 &firstPointId, const qint64 &secondPointId,
const qint64 &thirdPointId, Tool::Enum typeCreation, QGraphicsItem *parent):
VToolPoint(doc, data, id, parent){
this->typeLine = typeLine;
this->formula = formula;
VToolLinePoint(doc, data, id, typeLine, formula, secondPointId, 0, parent){
this->firstPointId = firstPointId;
this->secondPointId = secondPointId;
this->thirdPointId = thirdPointId;
//Лінія, що з'єднує дві точки
VPointF basePoint = data->GetPoint(secondPointId);
VPointF point = data->GetPoint(id);
mainLine = new QGraphicsLineItem(QLineF(basePoint.toQPointF(), point.toQPointF()), this);
mainLine->setPen(QPen(Qt::black, widthHairLine));
mainLine->setFlag(QGraphicsItem::ItemStacksBehindParent, true);
if(typeLine == "none"){
mainLine->setVisible(false);
} else {
mainLine->setVisible(true);
}
if(typeCreation == Tool::FromGui){
AddToFile();
}
@ -42,28 +27,15 @@ QPointF VToolBisector::FindPoint(const QPointF &firstPoint, const QPointF &secon
}
void VToolBisector::FullUpdateFromFile(){
QString name;
qreal mx, my;
QDomElement domElement = doc->elementById(QString().setNum(id));
if(domElement.isElement()){
name = domElement.attribute("name", "");
mx = domElement.attribute("mx", "").toDouble()*PrintDPI/25.4;
my = domElement.attribute("my", "").toDouble()*PrintDPI/25.4;
typeLine = domElement.attribute("typeLine", "");
formula = domElement.attribute("length", "");
firstPointId = domElement.attribute("firstPoint", "").toLongLong();
secondPointId = domElement.attribute("secondPoint", "").toLongLong();
basePointId = domElement.attribute("secondPoint", "").toLongLong();
thirdPointId = domElement.attribute("thirdPoint", "").toLongLong();
}
VPointF point = VAbstractTool::data->GetPoint(id);
RefreshGeometry(name, point.x(), point.y(), mx, my);
VPointF basePoint = VAbstractTool::data->GetPoint(secondPointId);
mainLine->setLine(QLineF(basePoint.toQPointF(), point.toQPointF()));
if(typeLine == "none"){
mainLine->setVisible(false);
} else {
mainLine->setVisible(true);
}
RefreshGeometry();
}
void VToolBisector::FullUpdateFromGui(int result){
@ -82,16 +54,6 @@ void VToolBisector::FullUpdateFromGui(int result){
dialogBisector.clear();
}
void VToolBisector::ChangedActivDraw(const QString newName){
if(nameActivDraw == newName){
mainLine->setPen(QPen(Qt::black, widthHairLine));
VToolPoint::ChangedActivDraw(newName);
} else {
mainLine->setPen(QPen(Qt::gray, widthHairLine));
VToolPoint::ChangedActivDraw(newName);
}
}
void VToolBisector::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){
if(!ignoreContextMenuEvent){
QMenu menu;
@ -112,7 +74,7 @@ void VToolBisector::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){
dialogBisector->setTypeLine(typeLine);
dialogBisector->setFormula(formula);
dialogBisector->setFirstPointId(firstPointId);
dialogBisector->setSecondPointId(secondPointId);
dialogBisector->setSecondPointId(basePointId);
dialogBisector->setThirdPointId(thirdPointId);
dialogBisector->setPointName(p.name());
@ -134,7 +96,7 @@ void VToolBisector::AddToFile(){
AddAttribute(domElement, "typeLine", typeLine);
AddAttribute(domElement, "length", formula);
AddAttribute(domElement, "firstPoint", firstPointId);
AddAttribute(domElement, "secondPoint", secondPointId);
AddAttribute(domElement, "secondPoint", basePointId);
AddAttribute(domElement, "thirdPoint", thirdPointId);
AddToCalculation(domElement);

View File

@ -3,31 +3,26 @@
#include <QSharedPointer>
#include "vtoolpoint.h"
#include "vtoollinepoint.h"
#include "../dialogs/dialogbisector.h"
class VToolBisector : public VToolPoint
class VToolBisector : public VToolLinePoint
{
public:
VToolBisector(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &typeLine,
const QString &formula, const qint64 &firstPointId, const qint64 &secondPointId,
const qint64 &thirdPointId,Tool::Enum typeCreation, QGraphicsItem * parent = 0);
const qint64 &thirdPointId, Tool::Enum typeCreation, QGraphicsItem * parent = 0);
static QPointF FindPoint(const QPointF &firstPoint, const QPointF &secondPoint,
const QPointF &thirdPoint, const qreal& length);
public slots:
virtual void FullUpdateFromFile();
virtual void FullUpdateFromGui(int result);
virtual void ChangedActivDraw(const QString newName);
protected:
virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event );
virtual void AddToFile();
private:
QString typeLine;
QString formula;
qint64 firstPointId;
qint64 secondPointId;
qint64 thirdPointId;
QGraphicsLineItem *mainLine;
QSharedPointer<DialogBisector> dialogBisector;
};

View File

@ -4,26 +4,10 @@
#include "../widgets/vmaingraphicsscene.h"
VToolEndLine::VToolEndLine(VDomDocument *doc, VContainer *data, const qint64 &id,
const QString &typeLine, const QString &formula, const qint32 &angle,
const qint64 &basePointId, Tool::Enum typeCreation,
QGraphicsItem *parent):VToolPoint(doc, data, id, parent){
this->typeLine = typeLine;
this->formula = formula;
this->angle = angle;
this->basePointId = basePointId;
//Лінія, що з'єднує дві точки
VPointF basePoint = data->GetPoint(basePointId);
VPointF point = data->GetPoint(id);
mainLine = new QGraphicsLineItem(QLineF(basePoint.toQPointF(), point.toQPointF()), this);
mainLine->setPen(QPen(Qt::black, widthHairLine));
mainLine->setFlag(QGraphicsItem::ItemStacksBehindParent, true);
if(typeLine == "none"){
mainLine->setVisible(false);
} else {
mainLine->setVisible(true);
}
VToolEndLine::VToolEndLine(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &typeLine,
const QString &formula, const qint32 &angle, const qint64 &basePointId,
Tool::Enum typeCreation, QGraphicsItem *parent):
VToolLinePoint(doc, data, id, typeLine, formula, basePointId, angle, parent){
if(typeCreation == Tool::FromGui){
AddToFile();
@ -31,27 +15,14 @@ VToolEndLine::VToolEndLine(VDomDocument *doc, VContainer *data, const qint64 &id
}
void VToolEndLine::FullUpdateFromFile(){
QString name;
qreal mx, my;
QDomElement domElement = doc->elementById(QString().setNum(id));
if(domElement.isElement()){
name = domElement.attribute("name", "");
mx = domElement.attribute("mx", "").toDouble()*PrintDPI/25.4;
my = domElement.attribute("my", "").toDouble()*PrintDPI/25.4;
typeLine = domElement.attribute("typeLine", "");
formula = domElement.attribute("length", "");
basePointId = domElement.attribute("basePoint", "").toLongLong();
angle = domElement.attribute("angle", "").toInt();
}
VPointF point = VAbstractTool::data->GetPoint(id);
RefreshGeometry(name, point.x(), point.y(), mx, my);
VPointF basePoint = VAbstractTool::data->GetPoint(basePointId);
mainLine->setLine(QLineF(basePoint.toQPointF(), point.toQPointF()));
if(typeLine == "none"){
mainLine->setVisible(false);
} else {
mainLine->setVisible(true);
}
RefreshGeometry();
}
void VToolEndLine::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){
@ -96,16 +67,6 @@ void VToolEndLine::FullUpdateFromGui(int result){
dialogEndLine.clear();
}
void VToolEndLine::ChangedActivDraw(const QString newName){
if(nameActivDraw == newName){
mainLine->setPen(QPen(Qt::black, widthHairLine));
VToolPoint::ChangedActivDraw(newName);
} else {
mainLine->setPen(QPen(Qt::gray, widthHairLine));
VToolPoint::ChangedActivDraw(newName);
}
}
void VToolEndLine::AddToFile(){
VPointF point = VAbstractTool::data->GetPoint(id);
QDomElement domElement = doc->createElement("point");

View File

@ -3,10 +3,10 @@
#include <QSharedPointer>
#include "vtoolpoint.h"
#include "vtoollinepoint.h"
#include "../dialogs/dialogendline.h"
class VToolEndLine : public VToolPoint
class VToolEndLine : public VToolLinePoint
{
Q_OBJECT
public:
@ -17,16 +17,10 @@ public:
public slots:
virtual void FullUpdateFromFile();
virtual void FullUpdateFromGui(int result);
virtual void ChangedActivDraw(const QString newName);
protected:
virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event );
virtual void AddToFile();
private:
QString typeLine;
QString formula;
qint32 angle;
qint64 basePointId;
QGraphicsLineItem *mainLine;
QSharedPointer<DialogEndLine> dialogEndLine;
};

View File

@ -0,0 +1,85 @@
#include "vtoollineintersect.h"
#include <QMenu>
VToolLineIntersect::VToolLineIntersect(VDomDocument *doc, VContainer *data, const qint64 &id,
const qint64 &p1Line1, const qint64 &p2Line1, const qint64 &p1Line2,
const qint64 &p2Line2, Tool::Enum typeCreation, QGraphicsItem *parent):
VToolPoint(doc, data, id, parent){
this->p1Line1 = p1Line1;
this->p2Line1 = p2Line1;
this->p1Line2 = p1Line2;
this->p2Line2 = p2Line2;
if(typeCreation == Tool::FromGui){
AddToFile();
}
}
void VToolLineIntersect::FullUpdateFromFile(){
QDomElement domElement = doc->elementById(QString().setNum(id));
if(domElement.isElement()){
p1Line1 = domElement.attribute("p1Line1", "").toLongLong();
p2Line1 = domElement.attribute("p2Line1", "").toLongLong();
p1Line2 = domElement.attribute("p1Line2", "").toLongLong();
p2Line2 = domElement.attribute("p2Line2", "").toLongLong();
}
RefreshGeometry();
}
void VToolLineIntersect::FullUpdateFromGui(int result){
if(result == QDialog::Accepted){
QDomElement domElement = doc->elementById(QString().setNum(id));
if(domElement.isElement()){
domElement.setAttribute("name", dialogLineIntersect->getPointName());
domElement.setAttribute("p1Line1", QString().setNum(dialogLineIntersect->getP1Line1()));
domElement.setAttribute("p2Line1", QString().setNum(dialogLineIntersect->getP2Line1()));
domElement.setAttribute("p1Line2", QString().setNum(dialogLineIntersect->getP1Line2()));
domElement.setAttribute("p2Line2", QString().setNum(dialogLineIntersect->getP2Line2()));
emit FullUpdateTree();
}
}
dialogLineIntersect.clear();
}
void VToolLineIntersect::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){
if(!ignoreContextMenuEvent){
QMenu menu;
QAction *actionOption = menu.addAction("Властивості");
QAction *selectedAction = menu.exec(event->screenPos());
if(selectedAction == actionOption){
dialogLineIntersect = QSharedPointer<DialogLineIntersect>(new DialogLineIntersect(VAbstractTool::data));
connect(qobject_cast< VMainGraphicsScene * >(this->scene()), &VMainGraphicsScene::ChoosedObject,
dialogLineIntersect.data(), &DialogLineIntersect::ChoosedPoint);
connect(dialogLineIntersect.data(), &DialogLineIntersect::DialogClosed, this,
&VToolLineIntersect::FullUpdateFromGui);
VPointF p = VAbstractTool::data->GetPoint(id);
dialogLineIntersect->setP1Line1(p1Line1);
dialogLineIntersect->setP2Line1(p2Line1);
dialogLineIntersect->setP1Line2(p1Line2);
dialogLineIntersect->setP2Line2(p2Line2);
dialogLineIntersect->setPointName(p.name());
dialogLineIntersect->show();
}
}
}
void VToolLineIntersect::AddToFile(){
VPointF point = VAbstractTool::data->GetPoint(id);
QDomElement domElement = doc->createElement("point");
AddAttribute(domElement, "id", id);
AddAttribute(domElement, "type", "lineIntersect");
AddAttribute(domElement, "name", point.name());
AddAttribute(domElement, "mx", point.mx()/PrintDPI*25.4);
AddAttribute(domElement, "my", point.my()/PrintDPI*25.4);
AddAttribute(domElement, "p1Line1", p1Line1);
AddAttribute(domElement, "p2Line1", p2Line1);
AddAttribute(domElement, "p1Line2", p1Line2);
AddAttribute(domElement, "p2Line2", p2Line2);
AddToCalculation(domElement);
}

View File

@ -0,0 +1,29 @@
#ifndef VTOOLLINEINTERSECT_H
#define VTOOLLINEINTERSECT_H
#include "vtoolpoint.h"
#include "../dialogs/dialoglineintersect.h"
class VToolLineIntersect:public VToolPoint
{
public:
VToolLineIntersect(VDomDocument *doc, VContainer *data,
const qint64 &id, const qint64 &p1Line1,
const qint64 &p2Line1, const qint64 &p1Line2,
const qint64 &p2Line2, Tool::Enum typeCreation,
QGraphicsItem * parent = 0);
public slots:
virtual void FullUpdateFromFile();
virtual void FullUpdateFromGui(int result);
protected:
virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event );
virtual void AddToFile();
private:
qint64 p1Line1;
qint64 p2Line1;
qint64 p1Line2;
qint64 p2Line2;
QSharedPointer<DialogLineIntersect> dialogLineIntersect;
};
#endif // VTOOLLINEINTERSECT_H

View File

@ -1,16 +1,17 @@
#include "vtoollinepoint.h"
VToolLinePoint::VToolLinePoint(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &typeLine,
const QString &formula, const qint64 &pointId, const qint32 &angle,
const QString &formula, const qint64 &basePointId, const qint32 &angle,
QGraphicsItem *parent):VToolPoint(doc, data, id, parent){
this->typeLine = typeLine;
this->formula = formula;
this->angle = angle;
this->basePointId = basePointId;
//Лінія, що з'єднує дві точки
VPointF firstPoint = data->GetPoint(pointId);
VPointF point = data->GetPoint(id);
mainLine = new QGraphicsLineItem(QLineF(firstPoint.toQPointF(), point.toQPointF()), this);
VPointF point1 = data->GetPoint(basePointId);
VPointF point2 = data->GetPoint(id);
mainLine = new QGraphicsLineItem(QLineF(point1.toQPointF(), point2.toQPointF()), this);
mainLine->setPen(QPen(Qt::black, widthHairLine));
mainLine->setFlag(QGraphicsItem::ItemStacksBehindParent, true);
if(typeLine == "none"){
@ -29,3 +30,15 @@ void VToolLinePoint::ChangedActivDraw(const QString newName){
VToolPoint::ChangedActivDraw(newName);
}
}
void VToolLinePoint::RefreshGeometry(){
VToolPoint::RefreshGeometry();
VPointF point = VAbstractTool::data->GetPoint(id);
VPointF basePoint = VAbstractTool::data->GetPoint(basePointId);
mainLine->setLine(QLineF(basePoint.toQPointF(), point.toQPointF()));
if(typeLine == "none"){
mainLine->setVisible(false);
} else {
mainLine->setVisible(true);
}
}

View File

@ -8,13 +8,15 @@ class VToolLinePoint : public VToolPoint
public:
VToolLinePoint(VDomDocument *doc, VContainer *data, const qint64 &id,
const QString &typeLine, const QString &formula,
const qint64 &pointId, const qint32 &angle, QGraphicsItem * parent = 0);
const qint64 &basePointId, const qint32 &angle, QGraphicsItem * parent = 0);
public slots:
virtual void ChangedActivDraw(const QString newName);
virtual void RefreshGeometry();
protected:
QString typeLine;
QString formula;
qint32 angle;
qint64 basePointId;
QGraphicsLineItem *mainLine;
};

View File

@ -4,25 +4,9 @@
VToolNormal::VToolNormal(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &typeLine,
const QString &formula, const qint32 &angle, const qint64 &firstPointId,
const qint64 &secondPointId, Tool::Enum typeCreation, QGraphicsItem *parent):
VToolPoint(doc, data, id, parent){
this->typeLine = typeLine;
this->formula = formula;
this->angle = angle;
this->firstPointId = firstPointId;
VToolLinePoint(doc, data, id, typeLine, formula, firstPointId, angle, parent){
this->secondPointId = secondPointId;
//Лінія, що з'єднує дві точки
VPointF firstPoint = data->GetPoint(firstPointId);
VPointF point = data->GetPoint(id);
mainLine = new QGraphicsLineItem(QLineF(firstPoint.toQPointF(), point.toQPointF()), this);
mainLine->setPen(QPen(Qt::black, widthHairLine));
mainLine->setFlag(QGraphicsItem::ItemStacksBehindParent, true);
if(typeLine == "none"){
mainLine->setVisible(false);
} else {
mainLine->setVisible(true);
}
if(typeCreation == Tool::FromGui){
AddToFile();
}
@ -39,28 +23,15 @@ QPointF VToolNormal::FindPoint(const QPointF &firstPoint, const QPointF &secondP
}
void VToolNormal::FullUpdateFromFile(){
QString name;
qreal mx, my;
QDomElement domElement = doc->elementById(QString().setNum(id));
if(domElement.isElement()){
name = domElement.attribute("name", "");
mx = domElement.attribute("mx", "").toDouble()*PrintDPI/25.4;
my = domElement.attribute("my", "").toDouble()*PrintDPI/25.4;
typeLine = domElement.attribute("typeLine", "");
formula = domElement.attribute("length", "");
firstPointId = domElement.attribute("firstPoint", "").toLongLong();
basePointId = domElement.attribute("firstPoint", "").toLongLong();
secondPointId = domElement.attribute("secondPoint", "").toLongLong();
angle = domElement.attribute("angle", "").toInt();
}
VPointF point = VAbstractTool::data->GetPoint(id);
RefreshGeometry(name, point.x(), point.y(), mx, my);
VPointF firstPoint = VAbstractTool::data->GetPoint(firstPointId);
mainLine->setLine(QLineF(firstPoint.toQPointF(), point.toQPointF()));
if(typeLine == "none"){
mainLine->setVisible(false);
} else {
mainLine->setVisible(true);
}
RefreshGeometry();
}
void VToolNormal::FullUpdateFromGui(int result){
@ -79,16 +50,6 @@ void VToolNormal::FullUpdateFromGui(int result){
dialogNormal.clear();
}
void VToolNormal::ChangedActivDraw(const QString newName){
if(nameActivDraw == newName){
mainLine->setPen(QPen(Qt::black, widthHairLine));
VToolPoint::ChangedActivDraw(newName);
} else {
mainLine->setPen(QPen(Qt::gray, widthHairLine));
VToolPoint::ChangedActivDraw(newName);
}
}
void VToolNormal::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){
if(!ignoreContextMenuEvent){
QMenu menu;
@ -108,7 +69,7 @@ void VToolNormal::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){
dialogNormal->setTypeLine(typeLine);
dialogNormal->setFormula(formula);
dialogNormal->setAngle(angle);
dialogNormal->setFirstPointId(firstPointId);
dialogNormal->setFirstPointId(basePointId);
dialogNormal->setSecondPointId(secondPointId);
dialogNormal->setPointName(p.name());
@ -130,7 +91,7 @@ void VToolNormal::AddToFile(){
AddAttribute(domElement, "typeLine", typeLine);
AddAttribute(domElement, "length", formula);
AddAttribute(domElement, "angle", angle);
AddAttribute(domElement, "firstPoint", firstPointId);
AddAttribute(domElement, "firstPoint", basePointId);
AddAttribute(domElement, "secondPoint", secondPointId);
AddToCalculation(domElement);

View File

@ -3,10 +3,10 @@
#include <QSharedPointer>
#include "vtoolpoint.h"
#include "vtoollinepoint.h"
#include "../dialogs/dialognormal.h"
class VToolNormal : public VToolPoint
class VToolNormal : public VToolLinePoint
{
public:
VToolNormal(VDomDocument *doc, VContainer *data, const qint64 &id,
@ -19,17 +19,11 @@ public:
public slots:
virtual void FullUpdateFromFile();
virtual void FullUpdateFromGui(int result);
virtual void ChangedActivDraw(const QString newName);
protected:
virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event );
virtual void AddToFile();
private:
QString typeLine;
QString formula;
qint32 angle;
qint64 firstPointId;
qint64 secondPointId;
QGraphicsLineItem *mainLine;
QSharedPointer<DialogNormal> dialogNormal;
};

View File

@ -192,15 +192,15 @@ void VToolPoint::mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ){
QGraphicsItem::mouseReleaseEvent(event);
}
void VToolPoint::RefreshGeometry(const QString &name, const qreal &x, const qreal &y, const qreal &mx,
const qreal &my){
QRectF rec = QRectF(x, y, radius*2, radius*2);
rec.translate(x-rec.center().x(), y-rec.center().y());
void VToolPoint::RefreshGeometry(){
VPointF point = VAbstractTool::data->GetPoint(id);
QRectF rec = QRectF(point.x(), point.y(), radius*2, radius*2);
rec.translate(point.x()-rec.center().x(), point.y()-rec.center().y());
this->setRect(rec);
rec = this->rect();
namePoint->setText(name);
namePoint->setPos(QPointF(rec.center().x()+mx, rec.center().y()+my));
namePoint->setText(point.name());
namePoint->setPos(QPointF(rec.center().x()+point.mx(), rec.center().y()+point.my()));
RefreshLine();
}

View File

@ -23,8 +23,7 @@ protected:
VGraphicsSimpleTextItem *namePoint;
QGraphicsLineItem *lineName;
virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event );
void RefreshGeometry(const QString &name, const qreal &x, const qreal &y,
const qreal &mx, const qreal &my);
virtual void RefreshGeometry();
virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event );
virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event );
private:

View File

@ -5,24 +5,11 @@
VToolShoulderPoint::VToolShoulderPoint(VDomDocument *doc, VContainer *data, const qint64 &id,
const QString &typeLine, const QString &formula, const qint64 &p1Line,
const qint64 &p2Line, const qint64 &pShoulder, Tool::Enum typeCreation,
QGraphicsItem * parent):VToolPoint(doc, data, id, parent){
this->typeLine = typeLine;
this->formula = formula;
this->p1Line = p1Line;
QGraphicsItem * parent):
VToolLinePoint(doc, data, id, typeLine, formula, p1Line, 0, parent){
this->p2Line = p2Line;
this->pShoulder = pShoulder;
//Лінія, що з'єднує дві точки
VPointF p1L = data->GetPoint(p1Line);
VPointF point = data->GetPoint(id);
mainLine = new QGraphicsLineItem(QLineF(p1L.toQPointF(), point.toQPointF()), this);
mainLine->setFlag(QGraphicsItem::ItemStacksBehindParent, true);
if(typeLine == "none"){
mainLine->setVisible(false);
} else {
mainLine->setVisible(true);
}
if(typeCreation == Tool::FromGui){
AddToFile();
}
@ -51,28 +38,15 @@ QPointF VToolShoulderPoint::FindPoint(const QPointF &p1Line, const QPointF &p2Li
}
void VToolShoulderPoint::FullUpdateFromFile(){
QString name;
qreal mx, my;
QDomElement domElement = doc->elementById(QString().setNum(id));
if(domElement.isElement()){
name = domElement.attribute("name", "");
mx = domElement.attribute("mx", "").toDouble()*PrintDPI/25.4;
my = domElement.attribute("my", "").toDouble()*PrintDPI/25.4;
typeLine = domElement.attribute("typeLine", "");
formula = domElement.attribute("length", "");
p1Line = domElement.attribute("p1Line", "").toLongLong();
basePointId = domElement.attribute("p1Line", "").toLongLong();
p2Line = domElement.attribute("p2Line", "").toLongLong();
pShoulder = domElement.attribute("pShoulder", "").toLongLong();
}
VPointF point = VAbstractTool::data->GetPoint(id);
RefreshGeometry(name, point.x(), point.y(), mx, my);
VPointF p1L = VAbstractTool::data->GetPoint(p1Line);
mainLine->setLine(QLineF(p1L.toQPointF(), point.toQPointF()));
if(typeLine == "none"){
mainLine->setVisible(false);
} else {
mainLine->setVisible(true);
}
RefreshGeometry();
}
void VToolShoulderPoint::FullUpdateFromGui(int result){
@ -91,16 +65,6 @@ void VToolShoulderPoint::FullUpdateFromGui(int result){
dialogShoulderPoint.clear();
}
void VToolShoulderPoint::ChangedActivDraw(const QString newName){
if(nameActivDraw == newName){
mainLine->setPen(QPen(Qt::black, widthHairLine));
VToolPoint::ChangedActivDraw(newName);
} else {
mainLine->setPen(QPen(Qt::gray, widthHairLine));
VToolPoint::ChangedActivDraw(newName);
}
}
void VToolShoulderPoint::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){
if(!ignoreContextMenuEvent){
QMenu menu;
@ -114,13 +78,14 @@ void VToolShoulderPoint::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
dialogShoulderPoint.data(), &DialogShoulderPoint::ChoosedPoint);
connect(dialogShoulderPoint.data(), &DialogShoulderPoint::DialogClosed, this,
&VToolShoulderPoint::FullUpdateFromGui);
connect(doc, &VDomDocument::FullUpdateFromFile, dialogShoulderPoint.data(), &DialogShoulderPoint::UpdateList);
connect(doc, &VDomDocument::FullUpdateFromFile, dialogShoulderPoint.data(),
&DialogShoulderPoint::UpdateList);
VPointF p = VAbstractTool::data->GetPoint(id);
dialogShoulderPoint->setTypeLine(typeLine);
dialogShoulderPoint->setFormula(formula);
dialogShoulderPoint->setP1Line(p1Line);
dialogShoulderPoint->setP1Line(basePointId);
dialogShoulderPoint->setP2Line(p2Line);
dialogShoulderPoint->setPShoulder(pShoulder);
dialogShoulderPoint->setPointName(p.name());
@ -142,7 +107,7 @@ void VToolShoulderPoint::AddToFile(){
AddAttribute(domElement, "typeLine", typeLine);
AddAttribute(domElement, "length", formula);
AddAttribute(domElement, "p1Line", p1Line);
AddAttribute(domElement, "p1Line", basePointId);
AddAttribute(domElement, "p2Line", p2Line);
AddAttribute(domElement, "pShoulder", pShoulder);

View File

@ -1,10 +1,10 @@
#ifndef VTOOLSHOULDERPOINT_H
#define VTOOLSHOULDERPOINT_H
#include "vtoolpoint.h"
#include "vtoollinepoint.h"
#include "../dialogs/dialogshoulderpoint.h"
class VToolShoulderPoint : public VToolPoint
class VToolShoulderPoint : public VToolLinePoint
{
public:
VToolShoulderPoint(VDomDocument *doc, VContainer *data, const qint64 &id,
@ -16,17 +16,12 @@ public:
public slots:
virtual void FullUpdateFromFile();
virtual void FullUpdateFromGui(int result);
virtual void ChangedActivDraw(const QString newName);
protected:
virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event );
virtual void AddToFile();
private:
QString typeLine;
QString formula;
qint64 p1Line;
qint64 p2Line;
qint64 pShoulder;
QGraphicsLineItem *mainLine;
QSharedPointer<DialogShoulderPoint> dialogShoulderPoint;
};

View File

@ -63,15 +63,5 @@ void VToolSimplePoint::contextMenuEvent ( QGraphicsSceneContextMenuEvent * event
}
void VToolSimplePoint::FullUpdateFromFile(){
QString name;
qreal x, y, mx, my;
QDomElement domElement = doc->elementById(QString().setNum(id));
if(domElement.isElement()){
name = domElement.attribute("name", "");
x = domElement.attribute("x", "").toDouble()*PrintDPI/25.4;
y = domElement.attribute("y", "").toDouble()*PrintDPI/25.4;
mx = domElement.attribute("mx", "").toDouble()*PrintDPI/25.4;
my = domElement.attribute("my", "").toDouble()*PrintDPI/25.4;
}
RefreshGeometry(name, x, y, mx, my);
RefreshGeometry();
}

View File

@ -8,6 +8,7 @@
#include "../tools/vtoolshoulderpoint.h"
#include "../tools/vtoolnormal.h"
#include "../tools/vtoolbisector.h"
#include "../tools/vtoollineintersect.h"
#include "../options.h"
#include "../container/calculator.h"
@ -571,6 +572,50 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen
}
return;
}
if(type == "lineIntersect"){
if(!domElement.isNull()){
QString name;
qreal mx=5, my=10;
qint64 id, p1Line1Id, p2Line1Id, p1Line2Id, p2Line2Id;
if(!domElement.isNull()){
id = domElement.attribute("id", "").toLongLong();
name = domElement.attribute("name", "");
mx = domElement.attribute("mx","").toDouble()*PrintDPI/25.4;
my = domElement.attribute("my","").toDouble()*PrintDPI/25.4;
p1Line1Id = domElement.attribute("p1Line1", "").toLongLong();
p2Line1Id = domElement.attribute("p2Line1", "").toLongLong();
p1Line2Id = domElement.attribute("p1Line2", "").toLongLong();
p2Line2Id = domElement.attribute("p2Line2", "").toLongLong();
VPointF p1Line1 = data->GetPoint(p1Line1Id);
VPointF p2Line1 = data->GetPoint(p2Line1Id);
VPointF p1Line2 = data->GetPoint(p1Line2Id);
VPointF p2Line2 = data->GetPoint(p2Line2Id);
QLineF line1(p1Line1, p2Line1);
QLineF line2(p1Line2, p2Line2);
QPointF fPoint;
QLineF::IntersectType intersect = line1.intersect(line2, &fPoint);
if(intersect == QLineF::UnboundedIntersection || intersect == QLineF::BoundedIntersection){
data->UpdatePoint(id, VPointF(fPoint.x(), fPoint.y(), name, mx, my));
data->AddLine(p1Line1Id, id);
data->AddLine(id, p2Line1Id);
data->AddLine(p1Line2Id, id);
data->AddLine(id, p2Line2Id);
if(parse == Document::FullParse){
VToolLineIntersect *point = new VToolLineIntersect(this, data, id, p1Line1Id,
p2Line1Id, p1Line2Id,
p2Line2Id, Tool::FromGui);
scene->addItem(point);
connect(point, &VToolLineIntersect::ChoosedPoint, scene,
&VMainGraphicsScene::ChoosedItem);
}
}
}
}
return;
}
}
void VDomDocument::ParseLineElement(VMainGraphicsScene *scene, const QDomElement &domElement,