Refactoring.

--HG--
branch : develop
This commit is contained in:
dismine 2013-10-28 17:45:27 +02:00
parent 8e07ed5fd4
commit 8f76443160
13 changed files with 115 additions and 161 deletions

View File

@ -586,44 +586,44 @@ QPainterPath VSpline::GetPath() const{
2 - 1 real root + complex roots imaginary part is zero 2 - 1 real root + complex roots imaginary part is zero
(i.e. 2 real roots). (i.e. 2 real roots).
*/ */
qint32 VSpline::Cubic(qreal *x, qreal a, qreal b, qreal c){ //qint32 VSpline::Cubic(qreal *x, qreal a, qreal b, qreal c){
qreal q,r,r2,q3; // qreal q,r,r2,q3;
q = (a*a - 3.*b)/9.; // q = (a*a - 3.*b)/9.;
r = (a*(2.*a*a - 9.*b) + 27.*c)/54.; // r = (a*(2.*a*a - 9.*b) + 27.*c)/54.;
r2 = r*r; // r2 = r*r;
q3 = pow(q,3); // q3 = pow(q,3);
if(r2<q3) { // if(r2<q3) {
qreal t = acos(r/sqrt(q3)); // qreal t = acos(r/sqrt(q3));
a/=3.; // a/=3.;
q = -2.*sqrt(q); // q = -2.*sqrt(q);
x[0] = q*cos(t/3.)-a; // x[0] = q*cos(t/3.)-a;
x[1] = q*cos((t + M_2PI)/3.) - a; // x[1] = q*cos((t + M_2PI)/3.) - a;
x[2] = q*cos((t - M_2PI)/3.) - a; // x[2] = q*cos((t - M_2PI)/3.) - a;
return(3); // return(3);
} else { // } else {
qreal aa,bb; // qreal aa,bb;
if(r<=0.){ // if(r<=0.){
r=-r; // r=-r;
} // }
aa = -pow(r + sqrt(r2-q3),1./3.); // aa = -pow(r + sqrt(r2-q3),1./3.);
if(aa!=0.){ // if(aa!=0.){
bb=q/aa; // bb=q/aa;
} else { // } else {
bb=0.; // bb=0.;
} // }
a/=3.; // a/=3.;
q = aa+bb; // q = aa+bb;
r = aa-bb; // r = aa-bb;
x[0] = q-a; // x[0] = q-a;
x[1] = (-0.5)*q-a; // x[1] = (-0.5)*q-a;
x[2] = (sqrt(3.)*0.5)*fabs(r); // x[2] = (sqrt(3.)*0.5)*fabs(r);
if(x[2]==0.){ // if(x[2]==0.){
return(2); // return(2);
} // }
return(1); // return(1);
} // }
} //}
//qreal VSpline::calc_t (qreal curve_coord1, qreal curve_coord2, qreal curve_coord3, //qreal VSpline::calc_t (qreal curve_coord1, qreal curve_coord2, qreal curve_coord3,
// qreal curve_coord4, qreal point_coord) const{ // qreal curve_coord4, qreal point_coord) const{

View File

@ -257,15 +257,15 @@ private:
* @return довжину. * @return довжину.
*/ */
static qreal CalcSqDistance ( qreal x1, qreal y1, qreal x2, qreal y2); static qreal CalcSqDistance ( qreal x1, qreal y1, qreal x2, qreal y2);
/** // /**
* @brief Cubic знаходить розв'язок кубічного рівняння. // * @brief Cubic знаходить розв'язок кубічного рівняння.
* @param x коефіцієнт. // * @param x коефіцієнт.
* @param a коефіцієнт. // * @param a коефіцієнт.
* @param b коефіцієнт. // * @param b коефіцієнт.
* @param c коефіцієнт. // * @param c коефіцієнт.
* @return повертає корені рівняння. // * @return повертає корені рівняння.
*/ // */
static qint32 Cubic(qreal *x, qreal a, qreal b, qreal c); // static qint32 Cubic(qreal *x, qreal a, qreal b, qreal c);
/** /**
* @brief calc_t знаходить параметр t якому відповідає точка на сплайні. * @brief calc_t знаходить параметр t якому відповідає точка на сплайні.
* @param curve_coord1 координата Х або У кривої. * @param curve_coord1 координата Х або У кривої.

View File

@ -171,7 +171,7 @@ void MainWindow::ActionNewDraw(){
void MainWindow::OptionDraw(){ void MainWindow::OptionDraw(){
QString nameDraw; QString nameDraw;
bool bOk; bool bOk = false;
qint32 index; qint32 index;
QString nDraw = doc->GetNameActivDraw(); QString nDraw = doc->GetNameActivDraw();
QInputDialog *dlg = new QInputDialog(this); QInputDialog *dlg = new QInputDialog(this);
@ -206,9 +206,8 @@ void MainWindow::OptionDraw(){
} }
template <typename Dialog, typename Func> template <typename Dialog, typename Func>
void MainWindow::SetToolButton(bool checked, Tool::Tools t, const QString &cursor, void MainWindow::SetToolButton(bool checked, Tool::Tools t, const QString &cursor, const QString &toolTip,
const QString &toolTip, QSharedPointer<Dialog> &dialog, QSharedPointer<Dialog> &dialog, Func closeDialogSlot){
Func closeDialogSlot){
if(checked){ if(checked){
CanselTool(); CanselTool();
tool = t; 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); connect(doc, &VDomDocument::FullUpdateFromFile, dialog.data(), &Dialog::UpdateList);
} else { } else {
if(QToolButton *tButton = qobject_cast< QToolButton * >(this->sender())){ if(QToolButton *tButton = qobject_cast< QToolButton * >(this->sender())){
Q_ASSERT(tButton != 0);
tButton->setChecked(true); tButton->setChecked(true);
} }
} }
} }
template <typename T> template <typename T>
void MainWindow::AddToolToDetail(T *tool, const qint64 &id, Tool::Tools typeTool, void MainWindow::AddToolToDetail(T *tool, const qint64 &id, Tool::Tools typeTool, const qint64 &idDetail){
const qint64 &idDetail){
QHash<qint64, VDataTool*>* tools = doc->getTools(); QHash<qint64, VDataTool*>* tools = doc->getTools();
VToolDetail *det = qobject_cast<VToolDetail*>(tools->value(idDetail)); VToolDetail *det = qobject_cast<VToolDetail*>(tools->value(idDetail));
Q_ASSERT(det != 0); Q_ASSERT(det != 0);

View File

@ -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 #endif // VDRAWTOOL_H

View File

@ -56,7 +56,6 @@ void VToolAlongLine::FullUpdateFromGui(int result){
domElement.setAttribute("secondPoint", QString().setNum(dialogAlongLine->getSecondPointId())); domElement.setAttribute("secondPoint", QString().setNum(dialogAlongLine->getSecondPointId()));
emit FullUpdateTree(); emit FullUpdateTree();
} }
} }
dialogAlongLine.clear(); dialogAlongLine.clear();
} }

View File

@ -125,31 +125,22 @@ void VToolArc::FullUpdateFromGui(int result){
} }
void VToolArc::ChangedActivDraw(const QString newName){ void VToolArc::ChangedActivDraw(const QString newName){
bool selectable = false;
if(nameActivDraw == newName){ if(nameActivDraw == newName){
this->setPen(QPen(Qt::black, widthHairLine/factor)); selectable = true;
this->setFlag(QGraphicsItem::ItemIsSelectable, true);
this->setAcceptHoverEvents(true);
currentColor = Qt::black; currentColor = Qt::black;
VDrawTool::ChangedActivDraw(newName);
} else { } else {
this->setPen(QPen(Qt::gray, widthHairLine/factor)); selectable = false;
this->setFlag(QGraphicsItem::ItemIsSelectable, false);
this->setAcceptHoverEvents (false);
currentColor = Qt::gray; 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){ void VToolArc::ShowTool(qint64 id, Qt::GlobalColor color, bool enable){
if(id == this->id){ ShowItem(this, id, color, enable);
if(enable == false){
this->setPen(QPen(baseColor, widthHairLine/factor));
currentColor = baseColor;
} else {
this->setPen(QPen(color, widthHairLine/factor));
currentColor = color;
}
}
} }
void VToolArc::SetFactor(qreal factor){ void VToolArc::SetFactor(qreal factor){

View File

@ -100,15 +100,7 @@ void VToolLine::FullUpdateFromGui(int result){
} }
void VToolLine::ShowTool(qint64 id, Qt::GlobalColor color, bool enable){ void VToolLine::ShowTool(qint64 id, Qt::GlobalColor color, bool enable){
if(id == this->id){ ShowItem(this, id, color, enable);
if(enable == false){
this->setPen(QPen(baseColor, widthHairLine/factor));
currentColor = baseColor;
} else {
this->setPen(QPen(color, widthHairLine/factor));
currentColor = color;
}
}
} }
void VToolLine::SetFactor(qreal factor){ void VToolLine::SetFactor(qreal factor){
@ -117,24 +109,23 @@ void VToolLine::SetFactor(qreal factor){
} }
void VToolLine::ChangedActivDraw(const QString newName){ void VToolLine::ChangedActivDraw(const QString newName){
bool selectable = false;
if(nameActivDraw == newName){ if(nameActivDraw == newName){
this->setPen(QPen(Qt::black, widthHairLine/factor)); selectable = true;
this->setAcceptHoverEvents (true);
currentColor = Qt::black; currentColor = Qt::black;
VDrawTool::ChangedActivDraw(newName);
} else { } else {
this->setPen(QPen(Qt::gray, widthHairLine/factor)); selectable = false;
this->setAcceptHoverEvents (false);
currentColor = Qt::gray; currentColor = Qt::gray;
VDrawTool::ChangedActivDraw(newName);
} }
this->setPen(QPen(currentColor, widthHairLine/factor));
this->setAcceptHoverEvents (selectable);
VDrawTool::ChangedActivDraw(newName);
} }
void VToolLine::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ void VToolLine::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){
ContextMenu(dialogLine, this, event); ContextMenu(dialogLine, this, event);
} }
void VToolLine::AddToFile(){ void VToolLine::AddToFile(){
QDomElement domElement = doc->createElement("line"); QDomElement domElement = doc->createElement("line");
AddAttribute(domElement, "id", id); AddAttribute(domElement, "id", id);

View File

@ -41,14 +41,12 @@ VToolLinePoint::VToolLinePoint(VDomDocument *doc, VContainer *data, const qint64
void VToolLinePoint::ChangedActivDraw(const QString newName){ void VToolLinePoint::ChangedActivDraw(const QString newName){
if(nameActivDraw == newName){ if(nameActivDraw == newName){
mainLine->setPen(QPen(Qt::black, widthHairLine/factor));
currentColor = Qt::black; currentColor = Qt::black;
VToolPoint::ChangedActivDraw(newName);
} else { } else {
mainLine->setPen(QPen(Qt::gray, widthHairLine/factor));
currentColor = Qt::gray; currentColor = Qt::gray;
VToolPoint::ChangedActivDraw(newName);
} }
mainLine->setPen(QPen(currentColor, widthHairLine/factor));
VToolPoint::ChangedActivDraw(newName);
} }
void VToolLinePoint::RefreshGeometry(){ void VToolLinePoint::RefreshGeometry(){

View File

@ -54,43 +54,28 @@ void VToolPoint::UpdateNamePosition(qreal mx, qreal my){
} }
void VToolPoint::ChangedActivDraw(const QString newName){ void VToolPoint::ChangedActivDraw(const QString newName){
bool selectable = false;
if(nameActivDraw == newName){ if(nameActivDraw == newName){
this->setPen(QPen(Qt::black, widthHairLine/factor)); selectable = true;
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));
currentColor = Qt::black; currentColor = Qt::black;
VDrawTool::ChangedActivDraw(newName);
} else { } else {
this->setPen(QPen(Qt::gray, widthHairLine/factor)); selectable = false;
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));
currentColor = Qt::gray; 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){ void VToolPoint::ShowTool(qint64 id, Qt::GlobalColor color, bool enable){
if(id == this->id){ ShowItem(this, id, color, enable);
if(enable == false){
this->setPen(QPen(baseColor, widthHairLine/factor));
currentColor = baseColor;
} else {
this->setPen(QPen(color, widthHairLine/factor));
currentColor = color;
}
}
} }
void VToolPoint::SetFactor(qreal factor){ void VToolPoint::SetFactor(qreal factor){

View File

@ -246,33 +246,23 @@ void VToolSpline::RefreshGeometry(){
void VToolSpline::ChangedActivDraw(const QString newName){ void VToolSpline::ChangedActivDraw(const QString newName){
bool selectable = false;
if(nameActivDraw == newName){ if(nameActivDraw == newName){
this->setPen(QPen(Qt::black, widthHairLine/factor)); selectable = true;
this->setFlag(QGraphicsItem::ItemIsSelectable, true);
this->setAcceptHoverEvents(true);
currentColor = Qt::black; currentColor = Qt::black;
emit setEnabledPoint(true);
VDrawTool::ChangedActivDraw(newName);
} else { } else {
this->setPen(QPen(Qt::gray, widthHairLine/factor)); selectable = false;
this->setFlag(QGraphicsItem::ItemIsSelectable, false);
this->setAcceptHoverEvents (false);
currentColor = Qt::gray; 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){ void VToolSpline::ShowTool(qint64 id, Qt::GlobalColor color, bool enable){
if(id == this->id){ ShowItem(this, id, color, enable);
if(enable == false){
this->setPen(QPen(baseColor, widthHairLine/factor));
currentColor = baseColor;
} else {
this->setPen(QPen(color, widthHairLine/factor));
currentColor = color;
}
}
} }
void VToolSpline::SetFactor(qreal factor){ void VToolSpline::SetFactor(qreal factor){

View File

@ -187,33 +187,23 @@ void VToolSplinePath::UpdatePathPoint(QDomNode& node, VSplinePath &path){
} }
void VToolSplinePath::ChangedActivDraw(const QString newName){ void VToolSplinePath::ChangedActivDraw(const QString newName){
bool selectable = false;
if(nameActivDraw == newName){ if(nameActivDraw == newName){
this->setPen(QPen(Qt::black, widthHairLine/factor)); selectable = true;
this->setFlag(QGraphicsItem::ItemIsSelectable, true);
this->setAcceptHoverEvents(true);
currentColor = Qt::black; currentColor = Qt::black;
emit setEnabledPoint(true);
VDrawTool::ChangedActivDraw(newName);
} else { } else {
this->setPen(QPen(Qt::gray, widthHairLine/factor)); selectable = false;
this->setFlag(QGraphicsItem::ItemIsSelectable, false);
this->setAcceptHoverEvents (false);
currentColor = Qt::gray; 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){ void VToolSplinePath::ShowTool(qint64 id, Qt::GlobalColor color, bool enable){
if(id == this->id){ ShowItem(this, id, color, enable);
if(enable == false){
this->setPen(QPen(baseColor, widthHairLine/factor));
currentColor = baseColor;
} else {
this->setPen(QPen(color, widthHairLine/factor));
currentColor = color;
}
}
} }
void VToolSplinePath::SetFactor(qreal factor){ void VToolSplinePath::SetFactor(qreal factor){

View File

@ -95,8 +95,8 @@ QPointF VToolTriangle::FindPoint(const QPointF axisP1, const QPointF axisP2, con
} }
} }
if(c*c < a*a + b*b){ if(c*c < a*a + b*b){
return line.p2();
qWarning()<<tr("Can't find point.")<<Q_FUNC_INFO; qWarning()<<tr("Can't find point.")<<Q_FUNC_INFO;
return line.p2();
} }
} }
} }

View File

@ -25,9 +25,8 @@
#include "modelingTools/modelingtools.h" #include "modelingTools/modelingtools.h"
VToolDetail::VToolDetail(VDomDocument *doc, VContainer *data, const qint64 &id, Tool::Sources typeCreation, VToolDetail::VToolDetail(VDomDocument *doc, VContainer *data, const qint64 &id, Tool::Sources typeCreation,
VMainGraphicsScene *scene, QGraphicsItem *parent) VMainGraphicsScene *scene, QGraphicsItem *parent) :VAbstractTool(doc, data, id),
:VAbstractTool(doc, data, id), QGraphicsPathItem(parent), dialogDetail(QSharedPointer<DialogDetail>()), QGraphicsPathItem(parent), dialogDetail(QSharedPointer<DialogDetail>()), sceneDetails(scene){
sceneDetails(scene){
VDetail detail = data->GetDetail(id); VDetail detail = data->GetDetail(id);
QHash<qint64, VDataTool*>* tools = doc->getTools(); QHash<qint64, VDataTool*>* tools = doc->getTools();
Q_ASSERT(tools != 0); Q_ASSERT(tools != 0);