Use static method FindPoint common for tools.

--HG--
branch : develop
This commit is contained in:
dismine 2013-10-18 13:43:51 +03:00
parent 54bf459e17
commit 25190e16a9
19 changed files with 216 additions and 303 deletions

View File

@ -25,13 +25,13 @@
#include "vtoollinepoint.h"
#include "dialogs/dialogalongline.h"
class VToolAlongLine : public VToolLinePoint
{
class VToolAlongLine : public VToolLinePoint{
Q_OBJECT
public:
VToolAlongLine(VDomDocument *doc, VContainer *data, qint64 id, const QString &formula,
const qint64 &firstPointId, const qint64 &secondPointId, const QString &typeLine,
Tool::Sources typeCreation, QGraphicsItem * parent = 0);
const qint64 &firstPointId, const qint64 &secondPointId,
const QString &typeLine, Tool::Sources typeCreation,
QGraphicsItem * parent = 0);
virtual void setDialog();
static void Create(QSharedPointer<DialogAlongLine> &dialog, VMainGraphicsScene *scene, VDomDocument *doc,
VContainer *data);

View File

@ -29,18 +29,18 @@ 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::Sources typeCreation,
QGraphicsItem * parent = 0);
const qint64 &secondPointId, const qint64 &thirdPointId,
Tool::Sources typeCreation, QGraphicsItem * parent = 0);
static QPointF FindPoint(const QPointF &firstPoint, const QPointF &secondPoint,
const QPointF &thirdPoint, const qreal& length);
virtual void setDialog();
static void Create(QSharedPointer<DialogBisector> &dialog, VMainGraphicsScene *scene, VDomDocument *doc,
VContainer *data);
static void Create(QSharedPointer<DialogBisector> &dialog, VMainGraphicsScene *scene,
VDomDocument *doc, VContainer *data);
static void Create(const qint64 _id, const QString &formula, const qint64 &firstPointId,
const qint64 &secondPointId, const qint64 &thirdPointId, const QString &typeLine,
const QString &pointName, const qreal &mx, const qreal &my, VMainGraphicsScene *scene,
VDomDocument *doc, VContainer *data, const Document::Documents &parse,
Tool::Sources typeCreation);
const QString &pointName, const qreal &mx, const qreal &my,
VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data,
const Document::Documents &parse, Tool::Sources typeCreation);
public slots:
virtual void FullUpdateFromFile();
virtual void FullUpdateFromGui(int result);

View File

