New tool Height.

--HG--
branch : develop
This commit is contained in:
dismine 2013-10-18 13:03:01 +03:00
parent 2fffdecc86
commit 54bf459e17
32 changed files with 1013 additions and 190 deletions

View File

@ -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 \

View File

@ -12,5 +12,6 @@
<file>cursor/splinepath_cursor.png</file>
<file>cursor/pointcontact_cursor.png</file>
<file>cursor/new_detail_cursor.png</file>
<file>cursor/height_cursor.png</file>
</qresource>
</RCC>

BIN
cursor/height_cursor.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -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,

122
dialogs/dialogheight.cpp Normal file
View File

@ -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);
}

40
dialogs/dialogheight.h Normal file
View File

@ -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

211
dialogs/dialogheight.ui Normal file
View File

@ -0,0 +1,211 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DialogHeight</class>
<widget class="QDialog" name="DialogHeight">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>247</width>
<height>220</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="labelEditNamePoint">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="palette">
<palette>
<active>
<colorrole role="WindowText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
</active>
<inactive>
<colorrole role="WindowText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
</inactive>
<disabled>
<colorrole role="WindowText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>159</red>
<green>158</green>
<blue>158</blue>
</color>
</brush>
</colorrole>
</disabled>
</palette>
</property>
<property name="text">
<string>Name new point</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEditNamePoint"/>
</item>
</layout>
</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>Base point</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBoxBasePoint">
<property name="toolTip">
<string>First point of line</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<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>First point of line</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBoxP1Line">
<property name="toolTip">
<string>First point of line</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QLabel" name="label_5">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Second point of line</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBoxP2Line">
<property name="toolTip">
<string>First point of line</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<widget class="QLabel" name="label_7">
<property name="text">
<string>Type line</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBoxLineType">
<property name="toolTip">
<string>Show line from first point to our point</string>
</property>
</widget>
</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>DialogHeight</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>DialogHeight</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

@ -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()<<tr("Get wrong tool type. Ignore.");
break;

View File

@ -37,5 +37,6 @@
#include "dialogsinglepoint.h"
#include "dialogspline.h"
#include "dialogsplinepath.h"
#include "dialogheight.h"
#endif // DIALOGS_H

View File

@ -125,6 +125,8 @@ void DialogTool::ChangeCurrentText(QComboBox *box, const QString &value){
qint32 index = box->findText(value);
if(index != -1){
box->setCurrentIndex(index);
} else {
qWarning()<<tr("Can't find point by name")<<value;
}
}

View File

@ -34,5 +34,6 @@
<file>icon/32x32/new_detail.png</file>
<file>icon/32x32/layout.png</file>
<file>icon/16x16/mirror.png</file>
<file>icon/32x32/height.png</file>
</qresource>
</RCC>

BIN
icon/32x32/height.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 857 B

View File

