Refactoring.
--HG-- branch : develop
This commit is contained in:
parent
8e07ed5fd4
commit
8f76443160
|
@ -586,44 +586,44 @@ QPainterPath VSpline::GetPath() const{
|
|||
2 - 1 real root + complex roots imaginary part is zero
|
||||
(i.e. 2 real roots).
|
||||
*/
|
||||
qint32 VSpline::Cubic(qreal *x, qreal a, qreal b, qreal c){
|
||||
qreal q,r,r2,q3;
|
||||
//qint32 VSpline::Cubic(qreal *x, qreal a, qreal b, qreal c){
|
||||
// qreal q,r,r2,q3;
|
||||
|
||||
q = (a*a - 3.*b)/9.;
|
||||
r = (a*(2.*a*a - 9.*b) + 27.*c)/54.;
|
||||
r2 = r*r;
|
||||
q3 = pow(q,3);
|
||||
if(r2<q3) {
|
||||
qreal t = acos(r/sqrt(q3));
|
||||
a/=3.;
|
||||
q = -2.*sqrt(q);
|
||||
x[0] = q*cos(t/3.)-a;
|
||||
x[1] = q*cos((t + M_2PI)/3.) - a;
|
||||
x[2] = q*cos((t - M_2PI)/3.) - a;
|
||||
return(3);
|
||||
} else {
|
||||
qreal aa,bb;
|
||||
if(r<=0.){
|
||||
r=-r;
|
||||
}
|
||||
aa = -pow(r + sqrt(r2-q3),1./3.);
|
||||
if(aa!=0.){
|
||||
bb=q/aa;
|
||||
} else {
|
||||
bb=0.;
|
||||
}
|
||||
a/=3.;
|
||||
q = aa+bb;
|
||||
r = aa-bb;
|
||||
x[0] = q-a;
|
||||
x[1] = (-0.5)*q-a;
|
||||
x[2] = (sqrt(3.)*0.5)*fabs(r);
|
||||
if(x[2]==0.){
|
||||
return(2);
|
||||
}
|
||||
return(1);
|
||||
}
|
||||
}
|
||||
// q = (a*a - 3.*b)/9.;
|
||||
// r = (a*(2.*a*a - 9.*b) + 27.*c)/54.;
|
||||
// r2 = r*r;
|
||||
// q3 = pow(q,3);
|
||||
// if(r2<q3) {
|
||||
// qreal t = acos(r/sqrt(q3));
|
||||
// a/=3.;
|
||||
// q = -2.*sqrt(q);
|
||||
// x[0] = q*cos(t/3.)-a;
|
||||
// x[1] = q*cos((t + M_2PI)/3.) - a;
|
||||
// x[2] = q*cos((t - M_2PI)/3.) - a;
|
||||
// return(3);
|
||||
// } else {
|
||||
// qreal aa,bb;
|
||||
// if(r<=0.){
|
||||
// r=-r;
|
||||
// }
|
||||
// aa = -pow(r + sqrt(r2-q3),1./3.);
|
||||
// if(aa!=0.){
|
||||
// bb=q/aa;
|
||||
// } else {
|
||||
// bb=0.;
|
||||
// }
|
||||
// a/=3.;
|
||||
// q = aa+bb;
|
||||
// r = aa-bb;
|
||||
// x[0] = q-a;
|
||||
// x[1] = (-0.5)*q-a;
|
||||
// x[2] = (sqrt(3.)*0.5)*fabs(r);
|
||||
// if(x[2]==0.){
|
||||
// return(2);
|
||||
// }
|
||||
// return(1);
|
||||
// }
|
||||
//}
|
||||
|
||||
//qreal VSpline::calc_t (qreal curve_coord1, qreal curve_coord2, qreal curve_coord3,
|
||||
// qreal curve_coord4, qreal point_coord) const{
|
||||
|
|
|
@ -257,15 +257,15 @@ private:
|
|||
* @return довжину.
|
||||
*/
|
||||
static qreal CalcSqDistance ( qreal x1, qreal y1, qreal x2, qreal y2);
|
||||
/**
|
||||
* @brief Cubic знаходить розв'язок кубічного рівняння.
|
||||
* @param x коефіцієнт.
|
||||
* @param a коефіцієнт.
|
||||
* @param b коефіцієнт.
|
||||
* @param c коефіцієнт.
|
||||
* @return повертає корені рівняння.
|
||||
*/
|
||||
static qint32 Cubic(qreal *x, qreal a, qreal b, qreal c);
|
||||
// /**
|
||||
// * @brief Cubic знаходить розв'язок кубічного рівняння.
|
||||
// * @param x коефіцієнт.
|
||||
// * @param a коефіцієнт.
|
||||
// * @param b коефіцієнт.
|
||||
// * @param c коефіцієнт.
|
||||
// * @return повертає корені рівняння.
|
||||
// */
|
||||
// static qint32 Cubic(qreal *x, qreal a, qreal b, qreal c);
|
||||
/**
|
||||
* @brief calc_t знаходить параметр t якому відповідає точка на сплайні.
|
||||
* @param curve_coord1 координата Х або У кривої.
|
||||
|
|
|
@ -171,7 +171,7 @@ void MainWindow::ActionNewDraw(){
|
|||
|
||||
void MainWindow::OptionDraw(){
|
||||
QString nameDraw;
|
||||
bool bOk;
|
||||
bool bOk = false;
|
||||
qint32 index;
|
||||
QString nDraw = doc->GetNameActivDraw();
|
||||
QInputDialog *dlg = new QInputDialog(this);
|
||||
|
@ -206,9 +206,8 @@ void MainWindow::OptionDraw(){
|
|||
}
|
||||
|
||||
template <typename Dialog, typename Func>
|
||||
void MainWindow::SetToolButton(bool checked, Tool::Tools t, const QString &cursor,
|
||||
const QString &toolTip, QSharedPointer<Dialog> &dialog,
|
||||
Func closeDialogSlot){
|
||||
void MainWindow::SetToolButton(bool checked, Tool::Tools t, const QString &cursor, const QString &toolTip,
|
||||
QSharedPointer<Dialog> &dialog, Func closeDialogSlot){
|
||||
if(checked){
|
||||
CanselTool();
|
||||
tool = t;
|
||||
|
@ -223,14 +222,14 @@ void MainWindow::SetToolButton(bool checked, Tool::Tools t, const QString &curso
|
|||
connect(doc, &VDomDocument::FullUpdateFromFile, dialog.data(), &Dialog::UpdateList);
|
||||
} else {
|
||||
if(QToolButton *tButton = qobject_cast< QToolButton * >(this->sender())){
|
||||
Q_ASSERT(tButton != 0);
|
||||
tButton->setChecked(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void MainWindow::AddToolToDetail(T *tool, const qint64 &id, Tool::Tools typeTool,
|
||||
const qint64 &idDetail){
|
||||
void MainWindow::AddToolToDetail(T *tool, const qint64 &id, Tool::Tools typeTool, const qint64 &idDetail){
|
||||
QHash<qint64, VDataTool*>* tools = doc->getTools();
|
||||
VToolDetail *det = qobject_cast<VToolDetail*>(tools->value(idDetail));
|
||||
Q_ASSERT(det != 0);
|
||||
|
|
|
@ -99,6 +99,18 @@ protected:
|
|||
}
|
||||
}
|
||||
}
|
||||
template <typename Item>
|
||||
void ShowItem(Item *item, qint64 id, Qt::GlobalColor color, bool enable){
|
||||
Q_ASSERT(item != 0);
|
||||
if(id == item->id){
|
||||
if(enable == false){
|
||||
currentColor = baseColor;
|
||||
} else {
|
||||
currentColor = color;
|
||||
}
|
||||
item->setPen(QPen(currentColor, widthHairLine/factor));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif // VDRAWTOOL_H
|
||||
|
|
|
@ -56,7 +56,6 @@ void VToolAlongLine::FullUpdateFromGui(int result){
|
|||
domElement.setAttribute("secondPoint", QString().setNum(dialogAlongLine->getSecondPointId()));
|
||||
emit FullUpdateTree();
|
||||
}
|
||||
|
||||
}
|
||||
dialogAlongLine.clear();
|
||||
}
|
||||
|
|
|
@ -125,31 +125,22 @@ void VToolArc::FullUpdateFromGui(int result){
|
|||
}
|
||||
|
||||
void VToolArc::ChangedActivDraw(const QString newName){
|
||||
bool selectable = false;
|
||||
if(nameActivDraw == newName){
|
||||
this->setPen(QPen(Qt::black, widthHairLine/factor));
|
||||
this->setFlag(QGraphicsItem::ItemIsSelectable, true);
|
||||
this->setAcceptHoverEvents(true);
|
||||
selectable = true;
|
||||
currentColor = Qt::black;
|
||||
VDrawTool::ChangedActivDraw(newName);
|
||||
} else {
|
||||
this->setPen(QPen(Qt::gray, widthHairLine/factor));
|
||||
this->setFlag(QGraphicsItem::ItemIsSelectable, false);
|
||||
this->setAcceptHoverEvents (false);
|
||||
selectable = false;
|
||||
currentColor = Qt::gray;
|
||||
VDrawTool::ChangedActivDraw(newName);
|
||||
}
|
||||
this->setPen(QPen(currentColor, widthHairLine/factor));
|
||||
this->setFlag(QGraphicsItem::ItemIsSelectable, selectable);
|
||||
this->setAcceptHoverEvents (selectable);
|
||||
VDrawTool::ChangedActivDraw(newName);
|
||||
}
|
||||
|
||||
void VToolArc::ShowTool(qint64 id, Qt::GlobalColor color, bool enable){
|
||||
if(id == this->id){
|
||||
if(enable == false){
|
||||
this->setPen(QPen(baseColor, widthHairLine/factor));
|
||||
currentColor = baseColor;
|
||||
} else {
|
||||
this->setPen(QPen(color, widthHairLine/factor));
|
||||
currentColor = color;
|
||||
}
|
||||
}
|
||||
ShowItem(this, id, color, enable);
|
||||
}
|
||||
|
||||
void VToolArc::SetFactor(qreal factor){
|
||||
|
|
|
@ -100,15 +100,7 @@ void VToolLine::FullUpdateFromGui(int result){
|
|||
}
|
||||
|
||||
void VToolLine::ShowTool(qint64 id, Qt::GlobalColor color, bool enable){
|
||||
if(id == this->id){
|
||||
if(enable == false){
|
||||
this->setPen(QPen(baseColor, widthHairLine/factor));
|
||||
currentColor = baseColor;
|
||||
} else {
|
||||
this->setPen(QPen(color, widthHairLine/factor));
|
||||
currentColor = color;
|
||||
}
|
||||
}
|
||||
ShowItem(this, id, color, enable);
|
||||
}
|
||||
|
||||
void VToolLine::SetFactor(qreal factor){
|
||||
|
@ -117,24 +109,23 @@ void VToolLine::SetFactor(qreal factor){
|
|||
}
|
||||
|
||||
void VToolLine::ChangedActivDraw(const QString newName){
|
||||
bool selectable = false;
|
||||
if(nameActivDraw == newName){
|
||||
this->setPen(QPen(Qt::black, widthHairLine/factor));
|
||||
this->setAcceptHoverEvents (true);
|
||||
selectable = true;
|
||||
currentColor = Qt::black;
|
||||
VDrawTool::ChangedActivDraw(newName);
|
||||
} else {
|
||||
this->setPen(QPen(Qt::gray, widthHairLine/factor));
|
||||
this->setAcceptHoverEvents (false);
|
||||
selectable = false;
|
||||
currentColor = Qt::gray;
|
||||
VDrawTool::ChangedActivDraw(newName);
|
||||
}
|
||||
this->setPen(QPen(currentColor, widthHairLine/factor));
|
||||
this->setAcceptHoverEvents (selectable);
|
||||
VDrawTool::ChangedActivDraw(newName);
|
||||
}
|
||||
|
||||
void VToolLine::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){
|
||||
ContextMenu(dialogLine, this, event);
|
||||
}
|
||||
|
||||
|
||||
void VToolLine::AddToFile(){
|
||||
QDomElement domElement = doc->createElement("line");
|
||||
AddAttribute(domElement, "id", id);
|
||||
|
|
|
@ -41,14 +41,12 @@ VToolLinePoint::VToolLinePoint(VDomDocument *doc, VContainer *data, const qint64
|
|||
|
||||
void VToolLinePoint::ChangedActivDraw(const QString newName){
|
||||
if(nameActivDraw == newName){
|
||||
mainLine->setPen(QPen(Qt::black, widthHairLine/factor));
|
||||
currentColor = Qt::black;
|
||||
VToolPoint::ChangedActivDraw(newName);
|
||||
} else {
|
||||
mainLine->setPen(QPen(Qt::gray, widthHairLine/factor));
|
||||
currentColor = Qt::gray;
|
||||
VToolPoint::ChangedActivDraw(newName);
|
||||
}
|
||||
mainLine->setPen(QPen(currentColor, widthHairLine/factor));
|
||||
VToolPoint::ChangedActivDraw(newName);
|
||||
}
|
||||
|
||||
void VToolLinePoint::RefreshGeometry(){
|
||||
|
|
|
@ -54,43 +54,28 @@ void VToolPoint::UpdateNamePosition(qreal mx, qreal my){
|
|||
}
|
||||
|
||||
void VToolPoint::ChangedActivDraw(const QString newName){
|
||||
bool selectable = false;
|
||||
if(nameActivDraw == newName){
|
||||
this->setPen(QPen(Qt::black, widthHairLine/factor));
|
||||
this->setFlag(QGraphicsItem::ItemIsSelectable, true);
|
||||
this->setAcceptHoverEvents(true);
|
||||
namePoint->setFlag(QGraphicsItem::ItemIsMovable, true);
|
||||
namePoint->setFlag(QGraphicsItem::ItemIsSelectable, true);
|
||||
namePoint->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
|
||||
namePoint->setBrush(QBrush(Qt::black));
|
||||
namePoint->setAcceptHoverEvents(true);
|
||||
lineName->setPen(QPen(Qt::black, widthHairLine/factor));
|
||||
selectable = true;
|
||||
currentColor = Qt::black;
|
||||
VDrawTool::ChangedActivDraw(newName);
|
||||
} else {
|
||||
this->setPen(QPen(Qt::gray, widthHairLine/factor));
|
||||
this->setFlag(QGraphicsItem::ItemIsSelectable, false);
|
||||
this->setAcceptHoverEvents (false);
|
||||
namePoint->setFlag(QGraphicsItem::ItemIsMovable, false);
|
||||
namePoint->setFlag(QGraphicsItem::ItemIsSelectable, false);
|
||||
namePoint->setFlag(QGraphicsItem::ItemSendsGeometryChanges, false);
|
||||
namePoint->setBrush(QBrush(Qt::gray));
|
||||
namePoint->setAcceptHoverEvents(false);
|
||||
lineName->setPen(QPen(Qt::gray, widthHairLine/factor));
|
||||
selectable = false;
|
||||
currentColor = Qt::gray;
|
||||
VDrawTool::ChangedActivDraw(newName);
|
||||
}
|
||||
this->setPen(QPen(currentColor, widthHairLine/factor));
|
||||
this->setFlag(QGraphicsItem::ItemIsSelectable, selectable);
|
||||
this->setAcceptHoverEvents (selectable);
|
||||
namePoint->setFlag(QGraphicsItem::ItemIsMovable, selectable);
|
||||
namePoint->setFlag(QGraphicsItem::ItemIsSelectable, selectable);
|
||||
namePoint->setFlag(QGraphicsItem::ItemSendsGeometryChanges, selectable);
|
||||
namePoint->setBrush(QBrush(currentColor));
|
||||
namePoint->setAcceptHoverEvents(selectable);
|
||||
lineName->setPen(QPen(currentColor, widthHairLine/factor));
|
||||
VDrawTool::ChangedActivDraw(newName);
|
||||
}
|
||||
|
||||
void VToolPoint::ShowTool(qint64 id, Qt::GlobalColor color, bool enable){
|
||||
if(id == this->id){
|
||||
if(enable == false){
|
||||
this->setPen(QPen(baseColor, widthHairLine/factor));
|
||||
currentColor = baseColor;
|
||||
} else {
|
||||
this->setPen(QPen(color, widthHairLine/factor));
|
||||
currentColor = color;
|
||||
}
|
||||
}
|
||||
ShowItem(this, id, color, enable);
|
||||
}
|
||||
|
||||
void VToolPoint::SetFactor(qreal factor){
|
||||
|
|
|
@ -246,33 +246,23 @@ void VToolSpline::RefreshGeometry(){
|
|||
|
||||
|
||||
void VToolSpline::ChangedActivDraw(const QString newName){
|
||||
bool selectable = false;
|
||||
if(nameActivDraw == newName){
|
||||
this->setPen(QPen(Qt::black, widthHairLine/factor));
|
||||
this->setFlag(QGraphicsItem::ItemIsSelectable, true);
|
||||
this->setAcceptHoverEvents(true);
|
||||
selectable = true;
|
||||
currentColor = Qt::black;
|
||||
emit setEnabledPoint(true);
|
||||
VDrawTool::ChangedActivDraw(newName);
|
||||
} else {
|
||||
this->setPen(QPen(Qt::gray, widthHairLine/factor));
|
||||
this->setFlag(QGraphicsItem::ItemIsSelectable, false);
|
||||
this->setAcceptHoverEvents (false);
|
||||
selectable = false;
|
||||
currentColor = Qt::gray;
|
||||
emit setEnabledPoint(false);
|
||||
VDrawTool::ChangedActivDraw(newName);
|
||||
}
|
||||
this->setPen(QPen(currentColor, widthHairLine/factor));
|
||||
this->setFlag(QGraphicsItem::ItemIsSelectable, selectable);
|
||||
this->setAcceptHoverEvents (selectable);
|
||||
emit setEnabledPoint(selectable);
|
||||
VDrawTool::ChangedActivDraw(newName);
|
||||
}
|
||||
|
||||
void VToolSpline::ShowTool(qint64 id, Qt::GlobalColor color, bool enable){
|
||||
if(id == this->id){
|
||||
if(enable == false){
|
||||
this->setPen(QPen(baseColor, widthHairLine/factor));
|
||||
currentColor = baseColor;
|
||||
} else {
|
||||
this->setPen(QPen(color, widthHairLine/factor));
|
||||
currentColor = color;
|
||||
}
|
||||
}
|
||||
ShowItem(this, id, color, enable);
|
||||
}
|
||||
|
||||
void VToolSpline::SetFactor(qreal factor){
|
||||
|
|
|
@ -187,33 +187,23 @@ void VToolSplinePath::UpdatePathPoint(QDomNode& node, VSplinePath &path){
|
|||
}
|
||||
|
||||
void VToolSplinePath::ChangedActivDraw(const QString newName){
|
||||
bool selectable = false;
|
||||
if(nameActivDraw == newName){
|
||||
this->setPen(QPen(Qt::black, widthHairLine/factor));
|
||||
this->setFlag(QGraphicsItem::ItemIsSelectable, true);
|
||||
this->setAcceptHoverEvents(true);
|
||||
selectable = true;
|
||||
currentColor = Qt::black;
|
||||
emit setEnabledPoint(true);
|
||||
VDrawTool::ChangedActivDraw(newName);
|
||||
} else {
|
||||
this->setPen(QPen(Qt::gray, widthHairLine/factor));
|
||||
this->setFlag(QGraphicsItem::ItemIsSelectable, false);
|
||||
this->setAcceptHoverEvents (false);
|
||||
selectable = false;
|
||||
currentColor = Qt::gray;
|
||||
emit setEnabledPoint(false);
|
||||
VDrawTool::ChangedActivDraw(newName);
|
||||
}
|
||||
this->setPen(QPen(currentColor, widthHairLine/factor));
|
||||
this->setFlag(QGraphicsItem::ItemIsSelectable, selectable);
|
||||
this->setAcceptHoverEvents (selectable);
|
||||
emit setEnabledPoint(selectable);
|
||||
VDrawTool::ChangedActivDraw(newName);
|
||||
}
|
||||
|
||||
void VToolSplinePath::ShowTool(qint64 id, Qt::GlobalColor color, bool enable){
|
||||
if(id == this->id){
|
||||
if(enable == false){
|
||||
this->setPen(QPen(baseColor, widthHairLine/factor));
|
||||
currentColor = baseColor;
|
||||
} else {
|
||||
this->setPen(QPen(color, widthHairLine/factor));
|
||||
currentColor = color;
|
||||
}
|
||||
}
|
||||
ShowItem(this, id, color, enable);
|
||||
}
|
||||
|
||||
void VToolSplinePath::SetFactor(qreal factor){
|
||||
|
|
|
@ -95,8 +95,8 @@ QPointF VToolTriangle::FindPoint(const QPointF axisP1, const QPointF axisP2, con
|
|||
}
|
||||
}
|
||||
if(c*c < a*a + b*b){
|
||||
return line.p2();
|
||||
qWarning()<<tr("Can't find point.")<<Q_FUNC_INFO;
|
||||
return line.p2();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,9 +25,8 @@
|
|||
#include "modelingTools/modelingtools.h"
|
||||
|
||||
VToolDetail::VToolDetail(VDomDocument *doc, VContainer *data, const qint64 &id, Tool::Sources typeCreation,
|
||||
VMainGraphicsScene *scene, QGraphicsItem *parent)
|
||||
:VAbstractTool(doc, data, id), QGraphicsPathItem(parent), dialogDetail(QSharedPointer<DialogDetail>()),
|
||||
sceneDetails(scene){
|
||||
VMainGraphicsScene *scene, QGraphicsItem *parent) :VAbstractTool(doc, data, id),
|
||||
QGraphicsPathItem(parent), dialogDetail(QSharedPointer<DialogDetail>()), sceneDetails(scene){
|
||||
VDetail detail = data->GetDetail(id);
|
||||
QHash<qint64, VDataTool*>* tools = doc->getTools();
|
||||
Q_ASSERT(tools != 0);
|
||||
|
|
Loading…
Reference in New Issue
Block a user