@ -28,16 +28,15 @@
class VToolEndLine : public VToolLinePoint{
Q_OBJECT
public:
VToolEndLine(VDomDocument *doc, VContainer *data, const qint64 &id,
const QString &typeLine, const QString &formula, const qreal &angle,
const qint64 &basePointId, Tool::Sources typeCreation,
QGraphicsItem * parent = 0);
VToolEndLine(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &typeLine,
const QString &formula, const qreal &angle, const qint64 &basePointId,
Tool::Sources typeCreation, QGraphicsItem * parent = 0);
virtual void setDialog();
static void Create(QSharedPointer<DialogEndLine> &dialog, VMainGraphicsScene *scene, VDomDocument *doc,
VContainer *data);
static void Create(const qint64 _id, const QString &pointName, const QString &typeLine,
const QString &formula, const qreal &angle, const qint64 &basePointId, const qreal &mx, const qreal &my,
VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data,
const QString &formula, const qreal &angle, const qint64 &basePointId, const qreal &mx,
const qreal &my, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data,
const Document::Documents &parse, Tool::Sources typeCreation);
public slots:
virtual void FullUpdateFromFile();

View File

@ -32,8 +32,8 @@ public:
VToolLine(VDomDocument *doc, VContainer *data, qint64 id, qint64 firstPoint,
qint64 secondPoint, Tool::Sources typeCreation, QGraphicsItem * parent = 0);
virtual void setDialog();
static void Create(QSharedPointer<DialogLine> &dialog, VMainGraphicsScene *scene,
VDomDocument *doc, VContainer *data);
static void Create(QSharedPointer<DialogLine> &dialog, VMainGraphicsScene *scene, VDomDocument *doc,
VContainer *data);
static void Create(const qint64 &_id, const qint64 &firstPoint, const qint64 &secondPoint,
VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data,
const Document::Documents &parse, Tool::Sources typeCreation);

View File

@ -25,8 +25,7 @@
#include "vtoollinepoint.h"
#include "dialogs/dialognormal.h"
class VToolNormal : public VToolLinePoint
{
class VToolNormal : public VToolLinePoint{
Q_OBJECT
public:
VToolNormal(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &typeLine,

View File

@ -25,8 +25,7 @@
#include "vtoolpoint.h"
#include "dialogs/dialogpointofcontact.h"
class VToolPointOfContact : public VToolPoint
{
class VToolPointOfContact : public VToolPoint{
public:
VToolPointOfContact(VDomDocument *doc, VContainer *data, const qint64 &id,
const QString &radius, const qint64 &center,

View File

@ -25,12 +25,11 @@
#include "dialogs/dialogsinglepoint.h"
#include "vtoolpoint.h"
class VToolSinglePoint : public VToolPoint
{
class VToolSinglePoint : public VToolPoint{
Q_OBJECT
public:
VToolSinglePoint (VDomDocument *doc, VContainer *data, qint64 id,
Tool::Sources typeCreation, QGraphicsItem * parent = 0 );
VToolSinglePoint (VDomDocument *doc, VContainer *data, qint64 id, Tool::Sources typeCreation,
QGraphicsItem * parent = 0 );
virtual void setDialog();
public slots:
virtual void FullUpdateFromFile();

View File

@ -21,6 +21,7 @@
#include "vmodelingbisector.h"
#include <QMenu>
#include "../drawTools/vtoolbisector.h"
VModelingBisector::VModelingBisector(VDomDocument *doc, VContainer *data, const qint64 &id,
const QString &typeLine, const QString &formula, const qint64 &firstPointId,
@ -36,19 +37,6 @@ VModelingBisector::VModelingBisector(VDomDocument *doc, VContainer *data, const
}
}
QPointF VModelingBisector::FindPoint(const QPointF &firstPoint, const QPointF &secondPoint,
const QPointF &thirdPoint, const qreal &length){
QLineF line1(secondPoint, firstPoint);
QLineF line2(secondPoint, thirdPoint);
qreal angle = line1.angleTo(line2);
if(angle>180){
angle = 360 - angle;
}
line1.setAngle(line1.angle()-angle/2);
line1.setLength(length);
return line1.p2();
}
void VModelingBisector::setDialog(){
Q_ASSERT(!dialogBisector.isNull());
if(!dialogBisector.isNull()){
@ -89,7 +77,7 @@ VModelingBisector *VModelingBisector::Create(const qint64 _id, const QString &fo
QString errorMsg;
qreal result = cal.eval(formula, &errorMsg);
if(errorMsg.isEmpty()){
QPointF fPoint = VModelingBisector::FindPoint(firstPoint.toQPointF(), secondPoint.toQPointF(),
QPointF fPoint = VToolBisector::FindPoint(firstPoint.toQPointF(), secondPoint.toQPointF(),
thirdPoint.toQPointF(), result*PrintDPI/25.4);
qint64 id = _id;
if(typeCreation == Tool::FromGui){

View File

@ -33,8 +33,6 @@ public:
const qint64 &firstPointId, const qint64 &secondPointId,
const qint64 &thirdPointId, Tool::Sources typeCreation,
QGraphicsItem * parent = 0);
static QPointF FindPoint(const QPointF &firstPoint, const QPointF &secondPoint,
const QPointF &thirdPoint, const qreal& length);
virtual void setDialog();
static VModelingBisector* Create(QSharedPointer<DialogBisector> &dialog, VDomDocument *doc,
VContainer *data);

View File

@ -1,4 +1,5 @@
#include "vmodelingheight.h"
#include "../drawTools/vtoolheight.h"
VModelingHeight::VModelingHeight(VDomDocument *doc, VContainer *data, const qint64 &id,
const QString &typeLine, const qint64 &basePointId, const qint64 &p1LineId,
@ -44,7 +45,8 @@ VModelingHeight *VModelingHeight::Create(const qint64 _id, const QString &pointN
VPointF p1Line = data->GetModelingPoint(p1LineId);
VPointF p2Line = data->GetModelingPoint(p2LineId);
QPointF pHeight = FindPoint(QLineF(p1Line.toQPointF(), p2Line.toQPointF()), basePoint.toQPointF());
QPointF pHeight = VToolHeight::FindPoint(QLineF(p1Line.toQPointF(), p2Line.toQPointF()),
basePoint.toQPointF());
QLineF line = QLineF(basePoint.toQPointF(), pHeight);
qint64 id = _id;
if(typeCreation == Tool::FromGui){
@ -113,18 +115,3 @@ void VModelingHeight::AddToFile(){
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

@ -11,14 +11,13 @@ public:
const QString &typeLine, const qint64 &basePointId,
const qint64 &p1LineId, const qint64 &p2LineId,
Tool::Sources typeCreation, QGraphicsItem * parent = 0);
virtual void setDialog();
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);

View File

@ -20,6 +20,7 @@
****************************************************************************/
#include "vmodelingnormal.h"
#include "../drawTools/vtoolnormal.h"
VModelingNormal::VModelingNormal(VDomDocument *doc, VContainer *data, const qint64 &id,
const QString &typeLine,
@ -72,8 +73,8 @@ VModelingNormal *VModelingNormal::Create(const qint64 _id, const QString &formul
QString errorMsg;
qreal result = cal.eval(formula, &errorMsg);
if(errorMsg.isEmpty()){
QPointF fPoint = VModelingNormal::FindPoint(firstPoint.toQPointF(), secondPoint.toQPointF(),
result*PrintDPI/25.4, angle);
QPointF fPoint = VToolNormal::FindPoint(firstPoint.toQPointF(), secondPoint.toQPointF(),
toPixel(result), angle);
qint64 id = _id;
if(typeCreation == Tool::FromGui){
id = data->AddModelingPoint(VPointF(fPoint.x(), fPoint.y(), pointName, mx, my));
@ -95,15 +96,6 @@ VModelingNormal *VModelingNormal::Create(const qint64 _id, const QString &formul
return point;
}
QPointF VModelingNormal::FindPoint(const QPointF &firstPoint, const QPointF &secondPoint, const qreal &length,
const qreal &angle){
QLineF line(firstPoint, secondPoint);
QLineF normal = line.normalVector();
normal.setAngle(normal.angle()+angle);
normal.setLength(length);
return normal.p2();
}
void VModelingNormal::FullUpdateFromFile(){
QDomElement domElement = doc->elementById(QString().setNum(id));
if(domElement.isElement()){

View File

@ -34,15 +34,12 @@ public:
const qint64 &secondPointId, Tool::Sources typeCreation,
QGraphicsItem * parent = 0);
virtual void setDialog();
static VModelingNormal* Create(QSharedPointer<DialogNormal> &dialog, VDomDocument *doc,
VContainer *data);
static VModelingNormal* Create(QSharedPointer<DialogNormal> &dialog, VDomDocument *doc, VContainer *data);
static VModelingNormal* Create(const qint64 _id, const QString &formula, const qint64 &firstPointId,
const qint64 &secondPointId, const QString typeLine,
const QString pointName, const qreal angle, const qreal &mx,
const qreal &my, VDomDocument *doc, VContainer *data,
const Document::Documents &parse, Tool::Sources typeCreation);
static QPointF FindPoint(const QPointF &firstPoint, const QPointF &secondPoint,
const qreal &length, const qreal &angle = 0);
public slots:
virtual void FullUpdateFromFile();
virtual void FullUpdateFromGui(int result);

View File

@ -20,6 +20,7 @@
****************************************************************************/
#include "vmodelingpointofcontact.h"
#include "../drawTools/vtoolpointofcontact.h"
VModelingPointOfContact::VModelingPointOfContact(VDomDocument *doc, VContainer *data, const qint64 &id,
const QString &radius, const qint64 &center,
@ -45,28 +46,6 @@ void VModelingPointOfContact::setDialog(){
}
}
QPointF VModelingPointOfContact::FindPoint(const qreal &radius, const QPointF &center, const QPointF &firstPoint,
const QPointF &secondPoint){
QPointF pArc;
qreal s = 0.0, s_x, s_y, step = 0.01, distans;
while( s < 1){
s_x = secondPoint.x()-(qAbs(secondPoint.x()-firstPoint.x()))*s;
s_y = secondPoint.y()-(qAbs(secondPoint.y()-firstPoint.y()))*s;
distans = QLineF(center.x(), center.y(), s_x, s_y).length();
if(ceil(distans*10) == ceil(radius*10)){
pArc.rx() = s_x;
pArc.ry() = s_y;
break;
}
if(distans<radius){
pArc.rx() = s_x;
pArc.ry() = s_y;
}
s = s + step;
}
return pArc;
}
VModelingPointOfContact *VModelingPointOfContact::Create(QSharedPointer<DialogPointOfContact> &dialog,
VDomDocument *doc, VContainer *data){
QString radius = dialog->getRadius();
@ -94,7 +73,7 @@ VModelingPointOfContact *VModelingPointOfContact::Create(const qint64 _id, const
QString errorMsg;
qreal result = cal.eval(radius, &errorMsg);
if(errorMsg.isEmpty()){
QPointF fPoint = VModelingPointOfContact::FindPoint(result*PrintDPI/25.4, centerP.toQPointF(),
QPointF fPoint = VToolPointOfContact::FindPoint(toPixel(result), centerP.toQPointF(),
firstP.toQPointF(), secondP.toQPointF());
qint64 id = _id;
if(typeCreation == Tool::FromGui){

View File

@ -30,14 +30,11 @@ class VModelingPointOfContact : public VModelingPoint{
public:
VModelingPointOfContact(VDomDocument *doc, VContainer *data,
const qint64 &id, const QString &radius,
const qint64 &center,
const qint64 &firstPointId,
const qint64 &center, const qint64 &firstPointId,
const qint64 &secondPointId,
Tool::Sources typeCreation,
QGraphicsItem * parent = 0);
virtual void setDialog();
static QPointF FindPoint(const qreal &radius, const QPointF &center,
const QPointF &firstPoint, const QPointF &secondPoint);
static VModelingPointOfContact* Create(QSharedPointer<DialogPointOfContact> &dialog,
VDomDocument *doc, VContainer *data);
static VModelingPointOfContact* Create(const qint64 _id, const QString &radius, const qint64 &center,

View File

@ -21,6 +21,7 @@
#include "vmodelingshoulderpoint.h"
#include <QDebug>
#include "../drawTools/vtoolshoulderpoint.h"
VModelingShoulderPoint::VModelingShoulderPoint(VDomDocument *doc, VContainer *data, const qint64 &id,
const QString &typeLine, const QString &formula, const qint64 &p1Line,
@ -48,27 +49,6 @@ void VModelingShoulderPoint::setDialog(){
}
}
QPointF VModelingShoulderPoint::FindPoint(const QPointF &p1Line, const QPointF &p2Line, const QPointF &pShoulder,
const qreal &length){
QLineF line = QLineF(p1Line, p2Line);
qreal dist = line.length();
if(dist>length){
qDebug()<<"A3П2="<<length/PrintDPI*25.4<<"А30П ="<<dist/PrintDPI*25.4;
throw"Не можу знайти точку плеча. Довжина А3П2 < А3П.";
}
if(dist==length){
return line.p2();
}
qreal step = 0.01;
while(1){
line.setLength(line.length()+step);
QLineF line2 = QLineF(pShoulder, line.p2());
if(line2.length()>=length){
return line.p2();
}
}
}
VModelingShoulderPoint *VModelingShoulderPoint::Create(QSharedPointer<DialogShoulderPoint> &dialog,
VDomDocument *doc, VContainer *data){
QString formula = dialog->getFormula();
@ -97,8 +77,8 @@ VModelingShoulderPoint *VModelingShoulderPoint::Create(const qint64 _id, const Q
QString errorMsg;
qreal result = cal.eval(formula, &errorMsg);
if(errorMsg.isEmpty()){
QPointF fPoint = VModelingShoulderPoint::FindPoint(firstPoint.toQPointF(), secondPoint.toQPointF(),
shoulderPoint.toQPointF(), result*PrintDPI/25.4);
QPointF fPoint = VToolShoulderPoint::FindPoint(firstPoint.toQPointF(), secondPoint.toQPointF(),
shoulderPoint.toQPointF(), toPixel(result));
qint64 id = _id;
if(typeCreation == Tool::FromGui){
id = data->AddModelingPoint(VPointF(fPoint.x(), fPoint.y(), pointName, mx, my));

View File

@ -35,16 +35,13 @@ public:
Tool::Sources typeCreation,
QGraphicsItem * parent = 0);
virtual void setDialog();
static QPointF FindPoint(const QPointF &p1Line, const QPointF &p2Line,
const QPointF &pShoulder, const qreal &length);
static VModelingShoulderPoint* Create(QSharedPointer<DialogShoulderPoint> &dialog,
VDomDocument *doc, VContainer *data);
static VModelingShoulderPoint* Create(QSharedPointer<DialogShoulderPoint> &dialog, VDomDocument *doc,
VContainer *data);
static VModelingShoulderPoint* Create(const qint64 _id, const QString &formula, const qint64 &p1Line,
const qint64 &p2Line, const qint64 &pShoulder,
const QString &typeLine, const QString &pointName,
const qreal &mx, const qreal &my, VDomDocument *doc,
VContainer *data, const Document::Documents &parse,
const Tool::Sources &typeCreation);
const QString &typeLine, const QString &pointName, const qreal &mx,
const qreal &my, VDomDocument *doc, VContainer *data,
const Document::Documents &parse, const Tool::Sources &typeCreation);
public slots:
virtual void FullUpdateFromFile();
virtual void FullUpdateFromGui(int result);

View File

@ -31,11 +31,10 @@ class VModelingSplinePath:public VModelingTool, public QGraphicsPathItem{
Q_OBJECT
public:
VModelingSplinePath(VDomDocument *doc, VContainer *data, qint64 id,
Tool::Sources typeCreation,
QGraphicsItem * parent = 0);
Tool::Sources typeCreation, QGraphicsItem * parent = 0);
virtual void setDialog();
static VModelingSplinePath* Create(QSharedPointer<DialogSplinePath> &dialog,
VDomDocument *doc, VContainer *data);
static VModelingSplinePath* Create(QSharedPointer<DialogSplinePath> &dialog, VDomDocument *doc,
VContainer *data);
static VModelingSplinePath* Create(const qint64 _id, const VSplinePath &path, VDomDocument *doc,
VContainer *data, const Document::Documents &parse,
Tool::Sources typeCreation);
@ -47,8 +46,7 @@ public slots:
virtual void FullUpdateFromFile();
virtual void FullUpdateFromGui(int result);
void ControlPointChangePosition(const qint32 &indexSpline,
SplinePoint::Position position,
const QPointF pos);
SplinePoint::Position position, const QPointF pos);
protected:
virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event );
virtual void AddToFile();

View File

@ -51,6 +51,11 @@ protected:
QAction *actionRemove = 0;
if(showRemove){
actionRemove = menu.addAction(tr("Delete"));
if(_referens > 1){
actionRemove->setEnabled(false);
} else {
actionRemove->setEnabled(true);
}
}
QAction *selectedAction = menu.exec(event->screenPos());
if(selectedAction == actionOption){