@ -44,10 +44,10 @@ MainWindow::MainWindow(QWidget *parent) :
dialogAlongLine(QSharedPointer<DialogAlongLine>()),
dialogShoulderPoint(QSharedPointer<DialogShoulderPoint>()), dialogNormal(QSharedPointer<DialogNormal>()),
dialogBisector(QSharedPointer<DialogBisector>()),
dialogLineIntersect(QSharedPointer<DialogLineIntersect>()),
dialogSpline(QSharedPointer<DialogSpline>()),
dialogLineIntersect(QSharedPointer<DialogLineIntersect>()), dialogSpline(QSharedPointer<DialogSpline>()),
dialogArc(QSharedPointer<DialogArc>()), dialogSplinePath(QSharedPointer<DialogSplinePath>()),
dialogPointOfContact(QSharedPointer<DialogPointOfContact>()), dialogDetail(QSharedPointer<DialogDetail>()),
dialogPointOfContact(QSharedPointer<DialogPointOfContact>()),
dialogDetail(QSharedPointer<DialogDetail>()), dialogHeight(QSharedPointer<DialogHeight>()),
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(){

View File

@ -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> dialogSplinePath;
QSharedPointer<DialogPointOfContact> dialogPointOfContact;
QSharedPointer<DialogDetail> dialogDetail;
QSharedPointer<DialogHeight> dialogHeight;
DialogHistory *dialogHistory;
VDomDocument *doc;
VContainer *data;

View File

@ -48,7 +48,7 @@
<x>0</x>
<y>0</y>
<width>150</width>
<height>104</height>
<height>150</height>
</rect>
</property>
<property name="sizePolicy">
@ -64,20 +64,20 @@
<string>Point</string>
</attribute>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0">
<widget class="QToolButton" name="toolButtonNormal">
<item row="0" column="0">
<widget class="QToolButton" name="toolButtonEndLine">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Tool point of normal.</string>
<string>Tool point on the end line.</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="icon.qrc">
<normaloff>:/icon/32x32/normal.png</normaloff>:/icon/32x32/normal.png</iconset>
<normaloff>:/icon/32x32/segment.png</normaloff>:/icon/32x32/segment.png</iconset>
</property>
<property name="iconSize">
<size>
@ -116,46 +116,20 @@
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QToolButton" name="toolButtonEndLine">
<item row="1" column="2">
<widget class="QToolButton" name="toolButtonPointOfContact">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Tool point on the end line.</string>
<string>Tool point of contact.</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="icon.qrc">
<normaloff>:/icon/32x32/segment.png</normaloff>:/icon/32x32/segment.png</iconset>
</property>
<property name="iconSize">
<size>
<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="toolButtonAlongLine">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Tool point along line.</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="icon.qrc">
<normaloff>:/icon/32x32/along_line.png</normaloff>:/icon/32x32/along_line.png</iconset>
<normaloff>:/icon/32x32/point_of_contact.png</normaloff>:/icon/32x32/point_of_contact.png</iconset>
</property>
<property name="iconSize">
<size>
@ -194,20 +168,72 @@
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QToolButton" name="toolButtonPointOfContact">
<item row="1" column="0">
<widget class="QToolButton" name="toolButtonNormal">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Tool point of contact.</string>
<string>Tool point of normal.</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="icon.qrc">
<normaloff>:/icon/32x32/point_of_contact.png</normaloff>:/icon/32x32/point_of_contact.png</iconset>
<normaloff>:/icon/32x32/normal.png</normaloff>:/icon/32x32/normal.png</iconset>
</property>
<property name="iconSize">
<size>
<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="toolButtonAlongLine">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Tool point along line.</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="icon.qrc">
<normaloff>:/icon/32x32/along_line.png</normaloff>:/icon/32x32/along_line.png</iconset>
</property>
<property name="iconSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QToolButton" name="toolButtonHeight">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Tool point of height.</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="icon.qrc">
<normaloff>:/icon/32x32/height.png</normaloff>:/icon/32x32/height.png</iconset>
</property>
<property name="iconSize">
<size>

View File

@ -55,7 +55,8 @@ enum Tool {ArrowTool,
NodePoint,
NodeArc,
NodeSpline,
NodeSplinePath
NodeSplinePath,
Height
};
Q_DECLARE_FLAGS(Tools, Tool)

View File

@ -34,5 +34,6 @@
#include "vtoolsinglepoint.h"
#include "vtoolspline.h"
#include "vtoolsplinepath.h"
#include "vtoolheight.h"
#endif // DRAWTOOLS_H

View File

@ -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);

View File

@ -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<Dialog>(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();

View File

@ -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<DialogEndLine> &dialog, VMainGraphicsScene *scene,

View File

@ -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<DialogHeight>()), 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<DialogHeight> &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);
}

View File

@ -0,0 +1,34 @@
#ifndef VTOOLHEIGHT_H
#define VTOOLHEIGHT_H
#include "vtoollinepoint.h"
#include "dialogs/dialogheight.h"
#include <QLineF>
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<DialogHeight> &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> dialogHeight;
qint64 p1LineId;
qint64 p2LineId;
};
#endif // VTOOLHEIGHT_H

View File

@ -34,5 +34,6 @@
#include "vmodelingsinglepoint.h"
#include "vmodelingspline.h"
#include "vmodelingsplinepath.h"
#include "vmodelingheight.h"
#endif // MODELINGTOOLS_H

View File

@ -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);

View File

@ -24,9 +24,10 @@
#include <QMenu>
#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<DialogEndLine>()){
@ -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<DialogEndLine> &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();
}

View File

@ -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<DialogHeight>()), 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<DialogHeight> &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();
}
}

View File

@ -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<DialogHeight> &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> dialogHeight;
qint64 p1LineId;
qint64 p2LineId;
};
#endif // VMODELINGHEIGHT_H

View File

@ -23,7 +23,7 @@
#include <QDebug>
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;
}

View File

@ -39,6 +39,7 @@ signals:
void RemoveTool(QGraphicsItem *tool);
protected:
bool ignoreContextMenuEvent;
bool ignoreFullUpdate;
void AddToModeling(const QDomElement &domElement);
virtual void decrementReferens();
template <typename Dialog, typename Tool>
@ -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<Dialog>(new Dialog(getData()));
dialog = QSharedPointer<Dialog>(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);
}
}
}
}
}
}

View File

@ -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;
}

View File

@ -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:

View File

@ -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,