diff --git a/.hgignore b/.hgignore index 6f58ef173..2e058acbc 100644 --- a/.hgignore +++ b/.hgignore @@ -22,3 +22,6 @@ latex/ # Ignore file used QtCreator for user profile. *.pro.user + +# Ignore file Qt translation. +*.qm diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 000000000..dd9952069 --- /dev/null +++ b/AUTHORS @@ -0,0 +1,5 @@ +Author: + + (*) Roman Telezhinsky + Founder of the project. + diff --git a/ChangeLog b/ChangeLog new file mode 100644 index 000000000..f43868e56 --- /dev/null +++ b/ChangeLog @@ -0,0 +1,3 @@ +# Version 0.2.0 Released October 29, 2013 + + diff --git a/README b/README new file mode 100644 index 000000000..ccf3d0cc9 --- /dev/null +++ b/README @@ -0,0 +1,44 @@ +Valentina +========== +Open source project of creating a pattern making program, whose allow +create and modeling patterns of clothing. +Published under GNU GPL v3 license. + +Supported Platforms +=================== +The standalone binary packages support the following platforms: + +Windows XP SP2 or later +Ubuntu Linux 11.10 (32-bit) or later + +Building the sources requires Qt 5.0.0 or later. + +Compiling Valentina +==================== +Prerequisites: + * Qt 5.0.0 or later + * On Windows: + - MinGW or Visual Studio + +The installed toolchains have to match the one Qt was compiled with. + +You can build Valentina with + + cd $SOURCE_DIRECTORY + qmake -r + make (or mingw32-make or nmake or jom, depending on your platform) + +Installation ("make install") is not needed. + +Note:In order to build and use Valentina, the PATH environment variable +needs to be extended: + + PATH - to locate qmake, moc and other Qt tools +This is done by adding c:\Qt\%VERSION%\bin to the PATH variable. + +For newer versions of Windows, PATH can be extended through the +Control Panel|System|Advanced|Environment variables menu. + +You may also need to ensure that the locations of your compiler and +other build tools are listed in the PATH variable. This will depend on +your choice of software development environment. diff --git a/TODO b/TODO new file mode 100644 index 000000000..1499e59a6 --- /dev/null +++ b/TODO @@ -0,0 +1,33 @@ +Valentina TODO file. +For more information see https://bitbucket.org/dismine/valentina/issues + +(c) Valentina Team 2013 + + * Rotate details. + * Reflection details. + * Theme with icon for windows version of program. + * Label on detail. + * Checking integrity of file. + * Description of pattern. + * Type of lines. + * New way create detail. + * Tuck transfer. + * Point on arc, curve and curve path. + * Union details. + * Сonditions. + * New format name. + * Standard table of measurements. + * Localization. + * Window "Option". + * Undo/redo functionality in applications. + * Checking file integrity. + * Sketch drawing. + * Graduation card. + * Individual mode of construction pattern. + * Description about pattern in SVG file. + * Visualization. + + + + + diff --git a/Valentina.pro b/Valentina.pro index f94c2e337..15171136b 100644 --- a/Valentina.pro +++ b/Valentina.pro @@ -8,208 +8,21 @@ QT += core gui widgets xml svg -TARGET = Valentina TEMPLATE = app + +DEBUG_TARGET = Valentinad +RELEASE_TARGET = Valentina + CONFIG -= debug_and_release debug_and_release_target -CONFIG += c++11 +CONFIG += c++11 precompile_header -SOURCES += main.cpp\ - mainwindow.cpp \ - dialogs/dialogsinglepoint.cpp \ - widgets/vgraphicssimpletextitem.cpp \ - xml/vdomdocument.cpp \ - container/vpointf.cpp \ - container/vcontainer.cpp \ - tools/drawTools/vtoolpoint.cpp \ - container/calculator.cpp \ - dialogs/dialogincrements.cpp \ - container/vstandarttablecell.cpp \ - container/vincrementtablerow.cpp \ - widgets/doubledelegate.cpp \ - dialogs/dialogendline.cpp \ - tools/drawTools/vtoolendline.cpp \ - tools/drawTools/vtoolline.cpp \ - tools/vabstracttool.cpp \ - dialogs/dialogline.cpp \ - tools/drawTools/vtoolalongline.cpp \ - dialogs/dialogtool.cpp \ - dialogs/dialogalongline.cpp \ - tools/drawTools/vtoolshoulderpoint.cpp \ - dialogs/dialogshoulderpoint.cpp \ - tools/drawTools/vtoolnormal.cpp \ - dialogs/dialognormal.cpp \ - tools/drawTools/vtoolbisector.cpp \ - dialogs/dialogbisector.cpp \ - tools/drawTools/vtoollinepoint.cpp \ - tools/drawTools/vtoollineintersect.cpp \ - dialogs/dialoglineintersect.cpp \ - geometry/vspline.cpp \ - tools/drawTools/vtoolsinglepoint.cpp \ - geometry/varc.cpp \ - widgets/vcontrolpointspline.cpp \ - tools/drawTools/vtoolspline.cpp \ - dialogs/dialogspline.cpp \ - tools/drawTools/vtoolarc.cpp \ - dialogs/dialogarc.cpp \ - geometry/vsplinepoint.cpp \ - geometry/vsplinepath.cpp \ - tools/drawTools/vtoolsplinepath.cpp \ - dialogs/dialogsplinepath.cpp \ - widgets/vmaingraphicsscene.cpp \ - widgets/vmaingraphicsview.cpp \ - tools/vdatatool.cpp \ - xml/vtoolrecord.cpp \ - dialogs/dialoghistory.cpp \ - tools/drawTools/vtoolpointofcontact.cpp \ - dialogs/dialogpointofcontact.cpp \ - geometry/vnodedetail.cpp \ - geometry/vdetail.cpp \ - dialogs/dialogdetail.cpp \ - tools/vtooldetail.cpp \ - widgets/vtablegraphicsview.cpp \ - widgets/vitem.cpp \ - tablewindow.cpp \ - tools/nodeDetails/vnodearc.cpp \ - tools/nodeDetails/vnodepoint.cpp \ - tools/nodeDetails/vnodespline.cpp \ - tools/nodeDetails/vnodesplinepath.cpp \ - tools/drawTools/vdrawtool.cpp \ - tools/nodeDetails/vabstractnode.cpp \ - tools/modelingTools/vmodelingtool.cpp \ - tools/modelingTools/vmodelingalongline.cpp \ - tools/modelingTools/vmodelingarc.cpp \ - tools/modelingTools/vmodelingbisector.cpp \ - tools/modelingTools/vmodelingendline.cpp \ - tools/modelingTools/vmodelingline.cpp \ - tools/modelingTools/vmodelinglineintersect.cpp \ - tools/modelingTools/vmodelinglinepoint.cpp \ - tools/modelingTools/vmodelingnormal.cpp \ - tools/modelingTools/vmodelingpoint.cpp \ - tools/modelingTools/vmodelingpointofcontact.cpp \ - tools/modelingTools/vmodelingshoulderpoint.cpp \ - tools/modelingTools/vmodelingspline.cpp \ - tools/modelingTools/vmodelingsplinepath.cpp \ - exception/vexception.cpp \ - exception/vexceptionbadid.cpp \ - exception/vexceptionwrongparameterid.cpp \ - exception/vexceptionconversionerror.cpp \ - exception/vexceptionemptyparameter.cpp \ - exception/vexceptionobjecterror.cpp \ - widgets/vapplication.cpp \ - exception/vexceptionuniqueid.cpp +#DEFINES += ... -HEADERS += mainwindow.h \ - widgets/vmaingraphicsscene.h \ - dialogs/dialogsinglepoint.h \ - options.h \ - widgets/vgraphicssimpletextitem.h \ - xml/vdomdocument.h \ - container/vpointf.h \ - container/vcontainer.h \ - tools/drawTools/vtoolpoint.h \ - container/calculator.h \ - dialogs/dialogincrements.h \ - container/vstandarttablecell.h \ - container/vincrementtablerow.h \ - widgets/doubledelegate.h \ - dialogs/dialogendline.h \ - tools/drawTools/vtoolendline.h \ - tools/drawTools/vtoolline.h \ - tools/vabstracttool.h \ - dialogs/dialogline.h \ - tools/drawTools/vtoolalongline.h \ - dialogs/dialogtool.h \ - dialogs/dialogalongline.h \ - tools/drawTools/vtoolshoulderpoint.h \ - dialogs/dialogshoulderpoint.h \ - tools/drawTools/vtoolnormal.h \ - dialogs/dialognormal.h \ - tools/drawTools/vtoolbisector.h \ - dialogs/dialogbisector.h \ - tools/drawTools/vtoollinepoint.h \ - tools/drawTools/vtoollineintersect.h \ - dialogs/dialoglineintersect.h \ - geometry/vspline.h \ - tools/drawTools/vtoolsinglepoint.h \ - geometry/varc.h \ - widgets/vcontrolpointspline.h \ - tools/drawTools/vtoolspline.h \ - dialogs/dialogspline.h \ - tools/drawTools/vtoolarc.h \ - dialogs/dialogarc.h \ - geometry/vsplinepoint.h \ - geometry/vsplinepath.h \ - tools/drawTools/vtoolsplinepath.h \ - dialogs/dialogsplinepath.h \ - widgets/vmaingraphicsview.h \ - tools/vdatatool.h \ - xml/vtoolrecord.h \ - dialogs/dialoghistory.h \ - tools/drawTools/vtoolpointofcontact.h \ - dialogs/dialogpointofcontact.h \ - geometry/vnodedetail.h \ - geometry/vdetail.h \ - dialogs/dialogdetail.h \ - tools/vtooldetail.h \ - widgets/vtablegraphicsview.h \ - widgets/vitem.h \ - tablewindow.h \ - tools/tools.h \ - tools/drawTools/drawtools.h \ - tools/nodeDetails/nodedetails.h \ - tools/nodeDetails/vnodearc.h \ - tools/nodeDetails/vnodepoint.h \ - tools/nodeDetails/vnodespline.h \ - tools/nodeDetails/vnodesplinepath.h \ - stable.h \ - tools/drawTools/vdrawtool.h \ - tools/nodeDetails/vabstractnode.h \ - dialogs/dialogs.h \ - tools/modelingTools/modelingtools.h \ - tools/modelingTools/vmodelingtool.h \ - tools/modelingTools/vmodelingalongline.h \ - tools/modelingTools/vmodelingarc.h \ - tools/modelingTools/vmodelingbisector.h \ - tools/modelingTools/vmodelingendline.h \ - tools/modelingTools/vmodelingline.h \ - tools/modelingTools/vmodelinglineintersect.h \ - tools/modelingTools/vmodelinglinepoint.h \ - tools/modelingTools/vmodelingnormal.h \ - tools/modelingTools/vmodelingpoint.h \ - tools/modelingTools/vmodelingpointofcontact.h \ - tools/modelingTools/vmodelingshoulderpoint.h \ - tools/modelingTools/vmodelingspline.h \ - tools/modelingTools/vmodelingsplinepath.h \ - exception/vexception.h \ - exception/vexceptionbadid.h \ - exception/vexceptionwrongparameterid.h \ - exception/vexceptionconversionerror.h \ - exception/vexceptionemptyparameter.h \ - exception/vexceptionobjecterror.h \ - widgets/vapplication.h \ - exception/vexceptionuniqueid.h - -FORMS += mainwindow.ui \ - dialogs/dialogsinglepoint.ui \ - dialogs/dialogincrements.ui \ - dialogs/dialogendline.ui \ - dialogs/dialogline.ui \ - dialogs/dialogalongline.ui \ - dialogs/dialogshoulderpoint.ui \ - dialogs/dialognormal.ui \ - dialogs/dialogbisector.ui \ - dialogs/dialoglineintersect.ui \ - dialogs/dialogspline.ui \ - dialogs/dialogarc.ui \ - dialogs/dialogsplinepath.ui \ - dialogs/dialoghistory.ui \ - dialogs/dialogpointofcontact.ui \ - dialogs/dialogdetail.ui \ - tablewindow.ui - -RESOURCES += \ - icon.qrc \ - cursor.qrc +# Precompiled headers (PCH) +PRECOMPILED_HEADER = stable.h +win32-msvc* { + PRECOMPILED_SOURCE = stable.cpp +} # directory for executable file DESTDIR = bin @@ -226,28 +39,65 @@ RCC_DIR = rcc # files created uic UI_DIR = uic -# Use Precompiled headers (PCH) -PRECOMPILED_HEADER = stable.h +include(container/container.pri) +include(dialogs/dialogs.pri) +include(exception/exception.pri) +include(geometry/geometry.pri) +include(tools/tools.pri) +include(widgets/widgets.pri) +include(xml/xml.pri) + +SOURCES += main.cpp\ + mainwindow.cpp \ + tablewindow.cpp \ + stable.cpp + +HEADERS += mainwindow.h \ + options.h \ + tablewindow.h \ + stable.h \ + version.h + +FORMS += mainwindow.ui \ + tablewindow.ui + +RESOURCES += \ + icon.qrc \ + cursor.qrc TRANSLATIONS += translations/valentina_ru.ts \ translations/valentina_uk.ts CONFIG(debug, debug|release){ # Debug + QMAKE_CXX = ccache g++ + TARGET = $$DEBUG_TARGET + QMAKE_CXXFLAGS += -isystem "/usr/include/qt5" -isystem "/usr/include/qt5/QtWidgets" \ -isystem "/usr/include/qt5/QtXml" -isystem "/usr/include/qt5/QtGui" \ -isystem "/usr/include/qt5/QtCore" -isystem "$$OUT_PWD/uic" -isystem "$$OUT_PWD/moc/" \ + -isystem "$$OUT_PWD/rcc/" \ -Og -Wall -Wextra -pedantic -Weffc++ -Woverloaded-virtual -Wctor-dtor-privacy \ -Wnon-virtual-dtor -Wold-style-cast -Wconversion -Winit-self \ - -Wunreachable-code + -Wunreachable-code -Wcast-align -Wcast-qual -Wdisabled-optimization -Wfloat-equal \ + -Wformat -Wformat=2 -Wformat-nonliteral -Wformat-security -Wformat-y2k\ + -Winvalid-pch -Wunsafe-loop-optimizations -Wlong-long -Wmissing-format-attribute \ + -Wmissing-include-dirs -Wpacked -Wredundant-decls \ + -Wswitch-default -Wswitch-enum -Wuninitialized -Wunused-parameter -Wvariadic-macros \ + -Wlogical-op -Wnoexcept \ + -Wstrict-null-sentinel -Wstrict-overflow=5 -Wundef -Wno-unused -gdwarf-3 }else{ # Release + TARGET = $$RELEASE_TARGET + QMAKE_CXXFLAGS += -O1 + DEFINES += QT_NO_DEBUG_OUTPUT + QMAKE_EXTRA_COMPILERS += lrelease lrelease.input = TRANSLATIONS lrelease.output = ${QMAKE_FILE_BASE}.qm - lrelease.commands = $$[QT_INSTALL_BINS]/lrelease ${QMAKE_FILE_IN} -qm ${DESTDIR}${QMAKE_FILE_BASE}.qm + lrelease.commands = $$[QT_INSTALL_BINS]/lrelease ${QMAKE_FILE_IN} -qm "bin/"${QMAKE_FILE_BASE}.qm lrelease.CONFIG += no_link target_predeps } @@ -263,5 +113,3 @@ message(Data files: $$[QT_INSTALL_DATA]) message(Translation files: $$[QT_INSTALL_TRANSLATIONS]) message(Settings: $$[QT_INSTALL_SETTINGS]) message(Examples: $$[QT_INSTALL_EXAMPLES]) - - diff --git a/container/calculator.cpp b/container/calculator.cpp index d60077f27..ca6c71dea 100644 --- a/container/calculator.cpp +++ b/container/calculator.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file calculator.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,7 +24,7 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "calculator.h" #include @@ -31,11 +38,8 @@ #define FINISHED 10 #define EOL 9 -Calculator::Calculator(const VContainer *data):errorMsg(0), token(QString()), tok(0), token_type(0), - prog(QString()), index(0), data(data), debugFormula(QString()){ -} - -qreal Calculator::eval(QString prog, QString *errorMsg){ +qreal Calculator::eval(QString prog, QString *errorMsg) +{ this->errorMsg = errorMsg; this->errorMsg->clear(); debugFormula.clear(); @@ -49,10 +53,12 @@ qreal Calculator::eval(QString prog, QString *errorMsg){ return result; } -qreal Calculator::get_exp(){ +qreal Calculator::get_exp() +{ qreal result = 0; get_token(); - if(token.isEmpty()) { + if (token.isEmpty()) + { serror(2); return 0; } @@ -61,69 +67,86 @@ qreal Calculator::get_exp(){ return result; } -void Calculator::level2(qreal *result){ + +void Calculator::level2(qreal *result) +{ QChar op; qreal hold; level3(result); - while((op=token[0]) == '+' || op == '-') { + while ((op=token[0]) == '+' || op == '-') + { get_token(); level3(&hold); - arith(op,result,&hold); + arith(op, result, &hold); } } -void Calculator::level3(qreal *result){ +void Calculator::level3(qreal *result) +{ QChar op; qreal hold; level4(result); - while((op = token[0]) == '*' || op == '/' || op == '%') { + while ((op = token[0]) == '*' || op == '/' || op == '%') + { get_token(); level4(&hold); - arith(op,result,&hold); + arith(op, result, &hold); } } -void Calculator::level4(qreal *result){ +void Calculator::level4(qreal *result) +{ qreal hold; level5(result); - if(token[0] == '^') { + if (token[0] == '^') + { get_token(); level4(&hold); arith('^', result, &hold); } } -void Calculator::level5(qreal *result){ +void Calculator::level5(qreal *result) +{ QChar op; op = '\0'; - if((token_type==DELIMITER) && (token[0]=='+' || token[0]=='-')) { + if ((token_type==DELIMITER) && (token[0]=='+' || token[0]=='-')) + { op = token[0]; get_token(); } level6(result); - if(op != '\0') + if (op != '\0') + { unary(op, result); + } } -void Calculator::level6(qreal *result){ - if((token[0] == '(') && (token_type == DELIMITER)) { +void Calculator::level6(qreal *result) +{ + if ((token[0] == '(') && (token_type == DELIMITER)) + { get_token(); level2(result); - if(token[0] != ')') + if (token[0] != ')') + { serror(1); + } get_token(); } else primitive(result); } -void Calculator::primitive(qreal *result){ +void Calculator::primitive(qreal *result) +{ QString str; - switch(token_type) { + switch (token_type) + { case VARIABLE: *result = find_var(token); str = QString("%1").arg(*result, 0, 'f', 3); @@ -141,10 +164,12 @@ void Calculator::primitive(qreal *result){ } } -void Calculator::arith(QChar o, qreal *r, qreal *h){ - qreal t; +void Calculator::arith(QChar o, qreal *r, qreal *h) +{ + qreal t;//, ex; - switch(o.toLatin1()) { + switch (o.toLatin1()) + { case '-': *r = *r-*h; break; @@ -163,19 +188,26 @@ void Calculator::arith(QChar o, qreal *r, qreal *h){ break; case '^': *r = pow(*r, *h); - break; - } + break; + default: + break; + } } -void Calculator::unary(QChar o, qreal *r){ - if(o=='-') +void Calculator::unary(QChar o, qreal *r) +{ + if (o=='-') + { *r = -(*r); + } } -qreal Calculator::find_var(QString s){ +qreal Calculator::find_var(QString s) +{ bool ok = false; qreal value = data->FindVar(s, &ok); - if(!ok){ + if (ok == false) + { qDebug()<clear(); *errorMsg = e[error]; qDebug()</*%^=()",c) || c=='\n' || c=='\r' || c=='\0') +bool Calculator::isdelim(QChar c) +{ + if (StrChr(" ;,+-<>/*%^=()", c) || c=='\n' || c=='\r' || c=='\0') + { return true; + } return false; } -bool Calculator::iswhite(QChar c){ - if(c==' ' || c=='\t') +bool Calculator::iswhite(QChar c) +{ + if (c==' ' || c=='\t') + { return true; + } else + { return false; + } } -void Calculator::get_token(){ +void Calculator::get_token() +{ QString *temp; token_type=0; tok=0; token.clear(); temp=&token; - if(prog[index]=='\0') { /* end of file */ + if (prog[index]=='\0') + { /* end of file */ token="\0"; tok=FINISHED; token_type=DELIMITER; return; } - while(iswhite(prog[index])) ++index; /* skip spaces */ + while (iswhite(prog[index])) + { + ++index; /* skip spaces */ + } - if(prog[index]=='\r') { /* crtl */ + if (prog[index]=='\r') + { /* crtl */ ++index; ++index; tok= EOL; token='\r'; token.append('\n');token.append("\0"); @@ -242,7 +291,8 @@ void Calculator::get_token(){ return; } - if(StrChr("+-*^/%=;(),><", prog[index])) { /* delimiter */ + if (StrChr("+-*^/%=;(),><", prog[index])) + { /* delimiter */ *temp=prog[index]; index++; /* jump to the next position */ temp->append("\0"); @@ -250,20 +300,26 @@ void Calculator::get_token(){ debugFormula.append(token); return; } - if(prog[index]=='"') { /* quoted string */ + if (prog[index]=='"') + { /* quoted string */ index++; - while(prog[index] != '"' && prog[index] != '\r'){ + while (prog[index] != '"' && prog[index] != '\r') + { temp->append(prog[index]); index++; } - if(prog[index]=='\r') + if (prog[index]=='\r') + { serror(1); + } index++;temp->append("\0"); token_type=QUOTE; return; } - if(prog[index].isDigit()) { /* number */ - while(!isdelim(prog[index])){ + if (prog[index].isDigit()) + { /* number */ + while (isdelim(prog[index]) == false) + { temp->append(prog[index]); index++; } @@ -272,8 +328,10 @@ void Calculator::get_token(){ return; } - if(prog[index].isPrint()) { /* variable or command */ - while(!isdelim(prog[index])){ + if (prog[index].isPrint()) + { /* variable or command */ + while (isdelim(prog[index]) == false) + { temp->append(prog[index]); index++; } @@ -282,20 +340,28 @@ void Calculator::get_token(){ temp->append("\0"); /* Seen if there is a command line or a variable */ - if(token_type==STRING) { + if (token_type==STRING) + { tok=look_up(token); - if(!tok) + if (tok == false) + { token_type = VARIABLE; - else token_type = COMMAND; /* It is command */ - } + } + else + { + token_type = COMMAND; /* It is command */ + } + } return; } -bool Calculator::StrChr(QString string, QChar c){ +bool Calculator::StrChr(QString string, QChar c) +{ return string.contains(c, Qt::CaseInsensitive); } -void Calculator::putback(){ +void Calculator::putback() +{ QString t; t = token; index = index - t.size(); diff --git a/container/calculator.h b/container/calculator.h index c6be25745..28f7d6535 100644 --- a/container/calculator.h +++ b/container/calculator.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file calculator.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,57 +24,58 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef CALCULATOR_H #define CALCULATOR_H -#include #include "vcontainer.h" /** * @brief The Calculator class calculate formulas of pattern. Support operation +,-,/,* and braces. * Can replace name of variables her value. */ -class Calculator{ +class Calculator +{ public: /** * @brief Calculator class constructor. * @param data pointer to a variable container. */ - explicit Calculator(const VContainer *data); + explicit Calculator(const VContainer *data):errorMsg(0), token(QString()), tok(0), token_type(0), prog(QString()), + index(0), data(data), debugFormula(QString()){} /** * @brief eval calculate formula. * @param prog string of formula. * @return value of formula. */ - qreal eval(QString prog, QString *errorMsg); + qreal eval(QString prog, QString *errorMsg); private: Q_DISABLE_COPY(Calculator) /** * @brief errorMsg keeps error message of calculation. */ - QString *errorMsg; + QString *errorMsg; /** - * @brief token current token. + * @brief token теперішня лексема. */ - QString token; + QString token; /** * @brief tok internal representation of token. */ - qint32 tok; + qint32 tok; /** * @brief token_type type of token. */ - qint32 token_type; + qint32 token_type; /** * @brief prog string where keeps formula. */ - QString prog; + QString prog; /** * @brief index number character in string of formula. */ - qint32 index; + qint32 index; /** * @brief data container of all variables. */ @@ -75,99 +83,104 @@ private: /** * @brief debugFormula decoded string of formula. */ - QString debugFormula; + QString debugFormula; /** * @brief get_exp calculate formula. * @return value of formula. */ - qreal get_exp(); + qreal get_exp(); /** * @brief get_token return next token. */ - void get_token(); + void get_token(); /** * @brief StrChr checks whether the character belongs to the line. * @param string string with formula * @param c character. * @return true - belongs to the line, false - don't belongs to the line. */ - static bool StrChr(QString string, QChar c); + static bool StrChr(QString string, QChar c); /** * @brief putback returns the readout token back into the flow. */ - void putback(); + void putback(); /** * @brief level2 method of addition and subtraction of two terms. * @param result result of operation. */ - void level2(qreal *result); + void level2(qreal *result); /** * @brief level3 method of multiplication, division, finding percent. * @param result result of operation. */ - void level3(qreal *result); + void level3(qreal *result); /** * @brief level4 method of degree two numbers. * @param result result of operation. */ - void level4(qreal *result); + void level4(qreal *result); /** * @brief level5 method for finding unary plus or minus. * @param result result of operation. */ - void level5(qreal *result); + void level5(qreal *result); /** * @brief level6 processing method of the expression in brackets. * @param result result of operation. */ - void level6(qreal *result); + void level6(qreal *result); /** * @brief primitive method of determining the value of a variable by its name. * @param result result of operation. */ - void primitive(qreal *result); + void primitive(qreal *result); /** * @brief arith perform the specified arithmetic. The result is written to the first element. - * @param o sign operation. + * @param o sign of operation. * @param r first element. * @param h second element. */ - static void arith(QChar o, qreal *r, qreal *h); + static void arith(QChar o, qreal *r, qreal *h); /** * @brief unary method changes the sign. * @param o sign of symbol. * @param r element. */ - static void unary(QChar o, qreal *r); + static void unary(QChar o, qreal *r); /** * @brief find_var method is finding variable by name. * @param s name of variable. * @return value of variable. */ - qreal find_var(QString s); + qreal find_var(QString s); /** * @brief serror report an error * @param error error code */ - void serror(qint32 error); + void serror(qint32 error); /** - * @brief look_up Finding the internal format for the current token in the token table. + * @brief look_up finding the internal format for the current token in the token table. * @param s name of token. * @return internal number of token. */ - static char look_up(QString s); + static char look_up(QString s); /** * @brief isdelim return true if c delimiter. * @param c character. * @return true - delimiter, false - do not delimiter. */ - static bool isdelim(QChar c); + static bool isdelim(QChar c); + /** + * @brief isdelim return true if c delimiter. + * @param c character. + * @return true - delimiter, false - do not delimiter. + */ + static bool iswhite(QChar c); /** * @brief iswhite checks whether c space or tab. * @param c character. * @return true - space or tab, false - don't space and don't tab. */ - static bool iswhite(QChar c); }; #endif // CALCULATOR_H diff --git a/container/container.pri b/container/container.pri new file mode 100644 index 000000000..a6461484b --- /dev/null +++ b/container/container.pri @@ -0,0 +1,13 @@ +SOURCES += \ + container/vpointf.cpp \ + container/vincrementtablerow.cpp \ + container/vcontainer.cpp \ + container/calculator.cpp \ + container/vstandarttablecell.cpp + +HEADERS += \ + container/vstandarttablecell.h \ + container/vpointf.h \ + container/vincrementtablerow.h \ + container/vcontainer.h \ + container/calculator.h diff --git a/container/vcontainer.cpp b/container/vcontainer.cpp index 65292950e..5bbe38e15 100644 --- a/container/vcontainer.cpp +++ b/container/vcontainer.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vcontainer.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,16 +24,15 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "vcontainer.h" -#include -#include "options.h" -#include +#include "../exception/vexceptionbadid.h" qint64 VContainer::_id = 0; -VContainer::VContainer():base(QHash()), points(QHash()), +VContainer::VContainer() + :base(QHash()), points(QHash()), modelingPoints(QHash()), standartTable(QHash()), incrementTable(QHash()), lengthLines(QHash()), lineAngles(QHash()), splines(QHash()), @@ -34,18 +40,21 @@ VContainer::VContainer():base(QHash()), points(QHash()), arcs(QHash()), modelingArcs(QHash()), lengthArcs(QHash()), splinePaths(QHash()), modelingSplinePaths(QHash()), - details(QHash()){ + details(QHash()) +{ SetSize(500); SetGrowth(1760); CreateManTableIGroup (); } -VContainer &VContainer::operator =(const VContainer &data){ +VContainer &VContainer::operator =(const VContainer &data) +{ setData(data); return *this; } -VContainer::VContainer(const VContainer &data):base(QHash()), points(QHash()), +VContainer::VContainer(const VContainer &data) + :base(QHash()), points(QHash()), modelingPoints(QHash()), standartTable(QHash()), incrementTable(QHash()), lengthLines(QHash()), lineAngles(QHash()), splines(QHash()), @@ -53,18 +62,20 @@ VContainer::VContainer(const VContainer &data):base(QHash()), p lengthSplines(QHash()), arcs(QHash()), modelingArcs(QHash()), lengthArcs(QHash()), splinePaths(QHash()), modelingSplinePaths(QHash()), - details(QHash()){ + details(QHash()) +{ setData(data); } -void VContainer::setData(const VContainer &data){ +void VContainer::setData(const VContainer &data) +{ base = *data.DataBase(); points = *data.DataPoints(); modelingPoints = *data.DataModelingPoints(); standartTable = *data.DataStandartTable(); incrementTable = *data.DataIncrementTable(); lengthLines = *data.DataLengthLines(); - lineAngles = *data.DataLengthArcs(); + lineAngles = *data.DataLineAngles(); splines = *data.DataSplines(); modelingSplines = *data.DataModelingSplines(); lengthSplines = *data.DataLengthSplines(); @@ -76,190 +87,320 @@ void VContainer::setData(const VContainer &data){ details = *data.DataDetails(); } +VPointF VContainer::GetPoint(qint64 id) const +{ + return GetObject(points, id); +} + +VPointF VContainer::GetModelingPoint(qint64 id) const +{ + return GetObject(modelingPoints, id); +} + template -val VContainer::GetObject(const QHash &obj, key id){ - if(obj.contains(id)){ +val VContainer::GetObject(const QHash &obj, key id) +{ + if (obj.contains(id)) + { return obj.value(id); - } else { + } + else + { throw VExceptionBadId(tr("Can't find object"), id); } } -VPointF VContainer::GetPoint(qint64 id) const{ - return GetObject(points, id); -} - -VPointF VContainer::GetModelingPoint(qint64 id) const{ - return GetObject(modelingPoints, id); -} - -VStandartTableCell VContainer::GetStandartTableCell(const QString &name) const{ - Q_ASSERT(!name.isEmpty()); +VStandartTableCell VContainer::GetStandartTableCell(const QString &name) const +{ + Q_ASSERT(name.isEmpty()==false); return GetObject(standartTable, name); } -VIncrementTableRow VContainer::GetIncrementTableRow(const QString& name) const{ - Q_ASSERT(!name.isEmpty()); +VIncrementTableRow VContainer::GetIncrementTableRow(const QString& name) const +{ + Q_ASSERT(name.isEmpty()==false); return GetObject(incrementTable, name); } -qreal VContainer::GetLine(const QString &name) const{ - Q_ASSERT(!name.isEmpty()); +qreal VContainer::GetLine(const QString &name) const +{ + Q_ASSERT(name.isEmpty()==false); return GetObject(lengthLines, name); } -qreal VContainer::GetLineArc(const QString &name) const{ - Q_ASSERT(!name.isEmpty()); +qreal VContainer::GetLengthArc(const QString &name) const +{ + Q_ASSERT(name.isEmpty()==false); + return GetObject(lengthArcs, name); +} + +qreal VContainer::GetLengthSpline(const QString &name) const +{ + Q_ASSERT(name.isEmpty()==false); + return GetObject(lengthSplines, name); +} + +qreal VContainer::GetLineAngle(const QString &name) const +{ + Q_ASSERT(name.isEmpty()==false); return GetObject(lineAngles, name); } -VSpline VContainer::GetSpline(qint64 id) const{ +VSpline VContainer::GetSpline(qint64 id) const +{ return GetObject(splines, id); } -VSpline VContainer::GetModelingSpline(qint64 id) const{ +VSpline VContainer::GetModelingSpline(qint64 id) const +{ return GetObject(modelingSplines, id); } -VArc VContainer::GetArc(qint64 id) const{ +VArc VContainer::GetArc(qint64 id) const +{ return GetObject(arcs, id); } -VArc VContainer::GetModelingArc(qint64 id) const{ +VArc VContainer::GetModelingArc(qint64 id) const +{ return GetObject(modelingArcs, id); } -VSplinePath VContainer::GetSplinePath(qint64 id) const{ +VSplinePath VContainer::GetSplinePath(qint64 id) const +{ return GetObject(splinePaths, id); } -VSplinePath VContainer::GetModelingSplinePath(qint64 id) const{ +VSplinePath VContainer::GetModelingSplinePath(qint64 id) const +{ return GetObject(modelingSplinePaths, id); } -VDetail VContainer::GetDetail(qint64 id) const{ +VDetail VContainer::GetDetail(qint64 id) const +{ return GetObject(details, id); } -void VContainer::AddStandartTableCell(const QString& name, const VStandartTableCell& cell){ - standartTable[name] = cell; +qint64 VContainer::AddPoint(const VPointF &point) +{ + return AddObject(points, point); } -void VContainer::AddIncrementTableRow(const QString& name, const VIncrementTableRow& cell){ - incrementTable[name] = cell; +qint64 VContainer::AddModelingPoint(const VPointF &point) +{ + return AddObject(modelingPoints, point); } -qint64 VContainer::getId(){ - return _id; +qint64 VContainer::AddDetail(const VDetail &detail) +{ + return AddObject(details, detail); } -qint64 VContainer::getNextId(){ +qint64 VContainer::getNextId() +{ _id++; return _id; } -void VContainer::UpdateId(qint64 newId){ - if(newId > _id){ +void VContainer::UpdateId(qint64 newId) +{ + if (newId > _id) + { _id = newId; } } -QPainterPath VContainer::ContourPath(qint64 idDetail) const{ +QPainterPath VContainer::ContourPath(qint64 idDetail) const +{ VDetail detail = GetDetail(idDetail); QVector points; - for(qint32 i = 0; i< detail.CountNode(); ++i){ - switch(detail[i].getTypeTool()){ - case(Tool::NodePoint):{ - VPointF point = GetModelingPoint(detail[i].getId()); - points.append(point.toQPointF()); - } - break; - case(Tool::NodeArc):{ - VArc arc = GetModelingArc(detail[i].getId()); - qreal len1 = GetLengthContour(points, arc.GetPoints()); - qreal lenReverse = GetLengthContour(points, GetReversePoint(arc.GetPoints())); - if(len1 <= lenReverse){ - points << arc.GetPoints(); - } else { - points << GetReversePoint(arc.GetPoints()); + QVector pointsEkv; + for (ptrdiff_t i = 0; i< detail.CountNode(); ++i) + { + switch (detail[i].getTypeTool()) + { + case (Tool::NodePoint): + { + VPointF point = GetModelingPoint(detail[i].getId()); + points.append(point.toQPointF()); + if (detail.getSupplement() == true) + { + QPointF pEkv = point.toQPointF(); + pEkv.setX(pEkv.x()+detail[i].getMx()); + pEkv.setY(pEkv.y()+detail[i].getMy()); + pointsEkv.append(pEkv); + } } - } break; - case(Tool::NodeSpline):{ - VSpline spline = GetModelingSpline(detail[i].getId()); - qreal len1 = GetLengthContour(points, spline.GetPoints()); - qreal lenReverse = GetLengthContour(points, GetReversePoint(spline.GetPoints())); - if(len1 <= lenReverse){ - points << spline.GetPoints(); - } else { - points << GetReversePoint(spline.GetPoints()); + case (Tool::NodeArc): + { + VArc arc = GetModelingArc(detail[i].getId()); + qreal len1 = GetLengthContour(points, arc.GetPoints()); + qreal lenReverse = GetLengthContour(points, GetReversePoint(arc.GetPoints())); + if (len1 <= lenReverse) + { + points << arc.GetPoints(); + if (detail.getSupplement() == true) + { + pointsEkv << biasPoints(arc.GetPoints(), detail[i].getMx(), detail[i].getMy()); + } + } + else + { + points << GetReversePoint(arc.GetPoints()); + if (detail.getSupplement() == true) + { + pointsEkv << biasPoints(GetReversePoint(arc.GetPoints()), detail[i].getMx(), detail[i].getMy()); + } + } } - } break; - case(Tool::NodeSplinePath):{ - VSplinePath splinePath = GetModelingSplinePath(detail[i].getId()); - qreal len1 = GetLengthContour(points, splinePath.GetPathPoints()); - qreal lenReverse = GetLengthContour(points, GetReversePoint(splinePath.GetPathPoints())); - if(len1 <= lenReverse){ - points << splinePath.GetPathPoints(); - } else { - points << GetReversePoint(splinePath.GetPathPoints()); + case (Tool::NodeSpline): + { + VSpline spline = GetModelingSpline(detail[i].getId()); + qreal len1 = GetLengthContour(points, spline.GetPoints()); + qreal lenReverse = GetLengthContour(points, GetReversePoint(spline.GetPoints())); + if (len1 <= lenReverse) + { + points << spline.GetPoints(); + if (detail.getSupplement() == true) + { + pointsEkv << biasPoints(spline.GetPoints(), detail[i].getMx(), detail[i].getMy()); + } + } + else + { + points << GetReversePoint(spline.GetPoints()); + if (detail.getSupplement() == true) + { + pointsEkv << biasPoints(GetReversePoint(spline.GetPoints()), detail[i].getMx(), + detail[i].getMy()); + } + } } + break; + case (Tool::NodeSplinePath): + { + VSplinePath splinePath = GetModelingSplinePath(detail[i].getId()); + qreal len1 = GetLengthContour(points, splinePath.GetPathPoints()); + qreal lenReverse = GetLengthContour(points, GetReversePoint(splinePath.GetPathPoints())); + if (len1 <= lenReverse) + { + points << splinePath.GetPathPoints(); + if (detail.getSupplement() == true) + { + pointsEkv << biasPoints(splinePath.GetPathPoints(), detail[i].getMx(), detail[i].getMy()); + } + } + else + { + points << GetReversePoint(splinePath.GetPathPoints()); + if (detail.getSupplement() == true) + { + pointsEkv << biasPoints(GetReversePoint(splinePath.GetPathPoints()), detail[i].getMx(), + detail[i].getMy()); + } + } + } + break; + case (Tool::SplineTool): + break;//Nothing to do, just ignore. + default: + qWarning()<<"Get wrong tool type. Ignore."< points, const Detail::Equidistant &eqv, - const qreal &width) const{ +QVector VContainer::biasPoints(const QVector &points, const qreal &mx, const qreal &my) const +{ + QVector p; + for (qint32 i = 0; i < points.size(); ++i) + { + QPointF point = points.at(i); + point.setX(point.x() + mx); + point.setY(point.y() + my); + p.append(point); + } + return p; +} + +QPainterPath VContainer::Equidistant(QVector points, const Detail::Equidistant &eqv, const qreal &width) const +{ QPainterPath ekv; QVector ekvPoints; - if ( points.size() < 3 ){ + if ( points.size() < 3 ) + { qDebug()<<"Not enough points for build equidistant.\n"; return ekv; } - for (qint32 i = 0; i < points.size(); ++i ){ - if(i != points.size()-1){ - if(points[i] == points[i+1]){ + for (qint32 i = 0; i < points.size(); ++i ) + { + if (i != points.size()-1) + { + if (points[i] == points[i+1]) + { points.remove(i+1); } - } else { - if(points[i] == points[0]){ + } + else + { + if (points[i] == points[0]) + { points.remove(i); } } } - if(eqv == Detail::CloseEquidistant){ + if (eqv == Detail::CloseEquidistant) + { points.append(points.at(0)); } - for (qint32 i = 0; i < points.size(); ++i ){ - if ( i == 0 && eqv == Detail::CloseEquidistant){//перша точка, ламана замкнена - ekvPoints< points, const Detail::Equi } ekvPoints = CheckLoops(ekvPoints); ekv.moveTo(ekvPoints[0]); - for (qint32 i = 1; i < ekvPoints.count(); ++i){ + for (qint32 i = 1; i < ekvPoints.count(); ++i) + { ekv.lineTo(ekvPoints[i]); } return ekv; } -QLineF VContainer::ParallelLine(const QLineF &line, qreal width){ +QLineF VContainer::ParallelLine(const QLineF &line, qreal width) +{ Q_ASSERT(width > 0); - QLineF paralel = QLineF (SingleParallelPoint(line, 90, width), - SingleParallelPoint(QLineF(line.p2(), line.p1()), -90, width)); + QLineF paralel = QLineF (SingleParallelPoint(line, 90, width), SingleParallelPoint(QLineF(line.p2(), line.p1()), + -90, width)); return paralel; } -QPointF VContainer::SingleParallelPoint(const QLineF &line, const qreal &angle, const qreal &width){ +QPointF VContainer::SingleParallelPoint(const QLineF &line, const qreal &angle, const qreal &width) +{ Q_ASSERT(width > 0); - QLineF l = line; - l.setAngle( l.angle() + angle ); - l.setLength( width ); - return l.p2(); + QLineF pLine = line; + pLine.setAngle( pLine.angle() + angle ); + pLine.setLength( width ); + return pLine.p2(); } -QVector VContainer::EkvPoint(const QLineF &line1, const QLineF &line2, const qreal &width) const{ +QVector VContainer::EkvPoint(const QLineF &line1, const QLineF &line2, const qreal &width) const +{ Q_ASSERT(width > 0); QVector points; - if(line1.p2() != line2.p2()){ + if (line1.p2() != line2.p2()) + { qWarning()<<"Last point of two lines must be equal."; } QPointF CrosPoint; QLineF bigLine1 = ParallelLine(line1, width ); QLineF bigLine2 = ParallelLine(QLineF(line2.p2(), line2.p1()), width ); QLineF::IntersectType type = bigLine1.intersect( bigLine2, &CrosPoint ); - switch(type){ - case(QLineF::BoundedIntersection): - points.append(CrosPoint); - return points; - break; - case(QLineF::UnboundedIntersection):{ - QLineF line( line1.p2(), CrosPoint ); - if(line.length() > width + toPixel(8)){ - QLineF l; - l = QLineF(bigLine1.p2(), CrosPoint); - l.setLength(width); - points.append(l.p2()); - - l = QLineF(bigLine2.p1(), CrosPoint); - l.setLength(width); - points.append(l.p2()); - } else { + switch (type) + { + case (QLineF::BoundedIntersection): points.append(CrosPoint); return points; + break; + case (QLineF::UnboundedIntersection): + { + QLineF line( line1.p2(), CrosPoint ); + if (line.length() > width + toPixel(8)) + { + QLineF lineL; + lineL = QLineF(bigLine1.p2(), CrosPoint); + lineL.setLength(width); + points.append(lineL.p2()); + + lineL = QLineF(bigLine2.p1(), CrosPoint); + lineL.setLength(width); + points.append(lineL.p2()); + } + else + { + points.append(CrosPoint); + return points; + } + break; } - break; - } - case(QLineF::NoIntersection): - /*If we have correct lines this means lines lie on a line.*/ - points.append(bigLine1.p2()); - return points; - break; + case (QLineF::NoIntersection): + /*If we have correct lines this means lines lie on a line.*/ + points.append(bigLine1.p2()); + return points; + break; + default: + break; } return points; } -QVector VContainer::CheckLoops(const QVector &points) const{ +QVector VContainer::CheckLoops(const QVector &points) const +{ QVector ekvPoints; /*If we got less than 4 points no need seek loops.*/ - if(points.size() < 4){ + if (points.size() < 4) + { return ekvPoints; } bool closed = false; - if(points.at(0) == points.at(points.size()-1)){ + if (points.at(0) == points.at(points.size()-1)) + { closed = true; } qint32 i, j; - for(i = 0; i < points.size(); ++i){ + for (i = 0; i < points.size(); ++i) + { /*Last three points no need check.*/ - if(i >= points.size()-3){ + if (i >= points.size()-3) + { ekvPoints.append(points.at(i)); continue; } QPointF crosPoint; QLineF::IntersectType intersect = QLineF::NoIntersection; - QLineF line1(points.at(i),points.at(i+1)); - for(j = i+2; j < points.size()-1; ++j){ - QLineF line2(points.at(j),points.at(j+1)); + QLineF line1(points.at(i), points.at(i+1)); + for (j = i+2; j < points.size()-1; ++j) + { + QLineF line2(points.at(j), points.at(j+1)); intersect = line1.intersect(line2, &crosPoint); - if(intersect == QLineF::BoundedIntersection){ + if (intersect == QLineF::BoundedIntersection) + { break; } } - if(intersect == QLineF::BoundedIntersection){ - if(i == 0 && j+1 == points.size()-1 && closed){ + if (intersect == QLineF::BoundedIntersection) + { + if (i == 0 && j+1 == points.size()-1 && closed) + { /*We got closed contour.*/ ekvPoints.append(points.at(i)); - } else { + } + else + { /*We found loop.*/ ekvPoints.append(points.at(i)); ekvPoints.append(crosPoint); ekvPoints.append(points.at(j+1)); i = j + 2; } - } else { + } + else + { /*We did not found loop.*/ ekvPoints.append(points.at(i)); } @@ -375,105 +541,67 @@ QVector VContainer::CheckLoops(const QVector &points) const{ return ekvPoints; } -void VContainer::PrepareDetails(QVector &list) const{ +void VContainer::PrepareDetails(QVector &list) const +{ QHashIterator iDetail(details); - while (iDetail.hasNext()) { + while (iDetail.hasNext()) + { iDetail.next(); list.append(new VItem(ContourPath(iDetail.key()), list.size())); } } -void VContainer::RemoveIncrementTableRow(const QString& name){ - incrementTable.remove(name); -} - template -void VContainer::UpdateObject(QHash &obj, const qint64 &id, const val& point){ +void VContainer::UpdateObject(QHash &obj, const qint64 &id, const val& point) +{ Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0"); obj[id] = point; UpdateId(id); } -void VContainer::UpdatePoint(qint64 id, const VPointF& point){ - UpdateObject(points, id, point); -} - -void VContainer::UpdateModelingPoint(qint64 id, const VPointF &point){ - UpdateObject(modelingPoints, id, point); -} - -void VContainer::UpdateDetail(qint64 id, const VDetail &detail){ - UpdateObject(details, id, detail); -} - -void VContainer::UpdateSpline(qint64 id, const VSpline &spl){ - UpdateObject(splines, id, spl); -} - -void VContainer::UpdateModelingSpline(qint64 id, const VSpline &spl){ - UpdateObject(modelingSplines, id, spl); -} - -void VContainer::UpdateSplinePath(qint64 id, const VSplinePath &splPath){ - UpdateObject(splinePaths, id, splPath); -} - -void VContainer::UpdateModelingSplinePath(qint64 id, const VSplinePath &splPath){ - UpdateObject(modelingSplinePaths, id, splPath); -} - -void VContainer::UpdateArc(qint64 id, const VArc &arc){ - UpdateObject(arcs, id, arc); -} - -void VContainer::UpdateModelingArc(qint64 id, const VArc &arc){ - UpdateObject(modelingArcs, id, arc); -} - -void VContainer::UpdateStandartTableCell(const QString& name, const VStandartTableCell& cell){ - standartTable[name] = cell; -} - -void VContainer::UpdateIncrementTableRow(const QString& name, const VIncrementTableRow& cell){ - incrementTable[name] = cell; -} - -void VContainer::AddLengthSpline(const QString &name, const qreal &value){ - Q_ASSERT(!name.isEmpty()); +void VContainer::AddLengthSpline(const QString &name, const qreal &value) +{ + Q_ASSERT(name.isEmpty() == false); lengthSplines[name] = value; } -void VContainer::AddLengthArc(const qint64 ¢er, const qint64 &id){ - AddLengthArc(GetNameArc(center, id), GetArc(id).GetLength()); +void VContainer::AddLengthArc(const qint64 &id) +{ + AddLengthArc(GetArc(id).name(), toMM(GetArc(id).GetLength())); } -void VContainer::AddLengthArc(const QString &name, const qreal &value){ - Q_ASSERT(!name.isEmpty()); +void VContainer::AddLengthArc(const QString &name, const qreal &value) +{ + Q_ASSERT(name.isEmpty() == false); lengthArcs[name] = value; } -void VContainer::AddLineAngle(const QString &name, const qreal &value){ - Q_ASSERT(!name.isEmpty()); +void VContainer::AddLineAngle(const QString &name, const qreal &value) +{ + Q_ASSERT(name.isEmpty() == false); lineAngles[name] = value; } -qreal VContainer::GetValueStandartTableCell(const QString& name) const{ +qreal VContainer::GetValueStandartTableCell(const QString& name) const +{ VStandartTableCell cell = GetStandartTableCell(name); - qreal k_size = ( static_cast (size()/10.0) - 50.0 ) / 2.0; + qreal k_size = ( static_cast (size()/10.0) - 50.0 ) / 2.0; qreal k_growth = ( static_cast (growth()/10.0) - 176.0 ) / 6.0; - qreal value = cell.GetBase() + k_size*cell.GetKsize() + k_growth*cell.GetKgrowth(); + qreal value = cell.GetBase() + k_size*cell.GetKsize() + k_growth*cell.GetKgrowth(); return value; } -qreal VContainer::GetValueIncrementTableRow(const QString& name) const{ +qreal VContainer::GetValueIncrementTableRow(const QString& name) const +{ VIncrementTableRow cell = GetIncrementTableRow(name); - qreal k_size = ( static_cast (size()/10.0) - 50.0 ) / 2.0; + qreal k_size = ( static_cast (size()/10.0) - 50.0 ) / 2.0; qreal k_growth = ( static_cast (growth()/10.0) - 176.0 ) / 6.0; qreal value = cell.getBase() + k_size*cell.getKsize() + k_growth*cell.getKgrowth(); return value; } -void VContainer::Clear(){ +void VContainer::Clear() +{ _id = 0; standartTable.clear(); incrementTable.clear(); @@ -489,299 +617,201 @@ void VContainer::Clear(){ CreateManTableIGroup (); } -void VContainer::ClearObject(){ +void VContainer::ClearObject() +{ points.clear(); splines.clear(); arcs.clear(); splinePaths.clear(); } -void VContainer::ClearIncrementTable(){ - incrementTable.clear(); -} - -void VContainer::ClearLengthLines(){ - lengthLines.clear(); -} - -void VContainer::ClearLengthSplines(){ - lengthSplines.clear(); -} - -void VContainer::ClearLengthArcs(){ - lengthArcs.clear(); -} - -void VContainer::ClearLineAngles(){ - lineAngles.clear(); -} - -void VContainer::SetSize(qint32 size){ - base["Сг"] = size; -} - -void VContainer::SetGrowth(qint32 growth){ - base["Р"] = growth; -} - -qint32 VContainer::size() const{ - return base.value("Сг"); -} - -qint32 VContainer::growth() const{ - return base.value("Р"); -} - -bool VContainer::IncrementTableContains(const QString& name){ - return incrementTable.contains(name); -} - -qreal VContainer::FindVar(const QString &name, bool *ok)const{ - if(base.contains(name)){ +qreal VContainer::FindVar(const QString &name, bool *ok)const +{ + if (base.contains(name)) + { *ok = true; return base.value(name); } - if(standartTable.contains(name)){ + if (standartTable.contains(name)) + { *ok = true; return GetValueStandartTableCell(name); } - if(incrementTable.contains(name)){ + if (incrementTable.contains(name)) + { *ok = true; return GetValueIncrementTableRow(name); } - if(lengthLines.contains(name)){ + if (lengthLines.contains(name)) + { *ok = true; return lengthLines.value(name); } - if(lengthArcs.contains(name)){ + if (lengthArcs.contains(name)) + { *ok = true; return lengthArcs.value(name); } - if(lineAngles.contains(name)){ + if (lineAngles.contains(name)) + { *ok = true; return lineAngles.value(name); } + if (lengthSplines.contains(name)) + { + *ok = true; + return lengthSplines.value(name); + } *ok = false; return 0; } -const QHash *VContainer::DataPoints() const{ - return &points; -} - -const QHash *VContainer::DataModelingPoints() const{ - return &modelingPoints; -} - -const QHash *VContainer::DataSplines() const{ - return &splines; -} - -const QHash *VContainer::DataModelingSplines() const{ - return &modelingSplines; -} - -const QHash *VContainer::DataArcs() const{ - return &arcs; -} - -const QHash *VContainer::DataModelingArcs() const{ - return &modelingArcs; -} - -const QHash *VContainer::DataBase() const{ - return &base; -} - -const QHash *VContainer::DataStandartTable() const{ - return &standartTable; -} - -const QHash *VContainer::DataIncrementTable() const{ - return &incrementTable; -} - -const QHash *VContainer::DataLengthLines() const{ - return &lengthLines; -} - -const QHash *VContainer::DataLengthSplines() const{ - return &lengthSplines; -} - -const QHash *VContainer::DataLengthArcs() const{ - return &lengthArcs; -} - -const QHash *VContainer::DataLineAngles() const{ - return &lineAngles; -} - -const QHash *VContainer::DataSplinePaths() const{ - return &splinePaths; -} - -const QHash *VContainer::DataModelingSplinePaths() const{ - return &modelingSplinePaths; -} - -const QHash *VContainer::DataDetails() const{ - return &details; -} - -void VContainer::AddLine(const qint64 &firstPointId, const qint64 &secondPointId, Draw::Draws mode){ +void VContainer::AddLine(const qint64 &firstPointId, const qint64 &secondPointId, const Draw::Draws &mode) +{ QString nameLine = GetNameLine(firstPointId, secondPointId, mode); VPointF first; VPointF second; - if(mode == Draw::Calculation){ + if (mode == Draw::Calculation) + { first = GetPoint(firstPointId); second = GetPoint(secondPointId); - } else { + } + else + { first = GetModelingPoint(firstPointId); second = GetModelingPoint(secondPointId); } - AddLengthLine(nameLine, QLineF(first.toQPointF(), second.toQPointF()).length()/PrintDPI*25.4); + AddLengthLine(nameLine, toMM(QLineF(first.toQPointF(), second.toQPointF()).length())); nameLine = GetNameLineAngle(firstPointId, secondPointId, mode); AddLineAngle(nameLine, QLineF(first.toQPointF(), second.toQPointF()).angle()); } +qint64 VContainer::AddSpline(const VSpline &spl) +{ + return AddObject(splines, spl); +} + +qint64 VContainer::AddModelingSpline(const VSpline &spl) +{ + return AddObject(modelingSplines, spl); +} + +qint64 VContainer::AddSplinePath(const VSplinePath &splPath) +{ + return AddObject(splinePaths, splPath); +} + +qint64 VContainer::AddModelingSplinePath(const VSplinePath &splPath) +{ + return AddObject(modelingSplinePaths, splPath); +} + +qint64 VContainer::AddArc(const VArc &arc) +{ + return AddObject(arcs, arc); +} + +qint64 VContainer::AddModelingArc(const VArc &arc) +{ + return AddObject(modelingArcs, arc); +} + template -qint64 VContainer::AddObject(QHash &obj, const val& value){ +qint64 VContainer::AddObject(QHash &obj, const val& value) +{ qint64 id = getNextId(); obj[id] = value; return id; } -qint64 VContainer::AddPoint(const VPointF& point){ - return AddObject(points, point); -} - -qint64 VContainer::AddModelingPoint(const VPointF &point){ - return AddObject(modelingPoints, point); -} - -qint64 VContainer::AddDetail(const VDetail &detail){ - return AddObject(details, detail); -} - -qint64 VContainer::AddSpline(const VSpline &spl){ - return AddObject(splines, spl); -} - -qint64 VContainer::AddModelingSpline(const VSpline &spl){ - return AddObject(modelingSplines, spl); -} - -qint64 VContainer::AddSplinePath(const VSplinePath &splPath){ - return AddObject(splinePaths, splPath); -} - -qint64 VContainer::AddModelingSplinePath(const VSplinePath &splPath){ - return AddObject(modelingSplinePaths, splPath); -} - -qint64 VContainer::AddArc(const VArc &arc){ - return AddObject(arcs, arc); -} - -qint64 VContainer::AddModelingArc(const VArc &arc){ - return AddObject(modelingArcs, arc); -} - -QString VContainer::GetNameLine(const qint64 &firstPoint, const qint64 &secondPoint, Draw::Draws mode) const{ +QString VContainer::GetNameLine(const qint64 &firstPoint, const qint64 &secondPoint, const Draw::Draws &mode) const +{ VPointF first; VPointF second; - if(mode == Draw::Calculation){ + if (mode == Draw::Calculation) + { first = GetPoint(firstPoint); second = GetPoint(secondPoint); - } else { + } + else + { first = GetModelingPoint(firstPoint); second = GetModelingPoint(secondPoint); } return QString("Line_%1_%2").arg(first.name(), second.name()); } -QString VContainer::GetNameLineAngle(const qint64 &firstPoint, const qint64 &secondPoint, - Draw::Draws mode) const{ +QString VContainer::GetNameLineAngle(const qint64 &firstPoint, const qint64 &secondPoint, const Draw::Draws &mode) const +{ VPointF first; VPointF second; - if(mode == Draw::Calculation){ + if (mode == Draw::Calculation) + { first = GetPoint(firstPoint); second = GetPoint(secondPoint); - } else { + } + else + { first = GetModelingPoint(firstPoint); second = GetModelingPoint(secondPoint); } return QString("AngleLine_%1_%2").arg(first.name(), second.name()); } -QString VContainer::GetNameSpline(const qint64 &firstPoint, const qint64 &secondPoint, - Draw::Draws mode) const{ - VPointF first; - VPointF second; - if(mode == Draw::Calculation){ - first = GetPoint(firstPoint); - second = GetPoint(secondPoint); - } else { - first = GetModelingPoint(firstPoint); - second = GetModelingPoint(secondPoint); - } - return QString("Spl_%1_%2").arg(first.name(), second.name()); +void VContainer::UpdatePoint(qint64 id, const VPointF &point) +{ + UpdateObject(points, id, point); } -QString VContainer::GetNameSplinePath(const VSplinePath &path, Draw::Draws mode) const{ - if(path.Count() == 0){ - return QString(); - } - QString name("SplPath"); - for(qint32 i = 1; i <= path.Count(); ++i){ - VSpline spl = path.GetSpline(i); - VPointF first; - VPointF second; - if(mode == Draw::Calculation){ - first = GetPoint(spl.GetP1()); - second = GetPoint(spl.GetP4()); - } else { - first = GetModelingPoint(spl.GetP1()); - second = GetModelingPoint(spl.GetP4()); - } - QString splName = QString("_%1_%2").arg(first.name(), second.name()); - name.append(splName); - } - return name; +void VContainer::UpdateModelingPoint(qint64 id, const VPointF &point) +{ + UpdateObject(modelingPoints, id, point); } -QString VContainer::GetNameArc(const qint64 ¢er, const qint64 &id, Draw::Draws mode) const{ - VPointF centerPoint; - if(mode == Draw::Calculation){ - centerPoint = GetPoint(center); - } else { - centerPoint = GetModelingPoint(center); - } - return QString ("Arc(%1)%2").arg(centerPoint.name()).arg(id); +void VContainer::UpdateDetail(qint64 id, const VDetail &detail) +{ + UpdateObject(details, id, detail); } -void VContainer::AddLengthLine(const QString &name, const qreal &value){ - Q_ASSERT(!name.isEmpty()); +void VContainer::UpdateSpline(qint64 id, const VSpline &spl) +{ + UpdateObject(splines, id, spl); +} + +void VContainer::UpdateModelingSpline(qint64 id, const VSpline &spl) +{ + UpdateObject(modelingSplines, id, spl); +} + +void VContainer::UpdateSplinePath(qint64 id, const VSplinePath &splPath) +{ + UpdateObject(splinePaths, id, splPath); +} + +void VContainer::UpdateModelingSplinePath(qint64 id, const VSplinePath &splPath) +{ + UpdateObject(modelingSplinePaths, id, splPath); +} + +void VContainer::UpdateArc(qint64 id, const VArc &arc) +{ + UpdateObject(arcs, id, arc); +} + +void VContainer::UpdateModelingArc(qint64 id, const VArc &arc) +{ + UpdateObject(modelingArcs, id, arc); +} + +void VContainer::AddLengthLine(const QString &name, const qreal &value) +{ + Q_ASSERT(name.isEmpty() == false); lengthLines[name] = value; } -void VContainer::AddLengthSpline(const qint64 &firstPointId, const qint64 &secondPointId, Draw::Draws mode){ - QString nameLine = GetNameSpline(firstPointId, secondPointId, mode); - VPointF first; - VPointF second; - if(mode == Draw::Calculation){ - first = GetPoint(firstPointId); - second = GetPoint(secondPointId); - } else { - first = GetModelingPoint(firstPointId); - second = GetModelingPoint(secondPointId); - } - AddLengthSpline(nameLine, QLineF(first.toQPointF(), second.toQPointF()).length()); -} - -void VContainer::CreateManTableIGroup (){ +void VContainer::CreateManTableIGroup () +{ AddStandartTableCell("Pkor", VStandartTableCell(84, 0, 3)); AddStandartTableCell("Pkor", VStandartTableCell(84, 0, 3)); AddStandartTableCell("Vtos", VStandartTableCell(1450, 2, 51)); @@ -794,18 +824,17 @@ void VContainer::CreateManTableIGroup (){ AddStandartTableCell("Vzy", VStandartTableCell(1328, 0, 49)); AddStandartTableCell("Vlop", VStandartTableCell(1320, 0, 49)); AddStandartTableCell("Vps", VStandartTableCell(811, -1, 36)); - AddStandartTableCell("Osh", VStandartTableCell(404,8, 2)); - AddStandartTableCell("OgI", VStandartTableCell(1034, 36, 4)); - AddStandartTableCell("OgII", VStandartTableCell(1044, 38, 2)); - AddStandartTableCell("OgIII", VStandartTableCell(1000, 40, 0)); - AddStandartTableCell("Ot", VStandartTableCell(780, 40, 0)); - AddStandartTableCell("Ob", VStandartTableCell(984, 30, 10)); - AddStandartTableCell("ObI", VStandartTableCell(964, 24, 12)); + AddStandartTableCell("Ssh", VStandartTableCell(202, 4, 1)); + AddStandartTableCell("SgI", VStandartTableCell(517, 18, 2)); + AddStandartTableCell("SgII", VStandartTableCell(522, 19, 1)); + AddStandartTableCell("SgIII", VStandartTableCell(500, 20, 0)); + AddStandartTableCell("St", VStandartTableCell(390, 20, 0)); + AddStandartTableCell("Sb", VStandartTableCell(492, 15, 5)); + AddStandartTableCell("SbI", VStandartTableCell(482, 12, 6)); AddStandartTableCell("Obed", VStandartTableCell(566, 18, 6)); AddStandartTableCell("Ok", VStandartTableCell(386, 8, 8)); AddStandartTableCell("Oi", VStandartTableCell(380, 8, 6)); AddStandartTableCell("Osch", VStandartTableCell(234, 4, 4)); - AddStandartTableCell("Os", VStandartTableCell(350, 2, 8)); AddStandartTableCell("Dsb", VStandartTableCell(1120, 0, 44)); AddStandartTableCell("Dsp", VStandartTableCell(1110, 0, 43)); AddStandartTableCell("Dn", VStandartTableCell(826, -3, 37)); @@ -839,20 +868,24 @@ void VContainer::CreateManTableIGroup (){ AddStandartTableCell("Sb", VStandartTableCell(504, 15, 4)); } -QVector VContainer::GetReversePoint(const QVector &points) const{ +QVector VContainer::GetReversePoint(const QVector &points) const +{ Q_ASSERT(points.size() > 0); QVector reversePoints; - for (qint32 i = points.size() - 1; i >= 0; --i) { + for (qint32 i = points.size() - 1; i >= 0; --i) + { reversePoints.append(points.at(i)); } return reversePoints; } -qreal VContainer::GetLengthContour(const QVector &contour, const QVector &newPoints) const{ +qreal VContainer::GetLengthContour(const QVector &contour, const QVector &newPoints) const +{ qreal length = 0; QVector points; points << contour << newPoints; - for (qint32 i = 0; i < points.size()-1; ++i) { + for (qint32 i = 0; i < points.size()-1; ++i) + { QLineF line(points.at(i), points.at(i+1)); length += line.length(); } diff --git a/container/vcontainer.h b/container/vcontainer.h index a1b836594..c093f0477 100644 --- a/container/vcontainer.h +++ b/container/vcontainer.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vcontainer.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,194 +24,179 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef VCONTAINER_H #define VCONTAINER_H -#include #include "vstandarttablecell.h" #include "vincrementtablerow.h" -#include "geometry/varc.h" -#include "geometry/vsplinepath.h" -#include "geometry/vdetail.h" -#include "widgets/vitem.h" -#include +#include "../geometry/varc.h" +#include "../geometry/vsplinepath.h" +#include "../geometry/vdetail.h" +#include "../widgets/vitem.h" /** * @brief The VContainer class container of all variables. */ -class VContainer{ +class VContainer +{ Q_DECLARE_TR_FUNCTIONS(VContainer) public: - /** - * @brief VContainer create empty container - */ - VContainer(); - /** - * @brief operator = copy constructor - * @param data container - * @return copy container - */ - VContainer &operator=(const VContainer &data); - /** - * @brief VContainer create container from another container - * @param data container - */ - VContainer(const VContainer &data); + /** + * @brief VContainer create empty container + */ + VContainer(); + /** + * @brief operator = copy constructor + * @param data container + * @return copy container + */ + VContainer &operator=(const VContainer &data); + /** + * @brief VContainer create container from another container + * @param data container + */ + VContainer(const VContainer &data); /** * @brief setData copy data from container * @param data container */ - void setData(const VContainer &data); + void setData(const VContainer &data); /** * @brief GetPoint returns a point by id * @param id id of point * @return point */ - VPointF GetPoint(qint64 id) const; + VPointF GetPoint(qint64 id) const; /** * @brief GetModelingPoint return a modeling point by id * @param id id of modeling point * @return modeling point */ - VPointF GetModelingPoint(qint64 id) const; + VPointF GetModelingPoint(qint64 id) const; /** * @brief GetStandartTableCell * @param name * @return */ - VStandartTableCell GetStandartTableCell(const QString& name) const; - VIncrementTableRow GetIncrementTableRow(const QString& name) const; - qreal GetLine(const QString &name) const; - qreal GetLineArc(const QString &name) const; - VSpline GetSpline(qint64 id) const; - VSpline GetModelingSpline(qint64 id) const; - VArc GetArc(qint64 id) const; - VArc GetModelingArc(qint64 id) const; - VSplinePath GetSplinePath(qint64 id) const; - VSplinePath GetModelingSplinePath(qint64 id) const; - VDetail GetDetail(qint64 id) const; - static qint64 getId(); - qint64 AddPoint(const VPointF& point); - qint64 AddModelingPoint(const VPointF& point); - qint64 AddDetail(const VDetail& detail); - void AddStandartTableCell(const QString& name, - const VStandartTableCell& cell); - void AddIncrementTableRow(const QString& name, - const VIncrementTableRow &cell); - void AddLengthLine(const QString &name, const qreal &value); - void AddLengthSpline(const qint64 &firstPointId, - const qint64 &secondPointId, - Draw::Draws mode = Draw::Calculation); - void AddLengthSpline(const QString &name, const qreal &value); - void AddLengthArc(const qint64 ¢er, const qint64 &id); - void AddLengthArc(const QString &name, const qreal &value); - void AddLineAngle(const QString &name, const qreal &value); - void AddLine(const qint64 &firstPointId, const qint64 &secondPointId, - Draw::Draws mode = Draw::Calculation); - qint64 AddSpline(const VSpline& spl); - qint64 AddModelingSpline(const VSpline& spl); - qint64 AddSplinePath(const VSplinePath& splPath); - qint64 AddModelingSplinePath(const VSplinePath& splPath); - qint64 AddArc(const VArc& arc); - qint64 AddModelingArc(const VArc& arc); - QString GetNameLine(const qint64 &firstPoint, const qint64 &secondPoint, - Draw::Draws mode = Draw::Calculation) const; - QString GetNameLineAngle(const qint64 &firstPoint, - const qint64 &secondPoint, - Draw::Draws mode = Draw::Calculation) const; - QString GetNameSpline(const qint64 &firstPoint, const qint64 &secondPoint, - Draw::Draws mode = Draw::Calculation) const; - QString GetNameSplinePath(const VSplinePath &path, - Draw::Draws mode = Draw::Calculation) const; - QString GetNameArc(const qint64 ¢er, const qint64 &id, - Draw::Draws mode = Draw::Calculation) const; - void UpdatePoint(qint64 id, const VPointF& point); - void UpdateModelingPoint(qint64 id, const VPointF& point); - void UpdateDetail(qint64 id, const VDetail& detail); - void UpdateSpline(qint64 id, const VSpline& spl); - void UpdateModelingSpline(qint64 id, const VSpline& spl); - void UpdateSplinePath(qint64 id, const VSplinePath& splPath); - void UpdateModelingSplinePath(qint64 id, const VSplinePath& splPath); - void UpdateArc(qint64 id, const VArc& arc); - void UpdateModelingArc(qint64 id, const VArc& arc); - void UpdateStandartTableCell(const QString& name, - const VStandartTableCell& cell); - void UpdateIncrementTableRow(const QString& name, - const VIncrementTableRow& cell); - qreal GetValueStandartTableCell(const QString& name) const; - qreal GetValueIncrementTableRow(const QString& name) const; - void Clear(); - void ClearObject(); - void ClearIncrementTable(); - void ClearLengthLines(); - void ClearLengthSplines(); - void ClearLengthArcs(); - void ClearLineAngles(); - void SetSize(qint32 size); - void SetGrowth(qint32 growth); - qint32 size() const; - qint32 growth() const; - qreal FindVar(const QString& name, bool *ok)const; - bool IncrementTableContains(const QString& name); - static qint64 getNextId(); - void RemoveIncrementTableRow(const QString& name); - const QHash *DataPoints() const; - const QHash *DataModelingPoints() const; - const QHash *DataSplines() const; - const QHash *DataModelingSplines() const; - const QHash *DataArcs() const; - const QHash *DataModelingArcs() const; - const QHash *DataBase() const; - const QHash *DataStandartTable() const; - const QHash *DataIncrementTable() const; - const QHash *DataLengthLines() const; - const QHash *DataLengthSplines() const; - const QHash *DataLengthArcs() const; - const QHash *DataLineAngles() const; - const QHash *DataSplinePaths() const; - const QHash *DataModelingSplinePaths() const; - const QHash *DataDetails() const; - static void UpdateId(qint64 newId); - QPainterPath ContourPath(qint64 idDetail) const; - QPainterPath Equidistant(QVector points, - const Detail::Equidistant &eqv, - const qreal &width)const; - static QLineF ParallelLine(const QLineF &line, qreal width ); - static QPointF SingleParallelPoint(const QLineF &line, const qreal &angle, - const qreal &width); - QVector EkvPoint(const QLineF &line1, const QLineF &line2, - const qreal &width)const; - QVector CheckLoops(const QVector &points) const; - void PrepareDetails(QVector & list)const; + VStandartTableCell GetStandartTableCell(const QString& name) const; + VIncrementTableRow GetIncrementTableRow(const QString& name) const; + qreal GetLine(const QString &name) const; + qreal GetLengthArc(const QString &name) const; + qreal GetLengthSpline(const QString &name) const; + qreal GetLineAngle(const QString &name) const; + VSpline GetSpline(qint64 id) const; + VSpline GetModelingSpline(qint64 id) const; + VArc GetArc(qint64 id) const; + VArc GetModelingArc(qint64 id) const; + VSplinePath GetSplinePath(qint64 id) const; + VSplinePath GetModelingSplinePath(qint64 id) const; + VDetail GetDetail(qint64 id) const; + static qint64 getId() {return _id;} + qint64 AddPoint(const VPointF& point); + qint64 AddModelingPoint(const VPointF& point); + qint64 AddDetail(const VDetail& detail); + inline void AddStandartTableCell(const QString& name, const VStandartTableCell& cell) + {standartTable[name] = cell;} + inline void AddIncrementTableRow(const QString& name, const VIncrementTableRow &cell) + {incrementTable[name] = cell;} + void AddLengthLine(const QString &name, const qreal &value); + void AddLengthSpline(const QString &name, const qreal &value); + void AddLengthArc(const qint64 &id); + void AddLengthArc(const QString &name, const qreal &value); + void AddLineAngle(const QString &name, const qreal &value); + void AddLine(const qint64 &firstPointId, const qint64 &secondPointId, + const Draw::Draws &mode = Draw::Calculation); + qint64 AddSpline(const VSpline& spl); + qint64 AddModelingSpline(const VSpline& spl); + qint64 AddSplinePath(const VSplinePath& splPath); + qint64 AddModelingSplinePath(const VSplinePath& splPath); + qint64 AddArc(const VArc& arc); + qint64 AddModelingArc(const VArc& arc); + QString GetNameLine(const qint64 &firstPoint, const qint64 &secondPoint, + const Draw::Draws &mode = Draw::Calculation) const; + QString GetNameLineAngle(const qint64 &firstPoint, const qint64 &secondPoint, + const Draw::Draws &mode = Draw::Calculation) const; + void UpdatePoint(qint64 id, const VPointF& point); + void UpdateModelingPoint(qint64 id, const VPointF& point); + void UpdateDetail(qint64 id, const VDetail& detail); + void UpdateSpline(qint64 id, const VSpline& spl); + void UpdateModelingSpline(qint64 id, const VSpline& spl); + void UpdateSplinePath(qint64 id, const VSplinePath& splPath); + void UpdateModelingSplinePath(qint64 id, const VSplinePath& splPath); + void UpdateArc(qint64 id, const VArc& arc); + void UpdateModelingArc(qint64 id, const VArc& arc); + inline void UpdateStandartTableCell(const QString& name, const VStandartTableCell& cell) + {standartTable[name] = cell;} + inline void UpdateIncrementTableRow(const QString& name, const VIncrementTableRow& cell) + {incrementTable[name] = cell;} + qreal GetValueStandartTableCell(const QString& name) const; + qreal GetValueIncrementTableRow(const QString& name) const; + void Clear(); + void ClearObject(); + inline void ClearIncrementTable() {incrementTable.clear();} + inline void ClearLengthLines() {lengthLines.clear();} + inline void ClearLengthSplines() {lengthSplines.clear();} + inline void ClearLengthArcs() {lengthArcs.clear();} + inline void ClearLineAngles() {lineAngles.clear();} + inline void SetSize(qint32 size) {base["Сг"] = size;} + inline void SetGrowth(qint32 growth) {base["Р"] = growth;} + inline qint32 size() const {return base.value("Сг");} + inline qint32 growth() const {return base.value("Р");} + qreal FindVar(const QString& name, bool *ok)const; + inline bool IncrementTableContains(const QString& name) {return incrementTable.contains(name);} + static qint64 getNextId(); + inline void RemoveIncrementTableRow(const QString& name) {incrementTable.remove(name);} + inline const QHash *DataPoints() const {return &points;} + inline const QHash *DataModelingPoints() const {return &modelingPoints;} + inline const QHash *DataSplines() const {return &splines;} + inline const QHash *DataModelingSplines() const {return &modelingSplines;} + inline const QHash *DataArcs() const {return &arcs;} + inline const QHash *DataModelingArcs() const {return &modelingArcs;} + inline const QHash *DataBase() const {return &base;} + inline const QHash *DataStandartTable() const {return &standartTable;} + inline const QHash *DataIncrementTable() const {return &incrementTable;} + inline const QHash *DataLengthLines() const {return &lengthLines;} + inline const QHash *DataLengthSplines() const {return &lengthSplines;} + inline const QHash *DataLengthArcs() const {return &lengthArcs;} + inline const QHash *DataLineAngles() const {return &lineAngles;} + inline const QHash *DataSplinePaths() const {return &splinePaths;} + inline const QHash *DataModelingSplinePaths() const {return &modelingSplinePaths;} + inline const QHash *DataDetails() const {return &details;} + static void UpdateId(qint64 newId); + QPainterPath ContourPath(qint64 idDetail) const; + QVector biasPoints(const QVector &points, const qreal &mx, const qreal &my) const; + QPainterPath Equidistant(QVector points, const Detail::Equidistant &eqv, const qreal &width)const; + static QLineF ParallelLine(const QLineF &line, qreal width ); + static QPointF SingleParallelPoint(const QLineF &line, const qreal &angle, const qreal &width); + QVector EkvPoint(const QLineF &line1, const QLineF &line2, const qreal &width)const; + QVector CheckLoops(const QVector &points) const; + void PrepareDetails(QVector & list) const; private: - static qint64 _id; - QHash base; - QHash points; - QHash modelingPoints; + static qint64 _id; + QHash base; + QHash points; + QHash modelingPoints; QHash standartTable; QHash incrementTable; - QHash lengthLines; - QHash lineAngles; - QHash splines; - QHash modelingSplines; - QHash lengthSplines; - QHash arcs; - QHash modelingArcs; - QHash lengthArcs; - QHash splinePaths; - QHash modelingSplinePaths; - QHash details; - template static val GetObject(const QHash &obj, key id); - template static void UpdateObject(QHash &obj, const qint64 &id, - const val& point); - template static qint64 AddObject(QHash &obj, - const val& value); - void CreateManTableIGroup (); - QVector GetReversePoint(const QVector &points)const; - qreal GetLengthContour(const QVector &contour, - const QVector &newPoints)const; + QHash lengthLines; + QHash lineAngles; + QHash splines; + QHash modelingSplines; + QHash lengthSplines; + QHash arcs; + QHash modelingArcs; + QHash lengthArcs; + QHash splinePaths; + QHash modelingSplinePaths; + QHash details; + void CreateManTableIGroup (); + QVector GetReversePoint(const QVector &points)const; + qreal GetLengthContour(const QVector &contour, const QVector &newPoints)const; + template static val GetObject(const QHash &obj, key id); + template static void UpdateObject(QHash &obj, const qint64 &id, const val& point); + template static qint64 AddObject(QHash &obj, const val& value); }; #endif // VCONTAINER_H diff --git a/container/vincrementtablerow.cpp b/container/vincrementtablerow.cpp index 5240da150..7b7b00655 100644 --- a/container/vincrementtablerow.cpp +++ b/container/vincrementtablerow.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vincrementtablerow.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,54 +24,12 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "vincrementtablerow.h" -VIncrementTableRow::VIncrementTableRow():id(0), base(0), ksize(0), kgrowth(0), description(QString()){ -} +VIncrementTableRow::VIncrementTableRow() + :id(0), base(0), ksize(0), kgrowth(0), description(QString()){} -VIncrementTableRow::VIncrementTableRow(qint64 id, qreal base, qreal ksize, qreal kgrowth, - QString description):id(id), base(base), ksize(ksize), - kgrowth(kgrowth), description(description){ -} - -QString VIncrementTableRow::getDescription() const{ - return description; -} - -void VIncrementTableRow::setDescription(const QString &value){ - description = value; -} - -qreal VIncrementTableRow::getKgrowth() const{ - return kgrowth; -} - -void VIncrementTableRow::setKgrowth(const qreal &value){ - kgrowth = value; -} - -qreal VIncrementTableRow::getKsize() const{ - return ksize; -} - -void VIncrementTableRow::setKsize(const qreal &value){ - ksize = value; -} - -qreal VIncrementTableRow::getBase() const{ - return base; -} - -void VIncrementTableRow::setBase(const qreal &value){ - base = value; -} - -qint64 VIncrementTableRow::getId() const{ - return id; -} - -void VIncrementTableRow::setId(const qint64 &value){ - id = value; -} +VIncrementTableRow::VIncrementTableRow(qint64 id, qreal base, qreal ksize, qreal kgrowth, QString description) + :id(id), base(base), ksize(ksize), kgrowth(kgrowth), description(description){} diff --git a/container/vincrementtablerow.h b/container/vincrementtablerow.h index 3896340fb..5aa643e7d 100644 --- a/container/vincrementtablerow.h +++ b/container/vincrementtablerow.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vincrementtablerow.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,40 +24,33 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef VINCREMENTTABLEROW_H #define VINCREMENTTABLEROW_H -#include - class VIncrementTableRow { public: - VIncrementTableRow(); - VIncrementTableRow(qint64 id, qreal base, qreal ksize, qreal kgrowth, - QString description = QString()); - qint64 getId() const; - void setId(const qint64 &value); - - qreal getBase() const; - void setBase(const qreal &value); - - qreal getKsize() const; - void setKsize(const qreal &value); - - qreal getKgrowth() const; - void setKgrowth(const qreal &value); - - QString getDescription() const; - void setDescription(const QString &value); - + VIncrementTableRow(); + VIncrementTableRow(qint64 id, qreal base, qreal ksize, qreal kgrowth, + QString description = QString()); + inline qint64 getId() const {return id;} + inline void setId(const qint64 &value) {id = value;} + inline qreal getBase() const {return base;} + inline void setBase(const qreal &value) {base = value;} + inline qreal getKsize() const {return ksize;} + inline void setKsize(const qreal &value) {ksize = value;} + inline qreal getKgrowth() const {return kgrowth;} + inline void setKgrowth(const qreal &value) {kgrowth = value;} + inline QString getDescription() const {return description;} + inline void setDescription(const QString &value) {description = value;} private: - qint64 id; - qreal base; - qreal ksize; - qreal kgrowth; - QString description; + qint64 id; + qreal base; + qreal ksize; + qreal kgrowth; + QString description; }; #endif // VINCREMENTTABLEROW_H diff --git a/container/vpointf.cpp b/container/vpointf.cpp index b9ae72544..9bae8f96f 100644 --- a/container/vpointf.cpp +++ b/container/vpointf.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vpointf.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,11 +24,12 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "vpointf.h" -VPointF &VPointF::operator =(const VPointF &point){ +VPointF &VPointF::operator =(const VPointF &point) +{ _name = point.name(); _mx = point.mx(); _my = point.my(); diff --git a/container/vpointf.h b/container/vpointf.h index cfe7c8f1a..b2396ce54 100644 --- a/container/vpointf.h +++ b/container/vpointf.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vpointf.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,16 +24,13 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef VPOINTF_H #define VPOINTF_H -#include -#include -#include "options.h" - -class VPointF{ +class VPointF +{ public: inline VPointF () :_name(QString()), _mx(0), _my(0), _x(0), _y(0), mode(Draw::Calculation), idObject(0){} diff --git a/container/vstandarttablecell.cpp b/container/vstandarttablecell.cpp index 201aa4481..4a824bba9 100644 --- a/container/vstandarttablecell.cpp +++ b/container/vstandarttablecell.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vstandarttablecell.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,29 +24,12 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "vstandarttablecell.h" -VStandartTableCell::VStandartTableCell():base(0), ksize(0), kgrowth(0), description(QString()){ -} +VStandartTableCell::VStandartTableCell() + :base(0), ksize(0), kgrowth(0), description(QString()){} -VStandartTableCell::VStandartTableCell(qint32 base, qreal ksize, qreal kgrowth, QString description):base(base), - ksize(ksize), kgrowth(kgrowth), description(description){ -} - -qint32 VStandartTableCell::GetBase() const{ - return base; -} - -qreal VStandartTableCell::GetKsize() const{ - return ksize; -} - -qreal VStandartTableCell::GetKgrowth() const{ - return kgrowth; -} - -QString VStandartTableCell::GetDescription() const{ - return description; -} +VStandartTableCell::VStandartTableCell(qint32 base, qreal ksize, qreal kgrowth, QString description) + :base(base), ksize(ksize), kgrowth(kgrowth), description(description){} diff --git a/container/vstandarttablecell.h b/container/vstandarttablecell.h index c165fbca4..b0fe41bb0 100644 --- a/container/vstandarttablecell.h +++ b/container/vstandarttablecell.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vstandarttablecell.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,27 +24,25 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef VSTANDARTTABLECELL_H #define VSTANDARTTABLECELL_H -#include - class VStandartTableCell { public: - VStandartTableCell(); - VStandartTableCell(qint32 base, qreal ksize, qreal kgrowth, QString description = QString()); - qint32 GetBase() const; - qreal GetKsize() const; - qreal GetKgrowth() const; - QString GetDescription() const; + VStandartTableCell(); + VStandartTableCell(qint32 base, qreal ksize, qreal kgrowth, QString description = QString()); + inline qint32 GetBase() const {return base;} + inline qreal GetKsize() const {return ksize;} + inline qreal GetKgrowth() const {return kgrowth;} + inline QString GetDescription() const {return description;} private: - qint32 base; - qreal ksize; - qreal kgrowth; - QString description; + qint32 base; + qreal ksize; + qreal kgrowth; + QString description; }; #endif // VSTANDARTTABLECELL_H diff --git a/cursor.qrc b/cursor.qrc index ece04dd88..785c3ddd8 100644 --- a/cursor.qrc +++ b/cursor.qrc @@ -12,5 +12,8 @@ cursor/splinepath_cursor.png cursor/pointcontact_cursor.png cursor/new_detail_cursor.png + cursor/height_cursor.png + cursor/triangle_cursor.png + cursor/pointofintersect_cursor.png diff --git a/cursor/height_cursor.png b/cursor/height_cursor.png new file mode 100644 index 000000000..05da2a5ae Binary files /dev/null and b/cursor/height_cursor.png differ diff --git a/cursor/pointofintersect_cursor.png b/cursor/pointofintersect_cursor.png new file mode 100644 index 000000000..c01923887 Binary files /dev/null and b/cursor/pointofintersect_cursor.png differ diff --git a/cursor/triangle_cursor.png b/cursor/triangle_cursor.png new file mode 100644 index 000000000..2fc657ce8 Binary files /dev/null and b/cursor/triangle_cursor.png differ diff --git a/dialogs/dialogalongline.cpp b/dialogs/dialogalongline.cpp index 4d522963a..adaa26647 100644 --- a/dialogs/dialogalongline.cpp +++ b/dialogs/dialogalongline.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file dialogalongline.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,14 +24,15 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "dialogalongline.h" #include "ui_dialogalongline.h" -DialogAlongLine::DialogAlongLine(const VContainer *data, Draw::Draws mode, QWidget *parent) : - DialogTool(data, mode, parent), ui(new Ui::DialogAlongLine), number(0), pointName(QString()), - typeLine(QString()), formula(QString()), firstPointId(0), secondPointId(0){ +DialogAlongLine::DialogAlongLine(const VContainer *data, Draw::Draws mode, QWidget *parent) + :DialogTool(data, mode, parent), ui(new Ui::DialogAlongLine), number(0), pointName(QString()), + typeLine(QString()), formula(QString()), firstPointId(0), secondPointId(0) +{ ui->setupUi(this); listWidget = ui->listWidget; labelResultCalculation = ui->labelResultCalculation; @@ -33,6 +41,8 @@ DialogAlongLine::DialogAlongLine(const VContainer *data, Draw::Draws mode, QWidg radioButtonStandartTable = ui->radioButtonStandartTable; radioButtonIncrements = ui->radioButtonIncrements; radioButtonLengthLine = ui->radioButtonLengthLine; + radioButtonLengthArc = ui->radioButtonLengthArc; + radioButtonLengthCurve = ui->radioButtonLengthSpline; lineEditFormula = ui->lineEditFormula; labelEditFormula = ui->labelEditFormula; labelEditNamePoint = ui->labelEditNamePoint; @@ -44,6 +54,7 @@ DialogAlongLine::DialogAlongLine(const VContainer *data, Draw::Draws mode, QWidg QPushButton *bCansel = ui->buttonBox->button(QDialogButtonBox::Cancel); connect(bCansel, &QPushButton::clicked, this, &DialogAlongLine::DialogRejected); FillComboBoxTypeLine(ui->comboBoxLineType); + ui->comboBoxLineType->setCurrentIndex(1); FillComboBoxPoints(ui->comboBoxFirstPoint); FillComboBoxPoints(ui->comboBoxSecondPoint); @@ -56,58 +67,76 @@ DialogAlongLine::DialogAlongLine(const VContainer *data, Draw::Draws mode, QWidg connect(ui->radioButtonStandartTable, &QRadioButton::clicked, this, &DialogAlongLine::StandartTable); connect(ui->radioButtonIncrements, &QRadioButton::clicked, this, &DialogAlongLine::Increments); connect(ui->radioButtonLengthLine, &QRadioButton::clicked, this, &DialogAlongLine::LengthLines); + connect(ui->radioButtonLengthArc, &QRadioButton::clicked, this, &DialogAlongLine::LengthArcs); + connect(ui->radioButtonLengthSpline, &QRadioButton::clicked, this, &DialogAlongLine::LengthCurves); connect(ui->toolButtonEqual, &QPushButton::clicked, this, &DialogAlongLine::EvalFormula); connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogAlongLine::NamePointChanged); connect(ui->lineEditFormula, &QLineEdit::textChanged, this, &DialogAlongLine::FormulaChanged); } -DialogAlongLine::~DialogAlongLine(){ +DialogAlongLine::~DialogAlongLine() +{ delete ui; } -void DialogAlongLine::ChoosedObject(qint64 id, Scene::Scenes type){ - if(idDetail == 0 && mode == Draw::Modeling){ - if(type == Scene::Detail){ +void DialogAlongLine::ChoosedObject(qint64 id, const Scene::Scenes &type) +{ + if (idDetail == 0 && mode == Draw::Modeling) + { + if (type == Scene::Detail) + { idDetail = id; return; } } - if(mode == Draw::Modeling){ - if(!CheckObject(id)){ + if (mode == Draw::Modeling) + { + if (CheckObject(id) == false) + { return; } } - if(type == Scene::Point){ + if (type == Scene::Point) + { VPointF point; - if(mode == Draw::Calculation){ + if (mode == Draw::Calculation) + { point = data->GetPoint(id); - } else { + } + else + { point = data->GetModelingPoint(id); } - if(number == 0){ + if (number == 0) + { qint32 index = ui->comboBoxFirstPoint->findText(point.name()); - if ( index != -1 ) { // -1 for not found + if ( index != -1 ) + { // -1 for not found ui->comboBoxFirstPoint->setCurrentIndex(index); number++; emit ToolTip(tr("Select second point of line")); return; } } - if(number == 1){ + if (number == 1) + { qint32 index = ui->comboBoxSecondPoint->findText(point.name()); - if ( index != -1 ) { // -1 for not found + if ( index != -1 ) + { // -1 for not found ui->comboBoxSecondPoint->setCurrentIndex(index); number = 0; emit ToolTip(""); } - if(!isInitialized){ + if (isInitialized == false) + { this->show(); } } } } -void DialogAlongLine::DialogAccepted(){ +void DialogAlongLine::DialogAccepted() +{ pointName = ui->lineEditNamePoint->text(); typeLine = GetTypeLine(ui->comboBoxLineType); formula = ui->lineEditFormula->text(); @@ -116,45 +145,30 @@ void DialogAlongLine::DialogAccepted(){ emit DialogClosed(QDialog::Accepted); } -qint64 DialogAlongLine::getSecondPointId() const{ - return secondPointId; -} - -void DialogAlongLine::setSecondPointId(const qint64 &value, const qint64 &id){ +void DialogAlongLine::setSecondPointId(const qint64 &value, const qint64 &id) +{ setCurrentPointId(ui->comboBoxSecondPoint, secondPointId, value, id); } -qint64 DialogAlongLine::getFirstPointId() const{ - return firstPointId; -} - -void DialogAlongLine::setFirstPointId(const qint64 &value, const qint64 &id){ +void DialogAlongLine::setFirstPointId(const qint64 &value, const qint64 &id) +{ setCurrentPointId(ui->comboBoxFirstPoint, firstPointId, value, id); } -QString DialogAlongLine::getFormula() const{ - return formula; -} - -void DialogAlongLine::setFormula(const QString &value){ +void DialogAlongLine::setFormula(const QString &value) +{ formula = value; ui->lineEditFormula->setText(formula); } -QString DialogAlongLine::getTypeLine() const{ - return typeLine; -} - -void DialogAlongLine::setTypeLine(const QString &value){ +void DialogAlongLine::setTypeLine(const QString &value) +{ typeLine = value; SetupTypeLine(ui->comboBoxLineType, value); } -QString DialogAlongLine::getPointName() const{ - return pointName; -} - -void DialogAlongLine::setPointName(const QString &value){ +void DialogAlongLine::setPointName(const QString &value) +{ pointName = value; ui->lineEditNamePoint->setText(pointName); } diff --git a/dialogs/dialogalongline.h b/dialogs/dialogalongline.h index 3f004fb52..819498b1d 100644 --- a/dialogs/dialogalongline.h +++ b/dialogs/dialogalongline.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file dialogalongline.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,37 +24,37 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef DIALOGALONGLINE_H #define DIALOGALONGLINE_H #include "dialogtool.h" -#include "container/calculator.h" -namespace Ui { -class DialogAlongLine; +namespace Ui +{ + class DialogAlongLine; } class DialogAlongLine : public DialogTool { - Q_OBJECT + Q_OBJECT public: - explicit DialogAlongLine(const VContainer *data, Draw::Draws mode = Draw::Calculation, + DialogAlongLine(const VContainer *data, Draw::Draws mode = Draw::Calculation, QWidget *parent = 0); ~DialogAlongLine(); - QString getPointName() const; + inline QString getPointName() const {return pointName;} void setPointName(const QString &value); - QString getTypeLine() const; + inline QString getTypeLine() const {return typeLine;} void setTypeLine(const QString &value); - QString getFormula() const; + inline QString getFormula() const {return formula;} void setFormula(const QString &value); - qint64 getFirstPointId() const; + inline qint64 getFirstPointId() const {return firstPointId;} void setFirstPointId(const qint64 &value, const qint64 &id); - qint64 getSecondPointId() const; + inline qint64 getSecondPointId() const {return secondPointId;} void setSecondPointId(const qint64 &value, const qint64 &id); public slots: - virtual void ChoosedObject(qint64 id, Scene::Scenes type); + virtual void ChoosedObject(qint64 id, const Scene::Scenes &type); virtual void DialogAccepted(); private: Q_DISABLE_COPY(DialogAlongLine) diff --git a/dialogs/dialogalongline.ui b/dialogs/dialogalongline.ui index acfb90561..3030f22ba 100644 --- a/dialogs/dialogalongline.ui +++ b/dialogs/dialogalongline.ui @@ -302,7 +302,7 @@ - false + true Length of arcs @@ -312,7 +312,7 @@ - false + true Length of curves diff --git a/dialogs/dialogarc.cpp b/dialogs/dialogarc.cpp index 7b4548ef1..ed4beb7a2 100644 --- a/dialogs/dialogarc.cpp +++ b/dialogs/dialogarc.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file dialogarc.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,15 +24,15 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "dialogarc.h" #include "ui_dialogarc.h" -#include "../container/calculator.h" -DialogArc::DialogArc(const VContainer *data, Draw::Draws mode, QWidget *parent) : - DialogTool(data, mode, parent), ui(new Ui::DialogArc), flagRadius(false), flagF1(false), flagF2(false), - timerRadius(0), timerF1(0), timerF2(0), center(0), radius(QString()), f1(QString()), f2(QString()){ +DialogArc::DialogArc(const VContainer *data, Draw::Draws mode, QWidget *parent) + :DialogTool(data, mode, parent), ui(new Ui::DialogArc), flagRadius(false), flagF1(false), flagF2(false), + timerRadius(0), timerF1(0), timerF2(0), center(0), radius(QString()), f1(QString()), f2(QString()) +{ ui->setupUi(this); timerRadius = new QTimer(this); @@ -52,6 +59,8 @@ DialogArc::DialogArc(const VContainer *data, Draw::Draws mode, QWidget *parent) radioButtonStandartTable = ui->radioButtonStandartTable; radioButtonIncrements = ui->radioButtonIncrements; radioButtonLengthLine = ui->radioButtonLengthLine; + radioButtonLengthArc = ui->radioButtonLengthArc; + radioButtonLengthCurve = ui->radioButtonLengthSpline; connect(ui->toolButtonPutHereRadius, &QPushButton::clicked, this, &DialogArc::PutRadius); connect(ui->toolButtonPutHereF1, &QPushButton::clicked, this, &DialogArc::PutF1); @@ -63,7 +72,9 @@ DialogArc::DialogArc(const VContainer *data, Draw::Draws mode, QWidget *parent) connect(ui->radioButtonStandartTable, &QRadioButton::clicked, this, &DialogArc::StandartTable); connect(ui->radioButtonIncrements, &QRadioButton::clicked, this, &DialogArc::Increments); connect(ui->radioButtonLengthLine, &QRadioButton::clicked, this, &DialogArc::LengthLines); - connect(ui->radioButtonLineAngles, &QRadioButton::clicked, this, &DialogArc::LineArcs); + connect(ui->radioButtonLineAngles, &QRadioButton::clicked, this, &DialogArc::LineAngles); + connect(ui->radioButtonLengthArc, &QRadioButton::clicked, this, &DialogArc::LengthArcs); + connect(ui->radioButtonLengthSpline, &QRadioButton::clicked, this, &DialogArc::LengthCurves); connect(ui->toolButtonEqualRadius, &QPushButton::clicked, this, &DialogArc::EvalRadius); connect(ui->toolButtonEqualF1, &QPushButton::clicked, this, &DialogArc::EvalF1); @@ -74,63 +85,61 @@ DialogArc::DialogArc(const VContainer *data, Draw::Draws mode, QWidget *parent) connect(ui->lineEditF2, &QLineEdit::textChanged, this, &DialogArc::F2Changed); } -qint64 DialogArc::GetCenter() const{ - return center; +DialogArc::~DialogArc() +{ + delete ui; } -void DialogArc::SetCenter(const qint64 &value){ +void DialogArc::SetCenter(const qint64 &value) +{ center = value; ChangeCurrentData(ui->comboBoxBasePoint, center); } -QString DialogArc::GetF2() const{ - return f2; -} - -void DialogArc::SetF2(const QString &value){ +void DialogArc::SetF2(const QString &value) +{ f2 = value; ui->lineEditF2->setText(f2); } -QString DialogArc::GetF1() const{ - return f1; -} - -void DialogArc::SetF1(const QString &value){ +void DialogArc::SetF1(const QString &value) +{ f1 = value; ui->lineEditF1->setText(f1); } -QString DialogArc::GetRadius() const{ - return radius; -} - -void DialogArc::SetRadius(const QString &value){ +void DialogArc::SetRadius(const QString &value) +{ radius = value; ui->lineEditRadius->setText(radius); } -DialogArc::~DialogArc(){ -delete ui; -} - -void DialogArc::ChoosedObject(qint64 id, Scene::Scenes type){ - if(idDetail == 0 && mode == Draw::Modeling){ - if(type == Scene::Detail){ +void DialogArc::ChoosedObject(qint64 id, const Scene::Scenes &type) +{ + if (idDetail == 0 && mode == Draw::Modeling) + { + if (type == Scene::Detail) + { idDetail = id; return; } } - if(mode == Draw::Modeling){ - if(!CheckObject(id)){ + if (mode == Draw::Modeling) + { + if (CheckObject(id)==false) + { return; } } - if(type == Scene::Point){ + if (type == Scene::Point) + { VPointF point; - if(mode == Draw::Calculation){ + if (mode == Draw::Calculation) + { point = data->GetPoint(id); - } else { + } + else + { point = data->GetModelingPoint(id); } ChangeCurrentText(ui->comboBoxBasePoint, point.name()); @@ -139,7 +148,8 @@ void DialogArc::ChoosedObject(qint64 id, Scene::Scenes type){ } } -void DialogArc::DialogAccepted(){ +void DialogArc::DialogAccepted() +{ radius = ui->lineEditRadius->text(); f1 = ui->lineEditF1->text(); f2 = ui->lineEditF2->text(); @@ -147,13 +157,16 @@ void DialogArc::DialogAccepted(){ emit DialogClosed(QDialog::Accepted); } -void DialogArc::ValChenged(int row){ - if(ui->listWidget->count() == 0){ +void DialogArc::ValChenged(int row) +{ + if (ui->listWidget->count() == 0) + { return; } QListWidgetItem *item = ui->listWidget->item( row ); - if(ui->radioButtonLineAngles->isChecked()){ - QString desc = QString("%1(%2) - %3").arg(item->text()).arg(data->GetLineArc(item->text())) + if (ui->radioButtonLineAngles->isChecked()) + { + QString desc = QString("%1(%2) - %3").arg(item->text()).arg(data->GetLineAngle(item->text())) .arg(tr("Value angle of line.")); ui->labelDescription->setText(desc); return; @@ -161,61 +174,78 @@ void DialogArc::ValChenged(int row){ DialogTool::ValChenged(row); } -void DialogArc::PutRadius(){ +void DialogArc::PutRadius() +{ PutValHere(ui->lineEditRadius, ui->listWidget); } -void DialogArc::PutF1(){ +void DialogArc::PutF1() +{ PutValHere(ui->lineEditF1, ui->listWidget); } -void DialogArc::PutF2(){ +void DialogArc::PutF2() +{ PutValHere(ui->lineEditF2, ui->listWidget); } -void DialogArc::LineArcs(){ - ShowLineArcs(); +void DialogArc::LineAngles() +{ + ShowLineAngles(); } -void DialogArc::RadiusChanged(){ +void DialogArc::RadiusChanged() +{ + labelEditFormula = ui->labelEditRadius; ValFormulaChanged(flagRadius, ui->lineEditRadius, timerRadius); } -void DialogArc::F1Changed(){ +void DialogArc::F1Changed() +{ + labelEditFormula = ui->labelEditF1; ValFormulaChanged(flagF1, ui->lineEditF1, timerF1); } -void DialogArc::F2Changed(){ +void DialogArc::F2Changed() +{ + labelEditFormula = ui->labelEditF2; ValFormulaChanged(flagF2, ui->lineEditF2, timerF2); } -void DialogArc::CheckState(){ - Q_CHECK_PTR(bOk); +void DialogArc::CheckState() +{ + Q_ASSERT(bOk != 0); bOk->setEnabled(flagRadius && flagF1 && flagF2); } -void DialogArc::EvalRadius(){ +void DialogArc::EvalRadius() +{ labelEditFormula = ui->labelEditRadius; Eval(ui->lineEditRadius, flagRadius, timerRadius, ui->labelResultRadius); } -void DialogArc::EvalF1(){ +void DialogArc::EvalF1() +{ labelEditFormula = ui->labelEditF1; Eval(ui->lineEditF1, flagF1, timerF1, ui->labelResultF1); } -void DialogArc::EvalF2(){ +void DialogArc::EvalF2() +{ labelEditFormula = ui->labelEditF2; Eval(ui->lineEditF2, flagF2, timerF2, ui->labelResultF2); } -void DialogArc::ShowLineArcs(){ +void DialogArc::ShowLineAngles() +{ disconnect(ui->listWidget, &QListWidget::currentRowChanged, this, &DialogArc::ValChenged); ui->listWidget->clear(); connect(ui->listWidget, &QListWidget::currentRowChanged, this, &DialogArc::ValChenged); - const QHash *lineArcsTable = data->DataLineAngles(); - QHashIterator i(*lineArcsTable); - while (i.hasNext()) { + const QHash *lineAnglesTable = data->DataLineAngles(); + Q_ASSERT(lineAnglesTable != 0); + QHashIterator i(*lineAnglesTable); + while (i.hasNext()) + { i.next(); QListWidgetItem *item = new QListWidgetItem(i.key()); diff --git a/dialogs/dialogarc.h b/dialogs/dialogarc.h index 00f23e8e5..014955cce 100644 --- a/dialogs/dialogarc.h +++ b/dialogs/dialogarc.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file dialogarc.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,43 +24,40 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef DIALOGARC_H #define DIALOGARC_H #include "dialogtool.h" -namespace Ui { -class DialogArc; +namespace Ui +{ + class DialogArc; } class DialogArc : public DialogTool { Q_OBJECT public: - explicit DialogArc(const VContainer *data, Draw::Draws mode = Draw::Calculation, QWidget *parent = 0); - ~DialogArc(); - qint64 GetCenter() const; - void SetCenter(const qint64 &value); - - QString GetRadius() const; - void SetRadius(const QString &value); - - QString GetF1() const; - void SetF1(const QString &value); - - QString GetF2() const; - void SetF2(const QString &value); - + DialogArc(const VContainer *data, Draw::Draws mode = Draw::Calculation, QWidget *parent = 0); + ~DialogArc(); + inline qint64 GetCenter() const {return center;} + void SetCenter(const qint64 &value); + inline QString GetRadius() const {return radius;} + void SetRadius(const QString &value); + inline QString GetF1() const {return f1;} + void SetF1(const QString &value); + inline QString GetF2() const {return f2;} + void SetF2(const QString &value); public slots: - virtual void ChoosedObject(qint64 id, Scene::Scenes type); + virtual void ChoosedObject(qint64 id, const Scene::Scenes &type); virtual void DialogAccepted(); virtual void ValChenged(int row); void PutRadius(); void PutF1(); void PutF2(); - void LineArcs(); + void LineAngles(); void RadiusChanged(); void F1Changed(); void F2Changed(); @@ -75,7 +79,7 @@ private: void EvalRadius(); void EvalF1(); void EvalF2(); - void ShowLineArcs(); + void ShowLineAngles(); }; #endif // DIALOGARC_H diff --git a/dialogs/dialogarc.ui b/dialogs/dialogarc.ui index 26d4e43bb..65ab8d07b 100644 --- a/dialogs/dialogarc.ui +++ b/dialogs/dialogarc.ui @@ -495,7 +495,7 @@ true - Length of arcs + Length of curves diff --git a/dialogs/dialogbisector.cpp b/dialogs/dialogbisector.cpp index 6f6e785ce..2eda284bc 100644 --- a/dialogs/dialogbisector.cpp +++ b/dialogs/dialogbisector.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file dialogbisector.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,14 +24,15 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "dialogbisector.h" #include "ui_dialogbisector.h" -DialogBisector::DialogBisector(const VContainer *data, Draw::Draws mode, QWidget *parent) : - DialogTool(data, mode, parent), ui(new Ui::DialogBisector), number(0), pointName(QString()), - typeLine(QString()), formula(QString()), firstPointId(0), secondPointId(0), thirdPointId(0){ +DialogBisector::DialogBisector(const VContainer *data, Draw::Draws mode, QWidget *parent) + :DialogTool(data, mode, parent), ui(new Ui::DialogBisector), number(0), pointName(QString()), + typeLine(QString()), formula(QString()), firstPointId(0), secondPointId(0), thirdPointId(0) +{ ui->setupUi(this); listWidget = ui->listWidget; labelResultCalculation = ui->labelResultCalculation; @@ -33,6 +41,8 @@ DialogBisector::DialogBisector(const VContainer *data, Draw::Draws mode, QWidget radioButtonStandartTable = ui->radioButtonStandartTable; radioButtonIncrements = ui->radioButtonIncrements; radioButtonLengthLine = ui->radioButtonLengthLine; + radioButtonLengthArc = ui->radioButtonLengthArc; + radioButtonLengthCurve = ui->radioButtonLengthSpline; lineEditFormula = ui->lineEditFormula; labelEditFormula = ui->labelEditFormula; labelEditNamePoint = ui->labelEditNamePoint; @@ -57,118 +67,120 @@ DialogBisector::DialogBisector(const VContainer *data, Draw::Draws mode, QWidget connect(ui->radioButtonStandartTable, &QRadioButton::clicked, this, &DialogBisector::StandartTable); connect(ui->radioButtonIncrements, &QRadioButton::clicked, this, &DialogBisector::Increments); connect(ui->radioButtonLengthLine, &QRadioButton::clicked, this, &DialogBisector::LengthLines); + connect(ui->radioButtonLengthArc, &QRadioButton::clicked, this, &DialogBisector::LengthArcs); + connect(ui->radioButtonLengthSpline, &QRadioButton::clicked, this, &DialogBisector::LengthCurves); connect(ui->toolButtonEqual, &QPushButton::clicked, this, &DialogBisector::EvalFormula); connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogBisector::NamePointChanged); connect(ui->lineEditFormula, &QLineEdit::textChanged, this, &DialogBisector::FormulaChanged); } -DialogBisector::~DialogBisector(){ +DialogBisector::~DialogBisector() +{ delete ui; } -void DialogBisector::ChoosedObject(qint64 id, Scene::Scenes type){ - if(idDetail == 0 && mode == Draw::Modeling){ - if(type == Scene::Detail){ +void DialogBisector::ChoosedObject(qint64 id, const Scene::Scenes &type) +{ + if (idDetail == 0 && mode == Draw::Modeling) + { + if (type == Scene::Detail) + { idDetail = id; return; } } - if(mode == Draw::Modeling){ - if(!CheckObject(id)){ + if (mode == Draw::Modeling) + { + if (CheckObject(id) == false) + { return; } } - if(type == Scene::Point){ + if (type == Scene::Point) + { VPointF point; - if(mode == Draw::Calculation){ + if (mode == Draw::Calculation) + { point = data->GetPoint(id); - } else { + } + else + { point = data->GetModelingPoint(id); } - if(number == 0){ + if (number == 0) + { qint32 index = ui->comboBoxFirstPoint->findText(point.name()); - if ( index != -1 ) { // -1 for not found + if ( index != -1 ) + { // -1 for not found ui->comboBoxFirstPoint->setCurrentIndex(index); number++; emit ToolTip(tr("Select second point of angle")); return; } } - if(number == 1){ + if (number == 1) + { qint32 index = ui->comboBoxSecondPoint->findText(point.name()); - if ( index != -1 ) { // -1 for not found + if ( index != -1 ) + { // -1 for not found ui->comboBoxSecondPoint->setCurrentIndex(index); number++; emit ToolTip(tr("Select third point of angle")); return; } } - if(number == 2){ + if (number == 2) + { qint32 index = ui->comboBoxThirdPoint->findText(point.name()); - if ( index != -1 ) { // -1 for not found + if ( index != -1 ) + { // -1 for not found ui->comboBoxThirdPoint->setCurrentIndex(index); number = 0; emit ToolTip(""); } - if(!isInitialized){ + if (isInitialized == false) + { this->show(); } } } } -QString DialogBisector::getPointName() const{ - return pointName; -} - -void DialogBisector::setPointName(const QString &value){ +void DialogBisector::setPointName(const QString &value) +{ pointName = value; ui->lineEditNamePoint->setText(pointName); } -QString DialogBisector::getTypeLine() const{ - return typeLine; -} - -void DialogBisector::setTypeLine(const QString &value){ +void DialogBisector::setTypeLine(const QString &value) +{ typeLine = value; SetupTypeLine(ui->comboBoxLineType, value); } -QString DialogBisector::getFormula() const{ - return formula; -} - -void DialogBisector::setFormula(const QString &value){ +void DialogBisector::setFormula(const QString &value) +{ formula = value; ui->lineEditFormula->setText(formula); } -qint64 DialogBisector::getFirstPointId() const{ - return firstPointId; -} - -void DialogBisector::setFirstPointId(const qint64 &value, const qint64 &id){ +void DialogBisector::setFirstPointId(const qint64 &value, const qint64 &id) +{ setCurrentPointId(ui->comboBoxFirstPoint, firstPointId, value, id); } -qint64 DialogBisector::getSecondPointId() const{ - return secondPointId; -} - -void DialogBisector::setSecondPointId(const qint64 &value, const qint64 &id){ +void DialogBisector::setSecondPointId(const qint64 &value, const qint64 &id) +{ setCurrentPointId(ui->comboBoxSecondPoint, secondPointId, value, id); } -qint64 DialogBisector::getThirdPointId() const{ - return thirdPointId; -} - -void DialogBisector::setThirdPointId(const qint64 &value, const qint64 &id){ +void DialogBisector::setThirdPointId(const qint64 &value, const qint64 &id) +{ setCurrentPointId(ui->comboBoxThirdPoint, thirdPointId, value, id); } -void DialogBisector::DialogAccepted(){ +void DialogBisector::DialogAccepted() +{ pointName = ui->lineEditNamePoint->text(); typeLine = GetTypeLine(ui->comboBoxLineType); formula = ui->lineEditFormula->text(); diff --git a/dialogs/dialogbisector.h b/dialogs/dialogbisector.h index aa7f529f2..99a665ce9 100644 --- a/dialogs/dialogbisector.h +++ b/dialogs/dialogbisector.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file dialogbisector.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,41 +24,39 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef DIALOGBISECTOR_H #define DIALOGBISECTOR_H #include "dialogtool.h" -#include -#include "container/calculator.h" -namespace Ui { -class DialogBisector; +namespace Ui +{ + class DialogBisector; } class DialogBisector : public DialogTool { Q_OBJECT - public: explicit DialogBisector(const VContainer *data, Draw::Draws mode = Draw::Calculation, QWidget *parent = 0); - ~DialogBisector(); - QString getPointName() const; + ~DialogBisector(); + QString getPointName() const {return pointName;} void setPointName(const QString &value); - QString getTypeLine() const; + inline QString getTypeLine() const {return typeLine;} void setTypeLine(const QString &value); - QString getFormula() const; + inline QString getFormula() const {return formula;} void setFormula(const QString &value); - qint64 getFirstPointId() const; + inline qint64 getFirstPointId() const {return firstPointId;} void setFirstPointId(const qint64 &value, const qint64 &id); - qint64 getSecondPointId() const; + inline qint64 getSecondPointId() const {return secondPointId;} void setSecondPointId(const qint64 &value, const qint64 &id); - qint64 getThirdPointId() const; + inline qint64 getThirdPointId() const {return thirdPointId;} void setThirdPointId(const qint64 &value, const qint64 &id); public slots: - virtual void ChoosedObject(qint64 id, Scene::Scenes type); + virtual void ChoosedObject(qint64 id, const Scene::Scenes &type); virtual void DialogAccepted(); private: Q_DISABLE_COPY(DialogBisector) diff --git a/dialogs/dialogbisector.ui b/dialogs/dialogbisector.ui index a4253118a..c33b41537 100644 --- a/dialogs/dialogbisector.ui +++ b/dialogs/dialogbisector.ui @@ -344,7 +344,7 @@ - false + true Length of arcs @@ -354,7 +354,7 @@ - false + true Length of curves diff --git a/dialogs/dialogdetail.cpp b/dialogs/dialogdetail.cpp index 32492ffb3..f7ab1e834 100644 --- a/dialogs/dialogdetail.cpp +++ b/dialogs/dialogdetail.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file dialogdetail.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,132 +24,228 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "dialogdetail.h" -#include -DialogDetail::DialogDetail(const VContainer *data, Draw::Draws mode, QWidget *parent) : - DialogTool(data, mode, parent), ui(), details(VDetail()){ +DialogDetail::DialogDetail(const VContainer *data, Draw::Draws mode, QWidget *parent) + :DialogTool(data, mode, parent), ui(), details(VDetail()), supplement(true), closed(true) +{ ui.setupUi(this); + labelEditNamePoint = ui.labelEditNameDetail; bOk = ui.buttonBox->button(QDialogButtonBox::Ok); connect(bOk, &QPushButton::clicked, this, &DialogDetail::DialogAccepted); - + flagName = false; + CheckState(); QPushButton *bCansel = ui.buttonBox->button(QDialogButtonBox::Cancel); connect(bCansel, &QPushButton::clicked, this, &DialogDetail::DialogRejected); + + connect(ui.listWidget, &QListWidget::currentRowChanged, this, &DialogDetail::ObjectChanged); + connect(ui.doubleSpinBoxBiasX, static_cast(&QDoubleSpinBox::valueChanged), + this, &DialogDetail::BiasXChanged); + connect(ui.doubleSpinBoxBiasY, static_cast(&QDoubleSpinBox::valueChanged), + this, &DialogDetail::BiasYChanged); + connect(ui.checkBoxSeams, &QCheckBox::clicked, this, &DialogDetail::ClickedSeams); + connect(ui.checkBoxClosed, &QCheckBox::clicked, this, &DialogDetail::ClickedClosed); + connect(ui.lineEditNameDetail, &QLineEdit::textChanged, this, &DialogDetail::NamePointChanged); } -void DialogDetail::ChoosedObject(qint64 id, Scene::Scenes type){ - if(idDetail == 0 && mode == Draw::Modeling){ - if(type == Scene::Detail){ +void DialogDetail::ChoosedObject(qint64 id, const Scene::Scenes &type) +{ + if (idDetail == 0 && mode == Draw::Modeling) + { + if (type == Scene::Detail) + { idDetail = id; return; } } - if(mode == Draw::Modeling){ - if(!CheckObject(id)){ + if (mode == Draw::Modeling) + { + if (CheckObject(id) == false) + { return; } } - if(type != Scene::Line && type != Scene::Detail){ - switch(type){ - case(Scene::Arc): - NewItem(id, Tool::NodeArc, mode, NodeDetail::Contour); - break; - case(Scene::Point): - NewItem(id, Tool::NodePoint, mode, NodeDetail::Contour); - break; - case(Scene::Spline): - NewItem(id, Tool::NodeSpline, mode, NodeDetail::Contour); - break; - case(Scene::SplinePath): - NewItem(id, Tool::NodeSplinePath, mode, NodeDetail::Contour); - break; - default: - qWarning()<show(); } } -void DialogDetail::DialogAccepted(){ +void DialogDetail::DialogAccepted() +{ details.Clear(); - for(qint32 i = 0; i < ui.listWidget->count(); ++i){ + for (qint32 i = 0; i < ui.listWidget->count(); ++i) + { QListWidgetItem *item = ui.listWidget->item(i); details.append( qvariant_cast(item->data(Qt::UserRole))); } + details.setWidth(ui.doubleSpinBoxSeams->value()); details.setName(ui.lineEditNameDetail->text()); + details.setSupplement(supplement); + details.setClosed(closed); emit ToolTip(""); emit DialogClosed(QDialog::Accepted); } -void DialogDetail::NewItem(qint64 id, Tool::Tools typeTool, Draw::Draws mode, NodeDetail::NodeDetails typeNode){ +void DialogDetail::NewItem(qint64 id, const Tool::Tools &typeTool, const Draw::Draws &mode, + const NodeDetail::NodeDetails &typeNode, qreal mx, qreal my) +{ QString name; - switch(typeTool){ - case(Tool::NodePoint):{ - VPointF point; - if(mode == Draw::Calculation){ - point = data->GetPoint(id); - } else { - point = data->GetModelingPoint(id); + switch (typeTool) + { + case (Tool::NodePoint): + { + VPointF point; + if (mode == Draw::Calculation) + { + point = data->GetPoint(id); + } + else + { + point = data->GetModelingPoint(id); + } + name = point.name(); + break; } - name = point.name(); - break; - } - case(Tool::NodeArc):{ - VArc arc; - if(mode == Draw::Calculation){ - arc = data->GetArc(id); - } else { - arc = data->GetModelingArc(id); + case (Tool::NodeArc): + { + VArc arc; + if (mode == Draw::Calculation) + { + arc = data->GetArc(id); + } + else + { + arc = data->GetModelingArc(id); + } + name = arc.name(); + break; } - name = data->GetNameArc(arc.GetCenter(), id, mode); - break; - } - case(Tool::NodeSpline):{ - VSpline spl; - if(mode == Draw::Calculation){ - spl = data->GetSpline(id); - } else { - spl = data->GetModelingSpline(id); + case (Tool::NodeSpline): + { + VSpline spl; + if (mode == Draw::Calculation) + { + spl = data->GetSpline(id); + } + else + { + spl = data->GetModelingSpline(id); + } + name = spl.GetName(); + break; } - name = spl.GetName(); - break; - } - case(Tool::NodeSplinePath):{ - VSplinePath splPath; - if(mode == Draw::Calculation){ - splPath = data->GetSplinePath(id); - } else { - splPath = data->GetModelingSplinePath(id); + case (Tool::NodeSplinePath): + { + VSplinePath splPath; + if (mode == Draw::Calculation) + { + splPath = data->GetSplinePath(id); + } + else + { + splPath = data->GetModelingSplinePath(id); + } + name = splPath.name(); + break; } - name = data->GetNameSplinePath(splPath, mode); - break; - } - default: - qWarning()<setFont(QFont("Times", 12, QFont::Bold)); - VNodeDetail node(id, typeTool, mode, typeNode); + VNodeDetail node(id, typeTool, mode, typeNode, mx, my); item->setData(Qt::UserRole, QVariant::fromValue(node)); ui.listWidget->addItem(item); + disconnect(ui.doubleSpinBoxBiasX, static_cast(&QDoubleSpinBox::valueChanged), + this, &DialogDetail::BiasXChanged); + disconnect(ui.doubleSpinBoxBiasY, static_cast(&QDoubleSpinBox::valueChanged), + this, &DialogDetail::BiasYChanged); + ui.doubleSpinBoxBiasX->setValue(toMM(node.getMx())); + ui.doubleSpinBoxBiasY->setValue(toMM(node.getMy())); + connect(ui.doubleSpinBoxBiasX, static_cast(&QDoubleSpinBox::valueChanged), + this, &DialogDetail::BiasXChanged); + connect(ui.doubleSpinBoxBiasY, static_cast(&QDoubleSpinBox::valueChanged), + this, &DialogDetail::BiasYChanged); } -VDetail DialogDetail::getDetails() const{ - return details; -} - -void DialogDetail::setDetails(const VDetail &value){ +void DialogDetail::setDetails(const VDetail &value) +{ details = value; ui.listWidget->clear(); - for(qint32 i = 0; i < details.CountNode(); ++i){ - NewItem(details[i].getId(), details[i].getTypeTool(),details[i].getMode(), details[i].getTypeNode()); + for (ptrdiff_t i = 0; i < details.CountNode(); ++i) + { + NewItem(details[i].getId(), details[i].getTypeTool(), details[i].getMode(), details[i].getTypeNode(), + details[i].getMx(), details[i].getMy()); } - details.setName(ui.lineEditNameDetail->text()); + ui.lineEditNameDetail->setText(details.getName()); + ui.checkBoxSeams->setChecked(details.getSupplement()); + ui.checkBoxClosed->setChecked(details.getClosed()); + ui.doubleSpinBoxSeams->setValue(details.getWidth()); + ui.listWidget->setCurrentRow(0); ui.listWidget->setFocus(Qt::OtherFocusReason); } +void DialogDetail::BiasXChanged(qreal d) +{ + qint32 row = ui.listWidget->currentRow(); + QListWidgetItem *item = ui.listWidget->item( row ); + VNodeDetail node = qvariant_cast(item->data(Qt::UserRole)); + node.setMx(toPixel(d)); + item->setData(Qt::UserRole, QVariant::fromValue(node)); +} + +void DialogDetail::BiasYChanged(qreal d) +{ + qint32 row = ui.listWidget->currentRow(); + QListWidgetItem *item = ui.listWidget->item( row ); + VNodeDetail node = qvariant_cast(item->data(Qt::UserRole)); + node.setMy(toPixel(d)); + item->setData(Qt::UserRole, QVariant::fromValue(node)); +} + +void DialogDetail::ClickedSeams(bool checked) +{ + supplement = checked; + ui.checkBoxClosed->setEnabled(checked); + ui.doubleSpinBoxSeams->setEnabled(checked); +} + +void DialogDetail::ClickedClosed(bool checked) +{ + closed = checked; +} + +void DialogDetail::ObjectChanged(int row) +{ + if (ui.listWidget->count() == 0) + { + return; + } + QListWidgetItem *item = ui.listWidget->item( row ); + VNodeDetail node = qvariant_cast(item->data(Qt::UserRole)); + ui.doubleSpinBoxBiasX->setValue(toMM(node.getMx())); + ui.doubleSpinBoxBiasY->setValue(toMM(node.getMy())); +} diff --git a/dialogs/dialogdetail.h b/dialogs/dialogdetail.h index 79cc1b55e..e4024f9f2 100644 --- a/dialogs/dialogdetail.h +++ b/dialogs/dialogdetail.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file dialogdetail.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,29 +24,36 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef DIALOGDETAIL_H #define DIALOGDETAIL_H #include "ui_dialogdetail.h" #include "dialogtool.h" -#include "geometry/vdetail.h" -class DialogDetail : public DialogTool{ - Q_OBJECT +class DialogDetail : public DialogTool +{ + Q_OBJECT public: - explicit DialogDetail(const VContainer *data, Draw::Draws mode, QWidget *parent = 0); - VDetail getDetails() const; - void setDetails(const VDetail &value); - + DialogDetail(const VContainer *data, Draw::Draws mode, QWidget *parent = 0); + inline VDetail getDetails() const {return details;} + void setDetails(const VDetail &value); public slots: - virtual void ChoosedObject(qint64 id, Scene::Scenes type); - virtual void DialogAccepted(); + virtual void ChoosedObject(qint64 id, const Scene::Scenes &type); + virtual void DialogAccepted(); + void BiasXChanged(qreal d); + void BiasYChanged(qreal d); + void ClickedSeams(bool checked); + void ClickedClosed(bool checked); + void ObjectChanged(int row); private: Ui::DialogDetail ui; - VDetail details; - void NewItem(qint64 id, Tool::Tools typeTool, Draw::Draws mode, NodeDetail::NodeDetails typeNode); + VDetail details; + bool supplement; + bool closed; + void NewItem(qint64 id, const Tool::Tools &typeTool, const Draw::Draws &mode, + const NodeDetail::NodeDetails &typeNode, qreal mx = 0, qreal my = 0); }; #endif // DIALOGDETAIL_H diff --git a/dialogs/dialogdetail.ui b/dialogs/dialogdetail.ui index 7f1370ed1..08aba5839 100644 --- a/dialogs/dialogdetail.ui +++ b/dialogs/dialogdetail.ui @@ -6,8 +6,8 @@ 0 0 - 340 - 298 + 544 + 327 @@ -20,47 +20,196 @@ - + - + - + - + + + 6 + + + QLayout::SetDefaultConstraint + + + 0 + + + 0 + - + + + Bias X + + + + + + + -10000.000000000000000 + + + 10000.000000000000000 + + + + + + + + + 0 0 - - - - Name detail + Bias Y - + + + -10000.000000000000000 + + + 10000.000000000000000 + + - - - - - Closed - - - true - - - - + + + Option + + + + + + + + + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 159 + 158 + 158 + + + + + + + + + + + Name of detail + + + + + + + + 0 + 0 + + + + + + + + + + Supplement for seams + + + true + + + + + + + + + + 0 + 0 + + + + + + + Width + + + + + + + -10000.000000000000000 + + + 10.000000000000000 + + + + + + + + + Closed + + + true + + + + + @@ -83,7 +232,6 @@ lineEditNameDetail - checkBoxClosed listWidget buttonBox diff --git a/dialogs/dialogendline.cpp b/dialogs/dialogendline.cpp index fc0530c0a..550ea4e0e 100644 --- a/dialogs/dialogendline.cpp +++ b/dialogs/dialogendline.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file dialogendline.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,18 +24,15 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "dialogendline.h" #include "ui_dialogendline.h" -#include -#include -#include "container/vpointf.h" -#include "container/calculator.h" -DialogEndLine::DialogEndLine(const VContainer *data, Draw::Draws mode, QWidget *parent) : - DialogTool(data, mode, parent), ui(new Ui::DialogEndLine), pointName(QString()), typeLine(QString()), - formula(QString()), angle(0), basePointId(0){ +DialogEndLine::DialogEndLine(const VContainer *data, Draw::Draws mode, QWidget *parent) + :DialogTool(data, mode, parent), ui(new Ui::DialogEndLine), pointName(QString()), typeLine(QString()), + formula(QString()), angle(0), basePointId(0) +{ ui->setupUi(this); spinBoxAngle = ui->doubleSpinBoxAngle; listWidget = ui->listWidget; @@ -38,6 +42,8 @@ DialogEndLine::DialogEndLine(const VContainer *data, Draw::Draws mode, QWidget * radioButtonStandartTable = ui->radioButtonStandartTable; radioButtonIncrements = ui->radioButtonIncrements; radioButtonLengthLine = ui->radioButtonLengthLine; + radioButtonLengthArc = ui->radioButtonLengthArc; + radioButtonLengthCurve = ui->radioButtonLengthSpline; lineEditFormula = ui->lineEditFormula; labelEditFormula = ui->labelEditFormula; labelEditNamePoint = ui->labelEditNamePoint; @@ -76,28 +82,39 @@ DialogEndLine::DialogEndLine(const VContainer *data, Draw::Draws mode, QWidget * connect(ui->radioButtonStandartTable, &QRadioButton::clicked, this, &DialogEndLine::StandartTable); connect(ui->radioButtonIncrements, &QRadioButton::clicked, this, &DialogEndLine::Increments); connect(ui->radioButtonLengthLine, &QRadioButton::clicked, this, &DialogEndLine::LengthLines); + connect(ui->radioButtonLengthArc, &QRadioButton::clicked, this, &DialogEndLine::LengthArcs); + connect(ui->radioButtonLengthSpline, &QRadioButton::clicked, this, &DialogEndLine::LengthCurves); connect(ui->toolButtonEqual, &QPushButton::clicked, this, &DialogEndLine::EvalFormula); connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogEndLine::NamePointChanged); connect(ui->lineEditFormula, &QLineEdit::textChanged, this, &DialogEndLine::FormulaChanged); } -void DialogEndLine::ChoosedObject(qint64 id, Scene::Scenes type){ - if(idDetail == 0 && mode == Draw::Modeling){ - if(type == Scene::Detail){ +void DialogEndLine::ChoosedObject(qint64 id, const Scene::Scenes &type) +{ + if (idDetail == 0 && mode == Draw::Modeling) + { + if (type == Scene::Detail) + { idDetail = id; return; } } - if(mode == Draw::Modeling){ - if(!CheckObject(id)){ + if (mode == Draw::Modeling) + { + if (CheckObject(id) == false) + { return; } } - if(type == Scene::Point){ + if (type == Scene::Point) + { VPointF point; - if(mode == Draw::Calculation){ + if (mode == Draw::Calculation) + { point = data->GetPoint(id); - } else { + } + else + { point = data->GetModelingPoint(id); } ChangeCurrentText(ui->comboBoxBasePoint, point.name()); @@ -106,51 +123,37 @@ void DialogEndLine::ChoosedObject(qint64 id, Scene::Scenes type){ } } -QString DialogEndLine::getPointName() const{ - return pointName; -} - -void DialogEndLine::setPointName(const QString &value){ +void DialogEndLine::setPointName(const QString &value) +{ pointName = value; ui->lineEditNamePoint->setText(pointName); } -QString DialogEndLine::getTypeLine() const{ - return typeLine; -} - -void DialogEndLine::setTypeLine(const QString &value){ +void DialogEndLine::setTypeLine(const QString &value) +{ typeLine = value; SetupTypeLine(ui->comboBoxLineType, value); } -QString DialogEndLine::getFormula() const{ - return formula; -} - -void DialogEndLine::setFormula(const QString &value){ +void DialogEndLine::setFormula(const QString &value) +{ formula = value; ui->lineEditFormula->setText(formula); } -qreal DialogEndLine::getAngle() const{ - return angle; -} - -void DialogEndLine::setAngle(const qreal &value){ +void DialogEndLine::setAngle(const qreal &value) +{ angle = value; ui->doubleSpinBoxAngle->setValue(angle); } -qint64 DialogEndLine::getBasePointId() const{ - return basePointId; -} - -void DialogEndLine::setBasePointId(const qint64 &value, const qint64 &id){ +void DialogEndLine::setBasePointId(const qint64 &value, const qint64 &id) +{ setCurrentPointId(ui->comboBoxBasePoint, basePointId, value, id); } -void DialogEndLine::DialogAccepted(){ +void DialogEndLine::DialogAccepted() +{ pointName = ui->lineEditNamePoint->text(); typeLine = GetTypeLine(ui->comboBoxLineType); formula = ui->lineEditFormula->text(); diff --git a/dialogs/dialogendline.h b/dialogs/dialogendline.h index 5053e6462..0dfd06401 100644 --- a/dialogs/dialogendline.h +++ b/dialogs/dialogendline.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file dialogendline.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,38 +24,36 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef DIALOGENDLINE_H #define DIALOGENDLINE_H #include "dialogtool.h" -#include -#include "container/calculator.h" -namespace Ui { -class DialogEndLine; +namespace Ui +{ + class DialogEndLine; } class DialogEndLine : public DialogTool { - Q_OBJECT + Q_OBJECT public: - explicit DialogEndLine(const VContainer *data, Draw::Draws mode = Draw::Calculation, - QWidget *parent = 0); + DialogEndLine(const VContainer *data, Draw::Draws mode = Draw::Calculation, QWidget *parent = 0); ~DialogEndLine(); - QString getPointName() const; + inline QString getPointName() const {return pointName;} void setPointName(const QString &value); - QString getTypeLine() const; + inline QString getTypeLine() const {return typeLine;} void setTypeLine(const QString &value); - QString getFormula() const; + inline QString getFormula() const {return formula;} void setFormula(const QString &value); - qreal getAngle() const; + inline qreal getAngle() const {return angle;} void setAngle(const qreal &value); - qint64 getBasePointId() const; + inline qint64 getBasePointId() const {return basePointId;} void setBasePointId(const qint64 &value, const qint64 &id); public slots: - virtual void ChoosedObject(qint64 id, Scene::Scenes type); + virtual void ChoosedObject(qint64 id, const Scene::Scenes &type); virtual void DialogAccepted(); private: Q_DISABLE_COPY(DialogEndLine) diff --git a/dialogs/dialogendline.ui b/dialogs/dialogendline.ui index 2b4c079ee..ad99685ca 100644 --- a/dialogs/dialogendline.ui +++ b/dialogs/dialogendline.ui @@ -500,7 +500,7 @@ - false + true Length of arcs @@ -510,7 +510,7 @@ - false + true Length of curves diff --git a/dialogs/dialogheight.cpp b/dialogs/dialogheight.cpp new file mode 100644 index 000000000..3ce7fb730 --- /dev/null +++ b/dialogs/dialogheight.cpp @@ -0,0 +1,149 @@ +/************************************************************************ + ** + ** @file dialogheight.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#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; + 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; +} + +void DialogHeight::setPointName(const QString &value) +{ + pointName = value; + ui->lineEditNamePoint->setText(pointName); +} + +void DialogHeight::setTypeLine(const QString &value) +{ + typeLine = value; + SetupTypeLine(ui->comboBoxLineType, value); +} + +void DialogHeight::setBasePointId(const qint64 &value, const qint64 &id) +{ + basePointId = value; + setCurrentPointId(ui->comboBoxBasePoint, basePointId, value, id); +} + +void DialogHeight::setP1LineId(const qint64 &value, const qint64 &id) +{ + p1LineId = value; + setCurrentPointId(ui->comboBoxP1Line, p1LineId, value, id); +} + +void DialogHeight::setP2LineId(const qint64 &value, const qint64 &id) +{ + p2LineId = value; + setCurrentPointId(ui->comboBoxP2Line, p2LineId, value, id); +} + +void DialogHeight::ChoosedObject(qint64 id, const Scene::Scenes &type) +{ + if (idDetail == 0 && mode == Draw::Modeling) + { + if (type == Scene::Detail) + { + idDetail = id; + return; + } + } + if (mode == Draw::Modeling) + { + if (CheckObject(id) == false) + { + 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 == false) + { + this->show(); + } + break; + default: + 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); +} diff --git a/dialogs/dialogheight.h b/dialogs/dialogheight.h new file mode 100644 index 000000000..186af6873 --- /dev/null +++ b/dialogs/dialogheight.h @@ -0,0 +1,70 @@ +/************************************************************************ + ** + ** @file dialogheight.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef DIALOGHEIGHT_H +#define DIALOGHEIGHT_H + +#include "dialogtool.h" + +namespace Ui +{ + class DialogHeight; +} + +class DialogHeight : public DialogTool +{ + Q_OBJECT +public: + DialogHeight(const VContainer *data, Draw::Draws mode = Draw::Calculation, + QWidget *parent = 0); + ~DialogHeight(); + inline QString getPointName() const {return pointName;} + void setPointName(const QString &value); + inline QString getTypeLine() const {return typeLine;} + void setTypeLine(const QString &value); + inline qint64 getBasePointId() const {return basePointId;} + void setBasePointId(const qint64 &value, const qint64 &id); + inline qint64 getP1LineId() const {return p1LineId;} + void setP1LineId(const qint64 &value, const qint64 &id); + inline qint64 getP2LineId() const{return p2LineId;} + void setP2LineId(const qint64 &value, const qint64 &id); +public slots: + virtual void ChoosedObject(qint64 id, const 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 diff --git a/dialogs/dialogheight.ui b/dialogs/dialogheight.ui new file mode 100644 index 000000000..9c4900050 --- /dev/null +++ b/dialogs/dialogheight.ui @@ -0,0 +1,214 @@ + + + DialogHeight + + + + 0 + 0 + 247 + 220 + + + + Dialog + + + + + + + + + + + + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 159 + 158 + 158 + + + + + + + + Name new point + + + + + + + + + + + + + + + 0 + 0 + + + + Base point + + + + + + + First point of line + + + + + + + + + + + + 0 + 0 + + + + First point of line + + + + + + + First point of line + + + + + + + + + + + + 0 + 0 + + + + Second point of line + + + + + + + First point of line + + + + + + + + + + + Type line + + + + + + + Show line from first point to our point + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + DialogHeight + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + DialogHeight + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/dialogs/dialoghistory.cpp b/dialogs/dialoghistory.cpp index 8e59671a3..fb2dcb0ca 100644 --- a/dialogs/dialoghistory.cpp +++ b/dialogs/dialoghistory.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file dialoghistory.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,18 +24,19 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "dialoghistory.h" #include "ui_dialoghistory.h" -#include "geometry/varc.h" -#include "geometry/vspline.h" -#include "geometry/vsplinepath.h" +#include "../geometry/varc.h" +#include "../geometry/vspline.h" +#include "../geometry/vsplinepath.h" #include -DialogHistory::DialogHistory(VContainer *data, VDomDocument *doc, QWidget *parent) : - DialogTool(data, Draw::Calculation, parent), ui(new Ui::DialogHistory), doc(doc), cursorRow(0), - cursorToolRecordRow(0){ +DialogHistory::DialogHistory(VContainer *data, VDomDocument *doc, QWidget *parent) + :DialogTool(data, Draw::Calculation, parent), ui(new Ui::DialogHistory), doc(doc), cursorRow(0), + cursorToolRecordRow(0) +{ ui->setupUi(this); bOk = ui->buttonBox->button(QDialogButtonBox::Ok); connect(bOk, &QPushButton::clicked, this, &DialogHistory::DialogAccepted); @@ -42,19 +50,23 @@ DialogHistory::DialogHistory(VContainer *data, VDomDocument *doc, QWidget *paren ShowPoint(); } -DialogHistory::~DialogHistory(){ +DialogHistory::~DialogHistory() +{ delete ui; } -void DialogHistory::DialogAccepted(){ +void DialogHistory::DialogAccepted() +{ QTableWidgetItem *item = ui->tableWidget->item(cursorToolRecordRow, 0); qint64 id = qvariant_cast(item->data(Qt::UserRole)); emit ShowHistoryTool(id, Qt::green, false); emit DialogClosed(QDialog::Accepted); } -void DialogHistory::cellClicked(int row, int column){ - if(column == 0){ +void DialogHistory::cellClicked(int row, int column) +{ + if (column == 0) + { QTableWidgetItem *item = ui->tableWidget->item(cursorRow, 0); item->setIcon(QIcon()); @@ -65,7 +77,9 @@ void DialogHistory::cellClicked(int row, int column){ disconnect(doc, &VDomDocument::ChangedCursor, this, &DialogHistory::ChangedCursor); doc->setCursor(id); connect(doc, &VDomDocument::ChangedCursor, this, &DialogHistory::ChangedCursor); - } else { + } + else + { QTableWidgetItem *item = ui->tableWidget->item(cursorToolRecordRow, 0); qint64 id = qvariant_cast(item->data(Qt::UserRole)); emit ShowHistoryTool(id, Qt::green, false); @@ -77,11 +91,14 @@ void DialogHistory::cellClicked(int row, int column){ } } -void DialogHistory::ChangedCursor(qint64 id){ - for(qint32 i = 0; i< ui->tableWidget->rowCount(); ++i){ +void DialogHistory::ChangedCursor(qint64 id) +{ + for (qint32 i = 0; i< ui->tableWidget->rowCount(); ++i) + { QTableWidgetItem *item = ui->tableWidget->item(i, 0); qint64 rId = qvariant_cast(item->data(Qt::UserRole)); - if(rId == id){ + if (rId == id) + { QTableWidgetItem *oldCursorItem = ui->tableWidget->item(cursorRow, 0); oldCursorItem->setIcon(QIcon()); cursorRow = i; @@ -90,20 +107,24 @@ void DialogHistory::ChangedCursor(qint64 id){ } } -void DialogHistory::UpdateHistory(){ +void DialogHistory::UpdateHistory() +{ FillTable(); InitialTable(); } -void DialogHistory::FillTable(){ +void DialogHistory::FillTable() +{ ui->tableWidget->clear(); QVector *history = doc->getHistory(); qint32 currentRow = -1; qint32 count = 0; ui->tableWidget->setRowCount(history->size()); - for(qint32 i = 0; i< history->size(); ++i){ + for (qint32 i = 0; i< history->size(); ++i) + { VToolRecord tool = history->at(i); - if(tool.getNameDraw() != doc->GetNameActivDraw()){ + if (tool.getNameDraw() != doc->GetNameActivDraw()) + { continue; } currentRow++; @@ -121,7 +142,8 @@ void DialogHistory::FillTable(){ ++count; } ui->tableWidget->setRowCount(count); - if(history->size()>0){ + if (history->size()>0) + { cursorRow = currentRow; QTableWidgetItem *item = ui->tableWidget->item(cursorRow, 0); item->setIcon(QIcon("://icon/32x32/put_after.png")); @@ -131,7 +153,8 @@ void DialogHistory::FillTable(){ ui->tableWidget->verticalHeader()->setDefaultSectionSize(20); } -QString DialogHistory::Record(const VToolRecord &tool){ +QString DialogHistory::Record(const VToolRecord &tool) +{ QString record = QString(); qint64 basePointId = 0; qint64 secondPointId = 0; @@ -143,7 +166,8 @@ QString DialogHistory::Record(const VToolRecord &tool){ qint64 p2Line2 = 0; qint64 center = 0; QDomElement domElement; - switch( tool.getTypeTool() ){ + switch ( tool.getTypeTool() ) + { case Tool::ArrowTool: break; case Tool::SinglePointTool: @@ -151,7 +175,8 @@ QString DialogHistory::Record(const VToolRecord &tool){ break; case Tool::EndLineTool: domElement = doc->elementById(QString().setNum(tool.getId())); - if(domElement.isElement()){ + if (domElement.isElement()) + { basePointId = domElement.attribute("basePoint", "").toLongLong(); } record = QString(tr("%1_%2 - Line from point %1 to point %2")).arg(data->GetPoint(basePointId).name(), @@ -159,7 +184,8 @@ QString DialogHistory::Record(const VToolRecord &tool){ break; case Tool::LineTool: domElement = doc->elementById(QString().setNum(tool.getId())); - if(domElement.isElement()){ + if (domElement.isElement()) + { firstPointId = domElement.attribute("firstPoint", "").toLongLong(); secondPointId = domElement.attribute("secondPoint", "").toLongLong(); } @@ -168,7 +194,8 @@ QString DialogHistory::Record(const VToolRecord &tool){ break; case Tool::AlongLineTool: domElement = doc->elementById(QString().setNum(tool.getId())); - if(domElement.isElement()){ + if (domElement.isElement()) + { basePointId = domElement.attribute("firstPoint", "").toLongLong(); secondPointId = domElement.attribute("secondPoint", "").toLongLong(); } @@ -181,7 +208,8 @@ QString DialogHistory::Record(const VToolRecord &tool){ break; case Tool::NormalTool: domElement = doc->elementById(QString().setNum(tool.getId())); - if(domElement.isElement()){ + if (domElement.isElement()) + { basePointId = domElement.attribute("firstPoint", "").toLongLong(); secondPointId = domElement.attribute("secondPoint", "").toLongLong(); } @@ -191,7 +219,8 @@ QString DialogHistory::Record(const VToolRecord &tool){ break; case Tool::BisectorTool: domElement = doc->elementById(QString().setNum(tool.getId())); - if(domElement.isElement()){ + if (domElement.isElement()) + { firstPointId = domElement.attribute("firstPoint", "").toLongLong(); basePointId = domElement.attribute("secondPoint", "").toLongLong(); thirdPointId = domElement.attribute("thirdPoint", "").toLongLong(); @@ -203,7 +232,8 @@ QString DialogHistory::Record(const VToolRecord &tool){ break; case Tool::LineIntersectTool: domElement = doc->elementById(QString().setNum(tool.getId())); - if(domElement.isElement()){ + if (domElement.isElement()) + { p1Line1 = domElement.attribute("p1Line1", "").toLongLong(); p2Line1 = domElement.attribute("p2Line1", "").toLongLong(); p1Line2 = domElement.attribute("p1Line2", "").toLongLong(); @@ -213,43 +243,81 @@ QString DialogHistory::Record(const VToolRecord &tool){ data->GetPoint(p2Line1).name(), data->GetPoint(p1Line2).name(), data->GetPoint(p2Line2).name(), - data->GetPoint(tool.getId()).name()); + data->GetPoint(tool.getId()).name()); break; - case Tool::SplineTool:{ + case Tool::SplineTool: + { VSpline spl = data->GetSpline(tool.getId()); record = QString(tr("Curve %1_%2")).arg(data->GetPoint(spl.GetP1()).name(), data->GetPoint(spl.GetP4()).name()); } break; - case Tool::ArcTool:{ + case Tool::ArcTool: + { VArc arc = data->GetArc(tool.getId()); record = QString(tr("Arc with center in point %1")).arg(data->GetPoint(arc.GetCenter()).name()); } break; - case Tool::SplinePathTool:{ + case Tool::SplinePathTool: + { VSplinePath splPath = data->GetSplinePath(tool.getId()); QVector points = splPath.GetSplinePath(); - if(points.size() != 0 ){ + if (points.size() != 0 ) + { record = QString(tr("Curve point %1")).arg(data->GetPoint(points[0].P()).name()); - for(qint32 i = 1; i< points.size(); ++i){ + for (qint32 i = 1; i< points.size(); ++i) + { QString name = QString("_%1").arg(data->GetPoint(points[i].P()).name()); record.append(name); } } } - break; + break; case Tool::PointOfContact: domElement = doc->elementById(QString().setNum(tool.getId())); - if(domElement.isElement()){ + if (domElement.isElement()) + { center = domElement.attribute("center", "").toLongLong(); firstPointId = domElement.attribute("firstPoint", "").toLongLong(); secondPointId = domElement.attribute("secondPoint", "").toLongLong(); } - record = QString(tr("%4 - Point of contact arc with center in point %1 and line %2_%3")).arg(data->GetPoint(center).name(), - data->GetPoint(firstPointId).name(), - data->GetPoint(secondPointId).name(), - data->GetPoint(tool.getId()).name()); + record = QString(tr("%4 - Point of contact arc with center in point %1 and line %2_%3")).arg( + data->GetPoint(center).name(), data->GetPoint(firstPointId).name(), + 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; + } + case Tool::Triangle: + { + qint64 axisP1Id = 0; + qint64 axisP2Id = 0; + domElement = doc->elementById(QString().setNum(tool.getId())); + if (domElement.isElement()) + { + axisP1Id = domElement.attribute("axisP1", "").toLongLong(); + axisP2Id = domElement.attribute("axisP2", "").toLongLong(); + firstPointId = domElement.attribute("firstPoint", "").toLongLong(); + secondPointId = domElement.attribute("secondPoint", "").toLongLong(); + } + record = QString(tr("Triangle: axis %1_%2, points %3 and %4")).arg( + data->GetPoint(axisP1Id).name(), data->GetPoint(axisP2Id).name(), + data->GetPoint(firstPointId).name(), data->GetPoint(secondPointId).name()); + break; + } default: qWarning()<tableWidget->setSortingEnabled(false); ui->tableWidget->setHorizontalHeaderItem(0, new QTableWidgetItem(" ")); ui->tableWidget->setHorizontalHeaderItem(1, new QTableWidgetItem(tr("Tool"))); } -void DialogHistory::ShowPoint(){ +void DialogHistory::ShowPoint() +{ QVector *history = doc->getHistory(); - if(history->size()>0){ + if (history->size()>0) + { QTableWidgetItem *item = ui->tableWidget->item(0, 1); item->setSelected(true); cursorToolRecordRow = 0; @@ -275,8 +346,8 @@ void DialogHistory::ShowPoint(){ } } - -void DialogHistory::closeEvent(QCloseEvent *event){ +void DialogHistory::closeEvent(QCloseEvent *event) +{ QTableWidgetItem *item = ui->tableWidget->item(cursorToolRecordRow, 0); qint64 id = qvariant_cast(item->data(Qt::UserRole)); emit ShowHistoryTool(id, Qt::green, false); diff --git a/dialogs/dialoghistory.h b/dialogs/dialoghistory.h index a515a94a2..692f265c3 100644 --- a/dialogs/dialoghistory.h +++ b/dialogs/dialoghistory.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file dialoghistory.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,44 +24,44 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef DIALOGHISTORY_H #define DIALOGHISTORY_H #include "dialogtool.h" -#include "xml/vdomdocument.h" +#include "../xml/vdomdocument.h" -namespace Ui { -class DialogHistory; +namespace Ui +{ + class DialogHistory; } class DialogHistory : public DialogTool { Q_OBJECT - public: - explicit DialogHistory(VContainer *data, VDomDocument *doc, QWidget *parent = 0); - virtual ~DialogHistory(); + DialogHistory(VContainer *data, VDomDocument *doc, QWidget *parent = 0); + virtual ~DialogHistory(); public slots: - virtual void DialogAccepted(); - void cellClicked(int row, int column); - void ChangedCursor(qint64 id); - void UpdateHistory(); + virtual void DialogAccepted(); + void cellClicked(int row, int column); + void ChangedCursor(qint64 id); + void UpdateHistory(); signals: - void ShowHistoryTool(qint64 id, Qt::GlobalColor color, bool enable); + void ShowHistoryTool(qint64 id, Qt::GlobalColor color, bool enable); protected: - virtual void closeEvent ( QCloseEvent * event ); + virtual void closeEvent ( QCloseEvent * event ); private: Q_DISABLE_COPY(DialogHistory) Ui::DialogHistory *ui; - VDomDocument *doc; - qint32 cursorRow; - qint32 cursorToolRecordRow; - void FillTable(); - QString Record(const VToolRecord &tool); - void InitialTable(); - void ShowPoint(); + VDomDocument *doc; + qint32 cursorRow; + qint32 cursorToolRecordRow; + void FillTable(); + QString Record(const VToolRecord &tool); + void InitialTable(); + void ShowPoint(); }; #endif // DIALOGHISTORY_H diff --git a/dialogs/dialogincrements.cpp b/dialogs/dialogincrements.cpp index 7ea38338c..a50fd47dc 100644 --- a/dialogs/dialogincrements.cpp +++ b/dialogs/dialogincrements.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file dialogincrements.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,22 +24,22 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "dialogincrements.h" #include "ui_dialogincrements.h" -#include -#include -#include "widgets/doubledelegate.h" -#include "container/vincrementtablerow.h" -#include +#include "../widgets/doubledelegate.h" +#include "../exception/vexception.h" -DialogIncrements::DialogIncrements(VContainer *data, VDomDocument *doc, QWidget *parent) : - DialogTool(data, Draw::Calculation, parent), ui(new Ui::DialogIncrements), data(data), doc(doc){ +DialogIncrements::DialogIncrements(VContainer *data, VDomDocument *doc, QWidget *parent) + :DialogTool(data, Draw::Calculation, parent), ui(new Ui::DialogIncrements), data(data), doc(doc), row(0), column(0) +{ ui->setupUi(this); InitialStandartTable(); InitialIncrementTable(); InitialLinesTable(); + InitialSplinesTable(); + InitialArcsTable(); DoubleSpinBoxDelegate *doubleDelegate = new DoubleSpinBoxDelegate(ui->tableWidgetIncrement); ui->tableWidgetIncrement->setItemDelegateForColumn(2, doubleDelegate); ui->tableWidgetIncrement->setItemDelegateForColumn(3, doubleDelegate); @@ -40,7 +47,10 @@ DialogIncrements::DialogIncrements(VContainer *data, VDomDocument *doc, QWidget FillStandartTable(); FillIncrementTable(); FillLengthLines(); + FillLengthSplines(); + FillLengthArcs(); + connect(ui->tableWidgetIncrement, &QTableWidget::cellChanged, this, &DialogIncrements::cellChanged); connect(ui->toolButtonAdd, &QPushButton::clicked, this, &DialogIncrements::clickedToolButtonAdd); connect(ui->toolButtonRemove, &QPushButton::clicked, this, &DialogIncrements::clickedToolButtonRemove); @@ -52,14 +62,17 @@ DialogIncrements::DialogIncrements(VContainer *data, VDomDocument *doc, QWidget bOk = ui->buttonBox->button(QDialogButtonBox::Ok); connect(bOk, &QPushButton::clicked, this, &DialogIncrements::DialogAccepted); + ui->tabWidget->setCurrentIndex(0); } -void DialogIncrements::FillStandartTable(){ +void DialogIncrements::FillStandartTable() +{ const QHash *standartTable = data->DataStandartTable(); qint32 currentRow = -1; QHashIterator i(*standartTable); ui->tableWidgetStandart->setRowCount ( standartTable->size() ); - while (i.hasNext()) { + while (i.hasNext()) + { i.next(); VStandartTableCell cell = i.value(); currentRow++; @@ -94,12 +107,14 @@ void DialogIncrements::FillStandartTable(){ ui->tableWidgetStandart->verticalHeader()->setDefaultSectionSize(20); } -void DialogIncrements::FillIncrementTable(){ +void DialogIncrements::FillIncrementTable() +{ const QHash *incrementTable = data->DataIncrementTable(); QHashIterator i(*incrementTable); QMap map; //Sorting QHash by id - while (i.hasNext()) { + while (i.hasNext()) + { i.next(); VIncrementTableRow cell = i.value(); map.insert(cell.getId(), i.key()); @@ -107,7 +122,8 @@ void DialogIncrements::FillIncrementTable(){ qint32 currentRow = -1; QMapIterator iMap(map); - while (iMap.hasNext()) { + while (iMap.hasNext()) + { iMap.next(); VIncrementTableRow cell = incrementTable->value(iMap.value()); currentRow++; @@ -140,22 +156,34 @@ void DialogIncrements::FillIncrementTable(){ ui->tableWidgetIncrement->setItem(currentRow, 4, item); item = new QTableWidgetItem(cell.getDescription()); - item->setTextAlignment(Qt::AlignHCenter); + item->setTextAlignment(Qt::AlignLeft); ui->tableWidgetIncrement->setItem(currentRow, 5, item); } - if(ui->tableWidgetIncrement->rowCount()>0){ + if (ui->tableWidgetIncrement->rowCount()>0) + { ui->toolButtonRemove->setEnabled(true); } ui->tableWidgetIncrement->resizeColumnsToContents(); ui->tableWidgetIncrement->resizeRowsToContents(); - ui->tableWidgetIncrement->verticalHeader()->setDefaultSectionSize(20); + ui->tableWidgetIncrement->setCurrentCell( row, column ); } -void DialogIncrements::FillLengthLines(){ +void DialogIncrements::FillLengthLines() +{ const QHash *linesTable = data->DataLengthLines(); + QHashIterator iHash(*linesTable); + QMap map; + //Sorting QHash by name + while (iHash.hasNext()) + { + iHash.next(); + map.insert(iHash.key(), iHash.value()); + } + qint32 currentRow = -1; - QHashIterator i(*linesTable); - while (i.hasNext()) { + QMapIterator i(map); + while (i.hasNext()) + { i.next(); qreal length = i.value(); currentRow++; @@ -175,18 +203,29 @@ void DialogIncrements::FillLengthLines(){ ui->tableWidgetLines->verticalHeader()->setDefaultSectionSize(20); } -void DialogIncrements::FillLengthSplines(){ +void DialogIncrements::FillLengthSplines() +{ const QHash *splinesTable = data->DataLengthSplines(); + QHashIterator iHash(*splinesTable); + QMap map; + //Sorting QHash by name + while (iHash.hasNext()) + { + iHash.next(); + map.insert(iHash.key(), iHash.value()); + } + qint32 currentRow = -1; - QHashIterator i(*splinesTable); - while (i.hasNext()) { + QMapIterator i(map); + while (i.hasNext()) + { i.next(); qreal length = i.value(); currentRow++; ui->tableWidgetSplines->setRowCount ( splinesTable->size() ); QTableWidgetItem *item = new QTableWidgetItem(QString(i.key())); - item->setTextAlignment(Qt::AlignHCenter); + item->setTextAlignment(Qt::AlignLeft); item->setFont(QFont("Times", 12, QFont::Bold)); ui->tableWidgetSplines->setItem(currentRow, 0, item); @@ -199,11 +238,22 @@ void DialogIncrements::FillLengthSplines(){ ui->tableWidgetSplines->verticalHeader()->setDefaultSectionSize(20); } -void DialogIncrements::FillLengthArcs(){ +void DialogIncrements::FillLengthArcs() +{ const QHash *arcsTable = data->DataLengthArcs(); + QHashIterator iHash(*arcsTable); + QMap map; + //Sorting QHash by name + while (iHash.hasNext()) + { + iHash.next(); + map.insert(iHash.key(), iHash.value()); + } + qint32 currentRow = -1; - QHashIterator i(*arcsTable); - while (i.hasNext()) { + QMapIterator i(map); + while (i.hasNext()) + { i.next(); qreal length = i.value(); currentRow++; @@ -223,7 +273,8 @@ void DialogIncrements::FillLengthArcs(){ ui->tableWidgetArcs->verticalHeader()->setDefaultSectionSize(20); } -void DialogIncrements::FullUpdateFromFile(){ +void DialogIncrements::FullUpdateFromFile() +{ disconnect(ui->tableWidgetIncrement, &QTableWidget::cellChanged, this, &DialogIncrements::cellChanged); @@ -251,7 +302,8 @@ void DialogIncrements::FullUpdateFromFile(){ &DialogIncrements::cellChanged); } -void DialogIncrements::clickedToolButtonAdd(){ +void DialogIncrements::clickedToolButtonAdd() +{ disconnect(ui->tableWidgetIncrement, &QTableWidget::cellChanged, this, &DialogIncrements::cellChanged); ui->tableWidgetIncrement->setFocus(Qt::OtherFocusReason); @@ -260,10 +312,11 @@ void DialogIncrements::clickedToolButtonAdd(){ qint32 num = 1; QString name; - do{ + do + { name = QString(tr("Denotation %1")).arg(num); num++; - }while(data->IncrementTableContains(name)); + } while (data->IncrementTableContains(name)); qint64 id = data->getNextId(); qreal base = 0; @@ -309,9 +362,11 @@ void DialogIncrements::clickedToolButtonAdd(){ ui->toolButtonRemove->setEnabled(true); connect(ui->tableWidgetIncrement, &QTableWidget::cellChanged, this, &DialogIncrements::cellChanged); + emit haveLiteChange(); } -void DialogIncrements::clickedToolButtonRemove(){ +void DialogIncrements::clickedToolButtonRemove() +{ disconnect(ui->tableWidgetIncrement, &QTableWidget::cellChanged, this, &DialogIncrements::cellChanged); QTableWidgetItem *item = ui->tableWidgetIncrement->currentItem(); @@ -320,20 +375,24 @@ void DialogIncrements::clickedToolButtonRemove(){ data->RemoveIncrementTableRow(itemName->text()); qint64 id = qvariant_cast(item->data(Qt::UserRole)); QDomElement domElement = doc->elementById(QString().setNum(id)); - if(domElement.isElement()){ + if (domElement.isElement()) + { QDomNodeList list = doc->elementsByTagName("increments"); list.at(0).removeChild(domElement); } ui->tableWidgetIncrement->removeRow(row); - if(ui->tableWidgetIncrement->rowCount() == 0){ + if (ui->tableWidgetIncrement->rowCount() == 0) + { ui->toolButtonRemove->setEnabled(false); } connect(ui->tableWidgetIncrement, &QTableWidget::cellChanged, this, &DialogIncrements::cellChanged); + emit haveLiteChange(); } -void DialogIncrements::AddIncrementToFile(qint64 id, QString name, qreal base, qreal ksize, - qreal kgrowth, QString description){ +void DialogIncrements::AddIncrementToFile(qint64 id, QString name, qreal base, qreal ksize, qreal kgrowth, + QString description) +{ QDomNodeList list = doc->elementsByTagName("increments"); QDomElement element = doc->createElement("increment"); @@ -364,19 +423,24 @@ void DialogIncrements::AddIncrementToFile(qint64 id, QString name, qreal base, q list.at(0).appendChild(element); } -void DialogIncrements::cellChanged ( qint32 row, qint32 column ){ - QTableWidgetItem *item; - QTableWidgetItem *itemName; +void DialogIncrements::cellChanged ( qint32 row, qint32 column ) +{ + QTableWidgetItem *item = 0; + QTableWidgetItem *itemName = 0; qint64 id; QDomElement domElement; - switch(column) { + this->row = row; + switch (column) + { case 0: item = ui->tableWidgetIncrement->item(row, 0); id = qvariant_cast(item->data(Qt::UserRole)); domElement = doc->elementById(QString().setNum(id)); - if(domElement.isElement()){ + if (domElement.isElement()) + { domElement.setAttribute("name", item->text()); data->ClearIncrementTable(); + this->column = 2; emit FullUpdateTree(); } break; @@ -385,9 +449,20 @@ void DialogIncrements::cellChanged ( qint32 row, qint32 column ){ item = ui->tableWidgetIncrement->item(row, column); id = qvariant_cast(itemName->data(Qt::UserRole)); domElement = doc->elementById(QString().setNum(id)); - if(domElement.isElement()){ - domElement.setAttribute("base", item->text().toDouble()); - emit FullUpdateTree(); + if (domElement.isElement()) + { + bool ok = false; + qreal value = item->text().toDouble(&ok); + if (ok) + { + domElement.setAttribute("base", value); + this->column = 3; + emit FullUpdateTree(); + } + else + { + throw VException(tr("Can't convert toDouble value.")); + } } break; case 3: @@ -395,8 +470,10 @@ void DialogIncrements::cellChanged ( qint32 row, qint32 column ){ item = ui->tableWidgetIncrement->item(row, column); id = qvariant_cast(itemName->data(Qt::UserRole)); domElement = doc->elementById(QString().setNum(id)); - if(domElement.isElement()){ + if (domElement.isElement()) + { domElement.setAttribute("ksize", item->text().toDouble()); + this->column = 4; emit FullUpdateTree(); } break; @@ -405,8 +482,10 @@ void DialogIncrements::cellChanged ( qint32 row, qint32 column ){ item = ui->tableWidgetIncrement->item(row, column); id = qvariant_cast(itemName->data(Qt::UserRole)); domElement = doc->elementById(QString().setNum(id)); - if(domElement.isElement()){ + if (domElement.isElement()) + { domElement.setAttribute("kgrowth", item->text().toDouble()); + this->column = 5; emit FullUpdateTree(); } break; @@ -415,18 +494,25 @@ void DialogIncrements::cellChanged ( qint32 row, qint32 column ){ item = ui->tableWidgetIncrement->item(row, column); id = qvariant_cast(itemName->data(Qt::UserRole)); domElement = doc->elementById(QString().setNum(id)); - if(domElement.isElement()){ + if (domElement.isElement()) + { domElement.setAttribute("description", item->text()); VIncrementTableRow incr = data->GetIncrementTableRow(itemName->text()); incr.setDescription(item->text()); data->UpdateIncrementTableRow(itemName->text(), incr); + ui->tableWidgetIncrement->resizeColumnsToContents(); + ui->tableWidgetIncrement->resizeRowsToContents(); + ui->tableWidgetIncrement->setCurrentCell( row, 0 ); emit haveLiteChange(); } break; + default: + break; } } -void DialogIncrements::InitialStandartTable(){ +void DialogIncrements::InitialStandartTable() +{ ui->tableWidgetStandart->setSortingEnabled(false); ui->tableWidgetStandart->setHorizontalHeaderItem(0, new QTableWidgetItem(tr("Denotation"))); ui->tableWidgetStandart->setHorizontalHeaderItem(1, new QTableWidgetItem(tr("Calculated value"))); @@ -436,7 +522,8 @@ void DialogIncrements::InitialStandartTable(){ ui->tableWidgetStandart->setHorizontalHeaderItem(5, new QTableWidgetItem(tr("Description"))); } -void DialogIncrements::InitialIncrementTable(){ +void DialogIncrements::InitialIncrementTable() +{ ui->tableWidgetIncrement->setSortingEnabled(false); ui->tableWidgetIncrement->setHorizontalHeaderItem(0, new QTableWidgetItem(tr("Denotation"))); ui->tableWidgetIncrement->setHorizontalHeaderItem(1, new QTableWidgetItem(tr("Calculated value"))); @@ -444,27 +531,33 @@ void DialogIncrements::InitialIncrementTable(){ ui->tableWidgetIncrement->setHorizontalHeaderItem(3, new QTableWidgetItem(tr("In size"))); ui->tableWidgetIncrement->setHorizontalHeaderItem(4, new QTableWidgetItem(tr("In growth"))); ui->tableWidgetIncrement->setHorizontalHeaderItem(5, new QTableWidgetItem(tr("Description"))); + ui->tableWidgetIncrement->verticalHeader()->setDefaultSectionSize(20); } -void DialogIncrements::InitialLinesTable(){ +void DialogIncrements::InitialLinesTable() +{ ui->tableWidgetLines->setHorizontalHeaderItem(0, new QTableWidgetItem(tr("Line"))); ui->tableWidgetLines->setHorizontalHeaderItem(1, new QTableWidgetItem(tr("Length"))); } -void DialogIncrements::InitialSplinesTable(){ +void DialogIncrements::InitialSplinesTable() +{ ui->tableWidgetSplines->setHorizontalHeaderItem(0, new QTableWidgetItem(tr("Curve"))); ui->tableWidgetSplines->setHorizontalHeaderItem(1, new QTableWidgetItem(tr("Length"))); } -void DialogIncrements::InitialArcsTable(){ +void DialogIncrements::InitialArcsTable() +{ ui->tableWidgetArcs->setHorizontalHeaderItem(0, new QTableWidgetItem(tr("Arc"))); ui->tableWidgetArcs->setHorizontalHeaderItem(1, new QTableWidgetItem(tr("Length"))); } -void DialogIncrements::DialogAccepted(){ +void DialogIncrements::DialogAccepted() +{ emit DialogClosed(QDialog::Accepted); } -DialogIncrements::~DialogIncrements(){ +DialogIncrements::~DialogIncrements() +{ delete ui; } diff --git a/dialogs/dialogincrements.h b/dialogs/dialogincrements.h index ed357e92a..58fa46611 100644 --- a/dialogs/dialogincrements.h +++ b/dialogs/dialogincrements.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file dialogincrements.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,50 +24,53 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef DIALOGINCREMENTS_H #define DIALOGINCREMENTS_H #include "dialogtool.h" -#include "xml/vdomdocument.h" +#include "../xml/vdomdocument.h" -namespace Ui { -class DialogIncrements; +namespace Ui +{ + class DialogIncrements; } class DialogIncrements : public DialogTool { - Q_OBJECT + Q_OBJECT public: - explicit DialogIncrements(VContainer *data, VDomDocument *doc, QWidget *parent = 0); - ~DialogIncrements(); + DialogIncrements(VContainer *data, VDomDocument *doc, QWidget *parent = 0); + ~DialogIncrements(); public slots: - void clickedToolButtonAdd(); - void clickedToolButtonRemove(); - void cellChanged ( qint32 row, qint32 column ); - void FullUpdateFromFile(); - virtual void DialogAccepted(); + void clickedToolButtonAdd(); + void clickedToolButtonRemove(); + void cellChanged ( qint32 row, qint32 column ); + void FullUpdateFromFile(); + virtual void DialogAccepted(); signals: - void FullUpdateTree(); - void haveLiteChange(); + void FullUpdateTree(); + void haveLiteChange(); private: Q_DISABLE_COPY(DialogIncrements) Ui::DialogIncrements *ui; - VContainer *data; // need because we must change data - VDomDocument *doc; - void InitialStandartTable(); - void InitialIncrementTable(); - void InitialLinesTable(); - void InitialSplinesTable(); - void InitialArcsTable(); - void FillStandartTable(); - void FillIncrementTable(); - void FillLengthLines(); - void FillLengthSplines(); - void FillLengthArcs(); - void AddIncrementToFile(qint64 id, QString name, qreal base, qreal ksize, qreal kgrowth, - QString description); + VContainer *data; // need because we must change data + VDomDocument *doc; + qint32 row; + qint32 column; + void InitialStandartTable(); + void InitialIncrementTable(); + void InitialLinesTable(); + void InitialSplinesTable(); + void InitialArcsTable(); + void FillStandartTable(); + void FillIncrementTable(); + void FillLengthLines(); + void FillLengthSplines(); + void FillLengthArcs(); + void AddIncrementToFile(qint64 id, QString name, qreal base, qreal ksize, qreal kgrowth, + QString description); }; #endif // DIALOGINCREMENTS_H diff --git a/dialogs/dialogincrements.ui b/dialogs/dialogincrements.ui index a76b4ca69..74203d5cc 100644 --- a/dialogs/dialogincrements.ui +++ b/dialogs/dialogincrements.ui @@ -27,7 +27,7 @@ QTabWidget::North - 4 + 1 @@ -149,9 +149,15 @@ false + + false + 45 + + false + Denotation diff --git a/dialogs/dialogline.cpp b/dialogs/dialogline.cpp index 784d6448a..f14c311d8 100644 --- a/dialogs/dialogline.cpp +++ b/dialogs/dialogline.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file dialogline.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,15 +24,14 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "dialogline.h" #include "ui_dialogline.h" -#include -#include -DialogLine::DialogLine(const VContainer *data, Draw::Draws mode, QWidget *parent) : - DialogTool(data, mode, parent), ui(new Ui::DialogLine), number(0), firstPoint(0), secondPoint(0){ +DialogLine::DialogLine(const VContainer *data, Draw::Draws mode, QWidget *parent) + :DialogTool(data, mode, parent), ui(new Ui::DialogLine), number(0), firstPoint(0), secondPoint(0) +{ ui->setupUi(this); bOk = ui->buttonBox->button(QDialogButtonBox::Ok); connect(bOk, &QPushButton::clicked, this, &DialogLine::DialogAccepted); @@ -36,38 +42,36 @@ DialogLine::DialogLine(const VContainer *data, Draw::Draws mode, QWidget *parent number = 0; } -DialogLine::~DialogLine(){ +DialogLine::~DialogLine() +{ delete ui; } -qint64 DialogLine::getSecondPoint() const{ - return secondPoint; -} - -void DialogLine::setSecondPoint(const qint64 &value){ +void DialogLine::setSecondPoint(const qint64 &value) +{ secondPoint = value; VPointF point = data->GetPoint(value); qint32 index = ui->comboBoxSecondPoint->findText(point.name()); - if(index != -1){ + if (index != -1) + { ui->comboBoxSecondPoint->setCurrentIndex(index); } } -qint64 DialogLine::getFirstPoint() const{ - return firstPoint; -} - -void DialogLine::setFirstPoint(const qint64 &value){ +void DialogLine::setFirstPoint(const qint64 &value) +{ firstPoint = value; VPointF point = data->GetPoint(value); qint32 index = ui->comboBoxFirstPoint->findText(point.name()); - if(index != -1){ + if (index != -1) + { ui->comboBoxFirstPoint->setCurrentIndex(index); } } -void DialogLine::DialogAccepted(){ +void DialogLine::DialogAccepted() +{ qint32 index = ui->comboBoxFirstPoint->currentIndex(); firstPoint = qvariant_cast(ui->comboBoxFirstPoint->itemData(index)); index = ui->comboBoxSecondPoint->currentIndex(); @@ -75,42 +79,56 @@ void DialogLine::DialogAccepted(){ DialogClosed(QDialog::Accepted); } -void DialogLine::ChoosedObject(qint64 id, Scene::Scenes type){ - if(idDetail == 0 && mode == Draw::Modeling){ - if(type == Scene::Detail){ +void DialogLine::ChoosedObject(qint64 id, const Scene::Scenes &type) +{ + if (idDetail == 0 && mode == Draw::Modeling) + { + if (type == Scene::Detail) + { idDetail = id; return; } } - if(mode == Draw::Modeling){ - if(!CheckObject(id)){ + if (mode == Draw::Modeling) + { + if (CheckObject(id) == false) + { return; } } - if(type == Scene::Point){ + if (type == Scene::Point) + { VPointF point; - if(mode == Draw::Calculation){ + if (mode == Draw::Calculation) + { point = data->GetPoint(id); - } else { + } + else + { point = data->GetModelingPoint(id); } - if(number == 0){ + if (number == 0) + { qint32 index = ui->comboBoxFirstPoint->findText(point.name()); - if ( index != -1 ) { // -1 for not found + if ( index != -1 ) + { // -1 for not found ui->comboBoxFirstPoint->setCurrentIndex(index); number++; emit ToolTip(tr("Select second point")); return; } } - if(number == 1){ + if (number == 1) + { qint32 index = ui->comboBoxSecondPoint->findText(point.name()); - if ( index != -1 ) { // -1 for not found + if ( index != -1 ) + { // -1 for not found ui->comboBoxSecondPoint->setCurrentIndex(index); number = 0; emit ToolTip(""); } - if(!isInitialized){ + if (isInitialized == false) + { this->show(); } } diff --git a/dialogs/dialogline.h b/dialogs/dialogline.h index dca627eaa..d0e3c9d1c 100644 --- a/dialogs/dialogline.h +++ b/dialogs/dialogline.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file dialogline.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,30 +24,30 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef DIALOGLINE_H #define DIALOGLINE_H #include "dialogtool.h" -namespace Ui { -class DialogLine; +namespace Ui +{ + class DialogLine; } class DialogLine : public DialogTool { Q_OBJECT public: - explicit DialogLine(const VContainer *data, Draw::Draws mode = Draw::Calculation, - QWidget *parent = 0); - ~DialogLine(); - qint64 getFirstPoint() const; + DialogLine(const VContainer *data, Draw::Draws mode = Draw::Calculation, QWidget *parent = 0); + ~DialogLine(); + inline qint64 getFirstPoint() const {return firstPoint;} void setFirstPoint(const qint64 &value); - qint64 getSecondPoint() const; + inline qint64 getSecondPoint() const {return secondPoint;} void setSecondPoint(const qint64 &value); public slots: - void ChoosedObject(qint64 id, Scene::Scenes type); + void ChoosedObject(qint64 id, const Scene::Scenes &type); virtual void DialogAccepted(); private: Q_DISABLE_COPY(DialogLine) diff --git a/dialogs/dialoglineintersect.cpp b/dialogs/dialoglineintersect.cpp index 3388a331e..29ac3375f 100644 --- a/dialogs/dialoglineintersect.cpp +++ b/dialogs/dialoglineintersect.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file dialoglineintersect.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,14 +24,15 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "dialoglineintersect.h" #include "ui_dialoglineintersect.h" -DialogLineIntersect::DialogLineIntersect(const VContainer *data, Draw::Draws mode, QWidget *parent) : - DialogTool(data, mode, parent), ui(new Ui::DialogLineIntersect), number(0), pointName(QString()), - p1Line1(0), p2Line1(0), p1Line2(0), p2Line2(0), flagPoint(true){ +DialogLineIntersect::DialogLineIntersect(const VContainer *data, Draw::Draws mode, QWidget *parent) + :DialogTool(data, mode, parent), ui(new Ui::DialogLineIntersect), number(0), pointName(QString()), + p1Line1(0), p2Line1(0), p1Line2(0), p2Line2(0), flagPoint(true) +{ ui->setupUi(this); number = 0; bOk = ui->buttonBox->button(QDialogButtonBox::Ok); @@ -46,28 +54,39 @@ DialogLineIntersect::~DialogLineIntersect() delete ui; } -void DialogLineIntersect::ChoosedObject(qint64 id, Scene::Scenes type){ - if(idDetail == 0 && mode == Draw::Modeling){ - if(type == Scene::Detail){ +void DialogLineIntersect::ChoosedObject(qint64 id, const Scene::Scenes &type) +{ + if (idDetail == 0 && mode == Draw::Modeling) + { + if (type == Scene::Detail) + { idDetail = id; return; } } - if(mode == Draw::Modeling){ - if(!CheckObject(id)){ + if (mode == Draw::Modeling) + { + if (CheckObject(id) == false) + { return; } } - if(type == Scene::Point){ + if (type == Scene::Point) + { VPointF point; - if(mode == Draw::Calculation){ + if (mode == Draw::Calculation) + { point = data->GetPoint(id); - } else { + } + else + { point = data->GetModelingPoint(id); } - if(number == 0){ + if (number == 0) + { qint32 index = ui->comboBoxP1Line1->findText(point.name()); - if ( index != -1 ) { // -1 for not found + if ( index != -1 ) + { // -1 for not found ui->comboBoxP1Line1->setCurrentIndex(index); p1Line1 = id; number++; @@ -75,9 +94,11 @@ void DialogLineIntersect::ChoosedObject(qint64 id, Scene::Scenes type){ return; } } - if(number == 1){ + if (number == 1) + { qint32 index = ui->comboBoxP2Line1->findText(point.name()); - if ( index != -1 ) { // -1 for not found + if ( index != -1 ) + { // -1 for not found ui->comboBoxP2Line1->setCurrentIndex(index); p2Line1 = id; number++; @@ -85,9 +106,11 @@ void DialogLineIntersect::ChoosedObject(qint64 id, Scene::Scenes type){ return; } } - if(number == 2){ + if (number == 2) + { qint32 index = ui->comboBoxP1Line2->findText(point.name()); - if ( index != -1 ) { // -1 for not found + if ( index != -1 ) + { // -1 for not found ui->comboBoxP1Line2->setCurrentIndex(index); p1Line2 = id; number++; @@ -95,15 +118,18 @@ void DialogLineIntersect::ChoosedObject(qint64 id, Scene::Scenes type){ return; } } - if(number == 3){ + if (number == 3) + { qint32 index = ui->comboBoxP2Line2->findText(point.name()); - if ( index != -1 ) { // -1 for not found + if ( index != -1 ) + { // -1 for not found ui->comboBoxP2Line2->setCurrentIndex(index); p2Line2 = id; number = 0; emit ToolTip(""); } - if(!isInitialized){ + if (isInitialized == false) + { flagPoint = CheckIntersecion(); CheckState(); this->show(); @@ -124,7 +150,8 @@ void DialogLineIntersect::ChoosedObject(qint64 id, Scene::Scenes type){ } } -void DialogLineIntersect::DialogAccepted(){ +void DialogLineIntersect::DialogAccepted() +{ pointName = ui->lineEditNamePoint->text(); p1Line1 = getCurrentPointId(ui->comboBoxP1Line1); p2Line1 = getCurrentPointId(ui->comboBoxP2Line1); @@ -133,36 +160,42 @@ void DialogLineIntersect::DialogAccepted(){ emit DialogClosed(QDialog::Accepted); } -void DialogLineIntersect::P1Line1Changed( int index){ +void DialogLineIntersect::P1Line1Changed( int index) +{ p1Line1 = qvariant_cast(ui->comboBoxP1Line1->itemData(index)); flagPoint = CheckIntersecion(); CheckState(); } -void DialogLineIntersect::P2Line1Changed(int index){ +void DialogLineIntersect::P2Line1Changed(int index) +{ p2Line1 = qvariant_cast(ui->comboBoxP2Line1->itemData(index)); flagPoint = CheckIntersecion(); CheckState(); } -void DialogLineIntersect::P1Line2Changed(int index){ +void DialogLineIntersect::P1Line2Changed(int index) +{ p1Line2 = qvariant_cast(ui->comboBoxP1Line2->itemData(index)); flagPoint = CheckIntersecion(); CheckState(); } -void DialogLineIntersect::P2Line2Changed(int index){ +void DialogLineIntersect::P2Line2Changed(int index) +{ p2Line2 = qvariant_cast(ui->comboBoxP2Line2->itemData(index)); flagPoint = CheckIntersecion(); CheckState(); } -void DialogLineIntersect::CheckState(){ - Q_CHECK_PTR(bOk); +void DialogLineIntersect::CheckState() +{ + Q_ASSERT(bOk != 0); bOk->setEnabled(flagName && flagPoint); } -bool DialogLineIntersect::CheckIntersecion(){ +bool DialogLineIntersect::CheckIntersecion() +{ VPointF p1L1 = data->GetPoint(p1Line1); VPointF p2L1 = data->GetPoint(p2Line1); VPointF p1L2 = data->GetPoint(p1Line2); @@ -172,54 +205,42 @@ bool DialogLineIntersect::CheckIntersecion(){ QLineF line2(p1L2.toQPointF(), p2L2.toQPointF()); QPointF fPoint; QLineF::IntersectType intersect = line1.intersect(line2, &fPoint); - if(intersect == QLineF::UnboundedIntersection || intersect == QLineF::BoundedIntersection){ + if (intersect == QLineF::UnboundedIntersection || intersect == QLineF::BoundedIntersection) + { return true; - } else { + } + else + { return false; } } -qint64 DialogLineIntersect::getP2Line2() const{ - return p2Line2; -} - -void DialogLineIntersect::setP2Line2(const qint64 &value){ +void DialogLineIntersect::setP2Line2(const qint64 &value) +{ p2Line2 = value; ChangeCurrentData(ui->comboBoxP2Line2, value); } -qint64 DialogLineIntersect::getP1Line2() const{ - return p1Line2; -} - -void DialogLineIntersect::setP1Line2(const qint64 &value){ +void DialogLineIntersect::setP1Line2(const qint64 &value) +{ p1Line2 = value; ChangeCurrentData(ui->comboBoxP1Line2, value); } -qint64 DialogLineIntersect::getP2Line1() const{ - return p2Line1; -} - -void DialogLineIntersect::setP2Line1(const qint64 &value){ +void DialogLineIntersect::setP2Line1(const qint64 &value) +{ p2Line1 = value; ChangeCurrentData(ui->comboBoxP2Line1, value); } -qint64 DialogLineIntersect::getP1Line1() const{ - return p1Line1; -} - -void DialogLineIntersect::setP1Line1(const qint64 &value){ +void DialogLineIntersect::setP1Line1(const qint64 &value) +{ p1Line1 = value; ChangeCurrentData(ui->comboBoxP1Line1, value); } -QString DialogLineIntersect::getPointName() const{ - return pointName; -} - -void DialogLineIntersect::setPointName(const QString &value){ +void DialogLineIntersect::setPointName(const QString &value) +{ pointName = value; ui->lineEditNamePoint->setText(pointName); } diff --git a/dialogs/dialoglineintersect.h b/dialogs/dialoglineintersect.h index 4f2f586b8..ff3183c3c 100644 --- a/dialogs/dialoglineintersect.h +++ b/dialogs/dialoglineintersect.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file dialoglineintersect.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,36 +24,37 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef DIALOGLINEINTERSECT_H #define DIALOGLINEINTERSECT_H #include "dialogtool.h" -namespace Ui { -class DialogLineIntersect; +namespace Ui +{ + class DialogLineIntersect; } class DialogLineIntersect : public DialogTool { Q_OBJECT public: - explicit DialogLineIntersect(const VContainer *data, Draw::Draws mode = Draw::Calculation, + DialogLineIntersect(const VContainer *data, Draw::Draws mode = Draw::Calculation, QWidget *parent = 0); ~DialogLineIntersect(); - qint64 getP1Line1() const; + inline qint64 getP1Line1() const {return p1Line1;} void setP1Line1(const qint64 &value); - qint64 getP2Line1() const; + inline qint64 getP2Line1() const {return p2Line1;} void setP2Line1(const qint64 &value); - qint64 getP1Line2() const; + inline qint64 getP1Line2() const {return p1Line2;} void setP1Line2(const qint64 &value); - qint64 getP2Line2() const; + inline qint64 getP2Line2() const {return p2Line2;} void setP2Line2(const qint64 &value); - QString getPointName() const; + inline QString getPointName() const {return pointName;} void setPointName(const QString &value); public slots: - virtual void ChoosedObject(qint64 id, Scene::Scenes type); + virtual void ChoosedObject(qint64 id, const Scene::Scenes &type); virtual void DialogAccepted(); void P1Line1Changed( int index); void P2Line1Changed( int index); diff --git a/dialogs/dialognormal.cpp b/dialogs/dialognormal.cpp index 11cb6805d..4cf6e1d21 100644 --- a/dialogs/dialognormal.cpp +++ b/dialogs/dialognormal.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file dialognormal.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,15 +24,15 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "dialognormal.h" #include "ui_dialognormal.h" -#include -DialogNormal::DialogNormal(const VContainer *data, Draw::Draws mode, QWidget *parent) : - DialogTool(data, mode, parent), ui(new Ui::DialogNormal), number(0), pointName(QString()), - typeLine(QString()), formula(QString()), angle(0), firstPointId(0), secondPointId(0){ +DialogNormal::DialogNormal(const VContainer *data, Draw::Draws mode, QWidget *parent) + :DialogTool(data, mode, parent), ui(new Ui::DialogNormal), number(0), pointName(QString()), + typeLine(QString()), formula(QString()), angle(0), firstPointId(0), secondPointId(0) +{ ui->setupUi(this); spinBoxAngle = ui->doubleSpinBoxAngle; listWidget = ui->listWidget; @@ -35,6 +42,8 @@ DialogNormal::DialogNormal(const VContainer *data, Draw::Draws mode, QWidget *pa radioButtonStandartTable = ui->radioButtonStandartTable; radioButtonIncrements = ui->radioButtonIncrements; radioButtonLengthLine = ui->radioButtonLengthLine; + radioButtonLengthArc = ui->radioButtonLengthArc; + radioButtonLengthCurve = ui->radioButtonLengthSpline; lineEditFormula = ui->lineEditFormula; labelEditFormula = ui->labelEditFormula; labelEditNamePoint = ui->labelEditNamePoint; @@ -74,6 +83,8 @@ DialogNormal::DialogNormal(const VContainer *data, Draw::Draws mode, QWidget *pa connect(ui->radioButtonStandartTable, &QRadioButton::clicked, this, &DialogNormal::StandartTable); connect(ui->radioButtonIncrements, &QRadioButton::clicked, this, &DialogNormal::Increments); connect(ui->radioButtonLengthLine, &QRadioButton::clicked, this, &DialogNormal::LengthLines); + connect(ui->radioButtonLengthArc, &QRadioButton::clicked, this, &DialogNormal::LengthArcs); + connect(ui->radioButtonLengthSpline, &QRadioButton::clicked, this, &DialogNormal::LengthCurves); connect(ui->toolButtonEqual, &QPushButton::clicked, this, &DialogNormal::EvalFormula); connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogNormal::NamePointChanged); connect(ui->lineEditFormula, &QLineEdit::textChanged, this, &DialogNormal::FormulaChanged); @@ -84,49 +95,64 @@ DialogNormal::~DialogNormal() delete ui; } -void DialogNormal::ChoosedObject(qint64 id, Scene::Scenes type){ - if(idDetail == 0 && mode == Draw::Modeling){ - if(type == Scene::Detail){ +void DialogNormal::ChoosedObject(qint64 id, const Scene::Scenes &type) +{ + if (idDetail == 0 && mode == Draw::Modeling) + { + if (type == Scene::Detail) + { idDetail = id; return; } } - if(mode == Draw::Modeling){ - if(!CheckObject(id)){ + if (mode == Draw::Modeling) + { + if (CheckObject(id) == false) + { return; } } - if(type == Scene::Point){ + if (type == Scene::Point) + { VPointF point; - if(mode == Draw::Calculation){ + if (mode == Draw::Calculation) + { point = data->GetPoint(id); - } else { + } + else + { point = data->GetModelingPoint(id); } - if(number == 0){ + if (number == 0) + { qint32 index = ui->comboBoxFirstPoint->findText(point.name()); - if ( index != -1 ) { // -1 for not found + if ( index != -1 ) + { // -1 for not found ui->comboBoxFirstPoint->setCurrentIndex(index); number++; emit ToolTip(tr("Select second point of line")); return; } } - if(number == 1){ + if (number == 1) + { qint32 index = ui->comboBoxSecondPoint->findText(point.name()); - if ( index != -1 ) { // -1 for not found + if ( index != -1 ) + { // -1 for not found ui->comboBoxSecondPoint->setCurrentIndex(index); number = 0; emit ToolTip(""); } - if(!isInitialized){ + if (isInitialized == false) + { this->show(); } } } } -void DialogNormal::DialogAccepted(){ +void DialogNormal::DialogAccepted() +{ pointName = ui->lineEditNamePoint->text(); typeLine = GetTypeLine(ui->comboBoxLineType); formula = ui->lineEditFormula->text(); @@ -136,54 +162,36 @@ void DialogNormal::DialogAccepted(){ emit DialogClosed(QDialog::Accepted); } -qint64 DialogNormal::getSecondPointId() const{ - return secondPointId; -} - -void DialogNormal::setSecondPointId(const qint64 &value, const qint64 &id){ +void DialogNormal::setSecondPointId(const qint64 &value, const qint64 &id) +{ setCurrentPointId(ui->comboBoxSecondPoint, secondPointId, value, id); } -qint64 DialogNormal::getFirstPointId() const{ - return firstPointId; -} - -void DialogNormal::setFirstPointId(const qint64 &value, const qint64 &id){ +void DialogNormal::setFirstPointId(const qint64 &value, const qint64 &id) +{ setCurrentPointId(ui->comboBoxFirstPoint, firstPointId, value, id); } -qreal DialogNormal::getAngle() const{ - return angle; -} - -void DialogNormal::setAngle(const qreal &value){ +void DialogNormal::setAngle(const qreal &value) +{ angle = value; ui->doubleSpinBoxAngle->setValue(angle); } -QString DialogNormal::getFormula() const{ - return formula; -} - -void DialogNormal::setFormula(const QString &value){ +void DialogNormal::setFormula(const QString &value) +{ formula = value; ui->lineEditFormula->setText(formula); } -QString DialogNormal::getTypeLine() const{ - return typeLine; -} - -void DialogNormal::setTypeLine(const QString &value){ +void DialogNormal::setTypeLine(const QString &value) +{ typeLine = value; SetupTypeLine(ui->comboBoxLineType, value); } -QString DialogNormal::getPointName() const{ - return pointName; -} - -void DialogNormal::setPointName(const QString &value){ +void DialogNormal::setPointName(const QString &value) +{ pointName = value; ui->lineEditNamePoint->setText(pointName); } diff --git a/dialogs/dialognormal.h b/dialogs/dialognormal.h index 5586ae825..b2a7329f5 100644 --- a/dialogs/dialognormal.h +++ b/dialogs/dialognormal.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file dialognormal.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,40 +24,38 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef DIALOGNORMAL_H #define DIALOGNORMAL_H #include "dialogtool.h" -#include -#include "container/calculator.h" -namespace Ui { -class DialogNormal; +namespace Ui +{ + class DialogNormal; } class DialogNormal : public DialogTool { Q_OBJECT public: - explicit DialogNormal(const VContainer *data, Draw::Draws mode = Draw::Calculation, - QWidget *parent = 0); + DialogNormal(const VContainer *data, Draw::Draws mode = Draw::Calculation, QWidget *parent = 0); ~DialogNormal(); - QString getPointName() const; + inline QString getPointName() const{return pointName;} void setPointName(const QString &value); - QString getTypeLine() const; + inline QString getTypeLine() const {return typeLine;} void setTypeLine(const QString &value); - QString getFormula() const; + inline QString getFormula() const {return formula;} void setFormula(const QString &value); - qreal getAngle() const; + inline qreal getAngle() const {return angle;} void setAngle(const qreal &value); - qint64 getFirstPointId() const; + inline qint64 getFirstPointId() const {return firstPointId;} void setFirstPointId(const qint64 &value, const qint64 &id); - qint64 getSecondPointId() const; + inline qint64 getSecondPointId() const {return secondPointId;} void setSecondPointId(const qint64 &value, const qint64 &id); public slots: - virtual void ChoosedObject(qint64 id, Scene::Scenes type); + virtual void ChoosedObject(qint64 id, const Scene::Scenes &type); virtual void DialogAccepted(); private: Q_DISABLE_COPY(DialogNormal) diff --git a/dialogs/dialognormal.ui b/dialogs/dialognormal.ui index 26d182650..2283dbe55 100644 --- a/dialogs/dialognormal.ui +++ b/dialogs/dialognormal.ui @@ -519,7 +519,7 @@ - false + true Length of arcs @@ -529,7 +529,7 @@ - false + true Length of curves diff --git a/dialogs/dialogpointofcontact.cpp b/dialogs/dialogpointofcontact.cpp index 67148bb50..115379648 100644 --- a/dialogs/dialogpointofcontact.cpp +++ b/dialogs/dialogpointofcontact.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file dialogpointofcontact.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,13 +24,14 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "dialogpointofcontact.h" -DialogPointOfContact::DialogPointOfContact(const VContainer *data, Draw::Draws mode, QWidget *parent) : - DialogTool(data, mode, parent), ui(), number(0), pointName(QString()), radius(QString()), center(0), - firstPoint(0), secondPoint(0){ +DialogPointOfContact::DialogPointOfContact(const VContainer *data, Draw::Draws mode, QWidget *parent) + :DialogTool(data, mode, parent), ui(), number(0), pointName(QString()), radius(QString()), center(0), + firstPoint(0), secondPoint(0) +{ ui.setupUi(this); listWidget = ui.listWidget; labelResultCalculation = ui.labelResultCalculation; @@ -32,6 +40,8 @@ DialogPointOfContact::DialogPointOfContact(const VContainer *data, Draw::Draws m radioButtonStandartTable = ui.radioButtonStandartTable; radioButtonIncrements = ui.radioButtonIncrements; radioButtonLengthLine = ui.radioButtonLengthLine; + radioButtonLengthArc = ui.radioButtonLengthArc; + radioButtonLengthCurve = ui.radioButtonLengthSpline; lineEditFormula = ui.lineEditFormula; labelEditFormula = ui.labelEditFormula; labelEditNamePoint = ui.labelEditNamePoint; @@ -55,64 +65,82 @@ DialogPointOfContact::DialogPointOfContact(const VContainer *data, Draw::Draws m connect(ui.radioButtonStandartTable, &QRadioButton::clicked, this, &DialogPointOfContact::StandartTable); connect(ui.radioButtonIncrements, &QRadioButton::clicked, this, &DialogPointOfContact::Increments); connect(ui.radioButtonLengthLine, &QRadioButton::clicked, this, &DialogPointOfContact::LengthLines); + connect(ui.radioButtonLengthArc, &QRadioButton::clicked, this, &DialogPointOfContact::LengthArcs); + connect(ui.radioButtonLengthSpline, &QRadioButton::clicked, this, &DialogPointOfContact::LengthCurves); connect(ui.toolButtonEqual, &QPushButton::clicked, this, &DialogPointOfContact::EvalFormula); connect(ui.lineEditNamePoint, &QLineEdit::textChanged, this, &DialogPointOfContact::NamePointChanged); connect(ui.lineEditFormula, &QLineEdit::textChanged, this, &DialogPointOfContact::FormulaChanged); } -void DialogPointOfContact::ChoosedObject(qint64 id, Scene::Scenes type){ - if(idDetail == 0 && mode == Draw::Modeling){ - if(type == Scene::Detail){ +void DialogPointOfContact::ChoosedObject(qint64 id, const Scene::Scenes &type) +{ + if (idDetail == 0 && mode == Draw::Modeling) + { + if (type == Scene::Detail) + { idDetail = id; return; } } - if(mode == Draw::Modeling){ - if(!CheckObject(id)){ + if (mode == Draw::Modeling) + { + if (CheckObject(id) == false) + { return; } } - if(type == Scene::Point){ + if (type == Scene::Point) + { VPointF point; - if(mode == Draw::Calculation){ + if (mode == Draw::Calculation) + { point = data->GetPoint(id); - } else { + } + else + { point = data->GetModelingPoint(id); } - if(number == 0){ + if (number == 0) + { qint32 index = ui.comboBoxFirstPoint->findText(point.name()); - if ( index != -1 ) { // -1 for not found + if ( index != -1 ) + { // -1 for not found ui.comboBoxFirstPoint->setCurrentIndex(index); number++; emit ToolTip(tr("Select second point of line")); return; } } - if(number == 1){ + if (number == 1) + { qint32 index = ui.comboBoxSecondPoint->findText(point.name()); - if ( index != -1 ) { // -1 for not found + if ( index != -1 ) + { // -1 for not found ui.comboBoxSecondPoint->setCurrentIndex(index); number++; emit ToolTip(tr("Select point of center of arc")); return; } } - if(number == 2){ + if (number == 2) + { qint32 index = ui.comboBoxCenter->findText(point.name()); - if ( index != -1 ) { // -1 for not found + if ( index != -1 ) + { // -1 for not found ui.comboBoxCenter->setCurrentIndex(index); number = 0; emit ToolTip(""); } - if(!isInitialized){ + if (isInitialized == false) + { this->show(); } } } } - -void DialogPointOfContact::DialogAccepted(){ +void DialogPointOfContact::DialogAccepted() +{ pointName = ui.lineEditNamePoint->text(); radius = ui.lineEditFormula->text(); center = getCurrentPointId(ui.comboBoxCenter); @@ -121,45 +149,30 @@ void DialogPointOfContact::DialogAccepted(){ emit DialogClosed(QDialog::Accepted); } -qint64 DialogPointOfContact::getSecondPoint() const{ - return secondPoint; -} - -void DialogPointOfContact::setSecondPoint(const qint64 &value, const qint64 &id){ +void DialogPointOfContact::setSecondPoint(const qint64 &value, const qint64 &id) +{ setCurrentPointId(ui.comboBoxSecondPoint, secondPoint, value, id); } -qint64 DialogPointOfContact::getFirstPoint() const{ - return firstPoint; -} - -void DialogPointOfContact::setFirstPoint(const qint64 &value, const qint64 &id){ +void DialogPointOfContact::setFirstPoint(const qint64 &value, const qint64 &id) +{ setCurrentPointId(ui.comboBoxFirstPoint, firstPoint, value, id); } -qint64 DialogPointOfContact::getCenter() const{ - return center; -} - -void DialogPointOfContact::setCenter(const qint64 &value, const qint64 &id){ +void DialogPointOfContact::setCenter(const qint64 &value, const qint64 &id) +{ setCurrentPointId(ui.comboBoxCenter, center, value, id); center = value; } -QString DialogPointOfContact::getRadius() const{ - return radius; -} - -void DialogPointOfContact::setRadius(const QString &value){ +void DialogPointOfContact::setRadius(const QString &value) +{ radius = value; ui.lineEditFormula->setText(radius); } -QString DialogPointOfContact::getPointName() const{ - return pointName; -} - -void DialogPointOfContact::setPointName(const QString &value){ +void DialogPointOfContact::setPointName(const QString &value) +{ pointName = value; ui.lineEditNamePoint->setText(pointName); } diff --git a/dialogs/dialogpointofcontact.h b/dialogs/dialogpointofcontact.h index 7d85ddcb3..416e5adcf 100644 --- a/dialogs/dialogpointofcontact.h +++ b/dialogs/dialogpointofcontact.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file dialogpointofcontact.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,49 +24,42 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef DIALOGPOINTOFCONTACT_H #define DIALOGPOINTOFCONTACT_H #include "ui_dialogpointofcontact.h" #include "dialogtool.h" -#include "container/calculator.h" class DialogPointOfContact : public DialogTool { Q_OBJECT - public: - explicit DialogPointOfContact(const VContainer *data, Draw::Draws mode = Draw::Calculation, - QWidget *parent = 0); - QString getPointName() const; - void setPointName(const QString &value); - - QString getRadius() const; - void setRadius(const QString &value); - - qint64 getCenter() const; - void setCenter(const qint64 &value, const qint64 &id); - - qint64 getFirstPoint() const; - void setFirstPoint(const qint64 &value, const qint64 &id); - - qint64 getSecondPoint() const; - void setSecondPoint(const qint64 &value, const qint64 &id); - + DialogPointOfContact(const VContainer *data, Draw::Draws mode = Draw::Calculation, + QWidget *parent = 0); + inline QString getPointName() const {return pointName;} + void setPointName(const QString &value); + inline QString getRadius() const {return radius;} + void setRadius(const QString &value); + inline qint64 getCenter() const {return center;} + void setCenter(const qint64 &value, const qint64 &id); + inline qint64 getFirstPoint() const {return firstPoint;} + void setFirstPoint(const qint64 &value, const qint64 &id); + inline qint64 getSecondPoint() const {return secondPoint;} + void setSecondPoint(const qint64 &value, const qint64 &id); public slots: - virtual void ChoosedObject(qint64 id, Scene::Scenes type); - virtual void DialogAccepted(); + virtual void ChoosedObject(qint64 id, const Scene::Scenes &type); + virtual void DialogAccepted(); private: Q_DISABLE_COPY(DialogPointOfContact) Ui::DialogPointOfContact ui; - qint32 number; - QString pointName; - QString radius; - qint64 center; - qint64 firstPoint; - qint64 secondPoint; + qint32 number; + QString pointName; + QString radius; + qint64 center; + qint64 firstPoint; + qint64 secondPoint; }; #endif // DIALOGPOINTOFCONTACT_H diff --git a/dialogs/dialogpointofcontact.ui b/dialogs/dialogpointofcontact.ui index 4e28260b2..e4f1fba75 100644 --- a/dialogs/dialogpointofcontact.ui +++ b/dialogs/dialogpointofcontact.ui @@ -359,7 +359,7 @@ - false + true Length of arcs @@ -369,7 +369,7 @@ - false + true Length of curves diff --git a/dialogs/dialogpointofintersection.cpp b/dialogs/dialogpointofintersection.cpp new file mode 100644 index 000000000..abcd9a7da --- /dev/null +++ b/dialogs/dialogpointofintersection.cpp @@ -0,0 +1,134 @@ +/************************************************************************ + ** + ** @file dialogpointofintersection.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "dialogpointofintersection.h" +#include "ui_dialogpointofintersection.h" + +DialogPointOfIntersection::DialogPointOfIntersection(const VContainer *data, Draw::Draws mode, QWidget *parent) + :DialogTool(data, mode, parent), ui(new Ui::DialogPointOfIntersection), number(0), pointName(QString()), + firstPointId(0), secondPointId(0) +{ + ui->setupUi(this); + labelEditNamePoint = ui->labelEditNamePoint; + bOk = ui->buttonBox->button(QDialogButtonBox::Ok); + connect(bOk, &QPushButton::clicked, this, &DialogPointOfIntersection::DialogAccepted); + flagName = false; + CheckState(); + QPushButton *bCansel = ui->buttonBox->button(QDialogButtonBox::Cancel); + connect(bCansel, &QPushButton::clicked, this, &DialogPointOfIntersection::DialogRejected); + FillComboBoxPoints(ui->comboBoxFirstPoint); + FillComboBoxPoints(ui->comboBoxSecondPoint); + connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogPointOfIntersection::NamePointChanged); +} + +DialogPointOfIntersection::~DialogPointOfIntersection() +{ + delete ui; +} + +void DialogPointOfIntersection::setSecondPointId(const qint64 &value, const qint64 &id) +{ + secondPointId = value; + setCurrentPointId(ui->comboBoxSecondPoint, secondPointId, value, id); +} + +void DialogPointOfIntersection::ChoosedObject(qint64 id, const Scene::Scenes &type) +{ + if (idDetail == 0 && mode == Draw::Modeling) + { + if (type == Scene::Detail) + { + idDetail = id; + return; + } + } + if (mode == Draw::Modeling) + { + if (CheckObject(id) == false) + { + return; + } + } + if (type == Scene::Point) + { + VPointF point; + if (mode == Draw::Calculation) + { + point = data->GetPoint(id); + } + else + { + point = data->GetModelingPoint(id); + } + if (number == 0) + { + qint32 index = ui->comboBoxFirstPoint->findText(point.name()); + if ( index != -1 ) + { // -1 for not found + ui->comboBoxFirstPoint->setCurrentIndex(index); + number++; + emit ToolTip(tr("Select point horizontally")); + return; + } + } + if (number == 1) + { + qint32 index = ui->comboBoxSecondPoint->findText(point.name()); + if ( index != -1 ) + { // -1 for not found + ui->comboBoxSecondPoint->setCurrentIndex(index); + number = 0; + emit ToolTip(""); + } + if (isInitialized == false) + { + this->show(); + } + } + } +} + +void DialogPointOfIntersection::DialogAccepted() +{ + pointName = ui->lineEditNamePoint->text(); + firstPointId = getCurrentPointId(ui->comboBoxFirstPoint); + secondPointId = getCurrentPointId(ui->comboBoxSecondPoint); + emit DialogClosed(QDialog::Accepted); +} + +void DialogPointOfIntersection::setFirstPointId(const qint64 &value, const qint64 &id) +{ + firstPointId = value; + setCurrentPointId(ui->comboBoxFirstPoint, firstPointId, value, id); +} + +void DialogPointOfIntersection::setPointName(const QString &value) +{ + pointName = value; + ui->lineEditNamePoint->setText(pointName); +} diff --git a/dialogs/dialogpointofintersection.h b/dialogs/dialogpointofintersection.h new file mode 100644 index 000000000..9ea655f58 --- /dev/null +++ b/dialogs/dialogpointofintersection.h @@ -0,0 +1,64 @@ +/************************************************************************ + ** + ** @file dialogpointofintersection.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef DIALOGPOINTOFINTERSECTION_H +#define DIALOGPOINTOFINTERSECTION_H + +#include "dialogtool.h" + +namespace Ui +{ + class DialogPointOfIntersection; +} + +class DialogPointOfIntersection : public DialogTool +{ + Q_OBJECT +public: + DialogPointOfIntersection(const VContainer *data, Draw::Draws mode = Draw::Calculation, + QWidget *parent = 0); + ~DialogPointOfIntersection(); + inline QString getPointName() const {return pointName;} + void setPointName(const QString &value); + inline qint64 getFirstPointId() const {return firstPointId;} + void setFirstPointId(const qint64 &value, const qint64 &id); + inline qint64 getSecondPointId() const {return secondPointId;} + void setSecondPointId(const qint64 &value, const qint64 &id); +public slots: + virtual void ChoosedObject(qint64 id, const Scene::Scenes &type); + virtual void DialogAccepted(); +private: + Q_DISABLE_COPY(DialogPointOfIntersection) + Ui::DialogPointOfIntersection *ui; + qint32 number; + QString pointName; + qint64 firstPointId; + qint64 secondPointId; +}; + +#endif // DIALOGPOINTOFINTERSECTION_H diff --git a/dialogs/dialogpointofintersection.ui b/dialogs/dialogpointofintersection.ui new file mode 100644 index 000000000..303aa8cc0 --- /dev/null +++ b/dialogs/dialogpointofintersection.ui @@ -0,0 +1,169 @@ + + + DialogPointOfIntersection + + + + 0 + 0 + 293 + 180 + + + + Dialog + + + + + + + + + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 159 + 158 + 158 + + + + + + + + Name new point + + + + + + + + + + + + + + + 0 + 0 + + + + Point vertically + + + + + + + First point of angle + + + + + + + + + + + + 0 + 0 + + + + Point horizontally + + + + + + + Second point of angle + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + DialogPointOfIntersection + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + DialogPointOfIntersection + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/dialogs/dialogs.h b/dialogs/dialogs.h index 78716df81..c205f2522 100644 --- a/dialogs/dialogs.h +++ b/dialogs/dialogs.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file dialogs.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,7 +24,7 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef DIALOGS_H #define DIALOGS_H @@ -37,5 +44,6 @@ #include "dialogsinglepoint.h" #include "dialogspline.h" #include "dialogsplinepath.h" +#include "dialogheight.h" #endif // DIALOGS_H diff --git a/dialogs/dialogs.pri b/dialogs/dialogs.pri new file mode 100644 index 000000000..86876c1d2 --- /dev/null +++ b/dialogs/dialogs.pri @@ -0,0 +1,62 @@ +HEADERS += \ + dialogs/dialogtriangle.h \ + dialogs/dialogtool.h \ + dialogs/dialogsplinepath.h \ + dialogs/dialogspline.h \ + dialogs/dialogsinglepoint.h \ + dialogs/dialogshoulderpoint.h \ + dialogs/dialogs.h \ + dialogs/dialogpointofintersection.h \ + dialogs/dialogpointofcontact.h \ + dialogs/dialognormal.h \ + dialogs/dialoglineintersect.h \ + dialogs/dialogline.h \ + dialogs/dialogincrements.h \ + dialogs/dialoghistory.h \ + dialogs/dialogheight.h \ + dialogs/dialogendline.h \ + dialogs/dialogdetail.h \ + dialogs/dialogbisector.h \ + dialogs/dialogarc.h \ + dialogs/dialogalongline.h + +SOURCES += \ + dialogs/dialogtriangle.cpp \ + dialogs/dialogtool.cpp \ + dialogs/dialogsplinepath.cpp \ + dialogs/dialogspline.cpp \ + dialogs/dialogsinglepoint.cpp \ + dialogs/dialogshoulderpoint.cpp \ + dialogs/dialogpointofintersection.cpp \ + dialogs/dialogpointofcontact.cpp \ + dialogs/dialognormal.cpp \ + dialogs/dialoglineintersect.cpp \ + dialogs/dialogline.cpp \ + dialogs/dialogincrements.cpp \ + dialogs/dialoghistory.cpp \ + dialogs/dialogheight.cpp \ + dialogs/dialogendline.cpp \ + dialogs/dialogdetail.cpp \ + dialogs/dialogbisector.cpp \ + dialogs/dialogarc.cpp \ + dialogs/dialogalongline.cpp + +FORMS += \ + dialogs/dialogtriangle.ui \ + dialogs/dialogsplinepath.ui \ + dialogs/dialogspline.ui \ + dialogs/dialogsinglepoint.ui \ + dialogs/dialogshoulderpoint.ui \ + dialogs/dialogpointofintersection.ui \ + dialogs/dialogpointofcontact.ui \ + dialogs/dialognormal.ui \ + dialogs/dialoglineintersect.ui \ + dialogs/dialogline.ui \ + dialogs/dialogincrements.ui \ + dialogs/dialoghistory.ui \ + dialogs/dialogheight.ui \ + dialogs/dialogendline.ui \ + dialogs/dialogdetail.ui \ + dialogs/dialogbisector.ui \ + dialogs/dialogarc.ui \ + dialogs/dialogalongline.ui diff --git a/dialogs/dialogshoulderpoint.cpp b/dialogs/dialogshoulderpoint.cpp index 28201e968..92afa2a92 100644 --- a/dialogs/dialogshoulderpoint.cpp +++ b/dialogs/dialogshoulderpoint.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file dialogshoulderpoint.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,14 +24,15 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "dialogshoulderpoint.h" #include "ui_dialogshoulderpoint.h" -DialogShoulderPoint::DialogShoulderPoint(const VContainer *data, Draw::Draws mode, QWidget *parent) : - DialogTool(data, mode, parent), ui(new Ui::DialogShoulderPoint), number(0), pointName(QString()), - typeLine(QString()), formula(QString()), p1Line(0), p2Line(0), pShoulder(0){ +DialogShoulderPoint::DialogShoulderPoint(const VContainer *data, Draw::Draws mode, QWidget *parent) + :DialogTool(data, mode, parent), ui(new Ui::DialogShoulderPoint), number(0), pointName(QString()), + typeLine(QString()), formula(QString()), p1Line(0), p2Line(0), pShoulder(0) +{ ui->setupUi(this); number = 0; listWidget = ui->listWidget; @@ -34,6 +42,8 @@ DialogShoulderPoint::DialogShoulderPoint(const VContainer *data, Draw::Draws mod radioButtonStandartTable = ui->radioButtonStandartTable; radioButtonIncrements = ui->radioButtonIncrements; radioButtonLengthLine = ui->radioButtonLengthLine; + radioButtonLengthArc = ui->radioButtonLengthArc; + radioButtonLengthCurve = ui->radioButtonLengthSpline; lineEditFormula = ui->lineEditFormula; labelEditFormula = ui->labelEditFormula; labelEditNamePoint = ui->labelEditNamePoint; @@ -58,6 +68,8 @@ DialogShoulderPoint::DialogShoulderPoint(const VContainer *data, Draw::Draws mod connect(ui->radioButtonStandartTable, &QRadioButton::clicked, this, &DialogShoulderPoint::StandartTable); connect(ui->radioButtonIncrements, &QRadioButton::clicked, this, &DialogShoulderPoint::Increments); connect(ui->radioButtonLengthLine, &QRadioButton::clicked, this, &DialogShoulderPoint::LengthLines); + connect(ui->radioButtonLengthArc, &QRadioButton::clicked, this, &DialogShoulderPoint::LengthArcs); + connect(ui->radioButtonLengthSpline, &QRadioButton::clicked, this, &DialogShoulderPoint::LengthCurves); connect(ui->toolButtonEqual, &QPushButton::clicked, this, &DialogShoulderPoint::EvalFormula); connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogShoulderPoint::NamePointChanged); connect(ui->lineEditFormula, &QLineEdit::textChanged, this, &DialogShoulderPoint::FormulaChanged); @@ -68,58 +80,75 @@ DialogShoulderPoint::~DialogShoulderPoint() delete ui; } -void DialogShoulderPoint::ChoosedObject(qint64 id, Scene::Scenes type){ - if(idDetail == 0 && mode == Draw::Modeling){ - if(type == Scene::Detail){ +void DialogShoulderPoint::ChoosedObject(qint64 id, const Scene::Scenes &type) +{ + if (idDetail == 0 && mode == Draw::Modeling) + { + if (type == Scene::Detail) + { idDetail = id; return; } } - if(mode == Draw::Modeling){ - if(!CheckObject(id)){ + if (mode == Draw::Modeling) + { + if (CheckObject(id) == false) + { return; } } - if(type == Scene::Point){ + if (type == Scene::Point) + { VPointF point; - if(mode == Draw::Calculation){ + if (mode == Draw::Calculation) + { point = data->GetPoint(id); - } else { + } + else + { point = data->GetModelingPoint(id); } - if(number == 0){ + if (number == 0) + { qint32 index = ui->comboBoxP1Line->findText(point.name()); - if ( index != -1 ) { // -1 for not found + if ( index != -1 ) + { // -1 for not found ui->comboBoxP1Line->setCurrentIndex(index); number++; emit ToolTip(tr("Select second point of line")); return; } } - if(number == 1){ + if (number == 1) + { qint32 index = ui->comboBoxP2Line->findText(point.name()); - if ( index != -1 ) { // -1 for not found + if ( index != -1 ) + { // -1 for not found ui->comboBoxP2Line->setCurrentIndex(index); number++; emit ToolTip(tr("Select point of shoulder")); return; } } - if(number == 2){ + if (number == 2) + { qint32 index = ui->comboBoxPShoulder->findText(point.name()); - if ( index != -1 ) { // -1 for not found + if ( index != -1 ) + { // -1 for not found ui->comboBoxPShoulder->setCurrentIndex(index); number = 0; emit ToolTip(""); } - if(!isInitialized){ + if (isInitialized == false) + { this->show(); } } } } -void DialogShoulderPoint::DialogAccepted(){ +void DialogShoulderPoint::DialogAccepted() +{ pointName = ui->lineEditNamePoint->text(); typeLine = GetTypeLine(ui->comboBoxLineType); formula = ui->lineEditFormula->text(); @@ -129,53 +158,35 @@ void DialogShoulderPoint::DialogAccepted(){ emit DialogClosed(QDialog::Accepted); } -qint64 DialogShoulderPoint::getPShoulder() const{ - return pShoulder; -} - -void DialogShoulderPoint::setPShoulder(const qint64 &value, const qint64 &id){ +void DialogShoulderPoint::setPShoulder(const qint64 &value, const qint64 &id) +{ setCurrentPointId(ui->comboBoxPShoulder, pShoulder, value, id); } -qint64 DialogShoulderPoint::getP2Line() const{ - return p2Line; -} - -void DialogShoulderPoint::setP2Line(const qint64 &value, const qint64 &id){ +void DialogShoulderPoint::setP2Line(const qint64 &value, const qint64 &id) +{ setCurrentPointId(ui->comboBoxP2Line, p2Line, value, id); } -qint64 DialogShoulderPoint::getP1Line() const{ - return p1Line; -} - -void DialogShoulderPoint::setP1Line(const qint64 &value, const qint64 &id){ +void DialogShoulderPoint::setP1Line(const qint64 &value, const qint64 &id) +{ setCurrentPointId(ui->comboBoxP1Line, p1Line, value, id); } -QString DialogShoulderPoint::getFormula() const{ - return formula; -} - -void DialogShoulderPoint::setFormula(const QString &value){ +void DialogShoulderPoint::setFormula(const QString &value) +{ formula = value; ui->lineEditFormula->setText(formula); } -QString DialogShoulderPoint::getTypeLine() const{ - return typeLine; -} - -void DialogShoulderPoint::setTypeLine(const QString &value){ +void DialogShoulderPoint::setTypeLine(const QString &value) +{ typeLine = value; SetupTypeLine(ui->comboBoxLineType, value); } -QString DialogShoulderPoint::getPointName() const{ - return pointName; -} - -void DialogShoulderPoint::setPointName(const QString &value){ +void DialogShoulderPoint::setPointName(const QString &value) +{ pointName = value; ui->lineEditNamePoint->setText(pointName); } diff --git a/dialogs/dialogshoulderpoint.h b/dialogs/dialogshoulderpoint.h index 49df44255..b9c4df8c2 100644 --- a/dialogs/dialogshoulderpoint.h +++ b/dialogs/dialogshoulderpoint.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file dialogshoulderpoint.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,50 +24,50 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef DIALOGSHOULDERPOINT_H #define DIALOGSHOULDERPOINT_H #include "dialogtool.h" -#include "container/calculator.h" -namespace Ui { -class DialogShoulderPoint; +namespace Ui +{ + class DialogShoulderPoint; } class DialogShoulderPoint : public DialogTool { Q_OBJECT public: - explicit DialogShoulderPoint(const VContainer *data, Draw::Draws mode = Draw::Calculation, - QWidget *parent = 0); - ~DialogShoulderPoint(); - QString getPointName() const; - void setPointName(const QString &value); - QString getTypeLine() const; - void setTypeLine(const QString &value); - QString getFormula() const; - void setFormula(const QString &value); - qint64 getP1Line() const; - void setP1Line(const qint64 &value, const qint64 &id); - qint64 getP2Line() const; - void setP2Line(const qint64 &value, const qint64 &id); - qint64 getPShoulder() const; - void setPShoulder(const qint64 &value, const qint64 &id); + DialogShoulderPoint(const VContainer *data, Draw::Draws mode = Draw::Calculation, + QWidget *parent = 0); + ~DialogShoulderPoint(); + inline QString getPointName() const {return pointName;} + void setPointName(const QString &value); + inline QString getTypeLine() const {return typeLine;} + void setTypeLine(const QString &value); + inline QString getFormula() const {return formula;} + void setFormula(const QString &value); + inline qint64 getP1Line() const {return p1Line;} + void setP1Line(const qint64 &value, const qint64 &id); + inline qint64 getP2Line() const {return p2Line;} + void setP2Line(const qint64 &value, const qint64 &id); + inline qint64 getPShoulder() const {return pShoulder;} + void setPShoulder(const qint64 &value, const qint64 &id); public slots: - virtual void ChoosedObject(qint64 id, Scene::Scenes type); - virtual void DialogAccepted(); + virtual void ChoosedObject(qint64 id, const Scene::Scenes &type); + virtual void DialogAccepted(); private: Q_DISABLE_COPY(DialogShoulderPoint) Ui::DialogShoulderPoint *ui; - qint32 number; - QString pointName; - QString typeLine; - QString formula; - qint64 p1Line; - qint64 p2Line; - qint64 pShoulder; + qint32 number; + QString pointName; + QString typeLine; + QString formula; + qint64 p1Line; + qint64 p2Line; + qint64 pShoulder; }; #endif // DIALOGSHOULDERPOINT_H diff --git a/dialogs/dialogshoulderpoint.ui b/dialogs/dialogshoulderpoint.ui index f0b4d9e27..b1865211e 100644 --- a/dialogs/dialogshoulderpoint.ui +++ b/dialogs/dialogshoulderpoint.ui @@ -380,7 +380,7 @@ - false + true Length of lines @@ -390,7 +390,7 @@ - false + true Length of curves diff --git a/dialogs/dialogsinglepoint.cpp b/dialogs/dialogsinglepoint.cpp index 276dd9542..752d0b141 100644 --- a/dialogs/dialogsinglepoint.cpp +++ b/dialogs/dialogsinglepoint.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file dialogsinglepoint.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,21 +24,18 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "dialogsinglepoint.h" #include "ui_dialogsinglepoint.h" -#include -#include -#include -#include "options.h" -DialogSinglePoint::DialogSinglePoint(const VContainer *data, QWidget *parent) : - DialogTool(data, Draw::Calculation, parent), ui(new Ui::DialogSinglePoint), name(QString()), - point(QPointF()){ +DialogSinglePoint::DialogSinglePoint(const VContainer *data, QWidget *parent) + :DialogTool(data, Draw::Calculation, parent), ui(new Ui::DialogSinglePoint), name(QString()), + point(QPointF()) +{ ui->setupUi(this); - ui->doubleSpinBoxX->setRange(0,PaperSize/PrintDPI*25.4); - ui->doubleSpinBoxY->setRange(0,PaperSize/PrintDPI*25.4); + ui->doubleSpinBoxX->setRange(0, toMM(PaperSize)); + ui->doubleSpinBoxY->setRange(0, toMM(PaperSize)); bOk = ui->buttonBox->button(QDialogButtonBox::Ok); labelEditNamePoint = ui->labelEditName; flagName = false; @@ -39,45 +43,42 @@ DialogSinglePoint::DialogSinglePoint(const VContainer *data, QWidget *parent) : connect(bOk, &QPushButton::clicked, this, &DialogSinglePoint::DialogAccepted); QPushButton *bCansel = ui->buttonBox->button(QDialogButtonBox::Cancel); connect(bCansel, &QPushButton::clicked, this, &DialogSinglePoint::DialogRejected); - connect(ui->lineEditName,&QLineEdit::textChanged, this, &DialogSinglePoint::NamePointChanged); + connect(ui->lineEditName, &QLineEdit::textChanged, this, &DialogSinglePoint::NamePointChanged); } -void DialogSinglePoint::mousePress(QPointF scenePos){ - if(isInitialized == false){ - ui->doubleSpinBoxX->setValue(scenePos.x()/PrintDPI*25.4); - ui->doubleSpinBoxY->setValue(scenePos.y()/PrintDPI*25.4); +void DialogSinglePoint::mousePress(const QPointF &scenePos) +{ + if (isInitialized == false) + { + ui->doubleSpinBoxX->setValue(toMM(scenePos.x())); + ui->doubleSpinBoxY->setValue(toMM(scenePos.y())); this->show(); - } else { - ui->doubleSpinBoxX->setValue(scenePos.x()/PrintDPI*25.4); - ui->doubleSpinBoxY->setValue(scenePos.y()/PrintDPI*25.4); + } + else + { + ui->doubleSpinBoxX->setValue(toMM(scenePos.x())); + ui->doubleSpinBoxY->setValue(toMM(scenePos.y())); } } -void DialogSinglePoint::DialogAccepted(){ - point = QPointF(ui->doubleSpinBoxX->value()*PrintDPI/25.4, - ui->doubleSpinBoxY->value()*PrintDPI/25.4); +void DialogSinglePoint::DialogAccepted() +{ + point = QPointF(toPixel(ui->doubleSpinBoxX->value()), toPixel(ui->doubleSpinBoxY->value())); name = ui->lineEditName->text(); emit DialogClosed(QDialog::Accepted); } -void DialogSinglePoint::setData(const QString name, const QPointF point){ +void DialogSinglePoint::setData(const QString &name, const QPointF &point) +{ this->name = name; this->point = point; isInitialized = true; ui->lineEditName->setText(name); - ui->doubleSpinBoxX->setValue(point.x()/PrintDPI*25.4); - ui->doubleSpinBoxY->setValue(point.y()/PrintDPI*25.4); + ui->doubleSpinBoxX->setValue(toMM(point.x())); + ui->doubleSpinBoxY->setValue(toMM(point.y())); } -QString DialogSinglePoint::getName()const{ - return name; -} - -QPointF DialogSinglePoint::getPoint()const{ - return point; -} - -DialogSinglePoint::~DialogSinglePoint(){ +DialogSinglePoint::~DialogSinglePoint() +{ delete ui; } - diff --git a/dialogs/dialogsinglepoint.h b/dialogs/dialogsinglepoint.h index 02c064386..02c456bd4 100644 --- a/dialogs/dialogsinglepoint.h +++ b/dialogs/dialogsinglepoint.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file dialogsinglepoint.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,34 +24,35 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef DIALOGSINGLEPOINT_H #define DIALOGSINGLEPOINT_H #include "dialogtool.h" -namespace Ui { -class DialogSinglePoint; +namespace Ui +{ + class DialogSinglePoint; } class DialogSinglePoint : public DialogTool { - Q_OBJECT + Q_OBJECT public: - explicit DialogSinglePoint(const VContainer *data, QWidget *parent = 0); - void setData(const QString name, const QPointF point); - QString getName()const; - QPointF getPoint()const; - ~DialogSinglePoint(); + DialogSinglePoint(const VContainer *data, QWidget *parent = 0); + void setData(const QString &name, const QPointF &point); + inline QString getName()const {return name;} + inline QPointF getPoint()const {return point;} + ~DialogSinglePoint(); public slots: - void mousePress(QPointF scenePos); - virtual void DialogAccepted(); + void mousePress(const QPointF &scenePos); + virtual void DialogAccepted(); private: Q_DISABLE_COPY(DialogSinglePoint) Ui::DialogSinglePoint *ui; - QString name; - QPointF point; + QString name; + QPointF point; }; #endif // DIALOGSINGLEPOINT_H diff --git a/dialogs/dialogspline.cpp b/dialogs/dialogspline.cpp index c17c3d385..9d478f9ea 100644 --- a/dialogs/dialogspline.cpp +++ b/dialogs/dialogspline.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file dialogspline.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,63 +24,79 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "dialogspline.h" #include "ui_dialogspline.h" -DialogSpline::DialogSpline(const VContainer *data, Draw::Draws mode, QWidget *parent) : - DialogTool(data, mode, parent), ui(new Ui::DialogSpline), number(0), p1(0), p4(0), angle1(0), angle2(0), - kAsm1(1), kAsm2(1), kCurve(1){ +DialogSpline::DialogSpline(const VContainer *data, Draw::Draws mode, QWidget *parent) + :DialogTool(data, mode, parent), ui(new Ui::DialogSpline), number(0), p1(0), p4(0), angle1(0), angle2(0), + kAsm1(1), kAsm2(1), kCurve(1) +{ ui->setupUi(this); bOk = ui->buttonBox->button(QDialogButtonBox::Ok); connect(bOk, &QPushButton::clicked, this, &DialogSpline::DialogAccepted); QPushButton *bCansel = ui->buttonBox->button(QDialogButtonBox::Cancel); connect(bCansel, &QPushButton::clicked, this, &DialogSpline::DialogRejected); - if(mode == Draw::Calculation){ + if (mode == Draw::Calculation) + { FillComboBoxPoints(ui->comboBoxP1); FillComboBoxPoints(ui->comboBoxP4); } } -DialogSpline::~DialogSpline(){ +DialogSpline::~DialogSpline() +{ delete ui; } -void DialogSpline::ChoosedObject(qint64 id, Scene::Scenes type){ - if(idDetail == 0 && mode == Draw::Modeling){ - if(type == Scene::Detail){ +void DialogSpline::ChoosedObject(qint64 id, const Scene::Scenes &type) +{ + if (idDetail == 0 && mode == Draw::Modeling) + { + if (type == Scene::Detail) + { idDetail = id; FillComboBoxPoints(ui->comboBoxP1); FillComboBoxPoints(ui->comboBoxP4); return; } } - if(mode == Draw::Modeling){ - if(!CheckObject(id)){ + if (mode == Draw::Modeling) + { + if (CheckObject(id) == false) + { return; } } - if(type == Scene::Point){ + if (type == Scene::Point) + { VPointF point; - if(mode == Draw::Calculation){ + if (mode == Draw::Calculation) + { point = data->GetPoint(id); - } else { + } + else + { point = data->GetModelingPoint(id); } - if(number == 0){ + if (number == 0) + { qint32 index = ui->comboBoxP1->findText(point.name()); - if ( index != -1 ) { // -1 for not found + if ( index != -1 ) + { // -1 for not found ui->comboBoxP1->setCurrentIndex(index); number++; emit ToolTip(tr("Select last point of curve")); return; } } - if(number == 1){ + if (number == 1) + { qint32 index = ui->comboBoxP4->findText(point.name()); - if ( index != -1 ) { // -1 for not found + if ( index != -1 ) + { // -1 for not found ui->comboBoxP4->setCurrentIndex(index); number = 0; emit ToolTip(""); @@ -81,24 +104,29 @@ void DialogSpline::ChoosedObject(qint64 id, Scene::Scenes type){ qint64 p1Id = qvariant_cast(ui->comboBoxP1->itemData(index)); QPointF p1; QPointF p4; - if(mode == Draw::Calculation){ + if (mode == Draw::Calculation) + { p1 = data->GetPoint(p1Id).toQPointF(); p4 = data->GetPoint(id).toQPointF(); - } else { + } + else + { p1 = data->GetModelingPoint(p1Id).toQPointF(); p4 = data->GetModelingPoint(id).toQPointF(); } ui->spinBoxAngle1->setValue(static_cast(QLineF(p1, p4).angle())); ui->spinBoxAngle2->setValue(static_cast(QLineF(p4, p1).angle())); } - if(!isInitialized){ + if (isInitialized == false) + { this->show(); } } } } -void DialogSpline::DialogAccepted(){ +void DialogSpline::DialogAccepted() +{ p1 = getCurrentPointId(ui->comboBoxP1); p4 = getCurrentPointId(ui->comboBoxP4); angle1 = ui->spinBoxAngle1->value(); @@ -109,65 +137,44 @@ void DialogSpline::DialogAccepted(){ emit DialogClosed(QDialog::Accepted); } -qreal DialogSpline::getKCurve() const{ - return kCurve; -} - -void DialogSpline::setKCurve(const qreal &value){ +void DialogSpline::setKCurve(const qreal &value) +{ kCurve = value; ui->doubleSpinBoxKcurve->setValue(value); } -qreal DialogSpline::getKAsm2() const{ - return kAsm2; -} - -void DialogSpline::setKAsm2(const qreal &value){ +void DialogSpline::setKAsm2(const qreal &value) +{ kAsm2 = value; ui->doubleSpinBoxKasm2->setValue(value); } -qreal DialogSpline::getKAsm1() const{ - return kAsm1; -} - -void DialogSpline::setKAsm1(const qreal &value){ +void DialogSpline::setKAsm1(const qreal &value) +{ kAsm1 = value; ui->doubleSpinBoxKasm1->setValue(value); } -qreal DialogSpline::getAngle2() const{ - return angle2; -} - -void DialogSpline::setAngle2(const qreal &value){ +void DialogSpline::setAngle2(const qreal &value) +{ angle2 = value; ui->spinBoxAngle2->setValue(static_cast(value)); } -qreal DialogSpline::getAngle1() const{ - return angle1; -} - -void DialogSpline::setAngle1(const qreal &value){ +void DialogSpline::setAngle1(const qreal &value) +{ angle1 = value; ui->spinBoxAngle1->setValue(static_cast(value)); } -qint64 DialogSpline::getP4() const{ - return p4; -} - -void DialogSpline::setP4(const qint64 &value){ +void DialogSpline::setP4(const qint64 &value) +{ p4 = value; ChangeCurrentData(ui->comboBoxP4, value); } -qint64 DialogSpline::getP1() const{ - return p1; -} - -void DialogSpline::setP1(const qint64 &value){ +void DialogSpline::setP1(const qint64 &value) +{ p1 = value; ChangeCurrentData(ui->comboBoxP1, value); } diff --git a/dialogs/dialogspline.h b/dialogs/dialogspline.h index 180f3a455..6ae6b45fc 100644 --- a/dialogs/dialogspline.h +++ b/dialogs/dialogspline.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file dialogspline.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,52 +24,52 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef DIALOGSPLINE_H #define DIALOGSPLINE_H #include "dialogtool.h" -namespace Ui { -class DialogSpline; +namespace Ui +{ + class DialogSpline; } class DialogSpline : public DialogTool { - Q_OBJECT + Q_OBJECT public: - explicit DialogSpline(const VContainer *data, Draw::Draws mode = Draw::Calculation, - QWidget *parent = 0); - ~DialogSpline(); - qint64 getP1() const; - void setP1(const qint64 &value); - qint64 getP4() const; - void setP4(const qint64 &value); - qreal getAngle1() const; - void setAngle1(const qreal &value); - qreal getAngle2() const; - void setAngle2(const qreal &value); - qreal getKAsm1() const; - void setKAsm1(const qreal &value); - qreal getKAsm2() const; - void setKAsm2(const qreal &value); - qreal getKCurve() const; - void setKCurve(const qreal &value); + DialogSpline(const VContainer *data, Draw::Draws mode = Draw::Calculation, QWidget *parent = 0); + ~DialogSpline(); + inline qint64 getP1() const {return p1;} + void setP1(const qint64 &value); + inline qint64 getP4() const {return p4;} + void setP4(const qint64 &value); + inline qreal getAngle1() const {return angle1;} + void setAngle1(const qreal &value); + inline qreal getAngle2() const {return angle2;} + void setAngle2(const qreal &value); + inline qreal getKAsm1() const {return kAsm1;} + void setKAsm1(const qreal &value); + inline qreal getKAsm2() const {return kAsm2;} + void setKAsm2(const qreal &value); + inline qreal getKCurve() const {return kCurve;} + void setKCurve(const qreal &value); public slots: - virtual void ChoosedObject(qint64 id, Scene::Scenes type); - virtual void DialogAccepted(); + virtual void ChoosedObject(qint64 id, const Scene::Scenes &type); + virtual void DialogAccepted(); private: Q_DISABLE_COPY(DialogSpline) Ui::DialogSpline *ui; - qint32 number; - qint64 p1; // перша точка - qint64 p4; // четверта точка - qreal angle1; // кут нахилу дотичної в першій точці - qreal angle2; // кут нахилу дотичної в другій точці - qreal kAsm1; - qreal kAsm2; - qreal kCurve; + qint32 number; + qint64 p1; // перша точка + qint64 p4; // четверта точка + qreal angle1; // кут нахилу дотичної в першій точці + qreal angle2; // кут нахилу дотичної в другій точці + qreal kAsm1; + qreal kAsm2; + qreal kCurve; }; #endif // DIALOGSPLINE_H diff --git a/dialogs/dialogsplinepath.cpp b/dialogs/dialogsplinepath.cpp index 0f085895d..1446f4f8b 100644 --- a/dialogs/dialogsplinepath.cpp +++ b/dialogs/dialogsplinepath.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file dialogsplinepath.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,14 +24,15 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "dialogsplinepath.h" #include "ui_dialogsplinepath.h" -#include "geometry/vsplinepoint.h" +#include "../geometry/vsplinepoint.h" -DialogSplinePath::DialogSplinePath(const VContainer *data, Draw::Draws mode, QWidget *parent) : - DialogTool(data, mode, parent), ui(new Ui::DialogSplinePath), path(VSplinePath()){ +DialogSplinePath::DialogSplinePath(const VContainer *data, Draw::Draws mode, QWidget *parent) + :DialogTool(data, mode, parent), ui(new Ui::DialogSplinePath), path(VSplinePath()) +{ ui->setupUi(this); bOk = ui->buttonBox->button(QDialogButtonBox::Ok); connect(bOk, &QPushButton::clicked, this, &DialogSplinePath::DialogAccepted); @@ -53,14 +61,12 @@ DialogSplinePath::~DialogSplinePath() delete ui; } -VSplinePath DialogSplinePath::GetPath() const{ - return path; -} - -void DialogSplinePath::SetPath(const VSplinePath &value){ +void DialogSplinePath::SetPath(const VSplinePath &value) +{ this->path = value; - ui->listWidget->clear(); - for(qint32 i = 0; i < path.CountPoint(); ++i){ + ui->listWidget->clear(); + for (qint32 i = 0; i < path.CountPoint(); ++i) + { NewItem(path[i].P(), path[i].KAsm1(), path[i].Angle2(), path[i].KAsm2()); } ui->listWidget->setFocus(Qt::OtherFocusReason); @@ -68,28 +74,36 @@ void DialogSplinePath::SetPath(const VSplinePath &value){ } -void DialogSplinePath::ChoosedObject(qint64 id, Scene::Scenes type){ - if(idDetail == 0 && mode == Draw::Modeling){ - if(type == Scene::Detail){ +void DialogSplinePath::ChoosedObject(qint64 id, const Scene::Scenes &type) +{ + if (idDetail == 0 && mode == Draw::Modeling) + { + if (type == Scene::Detail) + { idDetail = id; return; } } - if(mode == Draw::Modeling){ - if(!CheckObject(id)){ + if (mode == Draw::Modeling) + { + if (CheckObject(id) == false) + { return; } } - if(type == Scene::Point){ + if (type == Scene::Point) + { NewItem(id, 1, 0, 1); emit ToolTip(tr("Select point of curve path")); this->show(); } } -void DialogSplinePath::DialogAccepted(){ +void DialogSplinePath::DialogAccepted() +{ path.Clear(); - for(qint32 i = 0; i < ui->listWidget->count(); ++i){ + for (qint32 i = 0; i < ui->listWidget->count(); ++i) + { QListWidgetItem *item = ui->listWidget->item(i); path.append( qvariant_cast(item->data(Qt::UserRole))); } @@ -98,8 +112,10 @@ void DialogSplinePath::DialogAccepted(){ emit DialogClosed(QDialog::Accepted); } -void DialogSplinePath::PointChenged(int row){ - if(ui->listWidget->count() == 0){ +void DialogSplinePath::PointChenged(int row) +{ + if (ui->listWidget->count() == 0) + { return; } QListWidgetItem *item = ui->listWidget->item( row ); @@ -108,7 +124,8 @@ void DialogSplinePath::PointChenged(int row){ EnableFields(); } -void DialogSplinePath::currentPointChanged(int index){ +void DialogSplinePath::currentPointChanged(int index) +{ qint64 id = qvariant_cast(ui->comboBoxPoint->itemData(index)); qint32 row = ui->listWidget->currentRow(); QListWidgetItem *item = ui->listWidget->item( row ); @@ -119,15 +136,18 @@ void DialogSplinePath::currentPointChanged(int index){ item->setData(Qt::UserRole, QVariant::fromValue(p)); } -void DialogSplinePath::Angle1Changed(int index){ +void DialogSplinePath::Angle1Changed(int index) +{ SetAngle(index+180); } -void DialogSplinePath::Angle2Changed(int index){ +void DialogSplinePath::Angle2Changed(int index) +{ SetAngle(index); } -void DialogSplinePath::KAsm1Changed(qreal d){ +void DialogSplinePath::KAsm1Changed(qreal d) +{ qint32 row = ui->listWidget->currentRow(); QListWidgetItem *item = ui->listWidget->item( row ); VSplinePoint p = qvariant_cast(item->data(Qt::UserRole)); @@ -135,7 +155,8 @@ void DialogSplinePath::KAsm1Changed(qreal d){ item->setData(Qt::UserRole, QVariant::fromValue(p)); } -void DialogSplinePath::KAsm2Changed(qreal d){ +void DialogSplinePath::KAsm2Changed(qreal d) +{ qint32 row = ui->listWidget->currentRow(); QListWidgetItem *item = ui->listWidget->item( row ); VSplinePoint p = qvariant_cast(item->data(Qt::UserRole)); @@ -143,11 +164,15 @@ void DialogSplinePath::KAsm2Changed(qreal d){ item->setData(Qt::UserRole, QVariant::fromValue(p)); } -void DialogSplinePath::NewItem(qint64 id, qreal kAsm1, qreal angle, qreal kAsm2){ +void DialogSplinePath::NewItem(qint64 id, qreal kAsm1, qreal angle, qreal kAsm2) +{ VPointF point; - if(mode == Draw::Calculation){ + if (mode == Draw::Calculation) + { point = data->GetPoint(id); - } else { + } + else + { point = data->GetModelingPoint(id); } QListWidgetItem *item = new QListWidgetItem(point.name()); @@ -159,7 +184,8 @@ void DialogSplinePath::NewItem(qint64 id, qreal kAsm1, qreal angle, qreal kAsm2) EnableFields(); } -void DialogSplinePath::DataPoint(qint64 id, qreal kAsm1, qreal angle1, qreal kAsm2, qreal angle2){ +void DialogSplinePath::DataPoint(qint64 id, qreal kAsm1, qreal angle1, qreal kAsm2, qreal angle2) +{ disconnect(ui->comboBoxPoint, static_cast(&QComboBox::currentIndexChanged), this, &DialogSplinePath::currentPointChanged); disconnect(ui->spinBoxAngle1, static_cast(&QSpinBox::valueChanged), @@ -189,25 +215,29 @@ void DialogSplinePath::DataPoint(qint64 id, qreal kAsm1, qreal angle1, qreal kAs this, &DialogSplinePath::KAsm2Changed); } -void DialogSplinePath::EnableFields(){ +void DialogSplinePath::EnableFields() +{ ui->doubleSpinBoxKasm1->setEnabled(true); ui->spinBoxAngle1->setEnabled(true); ui->doubleSpinBoxKasm2->setEnabled(true); ui->spinBoxAngle2->setEnabled(true); qint32 row = ui->listWidget->currentRow(); - if(row == 0){ + if (row == 0) + { ui->doubleSpinBoxKasm1->setEnabled(false); ui->spinBoxAngle1->setEnabled(false); return; } - if(row == ui->listWidget->count()-1){ + if (row == ui->listWidget->count()-1) + { ui->doubleSpinBoxKasm2->setEnabled(false); ui->spinBoxAngle2->setEnabled(false); return; } } -void DialogSplinePath::SetAngle(qint32 angle){ +void DialogSplinePath::SetAngle(qint32 angle) +{ qint32 row = ui->listWidget->currentRow(); QListWidgetItem *item = ui->listWidget->item( row ); VSplinePoint p = qvariant_cast(item->data(Qt::UserRole)); diff --git a/dialogs/dialogsplinepath.h b/dialogs/dialogsplinepath.h index 41cfeb0c2..1ea4d587b 100644 --- a/dialogs/dialogsplinepath.h +++ b/dialogs/dialogsplinepath.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file dialogsplinepath.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,44 +24,45 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef DIALOGSPLINEPATH_H #define DIALOGSPLINEPATH_H #include "dialogtool.h" -#include "geometry/vsplinepath.h" +#include "../geometry/vsplinepath.h" -namespace Ui { -class DialogSplinePath; +namespace Ui +{ + class DialogSplinePath; } class DialogSplinePath : public DialogTool { Q_OBJECT public: - explicit DialogSplinePath(const VContainer *data, Draw::Draws mode = Draw::Calculation, - QWidget *parent = 0); - ~DialogSplinePath(); - VSplinePath GetPath() const; - void SetPath(const VSplinePath &value); + DialogSplinePath(const VContainer *data, Draw::Draws mode = Draw::Calculation, + QWidget *parent = 0); + ~DialogSplinePath(); + inline VSplinePath GetPath() const {return path;} + void SetPath(const VSplinePath &value); public slots: - virtual void ChoosedObject(qint64 id, Scene::Scenes type); - virtual void DialogAccepted(); - void PointChenged(int row); - void currentPointChanged( int index ); - void Angle1Changed( int index ); - void Angle2Changed( int index ); - void KAsm1Changed(qreal d); - void KAsm2Changed(qreal d); + virtual void ChoosedObject(qint64 id, const Scene::Scenes &type); + virtual void DialogAccepted(); + void PointChenged(int row); + void currentPointChanged( int index ); + void Angle1Changed( int index ); + void Angle2Changed( int index ); + void KAsm1Changed(qreal d); + void KAsm2Changed(qreal d); private: Q_DISABLE_COPY(DialogSplinePath) Ui::DialogSplinePath *ui; - VSplinePath path; - void NewItem(qint64 id, qreal kAsm1, qreal angle, qreal kAsm2); - void DataPoint(qint64 id, qreal kAsm1, qreal angle1, qreal kAsm2, qreal angle2); - void EnableFields(); - void SetAngle(qint32 angle); + VSplinePath path; + void NewItem(qint64 id, qreal kAsm1, qreal angle, qreal kAsm2); + void DataPoint(qint64 id, qreal kAsm1, qreal angle1, qreal kAsm2, qreal angle2); + void EnableFields(); + void SetAngle(qint32 angle); }; #endif // DIALOGSPLINEPATH_H diff --git a/dialogs/dialogtool.cpp b/dialogs/dialogtool.cpp index ccb701f24..d394b1967 100644 --- a/dialogs/dialogtool.cpp +++ b/dialogs/dialogtool.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file dialogtool.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,72 +24,81 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "dialogtool.h" -#include -#include -#include "container/calculator.h" -#include "geometry/vdetail.h" -#include +#include "../container/calculator.h" -DialogTool::DialogTool(const VContainer *data, Draw::Draws mode, QWidget *parent):QDialog(parent), data(data), - isInitialized(false), flagName(true), flagFormula(true), timerFormula(0), bOk(0), spinBoxAngle(0), - lineEditFormula(0), listWidget(0), labelResultCalculation(0), labelDescription(0), labelEditNamePoint(0), - labelEditFormula(0), radioButtonSizeGrowth(0), radioButtonStandartTable(0), radioButtonIncrements(0), - radioButtonLengthLine(0), idDetail(0), mode(mode){ - Q_CHECK_PTR(data); +DialogTool::DialogTool(const VContainer *data, Draw::Draws mode, QWidget *parent) + :QDialog(parent), data(data), isInitialized(false), flagName(true), flagFormula(true), timerFormula(0), bOk(0), + spinBoxAngle(0), lineEditFormula(0), listWidget(0), labelResultCalculation(0), labelDescription(0), + labelEditNamePoint(0), labelEditFormula(0), radioButtonSizeGrowth(0), radioButtonStandartTable(0), + radioButtonIncrements(0), radioButtonLengthLine(0), radioButtonLengthArc(0), radioButtonLengthCurve(0), + idDetail(0), mode(mode) +{ + Q_ASSERT(data != 0); timerFormula = new QTimer(this); connect(timerFormula, &QTimer::timeout, this, &DialogTool::EvalFormula); } -DialogTool::~DialogTool(){ -} - -void DialogTool::closeEvent(QCloseEvent *event){ +void DialogTool::closeEvent(QCloseEvent *event) +{ DialogClosed(QDialog::Rejected); event->accept(); } -void DialogTool::showEvent(QShowEvent *event){ +void DialogTool::showEvent(QShowEvent *event) +{ QDialog::showEvent( event ); - if( event->spontaneous() ){ + if ( event->spontaneous() ) + { return; } - if(isInitialized){ + if (isInitialized) + { return; } isInitialized = true;//first show windows are held } -void DialogTool::FillComboBoxPoints(QComboBox *box, const qint64 &id) const{ +void DialogTool::FillComboBoxPoints(QComboBox *box, const qint64 &id) const +{ box->clear(); - if(mode == Draw::Calculation){ + if (mode == Draw::Calculation) + { const QHash *points = data->DataPoints(); QHashIterator i(*points); - while (i.hasNext()) { + while (i.hasNext()) + { i.next(); - if(i.key() != id){ + if (i.key() != id) + { VPointF point = i.value(); box->addItem(point.name(), i.key()); } } - } else { - if(idDetail <= 0){ + } + else + { + if (idDetail <= 0) + { qWarning()<GetDetail(idDetail); - for(qint32 i = 0; i< det.CountNode(); ++i){ - if(det[i].getTypeTool() == Tool::NodePoint || - det[i].getTypeTool() == Tool::AlongLineTool || - det[i].getTypeTool() == Tool::BisectorTool || - det[i].getTypeTool() == Tool::EndLineTool || - det[i].getTypeTool() == Tool::LineIntersectTool || - det[i].getTypeTool() == Tool::NormalTool || - det[i].getTypeTool() == Tool::PointOfContact || - det[i].getTypeTool() == Tool::ShoulderPointTool){ - if(det[i].getId() != id){ + for (ptrdiff_t i = 0; i< det.CountNode(); ++i) + { + if (det[i].getTypeTool() == Tool::NodePoint || + det[i].getTypeTool() == Tool::AlongLineTool || + det[i].getTypeTool() == Tool::BisectorTool || + det[i].getTypeTool() == Tool::EndLineTool || + det[i].getTypeTool() == Tool::LineIntersectTool || + det[i].getTypeTool() == Tool::NormalTool || + det[i].getTypeTool() == Tool::PointOfContact || + det[i].getTypeTool() == Tool::ShoulderPointTool) + { + if (det[i].getId() != id) + { VPointF point = data->GetModelingPoint(det[i].getId()); box->addItem(point.name(), det[i].getId()); } @@ -91,63 +107,86 @@ void DialogTool::FillComboBoxPoints(QComboBox *box, const qint64 &id) const{ } } -void DialogTool::FillComboBoxTypeLine(QComboBox *box) const{ +void DialogTool::FillComboBoxTypeLine(QComboBox *box) const +{ + Q_ASSERT(box != 0); QStringList list; list<addItems(list); } -QString DialogTool::GetTypeLine(const QComboBox *box) const{ - if(box->currentText()==tr("Line")){ +QString DialogTool::GetTypeLine(const QComboBox *box) const +{ + if (box->currentText()==tr("Line")) + { return QString("hair"); - } else { + } + else + { return QString("none"); } } -void DialogTool::SetupTypeLine(QComboBox *box, const QString &value){ - if(value == "hair"){ +void DialogTool::SetupTypeLine(QComboBox *box, const QString &value) +{ + if (value == "hair") + { qint32 index = box->findText(tr("Line")); - if(index != -1){ + if (index != -1) + { box->setCurrentIndex(index); } } - if(value == "none"){ + if (value == "none") + { qint32 index = box->findText(tr("No line")); - if(index != -1){ + if (index != -1) + { box->setCurrentIndex(index); } } } -void DialogTool::ChangeCurrentText(QComboBox *box, const QString &value){ +void DialogTool::ChangeCurrentText(QComboBox *box, const QString &value) +{ qint32 index = box->findText(value); - if(index != -1){ + if (index != -1) + { box->setCurrentIndex(index); } + else + { + qWarning()<findData(value); - if(index != -1){ + if (index != -1) + { box->setCurrentIndex(index); } } -void DialogTool::PutValHere(QLineEdit *lineEdit, QListWidget *listWidget){ - Q_CHECK_PTR(lineEdit); - Q_CHECK_PTR(listWidget); +void DialogTool::PutValHere(QLineEdit *lineEdit, QListWidget *listWidget) +{ + Q_ASSERT(lineEdit != 0); + Q_ASSERT(listWidget != 0); QListWidgetItem *item = listWidget->currentItem(); - QString val = item->text(); - lineEdit->setText(lineEdit->text().append(val)); + int pos = lineEdit->cursorPosition(); + lineEdit->setText(lineEdit->text().insert(lineEdit->cursorPosition(), item->text())); lineEdit->setFocus(); + lineEdit->setCursorPosition(pos + item->text().size()); } -void DialogTool::ValFormulaChanged(bool &flag, QLineEdit *edit, QTimer *timer){ - Q_CHECK_PTR(edit); - Q_CHECK_PTR(timer); - Q_CHECK_PTR(labelEditFormula); - if(edit->text().isEmpty()){ +void DialogTool::ValFormulaChanged(bool &flag, QLineEdit *edit, QTimer *timer) +{ + Q_ASSERT(edit != 0); + Q_ASSERT(timer != 0); + Q_ASSERT(labelEditFormula != 0); + if (edit->text().isEmpty()) + { flag = false; CheckState(); QPalette palette = labelEditFormula->palette(); @@ -158,27 +197,34 @@ void DialogTool::ValFormulaChanged(bool &flag, QLineEdit *edit, QTimer *timer){ timer->start(1000); } -void DialogTool::Eval(QLineEdit *edit, bool &flag, QTimer *timer, QLabel *label){ - Q_CHECK_PTR(edit); - Q_CHECK_PTR(timer); - Q_CHECK_PTR(label); - Q_CHECK_PTR(labelEditFormula); +void DialogTool::Eval(QLineEdit *edit, bool &flag, QTimer *timer, QLabel *label) +{ + Q_ASSERT(edit != 0); + Q_ASSERT(timer != 0); + Q_ASSERT(label != 0); + Q_ASSERT(labelEditFormula != 0); QPalette palette = labelEditFormula->palette(); - if(edit->text().isEmpty()){ + if (edit->text().isEmpty()) + { flag = false; palette.setColor(labelEditFormula->foregroundRole(), Qt::red); - } else { + } + else + { Calculator cal(data); QString errorMsg; - qreal result = cal.eval(edit->text(),&errorMsg); - if(!errorMsg.isEmpty()){ + qreal result = cal.eval(edit->text(), &errorMsg); + if (errorMsg.isEmpty() == false) + { label->setText(tr("Error")); flag = false; palette.setColor(labelEditFormula->foregroundRole(), Qt::red); - } else { + } + else + { label->setText(QString().setNum(result)); flag = true; - palette.setColor(labelEditFormula->foregroundRole(), QColor(76,76,76)); + palette.setColor(labelEditFormula->foregroundRole(), QColor(76, 76, 76)); } } CheckState(); @@ -186,205 +232,293 @@ void DialogTool::Eval(QLineEdit *edit, bool &flag, QTimer *timer, QLabel *label) labelEditFormula->setPalette(palette); } -void DialogTool::setCurrentPointId(QComboBox *box, qint64 &pointId, const qint64 &value, - const qint64 &id) const{ - Q_CHECK_PTR(box); +void DialogTool::setCurrentPointId(QComboBox *box, qint64 &pointId, const qint64 &value, const qint64 &id) const +{ + Q_ASSERT(box != 0); FillComboBoxPoints(box, id); pointId = value; ChangeCurrentData(box, value); } -qint64 DialogTool::getCurrentPointId(QComboBox *box) const{ - Q_CHECK_PTR(box); +qint64 DialogTool::getCurrentPointId(QComboBox *box) const +{ + Q_ASSERT(box != 0); qint32 index = box->currentIndex(); Q_ASSERT(index != -1); - if(index != -1){ + if (index != -1) + { return qvariant_cast(box->itemData(index)); - } else { + } + else + { return -1; } } -void DialogTool::CheckState(){ - Q_CHECK_PTR(bOk); +void DialogTool::CheckState() +{ + Q_ASSERT(bOk != 0); bOk->setEnabled(flagFormula && flagName); } - -void DialogTool::ChoosedObject(qint64 id, Scene::Scenes type){ +void DialogTool::ChoosedObject(qint64 id, const Scene::Scenes &type) +{ Q_UNUSED(id); Q_UNUSED(type); } -void DialogTool::NamePointChanged(){ - Q_CHECK_PTR(labelEditNamePoint); +void DialogTool::NamePointChanged() +{ + Q_ASSERT(labelEditNamePoint != 0); QLineEdit* edit = qobject_cast(sender()); - if (edit){ + if (edit) + { QString name = edit->text(); - if(name.isEmpty() || name.contains(" ")){ + if (name.isEmpty() || name.contains(" ")) + { flagName = false; QPalette palette = labelEditNamePoint->palette(); palette.setColor(labelEditNamePoint->foregroundRole(), Qt::red); labelEditNamePoint->setPalette(palette); - } else { + } + else + { flagName = true; QPalette palette = labelEditNamePoint->palette(); - palette.setColor(labelEditNamePoint->foregroundRole(), QColor(76,76,76)); + palette.setColor(labelEditNamePoint->foregroundRole(), QColor(76, 76, 76)); labelEditNamePoint->setPalette(palette); } } CheckState(); } -void DialogTool::DialogAccepted(){ +void DialogTool::DialogAccepted() +{ emit DialogClosed(QDialog::Accepted); } -void DialogTool::DialogRejected(){ +void DialogTool::DialogRejected() +{ emit DialogClosed(QDialog::Rejected); } -void DialogTool::FormulaChanged(){ +void DialogTool::FormulaChanged() +{ QLineEdit* edit = qobject_cast(sender()); - if(edit){ + if (edit) + { ValFormulaChanged(flagFormula, edit, timerFormula); } } -void DialogTool::ArrowUp(){ - Q_CHECK_PTR(spinBoxAngle); +void DialogTool::ArrowUp() +{ + Q_ASSERT(spinBoxAngle != 0); spinBoxAngle->setValue(90); } -void DialogTool::ArrowDown(){ - Q_CHECK_PTR(spinBoxAngle); +void DialogTool::ArrowDown() +{ + Q_ASSERT(spinBoxAngle != 0); spinBoxAngle->setValue(270); } -void DialogTool::ArrowLeft(){ - Q_CHECK_PTR(spinBoxAngle); +void DialogTool::ArrowLeft() +{ + Q_ASSERT(spinBoxAngle != 0); spinBoxAngle->setValue(180); } -void DialogTool::ArrowRight(){ - Q_CHECK_PTR(spinBoxAngle); +void DialogTool::ArrowRight() +{ + Q_ASSERT(spinBoxAngle != 0); spinBoxAngle->setValue(0); } -void DialogTool::ArrowLeftUp(){ - Q_CHECK_PTR(spinBoxAngle); +void DialogTool::ArrowLeftUp() +{ + Q_ASSERT(spinBoxAngle != 0); spinBoxAngle->setValue(135); } -void DialogTool::ArrowLeftDown(){ - Q_CHECK_PTR(spinBoxAngle); +void DialogTool::ArrowLeftDown() +{ + Q_ASSERT(spinBoxAngle != 0); spinBoxAngle->setValue(225); } -void DialogTool::ArrowRightUp(){ - Q_CHECK_PTR(spinBoxAngle); +void DialogTool::ArrowRightUp() +{ + Q_ASSERT(spinBoxAngle != 0); spinBoxAngle->setValue(45); } -void DialogTool::ArrowRightDown(){ - Q_CHECK_PTR(spinBoxAngle); +void DialogTool::ArrowRightDown() +{ + Q_ASSERT(spinBoxAngle != 0); spinBoxAngle->setValue(315); } -void DialogTool::EvalFormula(){ - Q_CHECK_PTR(lineEditFormula); - Q_CHECK_PTR(labelResultCalculation); +void DialogTool::EvalFormula() +{ + Q_ASSERT(lineEditFormula != 0); + Q_ASSERT(labelResultCalculation != 0); Eval(lineEditFormula, flagFormula, timerFormula, labelResultCalculation); } -void DialogTool::SizeGrowth(){ +void DialogTool::SizeGrowth() +{ ShowVariable(data->DataBase()); } -void DialogTool::StandartTable(){ +void DialogTool::StandartTable() +{ ShowVariable(data->DataStandartTable()); } -void DialogTool::LengthLines(){ +void DialogTool::LengthLines() +{ ShowVariable(data->DataLengthLines()); } -void DialogTool::Increments(){ +void DialogTool::LengthArcs() +{ + ShowVariable(data->DataLengthArcs()); +} + +void DialogTool::LengthCurves() +{ + ShowVariable(data->DataLengthSplines()); +} + +void DialogTool::Increments() +{ ShowVariable(data->DataIncrementTable()); } -void DialogTool::PutHere(){ +void DialogTool::PutHere() +{ PutValHere(lineEditFormula, listWidget); } -void DialogTool::PutVal(QListWidgetItem *item){ - Q_CHECK_PTR(lineEditFormula); - QString val = item->text(); - lineEditFormula->setText(lineEditFormula->text().append(val)); +void DialogTool::PutVal(QListWidgetItem *item) +{ + Q_ASSERT(lineEditFormula != 0); + Q_ASSERT(item != 0); + int pos = lineEditFormula->cursorPosition(); + lineEditFormula->setText(lineEditFormula->text().insert(lineEditFormula->cursorPosition(), + item->text())); lineEditFormula->setFocus(); + lineEditFormula->setCursorPosition(pos + item->text().size()); } -void DialogTool::ValChenged(int row){ - Q_CHECK_PTR(listWidget); - Q_CHECK_PTR(labelDescription); - Q_CHECK_PTR(radioButtonSizeGrowth); - Q_CHECK_PTR(radioButtonStandartTable); - Q_CHECK_PTR(radioButtonIncrements); - Q_CHECK_PTR(radioButtonLengthLine); - if(listWidget->count() == 0){ +void DialogTool::ValChenged(int row) +{ + Q_ASSERT(listWidget != 0); + Q_ASSERT(labelDescription != 0); + Q_ASSERT(radioButtonSizeGrowth != 0); + Q_ASSERT(radioButtonStandartTable != 0); + Q_ASSERT(radioButtonIncrements != 0); + Q_ASSERT(radioButtonLengthLine != 0); + Q_ASSERT(radioButtonLengthArc != 0); + Q_ASSERT(radioButtonLengthCurve != 0); + if (listWidget->count() == 0) + { return; } QListWidgetItem *item = listWidget->item( row ); - if(radioButtonSizeGrowth->isChecked()){ - if(item->text()=="Р"){ - QString desc = QString("%1(%2) - %3").arg(item->text()).arg(data->growth()).arg("Зріст"); + if (radioButtonSizeGrowth->isChecked()) + { + if (item->text()=="Р") + { + QString desc = QString("%1(%2) - %3").arg(item->text()).arg(data->growth()).arg(tr("Growth")); labelDescription->setText(desc); } - if(item->text()=="Сг"){ - QString desc = QString("%1(%2) - %3").arg(item->text()).arg(data->size()).arg("Розмір"); + if (item->text()=="Сг") + { + QString desc = QString("%1(%2) - %3").arg(item->text()).arg(data->size()).arg(tr("Size")); labelDescription->setText(desc); } return; } - if(radioButtonStandartTable->isChecked()){ + if (radioButtonStandartTable->isChecked()) + { VStandartTableCell stable = data->GetStandartTableCell(item->text()); QString desc = QString("%1(%2) - %3").arg(item->text()).arg(data->GetValueStandartTableCell(item->text())) .arg(stable.GetDescription()); labelDescription->setText(desc); return; } - if(radioButtonIncrements->isChecked()){ + if (radioButtonIncrements->isChecked()) + { VIncrementTableRow itable = data->GetIncrementTableRow(item->text()); QString desc = QString("%1(%2) - %3").arg(item->text()).arg(data->GetValueIncrementTableRow(item->text())) .arg(itable.getDescription()); labelDescription->setText(desc); return; } - if(radioButtonLengthLine->isChecked()){ + if (radioButtonLengthLine->isChecked()) + { QString desc = QString("%1(%2) - %3").arg(item->text()).arg(data->GetLine(item->text())) .arg(tr("Line length")); labelDescription->setText(desc); return; } -} - -void DialogTool::UpdateList(){ - if(radioButtonSizeGrowth == 0 || radioButtonStandartTable == 0 || radioButtonIncrements == 0){ + if (radioButtonLengthArc->isChecked()) + { + QString desc = QString("%1(%2) - %3").arg(item->text()).arg(data->GetLengthArc(item->text())) + .arg(tr("Arc length")); + labelDescription->setText(desc); return; } - if(radioButtonSizeGrowth->isChecked()){ - ShowVariable(data->DataBase()); - } - if(radioButtonStandartTable->isChecked()){ - ShowVariable(data->DataStandartTable()); - } - if(radioButtonIncrements->isChecked()){ - ShowVariable(data->DataIncrementTable()); + if (radioButtonLengthCurve->isChecked()) + { + QString desc = QString("%1(%2) - %3").arg(item->text()).arg(data->GetLengthSpline(item->text())) + .arg(tr("Curve length")); + labelDescription->setText(desc); + return; } } -bool DialogTool::CheckObject(const qint64 &id){ - if(mode == Draw::Calculation || idDetail == 0){ +void DialogTool::UpdateList() +{ + Q_ASSERT(radioButtonSizeGrowth != 0); + Q_ASSERT(radioButtonStandartTable != 0); + Q_ASSERT(radioButtonIncrements != 0); + Q_ASSERT(radioButtonLengthLine != 0); + Q_ASSERT(radioButtonLengthArc != 0); + Q_ASSERT(radioButtonLengthCurve != 0); + + if (radioButtonSizeGrowth->isChecked()) + { + ShowVariable(data->DataBase()); + } + if (radioButtonStandartTable->isChecked()) + { + ShowVariable(data->DataStandartTable()); + } + if (radioButtonIncrements->isChecked()) + { + ShowVariable(data->DataIncrementTable()); + } + if (radioButtonLengthLine->isChecked()) + { + ShowVariable(data->DataLengthLines()); + } + if (radioButtonLengthArc->isChecked()) + { + ShowVariable(data->DataLengthArcs()); + } + if (radioButtonLengthCurve->isChecked()) + { + ShowVariable(data->DataLengthSplines()); + } +} + +bool DialogTool::CheckObject(const qint64 &id) +{ + if (mode == Draw::Calculation || idDetail == 0) + { return false; } VDetail det = data->GetDetail(idDetail); @@ -392,25 +526,28 @@ bool DialogTool::CheckObject(const qint64 &id){ } template -void DialogTool::ShowVariable(const QHash *var){ - Q_CHECK_PTR(listWidget); +void DialogTool::ShowVariable(const QHash *var) +{ + Q_ASSERT(listWidget != 0); disconnect(listWidget, &QListWidget::currentRowChanged, this, &DialogTool::ValChenged); listWidget->clear(); - connect(listWidget, &QListWidget::currentRowChanged, this, &DialogTool::ValChenged); + QHashIterator i(*var); - while (i.hasNext()) { + QMap map; + while (i.hasNext()) + { i.next(); - QListWidgetItem *item = new QListWidgetItem(i.key()); + map.insert(i.key(), i.value()); + } + + QMapIterator iMap(map); + while (iMap.hasNext()) + { + iMap.next(); + QListWidgetItem *item = new QListWidgetItem(iMap.key()); item->setFont(QFont("Times", 12, QFont::Bold)); listWidget->addItem(item); } + connect(listWidget, &QListWidget::currentRowChanged, this, &DialogTool::ValChenged); listWidget->setCurrentRow (0); } - -qint64 DialogTool::getIdDetail() const{ - return idDetail; -} - -void DialogTool::setIdDetail(const qint64 &value){ - idDetail = value; -} diff --git a/dialogs/dialogtool.h b/dialogs/dialogtool.h index 630582144..34b9ce76e 100644 --- a/dialogs/dialogtool.h +++ b/dialogs/dialogtool.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file dialogtool.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,35 +24,27 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef DIALOGTOOL_H #define DIALOGTOOL_H #include -#include -#include -#include -#include -#include -#include -#include -#include -#include "container/vcontainer.h" +#include "../container/vcontainer.h" -class DialogTool : public QDialog{ +class DialogTool : public QDialog +{ Q_OBJECT public: - DialogTool(const VContainer *data, Draw::Draws mode = Draw::Calculation, - QWidget *parent = 0); - virtual ~DialogTool(); - qint64 getIdDetail() const; - void setIdDetail(const qint64 &value); + DialogTool(const VContainer *data, Draw::Draws mode = Draw::Calculation, QWidget *parent = 0); + virtual ~DialogTool() {} + inline qint64 getIdDetail() const {return idDetail;} + inline void setIdDetail(const qint64 &value) {idDetail = value;} signals: void DialogClosed(int result); void ToolTip(const QString &toolTip); public slots: - virtual void ChoosedObject(qint64 id, Scene::Scenes type); + virtual void ChoosedObject(qint64 id, const Scene::Scenes &type); void NamePointChanged(); virtual void DialogAccepted(); virtual void DialogRejected(); @@ -62,6 +61,8 @@ public slots: void SizeGrowth(); void StandartTable(); void LengthLines(); + void LengthArcs(); + void LengthCurves(); void Increments(); void PutHere(); void PutVal(QListWidgetItem * item); @@ -86,8 +87,10 @@ protected: QRadioButton *radioButtonStandartTable; QRadioButton *radioButtonIncrements; QRadioButton *radioButtonLengthLine; + QRadioButton *radioButtonLengthArc; + QRadioButton *radioButtonLengthCurve; qint64 idDetail; - Draw::Draws mode; + Draw::Draws mode; bool CheckObject(const qint64 &id); virtual void closeEvent ( QCloseEvent * event ); virtual void showEvent( QShowEvent *event ); diff --git a/dialogs/dialogtriangle.cpp b/dialogs/dialogtriangle.cpp new file mode 100644 index 000000000..49d607e38 --- /dev/null +++ b/dialogs/dialogtriangle.cpp @@ -0,0 +1,154 @@ +/************************************************************************ + ** + ** @file dialogtriangle.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "dialogtriangle.h" +#include "ui_dialogtriangle.h" + +DialogTriangle::DialogTriangle(const VContainer *data, Draw::Draws mode, QWidget *parent) + :DialogTool(data, mode, parent), ui(new Ui::DialogTriangle), number(0), pointName(QString()), axisP1Id(0), + axisP2Id(0), firstPointId(0), secondPointId(0) +{ + ui->setupUi(this); + labelEditNamePoint = ui->labelEditNamePoint; + bOk = ui->buttonBox->button(QDialogButtonBox::Ok); + connect(bOk, &QPushButton::clicked, this, &DialogTriangle::DialogAccepted); + flagName = false; + CheckState(); + QPushButton *bCansel = ui->buttonBox->button(QDialogButtonBox::Cancel); + connect(bCansel, &QPushButton::clicked, this, &DialogTriangle::DialogRejected); + FillComboBoxPoints(ui->comboBoxAxisP1); + FillComboBoxPoints(ui->comboBoxAxisP2); + FillComboBoxPoints(ui->comboBoxFirstPoint); + FillComboBoxPoints(ui->comboBoxSecondPoint); + connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogTriangle::NamePointChanged); +} + +DialogTriangle::~DialogTriangle() +{ + delete ui; +} + +void DialogTriangle::ChoosedObject(qint64 id, const Scene::Scenes &type) +{ + if (idDetail == 0 && mode == Draw::Modeling) + { + if (type == Scene::Detail) + { + idDetail = id; + return; + } + } + if (mode == Draw::Modeling) + { + if (CheckObject(id) == false) + { + 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->comboBoxAxisP1, point.name()); + number++; + emit ToolTip(tr("Select second point of axis")); + break; + case (1): + ChangeCurrentText(ui->comboBoxAxisP2, point.name()); + number++; + emit ToolTip(tr("Select first point")); + break; + case (2): + ChangeCurrentText(ui->comboBoxFirstPoint, point.name()); + number++; + emit ToolTip(tr("Select second point")); + break; + case (3): + ChangeCurrentText(ui->comboBoxSecondPoint, point.name()); + number = 0; + emit ToolTip(tr("")); + if (isInitialized == false) + { + this->show(); + } + break; + default: + break; + } + } +} + +void DialogTriangle::DialogAccepted() +{ + pointName = ui->lineEditNamePoint->text(); + firstPointId = getCurrentPointId(ui->comboBoxFirstPoint); + secondPointId = getCurrentPointId(ui->comboBoxSecondPoint); + axisP1Id = getCurrentPointId(ui->comboBoxAxisP1); + axisP2Id = getCurrentPointId(ui->comboBoxAxisP2); + emit DialogClosed(QDialog::Accepted); +} + +void DialogTriangle::setPointName(const QString &value) +{ + pointName = value; + ui->lineEditNamePoint->setText(pointName); +} + +void DialogTriangle::setSecondPointId(const qint64 &value, const qint64 &id) +{ + secondPointId = value; + setCurrentPointId(ui->comboBoxSecondPoint, secondPointId, value, id); +} + +void DialogTriangle::setFirstPointId(const qint64 &value, const qint64 &id) +{ + firstPointId = value; + setCurrentPointId(ui->comboBoxFirstPoint, firstPointId, value, id); +} + +void DialogTriangle::setAxisP2Id(const qint64 &value, const qint64 &id) +{ + axisP2Id = value; + setCurrentPointId(ui->comboBoxAxisP2, axisP2Id, value, id); +} + +void DialogTriangle::setAxisP1Id(const qint64 &value, const qint64 &id) +{ + axisP1Id = value; + setCurrentPointId(ui->comboBoxAxisP1, axisP1Id, value, id); +} diff --git a/dialogs/dialogtriangle.h b/dialogs/dialogtriangle.h new file mode 100644 index 000000000..a3aa2393d --- /dev/null +++ b/dialogs/dialogtriangle.h @@ -0,0 +1,69 @@ +/************************************************************************ + ** + ** @file dialogtriangle.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef DIALOGTRIANGLE_H +#define DIALOGTRIANGLE_H + +#include "dialogtool.h" + +namespace Ui +{ + class DialogTriangle; +} + +class DialogTriangle : public DialogTool +{ + Q_OBJECT +public: + DialogTriangle(const VContainer *data, Draw::Draws mode = Draw::Calculation, QWidget *parent = 0); + ~DialogTriangle(); + inline qint64 getAxisP1Id() const {return axisP1Id;} + void setAxisP1Id(const qint64 &value, const qint64 &id); + inline qint64 getAxisP2Id() const {return axisP2Id;} + void setAxisP2Id(const qint64 &value, const qint64 &id); + inline qint64 getFirstPointId() const {return firstPointId;} + void setFirstPointId(const qint64 &value, const qint64 &id); + inline qint64 getSecondPointId() const {return secondPointId;} + void setSecondPointId(const qint64 &value, const qint64 &id); + inline QString getPointName() const {return pointName;} + void setPointName(const QString &value); +public slots: + virtual void ChoosedObject(qint64 id, const Scene::Scenes &type); + virtual void DialogAccepted(); +private: + Q_DISABLE_COPY(DialogTriangle) + Ui::DialogTriangle *ui; + qint32 number; + QString pointName; + qint64 axisP1Id; + qint64 axisP2Id; + qint64 firstPointId; + qint64 secondPointId; +}; + +#endif // DIALOGTRIANGLE_H diff --git a/dialogs/dialogtriangle.ui b/dialogs/dialogtriangle.ui new file mode 100644 index 000000000..7e788b2f0 --- /dev/null +++ b/dialogs/dialogtriangle.ui @@ -0,0 +1,196 @@ + + + DialogTriangle + + + + 0 + 0 + 267 + 220 + + + + Dialog + + + + + + + + + + + + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 159 + 158 + 158 + + + + + + + + Name new point + + + + + + + + + + + + + + First point of axis + + + + + + + First point of line + + + + + + + + + + + Second point of axis + + + + + + + First point of line + + + + + + + + + + + First point + + + + + + + First point of line + + + + + + + + + + + Second point + + + + + + + First point of line + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + DialogTriangle + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + DialogTriangle + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/exception/exception.pri b/exception/exception.pri new file mode 100644 index 000000000..4293f086b --- /dev/null +++ b/exception/exception.pri @@ -0,0 +1,17 @@ +HEADERS += \ + exception/vexceptionwrongparameterid.h \ + exception/vexceptionuniqueid.h \ + exception/vexceptionobjecterror.h \ + exception/vexceptionemptyparameter.h \ + exception/vexceptionconversionerror.h \ + exception/vexceptionbadid.h \ + exception/vexception.h + +SOURCES += \ + exception/vexceptionwrongparameterid.cpp \ + exception/vexceptionuniqueid.cpp \ + exception/vexceptionobjecterror.cpp \ + exception/vexceptionemptyparameter.cpp \ + exception/vexceptionconversionerror.cpp \ + exception/vexceptionbadid.cpp \ + exception/vexception.cpp diff --git a/exception/vexception.cpp b/exception/vexception.cpp index a22df35a3..478a7613f 100644 --- a/exception/vexception.cpp +++ b/exception/vexception.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vexception.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,18 +24,17 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "vexception.h" -VException::VException(const QString &what):QException(), what(what){ - Q_ASSERT_X(!what.isEmpty(), Q_FUNC_INFO, "Error message is empty"); +VException::VException(const QString &what):QException(), what(what) +{ + Q_ASSERT_X(what.isEmpty() == false, Q_FUNC_INFO, "Error message is empty"); } -VException::VException(const VException &e):what(e.What()){ -} - -QString VException::ErrorMessage() const{ +QString VException::ErrorMessage() const +{ QString error = QString("Exception: %1").arg(what); return error; } diff --git a/exception/vexception.h b/exception/vexception.h index fc53c3d77..426a2c4fb 100644 --- a/exception/vexception.h +++ b/exception/vexception.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vexception.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,28 +24,27 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef VEXCEPTION_H #define VEXCEPTION_H #include -#include class VException : public QException { public: - VException(const QString &what); - VException(const VException &e); - virtual ~VException() noexcept(true){} - void raise() const { throw *this; } - VException *clone() const { return new VException(*this); } - virtual QString ErrorMessage() const; - virtual QString DetailedInformation() const { return QString(); } - QString What() const {return what;} + VException(const QString &what); + VException(const VException &e):what(e.What()){} + virtual ~VException() Q_DECL_NOEXCEPT_EXPR(true){} + inline void raise() const { throw *this; } + inline VException *clone() const { return new VException(*this); } + virtual QString ErrorMessage() const; + virtual QString DetailedInformation() const { return QString(); } + inline QString What() const {return what;} protected: - QString what; + QString what; }; #endif // VEXCEPTION_H diff --git a/exception/vexceptionbadid.cpp b/exception/vexceptionbadid.cpp index 82f686f48..78bfc6327 100644 --- a/exception/vexceptionbadid.cpp +++ b/exception/vexceptionbadid.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vexceptionbadid.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,28 +24,20 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "vexceptionbadid.h" -VExceptionBadId::VExceptionBadId(const QString &what, const qint64 &id):VException(what), id(id), - key(QString()){ -} - -VExceptionBadId::VExceptionBadId(const QString &what, const QString &key):VException(what), id(0), key(key) +QString VExceptionBadId::ErrorMessage() const { -} - -VExceptionBadId::VExceptionBadId(const VExceptionBadId &e):VException(e), id(e.BadId()), key(e.BadKey()){ -} - -QString VExceptionBadId::ErrorMessage() const{ QString error; - if(key.isEmpty()){ + if (key.isEmpty()) + { error = QString("ExceptionBadId: %1, id = %2").arg(what).arg(id); - } else { + } + else + { error = QString("ExceptionBadId: %1, id = %2").arg(what).arg(key); } return error; } - diff --git a/exception/vexceptionbadid.h b/exception/vexceptionbadid.h index caa9fcd54..d15c695e9 100644 --- a/exception/vexceptionbadid.h +++ b/exception/vexceptionbadid.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vexceptionbadid.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,7 +24,7 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef VEXCEPTIONBADID_H #define VEXCEPTIONBADID_H @@ -27,16 +34,19 @@ class VExceptionBadId : public VException { public: - VExceptionBadId(const QString &what, const qint64 &id); - VExceptionBadId(const QString &what, const QString &key); - VExceptionBadId(const VExceptionBadId &e); - virtual ~VExceptionBadId() noexcept(true){} + VExceptionBadId(const QString &what, const qint64 &id) + :VException(what), id(id), key(QString()){} + VExceptionBadId(const QString &what, const QString &key) + :VException(what), id(0), key(key){} + VExceptionBadId(const VExceptionBadId &e) + :VException(e), id(e.BadId()), key(e.BadKey()){} + virtual ~VExceptionBadId() Q_DECL_NOEXCEPT_EXPR(true){} virtual QString ErrorMessage() const; - qint64 BadId() const {return id; } - QString BadKey() const {return key; } + inline qint64 BadId() const {return id; } + inline QString BadKey() const {return key; } protected: - qint64 id; - QString key; + qint64 id; + QString key; }; #endif // VEXCEPTIONBADID_H diff --git a/exception/vexceptionconversionerror.cpp b/exception/vexceptionconversionerror.cpp index 7bfbf1366..cfc0634c5 100644 --- a/exception/vexceptionconversionerror.cpp +++ b/exception/vexceptionconversionerror.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vexceptionconversionerror.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,20 +24,18 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "vexceptionconversionerror.h" VExceptionConversionError::VExceptionConversionError(const QString &what, const QString &str) - :VException(what), str(str){ - Q_ASSERT_X(!str.isEmpty(), Q_FUNC_INFO, "Error converting string is empty"); + :VException(what), str(str) +{ + Q_ASSERT_X(str.isEmpty() == false, Q_FUNC_INFO, "Error converting string is empty"); } -VExceptionConversionError::VExceptionConversionError(const VExceptionConversionError &e): - VException(e), str(e.String()){ -} - -QString VExceptionConversionError::ErrorMessage() const{ +QString VExceptionConversionError::ErrorMessage() const +{ QString error = QString("ExceptionConversionError: %1 %2").arg(what, str); return error; } diff --git a/exception/vexceptionconversionerror.h b/exception/vexceptionconversionerror.h index f0650a50d..a864fc98e 100644 --- a/exception/vexceptionconversionerror.h +++ b/exception/vexceptionconversionerror.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vexceptionconversionerror.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,7 +24,7 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef VEXCEPTIONCONVERSIONERROR_H #define VEXCEPTIONCONVERSIONERROR_H @@ -27,13 +34,14 @@ class VExceptionConversionError : public VException { public: - VExceptionConversionError(const QString &what, const QString &str); - VExceptionConversionError(const VExceptionConversionError &e); - virtual ~VExceptionConversionError() noexcept(true) {} + VExceptionConversionError(const QString &what, const QString &str); + VExceptionConversionError(const VExceptionConversionError &e) + :VException(e), str(e.String()){} + virtual ~VExceptionConversionError() Q_DECL_NOEXCEPT_EXPR(true) {} virtual QString ErrorMessage() const; - QString String() const {return str;} + inline QString String() const {return str;} protected: - QString str; + QString str; }; #endif // VEXCEPTIONCONVERSIONERROR_H diff --git a/exception/vexceptionemptyparameter.cpp b/exception/vexceptionemptyparameter.cpp index fb7ee565f..af84d8ebd 100644 --- a/exception/vexceptionemptyparameter.cpp +++ b/exception/vexceptionemptyparameter.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vexceptionemptyparameter.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,32 +24,30 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "vexceptionemptyparameter.h" -#include VExceptionEmptyParameter::VExceptionEmptyParameter(const QString &what, const QString &name, - const QDomElement &domElement): VException(what), - name(name), tagText(QString()), tagName(QString()), lineNumber(-1){ - Q_ASSERT_X(!domElement.isNull(), Q_FUNC_INFO, "domElement is null"); - Q_ASSERT_X(!name.isEmpty(), Q_FUNC_INFO, "Parameter name is empty"); + const QDomElement &domElement) + : VException(what), name(name), tagText(QString()), tagName(QString()), lineNumber(-1) +{ + Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null"); + Q_ASSERT_X(name.isEmpty() == false, Q_FUNC_INFO, "Parameter name is empty"); QTextStream stream(&tagText); domElement.save(stream, 4); tagName = domElement.tagName(); lineNumber = domElement.lineNumber(); } -VExceptionEmptyParameter::VExceptionEmptyParameter(const VExceptionEmptyParameter &e):VException(e), - name(e.Name()), tagText(e.TagText()), tagName(e.TagName()), lineNumber(e.LineNumber()){ -} - -QString VExceptionEmptyParameter::ErrorMessage() const{ +QString VExceptionEmptyParameter::ErrorMessage() const +{ QString error = QString("ExceptionEmptyParameter: %1 %2").arg(what, name); return error; } -QString VExceptionEmptyParameter::DetailedInformation() const{ +QString VExceptionEmptyParameter::DetailedInformation() const +{ QString detail = QString("tag: %1 in line %2\nFull tag:\n%3").arg(tagName).arg(lineNumber).arg(tagText); return detail; } diff --git a/exception/vexceptionemptyparameter.h b/exception/vexceptionemptyparameter.h index 5e2ad973f..e877f3220 100644 --- a/exception/vexceptionemptyparameter.h +++ b/exception/vexceptionemptyparameter.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vexceptionemptyparameter.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,31 +24,32 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef VEXCEPTIONEMPTYPARAMETER_H #define VEXCEPTIONEMPTYPARAMETER_H #include "vexception.h" -#include class VExceptionEmptyParameter : public VException { public: - VExceptionEmptyParameter(const QString &what, const QString &name, const QDomElement &domElement); - VExceptionEmptyParameter(const VExceptionEmptyParameter &e); - virtual ~VExceptionEmptyParameter() noexcept(true) {} + VExceptionEmptyParameter(const QString &what, const QString &name, const QDomElement &domElement); + VExceptionEmptyParameter(const VExceptionEmptyParameter &e) + :VException(e), name(e.Name()), tagText(e.TagText()), tagName(e.TagName()), + lineNumber(e.LineNumber()){} + virtual ~VExceptionEmptyParameter() Q_DECL_NOEXCEPT_EXPR(true) {} virtual QString ErrorMessage() const; virtual QString DetailedInformation() const; - QString Name() const {return name;} - QString TagText() const {return tagText;} - QString TagName() const {return tagName;} - qint32 LineNumber() const {return lineNumber;} + inline QString Name() const {return name;} + inline QString TagText() const {return tagText;} + inline QString TagName() const {return tagName;} + inline qint32 LineNumber() const {return lineNumber;} protected: - QString name; - QString tagText; - QString tagName; - qint32 lineNumber; + QString name; + QString tagText; + QString tagName; + qint32 lineNumber; }; #endif // VEXCEPTIONEMPTYPARAMETER_H diff --git a/exception/vexceptionobjecterror.cpp b/exception/vexceptionobjecterror.cpp index d1a424eff..7b77be4a3 100644 --- a/exception/vexceptionobjecterror.cpp +++ b/exception/vexceptionobjecterror.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vexceptionobjecterror.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,42 +24,46 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "vexceptionobjecterror.h" #include -VExceptionObjectError::VExceptionObjectError(const QString &what, const QDomElement &domElement): - VException(what), tagText(QString()), tagName(QString()), lineNumber(-1), moreInfo(QString()){ - Q_ASSERT_X(!domElement.isNull(), Q_FUNC_INFO, "domElement is null"); +VExceptionObjectError::VExceptionObjectError(const QString &what, const QDomElement &domElement) + :VException(what), tagText(QString()), tagName(QString()), lineNumber(-1), moreInfo(QString()) +{ + Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null"); QTextStream stream(&tagText); domElement.save(stream, 4); tagName = domElement.tagName(); lineNumber = domElement.lineNumber(); } -VExceptionObjectError::VExceptionObjectError(const VExceptionObjectError &e):VException(e), - tagText(e.TagText()), tagName(e.TagName()), lineNumber(e.LineNumber()), moreInfo(e.MoreInformation()){ -} - -QString VExceptionObjectError::ErrorMessage() const{ +QString VExceptionObjectError::ErrorMessage() const +{ QString error = QString("ExceptionObjectError: %1").arg(what); return error; } -QString VExceptionObjectError::DetailedInformation() const{ +QString VExceptionObjectError::DetailedInformation() const +{ QString detail; - if(!moreInfo.isEmpty()){ + if (moreInfo.isEmpty() == false) + { QString i = QString("tag: %1 in line %2\n%3").arg(tagName).arg(lineNumber).arg(tagText); detail = QString("%1\n%2").arg(moreInfo, i); - } else { + } + else + { detail = QString("tag: %1 in line %2\n%3").arg(tagName).arg(lineNumber).arg(tagText); } return detail; } -void VExceptionObjectError::AddMoreInformation(const QString &info){ - if(info.isEmpty()){ +void VExceptionObjectError::AddMoreInformation(const QString &info) +{ + if (info.isEmpty()) + { qWarning()<<"Error additional information is empty."<moreInfo.append(info); diff --git a/exception/vexceptionobjecterror.h b/exception/vexceptionobjecterror.h index f0e36bb99..c0b3fbaf7 100644 --- a/exception/vexceptionobjecterror.h +++ b/exception/vexceptionobjecterror.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vexceptionobjecterror.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,32 +24,33 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef VEXCEPTIONOBJECTERROR_H #define VEXCEPTIONOBJECTERROR_H #include "vexception.h" -#include class VExceptionObjectError : public VException { public: - VExceptionObjectError(const QString &what, const QDomElement &domElement); - VExceptionObjectError(const VExceptionObjectError &e); - virtual ~VExceptionObjectError() noexcept(true) {} + VExceptionObjectError(const QString &what, const QDomElement &domElement); + VExceptionObjectError(const VExceptionObjectError &e) + :VException(e), tagText(e.TagText()), tagName(e.TagName()), lineNumber(e.LineNumber()), + moreInfo(e.MoreInformation()){} + virtual ~VExceptionObjectError() Q_DECL_NOEXCEPT_EXPR(true) {} virtual QString ErrorMessage() const; virtual QString DetailedInformation() const; - QString TagText() const {return tagText;} - QString TagName() const {return tagName;} - qint32 LineNumber() const {return lineNumber;} - void AddMoreInformation(const QString &info); - QString MoreInformation() const {return moreInfo;} + inline QString TagText() const {return tagText;} + inline QString TagName() const {return tagName;} + inline qint32 LineNumber() const {return lineNumber;} + void AddMoreInformation(const QString &info); + inline QString MoreInformation() const {return moreInfo;} protected: - QString tagText; - QString tagName; - qint32 lineNumber; - QString moreInfo; + QString tagText; + QString tagName; + qint32 lineNumber; + QString moreInfo; }; #endif // VEXCEPTIONOBJECTERROR_H diff --git a/exception/vexceptionuniqueid.cpp b/exception/vexceptionuniqueid.cpp index 51ddf4c82..10a3136ca 100644 --- a/exception/vexceptionuniqueid.cpp +++ b/exception/vexceptionuniqueid.cpp @@ -1,21 +1,51 @@ +/************************************************************************ + ** + ** @file vexceptionuniqueid.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + #include "vexceptionuniqueid.h" -#include VExceptionUniqueId::VExceptionUniqueId(const QString &what, const QDomElement &domElement) - :VException(what), tagText(QString()), tagName(QString()), lineNumber(-1){ - Q_ASSERT_X(!domElement.isNull(), Q_FUNC_INFO, "domElement is null"); + :VException(what), tagText(QString()), tagName(QString()), lineNumber(-1) +{ + Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null"); QTextStream stream(&tagText); domElement.save(stream, 4); tagName = domElement.tagName(); lineNumber = domElement.lineNumber(); } -QString VExceptionUniqueId::ErrorMessage() const{ +QString VExceptionUniqueId::ErrorMessage() const +{ QString error = QString("ExceptionUniqueId: %1").arg(what); return error; } -QString VExceptionUniqueId::DetailedInformation() const{ +QString VExceptionUniqueId::DetailedInformation() const +{ QString detail = QString("tag: %1 in line %2\nFull tag:\n%3").arg(tagName).arg(lineNumber).arg(tagText); return detail; } diff --git a/exception/vexceptionuniqueid.h b/exception/vexceptionuniqueid.h index 1bf1760d4..2ca8b1be2 100644 --- a/exception/vexceptionuniqueid.h +++ b/exception/vexceptionuniqueid.h @@ -1,24 +1,52 @@ +/************************************************************************ + ** + ** @file vexceptionuniqueid.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + #ifndef VEXCEPTIONUNIQUEID_H #define VEXCEPTIONUNIQUEID_H #include "vexception.h" -#include -class VExceptionUniqueId : public VException{ +class VExceptionUniqueId : public VException +{ public: - VExceptionUniqueId(const QString &what, const QDomElement &domElement); - VExceptionUniqueId(const VExceptionUniqueId &e):VException(e), tagText(e.TagText()), - tagName(e.TagName()), lineNumber(e.LineNumber()){} - virtual ~VExceptionUniqueId() noexcept(true){} + VExceptionUniqueId(const QString &what, const QDomElement &domElement); + VExceptionUniqueId(const VExceptionUniqueId &e) + :VException(e), tagText(e.TagText()), tagName(e.TagName()), lineNumber(e.LineNumber()){} + virtual ~VExceptionUniqueId() Q_DECL_NOEXCEPT_EXPR(true){} virtual QString ErrorMessage() const; virtual QString DetailedInformation() const; - QString TagText() const {return tagText;} - QString TagName() const {return tagName;} - qint32 LineNumber() const {return lineNumber;} + inline QString TagText() const {return tagText;} + inline QString TagName() const {return tagName;} + inline qint32 LineNumber() const {return lineNumber;} protected: - QString tagText; - QString tagName; - qint32 lineNumber; + QString tagText; + QString tagName; + qint32 lineNumber; }; #endif // VEXCEPTIONUNIQUEID_H diff --git a/exception/vexceptionwrongparameterid.cpp b/exception/vexceptionwrongparameterid.cpp index 0da7ea21b..14f5ab8ef 100644 --- a/exception/vexceptionwrongparameterid.cpp +++ b/exception/vexceptionwrongparameterid.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vexceptionwrongparameterid.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,30 +24,29 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "vexceptionwrongparameterid.h" #include -VExceptionWrongParameterId::VExceptionWrongParameterId(const QString &what, const QDomElement &domElement): - VException(what), tagText(QString()), tagName(QString()), lineNumber(-1){ - Q_ASSERT_X(!domElement.isNull(), Q_FUNC_INFO, "domElement is null"); +VExceptionWrongParameterId::VExceptionWrongParameterId(const QString &what, const QDomElement &domElement) + :VException(what), tagText(QString()), tagName(QString()), lineNumber(-1) +{ + Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null"); QTextStream stream(&tagText); domElement.save(stream, 4); tagName = domElement.tagName(); lineNumber = domElement.lineNumber(); } -VExceptionWrongParameterId::VExceptionWrongParameterId(const VExceptionWrongParameterId &e):VException(e), - tagText(e.TagText()), tagName(e.TagName()), lineNumber(e.LineNumber()){ -} - -QString VExceptionWrongParameterId::ErrorMessage() const{ +QString VExceptionWrongParameterId::ErrorMessage() const +{ QString error = QString("ExceptionWrongParameterId: %1").arg(what); return error; } -QString VExceptionWrongParameterId::DetailedInformation() const{ +QString VExceptionWrongParameterId::DetailedInformation() const +{ QString detail = QString("tag: %1 in line %2\n%3").arg(tagName).arg(lineNumber).arg(tagText); return detail; } diff --git a/exception/vexceptionwrongparameterid.h b/exception/vexceptionwrongparameterid.h index 1b8e611f6..ab5d2f2ee 100644 --- a/exception/vexceptionwrongparameterid.h +++ b/exception/vexceptionwrongparameterid.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vexceptionwrongparameterid.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,29 +24,29 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef VEXCEPTIONWRONGPARAMETERID_H #define VEXCEPTIONWRONGPARAMETERID_H #include "vexception.h" -#include class VExceptionWrongParameterId : public VException { public: - VExceptionWrongParameterId(const QString &what, const QDomElement &domElement); - VExceptionWrongParameterId(const VExceptionWrongParameterId &e); - virtual ~VExceptionWrongParameterId() noexcept(true){} + VExceptionWrongParameterId(const QString &what, const QDomElement &domElement); + VExceptionWrongParameterId(const VExceptionWrongParameterId &e) + :VException(e), tagText(e.TagText()), tagName(e.TagName()), lineNumber(e.LineNumber()){} + virtual ~VExceptionWrongParameterId() Q_DECL_NOEXCEPT_EXPR(true){} virtual QString ErrorMessage() const; virtual QString DetailedInformation() const; - QString TagText() const {return tagText;} - QString TagName() const {return tagName;} - qint32 LineNumber() const {return lineNumber;} + inline QString TagText() const {return tagText;} + inline QString TagName() const {return tagName;} + inline qint32 LineNumber() const {return lineNumber;} protected: - QString tagText; - QString tagName; - qint32 lineNumber; + QString tagText; + QString tagName; + qint32 lineNumber; }; #endif // VEXCEPTIONWRONGPARAMETERID_H diff --git a/geometry/geometry.pri b/geometry/geometry.pri new file mode 100644 index 000000000..37d5100cc --- /dev/null +++ b/geometry/geometry.pri @@ -0,0 +1,15 @@ +HEADERS += \ + geometry/vsplinepoint.h \ + geometry/vsplinepath.h \ + geometry/vspline.h \ + geometry/vnodedetail.h \ + geometry/vdetail.h \ + geometry/varc.h + +SOURCES += \ + geometry/vsplinepoint.cpp \ + geometry/vsplinepath.cpp \ + geometry/vspline.cpp \ + geometry/vnodedetail.cpp \ + geometry/vdetail.cpp \ + geometry/varc.cpp diff --git a/geometry/varc.cpp b/geometry/varc.cpp index 214a39a51..771f59b1f 100644 --- a/geometry/varc.cpp +++ b/geometry/varc.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file varc.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,28 +24,33 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "varc.h" -#include +#include "../exception/vexception.h" -VArc::VArc () : f1(0), formulaF1(QString()), f2(0), formulaF2(QString()), radius(0), formulaRadius(QString()), - center(0), points(0), mode(Draw::Calculation), idObject(0){ -} +class QRectF; + +VArc::VArc () + : f1(0), formulaF1(QString()), f2(0), formulaF2(QString()), radius(0), formulaRadius(QString()), + center(0), points(QHash()), mode(Draw::Calculation), idObject(0), _name(QString()){} VArc::VArc (const QHash *points, qint64 center, qreal radius, QString formulaRadius, qreal f1, QString formulaF1, qreal f2, QString formulaF2, Draw::Draws mode, qint64 idObject) : f1(f1), formulaF1(formulaF1), f2(f2), formulaF2(formulaF2), radius(radius), formulaRadius(formulaRadius), - center(center), points(points), mode(mode), idObject(idObject){ + center(center), points(*points), mode(mode), idObject(idObject), _name(QString()) +{ + _name = QString ("Arc_%1_%2").arg(this->GetCenterVPoint().name()).arg(radius); } -VArc::VArc(const VArc &arc): f1(arc.GetF1()), formulaF1(arc.GetFormulaF1()), f2(arc.GetF2()), +VArc::VArc(const VArc &arc) + : f1(arc.GetF1()), formulaF1(arc.GetFormulaF1()), f2(arc.GetF2()), formulaF2(arc.GetFormulaF2()), radius(arc.GetRadius()), formulaRadius(arc.GetFormulaRadius()), center(arc.GetCenter()), points(arc.GetDataPoints()), mode(arc.getMode()), - idObject(arc.getIdObject()){ -} + idObject(arc.getIdObject()), _name(arc.name()){} -VArc &VArc::operator =(const VArc &arc){ +VArc &VArc::operator =(const VArc &arc) +{ this->points = arc.GetDataPoints(); this->f1 = arc.GetF1(); this->formulaF1 = arc.GetFormulaF1(); @@ -49,70 +61,52 @@ VArc &VArc::operator =(const VArc &arc){ this->center = arc.GetCenter(); this->mode = arc.getMode(); this->idObject = arc.getIdObject(); + this->_name = arc.name(); return *this; } -qreal VArc::GetF1() const{ - return f1; +QPointF VArc::GetCenterPoint() const +{ + return GetCenterVPoint().toQPointF(); } -QString VArc::GetFormulaF1() const{ - return formulaF1; -} - -qreal VArc::GetF2() const{ - return f2; -} - -QString VArc::GetFormulaF2() const{ - return formulaF2; -} - -qreal VArc::GetLength () const{ - return M_PI * radius/180 * (f2-f1); -} - -qreal VArc::GetRadius() const{ - return radius; -} - -QString VArc::GetFormulaRadius() const{ - return formulaRadius; -} - -qint64 VArc::GetCenter() const{ - return center; -} - -QPointF VArc::GetCenterPoint() const{ - if(points->contains(center)){ - return points->value(center).toQPointF(); - } else { - qCritical()<<"Не можу знайти id = "< *VArc::GetDataPoints() const{ +const QHash VArc::GetDataPoints() const +{ return points; } -QPainterPath VArc::GetPath() const{ +QPainterPath VArc::GetPath() const +{ QPainterPath Path; QPointF center = GetCenterPoint(); QRectF rect(center.x()-radius, center.y()-radius, radius*2, radius*2); @@ -122,91 +116,99 @@ QPainterPath VArc::GetPath() const{ return Path; } -qreal VArc::AngleArc() const{ - QLineF l1(0,0, 100, 100); +qreal VArc::AngleArc() const +{ + QLineF l1(0, 0, 100, 100); l1.setAngle(f1); - QLineF l2(0,0, 100, 100); + QLineF l2(0, 0, 100, 100); l2.setAngle(f2); return l1.angleTo(l2); } -qint32 VArc::NumberSplOfArc() const{ +qint32 VArc::NumberSplOfArc() const +{ qint32 angArc = static_cast (AngleArc ()); - switch( angArc ){ - case 0: - throw "Кут дуги не може бути 0 градусів."; - break; - case 90: - return 1; - case 180: - return 2; - case 270: - return 3; - case 360: - return 4; - default : - return static_cast (AngleArc ( ) / 90 + 1); + switch ( angArc ) + { + case 0: + { + QString error = QString(tr("Angle of arc can't be 0 degree.")); + throw VException(error); + } + case 90: + return 1; + case 180: + return 2; + case 270: + return 3; + case 360: + return 4; + default: + return static_cast (AngleArc ( ) / 90 + 1); } } -QVector VArc::GetPoints() const{ +QVector VArc::GetPoints() const +{ QVector points; qint32 numberSpl = NumberSplOfArc(); - for(qint32 i = 1; i <= numberSpl; ++i){ + for (qint32 i = 1; i <= numberSpl; ++i) + { points< VArc::SplOfArc(qint32 number) const{ +QVector VArc::SplOfArc(qint32 number) const +{ qint32 n = NumberSplOfArc (); - if( number > n ){ - throw "Дуга не складається з такої кількості сплайнів."; + if ( number > n ) + { + QString error = QString(tr("Arc have not this number of part.")); + throw VException(error); } qreal f1 = GetF1 (); qreal f2 = GetF2 (); qint32 i; - for ( i = 0; i < n; ++i ){ - if ( i == n - 1 ){ + for ( i = 0; i < n; ++i ) + { + if ( i == n - 1 ) + { f2 = GetF2 (); - } else { - if ( f1 + 90 > 360 ){ + } + else + { + if ( f1 + 90 > 360 ) + { f2 = f1 + 90 - 360; - } else { + } + else + { f2 = f1 + 90; } } qreal anglF1, anglF2; - if ( f1 + 90 > 360 ){ - anglF1 = f1 + 90 - 360 ; - } else { - anglF1 = f1 + 90 ; + if ( f1 + 90 > 360 ) + { + anglF1 = f1 + 90 - 360; } - if ( f2 - 90 < 0 ){ - anglF2 = 360 + f2 - 90 ; - } else { - anglF2 = f2 - 90 ; + else + { + anglF1 = f1 + 90; } - if ( i + 1 == number ){ + if ( f2 - 90 < 0 ) + { + anglF2 = 360 + f2 - 90; + } + else + { + anglF2 = f2 - 90; + } + if ( i + 1 == number ) + { f1 = f2; return VSpline::SplinePoints(GetP1 (), GetP2 (), anglF1, anglF2, 1., 1., 1.); } } return QVector(); } - -Draw::Draws VArc::getMode() const{ - return mode; -} - -void VArc::setMode(const Draw::Draws &value){ - mode = value; -} - -qint64 VArc::getIdObject() const{ - return idObject; -} - -void VArc::setIdObject(const qint64 &value){ - idObject = value; -} diff --git a/geometry/varc.h b/geometry/varc.h index 349083a44..5939e7bf4 100644 --- a/geometry/varc.h +++ b/geometry/varc.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file varc.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,22 +24,28 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef VARC_H #define VARC_H #include "vspline.h" +class QString; +class QLineF; +class QPainterPath; +class QPointF; /** * @brief VArc клас, що реалізує дугу. Дуга розраховується за годиниковою стрілкою. */ -class VArc{ +class VArc +{ + Q_DECLARE_TR_FUNCTIONS(VArc) public: /** * @brief VArc конструктор по замовчуванню. */ - VArc (); + VArc (); /** * @brief VArc конструктор. * @param center точка центру. @@ -40,88 +53,91 @@ public: * @param f1 початковий кут в градусах. * @param f2 кінцевий кут в градусах. */ - VArc (const QHash *points, qint64 center, qreal radius, QString formulaRadius, - qreal f1, QString formulaF1, qreal f2 , QString formulaF2, - Draw::Draws mode = Draw::Calculation, qint64 idObject = 0); - VArc(const VArc &arc); - VArc& operator= (const VArc &arc); + VArc (const QHash *points, qint64 center, qreal radius, QString formulaRadius, + qreal f1, QString formulaF1, qreal f2, QString formulaF2, + Draw::Draws mode = Draw::Calculation, qint64 idObject = 0); + VArc(const VArc &arc); + VArc& operator= (const VArc &arc); /** * @brief GetF1 повертає початковий кут дуги. * @return повертає кут в градусах. */ - QString GetFormulaF1 () const; - qreal GetF1 () const; + inline QString GetFormulaF1 () const {return formulaF1;} + inline qreal GetF1 () const {return f1;} /** * @brief GetF2 повертає кінцевий кут дуги. * @return повертає кут в градусах. */ - QString GetFormulaF2 () const;\ - qreal GetF2 () const; + inline QString GetFormulaF2 () const {return formulaF2;} + inline qreal GetF2 () const {return f2;} /** * @brief GetLength повертає довжину дуги. * @return повертає довжину дуги. */ - qreal GetLength () const; + inline qreal GetLength () const {return M_PI * radius/180 * (f2-f1);} /** * @brief GetRadius повертає радіус дуги. * @return повертає радіус дуги. */ - QString GetFormulaRadius () const; - qreal GetRadius () const; + inline QString GetFormulaRadius () const {return formulaRadius;} + inline qreal GetRadius () const {return radius;} /** * @brief GetCenter повертає точку центра дуги. * @return повертає точку центра дуги. */ - qint64 GetCenter () const; - QPointF GetCenterPoint() const; + inline qint64 GetCenter () const {return center;} + QPointF GetCenterPoint() const; + VPointF GetCenterVPoint() const; /** * @brief GetP1 повертає першу точку з якої починається дуга. * @return точку початку дуги. */ - QPointF GetP1 () const; + QPointF GetP1 () const; /** * @brief GetP2 повертає другу точку в якій закінчується дуга. * @return точку кінця дуги. */ - QPointF GetP2 () const; - const QHash *GetDataPoints() const; + QPointF GetP2 () const; + const QHash GetDataPoints() const; /** * @brief GetPath будує шлях по даній дузі. * @return повертає шлях. */ - QPainterPath GetPath() const; - qreal AngleArc()const; - qint32 NumberSplOfArc () const; - QVector GetPoints () const; - QVector SplOfArc( qint32 number ) const; - Draw::Draws getMode() const; - void setMode(const Draw::Draws &value); - qint64 getIdObject() const; - void setIdObject(const qint64 &value); - + QPainterPath GetPath() const; + qreal AngleArc() const; + qint32 NumberSplOfArc () const; + QVector GetPoints () const; + QVector SplOfArc( qint32 number ) const; + inline Draw::Draws getMode() const {return mode;} + inline void setMode(const Draw::Draws &value) {mode = value;} + inline qint64 getIdObject() const {return idObject;} + inline void setIdObject(const qint64 &value) {idObject = value;} + QString name() const {return _name;} + void setName(const QString &name) {_name = name;} private: /** * @brief f1 початковий кут в градусах */ - qreal f1; // початковий кут нахилу дуги (градуси) - QString formulaF1; + qreal f1; // початковий кут нахилу дуги (градуси) + QString formulaF1; /** * @brief f2 кінцевий кут в градусах */ - qreal f2; // кінцевий кут нахилу дуги (градуси) - QString formulaF2; + qreal f2; // кінцевий кут нахилу дуги (градуси) + QString formulaF2; /** * @brief radius радіус дуги. */ - qreal radius; - QString formulaRadius; + qreal radius; + QString formulaRadius; /** * @brief center центральна точка дуги. */ - qint64 center; - const QHash *points; - Draw::Draws mode; - qint64 idObject; + qint64 center; + QHash points; + Draw::Draws mode; + qint64 idObject; + QString _name; }; #endif // VARC_H diff --git a/geometry/vdetail.cpp b/geometry/vdetail.cpp index 509fa073d..a5453788c 100644 --- a/geometry/vdetail.cpp +++ b/geometry/vdetail.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vdetail.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,67 +24,60 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "vdetail.h" -VDetail::VDetail():nodes(QVector()),name(QString()), mx(0), my(0){ -} +VDetail::VDetail() + :nodes(QVector()), name(QString()), mx(0), my(0), supplement(true), closed(true), width(10){} -VDetail::VDetail(const QString &name, const QVector &nodes):nodes(QVector()), - name(name), mx(0), my(0){ +VDetail::VDetail(const QString &name, const QVector &nodes) + :nodes(QVector()), name(name), mx(0), my(0), supplement(true), closed(true), width(10) +{ this->nodes = nodes; } -void VDetail::append(const VNodeDetail &node){ - nodes.append(node); +VDetail::VDetail(const VDetail &detail) + :nodes(detail.getNodes()), name(detail.getName()), mx(detail.getMx()), my(detail.getMy()), + supplement(detail.getSupplement()), closed(detail.getClosed()), width(detail.getWidth()){} + +VDetail &VDetail::operator =(const VDetail &detail) +{ + nodes = detail.getNodes(); + name = detail.getName(); + mx = detail.getMx(); + my = detail.getMy(); + supplement = detail.getSupplement(); + closed = detail.getClosed(); + width = detail.getWidth(); + return *this; } -void VDetail::Clear(){ +void VDetail::Clear() +{ nodes.clear(); name.clear(); mx = 0; my = 0; + supplement = true; + closed = true; + width = 10; } -qint32 VDetail::CountNode() const{ - return nodes.size(); -} - -bool VDetail::Containes(const qint64 &id) const{ - for(qint32 i = 0; i < nodes.size(); ++i){ +bool VDetail::Containes(const qint64 &id) const +{ + for (qint32 i = 0; i < nodes.size(); ++i) + { VNodeDetail node = nodes[i]; - if(node.getId() == id){ + if (node.getId() == id) + { return true; } } return false; } -VNodeDetail &VDetail::operator [](int indx){ +VNodeDetail &VDetail::operator [](ptrdiff_t indx) +{ return nodes[indx]; } - -qreal VDetail::getMy() const{ - return my; -} - -void VDetail::setMy(const qreal &value){ - my = value; -} - -qreal VDetail::getMx() const{ - return mx; -} - -void VDetail::setMx(const qreal &value){ - mx = value; -} - -QString VDetail::getName() const{ - return name; -} - -void VDetail::setName(const QString &value){ - name = value; -} diff --git a/geometry/vdetail.h b/geometry/vdetail.h index 45cf841fb..2b366c547 100644 --- a/geometry/vdetail.h +++ b/geometry/vdetail.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vdetail.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,17 +24,15 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef VDETAIL_H #define VDETAIL_H #include "vnodedetail.h" -#include -#include -#include -namespace Detail { +namespace Detail +{ enum Contour { OpenContour, CloseContour }; Q_DECLARE_FLAGS(Contours, Contour) @@ -37,26 +42,40 @@ namespace Detail { Q_DECLARE_OPERATORS_FOR_FLAGS(Detail::Contours) Q_DECLARE_OPERATORS_FOR_FLAGS(Detail::Equidistants) -class VDetail{ +class VDetail +{ public: - VDetail(); - VDetail(const QString &name, const QVector &nodes); - void append(const VNodeDetail &node); - void Clear(); - qint32 CountNode() const; - bool Containes(const qint64 &id)const; - VNodeDetail & operator[](int indx); - QString getName() const; - void setName(const QString &value); - qreal getMx() const; - void setMx(const qreal &value); - qreal getMy() const; - void setMy(const qreal &value); + VDetail(); + VDetail(const QString &name, const QVector &nodes); + VDetail(const VDetail &detail); + VDetail &operator=(const VDetail &detail); + inline void append(const VNodeDetail &node) {nodes.append(node);} + void Clear(); + inline qint32 CountNode() const {return nodes.size();} + bool Containes(const qint64 &id)const; + VNodeDetail & operator[](ptrdiff_t indx); + inline QString getName() const {return name;} + inline void setName(const QString &value) {name = value;} + inline qreal getMx() const {return mx;} + inline void setMx(const qreal &value) {mx = value;} + inline qreal getMy() const {return my;} + inline void setMy(const qreal &value) {my = value;} + inline bool getSupplement() const {return supplement;} + inline void setSupplement(bool value) {supplement = value;} + inline bool getClosed() const {return closed;} + inline void setClosed(bool value) {closed = value;} + inline qreal getWidth() const {return width;} + inline void setWidth(const qreal &value) {width = value;} + inline QVector getNodes() const {return nodes;} + inline void setNodes(const QVector &value) {nodes = value;} private: QVector nodes; - QString name; - qreal mx; - qreal my; + QString name; + qreal mx; + qreal my; + bool supplement; + bool closed; + qreal width; }; #endif // VDETAIL_H diff --git a/geometry/vnodedetail.cpp b/geometry/vnodedetail.cpp index e1392e22e..b7b09a005 100644 --- a/geometry/vnodedetail.cpp +++ b/geometry/vnodedetail.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vnodedetail.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,50 +24,28 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "vnodedetail.h" -VNodeDetail::VNodeDetail():id(0), typeTool(Tool::NodePoint), mode(Draw::Calculation), - typeNode(NodeDetail::Contour){ -} +VNodeDetail::VNodeDetail() + :id(0), typeTool(Tool::NodePoint), mode(Draw::Modeling), typeNode(NodeDetail::Contour), mx(0), my(0){} -VNodeDetail::VNodeDetail(qint64 id, Tool::Tools typeTool, Draw::Draws mode, NodeDetail::NodeDetails typeNode):id(id), - typeTool(typeTool), mode(mode), typeNode(typeNode){ -} +VNodeDetail::VNodeDetail(qint64 id, Tool::Tools typeTool, Draw::Draws mode, NodeDetail::NodeDetails typeNode, + qreal mx, qreal my) + :id(id), typeTool(typeTool), mode(mode), typeNode(typeNode), mx(mx), my(my){} -VNodeDetail::VNodeDetail(const VNodeDetail &node):id(node.getId()), typeTool(node.getTypeTool()), - mode(node.getMode()), typeNode(node.getTypeNode()){ -} +VNodeDetail::VNodeDetail(const VNodeDetail &node) + :id(node.getId()), typeTool(node.getTypeTool()), mode(node.getMode()), typeNode(node.getTypeNode()), + mx(node.getMx()), my(node.getMy()){} -Tool::Tools VNodeDetail::getTypeTool() const{ - return typeTool; -} - -void VNodeDetail::setTypeTool(const Tool::Tools &value){ - typeTool = value; -} - -qint64 VNodeDetail::getId() const{ - return id; -} - -void VNodeDetail::setId(const qint64 &value){ - id = value; -} - -Draw::Draws VNodeDetail::getMode() const{ - return mode; -} - -void VNodeDetail::setMode(const Draw::Draws &value){ - mode = value; -} - -NodeDetail::NodeDetails VNodeDetail::getTypeNode() const{ - return typeNode; -} - -void VNodeDetail::setTypeNode(const NodeDetail::NodeDetails &value){ - typeNode = value; +VNodeDetail &VNodeDetail::operator =(const VNodeDetail &node) +{ + id = node.getId(); + typeTool = node.getTypeTool(); + mode = node.getMode(); + typeNode = node.getTypeNode(); + mx = node.getMx(); + my = node.getMy(); + return *this; } diff --git a/geometry/vnodedetail.h b/geometry/vnodedetail.h index 71763a677..799a355aa 100644 --- a/geometry/vnodedetail.h +++ b/geometry/vnodedetail.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vnodedetail.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,15 +24,16 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef VNODEDETAIL_H #define VNODEDETAIL_H #include -#include "options.h" +#include "../options.h" -namespace NodeDetail { +namespace NodeDetail +{ enum NodeDetail { Contour, Modeling }; Q_DECLARE_FLAGS(NodeDetails, NodeDetail) } @@ -34,23 +42,30 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(NodeDetail::NodeDetails) class VNodeDetail { public: - VNodeDetail(); - VNodeDetail(qint64 id, Tool::Tools typeTool, Draw::Draws mode, NodeDetail::NodeDetails typeNode); - VNodeDetail(const VNodeDetail &node); - qint64 getId() const; - void setId(const qint64 &value); - Tool::Tools getTypeTool() const; - void setTypeTool(const Tool::Tools &value); - Draw::Draws getMode() const; - void setMode(const Draw::Draws &value); - NodeDetail::NodeDetails getTypeNode() const; - void setTypeNode(const NodeDetail::NodeDetails &value); - + VNodeDetail(); + VNodeDetail(qint64 id, Tool::Tools typeTool, Draw::Draws mode, NodeDetail::NodeDetails typeNode, + qreal mx = 0, qreal my = 0); + VNodeDetail(const VNodeDetail &node); + VNodeDetail &operator=(const VNodeDetail &node); + inline qint64 getId() const {return id;} + inline void setId(const qint64 &value) {id = value;} + inline Tool::Tools getTypeTool() const {return typeTool;} + inline void setTypeTool(const Tool::Tools &value) {typeTool = value;} + inline Draw::Draws getMode() const {return mode;} + inline void setMode(const Draw::Draws &value) {mode = value;} + inline NodeDetail::NodeDetails getTypeNode() const {return typeNode;} + inline void setTypeNode(const NodeDetail::NodeDetails &value) {typeNode = value;} + inline qreal getMx() const {return mx;} + inline void setMx(const qreal &value) {mx = value;} + inline qreal getMy() const {return my;} + inline void setMy(const qreal &value) {my = value;} private: - qint64 id; - Tool::Tools typeTool; - Draw::Draws mode; + qint64 id; + Tool::Tools typeTool; + Draw::Draws mode; NodeDetail::NodeDetails typeNode; + qreal mx; + qreal my; }; Q_DECLARE_METATYPE(VNodeDetail) diff --git a/geometry/vspline.cpp b/geometry/vspline.cpp index ee19f4a18..572ce9342 100644 --- a/geometry/vspline.cpp +++ b/geometry/vspline.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vspline.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,36 +24,40 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "vspline.h" -#include -VSpline::VSpline():p1(0), p2(QPointF()), p3(QPointF()), p4(0), angle1(0), angle2(0), kAsm1(1), kAsm2(1), - kCurve(1), points(0), mode(Draw::Calculation), idObject(0){ -} +VSpline::VSpline() + :p1(0), p2(QPointF()), p3(QPointF()), p4(0), angle1(0), angle2(0), kAsm1(1), kAsm2(1), kCurve(1), + points(QHash()), mode(Draw::Calculation), idObject(0), _name(QString()){} -VSpline::VSpline ( const VSpline & spline ):p1(spline.GetP1 ()), p2(spline.GetP2 ()), p3(spline.GetP3 ()), - p4(spline.GetP4 ()), angle1(spline.GetAngle1 ()), angle2(spline.GetAngle2 ()), kAsm1(spline.GetKasm1()), - kAsm2(spline.GetKasm2()), kCurve(spline.GetKcurve()), points(spline.GetDataPoints()), - mode(spline.getMode()), idObject(spline.getIdObject()){ -} +VSpline::VSpline ( const VSpline & spline ) + :p1(spline.GetP1 ()), p2(spline.GetP2 ()), p3(spline.GetP3 ()), p4(spline.GetP4 ()), angle1(spline.GetAngle1 ()), + angle2(spline.GetAngle2 ()), kAsm1(spline.GetKasm1()), kAsm2(spline.GetKasm2()), kCurve(spline.GetKcurve()), + points(spline.GetDataPoints()), mode(spline.getMode()), idObject(spline.getIdObject()), _name(spline.name()){} VSpline::VSpline (const QHash *points, qint64 p1, qint64 p4, qreal angle1, qreal angle2, - qreal kAsm1, qreal kAsm2 , qreal kCurve, Draw::Draws mode, qint64 idObject):p1(p1), p2(QPointF()), p3(QPointF()), - p4(p4), angle1(angle1), angle2(angle2), kAsm1(kAsm1), kAsm2(kAsm2), kCurve(kCurve), points(points), - mode(mode), idObject(idObject){ + qreal kAsm1, qreal kAsm2, qreal kCurve, Draw::Draws mode, qint64 idObject) + :p1(p1), p2(QPointF()), p3(QPointF()), p4(p4), angle1(angle1), angle2(angle2), kAsm1(kAsm1), kAsm2(kAsm2), + kCurve(kCurve), points(*points), mode(mode), idObject(idObject), _name(QString()) +{ + _name = QString("Spl_%1_%2").arg(this->GetPointP1().name(), this->GetPointP4().name()); ModifiSpl ( p1, p4, angle1, angle2, kAsm1, kAsm2, kCurve ); } VSpline::VSpline (const QHash *points, qint64 p1, QPointF p2, QPointF p3, qint64 p4, - qreal kCurve, Draw::Draws mode, qint64 idObject):p1(p1), p2(p2), p3(p3), p4(p4), angle1(0), - angle2(0), kAsm1(1), kAsm2(1), kCurve(1), points(points), mode(mode), idObject(idObject){ + qreal kCurve, Draw::Draws mode, qint64 idObject) + :p1(p1), p2(p2), p3(p3), p4(p4), angle1(0), angle2(0), kAsm1(1), kAsm2(1), kCurve(1), points(*points), mode(mode), + idObject(idObject), _name(QString()) +{ + _name = QString("Spl_%1_%2").arg(this->GetPointP1().name(), this->GetPointP4().name()); ModifiSpl ( p1, p2, p3, p4, kCurve); } void VSpline::ModifiSpl ( qint64 p1, qint64 p4, qreal angle1, qreal angle2, - qreal kAsm1, qreal kAsm2, qreal kCurve){ + qreal kAsm1, qreal kAsm2, qreal kCurve) +{ this->p1 = p1; this->p4 = p4; this->angle1 = angle1; @@ -63,7 +74,7 @@ void VSpline::ModifiSpl ( qint64 p1, qint64 p4, qreal angle1, qreal angle2, // } QPointF point1 = GetPointP1().toQPointF(); QPointF point4 = GetPointP4().toQPointF(); - radius = QLineF(QPointF(point1.x(), point4.y()),point4).length(); + radius = QLineF(QPointF(point1.x(), point4.y()), point4).length(); // radius = QLineF(GetPointP1(), GetPointP4()).length() / 2 / sin( angle * M_PI / 180.0 ); L = kCurve * radius * 4 / 3 * tan( angle * M_PI / 180.0 / 4 ); QLineF p1p2(GetPointP1().x(), GetPointP1().y(), GetPointP1().x() + L * kAsm1, GetPointP1().y()); @@ -74,7 +85,8 @@ void VSpline::ModifiSpl ( qint64 p1, qint64 p4, qreal angle1, qreal angle2, this->p3 = p4p3.p2(); } -void VSpline::ModifiSpl (qint64 p1, QPointF p2, QPointF p3, qint64 p4, qreal kCurve){ +void VSpline::ModifiSpl (const qint64 &p1, const QPointF &p2, const QPointF &p3, const qint64 &p4, const qreal &kCurve) +{ this->p1 = p1; this->p2 = p2; this->p3 = p3; @@ -91,7 +103,7 @@ void VSpline::ModifiSpl (qint64 p1, QPointF p2, QPointF p3, qint64 p4, qreal kCu // } QPointF point1 = GetPointP1().toQPointF(); QPointF point4 = GetPointP4().toQPointF(); - radius = QLineF(QPointF(point1.x(), point4.y()),point4).length(); + radius = QLineF(QPointF(point1.x(), point4.y()), point4).length(); // radius = QLineF(GetPointP1(), GetPointP4()).length() / 2 / sin( angle * M_PI / 180.0 ); L = kCurve * radius * 4 / 3 * tan( angle * M_PI / 180.0 / 4 ); @@ -124,77 +136,48 @@ void VSpline::ModifiSpl (qint64 p1, QPointF p2, QPointF p3, qint64 p4, qreal kCu // p4 = QPointF(p4.x()+mx, p4.y()+my); //} -qint64 VSpline::GetP1 () const{ - return p1; -} - -VPointF VSpline::GetPointP1() const{ - if(points->contains(p1)){ - return points->value(p1); - } else { +VPointF VSpline::GetPointP1() const +{ + if (points.contains(p1)) + { + return points.value(p1); + } + else + { qCritical()<<"Не можу знайти id = "<contains(p4)){ - return points->value(p4); - } else { +VPointF VSpline::GetPointP4() const +{ + if (points.contains(p4)) + { + return points.value(p4); + } + else + { qCritical()<<"Не можу знайти id = "<p2, this->p3, GetPointP4().toQPointF()); } -QString VSpline::GetName() const{ +QString VSpline::GetName() const +{ VPointF first = GetPointP1(); VPointF second = GetPointP4(); return QString("Spl_%1_%2").arg(first.name(), second.name()); } -qreal VSpline::GetKasm1() const{ - return kAsm1; -} - -qreal VSpline::GetKasm2() const{ - return kAsm2; -} - -qreal VSpline::GetKcurve() const{ - return kCurve; -} - -const QHash *VSpline::GetDataPoints() const{ - return points; -} - -QLineF::IntersectType VSpline::CrossingSplLine ( const QLineF &line, QPointF *intersectionPoint ) const{ +QLineF::IntersectType VSpline::CrossingSplLine ( const QLineF &line, QPointF *intersectionPoint ) const +{ QVector px; QVector py; px.append ( GetPointP1 ().x () ); @@ -209,10 +192,12 @@ QLineF::IntersectType VSpline::CrossingSplLine ( const QLineF &line, QPointF *in qint32 i = 0; QPointF crosPoint; QLineF::IntersectType type = QLineF::NoIntersection; - for ( i = 0; i < px.count()-1; ++i ){ + for ( i = 0; i < px.count()-1; ++i ) + { type = line.intersect(QLineF ( QPointF ( px[i], py[i] ), QPointF ( px[i+1], py[i+1] )), &crosPoint); - if ( type == QLineF::BoundedIntersection ){ + if ( type == QLineF::BoundedIntersection ) + { *intersectionPoint = crosPoint; return type; } @@ -277,7 +262,8 @@ QLineF::IntersectType VSpline::CrossingSplLine ( const QLineF &line, QPointF *in // } //} -QVector VSpline::GetPoints () const{ +QVector VSpline::GetPoints () const +{ return GetPoints(GetPointP1().toQPointF(), p2, p3, GetPointP4().toQPointF()); // QLineF line1(points.at(0).toPoint(), points.at(1).toPoint()); // line1.setLength(500); @@ -301,7 +287,8 @@ QVector VSpline::GetPoints () const{ // } } -QVector VSpline::GetPoints (QPointF p1, QPointF p2, QPointF p3, QPointF p4){ +QVector VSpline::GetPoints (const QPointF &p1, const QPointF &p2, const QPointF &p3, const QPointF &p4) +{ QVector pvector; QVector x; QVector y; @@ -313,36 +300,20 @@ QVector VSpline::GetPoints (QPointF p1, QPointF p2, QPointF p3, QPointF p3.x (), p3.y (), p4.x (), p4.y (), 0, wx, wy ); x.append ( p4.x () ); y.append ( p4.y () ); - for ( qint32 i = 0; i < x.count(); ++i ){ + for ( qint32 i = 0; i < x.count(); ++i ) + { pvector.append( QPointF ( x[i], y[i] ) ); } return pvector; } -qreal VSpline::LengthBezier ( QPointF p1, QPointF p2, QPointF p3, QPointF p4 ) const{ - /*QVector px; - QVector py; - QVector& wpx = px; - QVector& wpy = py; - px.append ( p1.x () ); - py.append ( p1.y () ); - PointBezier_r ( p1.x (), p1.y (), p2.x (), p2.y (), - p3.x (), p3.y (), p4.x (), p4.y (), 0, wpx, wpy); - px.append ( p4.x () ); - py.append ( p4.y () ); - qint32 i = 0; - qreal length = 0.0; - * - * Наприклад маємо 10 точок. Від 0 до 9 і останню точку не опрацьовуємо. - * Тому від 0 до 8(<10-1). - * - for ( i = 0; i < px.count() - 1; ++i ){ - length += QLineF ( QPointF ( px[i], py[i] ), QPointF ( px[i+1], py[i+1] ) ).length (); - }*/ +qreal VSpline::LengthBezier ( const QPointF &p1, const QPointF &p2, const QPointF &p3, const QPointF &p4 ) const +{ QPainterPath splinePath; QVector points = GetPoints (p1, p2, p3, p4); splinePath.moveTo(points[0]); - for (qint32 i = 1; i < points.count(); ++i){ + for (qint32 i = 1; i < points.count(); ++i) + { splinePath.lineTo(points[i]); } return splinePath.length(); @@ -350,9 +321,10 @@ qreal VSpline::LengthBezier ( QPointF p1, QPointF p2, QPointF p3, QPointF p4 ) c void VSpline::PointBezier_r ( qreal x1, qreal y1, qreal x2, qreal y2, qreal x3, qreal y3, qreal x4, qreal y4, - qint16 level, QVector &px, QVector &py){ - const double curve_collinearity_epsilon = 1e-30; - const double curve_angle_tolerance_epsilon = 0.01; + qint16 level, QVector &px, QVector &py) +{ + const double curve_collinearity_epsilon = 1e-30; + const double curve_angle_tolerance_epsilon = 0.01; const double m_angle_tolerance = 0.0; enum curve_recursion_limit_e { curve_recursion_limit = 32 }; const double m_cusp_limit = 0.0; @@ -362,7 +334,7 @@ void VSpline::PointBezier_r ( qreal x1, qreal y1, qreal x2, qreal y2, m_distance_tolerance_square = 0.5 / m_approximation_scale; m_distance_tolerance_square *= m_distance_tolerance_square; - if(level > curve_recursion_limit) + if (level > curve_recursion_limit) { return; } @@ -388,221 +360,246 @@ void VSpline::PointBezier_r ( qreal x1, qreal y1, qreal x2, qreal y2, double dx = x4-x1; double dy = y4-y1; - double d2 = fabs(((x2 - x4) * dy - (y2 - y4) * dx)); - double d3 = fabs(((x3 - x4) * dy - (y3 - y4) * dx)); + double d2 = fabs((x2 - x4) * dy - (y2 - y4) * dx); + double d3 = fabs((x3 - x4) * dy - (y3 - y4) * dx); double da1, da2, k; - switch((static_cast(d2 > curve_collinearity_epsilon) << 1) + - static_cast(d3 > curve_collinearity_epsilon)) + switch ((static_cast(d2 > curve_collinearity_epsilon) << 1) + + static_cast(d3 > curve_collinearity_epsilon)) { - case 0: - // All collinear OR p1==p4 - //---------------------- - k = dx*dx + dy*dy; - if(k == 0) - { - d2 = CalcSqDistance(x1, y1, x2, y2); - d3 = CalcSqDistance(x4, y4, x3, y3); - } - else - { - k = 1 / k; - da1 = x2 - x1; - da2 = y2 - y1; - d2 = k * (da1*dx + da2*dy); - da1 = x3 - x1; - da2 = y3 - y1; - d3 = k * (da1*dx + da2*dy); - if(d2 > 0 && d2 < 1 && d3 > 0 && d3 < 1) - { - // Simple collinear case, 1---2---3---4 - // We can leave just two endpoints - return; - } - if(d2 <= 0) - d2 = CalcSqDistance(x2, y2, x1, y1); - else if(d2 >= 1) - d2 = CalcSqDistance(x2, y2, x4, y4); - else - d2 = CalcSqDistance(x2, y2, x1 + d2*dx, y1 + d2*dy); - - if(d3 <= 0) - d3 = CalcSqDistance(x3, y3, x1, y1); - else if(d3 >= 1) - d3 = CalcSqDistance(x3, y3, x4, y4); - else - d3 = CalcSqDistance(x3, y3, x1 + d3*dx, y1 + d3*dy); - } - if(d2 > d3) - { - if(d2 < m_distance_tolerance_square) - { - - px.append(x2); - py.append(y2); - //m_points.add(point_d(x2, y2)); - return; - } - } - else - { - if(d3 < m_distance_tolerance_square) - { - - px.append(x3); - py.append(y3); - //m_points.add(point_d(x3, y3)); - return; - } - } - break; - case 1: - // p1,p2,p4 are collinear, p3 is significant - //---------------------- - if(d3 * d3 <= m_distance_tolerance_square * (dx*dx + dy*dy)) - { - if(m_angle_tolerance < curve_angle_tolerance_epsilon) - { - - px.append(x23); - py.append(y23); - //m_points.add(point_d(x23, y23)); - return; - } - - // Angle Condition + case 0: + // All collinear OR p1==p4 //---------------------- - da1 = fabs(atan2(y4 - y3, x4 - x3) - atan2(y3 - y2, x3 - x2)); - if(da1 >= M_PI) - da1 = 2*M_PI - da1; - - if(da1 < m_angle_tolerance) + k = dx*dx + dy*dy; + if (k < 0.000000001) { - - px.append(x2); - py.append(y2); - - px.append(x3); - py.append(y3); - //m_points.add(point_d(x2, y2)); - //m_points.add(point_d(x3, y3)); - return; + d2 = CalcSqDistance(x1, y1, x2, y2); + d3 = CalcSqDistance(x4, y4, x3, y3); } - - if(m_cusp_limit != 0.0) + else { - if(da1 > m_cusp_limit) + k = 1 / k; + da1 = x2 - x1; + da2 = y2 - y1; + d2 = k * (da1*dx + da2*dy); + da1 = x3 - x1; + da2 = y3 - y1; + d3 = k * (da1*dx + da2*dy); + if (d2 > 0 && d2 < 1 && d3 > 0 && d3 < 1) { - + // Simple collinear case, 1---2---3---4 + // We can leave just two endpoints + return; + } + if (d2 <= 0) + { + d2 = CalcSqDistance(x2, y2, x1, y1); + } + else if (d2 >= 1) + { + d2 = CalcSqDistance(x2, y2, x4, y4); + } + else + { + d2 = CalcSqDistance(x2, y2, x1 + d2*dx, y1 + d2*dy); + } + + if (d3 <= 0) + { + d3 = CalcSqDistance(x3, y3, x1, y1); + } + else if (d3 >= 1) + { + d3 = CalcSqDistance(x3, y3, x4, y4); + } + else + { + d3 = CalcSqDistance(x3, y3, x1 + d3*dx, y1 + d3*dy); + } + } + if (d2 > d3) + { + if (d2 < m_distance_tolerance_square) + { + + px.append(x2); + py.append(y2); + //m_points.add(point_d(x2, y2)); + return; + } + } + else + { + if (d3 < m_distance_tolerance_square) + { + px.append(x3); py.append(y3); //m_points.add(point_d(x3, y3)); return; } } - } - break; - - case 2: - // p1,p3,p4 are collinear, p2 is significant - //---------------------- - if(d2 * d2 <= m_distance_tolerance_square * (dx*dx + dy*dy)) - { - if(m_angle_tolerance < curve_angle_tolerance_epsilon) - { - - px.append(x23); - py.append(y23); - //m_points.add(point_d(x23, y23)); - return; - } - - // Angle Condition + break; + case 1: + // p1,p2,p4 are collinear, p3 is significant //---------------------- - da1 = fabs(atan2(y3 - y2, x3 - x2) - atan2(y2 - y1, x2 - x1)); - if(da1 >= M_PI) da1 = 2*M_PI - da1; - - if(da1 < m_angle_tolerance) + if (d3 * d3 <= m_distance_tolerance_square * (dx*dx + dy*dy)) { - - px.append(x2); - py.append(y2); - - px.append(x3); - py.append(y3); - //m_points.add(point_d(x2, y2)); - //m_points.add(point_d(x3, y3)); - return; - } - - if(m_cusp_limit != 0.0) - { - if(da1 > m_cusp_limit) + if (m_angle_tolerance < curve_angle_tolerance_epsilon) { - px.append(x2); - py.append(y2); - - //m_points.add(point_d(x2, y2)); + + px.append(x23); + py.append(y23); + //m_points.add(point_d(x23, y23)); return; } - } - } - break; - - case 3: - // Regular case - //----------------- - if((d2 + d3)*(d2 + d3) <= m_distance_tolerance_square * (dx*dx + dy*dy)) - { - // If the curvature doesn't exceed the distance_tolerance value - // we tend to finish subdivisions. - //---------------------- - if(m_angle_tolerance < curve_angle_tolerance_epsilon) - { - - px.append(x23); - py.append(y23); - //m_points.add(point_d(x23, y23)); - return; - } - - // Angle & Cusp Condition - //---------------------- - k = atan2(y3 - y2, x3 - x2); - da1 = fabs(k - atan2(y2 - y1, x2 - x1)); - da2 = fabs(atan2(y4 - y3, x4 - x3) - k); - if(da1 >= M_PI) da1 = 2*M_PI - da1; - if(da2 >= M_PI) da2 = 2*M_PI - da2; - - if(da1 + da2 < m_angle_tolerance) - { - // Finally we can stop the recursion + + // Angle Condition //---------------------- - - px.append(x23); - py.append(y23); - //m_points.add(point_d(x23, y23)); - return; - } - - if(m_cusp_limit != 0.0) - { - if(da1 > m_cusp_limit) + da1 = fabs(atan2(y4 - y3, x4 - x3) - atan2(y3 - y2, x3 - x2)); + if (da1 >= M_PI) { + da1 = 2*M_PI - da1; + } + + if (da1 < m_angle_tolerance) + { + px.append(x2); py.append(y2); - return; - } - - if(da2 > m_cusp_limit) - { + px.append(x3); py.append(y3); + //m_points.add(point_d(x2, y2)); + //m_points.add(point_d(x3, y3)); return; } + + if (m_cusp_limit > 0.0 || m_cusp_limit < 0.0) + { + if (da1 > m_cusp_limit) + { + + px.append(x3); + py.append(y3); + //m_points.add(point_d(x3, y3)); + return; + } + } } - } - break; + break; + + case 2: + // p1,p3,p4 are collinear, p2 is significant + //---------------------- + if (d2 * d2 <= m_distance_tolerance_square * (dx*dx + dy*dy)) + { + if (m_angle_tolerance < curve_angle_tolerance_epsilon) + { + + px.append(x23); + py.append(y23); + //m_points.add(point_d(x23, y23)); + return; + } + + // Angle Condition + //---------------------- + da1 = fabs(atan2(y3 - y2, x3 - x2) - atan2(y2 - y1, x2 - x1)); + if (da1 >= M_PI) + { + da1 = 2*M_PI - da1; + } + + if (da1 < m_angle_tolerance) + { + + px.append(x2); + py.append(y2); + + px.append(x3); + py.append(y3); + //m_points.add(point_d(x2, y2)); + //m_points.add(point_d(x3, y3)); + return; + } + + if (m_cusp_limit > 0.0 || m_cusp_limit < 0.0) + { + if (da1 > m_cusp_limit) + { + px.append(x2); + py.append(y2); + + //m_points.add(point_d(x2, y2)); + return; + } + } + } + break; + + case 3: + // Regular case + //----------------- + if ((d2 + d3)*(d2 + d3) <= m_distance_tolerance_square * (dx*dx + dy*dy)) + { + // If the curvature doesn't exceed the distance_tolerance value + // we tend to finish subdivisions. + //---------------------- + if (m_angle_tolerance < curve_angle_tolerance_epsilon) + { + + px.append(x23); + py.append(y23); + //m_points.add(point_d(x23, y23)); + return; + } + + // Angle & Cusp Condition + //---------------------- + k = atan2(y3 - y2, x3 - x2); + da1 = fabs(k - atan2(y2 - y1, x2 - x1)); + da2 = fabs(atan2(y4 - y3, x4 - x3) - k); + if (da1 >= M_PI) + { + da1 = 2*M_PI - da1; + } + if (da2 >= M_PI) + { + da2 = 2*M_PI - da2; + } + + if (da1 + da2 < m_angle_tolerance) + { + // Finally we can stop the recursion + //---------------------- + + px.append(x23); + py.append(y23); + //m_points.add(point_d(x23, y23)); + return; + } + + if (m_cusp_limit > 0.0 || m_cusp_limit < 0.0) + { + if (da1 > m_cusp_limit) + { + px.append(x2); + py.append(y2); + return; + } + + if (da2 > m_cusp_limit) + { + px.append(x3); + py.append(y3); + return; + } + } + } + break; + default: + break; } // Continue subdivision @@ -611,24 +608,33 @@ void VSpline::PointBezier_r ( qreal x1, qreal y1, qreal x2, qreal y2, PointBezier_r(x1234, y1234, x234, y234, x34, y34, x4, y4, static_cast(level + 1), px, py); } -qreal VSpline::CalcSqDistance (qreal x1, qreal y1, qreal x2, qreal y2){ +qreal VSpline::CalcSqDistance (qreal x1, qreal y1, qreal x2, qreal y2) +{ qreal dx = x2 - x1; qreal dy = y2 - y1; return dx * dx + dy * dy; } -QPainterPath VSpline::GetPath() const{ +QPainterPath VSpline::GetPath() const +{ QPainterPath splinePath; QVector points = GetPoints (); - splinePath.moveTo(points[0]); - for (qint32 i = 1; i < points.count(); ++i){ - splinePath.lineTo(points[i]); + if (points.count() >= 2) + { + for (qint32 i = 0; i < points.count()-1; ++i) + { + splinePath.moveTo(points[i]); + splinePath.lineTo(points[i+1]); + } + } + else + { + qWarning()<<"points.count() < 2"<(malloc(3*sizeof(qreal))); // P1 = curve_coord1; // P2 = curve_coord2; // P3 = curve_coord3; // P4 = curve_coord4; // Bt = point_coord; - +// // a = -P1 + 3*P2 - 3*P3 + P4; // b = 3*P1 - 6*P2 + 3*P3; // c = -3*P1 + 3*P2; // d = -Bt + P1; - +// // if(Cubic(t, b/a, c/a, d/a) == 3){ // ret_t = t[2]; // } else { @@ -707,7 +713,7 @@ qint32 VSpline::Cubic(qreal *x, qreal a, qreal b, qreal c){ // * Повертається три значення, але експереминтально знайдено що шукане // * значення знаходиться в третьому. // */ - +// // free(t); // if(ret_t<0 || ret_t>1){ // qDebug()<<"Неправильне значення параметра. фунція calc_t"; @@ -731,7 +737,7 @@ qint32 VSpline::Cubic(qreal *x, qreal a, qreal b, qreal c){ // else // return t_y; //} - +// //void VSpline::Mirror(const QPointF Pmirror){ // QPointF P1 = p1; // P1 = QPointF(P1.x() - Pmirror.x(), P1.y() - Pmirror.y()); @@ -752,20 +758,13 @@ qint32 VSpline::Cubic(qreal *x, qreal a, qreal b, qreal c){ // this->ModifiSpl(P1, P2, P3, P4); //} -Draw::Draws VSpline::getMode() const{ - return mode; -} - -void VSpline::setMode(const Draw::Draws &value){ - mode = value; -} - -QVector VSpline::SplinePoints(QPointF p1, QPointF p4, qreal angle1, qreal angle2, qreal kAsm1, - qreal kAsm2, qreal kCurve){ +QVector VSpline::SplinePoints(const QPointF &p1, const QPointF &p4, qreal angle1, qreal angle2, qreal kAsm1, + qreal kAsm2, qreal kCurve) +{ QLineF p1pX(p1.x(), p1.y(), p1.x() + 100, p1.y()); p1pX.setAngle( angle1 ); qreal L = 0, radius = 0, angle = 90; - radius = QLineF(QPointF(p1.x(), p4.y()),p4).length(); + radius = QLineF(QPointF(p1.x(), p4.y()), p4).length(); L = kCurve * radius * 4 / 3 * tan( angle * M_PI / 180.0 / 4 ); QLineF p1p2(p1.x(), p1.y(), p1.x() + L * kAsm1, p1.y()); p1p2.setAngle(angle1); @@ -776,15 +775,8 @@ QVector VSpline::SplinePoints(QPointF p1, QPointF p4, qreal angle1, qre return GetPoints(p1, p2, p3, p4); } -qint64 VSpline::getIdObject() const{ - return idObject; -} - -void VSpline::setIdObject(const qint64 &value){ - idObject = value; -} - -VSpline &VSpline::operator =(const VSpline &spline){ +VSpline &VSpline::operator =(const VSpline &spline) +{ this->p1 = spline.GetP1 (); this->p2 = spline.GetP2 (); this->p3 = spline.GetP3 (); @@ -797,5 +789,6 @@ VSpline &VSpline::operator =(const VSpline &spline){ this->points = spline.GetDataPoints(); this->mode = spline.getMode(); this->idObject = spline.getIdObject(); + this->_name = spline.name(); return *this; } diff --git a/geometry/vspline.h b/geometry/vspline.h index 79ee52fe4..644ff709d 100644 --- a/geometry/vspline.h +++ b/geometry/vspline.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vspline.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,29 +24,29 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef VSPLINE_H #define VSPLINE_H -#define M_2PI 6.28318530717958647692528676655900576 +#include "../container/vpointf.h" -#include -#include -#include -#include "container/vpointf.h" +class QString; + +#define M_2PI 6.28318530717958647692528676655900576 /** * @brief VSpline клас, що реалізує сплайн. */ -class VSpline{ +class VSpline +{ public: - VSpline(); + VSpline(); /** * @brief VSpline конструктор. * @param spline сплайн з якого копіюємо. */ - VSpline (const VSpline &spline ); + VSpline (const VSpline &spline ); /** * @brief VSpline конструктор. * @param p1 початкова точка сплайна. @@ -50,9 +57,9 @@ public: * @param kAsm1 коефіцієнт довжини першої напрямної. * @param kAsm2 коефіцієнт довжини другої напрямної. */ - VSpline (const QHash *points, qint64 p1, qint64 p4, qreal angle1, - qreal angle2, qreal kAsm1, qreal kAsm2, qreal kCurve, - Draw::Draws mode = Draw::Calculation, qint64 idObject = 0); + VSpline (const QHash *points, qint64 p1, qint64 p4, qreal angle1, qreal angle2, + qreal kAsm1, qreal kAsm2, qreal kCurve, Draw::Draws mode = Draw::Calculation, + qint64 idObject = 0); /** * @brief VSpline конструктор. * @param p1 початкова точка сплайну. @@ -60,9 +67,8 @@ public: * @param p3 друга контролююча точка сплайну. * @param p4 кінцева точка сплайну. */ - VSpline (const QHash *points, qint64 p1, QPointF p2, QPointF p3, - qint64 p4, qreal kCurve, Draw::Draws mode = Draw::Calculation, - qint64 idObject = 0); + VSpline (const QHash *points, qint64 p1, QPointF p2, QPointF p3, qint64 p4, + qreal kCurve, Draw::Draws mode = Draw::Calculation, qint64 idObject = 0); /** * @brief ModifiSpl модифікує сплайн. * @param p1 початкова точка сплайну. @@ -73,7 +79,7 @@ public: * @param kAsm1 коефіцієнт довжини першої напрямної. * @param kAsm2 коефіцієнт довжини другої напрямної. */ - void ModifiSpl ( qint64 p1, qint64 p4, qreal angle1, qreal angle2, qreal kAsm1, qreal kAsm2, + void ModifiSpl ( qint64 p1, qint64 p4, qreal angle1, qreal angle2, qreal kAsm1, qreal kAsm2, qreal kCurve); /** * @brief ModifiSpl модифікує сплайн. @@ -82,61 +88,62 @@ public: * @param p3 друга контролююча точка сплайну. * @param p4 кінцева точка сплайну. */ - void ModifiSpl (qint64 p1, QPointF p2, QPointF p3, qint64 p4, qreal kCurve); + void ModifiSpl (const qint64 &p1, const QPointF &p2, const QPointF &p3, const qint64 &p4, + const qreal &kCurve); /** * @brief RotationSpl поворот сплайна навколо точки на кут в градусах проти годиникової стрілки. * @param pRotate точка навколо якої повертаємо. * @param angle кут в градусах. */ -// void RotationSpl ( QPointF pRotate, qreal angle ); +// void RotationSpl ( QPointF pRotate, qreal angle ); /** * @brief BiasSpl зміщує сплайн. * @param mx зміщення по х координаті. * @param my зміщення по у координаті. */ -// void BiasSpl ( qreal mx, qreal my ); +// void BiasSpl ( qreal mx, qreal my ); /** * @brief GetP1 повертає першу точку сплайну. * @return перша точка сплайну. */ - qint64 GetP1 () const; - VPointF GetPointP1() const; + qint64 GetP1 () const {return p1;} + VPointF GetPointP1() const; /** * @brief GetP2 повертує першу контрольну точку сплайну. * @return перша контрольна точка сплайну. */ - QPointF GetP2 () const; + inline QPointF GetP2 () const {return p2;} /** * @brief GetP3 повертає другу контрольну точку сплайну. * @return друга контрольна точка сплайну. */ - QPointF GetP3 () const; + inline QPointF GetP3 () const {return p3;} /** * @brief GetP4 повертає останню точку сплайну. * @return остання точка сплайну. */ - qint64 GetP4 () const; - VPointF GetPointP4 () const; + inline qint64 GetP4 () const {return p4;} + VPointF GetPointP4 () const; /** * @brief GetAngle1 повертає кут першої напрямної. * @return кут в градусах. */ - qreal GetAngle1 () const; + inline qreal GetAngle1 () const {return angle1;} /** * @brief GetAngle2 повертає кут другої напрямної. * @return кут в градусах. */ - qreal GetAngle2() const; + inline qreal GetAngle2() const {return angle2;} /** * @brief GetLength повертає довжину сплайну. * @return довжина сплайну. */ - qreal GetLength () const; - QString GetName () const; - qreal GetKasm1() const; - qreal GetKasm2() const; - qreal GetKcurve() const; - const QHash *GetDataPoints() const; + qreal GetLength () const; + QString GetName () const; + inline qreal GetKasm1() const {return kAsm1;} + inline qreal GetKasm2() const {return kAsm2;} + inline qreal GetKcurve() const {return kCurve;} + inline const QHash GetDataPoints() const {return points;} /** * @brief CrossingSplLine перевіряє перетин сплайну з лінією. * @param line лінія з якою перевіряється перетин. @@ -150,20 +157,20 @@ public: * @param curFir перший сплайн. * @param curSec другий сплайн. */ -// void CutSpline ( qreal length, VSpline* curFir, VSpline* curSec ) const; +// void CutSpline ( qreal length, VSpline* curFir, VSpline* curSec ) const; /** * @brief CutSpline розрізає сплайн. * @param point точка що ділить сплайн. * @param curFir перший сплайн. * @param curSec другий сплайн. */ -// void CutSpline (QPointF point, VSpline* curFir, VSpline* curSec ) const; +// void CutSpline (QPointF point, VSpline* curFir, VSpline* curSec ) const; /** * @brief PutAlongSpl розміщає точку на сплайні. * @param moveP точка яка розміщується на сплайні. * @param move довжина від початку сплайну. */ -// void PutAlongSpl ( QPointF &moveP, qreal move ) const; +// void PutAlongSpl ( QPointF &moveP, qreal move ) const; /** * @brief GetPoints повертає точки з яких складається сплайн. * @return список точок. @@ -173,19 +180,21 @@ public: * @brief GetPath повертає шлях сплайну. * @return шлях. */ - QPainterPath GetPath() const; + QPainterPath GetPath() const; /** * @brief Mirror вертикальне дзеркалення сплайну відносно точки. * @param Pmirror точка відносно якої відбувається вертикальне дзеркалення сплайну. */ -// void Mirror(const QPointF Pmirror); - Draw::Draws getMode() const; - void setMode(const Draw::Draws &value); - static QVector SplinePoints(QPointF p1, QPointF p4, qreal angle1, - qreal angle2, qreal kAsm1, qreal kAsm2, qreal kCurve); - qint64 getIdObject() const; - void setIdObject(const qint64 &value); - VSpline &operator=(const VSpline &spl); +// void Mirror(const QPointF Pmirror); + inline Draw::Draws getMode() const {return mode;} + inline void setMode(const Draw::Draws &value) {mode = value;} + static QVector SplinePoints(const QPointF &p1, const QPointF &p4, qreal angle1, qreal angle2, qreal kAsm1, + qreal kAsm2, qreal kCurve); + inline qint64 getIdObject() const {return idObject;} + inline void setIdObject(const qint64 &value) {idObject = value;} + VSpline &operator=(const VSpline &spl); + QString name() const {return _name;} + void setName(const QString &name) {_name = name;} protected: /** * @brief GetPoints повертає точки з яких складається сплайн. @@ -195,38 +204,39 @@ protected: * @param p4 кінцева точка сплайну. * @return список точок. */ - static QVector GetPoints ( QPointF p1, QPointF p2, QPointF p3, QPointF p4 ); + static QVector GetPoints (const QPointF &p1, const QPointF &p2, const QPointF &p3, const QPointF &p4 ); private: /** * @brief p1 початкова точка сплайну */ - qint64 p1; // перша точка + qint64 p1; // перша точка /** * @brief p2 перша контрольна точка сплайну. */ - QPointF p2; // друга точка + QPointF p2; // друга точка /** * @brief p3 друга контрольна точка сплайну. */ - QPointF p3; // третя точка + QPointF p3; // третя точка /** * @brief p4 кінцеві точка сплайну. */ - qint64 p4; // четверта точка + qint64 p4; // четверта точка /** * @brief angle1 кут в градусах першої напрямної. */ - qreal angle1; // кут нахилу дотичної в першій точці + qreal angle1; // кут нахилу дотичної в першій точці /** * @brief angle2 кут в градусах другої напрямної. */ - qreal angle2; // кут нахилу дотичної в другій точці - qreal kAsm1; - qreal kAsm2; - qreal kCurve; - const QHash *points; - Draw::Draws mode; - qint64 idObject; + qreal angle2; // кут нахилу дотичної в другій точці + qreal kAsm1; + qreal kAsm2; + qreal kCurve; + QHash points; + Draw::Draws mode; + qint64 idObject; + QString _name; /** * @brief LengthBezier повертає дожину сплайну за його чотирьма точками. * @param p1 початкова точка сплайну. @@ -235,7 +245,7 @@ private: * @param p4 кінцева точка сплайну. * @return дожина сплайну. */ - qreal LengthBezier ( QPointF p1, QPointF p2, QPointF p3, QPointF p4 ) const; + qreal LengthBezier (const QPointF &p1, const QPointF &p2, const QPointF &p3, const QPointF &p4 ) const; /** * @brief PointBezier_r знаходить точки сплайну по його чотирьом точках. * @param x1 х координата першої точки сплайну. @@ -250,9 +260,8 @@ private: * @param px список х координат точок сплайну. * @param py список у коодринат сплайну. */ - static void PointBezier_r ( qreal x1, qreal y1, qreal x2, qreal y2, - qreal x3, qreal y3, qreal x4, qreal y4, - qint16 level, QVector &px, QVector &py); + static void PointBezier_r ( qreal x1, qreal y1, qreal x2, qreal y2, qreal x3, qreal y3, qreal x4, qreal y4, + qint16 level, QVector &px, QVector &py); /** * @brief CalcSqDistance розраховує довжину між точками. * @param x1 х координата першої точки. @@ -261,16 +270,16 @@ private: * @param y2 у координата другої точки. * @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); + 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 calc_t знаходить параметр t якому відповідає точка на сплайні. * @param curve_coord1 координата Х або У кривої. @@ -280,14 +289,14 @@ private: * @param point_coord координата Х або У точки на кривій. * @return */ -// static qreal calc_t (qreal curve_coord1, qreal curve_coord2, qreal curve_coord3, -// qreal curve_coord4, qreal point_coord)const; +// static qreal calc_t (qreal curve_coord1, qreal curve_coord2, qreal curve_coord3, qreal curve_coord4, +// qreal point_coord)const; /** * @brief param_t знаходить підходяще значення параметра t якому відповідає точка на сплайні * @param pBt точка для якої шукається значення параметра t. * @return підходяще значення t. */ -// qreal param_t (QPointF pBt)const; +// qreal param_t (QPointF pBt)const; }; #endif // VSPLINE_H diff --git a/geometry/vsplinepath.cpp b/geometry/vsplinepath.cpp index f6b6f1342..79b2acf76 100644 --- a/geometry/vsplinepath.cpp +++ b/geometry/vsplinepath.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vsplinepath.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,156 +24,148 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "vsplinepath.h" -#include "exception/vexception.h" +#include "../exception/vexception.h" -VSplinePath::VSplinePath(): path(QVector()), kCurve(1), mode(Draw::Calculation), points(0), - idObject(0){ -} +VSplinePath::VSplinePath() + : path(QVector()), kCurve(1), mode(Draw::Calculation), points(QHash()), idObject(0), + _name(QString()){} -VSplinePath::VSplinePath(const QHash *points, qreal kCurve, Draw::Draws mode, qint64 idObject): path(QVector()), - kCurve(kCurve), mode(mode), points(points), idObject(idObject){ -} +VSplinePath::VSplinePath(const QHash *points, qreal kCurve, Draw::Draws mode, qint64 idObject) + : path(QVector()), kCurve(kCurve), mode(mode), points(*points), idObject(idObject), _name(QString()) +{} -VSplinePath::VSplinePath(const VSplinePath &splPath): path(*splPath.GetPoint()), - kCurve(splPath.getKCurve()), mode(splPath.getMode()), points( splPath.GetDataPoints()), - idObject(splPath.getIdObject()){ -} +VSplinePath::VSplinePath(const VSplinePath &splPath) + : path(*splPath.GetPoint()), kCurve(splPath.getKCurve()), mode(splPath.getMode()), points(splPath.GetDataPoints()), + idObject(splPath.getIdObject()), _name(splPath.name()){} -Draw::Draws VSplinePath::getMode() const{ - return mode; -} - -void VSplinePath::setMode(const Draw::Draws &value){ - mode = value; -} - -void VSplinePath::append(VSplinePoint point){ +void VSplinePath::append(const VSplinePoint &point) +{ path.append(point); + _name = QString("SplPath"); + for (qint32 i = 1; i <= this->Count(); ++i) + { + VSpline spl = this->GetSpline(i); + VPointF first = spl.GetPointP1(); + VPointF second = spl.GetPointP4(); + QString splName = QString("_%1_%2").arg(first.name(), second.name()); + _name.append(splName); + } } -qint32 VSplinePath::Count() const{ - if(path.size() == 0){ +qint32 VSplinePath::Count() const +{ + if (path.size() == 0) + { return 0; - } else { + } + else + { return path.size() - 1; } } -qint32 VSplinePath::CountPoint() const{ - return path.size(); -} - -VSpline VSplinePath::GetSpline(qint32 index) const{ - if(Count()<1){ +VSpline VSplinePath::GetSpline(qint32 index) const +{ + if (Count()<1) + { throw VException(tr("Not enough points to create the spline.")); } - if(index < 1 || index > Count()){ + if (index < 1 || index > Count()) + { throw VException(tr("This spline is not exist.")); } - VSpline spl(points, path[index-1].P(), path[index].P(), path[index-1].Angle2(), path[index].Angle1(), + VSpline spl(&points, path[index-1].P(), path[index].P(), path[index-1].Angle2(), path[index].Angle1(), path[index-1].KAsm2(), path[index].KAsm1(), this->kCurve); return spl; } -QPainterPath VSplinePath::GetPath() const{ +QPainterPath VSplinePath::GetPath() const +{ QPainterPath painterPath; - for(qint32 i = 1; i <= Count(); ++i){ - VSpline spl(points, path[i-1].P(), path[i].P(), path[i-1].Angle2(), path[i].Angle1(), path[i-1].KAsm2(), - path[i].KAsm1(), this->kCurve); + for (qint32 i = 1; i <= Count(); ++i) + { + VSpline spl(&points, path[i-1].P(), path[i].P(), path[i-1].Angle2(), path[i].Angle1(), + path[i-1].KAsm2(), path[i].KAsm1(), this->kCurve); painterPath.addPath(spl.GetPath()); } return painterPath; } -QVector VSplinePath::GetPathPoints() const{ +QVector VSplinePath::GetPathPoints() const +{ QVector pathPoints; - for(qint32 i = 1; i <= Count(); ++i){ - VSpline spl(points, path[i-1].P(), path[i].P(), path[i-1].Angle2(), path[i].Angle1(), path[i-1].KAsm2(), - path[i].KAsm1(), this->kCurve); + for (qint32 i = 1; i <= Count(); ++i) + { + VSpline spl(&points, path[i-1].P(), path[i].P(), path[i-1].Angle2(), path[i].Angle1(), + path[i-1].KAsm2(), path[i].KAsm1(), this->kCurve); QVector splP = spl.GetPoints(); - for(qint32 j = 0; j < splP.size(); ++j){ + for (qint32 j = 0; j < splP.size(); ++j) + { pathPoints.append(splP[j]); } } return pathPoints; } -QVector VSplinePath::GetSplinePath() const{ - return path; -} - -qreal VSplinePath::GetLength() const{ +qreal VSplinePath::GetLength() const +{ qreal length = 0; - for(qint32 i = 1; i <= Count(); ++i){ - VSpline spl(points, path[i-1].P(), path[i].P(), path[i-1].Angle2(), path[i].Angle1(), path[i-1].KAsm2(), + for (qint32 i = 1; i <= Count(); ++i) + { + VSpline spl(&points, path[i-1].P(), path[i].P(), path[i-1].Angle2(), path[i].Angle1(), path[i-1].KAsm2(), path[i].KAsm1(), kCurve); length += spl.GetLength(); } return length; } -const QHash *VSplinePath::GetDataPoints() const{ - return points; -} - -void VSplinePath::UpdatePoint(qint32 indexSpline, SplinePoint::Position pos, VSplinePoint point){ - if(indexSpline < 1 || indexSpline > Count()){ +void VSplinePath::UpdatePoint(qint32 indexSpline, const SplinePoint::Position &pos, const VSplinePoint &point) +{ + if (indexSpline < 1 || indexSpline > Count()) + { throw VException(tr("This spline is not exist.")); } - if(pos == SplinePoint::FirstPoint){ + if (pos == SplinePoint::FirstPoint) + { path[indexSpline-1] = point; - } else { + } + else + { path[indexSpline] = point; } } -VSplinePoint VSplinePath::GetSplinePoint(qint32 indexSpline, SplinePoint::Position pos) const{ - if(indexSpline < 1 || indexSpline > Count()){ +VSplinePoint VSplinePath::GetSplinePoint(qint32 indexSpline, SplinePoint::Position pos) const +{ + if (indexSpline < 1 || indexSpline > Count()) + { throw VException(tr("This spline is not exist.")); } - if(pos == SplinePoint::FirstPoint){ + if (pos == SplinePoint::FirstPoint) + { return path.at(indexSpline-1); - } else { + } + else + { return path.at(indexSpline); } } -void VSplinePath::Clear(){ - path.clear(); -} - -qreal VSplinePath::getKCurve() const{ - return kCurve; -} - -void VSplinePath::setKCurve(const qreal &value){ - kCurve = value; -} - -const QVector *VSplinePath::GetPoint() const{ - return &path; -} - -VSplinePath &VSplinePath::operator =(const VSplinePath &path){ +VSplinePath &VSplinePath::operator =(const VSplinePath &path) +{ this->path = path.GetSplinePath(); this->kCurve = path.getKCurve(); this->mode = path.getMode(); this->points = path.GetDataPoints(); this->idObject = path.getIdObject(); + this->_name = path.name(); return *this; } -VSplinePoint & VSplinePath::operator[](int indx){ +VSplinePoint & VSplinePath::operator[](ptrdiff_t indx) +{ return path[indx]; } - -qint64 VSplinePath::getIdObject() const{ - return idObject; -} - -void VSplinePath::setIdObject(const qint64 &value){ - idObject = value; -} diff --git a/geometry/vsplinepath.h b/geometry/vsplinepath.h index 1036154dd..212bda56c 100644 --- a/geometry/vsplinepath.h +++ b/geometry/vsplinepath.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vsplinepath.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,76 +24,81 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef VSPLINEPATH_H #define VSPLINEPATH_H #include "vsplinepoint.h" +#include "../container/vpointf.h" #include "vspline.h" -#include +#include -namespace SplinePoint{ -enum Position { FirstPoint, LastPoint }; -Q_DECLARE_FLAGS(Positions, Position) +namespace SplinePoint +{ + enum Position { FirstPoint, LastPoint }; + Q_DECLARE_FLAGS(Positions, Position) } Q_DECLARE_OPERATORS_FOR_FLAGS( SplinePoint::Positions ) /** * @brief The VSplinePath клас, що розраховує шлях сплайнів. */ -class VSplinePath{ +class VSplinePath +{ Q_DECLARE_TR_FUNCTIONS(VSplinePath) public: /** * @brief VSplinePath конструктор по замовчуванню. */ - VSplinePath(); + VSplinePath(); /** * @brief VSplinePath конструктор по замовчуванню. */ - VSplinePath(const QHash *points, qreal kCurve = 1, - Draw::Draws mode = Draw::Calculation, qint64 idObject = 0); - VSplinePath(const VSplinePath& splPath); + VSplinePath(const QHash *points, qreal kCurve = 1, + Draw::Draws mode = Draw::Calculation, qint64 idObject = 0); + VSplinePath(const VSplinePath& splPath); /** * @brief append додає точку сплайну до шляху. * @param point точка. */ - void append(VSplinePoint point); - qint32 Count() const; - qint32 CountPoint() const; - VSpline GetSpline(qint32 index) const; - QPainterPath GetPath() const; - QVector GetPathPoints() const; - QVector GetSplinePath() const; - qreal GetLength() const; - const QHash *GetDataPoints() const; - void UpdatePoint(qint32 indexSpline, SplinePoint::Position pos, VSplinePoint point); - VSplinePoint GetSplinePoint(qint32 indexSpline, SplinePoint::Position pos) const; + void append(const VSplinePoint &point); + qint32 Count() const; + inline qint32 CountPoint() const {return path.size();} + VSpline GetSpline(qint32 index) const; + QPainterPath GetPath() const; + QVector GetPathPoints() const; + inline QVector GetSplinePath() const {return path;} + qreal GetLength() const; + inline QHash GetDataPoints() const {return points;} + void UpdatePoint(qint32 indexSpline, const SplinePoint::Position &pos, const VSplinePoint &point); + VSplinePoint GetSplinePoint(qint32 indexSpline, SplinePoint::Position pos) const; /** * @brief Clear очищає шлях сплайнів. */ - void Clear(); - qreal getKCurve() const; - void setKCurve(const qreal &value); - const QVector *GetPoint() const; - VSplinePath& operator=(const VSplinePath &path); - VSplinePoint & operator[](int indx); - Draw::Draws getMode() const; - void setMode(const Draw::Draws &value); - - qint64 getIdObject() const; - void setIdObject(const qint64 &value); + inline void Clear() {path.clear();} + inline qreal getKCurve() const {return kCurve;} + inline void setKCurve(const qreal &value) {kCurve = value;} + inline const QVector *GetPoint() const {return &path;} + VSplinePath &operator=(const VSplinePath &path); + VSplinePoint &operator[](ptrdiff_t indx); + inline Draw::Draws getMode() const {return mode;} + inline void setMode(const Draw::Draws &value) {mode = value;} + inline qint64 getIdObject() const {return idObject;} + inline void setIdObject(const qint64 &value) {idObject = value;} + QString name() const {return _name;} + void setName(const QString &name) {_name = name;} protected: /** * @brief path вектор з точок сплайна. */ QVector path; - qreal kCurve; - Draw::Draws mode; - const QHash *points; - qint64 idObject; + qreal kCurve; + Draw::Draws mode; + QHash points; + qint64 idObject; + QString _name; }; #endif // VSPLINEPATH_H diff --git a/geometry/vsplinepoint.cpp b/geometry/vsplinepoint.cpp index 6409eb5d5..e57a7363a 100644 --- a/geometry/vsplinepoint.cpp +++ b/geometry/vsplinepoint.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vsplinepoint.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,56 +24,15 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "vsplinepoint.h" -VSplinePoint::VSplinePoint():pSpline(0), angle(0), kAsm1(1), kAsm2(1){ -} +VSplinePoint::VSplinePoint() + :pSpline(0), angle(0), kAsm1(1), kAsm2(1){} -VSplinePoint::VSplinePoint(qint64 pSpline, qreal kAsm1, qreal angle , qreal kAsm2):pSpline(pSpline), - angle(angle), kAsm1(kAsm1), kAsm2(kAsm2){ -} +VSplinePoint::VSplinePoint(qint64 pSpline, qreal kAsm1, qreal angle, qreal kAsm2) + :pSpline(pSpline), angle(angle), kAsm1(kAsm1), kAsm2(kAsm2){} -VSplinePoint::VSplinePoint(const VSplinePoint &point):pSpline(point.P()), angle(point.Angle2()), - kAsm1(point.KAsm1()), kAsm2(point.KAsm2()){ -} - -VSplinePoint::~VSplinePoint(){ -} - -qint64 VSplinePoint::P() const{ - return pSpline; -} - -void VSplinePoint::SetP(const qint64 &value){ - pSpline = value; -} - -qreal VSplinePoint::Angle1() const{ - return angle+180; -} - -void VSplinePoint::SetAngle(const qreal &value){ - angle = value; -} - -qreal VSplinePoint::Angle2() const{ - return angle; -} - -qreal VSplinePoint::KAsm1() const{ - return kAsm1; -} - -void VSplinePoint::SetKAsm1(const qreal &value){ - kAsm1 = value; -} - -qreal VSplinePoint::KAsm2() const{ - return kAsm2; -} - -void VSplinePoint::SetKAsm2(const qreal &value){ - kAsm2 = value; -} +VSplinePoint::VSplinePoint(const VSplinePoint &point) + :pSpline(point.P()), angle(point.Angle2()), kAsm1(point.KAsm1()), kAsm2(point.KAsm2()){} diff --git a/geometry/vsplinepoint.h b/geometry/vsplinepoint.h index 219e9fa96..d6f6ef6d5 100644 --- a/geometry/vsplinepoint.h +++ b/geometry/vsplinepoint.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vsplinepoint.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,7 +24,7 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef VSPLINEPOINT_H #define VSPLINEPOINT_H @@ -27,67 +34,68 @@ /** * @brief The VSplinePoint клас, що містить у собі інформацію про точки сплайну. */ -class VSplinePoint{ +class VSplinePoint +{ public: /** * @brief VSplinePoint конструктор по замповчуванню. */ - VSplinePoint(); + VSplinePoint(); /** * @brief VSplinePoint конструктор. * @param pSpline точка сплайну. * @param angle кут дотичної сплайна. * @param factor коефіцієнт довжини дотичної. */ - VSplinePoint(qint64 pSpline, qreal kAsm1, qreal angle, qreal kAsm2); - VSplinePoint(const VSplinePoint &point); - ~VSplinePoint(); + VSplinePoint(qint64 pSpline, qreal kAsm1, qreal angle, qreal kAsm2); + VSplinePoint(const VSplinePoint &point); + ~VSplinePoint() {} /** * @brief P повертає точку. * @return точка. */ - qint64 P() const; - void SetP(const qint64 &value); + inline qint64 P() const {return pSpline;} + inline void SetP(const qint64 &value) {pSpline = value;} /** * @brief Angle1 повертає кут дотичної сплайна. * @return кут в градусах. */ - qreal Angle1() const; - void SetAngle(const qreal &value); + inline qreal Angle1() const {return angle+180;} + inline void SetAngle(const qreal &value) {angle = value;} /** * @brief Angle2 повертає кут дотичної сплайна. * @return кут в градусах. */ - qreal Angle2() const; + inline qreal Angle2() const {return angle;} /** * @brief KAsm1 повертає коефіцієнт довжини дотичної. * @return коефіцієнт. */ - qreal KAsm1() const; - void SetKAsm1(const qreal &value); + inline qreal KAsm1() const {return kAsm1;} + inline void SetKAsm1(const qreal &value) {kAsm1 = value;} /** * @brief KAsm2 повертає коефіцієнт довжини дотичної. * @return коефіцієнт. */ - qreal KAsm2() const; - void SetKAsm2(const qreal &value); + inline qreal KAsm2() const {return kAsm2;} + inline void SetKAsm2(const qreal &value) {kAsm2 = value;} protected: /** * @brief pSpline точка сплайну. */ - qint64 pSpline; + qint64 pSpline; /** * @brief angle кут дотичної сплайну. */ - qreal angle; + qreal angle; /** * @brief kAsm1 коефіцієнт довжини дотичної сплайну. */ - qreal kAsm1; + qreal kAsm1; /** * @brief kAsm2 коефіцієнт довжини дотичної сплайну. */ - qreal kAsm2; + qreal kAsm2; }; Q_DECLARE_METATYPE(VSplinePoint) diff --git a/icon.qrc b/icon.qrc index 739f4bdee..66b939f04 100644 --- a/icon.qrc +++ b/icon.qrc @@ -34,5 +34,8 @@ icon/32x32/new_detail.png icon/32x32/layout.png icon/16x16/mirror.png + icon/32x32/height.png + icon/32x32/triangle.png + icon/32x32/point_of_intersection.png diff --git a/icon/32x32/height.png b/icon/32x32/height.png new file mode 100644 index 000000000..c44de68bc Binary files /dev/null and b/icon/32x32/height.png differ diff --git a/icon/32x32/point_of_intersection.png b/icon/32x32/point_of_intersection.png new file mode 100644 index 000000000..7ab757dde Binary files /dev/null and b/icon/32x32/point_of_intersection.png differ diff --git a/icon/32x32/triangle.png b/icon/32x32/triangle.png new file mode 100644 index 000000000..c409b3b41 Binary files /dev/null and b/icon/32x32/triangle.png differ diff --git a/main.cpp b/main.cpp index 6ed51ac57..8a2cf8320 100644 --- a/main.cpp +++ b/main.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file main.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,36 +24,41 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "mainwindow.h" #include "widgets/vapplication.h" #include #include "tablewindow.h" -void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg){ +void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg) +{ QByteArray localMsg = msg.toLocal8Bit(); - switch (type) { - case QtDebugMsg: - fprintf(stderr, "Debug: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, - context.function); - break; - case QtWarningMsg: - fprintf(stderr, "Warning: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, - context.function); - break; - case QtCriticalMsg: - fprintf(stderr, "Critical: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, - context.function); - break; - case QtFatalMsg: - fprintf(stderr, "Fatal: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, - context.function); - abort(); + switch (type) + { + case QtDebugMsg: + fprintf(stderr, "Debug: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, + context.function); + break; + case QtWarningMsg: + fprintf(stderr, "Warning: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, + context.function); + break; + case QtCriticalMsg: + fprintf(stderr, "Critical: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, + context.function); + break; + case QtFatalMsg: + fprintf(stderr, "Fatal: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, + context.function); + abort(); + default: + break; } } -int main(int argc, char *argv[]){ +int main(int argc, char *argv[]) +{ qInstallMessageHandler(myMessageOutput); VApplication app(argc, argv); @@ -56,10 +68,11 @@ int main(int argc, char *argv[]){ app.installTranslator(&qtTranslator); QTranslator appTranslator; - appTranslator.load("valentina_" + QLocale::system().name(),"."); + appTranslator.load("valentina_" + QLocale::system().name(), "."); app.installTranslator(&appTranslator); MainWindow w; + w.setWindowState(w.windowState() ^ Qt::WindowMaximized); app.setWindowIcon(QIcon(":/icon/64x64/icon64x64.png")); TableWindow table; QObject::connect(&w, &MainWindow::ModelChosen, &table, &TableWindow::ModelChosen); @@ -69,23 +82,31 @@ int main(int argc, char *argv[]){ QString fileName; QRegExp rxArgOpenFile("-o");//parameter open file - if(args.size()>1){ - for (int i = 1; i < args.size(); ++i) { - if (rxArgOpenFile.indexIn(args.at(i)) != -1 ) { - if(args.at(i+1).isEmpty() == false){ + if (args.size()>1) + { + for (int i = 1; i < args.size(); ++i) + { + if (rxArgOpenFile.indexIn(args.at(i)) != -1 ) + { + if (args.at(i+1).isEmpty() == false) + { fileName = args.at(i+1); qDebug() << args.at(i)<< ":" << fileName; w.OpenPattern(fileName); } w.show(); break; - } else { + } + else + { qDebug() << "Uknown arg:" << args.at(i); w.show(); break; } } - } else { + } + else + { w.show(); } return app.exec(); diff --git a/mainwindow.cpp b/mainwindow.cpp index 2f0fb98b4..f8f742463 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file mainwindow.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,39 +24,34 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "mainwindow.h" #include "ui_mainwindow.h" -#include -#include -#include -#include -#include -#include -#include -#include #include "geometry/vspline.h" -#include #include "exception/vexceptionobjecterror.h" #include "exception/vexceptionconversionerror.h" #include "exception/vexceptionemptyparameter.h" #include "exception/vexceptionwrongparameterid.h" #include "exception/vexceptionuniqueid.h" +#include "version.h" -MainWindow::MainWindow(QWidget *parent) : - QMainWindow(parent), ui(new Ui::MainWindow), tool(Tool::ArrowTool), currentScene(0), sceneDraw(0), +MainWindow::MainWindow(QWidget *parent) + :QMainWindow(parent), ui(new Ui::MainWindow), tool(Tool::ArrowTool), currentScene(0), sceneDraw(0), sceneDetails(0), mouseCoordinate(0), helpLabel(0), view(0), isInitialized(false), dialogTable(0), dialogEndLine(QSharedPointer()), dialogLine(QSharedPointer()), dialogAlongLine(QSharedPointer()), dialogShoulderPoint(QSharedPointer()), dialogNormal(QSharedPointer()), dialogBisector(QSharedPointer()), - dialogLineIntersect(QSharedPointer()), - dialogSpline(QSharedPointer()), + dialogLineIntersect(QSharedPointer()), dialogSpline(QSharedPointer()), dialogArc(QSharedPointer()), dialogSplinePath(QSharedPointer()), - dialogPointOfContact(QSharedPointer()), dialogDetail(QSharedPointer()), + dialogPointOfContact(QSharedPointer()), + dialogDetail(QSharedPointer()), dialogHeight(QSharedPointer()), + dialogTriangle(QSharedPointer()), + dialogPointOfIntersection(QSharedPointer()), dialogHistory(0), doc(0), data(0), comboBoxDraws(0), fileName(QString()), changeInFile(false), - mode(Draw::Calculation){ + mode(Draw::Calculation) +{ ui->setupUi(this); ToolBarOption(); ToolBarDraws(); @@ -62,6 +64,7 @@ MainWindow::MainWindow(QWidget *parent) : view = new VMainGraphicsView(); ui->LayoutView->addWidget(view); view->setScene(currentScene); + connect(view, &VMainGraphicsView::NewFactor, sceneDraw, &VMainGraphicsScene::SetFactor); QSizePolicy policy(QSizePolicy::Expanding, QSizePolicy::Expanding); policy.setHorizontalStretch(12); view->setSizePolicy(policy); @@ -90,6 +93,9 @@ 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); + connect(ui->toolButtonTriangle, &QToolButton::clicked, this, &MainWindow::ToolTriangle); + connect(ui->toolButtonPointOfIntersection, &QToolButton::clicked, this, &MainWindow::ToolPointOfIntersection); data = new VContainer; @@ -113,7 +119,8 @@ MainWindow::MainWindow(QWidget *parent) : ui->toolBox->setCurrentIndex(0); } -void MainWindow::ActionNewDraw(){ +void MainWindow::ActionNewDraw() +{ QString nameDraw; bool bOk; qint32 index; @@ -123,25 +130,31 @@ void MainWindow::ActionNewDraw(){ dlg->setLabelText(tr("Drawing:")); dlg->setTextEchoMode(QLineEdit::Normal); dlg->setWindowTitle(tr("Enter a name for the drawing.")); - dlg->resize(300,100); + dlg->resize(300, 100); dlg->setTextValue(nDraw); - while(1){ + while (1) + { bOk = dlg->exec(); nameDraw = dlg->textValue(); - if(!bOk || nameDraw.isEmpty()){ + if (bOk == false || nameDraw.isEmpty()) + { delete dlg; return; } index = comboBoxDraws->findText(nameDraw); - if(index != -1){//we already have this name + if (index != -1) + {//we already have this name qCritical()<appendDraw(nameDraw); - if(bOk == false){ + if (bOk == false) + { qCritical()<addItem(nameDraw); index = comboBoxDraws->findText(nameDraw); - if ( index != -1 ) { // -1 for not found + if ( index != -1 ) + { // -1 for not found comboBoxDraws->setCurrentIndex(index); currentDrawChanged( index ); } - connect(comboBoxDraws, static_cast(&QComboBox::currentIndexChanged), - this, &MainWindow::currentDrawChanged); + connect(comboBoxDraws, static_cast(&QComboBox::currentIndexChanged), this, + &MainWindow::currentDrawChanged); data->ClearObject(); //Create single point - qint64 id = data->AddPoint(VPointF((10+comboBoxDraws->count()*5)*PrintDPI/25.4, 10*PrintDPI/25.4, "А", 5, - 10)); + qint64 id = data->AddPoint(VPointF(toPixel((10+comboBoxDraws->count()*5)), toPixel(10), "А", 5, 10)); VToolSinglePoint *spoint = new VToolSinglePoint(doc, data, id, Tool::FromGui); sceneDraw->addItem(spoint); connect(spoint, &VToolPoint::ChoosedTool, sceneDraw, &VMainGraphicsScene::ChoosedItem); + connect(sceneDraw, &VMainGraphicsScene::NewFactor, spoint, &VToolSinglePoint::SetFactor); QHash* tools = doc->getTools(); tools->insert(id, spoint); VDrawTool::AddRecord(id, Tool::SinglePointTool, doc); @@ -170,9 +184,9 @@ void MainWindow::ActionNewDraw(){ changeInFile = true; } -void MainWindow::OptionDraw(){ +void MainWindow::OptionDraw() +{ QString nameDraw; - bool bOk; qint32 index; QString nDraw = doc->GetNameActivDraw(); QInputDialog *dlg = new QInputDialog(this); @@ -180,33 +194,46 @@ void MainWindow::OptionDraw(){ dlg->setLabelText(tr("Drawing:")); dlg->setTextEchoMode(QLineEdit::Normal); dlg->setWindowTitle(tr("Enter a new name for the drawing.")); - dlg->resize(300,100); + dlg->resize(300, 100); dlg->setTextValue(nDraw); - while(1){ - bOk = dlg->exec(); + while (1) + { + bool bOk = dlg->exec(); nameDraw = dlg->textValue(); - if(!bOk || nameDraw.isEmpty()){ + if (bOk == false || nameDraw.isEmpty()) + { delete dlg; return; } index = comboBoxDraws->findText(nameDraw); - if(index != -1){//we already have this name + if (index != -1) + {//we already have this name qCritical()<findText(doc->GetNameActivDraw()); - doc->SetNameDraw(nameDraw); - comboBoxDraws->setItemText(index, nameDraw); + if (doc->SetNameDraw(nameDraw)) + { + comboBoxDraws->setItemText(index, nameDraw); + } + else + { + QMessageBox::warning(this, tr("Error saving change!!!"), tr("Can't save new name of drawing")); + } + } template -void MainWindow::SetToolButton(bool checked, Tool::Tools t, const QString &cursor, - const QString &toolTip, QSharedPointer &dialog, - Func closeDialogSlot){ - if(checked){ +void MainWindow::SetToolButton(bool checked, Tool::Tools t, const QString &cursor, const QString &toolTip, + QSharedPointer &dialog, Func closeDialogSlot) +{ + if (checked) + { CanselTool(); tool = t; QPixmap pixmap(cursor); @@ -218,220 +245,173 @@ void MainWindow::SetToolButton(bool checked, Tool::Tools t, const QString &curso connect(dialog.data(), &Dialog::DialogClosed, this, closeDialogSlot); connect(dialog.data(), &Dialog::ToolTip, this, &MainWindow::ShowToolTip); connect(doc, &VDomDocument::FullUpdateFromFile, dialog.data(), &Dialog::UpdateList); - } else { - if(QToolButton *tButton = qobject_cast< QToolButton * >(this->sender())){ + } + else + { + if (QToolButton *tButton = qobject_cast< QToolButton * >(this->sender())) + { + Q_ASSERT(tButton != 0); tButton->setChecked(true); } } } template -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* tools = doc->getTools(); VToolDetail *det = qobject_cast(tools->value(idDetail)); - Q_CHECK_PTR(det); + Q_ASSERT(det != 0); det->AddTool(tool, id, typeTool); } -void MainWindow::ToolEndLine(bool checked){ +template +void MainWindow::ClosedDialog(QSharedPointer &dialog, int result) +{ + if (result == QDialog::Accepted) + { + if (mode == Draw::Calculation) + { + DrawTool::Create(dialog, currentScene, doc, data); + } + else + { + ModelingTool *endLine = ModelingTool::Create(dialog, doc, data); + AddToolToDetail(endLine, endLine->getId(), tool, dialog->getIdDetail()); + } + } + ArrowTool(); +} + +void MainWindow::ToolEndLine(bool checked) +{ SetToolButton(checked, Tool::EndLineTool, ":/cursor/endline_cursor.png", tr("Select point"), dialogEndLine, &MainWindow::ClosedDialogEndLine); } -void MainWindow::ClosedDialogEndLine(int result){ - if(result == QDialog::Accepted){ - if(mode == Draw::Calculation){ - VToolEndLine::Create(dialogEndLine, currentScene, doc, data); - } else { - VModelingEndLine *endLine = VModelingEndLine::Create(dialogEndLine, doc, data); - AddToolToDetail(endLine, endLine->getId(), Tool::EndLineTool, dialogEndLine->getIdDetail()); - } - } - ArrowTool(); +void MainWindow::ClosedDialogEndLine(int result) +{ + ClosedDialog(dialogEndLine, result); } -void MainWindow::ToolLine(bool checked){ +void MainWindow::ToolLine(bool checked) +{ SetToolButton(checked, Tool::LineTool, ":/cursor/line_cursor.png", tr("Select first point"), dialogLine, &MainWindow::ClosedDialogLine); } -void MainWindow::ClosedDialogLine(int result){ - if(result == QDialog::Accepted){ - if(mode == Draw::Calculation){ - VToolLine::Create(dialogLine, currentScene, doc, data); - } else { - VModelingLine *line = VModelingLine::Create(dialogLine, doc, data); - AddToolToDetail(line, line->getId(), Tool::LineTool, dialogLine->getIdDetail()); - } - } - ArrowTool(); +void MainWindow::ClosedDialogLine(int result) +{ + ClosedDialog(dialogLine, result); } -void MainWindow::ToolAlongLine(bool checked){ +void MainWindow::ToolAlongLine(bool checked) +{ SetToolButton(checked, Tool::AlongLineTool, ":/cursor/alongline_cursor.png", tr("Select point"), dialogAlongLine, &MainWindow::ClosedDialogAlongLine); } -void MainWindow::ClosedDialogAlongLine(int result){ - if(result == QDialog::Accepted){ - if(mode == Draw::Calculation){ - VToolAlongLine::Create(dialogAlongLine, currentScene, doc, data); - } else{ - VModelingAlongLine *point = VModelingAlongLine::Create(dialogAlongLine, doc, data); - AddToolToDetail(point, point->getId(), Tool::AlongLineTool, dialogAlongLine->getIdDetail()); - } - } - ArrowTool(); +void MainWindow::ClosedDialogAlongLine(int result) +{ + ClosedDialog(dialogAlongLine, result); } -void MainWindow::ToolShoulderPoint(bool checked){ +void MainWindow::ToolShoulderPoint(bool checked) +{ SetToolButton(checked, Tool::ShoulderPointTool, ":/cursor/shoulder_cursor.png", tr("Select first point of line"), dialogShoulderPoint, &MainWindow::ClosedDialogShoulderPoint); } -void MainWindow::ClosedDialogShoulderPoint(int result){ - if(result == QDialog::Accepted){ - if(mode == Draw::Calculation){ - VToolShoulderPoint::Create(dialogShoulderPoint, currentScene, doc, data); - } else { - VModelingShoulderPoint *point = VModelingShoulderPoint::Create(dialogShoulderPoint, doc, data); - AddToolToDetail(point, point->getId(), Tool::ShoulderPointTool, - dialogShoulderPoint->getIdDetail()); - } - } - ArrowTool(); +void MainWindow::ClosedDialogShoulderPoint(int result) +{ + ClosedDialog(dialogShoulderPoint, result); } -void MainWindow::ToolNormal(bool checked){ +void MainWindow::ToolNormal(bool checked) +{ SetToolButton(checked, Tool::NormalTool, ":/cursor/normal_cursor.png", tr("Select first point of line"), dialogNormal, &MainWindow::ClosedDialogNormal); } -void MainWindow::ClosedDialogNormal(int result){ - if(result == QDialog::Accepted){ - if(mode == Draw::Calculation){ - VToolNormal::Create(dialogNormal, currentScene, doc, data); - } else { - VModelingNormal *point = VModelingNormal::Create(dialogNormal, doc, data); - AddToolToDetail(point, point->getId(), Tool::NormalTool, dialogNormal->getIdDetail()); - } - } - ArrowTool(); +void MainWindow::ClosedDialogNormal(int result) +{ + ClosedDialog(dialogNormal, result); } -void MainWindow::ToolBisector(bool checked){ +void MainWindow::ToolBisector(bool checked) +{ SetToolButton(checked, Tool::BisectorTool, ":/cursor/bisector_cursor.png", tr("Select first point of angle"), dialogBisector, &MainWindow::ClosedDialogBisector); } -void MainWindow::ClosedDialogBisector(int result){ - if(result == QDialog::Accepted){ - if(mode == Draw::Calculation){ - VToolBisector::Create(dialogBisector, currentScene, doc, data); - } else { - VModelingBisector *point = VModelingBisector::Create(dialogBisector, doc, data); - AddToolToDetail(point, point->getId(), Tool::BisectorTool, dialogBisector->getIdDetail()); - } - } - ArrowTool(); +void MainWindow::ClosedDialogBisector(int result) +{ + ClosedDialog(dialogBisector, result); } -void MainWindow::ToolLineIntersect(bool checked){ +void MainWindow::ToolLineIntersect(bool checked) +{ SetToolButton(checked, Tool::LineIntersectTool, ":/cursor/intersect_cursor.png", tr("Select first point of first line"), dialogLineIntersect, &MainWindow::ClosedDialogLineIntersect); } -void MainWindow::ClosedDialogLineIntersect(int result){ - if(result == QDialog::Accepted){ - if(mode == Draw::Calculation){ - VToolLineIntersect::Create(dialogLineIntersect, currentScene, doc, data); - } else { - VModelingLineIntersect *point = VModelingLineIntersect::Create(dialogLineIntersect, doc, - data); - AddToolToDetail(point, point->getId(), Tool::LineIntersectTool, - dialogLineIntersect->getIdDetail()); - } - } - ArrowTool(); +void MainWindow::ClosedDialogLineIntersect(int result) +{ + ClosedDialog(dialogLineIntersect, result); } -void MainWindow::ToolSpline(bool checked){ +void MainWindow::ToolSpline(bool checked) +{ SetToolButton(checked, Tool::SplineTool, ":/cursor/spline_cursor.png", tr("Select first point curve"), dialogSpline, &MainWindow::ClosedDialogSpline); } -void MainWindow::ClosedDialogSpline(int result){ - if(result == QDialog::Accepted){ - if(mode == Draw::Calculation){ - VToolSpline::Create(dialogSpline, currentScene, doc, data); - } else { - VModelingSpline *spl = VModelingSpline::Create(dialogSpline, doc, data); - AddToolToDetail(spl, spl->getId(), Tool::SplineTool, dialogSpline->getIdDetail()); - } - } - ArrowTool(); +void MainWindow::ClosedDialogSpline(int result) +{ + ClosedDialog(dialogSpline, result); } -void MainWindow::ToolArc(bool checked){ +void MainWindow::ToolArc(bool checked) +{ SetToolButton(checked, Tool::ArcTool, ":/cursor/arc_cursor.png", tr("Select point of center of arc"), dialogArc, &MainWindow::ClosedDialogArc); } -void MainWindow::ClosedDialogArc(int result){ - if(result == QDialog::Accepted){ - if(mode == Draw::Calculation){ - VToolArc::Create(dialogArc, currentScene, doc, data); - } else { - VModelingArc *arc = VModelingArc::Create(dialogArc, doc, data); - AddToolToDetail(arc, arc->getId(), Tool::ArcTool, dialogArc->getIdDetail()); - } - } - ArrowTool(); +void MainWindow::ClosedDialogArc(int result) +{ + ClosedDialog(dialogArc, result); } -void MainWindow::ToolSplinePath(bool checked){ +void MainWindow::ToolSplinePath(bool checked) +{ SetToolButton(checked, Tool::SplinePathTool, ":/cursor/splinepath_cursor.png", tr("Select point of curve path"), dialogSplinePath, &MainWindow::ClosedDialogSplinePath); } -void MainWindow::ClosedDialogSplinePath(int result){ - if(result == QDialog::Accepted){ - if(mode == Draw::Calculation){ - VToolSplinePath::Create(dialogSplinePath, currentScene, doc, data); - } else { - VModelingSplinePath *spl = VModelingSplinePath::Create(dialogSplinePath, doc, data); - AddToolToDetail(spl, spl->getId(), Tool::SplinePathTool, dialogSplinePath->getIdDetail()); - } - } - ArrowTool(); +void MainWindow::ClosedDialogSplinePath(int result) +{ + ClosedDialog(dialogSplinePath, result); } -void MainWindow::ToolPointOfContact(bool checked){ +void MainWindow::ToolPointOfContact(bool checked) +{ SetToolButton(checked, Tool::PointOfContact, ":/cursor/pointcontact_cursor.png", tr("Select first point of line"), dialogPointOfContact, &MainWindow::ClosedDialogPointOfContact); } -void MainWindow::ClosedDialogPointOfContact(int result){ - if(result == QDialog::Accepted){ - if(mode == Draw::Calculation){ - VToolPointOfContact::Create(dialogPointOfContact, currentScene, doc, data); - } else { - VModelingPointOfContact *point = VModelingPointOfContact::Create(dialogPointOfContact, doc, - data); - AddToolToDetail(point, point->getId(), Tool::PointOfContact, - dialogPointOfContact->getIdDetail()); - } - } - ArrowTool(); +void MainWindow::ClosedDialogPointOfContact(int result) +{ + ClosedDialog(dialogPointOfContact, result); } -void MainWindow::ToolDetail(bool checked){ - if(checked){ +void MainWindow::ToolDetail(bool checked) +{ + if (checked) + { CanselTool(); tool = Tool::Detail; QPixmap pixmap("://cursor/new_detail_cursor.png"); @@ -443,44 +423,95 @@ void MainWindow::ToolDetail(bool checked){ &DialogDetail::ChoosedObject); connect(dialogDetail.data(), &DialogDetail::DialogClosed, this, &MainWindow::ClosedDialogDetail); connect(doc, &VDomDocument::FullUpdateFromFile, dialogDetail.data(), &DialogDetail::UpdateList); - } else { - if(QToolButton *tButton = qobject_cast< QToolButton * >(this->sender())){ + } + else + { + if (QToolButton *tButton = qobject_cast< QToolButton * >(this->sender())) + { tButton->setChecked(true); } } } -void MainWindow::ClosedDialogDetail(int result){ - if(result == QDialog::Accepted){ +void MainWindow::ClosedDialogDetail(int result) +{ + if (result == QDialog::Accepted) + { VToolDetail::Create(dialogDetail, sceneDetails, doc, data); } ArrowTool(); } -void MainWindow::About(){ - QMessageBox::about(this, tr("About Valentina"), tr("Valentina v.0.1.0")); +void MainWindow::ToolHeight(bool checked) +{ + SetToolButton(checked, Tool::Height, ":/cursor/height_cursor.png", tr("Select base point"), + dialogHeight, &MainWindow::ClosedDialogHeight); } -void MainWindow::AboutQt(){ +void MainWindow::ClosedDialogHeight(int result) +{ + ClosedDialog(dialogHeight, result); +} + +void MainWindow::ToolTriangle(bool checked) +{ + SetToolButton(checked, Tool::Triangle, ":/cursor/triangle_cursor.png", tr("Select first point of axis"), + dialogTriangle, &MainWindow::ClosedDialogTriangle); +} + +void MainWindow::ClosedDialogTriangle(int result) +{ + ClosedDialog(dialogTriangle, result); +} + +void MainWindow::ToolPointOfIntersection(bool checked) +{ + SetToolButton(checked, Tool::PointOfIntersection, ":/cursor/pointofintersect_cursor.png", + tr("Select point vertically"), + dialogPointOfIntersection, &MainWindow::ClosedDialogPointOfIntersection); +} + +void MainWindow::ClosedDialogPointOfIntersection(int result) +{ + ClosedDialog(dialogPointOfIntersection, result); +} + +void MainWindow::About() +{ + QString fullName = QString("Valentina %1").arg(APP_VERSION); + QString qtBase(tr("Based on Qt %2 (32 bit)").arg(QT_VERSION_STR)); + QString buildOn(tr("Built on %3 at %4").arg(__DATE__).arg(__TIME__)); + QString about = QString(tr("

%1

%2

%3

%4")).arg(fullName).arg(qtBase).arg( + buildOn).arg(WARRANTY); + QMessageBox::about(this, tr("About Valentina"), about); +} + +void MainWindow::AboutQt() +{ QMessageBox::aboutQt(this, tr("About Qt")); } -void MainWindow::ShowToolTip(const QString &toolTip){ +void MainWindow::ShowToolTip(const QString &toolTip) +{ helpLabel->setText(toolTip); } -void MainWindow::tableClosed(){ +void MainWindow::tableClosed() +{ show(); MinimumScrollBar(); } -void MainWindow::showEvent( QShowEvent *event ){ +void MainWindow::showEvent( QShowEvent *event ) +{ QMainWindow::showEvent( event ); - if( event->spontaneous() ){ + if ( event->spontaneous() ) + { return; } - if(isInitialized){ + if (isInitialized) + { return; } // do your init stuff here @@ -489,8 +520,10 @@ void MainWindow::showEvent( QShowEvent *event ){ isInitialized = true;//first show windows are held } -void MainWindow::closeEvent(QCloseEvent *event){ - if(changeInFile == true){ +void MainWindow::closeEvent(QCloseEvent *event) +{ + if (changeInFile == true) + { QMessageBox msgBox; msgBox.setText(tr("The pattern has been modified.")); msgBox.setInformativeText(tr("Do you want to save your changes?")); @@ -498,50 +531,58 @@ void MainWindow::closeEvent(QCloseEvent *event){ msgBox.setDefaultButton(QMessageBox::Save); msgBox.setIcon(QMessageBox::Question); int ret = msgBox.exec(); - switch (ret) { - case QMessageBox::Save: - // Save was clicked - if(fileName.isEmpty()){ - ActionSaveAs(); - } else { - ActionSave(); - } - if(changeInFile){ - // We did't save file - event->ignore(); - } else { - // We have successfully saved the file + switch (ret) + { + case QMessageBox::Save: + // Save was clicked + if (fileName.isEmpty()) + { + ActionSaveAs(); + } + else + { + ActionSave(); + } + if (changeInFile) + { + // We did't save file + event->ignore(); + } + else + { + // We have successfully saved the file + event->accept(); + } + break; + case QMessageBox::Discard: + // Don't Save was clicked event->accept(); - } - break; - case QMessageBox::Discard: - // Don't Save was clicked - event->accept(); - break; - case QMessageBox::Cancel: - // Cancel was clicked - event->ignore(); - break; - default: - // should never be reached - event->accept(); - break; + break; + case QMessageBox::Cancel: + // Cancel was clicked + event->ignore(); + break; + default: + // should never be reached + event->accept(); + break; } } } -void MainWindow::ToolBarOption(){ +void MainWindow::ToolBarOption() +{ QLabel * labelGrowth = new QLabel; labelGrowth->setText(tr("Growth: ")); ui->toolBarOption->addWidget(labelGrowth); QStringList list; - list << "104"<<"110"<<"116"<<"122"<<"128"<<"134"<<"140"<<"146"<<"152"<<"158"<<"164"<<"170"<<"176" - << "182" << "188"; + list <<"92"<<"98"<<"104"<<"110"<<"116"<<"122"<<"128"<<"134"<<"140"<<"146"<<"152"<<"158"<<"164"<<"170"<<"176" + <<"182"<<"188"; QComboBox *comboBoxGrow = new QComboBox; comboBoxGrow->clear(); comboBoxGrow->addItems(list); - comboBoxGrow->setCurrentIndex(12); + comboBoxGrow->setCurrentIndex(14); ui->toolBarOption->addWidget(comboBoxGrow); connect(comboBoxGrow, static_cast(&QComboBox::currentIndexChanged), @@ -552,11 +593,11 @@ void MainWindow::ToolBarOption(){ ui->toolBarOption->addWidget(labelSize); list.clear(); - list << "28"<<"30"<<"32"<<"34"<<"36"<<"38"<<"40"<<"42"<<"44"<<"46"<<"48"<<"50" << "52" << "54" << "56"; + list <<"22"<<"24"<<"26"<<"28"<<"30"<<"32"<<"34"<<"36"<<"38"<<"40"<<"42"<<"44"<<"46"<<"48"<<"50"<<"52"<<"54"<<"56"; QComboBox *comboBoxSize = new QComboBox; comboBoxSize->clear(); comboBoxSize->addItems(list); - comboBoxSize->setCurrentIndex(11); + comboBoxSize->setCurrentIndex(14); ui->toolBarOption->addWidget(comboBoxSize); connect(comboBoxSize, static_cast(&QComboBox::currentIndexChanged), @@ -570,7 +611,8 @@ void MainWindow::ToolBarOption(){ } -void MainWindow::ToolBarDraws(){ +void MainWindow::ToolBarDraws() +{ QLabel * labelNameDraw = new QLabel; labelNameDraw ->setText(tr("Drawing: ")); ui->toolBarDraws->addWidget(labelNameDraw); @@ -595,28 +637,33 @@ void MainWindow::ToolBarDraws(){ connect(ui->actionLayout, &QAction::triggered, this, &MainWindow::ActionLayout); } -void MainWindow::currentDrawChanged( int index ){ - if(index != -1) { +void MainWindow::currentDrawChanged( int index ) +{ + if (index != -1) + { doc->setCurrentData(); doc->ChangeActivDraw(comboBoxDraws->itemText(index)); } } -void MainWindow::mouseMove(QPointF scenePos){ +void MainWindow::mouseMove(const QPointF &scenePos) +{ QString string = QString("%1, %2") - .arg(static_cast(scenePos.x()/PrintDPI*25.4)) - .arg(static_cast(scenePos.y()/PrintDPI*25.4)); + .arg(static_cast(toMM(scenePos.x()))) + .arg(static_cast(toMM(scenePos.y()))); mouseCoordinate->setText(string); } -void MainWindow::CanselTool(){ - switch( tool ) +void MainWindow::CanselTool() +{ + switch ( tool ) { case Tool::ArrowTool: ui->actionArrowTool->setChecked(false); helpLabel->setText(""); break; case Tool::SinglePointTool: + Q_UNREACHABLE(); //Nothing to do here because we can't create this tool from main window. break; case Tool::EndLineTool: @@ -689,13 +736,32 @@ void MainWindow::CanselTool(){ dialogDetail.clear(); ui->toolButtonNewDetail->setChecked(false); break; + case Tool::Height: + dialogHeight.clear(); + ui->toolButtonHeight->setChecked(false); + currentScene->setFocus(Qt::OtherFocusReason); + currentScene->clearSelection(); + break; + case Tool::Triangle: + dialogTriangle.clear(); + ui->toolButtonTriangle->setChecked(false); + currentScene->setFocus(Qt::OtherFocusReason); + currentScene->clearSelection(); + break; + case Tool::PointOfIntersection: + dialogPointOfIntersection.clear(); + ui->toolButtonPointOfIntersection->setChecked(false); + currentScene->setFocus(Qt::OtherFocusReason); + currentScene->clearSelection(); + break; default: qWarning()<<"Get wrong tool type. Ignore."; break; } } -void MainWindow::ArrowTool(){ +void MainWindow::ArrowTool() +{ CanselTool(); ui->actionArrowTool->setChecked(true); tool = Tool::ArrowTool; @@ -704,21 +770,28 @@ void MainWindow::ArrowTool(){ helpLabel->setText(""); } -void MainWindow::ActionAroowTool(){ +void MainWindow::ActionAroowTool() +{ ArrowTool(); } -void MainWindow::keyPressEvent ( QKeyEvent * event ){ - switch(event->key()){ +void MainWindow::keyPressEvent ( QKeyEvent * event ) +{ + switch (event->key()) + { case Qt::Key_Escape: ArrowTool(); break; + default: + break; } QMainWindow::keyPressEvent ( event ); } -void MainWindow::ActionDraw(bool checked){ - if(checked){ +void MainWindow::ActionDraw(bool checked) +{ + if (checked) + { ui->actionDetails->setChecked(false); /*Save scroll bars value for previous scene.*/ QScrollBar *horScrollBar = view->horizontalScrollBar(); @@ -736,13 +809,17 @@ void MainWindow::ActionDraw(bool checked){ mode = Draw::Calculation; doc->setCurrentData(); - } else { + } + else + { ui->actionDraw->setChecked(true); } } -void MainWindow::ActionDetails(bool checked){ - if(checked){ +void MainWindow::ActionDetails(bool checked) +{ + if (checked) + { ui->actionDraw->setChecked(false); /*Save scroll bars value for previous scene.*/ QScrollBar *horScrollBar = view->horizontalScrollBar(); @@ -758,19 +835,25 @@ void MainWindow::ActionDetails(bool checked){ verScrollBar = view->verticalScrollBar(); verScrollBar->setValue(currentScene->getVerScrollBar()); mode = Draw::Modeling; - } else { + } + else + { ui->actionDetails->setChecked(true); } } -void MainWindow::ActionSaveAs(){ +void MainWindow::ActionSaveAs() +{ QString filters(tr("Lekalo files (*.xml);;All files (*.*)")); QString defaultFilter(tr("Lekalo files (*.xml)")); QString fName = QFileDialog::getSaveFileName(this, tr("Save as"), QDir::homePath(), filters, &defaultFilter); - if(fName.isEmpty()) + if (fName.isEmpty()) + { return; - if(fName.indexOf(".xml",fName.size()-4)<0){ + } + if (fName.indexOf(".xml", fName.size()-4)<0) + { fName.append(".xml"); } fileName = fName; @@ -778,17 +861,22 @@ void MainWindow::ActionSaveAs(){ ActionSave(); } -void MainWindow::ActionSave(){ - if(!fileName.isEmpty()){ +void MainWindow::ActionSave() +{ + if (fileName.isEmpty() == false) + { bool result = SafeSaveing(fileName); - if(result){ + if (result) + { ui->actionSave->setEnabled(false); changeInFile = false; QFileInfo info(fileName); QString title(info.fileName()); title.append("-Valentina"); setWindowTitle(title); - } else { + } + else + { QMessageBox msgBox; msgBox.setWindowTitle(tr("Error!")); msgBox.setText(tr("Error saving file. Can't save file.")); @@ -800,14 +888,20 @@ void MainWindow::ActionSave(){ } } -void MainWindow::ActionOpen(){ +void MainWindow::ActionOpen() +{ QString filter(tr("Lekalo files (*.xml)")); QString fName = QFileDialog::getOpenFileName(this, tr("Open file"), QDir::homePath(), filter); - if(fName.isEmpty()) + if (fName.isEmpty()) + { return; - if(fileName.isEmpty() && changeInFile == false){ + } + if (fileName.isEmpty() && changeInFile == false) + { OpenPattern(fName); - } else { + } + else + { /*Open new copy application*/ QProcess *v = new QProcess(this); QStringList arguments; @@ -817,7 +911,8 @@ void MainWindow::ActionOpen(){ } } -void MainWindow::Clear(){ +void MainWindow::Clear() +{ setWindowTitle("Valentina"); fileName.clear(); data->Clear(); @@ -832,14 +927,17 @@ void MainWindow::Clear(){ SetEnableTool(false); } -void MainWindow::ActionNew(){ +void MainWindow::ActionNew() +{ QProcess *v = new QProcess(this); v->startDetached(QCoreApplication::applicationFilePath ()); delete v; } -void MainWindow::haveChange(){ - if(!fileName.isEmpty()){ +void MainWindow::haveChange() +{ + if (fileName.isEmpty() == false) + { ui->actionSave->setEnabled(true); changeInFile = true; QFileInfo info(fileName); @@ -849,61 +947,75 @@ void MainWindow::haveChange(){ } } -void MainWindow::ChangedSize(const QString & text){ +void MainWindow::ChangedSize(const QString & text) +{ qint32 size = text.toInt(); data->SetSize(size*10); doc->FullUpdateTree(); } -void MainWindow::ChangedGrowth(const QString &text){ +void MainWindow::ChangedGrowth(const QString &text) +{ qint32 growth = text.toInt(); data->SetGrowth(growth*10); doc->FullUpdateTree(); } -void MainWindow::SetEnableWidgets(bool enable){ +void MainWindow::SetEnableWidgets(bool enable) +{ ui->actionSaveAs->setEnabled(enable); ui->actionDraw->setEnabled(enable); ui->actionDetails->setEnabled(enable); ui->actionOptionDraw->setEnabled(enable); - if(enable == true && !fileName.isEmpty()){ + if (enable == true && fileName.isEmpty() == false) + { ui->actionSave->setEnabled(enable); } ui->actionTable->setEnabled(enable); ui->actionHistory->setEnabled(enable); } -void MainWindow::ActionTable(bool checked){ - if(checked){ +void MainWindow::ActionTable(bool checked) +{ + if (checked) + { dialogTable = new DialogIncrements(data, doc, this); connect(dialogTable, &DialogIncrements::DialogClosed, this, &MainWindow::ClosedActionTable); dialogTable->show(); - } else { + } + else + { ui->actionTable->setChecked(true); dialogTable->activateWindow(); } } -void MainWindow::ClosedActionTable(){ +void MainWindow::ClosedActionTable() +{ ui->actionTable->setChecked(false); delete dialogTable; } -void MainWindow::ActionHistory(bool checked){ - if(checked){ +void MainWindow::ActionHistory(bool checked) +{ + if (checked) + { dialogHistory = new DialogHistory(data, doc, this); dialogHistory->setWindowFlags(Qt::Window); connect(dialogHistory, &DialogHistory::DialogClosed, this, &MainWindow::ClosedActionHistory); dialogHistory->show(); - } else { + } + else + { ui->actionHistory->setChecked(true); dialogHistory->activateWindow(); } } -void MainWindow::ActionLayout(bool checked){ +void MainWindow::ActionLayout(bool checked) +{ Q_UNUSED(checked); hide(); QVector listDetails; @@ -911,12 +1023,14 @@ void MainWindow::ActionLayout(bool checked){ emit ModelChosen(listDetails); } -void MainWindow::ClosedActionHistory(){ +void MainWindow::ClosedActionHistory() +{ ui->actionHistory->setChecked(false); delete dialogHistory; } -void MainWindow::SetEnableTool(bool enable){ +void MainWindow::SetEnableTool(bool enable) +{ ui->toolButtonEndLine->setEnabled(enable); ui->toolButtonLine->setEnabled(enable); ui->toolButtonAlongLine->setEnabled(enable); @@ -929,17 +1043,40 @@ void MainWindow::SetEnableTool(bool enable){ ui->toolButtonSplinePath->setEnabled(enable); ui->toolButtonPointOfContact->setEnabled(enable); ui->toolButtonNewDetail->setEnabled(enable); + ui->toolButtonHeight->setEnabled(enable); + ui->toolButtonTriangle->setEnabled(enable); + ui->toolButtonPointOfIntersection->setEnabled(enable); } -void MainWindow::MinimumScrollBar(){ +void MainWindow::MinimumScrollBar() +{ QScrollBar *horScrollBar = view->horizontalScrollBar(); horScrollBar->setValue(horScrollBar->minimum()); QScrollBar *verScrollBar = view->verticalScrollBar(); verScrollBar->setValue(verScrollBar->minimum()); } -bool MainWindow::SafeSaveing(const QString &fileName) const{ - if(fileName.isEmpty()){ +bool MainWindow::SafeSaveing(const QString &fileName) const +{ + try + { + doc->TestUniqueId(); + } + catch (const VExceptionUniqueId &e) + { + QMessageBox msgBox; + msgBox.setWindowTitle(tr("Error!")); + msgBox.setText(tr("Error don't unique id.")); + msgBox.setInformativeText(e.ErrorMessage()); + msgBox.setStandardButtons(QMessageBox::Ok); + msgBox.setDefaultButton(QMessageBox::Ok); + msgBox.setDetailedText(e.DetailedInformation()); + msgBox.setIcon(QMessageBox::Critical); + msgBox.exec(); + return false; + } + if (fileName.isEmpty()) + { qWarning()<save(out, Indent); @@ -959,31 +1097,42 @@ bool MainWindow::SafeSaveing(const QString &fileName) const{ QFile patternFile(fileName); // We need here temporary file because we need restore pattern after error of copying temp file. QTemporaryFile tempOfPattern; - if (tempOfPattern.open()) { + if (tempOfPattern.open()) + { patternFile.copy(tempOfPattern.fileName()); } - if ( !patternFile.exists() || patternFile.remove() ) { - if ( !tempFile.copy(patternFile.fileName()) ){ + if ( patternFile.exists() == false || patternFile.remove() ) + { + if ( tempFile.copy(patternFile.fileName()) == false ) + { qCritical()<actionSave->setEnabled(false); changeInFile = false; QFileInfo info(fileName); @@ -994,26 +1143,22 @@ void MainWindow::AutoSavePattern(){ } } -MainWindow::~MainWindow(){ +MainWindow::~MainWindow() +{ CanselTool(); delete ui; - QFile file("lekalo.xml"); - if(file.open(QIODevice::WriteOnly | QIODevice::Truncate)){ - const int Indent = 4; - QTextStream out(&file); - doc->save(out, Indent); - file.close(); - } - delete data; - if(!doc->isNull()){ + if (doc->isNull() == false) + { delete doc; } } -void MainWindow::OpenPattern(const QString &fileName){ - if(fileName.isEmpty()){ +void MainWindow::OpenPattern(const QString &fileName) +{ + if (fileName.isEmpty()) + { qWarning()<setContent(&file, &errorMsg, &errorLine, &errorColumn)){ + if (file.open(QIODevice::ReadOnly)) + { + if (doc->setContent(&file, &errorMsg, &errorLine, &errorColumn)) + { disconnect(comboBoxDraws, static_cast(&QComboBox::currentIndexChanged), this, &MainWindow::currentDrawChanged); - try{ - doc->Parse(Document::FullParse, sceneDraw, sceneDetails); + try + { + doc->Parse(Document::FullParse, sceneDraw, sceneDetails); } - catch(const VExceptionObjectError &e){ + catch (const VExceptionObjectError &e) + { QMessageBox msgBox; msgBox.setWindowTitle(tr("Error!")); msgBox.setText(tr("Error parsing file.")); @@ -1042,7 +1191,8 @@ void MainWindow::OpenPattern(const QString &fileName){ Clear(); return; } - catch(const VExceptionConversionError &e){ + catch (const VExceptionConversionError &e) + { QMessageBox msgBox; msgBox.setWindowTitle(tr("Error!")); msgBox.setText(tr("Error can't convert value.")); @@ -1055,7 +1205,8 @@ void MainWindow::OpenPattern(const QString &fileName){ Clear(); return; } - catch(const VExceptionEmptyParameter &e){ + catch (const VExceptionEmptyParameter &e) + { QMessageBox msgBox; msgBox.setWindowTitle(tr("Error!")); msgBox.setText(tr("Error empty parameter.")); @@ -1069,7 +1220,8 @@ void MainWindow::OpenPattern(const QString &fileName){ Clear(); return; } - catch(const VExceptionWrongParameterId &e){ + catch (const VExceptionWrongParameterId &e) + { QMessageBox msgBox; msgBox.setWindowTitle(tr("Error!")); msgBox.setText(tr("Error wrong id.")); @@ -1083,7 +1235,8 @@ void MainWindow::OpenPattern(const QString &fileName){ Clear(); return; } - catch(const VExceptionUniqueId &e){ + catch (const VExceptionUniqueId &e) + { QMessageBox msgBox; msgBox.setWindowTitle(tr("Error!")); msgBox.setText(tr("Error don't unique id.")); @@ -1101,16 +1254,22 @@ void MainWindow::OpenPattern(const QString &fileName){ this, &MainWindow::currentDrawChanged); QString nameDraw = doc->GetNameActivDraw(); qint32 index = comboBoxDraws->findText(nameDraw); - if ( index != -1 ) { // -1 for not found + if ( index != -1 ) + { // -1 for not found comboBoxDraws->setCurrentIndex(index); } - if(comboBoxDraws->count() > 0){ + if (comboBoxDraws->count() > 0) + { SetEnableTool(true); - } else { + } + else + { SetEnableTool(false); } SetEnableWidgets(true); - } else { + } + else + { QMessageBox msgBox; msgBox.setWindowTitle(tr("Error!")); msgBox.setText(tr("Error parsing pattern file.")); diff --git a/mainwindow.h b/mainwindow.h index 3d55ab212..2c0f2c47e 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file mainwindow.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,39 +24,35 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef MAINWINDOW_H #define MAINWINDOW_H #include -#include -#include -#include -#include -#include #include "widgets/vmaingraphicsscene.h" #include "widgets/vmaingraphicsview.h" #include "widgets/vitem.h" #include "dialogs/dialogs.h" +#include "tools/vtooldetail.h" #include "tools/drawTools/drawtools.h" #include "tools/modelingTools/modelingtools.h" #include "xml/vdomdocument.h" -#include "tools/vtooldetail.h" -namespace Ui { -class MainWindow; +namespace Ui +{ + class MainWindow; } class MainWindow : public QMainWindow { - Q_OBJECT + Q_OBJECT public: - explicit MainWindow(QWidget *parent = 0); + explicit MainWindow(QWidget *parent = 0); ~MainWindow(); void OpenPattern(const QString &fileName); public slots: - void mouseMove(QPointF scenePos); + void mouseMove(const QPointF &scenePos); void ActionAroowTool(); void ActionDraw(bool checked); void ActionDetails(bool checked); @@ -80,6 +83,9 @@ public slots: void ToolSplinePath(bool checked); void ToolPointOfContact(bool checked); void ToolDetail(bool checked); + void ToolHeight(bool checked); + void ToolTriangle(bool checked); + void ToolPointOfIntersection(bool checked); void ClosedDialogEndLine(int result); void ClosedDialogLine(int result); void ClosedDialogAlongLine(int result); @@ -92,6 +98,9 @@ public slots: void ClosedDialogSplinePath(int result); void ClosedDialogPointOfContact(int result); void ClosedDialogDetail(int result); + void ClosedDialogHeight(int result); + void ClosedDialogTriangle(int result); + void ClosedDialogPointOfIntersection(int result); void About(); void AboutQt(); void ShowToolTip(const QString &toolTip); @@ -123,25 +132,28 @@ private: VMainGraphicsView *view; bool isInitialized; DialogIncrements *dialogTable; - QSharedPointer dialogEndLine; - QSharedPointer dialogLine; - QSharedPointer dialogAlongLine; - QSharedPointer dialogShoulderPoint; - QSharedPointer dialogNormal; - QSharedPointer dialogBisector; - QSharedPointer dialogLineIntersect; - QSharedPointer dialogSpline; - QSharedPointer dialogArc; - QSharedPointer dialogSplinePath; - QSharedPointer dialogPointOfContact; - QSharedPointer dialogDetail; + QSharedPointer dialogEndLine; + QSharedPointer dialogLine; + QSharedPointer dialogAlongLine; + QSharedPointer dialogShoulderPoint; + QSharedPointer dialogNormal; + QSharedPointer dialogBisector; + QSharedPointer dialogLineIntersect; + QSharedPointer dialogSpline; + QSharedPointer dialogArc; + QSharedPointer dialogSplinePath; + QSharedPointer dialogPointOfContact; + QSharedPointer dialogDetail; + QSharedPointer dialogHeight; + QSharedPointer dialogTriangle; + QSharedPointer dialogPointOfIntersection; DialogHistory *dialogHistory; VDomDocument *doc; VContainer *data; QComboBox *comboBoxDraws; QString fileName; bool changeInFile; - Draw::Draws mode; + Draw::Draws mode; void ToolBarOption(); void ToolBarDraws(); void CanselTool(); @@ -149,13 +161,14 @@ private: void SetEnableWidgets(bool enable); void SetEnableTool(bool enable); template - void SetToolButton(bool checked, Tool::Tools t, const QString &cursor, - const QString &toolTip,QSharedPointer &dialog, - Func closeDialogSlot); + void SetToolButton(bool checked, Tool::Tools t, const QString &cursor, const QString &toolTip, + QSharedPointer &dialog, Func closeDialogSlot); void MinimumScrollBar(); template void AddToolToDetail(T *tool, const qint64 &id, Tool::Tools typeTool, const qint64 &idDetail); + template + void ClosedDialog(QSharedPointer &dialog, int result); bool SafeSaveing(const QString &fileName)const; void AutoSavePattern(); }; diff --git a/mainwindow.ui b/mainwindow.ui index 5a99c2733..2ea6899fd 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -48,7 +48,7 @@ 0 0 150 - 104 + 150
@@ -64,20 +64,20 @@ Point
- - + + false - Tool point of normal. + Tool point on the end line. ... - :/icon/32x32/normal.png:/icon/32x32/normal.png + :/icon/32x32/segment.png:/icon/32x32/segment.png @@ -116,46 +116,20 @@ - - + + false - Tool point on the end line. + Tool point of contact. ... - :/icon/32x32/segment.png:/icon/32x32/segment.png - - - - 32 - 32 - - - - true - - - - - - - false - - - Tool point along line. - - - ... - - - - :/icon/32x32/along_line.png:/icon/32x32/along_line.png + :/icon/32x32/point_of_contact.png:/icon/32x32/point_of_contact.png @@ -194,20 +168,121 @@ - - + + false - Tool point of contact. + Tool point of normal. ... - :/icon/32x32/point_of_contact.png:/icon/32x32/point_of_contact.png + :/icon/32x32/normal.png:/icon/32x32/normal.png + + + + 32 + 32 + + + + true + + + + + + + false + + + Tool point along line. + + + ... + + + + :/icon/32x32/along_line.png:/icon/32x32/along_line.png + + + + 32 + 32 + + + + true + + + + + + + false + + + Tool point of height. + + + ... + + + + :/icon/32x32/height.png:/icon/32x32/height.png + + + + 32 + 32 + + + + true + + + + + + + false + + + Tool triangle. + + + ... + + + + :/icon/32x32/triangle.png:/icon/32x32/triangle.png + + + + 32 + 32 + + + + true + + + + + + + false + + + ... + + + + :/icon/32x32/point_of_intersection.png:/icon/32x32/point_of_intersection.png @@ -303,7 +378,7 @@ 0 0 - 137 + 150 58 @@ -379,7 +454,7 @@ 0 0 - 137 + 150 58
diff --git a/options.h b/options.h index d2620f3dd..beccd32d3 100644 --- a/options.h +++ b/options.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file options.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,7 +24,7 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef OPTIONS_H #define OPTIONS_H @@ -28,44 +35,52 @@ #define PaperSize 50000 #define toPixel(mm) ((mm / 25.4) * PrintDPI) #define toMM(pix) ((pix / PrintDPI) * 25.4) -#define widthMainLine toPixel(0.8) +#define widthMainLine 1.2 #define widthHairLine widthMainLine/3 -namespace Scene{ -enum Scene { Point, Line, Spline, Arc, SplinePath, Detail }; -Q_DECLARE_FLAGS(Scenes, Scene) +namespace Scene +{ + enum Scene { Point, Line, Spline, Arc, SplinePath, Detail }; + Q_DECLARE_FLAGS(Scenes, Scene) } Q_DECLARE_OPERATORS_FOR_FLAGS( Scene::Scenes ) -namespace Tool{ -enum Tool {ArrowTool, - SinglePointTool, - EndLineTool, - LineTool, - AlongLineTool, - ShoulderPointTool, - NormalTool, - BisectorTool, - LineIntersectTool, - SplineTool, - ArcTool, - SplinePathTool, - PointOfContact, - Detail, - NodePoint, - NodeArc, - NodeSpline, - NodeSplinePath -}; -Q_DECLARE_FLAGS(Tools, Tool) +namespace Tool +{ + enum Tool + { + ArrowTool, + SinglePointTool, + EndLineTool, + LineTool, + AlongLineTool, + ShoulderPointTool, + NormalTool, + BisectorTool, + LineIntersectTool, + SplineTool, + ArcTool, + SplinePathTool, + PointOfContact, + Detail, + NodePoint, + NodeArc, + NodeSpline, + NodeSplinePath, + Height, + Triangle, + PointOfIntersection + }; + Q_DECLARE_FLAGS(Tools, Tool) -enum Source { FromGui, FromFile }; -Q_DECLARE_FLAGS(Sources, Source) + enum Source { FromGui, FromFile }; + Q_DECLARE_FLAGS(Sources, Source) } Q_DECLARE_OPERATORS_FOR_FLAGS( Tool::Tools ) Q_DECLARE_OPERATORS_FOR_FLAGS( Tool::Sources ) -namespace Draw { +namespace Draw +{ enum Draw { Calculation, Modeling }; Q_DECLARE_FLAGS(Draws, Draw) } diff --git a/stable.cpp b/stable.cpp new file mode 100644 index 000000000..57b3c2027 --- /dev/null +++ b/stable.cpp @@ -0,0 +1,30 @@ +/************************************************************************ + ** + ** @file stable.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +// Build the precompiled headers. +#include "stable.h" diff --git a/stable.h b/stable.h index fba2585c6..bcc23a610 100644 --- a/stable.h +++ b/stable.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file stable.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,7 +24,15 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ + +#ifndef STABLE_H +#define STABLE_H + +/* I like to include this pragma too, +so the build log indicates if pre-compiled headers +were in use. */ +#pragma message("Compiling precompiled headers.\n") /* Add C includes here */ @@ -31,3 +46,5 @@ #include #include "options.h" #endif + +#endif // STABLE_H diff --git a/tablewindow.cpp b/tablewindow.cpp index 3189b9845..132c3a5e8 100644 --- a/tablewindow.cpp +++ b/tablewindow.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file tablewindow.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,29 +24,27 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "tablewindow.h" #include "ui_tablewindow.h" -#include -#include #include "widgets/vtablegraphicsview.h" -#include #include "options.h" -#include +#include -TableWindow::TableWindow(QWidget *parent) : - QMainWindow(parent), numberDetal(0), colission(0), ui(new Ui::TableWindow), +TableWindow::TableWindow(QWidget *parent) + :QMainWindow(parent), numberDetal(0), colission(0), ui(new Ui::TableWindow), listDetails(QVector()), outItems(false), collidingItems(false), currentScene(0), paper(0), shadowPaper(0), listOutItems(0), listCollidingItems(QList()), - indexDetail(0), sceneRect(QRectF()){ + indexDetail(0), sceneRect(QRectF()) +{ ui->setupUi(this); numberDetal = new QLabel("Залишилось 0 деталей.", this); colission = new QLabel("Колізій не знайдено.", this); ui->statusBar->addWidget(numberDetal); ui->statusBar->addWidget(colission); outItems = collidingItems = false; - //sceneRect = QRectF(0, 0, 203*PrintDPI/25.4, 287*PrintDPI/25.4); + //sceneRect = QRectF(0, 0, toPixel(203), toPixel(287)); sceneRect = QRectF(0, 0, toPixel(823), toPixel(1171)); currentScene = new QGraphicsScene(sceneRect); QBrush *brush = new QBrush(); @@ -47,7 +52,7 @@ TableWindow::TableWindow(QWidget *parent) : brush->setColor( QColor( Qt::gray ) ); currentScene->setBackgroundBrush( *brush ); VTableGraphicsView* view = new VTableGraphicsView(currentScene); - view->fitInView(view->scene()->sceneRect(),Qt::KeepAspectRatio); + view->fitInView(view->scene()->sceneRect(), Qt::KeepAspectRatio); ui->horizontalLayout->addWidget(view); connect(ui->actionTurn, &QAction::triggered, view, &VTableGraphicsView::rotateItems); connect(ui->actionMirror, &QAction::triggered, view, &VTableGraphicsView::MirrorItem); @@ -61,41 +66,47 @@ TableWindow::TableWindow(QWidget *parent) : connect(view, &VTableGraphicsView::itemChect, this, &TableWindow::itemChect); } -TableWindow::~TableWindow(){ +TableWindow::~TableWindow() +{ delete ui; } -void TableWindow::AddPaper(){ +void TableWindow::AddPaper() +{ qreal x1, y1, x2, y2; sceneRect.getCoords(&x1, &y1, &x2, &y2); - shadowPaper = new QGraphicsRectItem(QRectF(x1+4,y1+4,x2+4, y2+4)); + shadowPaper = new QGraphicsRectItem(QRectF(x1+4, y1+4, x2+4, y2+4)); shadowPaper->setBrush(QBrush(Qt::black)); currentScene->addItem(shadowPaper); - paper = new QGraphicsRectItem(QRectF(x1,y1,x2, y2)); - paper->setPen(QPen(Qt::black, toPixel(widthMainLine))); + paper = new QGraphicsRectItem(QRectF(x1, y1, x2, y2)); + paper->setPen(QPen(Qt::black, widthMainLine)); paper->setBrush(QBrush(Qt::white)); currentScene->addItem(paper); qDebug()<rect().size().toSize(); } -void TableWindow::AddDetail(){ - if(indexDetailclearSelection(); VItem* Detail = listDetails[indexDetail]; - QObject::connect(Detail, SIGNAL(itemOut(int,bool)), this, SLOT(itemOut(int,bool))); - QObject::connect(Detail, SIGNAL(itemColliding(QList,int)), this, - SLOT(itemColliding(QList,int))); + QObject::connect(Detail, SIGNAL(itemOut(int, bool)), this, SLOT(itemOut(int, bool))); + QObject::connect(Detail, SIGNAL(itemColliding(QList, int)), this, + SLOT(itemColliding(QList, int))); QObject::connect(this, SIGNAL(LengthChanged()), Detail, SLOT(LengthChanged())); - Detail->setPen(QPen(Qt::black, toPixel(widthMainLine))); + Detail->setPen(QPen(Qt::black, 1)); Detail->setBrush(QBrush(Qt::white)); Detail->setPos(paper->boundingRect().center()); Detail->setFlag(QGraphicsItem::ItemIsMovable, true); Detail->setFlag(QGraphicsItem::ItemIsSelectable, true); Detail->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); - Detail->setParentItem(paper); + Detail->setPaper(paper); + currentScene->addItem(Detail); Detail->setSelected(true); indexDetail++; - if(indexDetail==listDetails.count()){ + if (indexDetail==listDetails.count()) + { ui->actionSave->setEnabled(true); } } @@ -105,7 +116,8 @@ void TableWindow::AddDetail(){ /* * Отримуємо деталі розрахованої моделі для подальшого укладання. */ -void TableWindow::ModelChosen(QVector listDetails){ +void TableWindow::ModelChosen(QVector listDetails) +{ this->listDetails = listDetails; listOutItems = new QBitArray(this->listDetails.count()); AddPaper(); @@ -114,23 +126,27 @@ void TableWindow::ModelChosen(QVector listDetails){ show(); } -void TableWindow::closeEvent(QCloseEvent *event){ +void TableWindow::closeEvent(QCloseEvent *event) +{ event->ignore(); StopTable(); } -void TableWindow::moveToCenter(){ +void TableWindow::moveToCenter() +{ QRect rect = frameGeometry(); rect.moveCenter(QDesktopWidget().availableGeometry().center()); move(rect.topLeft()); } -void TableWindow::showEvent ( QShowEvent * event ){ +void TableWindow::showEvent ( QShowEvent * event ) +{ QMainWindow::showEvent(event); moveToCenter(); } -void TableWindow::StopTable(){ +void TableWindow::StopTable() +{ hide(); currentScene->clear(); delete listOutItems; @@ -140,66 +156,77 @@ void TableWindow::StopTable(){ emit closed(); } -void TableWindow::saveScene(){ - QString name = QFileDialog::getSaveFileName(0, "Зберегти розкладку", "", "Images (*.png);;Svg files (*.svg)"); - if(name.isNull()){ +void TableWindow::saveScene() +{ + QString name = QFileDialog::getSaveFileName(0, tr("Save layout"), "", "Images (*.png);;Svg files (*.svg)"); + if (name.isNull()) + { return; } QBrush *brush = new QBrush(); brush->setColor( QColor( Qt::white ) ); currentScene->setBackgroundBrush( *brush ); - currentScene->clearSelection(); // Selections would also render to the file - shadowPaper->setBrush(QBrush(Qt::white)); - shadowPaper->setPen(QPen(Qt::white, 0.1)); - paper->setPen(QPen(Qt::white, 0.1)); - paper->setBrush(QBrush(Qt::white)); - currentScene->setSceneRect(QRectF(10,10,590,590)); - currentScene->setSceneRect(currentScene->itemsBoundingRect()); - + currentScene->clearSelection(); // Selections would also render to the file + shadowPaper->setVisible(false); QFileInfo fi(name); - if(fi.suffix() == "svg"){ + if (fi.suffix() == "svg") + { + paper->setVisible(false); SvgFile(name); - } else if(fi.suffix() == "png"){ - PngFile(name); + paper->setVisible(true); + } + else if (fi.suffix() == "png") + { + paper->setPen(QPen(Qt::white, 0.1, Qt::NoPen)); + PngFile(name); + paper->setPen(QPen(Qt::black, widthMainLine)); } -// if(name.indexOf(".svg",name.size()-4)<0){ -// name.append(".svg"); -// } brush->setColor( QColor( Qt::gray ) ); brush->setStyle( Qt::SolidPattern ); currentScene->setBackgroundBrush( *brush ); - paper->setPen(QPen(Qt::black, widthMainLine)); - shadowPaper->setBrush(QBrush(Qt::black)); + shadowPaper->setVisible(true); + delete brush; } -void TableWindow::itemChect(bool flag){ +void TableWindow::itemChect(bool flag) +{ ui->actionTurn->setDisabled(flag); ui->actionMirror->setDisabled(flag); } -void TableWindow::checkNext(){ - if(outItems == true && collidingItems == true){ +void TableWindow::checkNext() +{ + if (outItems == true && collidingItems == true) + { colission->setText("Колізій не знайдено."); - if(indexDetail==listDetails.count()){ + if (indexDetail==listDetails.count()) + { ui->actionSave->setEnabled(true); ui->actionNext->setDisabled(true); - } else { + } + else + { ui->actionNext->setDisabled(false); ui->actionSave->setEnabled(false); } - } else { + } + else + { colission->setText("Знайдено колізії."); ui->actionNext->setDisabled(true); ui->actionSave->setEnabled(false); } } -void TableWindow::itemOut(int number, bool flag){ - listOutItems->setBit(number,flag); - for( int i = 0; i < listOutItems->count(); ++i ){ - if(listOutItems->at(i)==true){ +void TableWindow::itemOut(int number, bool flag) +{ + listOutItems->setBit(number, flag); + for ( int i = 0; i < listOutItems->count(); ++i ) + { + if (listOutItems->at(i)==true) + { outItems=false; qDebug()<<"itemOut::outItems="< list, int number){ +void TableWindow::itemColliding(QList list, int number) +{ //qDebug()<<"number="<1){ - for( int i = 0; i < listCollidingItems.count(); ++i ){ - QList l = listCollidingItems.at(i)->collidingItems(); - if(l.size()-2 <= 0){ + if (listCollidingItems.size()>1) + { + for ( int i = 0; i < listCollidingItems.count(); ++i ) + { + QList lis = listCollidingItems.at(i)->collidingItems(); + if (lis.size()-2 <= 0) + { VItem * bitem = qgraphicsitem_cast ( listCollidingItems.at(i) ); - if (bitem == 0){ + if (bitem == 0) + { qDebug()<<"Не можу привести тип об'єкту"; - } else { - bitem->setPen(QPen(Qt::black, toPixel(widthMainLine))); + } + else + { + bitem->setPen(QPen(Qt::black, widthMainLine)); } listCollidingItems.removeAt(i); } } - } else if(listCollidingItems.size()==1){ + } + else if (listCollidingItems.size()==1) + { VItem * bitem = qgraphicsitem_cast ( listCollidingItems.at(0) ); - if (bitem == 0){ + if (bitem == 0) + { qDebug()<<"Не можу привести тип об'єкту"; - } else { - bitem->setPen(QPen(Qt::black, toPixel(widthMainLine))); + } + else + { + bitem->setPen(QPen(Qt::black, widthMainLine)); } listCollidingItems.clear(); collidingItems = true; } - } else { + } + else + { collidingItems = true; } - } else { + } + else + { collidingItems = true; } - } else if(number==1){ - if(list.contains(paper)==true){ + } + else if (number==1) + { + if (list.contains(paper)==true) + { list.removeAt(list.indexOf(paper)); } - if(list.contains(shadowPaper)==true){ + if (list.contains(shadowPaper)==true) + { list.removeAt(list.indexOf(shadowPaper)); } - for( int i = 0; i < list.count(); ++i ){ - if(listCollidingItems.contains(list.at(i))==false){ + for ( int i = 0; i < list.count(); ++i ) + { + if (listCollidingItems.contains(list.at(i))==false) + { listCollidingItems.append(list.at(i)); } } @@ -263,11 +315,13 @@ void TableWindow::itemColliding(QList list, int number){ checkNext(); } -void TableWindow::GetNextDetail(){ +void TableWindow::GetNextDetail() +{ AddDetail(); } -void TableWindow::AddLength(){ +void TableWindow::AddLength() +{ QRectF rect = currentScene->sceneRect(); rect.setHeight(rect.height()+toPixel(279)); currentScene->setSceneRect(rect); @@ -281,8 +335,10 @@ void TableWindow::AddLength(){ emit LengthChanged(); } -void TableWindow::RemoveLength(){ - if(sceneRect.height()<=currentScene->sceneRect().height()-100){ +void TableWindow::RemoveLength() +{ + if (sceneRect.height() <= currentScene->sceneRect().height() - 100) + { QRectF rect = currentScene->sceneRect(); rect.setHeight(rect.height()-toPixel(279)); currentScene->setSceneRect(rect); @@ -292,18 +348,24 @@ void TableWindow::RemoveLength(){ rect = paper->rect(); rect.setHeight(rect.height()-toPixel(279)); paper->setRect(rect); - if(sceneRect.height()==currentScene->sceneRect().height()){ + if (fabs(sceneRect.height() - currentScene->sceneRect().height()) < 0.01) + { ui->actionRemove->setDisabled(true); } emit LengthChanged(); - } else { + } + else + { ui->actionRemove->setDisabled(true); } } -void TableWindow::keyPressEvent ( QKeyEvent * event ){ - if( event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return ){ - if(ui->actionNext->isEnabled() == true ){ +void TableWindow::keyPressEvent ( QKeyEvent * event ) +{ + if ( event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return ) + { + if (ui->actionNext->isEnabled() == true ) + { AddDetail(); qDebug()<<"Додали деталь."; } @@ -312,34 +374,38 @@ void TableWindow::keyPressEvent ( QKeyEvent * event ){ } -void TableWindow::SvgFile(const QString &name) const{ +void TableWindow::SvgFile(const QString &name) const +{ QSvgGenerator generator; generator.setFileName(name); generator.setSize(paper->rect().size().toSize()); - //generator.setViewBox(QRect(0, 0, 200, 200)); generator.setTitle(tr("SVG Generator Example Drawing")); generator.setDescription(tr("An SVG drawing created by the SVG Generator " "Example provided with Qt.")); + generator.setResolution(PrintDPI); + qDebug()<<"resolution is" << generator.resolution(); QPainter painter; painter.begin(&generator); painter.setFont( QFont( "Arial", 8, QFont::Normal ) ); painter.setRenderHint(QPainter::Antialiasing, true); - painter.setPen(QPen(Qt::black, widthMainLine, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); + painter.setPen(QPen(Qt::black, 1.2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); painter.setBrush ( QBrush ( Qt::NoBrush ) ); currentScene->render(&painter); painter.end(); } -void TableWindow::PngFile(const QString &name) const{ +void TableWindow::PngFile(const QString &name) const +{ QRectF r = paper->rect(); qreal x=0, y=0, w=0, h=0; - r.getRect(&x,&y,&w,&h);// Re-shrink the scene to it's bounding contents - QImage image(QSize(static_cast(w), static_cast(h)), QImage::Format_ARGB32); // Create the image with the exact size of the shrunk scene + r.getRect(&x, &y, &w, &h);// Re-shrink the scene to it's bounding contents + // Create the image with the exact size of the shrunk scene + QImage image(QSize(static_cast(w), static_cast(h)), QImage::Format_ARGB32); image.fill(Qt::transparent); // Start all pixels transparent QPainter painter(&image); painter.setFont( QFont( "Arial", 8, QFont::Normal ) ); painter.setRenderHint(QPainter::Antialiasing, true); - painter.setPen(QPen(Qt::black, toPixel(widthMainLine), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); + painter.setPen(QPen(Qt::black, widthMainLine, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); painter.setBrush ( QBrush ( Qt::NoBrush ) ); currentScene->render(&painter); image.save(name); diff --git a/tablewindow.h b/tablewindow.h index a8604a8bf..8d3ca8801 100644 --- a/tablewindow.h +++ b/tablewindow.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file tablewindow.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,23 +24,24 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef TABLEWINDOW_H #define TABLEWINDOW_H #include -#include #include "widgets/vitem.h" -namespace Ui { +namespace Ui +{ class TableWindow; } /** * @brief TableWindow клас вікна створення розкладки. */ -class TableWindow : public QMainWindow{ +class TableWindow : public QMainWindow +{ Q_OBJECT public: /** @@ -48,7 +56,7 @@ public: * @brief TableWindow Конструктор класу вікна створення розкладки. * @param parent Батько об'єкту. За замовчуванням = 0. */ - explicit TableWindow(QWidget *parent = 0); + explicit TableWindow(QWidget *parent = 0); /** * @brief ~TableWindow Деструктор класу вікна. */ diff --git a/tools/drawTools/drawtools.h b/tools/drawTools/drawtools.h index 0d2c5b613..b0102c570 100644 --- a/tools/drawTools/drawtools.h +++ b/tools/drawTools/drawtools.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file drawtools.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,7 +24,7 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef DRAWTOOLS_H #define DRAWTOOLS_H @@ -34,5 +41,8 @@ #include "vtoolsinglepoint.h" #include "vtoolspline.h" #include "vtoolsplinepath.h" +#include "vtoolheight.h" +#include "vtooltriangle.h" +#include "vtoolpointofintersection.h" #endif // DRAWTOOLS_H diff --git a/tools/drawTools/vdrawtool.cpp b/tools/drawTools/vdrawtool.cpp index 89164341b..20c93c55b 100644 --- a/tools/drawTools/vdrawtool.cpp +++ b/tools/drawTools/vdrawtool.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vdrawtool.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,35 +24,37 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "vdrawtool.h" -#include -VDrawTool::VDrawTool(VDomDocument *doc, VContainer *data, qint64 id, QObject *parent) : - VAbstractTool(doc, data, id, parent), ignoreContextMenuEvent(false), - nameActivDraw(doc->GetNameActivDraw()){ +qreal VDrawTool::factor = 1; + +VDrawTool::VDrawTool(VDomDocument *doc, VContainer *data, qint64 id, QObject *parent) + :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); connect(this->doc, &VDomDocument::ShowTool, this, &VDrawTool::ShowTool); } -VDrawTool::~VDrawTool(){ -} - -void VDrawTool::setDialog(){ -} - -void VDrawTool::AddRecord(const qint64 id, Tool::Tools toolType, VDomDocument *doc){ +void VDrawTool::AddRecord(const qint64 id, const Tool::Tools &toolType, VDomDocument *doc) +{ qint64 cursor = doc->getCursor(); QVector *history = doc->getHistory(); - if(cursor <= 0){ + if (cursor <= 0) + { history->append(VToolRecord(id, toolType, doc->GetNameActivDraw())); - } else { + } + else + { qint32 index = 0; - for(qint32 i = 0; isize(); ++i){ + for (qint32 i = 0; isize(); ++i) + { VToolRecord rec = history->at(i); - if(rec.getId() == cursor){ + if (rec.getId() == cursor) + { index = i; break; } @@ -54,48 +63,69 @@ void VDrawTool::AddRecord(const qint64 id, Tool::Tools toolType, VDomDocument *d } } -void VDrawTool::ignoreContextMenu(bool enable){ - ignoreContextMenuEvent = enable; -} - -void VDrawTool::ShowTool(qint64 id, Qt::GlobalColor color, bool enable){ +void VDrawTool::ShowTool(qint64 id, Qt::GlobalColor color, bool enable) +{ Q_UNUSED(id); Q_UNUSED(color); Q_UNUSED(enable); } -void VDrawTool::ChangedActivDraw(const QString newName){ - if(nameActivDraw == newName){ +void VDrawTool::ChangedActivDraw(const QString &newName) +{ + if (nameActivDraw == newName) + { ignoreContextMenuEvent = false; - } else { + } + else + { ignoreContextMenuEvent = true; } } -void VDrawTool::ChangedNameDraw(const QString oldName, const QString newName){ - if(nameActivDraw == oldName){ +void VDrawTool::ChangedNameDraw(const QString &oldName, const QString &newName) +{ + if (nameActivDraw == oldName) + { nameActivDraw = newName; } } -void VDrawTool::AddToCalculation(const QDomElement &domElement){ +void VDrawTool::SetFactor(qreal factor) +{ + if (factor <= 2 && factor >= 0.5) + { + this->factor = factor; + } +} + +void VDrawTool::AddToCalculation(const QDomElement &domElement) +{ QDomElement calcElement; bool ok = doc->GetActivCalculationElement(calcElement); - if(ok){ + if (ok) + { qint64 id = doc->getCursor(); - if(id <= 0){ + if (id <= 0) + { calcElement.appendChild(domElement); - } else { + } + else + { QDomElement refElement = doc->elementById(QString().setNum(doc->getCursor())); - if(refElement.isElement()){ - calcElement.insertAfter(domElement,refElement); + if (refElement.isElement()) + { + calcElement.insertAfter(domElement, refElement); doc->setCursor(0); - } else { - qCritical()<<"Не можу знайти елемент після якого потрібно вставляти."<< Q_FUNC_INFO; + } + else + { + qCritical()< + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,81 +24,116 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef VDRAWTOOL_H #define VDRAWTOOL_H #include "../vabstracttool.h" -#include -class VDrawTool : public VAbstractTool{ +class VDrawTool : public VAbstractTool +{ Q_OBJECT public: VDrawTool(VDomDocument *doc, VContainer *data, qint64 id, QObject *parent = 0); - virtual ~VDrawTool(); - virtual void setDialog(); - static void AddRecord(const qint64 id, Tool::Tools toolType, VDomDocument *doc); - void ignoreContextMenu(bool enable); + virtual ~VDrawTool() {} + virtual void setDialog() {} + static void AddRecord(const qint64 id, const Tool::Tools &toolType, VDomDocument *doc); + void ignoreContextMenu(bool enable) {ignoreContextMenuEvent = enable;} public slots: virtual void ShowTool(qint64 id, Qt::GlobalColor color, bool enable); - virtual void ChangedActivDraw(const QString newName); - void ChangedNameDraw(const QString oldName, const QString newName); + virtual void ChangedActivDraw(const QString &newName); + void ChangedNameDraw(const QString &oldName, const QString &newName); virtual void FullUpdateFromGui(int result)=0; -signals: - void RemoveTool(QGraphicsItem *tool); + virtual void SetFactor(qreal factor); protected: bool ignoreContextMenuEvent; + bool ignoreFullUpdate; QString nameActivDraw; + static qreal factor; void AddToCalculation(const QDomElement &domElement); template void ContextMenu(QSharedPointer &dialog, Tool *tool, QGraphicsSceneContextMenuEvent *event, - bool showRemove = true){ - if(!ignoreContextMenuEvent){ + bool showRemove = true) + { + Q_ASSERT(tool != 0); + Q_ASSERT(event != 0); + if (ignoreContextMenuEvent == false) + { QMenu menu; QAction *actionOption = menu.addAction(tr("Options")); QAction *actionRemove = 0; - if(showRemove){ + if (showRemove) + { actionRemove = menu.addAction(tr("Delete")); - if(_referens > 1){ + if (_referens > 1) + { actionRemove->setEnabled(false); - } else { + } + else + { actionRemove->setEnabled(true); } } QAction *selectedAction = menu.exec(event->screenPos()); - if(selectedAction == actionOption){ + if (selectedAction == actionOption) + { dialog = QSharedPointer(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 == false) + { + connect(doc, &VDomDocument::FullUpdateFromFile, dialog.data(), &Dialog::UpdateList); + } tool->setDialog(); dialog->show(); } - 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); + 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); + } } } } } } + template + 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 diff --git a/tools/drawTools/vtoolalongline.cpp b/tools/drawTools/vtoolalongline.cpp index e0237cbdd..c8bb272c2 100644 --- a/tools/drawTools/vtoolalongline.cpp +++ b/tools/drawTools/vtoolalongline.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vtoolalongline.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,93 +24,108 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "vtoolalongline.h" -#include -#include -#include "container/calculator.h" +#include "../../container/calculator.h" + +const QString VToolAlongLine::ToolType = QStringLiteral("alongLine"); VToolAlongLine::VToolAlongLine(VDomDocument *doc, VContainer *data, qint64 id, const QString &formula, const qint64 &firstPointId, const qint64 &secondPointId, - const QString &typeLine, Tool::Sources typeCreation, - QGraphicsItem *parent): - VToolLinePoint(doc, data, id, typeLine, formula, firstPointId, 0, parent), secondPointId(secondPointId), - dialogAlongLine(QSharedPointer()){ + const QString &typeLine, const Tool::Sources &typeCreation, + QGraphicsItem *parent) + :VToolLinePoint(doc, data, id, typeLine, formula, firstPointId, 0, parent), secondPointId(secondPointId), + dialogAlongLine(QSharedPointer()) +{ - if(typeCreation == Tool::FromGui){ + if (typeCreation == Tool::FromGui) + { AddToFile(); } } -void VToolAlongLine::FullUpdateFromFile(){ +void VToolAlongLine::FullUpdateFromFile() +{ QDomElement domElement = doc->elementById(QString().setNum(id)); - if(domElement.isElement()){ - typeLine = domElement.attribute("typeLine", ""); - formula = domElement.attribute("length", ""); - basePointId = domElement.attribute("firstPoint", "").toLongLong(); - secondPointId = domElement.attribute("secondPoint", "").toLongLong(); + if (domElement.isElement()) + { + typeLine = domElement.attribute(AttrTypeLine, ""); + formula = domElement.attribute(AttrLength, ""); + basePointId = domElement.attribute(AttrFirstPoint, "").toLongLong(); + secondPointId = domElement.attribute(AttrSecondPoint, "").toLongLong(); } RefreshGeometry(); } -void VToolAlongLine::FullUpdateFromGui(int result){ - if(result == QDialog::Accepted){ +void VToolAlongLine::FullUpdateFromGui(int result) +{ + if (result == QDialog::Accepted) + { QDomElement domElement = doc->elementById(QString().setNum(id)); - if(domElement.isElement()){ - domElement.setAttribute("name", dialogAlongLine->getPointName()); - domElement.setAttribute("typeLine", dialogAlongLine->getTypeLine()); - domElement.setAttribute("length", dialogAlongLine->getFormula()); - domElement.setAttribute("firstPoint", QString().setNum(dialogAlongLine->getFirstPointId())); - domElement.setAttribute("secondPoint", QString().setNum(dialogAlongLine->getSecondPointId())); + if (domElement.isElement()) + { + domElement.setAttribute(AttrName, dialogAlongLine->getPointName()); + domElement.setAttribute(AttrTypeLine, dialogAlongLine->getTypeLine()); + domElement.setAttribute(AttrLength, dialogAlongLine->getFormula()); + domElement.setAttribute(AttrFirstPoint, QString().setNum(dialogAlongLine->getFirstPointId())); + domElement.setAttribute(AttrSecondPoint, QString().setNum(dialogAlongLine->getSecondPointId())); emit FullUpdateTree(); } - } dialogAlongLine.clear(); } -void VToolAlongLine::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ +void VToolAlongLine::SetFactor(qreal factor) +{ + VDrawTool::SetFactor(factor); + RefreshGeometry(); +} + +void VToolAlongLine::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) +{ ContextMenu(dialogAlongLine, this, event); } -void VToolAlongLine::AddToFile(){ +void VToolAlongLine::AddToFile() +{ VPointF point = VAbstractTool::data.GetPoint(id); - QDomElement domElement = doc->createElement("point"); + QDomElement domElement = doc->createElement(TagName); - 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, AttrId, id); + AddAttribute(domElement, AttrType, ToolType); + AddAttribute(domElement, AttrName, point.name()); + AddAttribute(domElement, AttrMx, toMM(point.mx())); + AddAttribute(domElement, AttrMy, toMM(point.my())); - AddAttribute(domElement, "typeLine", typeLine); - AddAttribute(domElement, "length", formula); - AddAttribute(domElement, "firstPoint", basePointId); - AddAttribute(domElement, "secondPoint", secondPointId); + AddAttribute(domElement, AttrTypeLine, typeLine); + AddAttribute(domElement, AttrLength, formula); + AddAttribute(domElement, AttrFirstPoint, basePointId); + AddAttribute(domElement, AttrSecondPoint, secondPointId); AddToCalculation(domElement); } -void VToolAlongLine::RemoveReferens(){ +void VToolAlongLine::RemoveReferens() +{ doc->DecrementReferens(secondPointId); VToolLinePoint::RemoveReferens(); } -void VToolAlongLine::setDialog(){ - Q_ASSERT(!dialogAlongLine.isNull()); - if(!dialogAlongLine.isNull()){ - VPointF p = VAbstractTool::data.GetPoint(id); - dialogAlongLine->setTypeLine(typeLine); - dialogAlongLine->setFormula(formula); - dialogAlongLine->setFirstPointId(basePointId, id); - dialogAlongLine->setSecondPointId(secondPointId, id); - dialogAlongLine->setPointName(p.name()); - } +void VToolAlongLine::setDialog() +{ + Q_ASSERT(dialogAlongLine.isNull() == false); + VPointF p = VAbstractTool::data.GetPoint(id); + dialogAlongLine->setTypeLine(typeLine); + dialogAlongLine->setFormula(formula); + dialogAlongLine->setFirstPointId(basePointId, id); + dialogAlongLine->setSecondPointId(secondPointId, id); + dialogAlongLine->setPointName(p.name()); } void VToolAlongLine::Create(QSharedPointer &dialog, VMainGraphicsScene *scene, - VDomDocument *doc, VContainer *data){ + VDomDocument *doc, VContainer *data) +{ QString formula = dialog->getFormula(); qint64 firstPointId = dialog->getFirstPointId(); qint64 secondPointId = dialog->getSecondPointId(); @@ -116,33 +138,43 @@ void VToolAlongLine::Create(QSharedPointer &dialog, VMainGraphi void VToolAlongLine::Create(const qint64 _id, const QString &pointName, const QString &typeLine, const QString &formula, const qint64 &firstPointId, const qint64 &secondPointId, const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data, const Document::Documents &parse, Tool::Sources typeCreation){ + VContainer *data, const Document::Documents &parse, const Tool::Sources &typeCreation) +{ VPointF firstPoint = data->GetPoint(firstPointId); VPointF secondPoint = data->GetPoint(secondPointId); QLineF line = QLineF(firstPoint.toQPointF(), secondPoint.toQPointF()); Calculator cal(data); QString errorMsg; qreal result = cal.eval(formula, &errorMsg); - if(errorMsg.isEmpty()){ + if (errorMsg.isEmpty()) + { line.setLength(toPixel(result)); qint64 id = _id; - if(typeCreation == Tool::FromGui){ + if (typeCreation == Tool::FromGui) + { id = data->AddPoint(VPointF(line.p2().x(), line.p2().y(), pointName, mx, my)); - } else { + data->AddLine(firstPointId, id); + data->AddLine(id, secondPointId); + } + else + { data->UpdatePoint(id, VPointF(line.p2().x(), line.p2().y(), pointName, mx, my)); - if(parse != Document::FullParse){ + data->AddLine(firstPointId, id); + data->AddLine(id, secondPointId); + if (parse != Document::FullParse) + { doc->UpdateToolData(id, data); } } VDrawTool::AddRecord(id, Tool::AlongLineTool, doc); - data->AddLine(firstPointId, id); - data->AddLine(id, secondPointId); - if(parse == Document::FullParse){ + if (parse == Document::FullParse) + { VToolAlongLine *point = new VToolAlongLine(doc, data, id, formula, firstPointId, secondPointId, typeLine, typeCreation); scene->addItem(point); connect(point, &VToolAlongLine::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); connect(point, &VToolAlongLine::RemoveTool, scene, &VMainGraphicsScene::RemoveTool); + connect(scene, &VMainGraphicsScene::NewFactor, point, &VToolAlongLine::SetFactor); doc->AddTool(id, point); doc->IncrementReferens(firstPointId); doc->IncrementReferens(secondPointId); diff --git a/tools/drawTools/vtoolalongline.h b/tools/drawTools/vtoolalongline.h index aede99661..797383e95 100644 --- a/tools/drawTools/vtoolalongline.h +++ b/tools/drawTools/vtoolalongline.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vtoolalongline.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,38 +24,40 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef VTOOLALONGLINE_H #define VTOOLALONGLINE_H #include "vtoollinepoint.h" -#include "dialogs/dialogalongline.h" +#include "../../dialogs/dialogalongline.h" 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); - virtual void setDialog(); - static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data); - static void Create(const qint64 _id, const QString &pointName, const QString &typeLine, - const QString &formula, const qint64 &firstPointId, const qint64 &secondPointId, - const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data, const Document::Documents &parse, Tool::Sources typeCreation); + VToolAlongLine(VDomDocument *doc, VContainer *data, qint64 id, const QString &formula, + const qint64 &firstPointId, const qint64 &secondPointId, const QString &typeLine, + const Tool::Sources &typeCreation, QGraphicsItem * parent = 0); + virtual void setDialog(); + static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, + VContainer *data); + static void Create(const qint64 _id, const QString &pointName, const QString &typeLine, const QString &formula, + const qint64 &firstPointId, const qint64 &secondPointId, const qreal &mx, const qreal &my, + VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, + const Document::Documents &parse, const Tool::Sources &typeCreation); + static const QString ToolType; public slots: - virtual void FullUpdateFromFile(); - virtual void FullUpdateFromGui(int result); + virtual void FullUpdateFromFile(); + virtual void FullUpdateFromGui(int result); + virtual void SetFactor(qreal factor); protected: - virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile(); - virtual void RemoveReferens(); + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void AddToFile(); + virtual void RemoveReferens(); private: - qint64 secondPointId; - QSharedPointer dialogAlongLine; + qint64 secondPointId; + QSharedPointer dialogAlongLine; }; #endif // VTOOLALONGLINE_H diff --git a/tools/drawTools/vtoolarc.cpp b/tools/drawTools/vtoolarc.cpp index 84d453f8e..9951bfcfb 100644 --- a/tools/drawTools/vtoolarc.cpp +++ b/tools/drawTools/vtoolarc.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vtoolarc.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,41 +24,46 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "vtoolarc.h" -#include "container/calculator.h" +#include "../../container/calculator.h" -VToolArc::VToolArc(VDomDocument *doc, VContainer *data, qint64 id, Tool::Sources typeCreation, - QGraphicsItem *parent):VDrawTool(doc, data, id), QGraphicsPathItem(parent), - dialogArc(QSharedPointer()){ +const QString VToolArc::TagName = QStringLiteral("arc"); +const QString VToolArc::ToolType = QStringLiteral("simple"); + +VToolArc::VToolArc(VDomDocument *doc, VContainer *data, qint64 id, const Tool::Sources &typeCreation, + QGraphicsItem *parent) + :VDrawTool(doc, data, id), QGraphicsPathItem(parent), dialogArc(QSharedPointer()) +{ VArc arc = data->GetArc(id); QPainterPath path; path.addPath(arc.GetPath()); path.setFillRule( Qt::WindingFill ); this->setPath(path); - this->setPen(QPen(Qt::black, widthHairLine)); + this->setPen(QPen(Qt::black, widthHairLine/factor)); this->setFlag(QGraphicsItem::ItemIsSelectable, true); this->setAcceptHoverEvents(true); - if(typeCreation == Tool::FromGui){ + if (typeCreation == Tool::FromGui) + { AddToFile(); } } -void VToolArc::setDialog(){ - Q_ASSERT(!dialogArc.isNull()); - if(!dialogArc.isNull()){ - VArc arc = VAbstractTool::data.GetArc(id); - dialogArc->SetCenter(arc.GetCenter()); - dialogArc->SetRadius(arc.GetFormulaRadius()); - dialogArc->SetF1(arc.GetFormulaF1()); - dialogArc->SetF2(arc.GetFormulaF2()); - } +void VToolArc::setDialog() +{ + Q_ASSERT(dialogArc.isNull() == false); + VArc arc = VAbstractTool::data.GetArc(id); + dialogArc->SetCenter(arc.GetCenter()); + dialogArc->SetF1(arc.GetFormulaF1()); + dialogArc->SetF2(arc.GetFormulaF2()); + dialogArc->SetRadius(arc.GetFormulaRadius()); } void VToolArc::Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data){ + VContainer *data) +{ qint64 center = dialog->GetCenter(); QString radius = dialog->GetRadius(); QString f1 = dialog->GetF1(); @@ -60,42 +72,52 @@ void VToolArc::Create(QSharedPointer &dialog, VMainGraphicsScene *sce } void VToolArc::Create(const qint64 _id, const qint64 ¢er, const QString &radius, const QString &f1, - const QString &f2, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data, const Document::Documents &parse, Tool::Sources typeCreation){ + const QString &f2, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, + const Document::Documents &parse, const Tool::Sources &typeCreation) +{ qreal calcRadius = 0, calcF1 = 0, calcF2 = 0; Calculator cal(data); QString errorMsg; qreal result = cal.eval(radius, &errorMsg); - if(errorMsg.isEmpty()){ - calcRadius = result*PrintDPI/25.4; + if (errorMsg.isEmpty()) + { + calcRadius = toPixel(result); } errorMsg.clear(); result = cal.eval(f1, &errorMsg); - if(errorMsg.isEmpty()){ + if (errorMsg.isEmpty()) + { calcF1 = result; } errorMsg.clear(); result = cal.eval(f2, &errorMsg); - if(errorMsg.isEmpty()){ + if (errorMsg.isEmpty()) + { calcF2 = result; } VArc arc = VArc(data->DataPoints(), center, calcRadius, radius, calcF1, f1, calcF2, f2 ); qint64 id = _id; - if(typeCreation == Tool::FromGui){ + if (typeCreation == Tool::FromGui) + { id = data->AddArc(arc); - } else { + data->AddLengthArc(arc.name(), toMM(arc.GetLength())); + } + else + { data->UpdateArc(id, arc); - if(parse != Document::FullParse){ + data->AddLengthArc(arc.name(), toMM(arc.GetLength())); + if (parse != Document::FullParse) + { doc->UpdateToolData(id, data); } } - data->AddLengthArc(data->GetNameArc(center,id), arc.GetLength()); VDrawTool::AddRecord(id, Tool::ArcTool, doc); - if(parse == Document::FullParse){ + if (parse == Document::FullParse) + { VToolArc *toolArc = new VToolArc(doc, data, id, typeCreation); scene->addItem(toolArc); connect(toolArc, &VToolArc::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); @@ -105,91 +127,108 @@ void VToolArc::Create(const qint64 _id, const qint64 ¢er, const QString &rad } } -void VToolArc::FullUpdateFromFile(){ +void VToolArc::FullUpdateFromFile() +{ RefreshGeometry(); } -void VToolArc::FullUpdateFromGui(int result){ - if(result == QDialog::Accepted){ +void VToolArc::FullUpdateFromGui(int result) +{ + if (result == QDialog::Accepted) + { QDomElement domElement = doc->elementById(QString().setNum(id)); - if(domElement.isElement()){ - domElement.setAttribute("center", QString().setNum(dialogArc->GetCenter())); - domElement.setAttribute("radius", dialogArc->GetRadius()); - domElement.setAttribute("angle1", dialogArc->GetF1()); - domElement.setAttribute("angle2", dialogArc->GetF2()); + if (domElement.isElement()) + { + domElement.setAttribute(AttrCenter, QString().setNum(dialogArc->GetCenter())); + domElement.setAttribute(AttrRadius, dialogArc->GetRadius()); + domElement.setAttribute(AttrAngle1, dialogArc->GetF1()); + domElement.setAttribute(AttrAngle2, dialogArc->GetF2()); emit FullUpdateTree(); } } dialogArc.clear(); } -void VToolArc::ChangedActivDraw(const QString newName){ - if(nameActivDraw == newName){ - this->setPen(QPen(Qt::black, widthHairLine)); - this->setFlag(QGraphicsItem::ItemIsSelectable, true); - this->setAcceptHoverEvents(true); - VDrawTool::ChangedActivDraw(newName); - } else { - this->setPen(QPen(Qt::gray, widthHairLine)); - this->setFlag(QGraphicsItem::ItemIsSelectable, false); - this->setAcceptHoverEvents (false); - VDrawTool::ChangedActivDraw(newName); +void VToolArc::ChangedActivDraw(const QString &newName) +{ + bool selectable = false; + if (nameActivDraw == newName) + { + selectable = true; + currentColor = Qt::black; } + else + { + selectable = false; + currentColor = Qt::gray; + } + 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)); - currentColor = baseColor; - } else { - this->setPen(QPen(color, widthHairLine)); - currentColor = color; - } - } +void VToolArc::ShowTool(qint64 id, Qt::GlobalColor color, bool enable) +{ + ShowItem(this, id, color, enable); } -void VToolArc::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ +void VToolArc::SetFactor(qreal factor) +{ + VDrawTool::SetFactor(factor); + RefreshGeometry(); +} + +void VToolArc::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) +{ ContextMenu(dialogArc, this, event); } -void VToolArc::AddToFile(){ +void VToolArc::AddToFile() +{ VArc arc = VAbstractTool::data.GetArc(id); - QDomElement domElement = doc->createElement("arc"); + QDomElement domElement = doc->createElement(TagName); - AddAttribute(domElement, "id", id); - AddAttribute(domElement, "type", "simple"); - AddAttribute(domElement, "center", arc.GetCenter()); - AddAttribute(domElement, "radius", arc.GetFormulaRadius()); - AddAttribute(domElement, "angle1", arc.GetFormulaF1()); - AddAttribute(domElement, "angle2", arc.GetFormulaF2()); + AddAttribute(domElement, AttrId, id); + AddAttribute(domElement, AttrType, ToolType); + AddAttribute(domElement, AttrCenter, arc.GetCenter()); + AddAttribute(domElement, AttrRadius, arc.GetFormulaRadius()); + AddAttribute(domElement, AttrAngle1, arc.GetFormulaF1()); + AddAttribute(domElement, AttrAngle2, arc.GetFormulaF2()); AddToCalculation(domElement); } -void VToolArc::mouseReleaseEvent(QGraphicsSceneMouseEvent *event){ - if(event->button() == Qt::LeftButton){ +void VToolArc::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +{ + if (event->button() == Qt::LeftButton) + { emit ChoosedTool(id, Scene::Arc); } QGraphicsItem::mouseReleaseEvent(event); } -void VToolArc::hoverMoveEvent(QGraphicsSceneHoverEvent *event){ +void VToolArc::hoverMoveEvent(QGraphicsSceneHoverEvent *event) +{ Q_UNUSED(event); - this->setPen(QPen(currentColor, widthMainLine)); + this->setPen(QPen(currentColor, widthMainLine/factor)); } -void VToolArc::hoverLeaveEvent(QGraphicsSceneHoverEvent *event){ +void VToolArc::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) +{ Q_UNUSED(event); - this->setPen(QPen(currentColor, widthHairLine)); + this->setPen(QPen(currentColor, widthHairLine/factor)); } -void VToolArc::RemoveReferens(){ +void VToolArc::RemoveReferens() +{ VArc arc = VAbstractTool::data.GetArc(id); doc->DecrementReferens(arc.GetCenter()); } -void VToolArc::RefreshGeometry(){ +void VToolArc::RefreshGeometry() +{ + this->setPen(QPen(currentColor, widthHairLine/factor)); VArc arc = VAbstractTool::data.GetArc(id); QPainterPath path; path.addPath(arc.GetPath()); diff --git a/tools/drawTools/vtoolarc.h b/tools/drawTools/vtoolarc.h index f78f26bbc..17a757f88 100644 --- a/tools/drawTools/vtoolarc.h +++ b/tools/drawTools/vtoolarc.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vtoolarc.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,44 +24,46 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef VTOOLARC_H #define VTOOLARC_H #include "vdrawtool.h" #include -#include "dialogs/dialogarc.h" -#include "widgets/vcontrolpointspline.h" +#include "../../dialogs/dialogarc.h" +#include "../../widgets/vcontrolpointspline.h" -class VToolArc :public VDrawTool, public QGraphicsPathItem{ +class VToolArc :public VDrawTool, public QGraphicsPathItem +{ Q_OBJECT public: - VToolArc(VDomDocument *doc, VContainer *data, qint64 id, - Tool::Sources typeCreation, QGraphicsItem * parent = 0); - virtual void setDialog(); - static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, - VDomDocument *doc, - VContainer *data); - static void Create(const qint64 _id, const qint64 ¢er, const QString &radius, - const QString &f1, const QString &f2, VMainGraphicsScene *scene, - VDomDocument *doc, VContainer *data, const Document::Documents &parse, - Tool::Sources typeCreation); + VToolArc(VDomDocument *doc, VContainer *data, qint64 id, const Tool::Sources &typeCreation, + QGraphicsItem * parent = 0); + virtual void setDialog(); + static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, + VContainer *data); + static void Create(const qint64 _id, const qint64 ¢er, const QString &radius, const QString &f1, + const QString &f2, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, + const Document::Documents &parse, const Tool::Sources &typeCreation); + static const QString TagName; + static const QString ToolType; public slots: - virtual void FullUpdateFromFile(); - virtual void FullUpdateFromGui(int result); - virtual void ChangedActivDraw(const QString newName); - virtual void ShowTool(qint64 id, Qt::GlobalColor color, bool enable); + virtual void FullUpdateFromFile(); + virtual void FullUpdateFromGui(int result); + virtual void ChangedActivDraw(const QString &newName); + virtual void ShowTool(qint64 id, Qt::GlobalColor color, bool enable); + virtual void SetFactor(qreal factor); protected: - virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile(); - virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); - virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); - virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); - virtual void RemoveReferens(); + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void AddToFile(); + virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); + virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); + virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); + virtual void RemoveReferens(); private: QSharedPointer dialogArc; - void RefreshGeometry(); + void RefreshGeometry(); }; #endif // VTOOLARC_H diff --git a/tools/drawTools/vtoolbisector.cpp b/tools/drawTools/vtoolbisector.cpp index 80ee7453d..e29886be5 100644 --- a/tools/drawTools/vtoolbisector.cpp +++ b/tools/drawTools/vtoolbisector.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vtoolbisector.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,52 +24,63 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "vtoolbisector.h" +#include "../../container/calculator.h" + +const QString VToolBisector::ToolType = QStringLiteral("bisector"); VToolBisector::VToolBisector(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &typeLine, const QString &formula, const qint64 &firstPointId, - const qint64 &secondPointId, const qint64 &thirdPointId, Tool::Sources typeCreation, - QGraphicsItem *parent): - VToolLinePoint(doc, data, id, typeLine, formula, secondPointId, 0, parent), firstPointId(0), - thirdPointId(0), dialogBisector(QSharedPointer()){ + const qint64 &secondPointId, const qint64 &thirdPointId, const Tool::Sources &typeCreation, + QGraphicsItem *parent) + :VToolLinePoint(doc, data, id, typeLine, formula, secondPointId, 0, parent), firstPointId(0), + thirdPointId(0), dialogBisector(QSharedPointer()) +{ this->firstPointId = firstPointId; this->thirdPointId = thirdPointId; - if(typeCreation == Tool::FromGui){ + if (typeCreation == Tool::FromGui) + { AddToFile(); } } QPointF VToolBisector::FindPoint(const QPointF &firstPoint, const QPointF &secondPoint, - const QPointF &thirdPoint, const qreal &length){ + const QPointF &thirdPoint, const qreal &length) +{ QLineF line1(secondPoint, firstPoint); QLineF line2(secondPoint, thirdPoint); qreal angle = line1.angleTo(line2); - if(angle>180){ + if (angle>180) + { angle = 360 - angle; + line1.setAngle(line1.angle()-angle/2); + } + else + { + line1.setAngle(line1.angle()+angle/2); } - line1.setAngle(line1.angle()-angle/2); line1.setLength(length); return line1.p2(); } -void VToolBisector::setDialog(){ - Q_ASSERT(!dialogBisector.isNull()); - if(!dialogBisector.isNull()){ - VPointF p = VAbstractTool::data.GetPoint(id); - dialogBisector->setTypeLine(typeLine); - dialogBisector->setFormula(formula); - dialogBisector->setFirstPointId(firstPointId, id); - dialogBisector->setSecondPointId(basePointId, id); - dialogBisector->setThirdPointId(thirdPointId, id); - dialogBisector->setPointName(p.name()); - } +void VToolBisector::setDialog() +{ + Q_ASSERT(dialogBisector.isNull() == false); + VPointF p = VAbstractTool::data.GetPoint(id); + dialogBisector->setTypeLine(typeLine); + dialogBisector->setFormula(formula); + dialogBisector->setFirstPointId(firstPointId, id); + dialogBisector->setSecondPointId(basePointId, id); + dialogBisector->setThirdPointId(thirdPointId, id); + dialogBisector->setPointName(p.name()); } -void VToolBisector::Create(QSharedPointer &dialog, VMainGraphicsScene *scene, - VDomDocument *doc, VContainer *data){ +void VToolBisector::Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, + VContainer *data) +{ QString formula = dialog->getFormula(); qint64 firstPointId = dialog->getFirstPointId(); qint64 secondPointId = dialog->getSecondPointId(); @@ -77,7 +95,8 @@ void VToolBisector::Create(const qint64 _id, const QString &formula, const qint6 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 Document::Documents &parse, const Tool::Sources &typeCreation) +{ VPointF firstPoint = data->GetPoint(firstPointId); VPointF secondPoint = data->GetPoint(secondPointId); VPointF thirdPoint = data->GetPoint(thirdPointId); @@ -85,27 +104,34 @@ void VToolBisector::Create(const qint64 _id, const QString &formula, const qint6 Calculator cal(data); QString errorMsg; qreal result = cal.eval(formula, &errorMsg); - if(errorMsg.isEmpty()){ + if (errorMsg.isEmpty()) + { QPointF fPoint = VToolBisector::FindPoint(firstPoint.toQPointF(), secondPoint.toQPointF(), - thirdPoint.toQPointF(), result*PrintDPI/25.4); + thirdPoint.toQPointF(), toPixel(result)); qint64 id = _id; - if(typeCreation == Tool::FromGui){ + if (typeCreation == Tool::FromGui) + { id = data->AddPoint(VPointF(fPoint.x(), fPoint.y(), pointName, mx, my)); - } else { + data->AddLine(firstPointId, id); + } + else + { data->UpdatePoint(id, VPointF(fPoint.x(), fPoint.y(), pointName, mx, my)); - if(parse != Document::FullParse){ + data->AddLine(firstPointId, id); + if (parse != Document::FullParse) + { doc->UpdateToolData(id, data); } } - data->AddLine(firstPointId, id); VDrawTool::AddRecord(id, Tool::BisectorTool, doc); - if(parse == Document::FullParse){ - VToolBisector *point = new VToolBisector(doc, data, id, typeLine, formula, - firstPointId, secondPointId, thirdPointId, - typeCreation); + if (parse == Document::FullParse) + { + VToolBisector *point = new VToolBisector(doc, data, id, typeLine, formula, firstPointId, secondPointId, + thirdPointId, typeCreation); scene->addItem(point); connect(point, &VToolBisector::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); connect(point, &VToolBisector::RemoveTool, scene, &VMainGraphicsScene::RemoveTool); + connect(scene, &VMainGraphicsScene::NewFactor, point, &VToolBisector::SetFactor); doc->AddTool(id, point); doc->IncrementReferens(firstPointId); doc->IncrementReferens(secondPointId); @@ -114,58 +140,72 @@ void VToolBisector::Create(const qint64 _id, const QString &formula, const qint6 } } -void VToolBisector::FullUpdateFromFile(){ +void VToolBisector::FullUpdateFromFile() +{ QDomElement domElement = doc->elementById(QString().setNum(id)); - if(domElement.isElement()){ - typeLine = domElement.attribute("typeLine", ""); - formula = domElement.attribute("length", ""); - firstPointId = domElement.attribute("firstPoint", "").toLongLong(); - basePointId = domElement.attribute("secondPoint", "").toLongLong(); - thirdPointId = domElement.attribute("thirdPoint", "").toLongLong(); + if (domElement.isElement()) + { + typeLine = domElement.attribute(AttrTypeLine, ""); + formula = domElement.attribute(AttrLength, ""); + firstPointId = domElement.attribute(AttrFirstPoint, "").toLongLong(); + basePointId = domElement.attribute(AttrSecondPoint, "").toLongLong(); + thirdPointId = domElement.attribute(AttrThirdPoint, "").toLongLong(); } RefreshGeometry(); } -void VToolBisector::FullUpdateFromGui(int result){ - if(result == QDialog::Accepted){ +void VToolBisector::FullUpdateFromGui(int result) +{ + if (result == QDialog::Accepted) + { QDomElement domElement = doc->elementById(QString().setNum(id)); - if(domElement.isElement()){ - domElement.setAttribute("name", dialogBisector->getPointName()); - domElement.setAttribute("typeLine", dialogBisector->getTypeLine()); - domElement.setAttribute("length", dialogBisector->getFormula()); - domElement.setAttribute("firstPoint", QString().setNum(dialogBisector->getFirstPointId())); - domElement.setAttribute("secondPoint", QString().setNum(dialogBisector->getSecondPointId())); - domElement.setAttribute("thirdPoint", QString().setNum(dialogBisector->getThirdPointId())); + if (domElement.isElement()) + { + domElement.setAttribute(AttrName, dialogBisector->getPointName()); + domElement.setAttribute(AttrTypeLine, dialogBisector->getTypeLine()); + domElement.setAttribute(AttrLength, dialogBisector->getFormula()); + domElement.setAttribute(AttrFirstPoint, QString().setNum(dialogBisector->getFirstPointId())); + domElement.setAttribute(AttrSecondPoint, QString().setNum(dialogBisector->getSecondPointId())); + domElement.setAttribute(AttrThirdPoint, QString().setNum(dialogBisector->getThirdPointId())); emit FullUpdateTree(); } } dialogBisector.clear(); } -void VToolBisector::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ +void VToolBisector::SetFactor(qreal factor) +{ + VDrawTool::SetFactor(factor); + RefreshGeometry(); +} + +void VToolBisector::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) +{ ContextMenu(dialogBisector, this, event); } -void VToolBisector::AddToFile(){ +void VToolBisector::AddToFile() +{ VPointF point = VAbstractTool::data.GetPoint(id); - QDomElement domElement = doc->createElement("point"); + QDomElement domElement = doc->createElement(TagName); - AddAttribute(domElement, "id", id); - AddAttribute(domElement, "type", "bisector"); - AddAttribute(domElement, "name", point.name()); - AddAttribute(domElement, "mx", point.mx()/PrintDPI*25.4); - AddAttribute(domElement, "my", point.my()/PrintDPI*25.4); + AddAttribute(domElement, AttrId, id); + AddAttribute(domElement, AttrType, ToolType); + AddAttribute(domElement, AttrName, point.name()); + AddAttribute(domElement, AttrMx, toMM(point.mx())); + AddAttribute(domElement, AttrMy, toMM(point.my())); - AddAttribute(domElement, "typeLine", typeLine); - AddAttribute(domElement, "length", formula); - AddAttribute(domElement, "firstPoint", firstPointId); - AddAttribute(domElement, "secondPoint", basePointId); - AddAttribute(domElement, "thirdPoint", thirdPointId); + AddAttribute(domElement, AttrTypeLine, typeLine); + AddAttribute(domElement, AttrLength, formula); + AddAttribute(domElement, AttrFirstPoint, firstPointId); + AddAttribute(domElement, AttrSecondPoint, basePointId); + AddAttribute(domElement, AttrThirdPoint, thirdPointId); AddToCalculation(domElement); } -void VToolBisector::RemoveReferens(){ +void VToolBisector::RemoveReferens() +{ doc->DecrementReferens(firstPointId); doc->DecrementReferens(thirdPointId); VToolLinePoint::RemoveReferens(); diff --git a/tools/drawTools/vtoolbisector.h b/tools/drawTools/vtoolbisector.h index 1c88f670d..f449a462e 100644 --- a/tools/drawTools/vtoolbisector.h +++ b/tools/drawTools/vtoolbisector.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vtoolbisector.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,40 +24,43 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef VTOOLBISECTOR_H #define VTOOLBISECTOR_H #include "vtoollinepoint.h" -#include "dialogs/dialogbisector.h" +#include "../../dialogs/dialogbisector.h" -class VToolBisector : public VToolLinePoint{ +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); - static QPointF FindPoint(const QPointF &firstPoint, const QPointF &secondPoint, - const QPointF &thirdPoint, const qreal& length); - virtual void setDialog(); - static void Create(QSharedPointer &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); + VToolBisector(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &typeLine, + const QString &formula, const qint64 &firstPointId, const qint64 &secondPointId, + const qint64 &thirdPointId, const 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 &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, + const Tool::Sources &typeCreation); + static const QString ToolType; public slots: - virtual void FullUpdateFromFile(); - virtual void FullUpdateFromGui(int result); + virtual void FullUpdateFromFile(); + virtual void FullUpdateFromGui(int result); + virtual void SetFactor(qreal factor); protected: - virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile(); - virtual void RemoveReferens(); + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void AddToFile(); + virtual void RemoveReferens(); private: - qint64 firstPointId; - qint64 thirdPointId; + qint64 firstPointId; + qint64 thirdPointId; QSharedPointer dialogBisector; }; diff --git a/tools/drawTools/vtoolendline.cpp b/tools/drawTools/vtoolendline.cpp index a118ba707..0f08affbc 100644 --- a/tools/drawTools/vtoolendline.cpp +++ b/tools/drawTools/vtoolendline.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vtoolendline.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,38 +24,41 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "vtoolendline.h" -#include -#include -#include "widgets/vmaingraphicsscene.h" +#include "../../widgets/vmaingraphicsscene.h" +#include "../../container/calculator.h" + +const QString VToolEndLine::ToolType = QStringLiteral("endLine"); VToolEndLine::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): - VToolLinePoint(doc, data, id, typeLine, formula, basePointId, angle, parent), - dialogEndLine(QSharedPointer()){ + const Tool::Sources &typeCreation, QGraphicsItem *parent) + :VToolLinePoint(doc, data, id, typeLine, formula, basePointId, angle, parent), + dialogEndLine(QSharedPointer()) +{ - if(typeCreation == Tool::FromGui){ + if (typeCreation == Tool::FromGui) + { AddToFile(); } } -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()); - } +void VToolEndLine::setDialog() +{ + Q_ASSERT(dialogEndLine.isNull() == false); + 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 &dialog, VMainGraphicsScene *scene, - VDomDocument *doc, VContainer *data){ +void VToolEndLine::Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, + VContainer *data) +{ QString pointName = dialog->getPointName(); QString typeLine = dialog->getTypeLine(); QString formula = dialog->getFormula(); @@ -61,84 +71,98 @@ void VToolEndLine::Create(QSharedPointer &dialog, VMainGraphicsSc void VToolEndLine::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 Document::Documents &parse, Tool::Sources typeCreation){ - + VContainer *data, const Document::Documents &parse, const Tool::Sources &typeCreation) +{ VPointF basePoint = data->GetPoint(basePointId); QLineF line = QLineF(basePoint.toQPointF(), QPointF(basePoint.x()+100, basePoint.y())); Calculator cal(data); QString errorMsg; qreal result = cal.eval(formula, &errorMsg); - if(errorMsg.isEmpty()){ - line.setLength(result*PrintDPI/25.4); + if (errorMsg.isEmpty()) + { + line.setLength(toPixel(result)); line.setAngle(angle); qint64 id = _id; - if(typeCreation == Tool::FromGui){ + if (typeCreation == Tool::FromGui) + { id = data->AddPoint(VPointF(line.p2().x(), line.p2().y(), pointName, mx, my)); - } else { + data->AddLine(basePointId, id); + } + else + { data->UpdatePoint(id, VPointF(line.p2().x(), line.p2().y(), pointName, mx, my)); - if(parse != Document::FullParse){ + data->AddLine(basePointId, id); + if (parse != Document::FullParse) + { doc->UpdateToolData(id, data); } } - data->AddLine(basePointId, id); VDrawTool::AddRecord(id, Tool::EndLineTool, doc); - if(parse == Document::FullParse){ + if (parse == Document::FullParse) + { VToolEndLine *point = new VToolEndLine(doc, data, id, typeLine, formula, angle, basePointId, 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); } } } -void VToolEndLine::FullUpdateFromFile(){ +void VToolEndLine::FullUpdateFromFile() +{ QDomElement domElement = doc->elementById(QString().setNum(id)); - if(domElement.isElement()){ - typeLine = domElement.attribute("typeLine", ""); - formula = domElement.attribute("length", ""); - basePointId = domElement.attribute("basePoint", "").toLongLong(); - angle = domElement.attribute("angle", "").toInt(); + if (domElement.isElement()) + { + typeLine = domElement.attribute(AttrTypeLine, ""); + formula = domElement.attribute(AttrLength, ""); + basePointId = domElement.attribute(AttrBasePoint, "").toLongLong(); + angle = domElement.attribute(AttrAngle, "").toInt(); } RefreshGeometry(); } -void VToolEndLine::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ +void VToolEndLine::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) +{ ContextMenu(dialogEndLine, this, event); } -void VToolEndLine::FullUpdateFromGui(int result){ - if(result == QDialog::Accepted){ +void VToolEndLine::FullUpdateFromGui(int result) +{ + if (result == QDialog::Accepted) + { QDomElement domElement = doc->elementById(QString().setNum(id)); - if(domElement.isElement()){ - domElement.setAttribute("name", dialogEndLine->getPointName()); - domElement.setAttribute("typeLine", dialogEndLine->getTypeLine()); - domElement.setAttribute("length", dialogEndLine->getFormula()); - domElement.setAttribute("angle", QString().setNum(dialogEndLine->getAngle())); - domElement.setAttribute("basePoint", QString().setNum(dialogEndLine->getBasePointId())); + if (domElement.isElement()) + { + domElement.setAttribute(AttrName, dialogEndLine->getPointName()); + domElement.setAttribute(AttrTypeLine, dialogEndLine->getTypeLine()); + domElement.setAttribute(AttrLength, dialogEndLine->getFormula()); + domElement.setAttribute(AttrAngle, QString().setNum(dialogEndLine->getAngle())); + domElement.setAttribute(AttrBasePoint, QString().setNum(dialogEndLine->getBasePointId())); emit FullUpdateTree(); } } dialogEndLine.clear(); } -void VToolEndLine::AddToFile(){ +void VToolEndLine::AddToFile() +{ VPointF point = VAbstractTool::data.GetPoint(id); - QDomElement domElement = doc->createElement("point"); + QDomElement domElement = doc->createElement(TagName); - 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, AttrId, id); + AddAttribute(domElement, AttrType, ToolType); + AddAttribute(domElement, AttrName, point.name()); + AddAttribute(domElement, AttrMx, toMM(point.mx())); + AddAttribute(domElement, AttrMy, toMM(point.my())); - AddAttribute(domElement, "typeLine", typeLine); - AddAttribute(domElement, "length", formula); - AddAttribute(domElement, "angle", angle); - AddAttribute(domElement, "basePoint", basePointId); + AddAttribute(domElement, AttrTypeLine, typeLine); + AddAttribute(domElement, AttrLength, formula); + AddAttribute(domElement, AttrAngle, angle); + AddAttribute(domElement, AttrBasePoint, basePointId); AddToCalculation(domElement); } - diff --git a/tools/drawTools/vtoolendline.h b/tools/drawTools/vtoolendline.h index 4cd89b31b..a9ce3fa14 100644 --- a/tools/drawTools/vtoolendline.h +++ b/tools/drawTools/vtoolendline.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vtoolendline.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,34 +24,35 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef VTOOLENDLINE_H #define VTOOLENDLINE_H #include "vtoollinepoint.h" -#include "dialogs/dialogendline.h" +#include "../../dialogs/dialogendline.h" -class VToolEndLine : public VToolLinePoint{ +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, + const Tool::Sources &typeCreation, QGraphicsItem * parent = 0); virtual void setDialog(); - static void Create(QSharedPointer &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 Document::Documents &parse, Tool::Sources typeCreation); + static void Create(QSharedPointer &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 Document::Documents &parse, const Tool::Sources &typeCreation); + static const QString ToolType; public slots: - virtual void FullUpdateFromFile(); - virtual void FullUpdateFromGui(int result); + virtual void FullUpdateFromFile(); + virtual void FullUpdateFromGui(int result); protected: - virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile(); + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void AddToFile(); private: QSharedPointer dialogEndLine; }; diff --git a/tools/drawTools/vtoolheight.cpp b/tools/drawTools/vtoolheight.cpp new file mode 100644 index 000000000..528f1515c --- /dev/null +++ b/tools/drawTools/vtoolheight.cpp @@ -0,0 +1,189 @@ +/************************************************************************ + ** + ** @file vtoolheight.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "vtoolheight.h" + +const QString VToolHeight::ToolType = QStringLiteral("height"); + +VToolHeight::VToolHeight(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &typeLine, + const qint64 &basePointId, const qint64 &p1LineId, const qint64 &p2LineId, + const Tool::Sources &typeCreation, QGraphicsItem * parent) + :VToolLinePoint(doc, data, id, typeLine, QString(), basePointId, 0, parent), + dialogHeight(QSharedPointer()), p1LineId(p1LineId), p2LineId(p2LineId) +{ + ignoreFullUpdate = true; + if (typeCreation == Tool::FromGui) + { + AddToFile(); + } +} + +void VToolHeight::setDialog() +{ + Q_ASSERT(dialogHeight.isNull() == false); + 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 &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, const 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 lin (point, QPointF(x, y)); + QPointF p; + QLineF::IntersectType intersect = line.intersect(lin, &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(AttrTypeLine, ""); + basePointId = domElement.attribute(AttrBasePoint, "").toLongLong(); + p1LineId = domElement.attribute(AttrP1Line, "").toLongLong(); + p2LineId = domElement.attribute(AttrP2Line, "").toLongLong(); + } + RefreshGeometry(); + +} + +void VToolHeight::FullUpdateFromGui(int result) +{ + if (result == QDialog::Accepted) + { + QDomElement domElement = doc->elementById(QString().setNum(id)); + if (domElement.isElement()) + { + domElement.setAttribute(AttrName, dialogHeight->getPointName()); + domElement.setAttribute(AttrTypeLine, dialogHeight->getTypeLine()); + domElement.setAttribute(AttrBasePoint, QString().setNum(dialogHeight->getBasePointId())); + domElement.setAttribute(AttrP1Line, QString().setNum(dialogHeight->getP1LineId())); + domElement.setAttribute(AttrP2Line, 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(TagName); + + AddAttribute(domElement, AttrId, id); + AddAttribute(domElement, AttrType, ToolType); + AddAttribute(domElement, AttrName, point.name()); + AddAttribute(domElement, AttrMx, toMM(point.mx())); + AddAttribute(domElement, AttrMy, toMM(point.my())); + + AddAttribute(domElement, AttrTypeLine, typeLine); + AddAttribute(domElement, AttrBasePoint, basePointId); + AddAttribute(domElement, AttrP1Line, p1LineId); + AddAttribute(domElement, AttrP2Line, p2LineId); + + AddToCalculation(domElement); + +} diff --git a/tools/drawTools/vtoolheight.h b/tools/drawTools/vtoolheight.h new file mode 100644 index 000000000..1d070a225 --- /dev/null +++ b/tools/drawTools/vtoolheight.h @@ -0,0 +1,63 @@ +/************************************************************************ + ** + ** @file vtoolheight.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef VTOOLHEIGHT_H +#define VTOOLHEIGHT_H + +#include "vtoollinepoint.h" +#include "../../dialogs/dialogheight.h" + +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, + const Tool::Sources &typeCreation, QGraphicsItem * parent = 0); + virtual void setDialog(); + static void Create(QSharedPointer &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, const Tool::Sources &typeCreation); + static QPointF FindPoint(const QLineF &line, const QPointF &point); + static const QString ToolType; +public slots: + virtual void FullUpdateFromFile(); + virtual void FullUpdateFromGui(int result); +protected: + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void AddToFile(); +private: + QSharedPointer dialogHeight; + qint64 p1LineId; + qint64 p2LineId; +}; + +#endif // VTOOLHEIGHT_H diff --git a/tools/drawTools/vtoolline.cpp b/tools/drawTools/vtoolline.cpp index 6280a118d..5b6e0f3bf 100644 --- a/tools/drawTools/vtoolline.cpp +++ b/tools/drawTools/vtoolline.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vtoolline.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,15 +24,18 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "vtoolline.h" -#include + +const QString VToolLine::TagName = QStringLiteral("line"); VToolLine::VToolLine(VDomDocument *doc, VContainer *data, qint64 id, qint64 firstPoint, qint64 secondPoint, - Tool::Sources typeCreation, QGraphicsItem *parent):VDrawTool(doc, data, id), - QGraphicsLineItem(parent), firstPoint(firstPoint), secondPoint(secondPoint), - dialogLine(QSharedPointer()){ + const Tool::Sources &typeCreation, QGraphicsItem *parent) + :VDrawTool(doc, data, id), QGraphicsLineItem(parent), firstPoint(firstPoint), secondPoint(secondPoint), + dialogLine(QSharedPointer()) +{ + ignoreFullUpdate = true; //Лінія VPointF first = data->GetPoint(firstPoint); VPointF second = data->GetPoint(secondPoint); @@ -33,19 +43,23 @@ VToolLine::VToolLine(VDomDocument *doc, VContainer *data, qint64 id, qint64 firs this->setFlag(QGraphicsItem::ItemStacksBehindParent, true); this->setFlag(QGraphicsItem::ItemIsSelectable, true); this->setAcceptHoverEvents(true); + this->setPen(QPen(Qt::black, widthHairLine/factor)); - if(typeCreation == Tool::FromGui){ + if (typeCreation == Tool::FromGui) + { AddToFile(); } } -void VToolLine::setDialog(){ +void VToolLine::setDialog() +{ dialogLine->setFirstPoint(firstPoint); dialogLine->setSecondPoint(secondPoint); } void VToolLine::Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data){ + VContainer *data) +{ qint64 firstPoint = dialog->getFirstPoint(); qint64 secondPoint = dialog->getSecondPoint(); Create(0, firstPoint, secondPoint, scene, doc, data, Document::FullParse, Tool::FromGui); @@ -53,105 +67,133 @@ void VToolLine::Create(QSharedPointer &dialog, VMainGraphicsScene *s void VToolLine::Create(const qint64 &_id, const qint64 &firstPoint, const qint64 &secondPoint, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, - const Document::Documents &parse, Tool::Sources typeCreation){ - Q_CHECK_PTR(scene); - Q_CHECK_PTR(doc); - Q_CHECK_PTR(data); + const Document::Documents &parse, const Tool::Sources &typeCreation) +{ + Q_ASSERT(scene != 0); + Q_ASSERT(doc != 0); + Q_ASSERT(data != 0); qint64 id = _id; - if(typeCreation == Tool::FromGui){ + if (typeCreation == Tool::FromGui) + { id = data->getNextId(); - } else { - if(parse != Document::FullParse){ + data->AddLine(firstPoint, secondPoint); + } + else + { + data->UpdateId(id); + data->AddLine(firstPoint, secondPoint); + if (parse != Document::FullParse) + { doc->UpdateToolData(id, data); } } - data->AddLine(firstPoint, secondPoint); VDrawTool::AddRecord(id, Tool::LineTool, doc); - if(parse == Document::FullParse){ + if (parse == Document::FullParse) + { VToolLine *line = new VToolLine(doc, data, id, firstPoint, secondPoint, typeCreation); - Q_CHECK_PTR(line); + Q_ASSERT(line != 0); scene->addItem(line); connect(line, &VToolLine::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); connect(line, &VToolLine::RemoveTool, scene, &VMainGraphicsScene::RemoveTool); + connect(scene, &VMainGraphicsScene::NewFactor, line, &VToolLine::SetFactor); doc->AddTool(id, line); doc->IncrementReferens(firstPoint); doc->IncrementReferens(secondPoint); } } -void VToolLine::FullUpdateFromFile(){ - QDomElement domElement = doc->elementById(QString().setNum(id)); - if(domElement.isElement()){ - firstPoint = domElement.attribute("firstPoint", "").toLongLong(); - secondPoint = domElement.attribute("secondPoint", "").toLongLong(); - } - VPointF first = VAbstractTool::data.GetPoint(firstPoint); - VPointF second = VAbstractTool::data.GetPoint(secondPoint); - this->setLine(QLineF(first.toQPointF(), second.toQPointF())); +void VToolLine::FullUpdateFromFile() +{ + RefreshGeometry(); } -void VToolLine::FullUpdateFromGui(int result){ - if(result == QDialog::Accepted){ +void VToolLine::FullUpdateFromGui(int result) +{ + if (result == QDialog::Accepted) + { QDomElement domElement = doc->elementById(QString().setNum(id)); - if(domElement.isElement()){ - domElement.setAttribute("firstPoint", QString().setNum(dialogLine->getFirstPoint())); - domElement.setAttribute("secondPoint", QString().setNum(dialogLine->getSecondPoint())); + if (domElement.isElement()) + { + domElement.setAttribute(AttrFirstPoint, QString().setNum(dialogLine->getFirstPoint())); + domElement.setAttribute(AttrSecondPoint, QString().setNum(dialogLine->getSecondPoint())); emit FullUpdateTree(); } } dialogLine.clear(); } -void VToolLine::ShowTool(qint64 id, Qt::GlobalColor color, bool enable){ - if(id == this->id){ - if(enable == false){ - this->setPen(QPen(baseColor, widthHairLine)); - currentColor = baseColor; - } else { - this->setPen(QPen(color, widthHairLine)); - currentColor = color; - } - } +void VToolLine::ShowTool(qint64 id, Qt::GlobalColor color, bool enable) +{ + ShowItem(this, id, color, enable); } -void VToolLine::ChangedActivDraw(const QString newName){ - if(nameActivDraw == newName){ - this->setPen(QPen(Qt::black, widthHairLine)); - this->setAcceptHoverEvents (true); - VDrawTool::ChangedActivDraw(newName); - } else { - this->setPen(QPen(Qt::gray, widthHairLine)); - this->setAcceptHoverEvents (false); - VDrawTool::ChangedActivDraw(newName); - } +void VToolLine::SetFactor(qreal factor) +{ + VDrawTool::SetFactor(factor); + RefreshGeometry(); } -void VToolLine::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ +void VToolLine::ChangedActivDraw(const QString &newName) +{ + bool selectable = false; + if (nameActivDraw == newName) + { + selectable = true; + currentColor = Qt::black; + } + else + { + selectable = false; + currentColor = Qt::gray; + } + 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); - AddAttribute(domElement, "firstPoint", firstPoint); - AddAttribute(domElement, "secondPoint", secondPoint); +void VToolLine::AddToFile() +{ + QDomElement domElement = doc->createElement(TagName); + AddAttribute(domElement, AttrId, id); + AddAttribute(domElement, AttrFirstPoint, firstPoint); + AddAttribute(domElement, AttrSecondPoint, secondPoint); AddToCalculation(domElement); } -void VToolLine::hoverMoveEvent(QGraphicsSceneHoverEvent *event){ +void VToolLine::hoverMoveEvent(QGraphicsSceneHoverEvent *event) +{ Q_UNUSED(event); - this->setPen(QPen(currentColor, widthMainLine)); + this->setPen(QPen(currentColor, widthMainLine/factor)); } -void VToolLine::hoverLeaveEvent(QGraphicsSceneHoverEvent *event){ +void VToolLine::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) +{ Q_UNUSED(event); - this->setPen(QPen(currentColor, widthHairLine)); + this->setPen(QPen(currentColor, widthHairLine/factor)); } -void VToolLine::RemoveReferens(){ +void VToolLine::RemoveReferens() +{ doc->DecrementReferens(firstPoint); doc->DecrementReferens(secondPoint); } +void VToolLine::RefreshGeometry() +{ + QDomElement domElement = doc->elementById(QString().setNum(id)); + if (domElement.isElement()) + { + firstPoint = domElement.attribute(AttrFirstPoint, "").toLongLong(); + secondPoint = domElement.attribute(AttrSecondPoint, "").toLongLong(); + } + VPointF first = VAbstractTool::data.GetPoint(firstPoint); + VPointF second = VAbstractTool::data.GetPoint(secondPoint); + this->setLine(QLineF(first.toQPointF(), second.toQPointF())); + this->setPen(QPen(currentColor, widthHairLine/factor)); +} diff --git a/tools/drawTools/vtoolline.h b/tools/drawTools/vtoolline.h index a7b31824e..bcc7ac170 100644 --- a/tools/drawTools/vtoolline.h +++ b/tools/drawTools/vtoolline.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vtoolline.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,41 +24,45 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef VTOOLLINE_H #define VTOOLLINE_H #include "vdrawtool.h" -#include "QGraphicsLineItem" -#include "dialogs/dialogline.h" +#include +#include "../../dialogs/dialogline.h" -class VToolLine: public VDrawTool, public QGraphicsLineItem{ +class VToolLine: public VDrawTool, public QGraphicsLineItem +{ Q_OBJECT public: - VToolLine(VDomDocument *doc, VContainer *data, qint64 id, qint64 firstPoint, - qint64 secondPoint, Tool::Sources typeCreation, QGraphicsItem * parent = 0); + VToolLine(VDomDocument *doc, VContainer *data, qint64 id, qint64 firstPoint, + qint64 secondPoint, const Tool::Sources &typeCreation, QGraphicsItem * parent = 0); virtual void setDialog(); - static void Create(QSharedPointer &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); + static void Create(QSharedPointer &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, const Tool::Sources &typeCreation); + static const QString TagName; public slots: - virtual void FullUpdateFromFile(); - virtual void ChangedActivDraw(const QString newName); - virtual void FullUpdateFromGui(int result); - virtual void ShowTool(qint64 id, Qt::GlobalColor color, bool enable); + virtual void FullUpdateFromFile(); + virtual void ChangedActivDraw(const QString &newName); + virtual void FullUpdateFromGui(int result); + virtual void ShowTool(qint64 id, Qt::GlobalColor color, bool enable); + virtual void SetFactor(qreal factor); protected: - virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile(); - virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); - virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); - virtual void RemoveReferens(); + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void AddToFile(); + virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); + virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); + virtual void RemoveReferens(); private: - qint64 firstPoint; - qint64 secondPoint; + qint64 firstPoint; + qint64 secondPoint; QSharedPointer dialogLine; + void RefreshGeometry(); }; #endif // VTOOLLINE_H diff --git a/tools/drawTools/vtoollineintersect.cpp b/tools/drawTools/vtoollineintersect.cpp index e1a0abbd0..1663b4c71 100644 --- a/tools/drawTools/vtoollineintersect.cpp +++ b/tools/drawTools/vtoollineintersect.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vtoollineintersect.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,35 +24,40 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "vtoollineintersect.h" -#include + +const QString VToolLineIntersect::ToolType = QStringLiteral("lineIntersect"); VToolLineIntersect::VToolLineIntersect(VDomDocument *doc, VContainer *data, const qint64 &id, const qint64 &p1Line1, const qint64 &p2Line1, const qint64 &p1Line2, - const qint64 &p2Line2, Tool::Sources typeCreation, QGraphicsItem *parent): - VToolPoint(doc, data, id, parent), p1Line1(p1Line1), p2Line1(p2Line1), p1Line2(p1Line2), - p2Line2(p2Line2), dialogLineIntersect(QSharedPointer()){ - if(typeCreation == Tool::FromGui){ + const qint64 &p2Line2, const Tool::Sources &typeCreation, + QGraphicsItem *parent) + :VToolPoint(doc, data, id, parent), p1Line1(p1Line1), p2Line1(p2Line1), p1Line2(p1Line2), + p2Line2(p2Line2), dialogLineIntersect(QSharedPointer()) +{ + ignoreFullUpdate = true; + if (typeCreation == Tool::FromGui) + { AddToFile(); } } -void VToolLineIntersect::setDialog(){ - Q_ASSERT(!dialogLineIntersect.isNull()); - if(!dialogLineIntersect.isNull()){ - VPointF p = VAbstractTool::data.GetPoint(id); - dialogLineIntersect->setP1Line1(p1Line1); - dialogLineIntersect->setP2Line1(p2Line1); - dialogLineIntersect->setP1Line2(p1Line2); - dialogLineIntersect->setP2Line2(p2Line2); - dialogLineIntersect->setPointName(p.name()); - } +void VToolLineIntersect::setDialog() +{ + Q_ASSERT(dialogLineIntersect.isNull() == false); + VPointF p = VAbstractTool::data.GetPoint(id); + dialogLineIntersect->setP1Line1(p1Line1); + dialogLineIntersect->setP2Line1(p2Line1); + dialogLineIntersect->setP1Line2(p1Line2); + dialogLineIntersect->setP2Line2(p2Line2); + dialogLineIntersect->setPointName(p.name()); } void VToolLineIntersect::Create(QSharedPointer &dialog, VMainGraphicsScene *scene, - VDomDocument *doc, VContainer *data){ + VDomDocument *doc, VContainer *data) +{ qint64 p1Line1Id = dialog->getP1Line1(); qint64 p2Line1Id = dialog->getP2Line1(); qint64 p1Line2Id = dialog->getP1Line2(); @@ -57,8 +69,10 @@ void VToolLineIntersect::Create(QSharedPointer &dialog, VMa void VToolLineIntersect::Create(const qint64 _id, const qint64 &p1Line1Id, const qint64 &p2Line1Id, const qint64 &p1Line2Id, const qint64 &p2Line2Id, const QString &pointName, - const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data, const Document::Documents &parse, Tool::Sources typeCreation){ + const qreal &mx, const qreal &my, VMainGraphicsScene *scene, + VDomDocument *doc, VContainer *data, const Document::Documents &parse, + const Tool::Sources &typeCreation) +{ VPointF p1Line1 = data->GetPoint(p1Line1Id); VPointF p2Line1 = data->GetPoint(p2Line1Id); VPointF p1Line2 = data->GetPoint(p1Line2Id); @@ -68,28 +82,38 @@ void VToolLineIntersect::Create(const qint64 _id, const qint64 &p1Line1Id, const QLineF line2(p1Line2.toQPointF(), p2Line2.toQPointF()); QPointF fPoint; QLineF::IntersectType intersect = line1.intersect(line2, &fPoint); - if(intersect == QLineF::UnboundedIntersection || intersect == QLineF::BoundedIntersection){ + if (intersect == QLineF::UnboundedIntersection || intersect == QLineF::BoundedIntersection) + { qint64 id = _id; - if(typeCreation == Tool::FromGui){ + if (typeCreation == Tool::FromGui) + { id = data->AddPoint(VPointF(fPoint.x(), fPoint.y(), pointName, mx, my)); - } else { + data->AddLine(p1Line1Id, id); + data->AddLine(id, p2Line1Id); + data->AddLine(p1Line2Id, id); + data->AddLine(id, p2Line2Id); + } + else + { data->UpdatePoint(id, VPointF(fPoint.x(), fPoint.y(), pointName, mx, my)); - if(parse != Document::FullParse){ + data->AddLine(p1Line1Id, id); + data->AddLine(id, p2Line1Id); + data->AddLine(p1Line2Id, id); + data->AddLine(id, p2Line2Id); + if (parse != Document::FullParse) + { doc->UpdateToolData(id, data); } } - data->AddLine(p1Line1Id, id); - data->AddLine(id, p2Line1Id); - data->AddLine(p1Line2Id, id); - data->AddLine(id, p2Line2Id); VDrawTool::AddRecord(id, Tool::LineIntersectTool, doc); - if(parse == Document::FullParse){ - VToolLineIntersect *point = new VToolLineIntersect(doc, data, id, p1Line1Id, - p2Line1Id, p1Line2Id, + if (parse == Document::FullParse) + { + VToolLineIntersect *point = new VToolLineIntersect(doc, data, id, p1Line1Id, p2Line1Id, p1Line2Id, p2Line2Id, typeCreation); scene->addItem(point); connect(point, &VToolLineIntersect::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); connect(point, &VToolLineIntersect::RemoveTool, scene, &VMainGraphicsScene::RemoveTool); + connect(scene, &VMainGraphicsScene::NewFactor, point, &VToolLineIntersect::SetFactor); doc->AddTool(id, point); doc->IncrementReferens(p1Line1Id); doc->IncrementReferens(p2Line1Id); @@ -99,55 +123,69 @@ void VToolLineIntersect::Create(const qint64 _id, const qint64 &p1Line1Id, const } } -void VToolLineIntersect::FullUpdateFromFile(){ +void VToolLineIntersect::FullUpdateFromFile() +{ QDomElement domElement = doc->elementById(QString().setNum(id)); - if(domElement.isElement()){ - p1Line1 = domElement.attribute("p1Line1", "").toLongLong(); - p2Line1 = domElement.attribute("p2Line1", "").toLongLong(); - p1Line2 = domElement.attribute("p1Line2", "").toLongLong(); - p2Line2 = domElement.attribute("p2Line2", "").toLongLong(); + if (domElement.isElement()) + { + p1Line1 = domElement.attribute(AttrP1Line1, "").toLongLong(); + p2Line1 = domElement.attribute(AttrP2Line1, "").toLongLong(); + p1Line2 = domElement.attribute(AttrP1Line2, "").toLongLong(); + p2Line2 = domElement.attribute(AttrP2Line2, "").toLongLong(); } RefreshPointGeometry(VAbstractTool::data.GetPoint(id)); } -void VToolLineIntersect::FullUpdateFromGui(int result){ - if(result == QDialog::Accepted){ +void VToolLineIntersect::FullUpdateFromGui(int result) +{ + if (result == QDialog::Accepted) + { QDomElement domElement = doc->elementById(QString().setNum(id)); - if(domElement.isElement()){ - domElement.setAttribute("name", dialogLineIntersect->getPointName()); - domElement.setAttribute("p1Line1", QString().setNum(dialogLineIntersect->getP1Line1())); - domElement.setAttribute("p2Line1", QString().setNum(dialogLineIntersect->getP2Line1())); - domElement.setAttribute("p1Line2", QString().setNum(dialogLineIntersect->getP1Line2())); - domElement.setAttribute("p2Line2", QString().setNum(dialogLineIntersect->getP2Line2())); + if (domElement.isElement()) + { + domElement.setAttribute(AttrName, dialogLineIntersect->getPointName()); + domElement.setAttribute(AttrP1Line1, QString().setNum(dialogLineIntersect->getP1Line1())); + domElement.setAttribute(AttrP2Line1, QString().setNum(dialogLineIntersect->getP2Line1())); + domElement.setAttribute(AttrP1Line2, QString().setNum(dialogLineIntersect->getP1Line2())); + domElement.setAttribute(AttrP2Line2, QString().setNum(dialogLineIntersect->getP2Line2())); emit FullUpdateTree(); } } dialogLineIntersect.clear(); } -void VToolLineIntersect::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ +void VToolLineIntersect::SetFactor(qreal factor) +{ + VDrawTool::SetFactor(factor); + RefreshPointGeometry(VAbstractTool::data.GetPoint(id)); +} + +void VToolLineIntersect::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) +{ ContextMenu(dialogLineIntersect, this, event); } -void VToolLineIntersect::AddToFile(){ +void VToolLineIntersect::AddToFile() +{ VPointF point = VAbstractTool::data.GetPoint(id); - QDomElement domElement = doc->createElement("point"); + QDomElement domElement = doc->createElement(TagName); - AddAttribute(domElement, "id", id); - AddAttribute(domElement, "type", "lineIntersect"); - AddAttribute(domElement, "name", point.name()); - AddAttribute(domElement, "mx", point.mx()/PrintDPI*25.4); - AddAttribute(domElement, "my", point.my()/PrintDPI*25.4); + AddAttribute(domElement, AttrId, id); + AddAttribute(domElement, AttrType, ToolType); + AddAttribute(domElement, AttrName, point.name()); + AddAttribute(domElement, AttrMx, toMM(point.mx())); + AddAttribute(domElement, AttrMy, toMM(point.my())); - AddAttribute(domElement, "p1Line1", p1Line1); - AddAttribute(domElement, "p2Line1", p2Line1); - AddAttribute(domElement, "p1Line2", p1Line2); - AddAttribute(domElement, "p2Line2", p2Line2); + AddAttribute(domElement, AttrP1Line1, p1Line1); + AddAttribute(domElement, AttrP2Line1, p2Line1); + AddAttribute(domElement, AttrP1Line2, p1Line2); + AddAttribute(domElement, AttrP2Line2, p2Line2); AddToCalculation(domElement); } -void VToolLineIntersect::RemoveReferens(){ +void VToolLineIntersect::RemoveReferens() +{ doc->DecrementReferens(p1Line1); doc->DecrementReferens(p2Line1); doc->DecrementReferens(p1Line2); diff --git a/tools/drawTools/vtoollineintersect.h b/tools/drawTools/vtoollineintersect.h index 1c5b36cfd..aeb34b54d 100644 --- a/tools/drawTools/vtoollineintersect.h +++ b/tools/drawTools/vtoollineintersect.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vtoollineintersect.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,45 +24,42 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef VTOOLLINEINTERSECT_H #define VTOOLLINEINTERSECT_H #include "vtoolpoint.h" -#include "dialogs/dialoglineintersect.h" +#include "../../dialogs/dialoglineintersect.h" -class VToolLineIntersect:public VToolPoint{ +class VToolLineIntersect:public VToolPoint +{ Q_OBJECT public: - VToolLineIntersect(VDomDocument *doc, VContainer *data, - const qint64 &id, - const qint64 &p1Line1, - const qint64 &p2Line1, const qint64 &p1Line2, - const qint64 &p2Line2, Tool::Sources typeCreation, - QGraphicsItem * parent = 0); - virtual void setDialog(); - static void Create(QSharedPointer &dialog, - VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data); - static void Create(const qint64 _id, const qint64 &p1Line1Id, - const qint64 &p2Line1Id, const qint64 &p1Line2Id, - const qint64 &p2Line2Id, const QString &pointName, - const qreal &mx, const qreal &my, VMainGraphicsScene *scene, - VDomDocument *doc, VContainer *data, - const Document::Documents &parse, Tool::Sources typeCreation); + VToolLineIntersect(VDomDocument *doc, VContainer *data, const qint64 &id, const qint64 &p1Line1, + const qint64 &p2Line1, const qint64 &p1Line2, const qint64 &p2Line2, + const Tool::Sources &typeCreation, QGraphicsItem * parent = 0); + virtual void setDialog(); + static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, + VContainer *data); + static void Create(const qint64 _id, const qint64 &p1Line1Id, const qint64 &p2Line1Id, const qint64 &p1Line2Id, + const qint64 &p2Line2Id, const QString &pointName, const qreal &mx, const qreal &my, + VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, + const Document::Documents &parse, const Tool::Sources &typeCreation); + static const QString ToolType; public slots: - virtual void FullUpdateFromFile(); - virtual void FullUpdateFromGui(int result); + virtual void FullUpdateFromFile(); + virtual void FullUpdateFromGui(int result); + virtual void SetFactor(qreal factor); protected: - virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile(); - virtual void RemoveReferens(); + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void AddToFile(); + virtual void RemoveReferens(); private: - qint64 p1Line1; - qint64 p2Line1; - qint64 p1Line2; - qint64 p2Line2; + qint64 p1Line1; + qint64 p2Line1; + qint64 p1Line2; + qint64 p2Line2; QSharedPointer dialogLineIntersect; }; diff --git a/tools/drawTools/vtoollinepoint.cpp b/tools/drawTools/vtoollinepoint.cpp index b7536c1ae..e0042b60d 100644 --- a/tools/drawTools/vtoollinepoint.cpp +++ b/tools/drawTools/vtoollinepoint.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vtoollinepoint.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,50 +24,66 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "vtoollinepoint.h" VToolLinePoint::VToolLinePoint(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &typeLine, const QString &formula, const qint64 &basePointId, - const qreal &angle, QGraphicsItem *parent):VToolPoint(doc, data, id, parent), - typeLine(typeLine), formula(formula), angle(angle), basePointId(basePointId), mainLine(0){ + const qreal &angle, QGraphicsItem *parent) + :VToolPoint(doc, data, id, parent), typeLine(typeLine), formula(formula), angle(angle), basePointId(basePointId), + mainLine(0) +{ Q_ASSERT_X(basePointId > 0, Q_FUNC_INFO, "basePointId <= 0"); //Лінія, що з'єднує дві точки QPointF point1 = data->GetPoint(basePointId).toQPointF(); QPointF point2 = data->GetPoint(id).toQPointF(); mainLine = new QGraphicsLineItem(QLineF(point1 - point2, QPointF()), this); - mainLine->setPen(QPen(Qt::black, widthHairLine)); + mainLine->setPen(QPen(Qt::black, widthHairLine/factor)); mainLine->setFlag(QGraphicsItem::ItemStacksBehindParent, true); - if(typeLine == "none"){ + if (typeLine == TypeLineNone) + { mainLine->setVisible(false); - } else { + } + else + { mainLine->setVisible(true); } } -void VToolLinePoint::ChangedActivDraw(const QString newName){ - if(nameActivDraw == newName){ - mainLine->setPen(QPen(Qt::black, widthHairLine)); - VToolPoint::ChangedActivDraw(newName); - } else { - mainLine->setPen(QPen(Qt::gray, widthHairLine)); - VToolPoint::ChangedActivDraw(newName); +void VToolLinePoint::ChangedActivDraw(const QString &newName) +{ + if (nameActivDraw == newName) + { + currentColor = Qt::black; } + else + { + currentColor = Qt::gray; + } + mainLine->setPen(QPen(currentColor, widthHairLine/factor)); + VToolPoint::ChangedActivDraw(newName); } -void VToolLinePoint::RefreshGeometry(){ +void VToolLinePoint::RefreshGeometry() +{ + mainLine->setPen(QPen(currentColor, widthHairLine/factor)); VToolPoint::RefreshPointGeometry(VDrawTool::data.GetPoint(id)); QPointF point = VDrawTool::data.GetPoint(id).toQPointF(); QPointF basePoint = VDrawTool::data.GetPoint(basePointId).toQPointF(); mainLine->setLine(QLineF(basePoint - point, QPointF())); - if(typeLine == "none"){ + if (typeLine == TypeLineNone) + { mainLine->setVisible(false); - } else { + } + else + { mainLine->setVisible(true); } } -void VToolLinePoint::RemoveReferens(){ - doc->DecrementReferens(basePointId); +void VToolLinePoint::SetFactor(qreal factor) +{ + VDrawTool::SetFactor(factor); + RefreshGeometry(); } diff --git a/tools/drawTools/vtoollinepoint.h b/tools/drawTools/vtoollinepoint.h index a298bc5f1..dc10aeb17 100644 --- a/tools/drawTools/vtoollinepoint.h +++ b/tools/drawTools/vtoollinepoint.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vtoollinepoint.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,21 +24,23 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef VTOOLLINEPOINT_H #define VTOOLLINEPOINT_H #include "vtoolpoint.h" -class VToolLinePoint : public VToolPoint{ +class VToolLinePoint : public VToolPoint +{ Q_OBJECT public: - VToolLinePoint(VDomDocument *doc, VContainer *data, const qint64 &id, - const QString &typeLine, const QString &formula, - const qint64 &basePointId, const qreal &angle, QGraphicsItem * parent = 0); + VToolLinePoint(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &typeLine, + const QString &formula, const qint64 &basePointId, const qreal &angle, + QGraphicsItem * parent = 0); public slots: - virtual void ChangedActivDraw(const QString newName); + virtual void ChangedActivDraw(const QString &newName); + virtual void SetFactor(qreal factor); protected: QString typeLine; QString formula; @@ -39,7 +48,7 @@ protected: qint64 basePointId; QGraphicsLineItem *mainLine; virtual void RefreshGeometry(); - virtual void RemoveReferens(); + virtual void RemoveReferens() {doc->DecrementReferens(basePointId);} private: Q_DISABLE_COPY(VToolLinePoint) }; diff --git a/tools/drawTools/vtoolnormal.cpp b/tools/drawTools/vtoolnormal.cpp index 2fd033e3c..0acb05cdf 100644 --- a/tools/drawTools/vtoolnormal.cpp +++ b/tools/drawTools/vtoolnormal.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vtoolnormal.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,38 +24,42 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "vtoolnormal.h" +#include "../../container/calculator.h" -VToolNormal::VToolNormal(VDomDocument *doc, VContainer *data, const qint64 &id, - const QString &typeLine, +const QString VToolNormal::ToolType = QStringLiteral("normal"); + +VToolNormal::VToolNormal(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &typeLine, const QString &formula, const qreal &angle, const qint64 &firstPointId, - const qint64 &secondPointId, Tool::Sources typeCreation, QGraphicsItem *parent): - VToolLinePoint(doc, data, id, typeLine, formula, firstPointId, angle, parent), - secondPointId(secondPointId), dialogNormal(QSharedPointer()){ + const qint64 &secondPointId, const Tool::Sources &typeCreation, QGraphicsItem *parent) + :VToolLinePoint(doc, data, id, typeLine, formula, firstPointId, angle, parent), + secondPointId(secondPointId), dialogNormal(QSharedPointer()) +{ - if(typeCreation == Tool::FromGui){ + if (typeCreation == Tool::FromGui) + { AddToFile(); } } -void VToolNormal::setDialog(){ - Q_ASSERT(!dialogNormal.isNull()); - if(!dialogNormal.isNull()){ - VPointF p = VAbstractTool::data.GetPoint(id); - dialogNormal->setTypeLine(typeLine); - dialogNormal->setFormula(formula); - dialogNormal->setAngle(angle); - dialogNormal->setFirstPointId(basePointId, id); - dialogNormal->setSecondPointId(secondPointId, id); - dialogNormal->setPointName(p.name()); - } +void VToolNormal::setDialog() +{ + Q_ASSERT(dialogNormal.isNull() == false); + VPointF p = VAbstractTool::data.GetPoint(id); + dialogNormal->setTypeLine(typeLine); + dialogNormal->setFormula(formula); + dialogNormal->setAngle(angle); + dialogNormal->setFirstPointId(basePointId, id); + dialogNormal->setSecondPointId(secondPointId, id); + dialogNormal->setPointName(p.name()); } void VToolNormal::Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data){ + VContainer *data) +{ QString formula = dialog->getFormula(); qint64 firstPointId = dialog->getFirstPointId(); qint64 secondPointId = dialog->getSecondPointId(); @@ -60,34 +71,44 @@ void VToolNormal::Create(QSharedPointer &dialog, VMainGraphicsScen } void VToolNormal::Create(const qint64 _id, const QString &formula, const qint64 &firstPointId, - const qint64 &secondPointId, const QString typeLine, const QString pointName, + const qint64 &secondPointId, const QString &typeLine, const QString &pointName, const qreal angle, const qreal &mx, const qreal &my, VMainGraphicsScene *scene, - VDomDocument *doc, VContainer *data, const Document::Documents &parse, Tool::Sources typeCreation){ + VDomDocument *doc, VContainer *data, const Document::Documents &parse, + const Tool::Sources &typeCreation) +{ VPointF firstPoint = data->GetPoint(firstPointId); VPointF secondPoint = data->GetPoint(secondPointId); Calculator cal(data); QString errorMsg; qreal result = cal.eval(formula, &errorMsg); - if(errorMsg.isEmpty()){ + if (errorMsg.isEmpty()) + { QPointF fPoint = VToolNormal::FindPoint(firstPoint.toQPointF(), secondPoint.toQPointF(), - result*PrintDPI/25.4, angle); + toPixel(result), angle); qint64 id = _id; - if(typeCreation == Tool::FromGui){ + if (typeCreation == Tool::FromGui) + { id = data->AddPoint(VPointF(fPoint.x(), fPoint.y(), pointName, mx, my)); - } else { + data->AddLine(firstPointId, id); + } + else + { data->UpdatePoint(id, VPointF(fPoint.x(), fPoint.y(), pointName, mx, my)); - if(parse != Document::FullParse){ + data->AddLine(firstPointId, id); + if (parse != Document::FullParse) + { doc->UpdateToolData(id, data); } } - data->AddLine(firstPointId, id); VDrawTool::AddRecord(id, Tool::NormalTool, doc); - if(parse == Document::FullParse){ + if (parse == Document::FullParse) + { VToolNormal *point = new VToolNormal(doc, data, id, typeLine, formula, angle, firstPointId, secondPointId, typeCreation); scene->addItem(point); connect(point, &VToolNormal::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); connect(point, &VToolNormal::RemoveTool, scene, &VMainGraphicsScene::RemoveTool); + connect(scene, &VMainGraphicsScene::NewFactor, point, &VToolNormal::SetFactor); doc->AddTool(id, point); doc->IncrementReferens(firstPointId); doc->IncrementReferens(secondPointId); @@ -96,7 +117,8 @@ void VToolNormal::Create(const qint64 _id, const QString &formula, const qint64 } QPointF VToolNormal::FindPoint(const QPointF &firstPoint, const QPointF &secondPoint, const qreal &length, - const qreal &angle){ + const qreal &angle) +{ QLineF line(firstPoint, secondPoint); QLineF normal = line.normalVector(); normal.setAngle(normal.angle()+angle); @@ -104,58 +126,72 @@ QPointF VToolNormal::FindPoint(const QPointF &firstPoint, const QPointF &secondP return normal.p2(); } -void VToolNormal::FullUpdateFromFile(){ +void VToolNormal::FullUpdateFromFile() +{ QDomElement domElement = doc->elementById(QString().setNum(id)); - if(domElement.isElement()){ - typeLine = domElement.attribute("typeLine", ""); - formula = domElement.attribute("length", ""); - basePointId = domElement.attribute("firstPoint", "").toLongLong(); - secondPointId = domElement.attribute("secondPoint", "").toLongLong(); - angle = domElement.attribute("angle", "").toInt(); + if (domElement.isElement()) + { + typeLine = domElement.attribute(AttrTypeLine, ""); + formula = domElement.attribute(AttrLength, ""); + basePointId = domElement.attribute(AttrFirstPoint, "").toLongLong(); + secondPointId = domElement.attribute(AttrSecondPoint, "").toLongLong(); + angle = domElement.attribute(AttrAngle, "").toDouble(); } RefreshGeometry(); } -void VToolNormal::FullUpdateFromGui(int result){ - if(result == QDialog::Accepted){ +void VToolNormal::FullUpdateFromGui(int result) +{ + if (result == QDialog::Accepted) + { QDomElement domElement = doc->elementById(QString().setNum(id)); - if(domElement.isElement()){ - domElement.setAttribute("name", dialogNormal->getPointName()); - domElement.setAttribute("typeLine", dialogNormal->getTypeLine()); - domElement.setAttribute("length", dialogNormal->getFormula()); - domElement.setAttribute("angle", QString().setNum(dialogNormal->getAngle())); - domElement.setAttribute("firstPoint", QString().setNum(dialogNormal->getFirstPointId())); - domElement.setAttribute("secondPoint", QString().setNum(dialogNormal->getSecondPointId())); + if (domElement.isElement()) + { + domElement.setAttribute(AttrName, dialogNormal->getPointName()); + domElement.setAttribute(AttrTypeLine, dialogNormal->getTypeLine()); + domElement.setAttribute(AttrLength, dialogNormal->getFormula()); + domElement.setAttribute(AttrAngle, QString().setNum(dialogNormal->getAngle())); + domElement.setAttribute(AttrFirstPoint, QString().setNum(dialogNormal->getFirstPointId())); + domElement.setAttribute(AttrSecondPoint, QString().setNum(dialogNormal->getSecondPointId())); emit FullUpdateTree(); } } dialogNormal.clear(); } -void VToolNormal::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ +void VToolNormal::SetFactor(qreal factor) +{ + VDrawTool::SetFactor(factor); + RefreshGeometry(); +} + +void VToolNormal::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) +{ ContextMenu(dialogNormal, this, event); } -void VToolNormal::AddToFile(){ +void VToolNormal::AddToFile() +{ VPointF point = VAbstractTool::data.GetPoint(id); - QDomElement domElement = doc->createElement("point"); + QDomElement domElement = doc->createElement(TagName); - AddAttribute(domElement, "id", id); - AddAttribute(domElement, "type", "normal"); - AddAttribute(domElement, "name", point.name()); - AddAttribute(domElement, "mx", point.mx()/PrintDPI*25.4); - AddAttribute(domElement, "my", point.my()/PrintDPI*25.4); + AddAttribute(domElement, AttrId, id); + AddAttribute(domElement, AttrType, ToolType); + AddAttribute(domElement, AttrName, point.name()); + AddAttribute(domElement, AttrMx, toMM(point.mx())); + AddAttribute(domElement, AttrMy, toMM(point.my())); - AddAttribute(domElement, "typeLine", typeLine); - AddAttribute(domElement, "length", formula); - AddAttribute(domElement, "angle", angle); - AddAttribute(domElement, "firstPoint", basePointId); - AddAttribute(domElement, "secondPoint", secondPointId); + AddAttribute(domElement, AttrTypeLine, typeLine); + AddAttribute(domElement, AttrLength, formula); + AddAttribute(domElement, AttrAngle, angle); + AddAttribute(domElement, AttrFirstPoint, basePointId); + AddAttribute(domElement, AttrSecondPoint, secondPointId); AddToCalculation(domElement); } -void VToolNormal::RemoveReferens(){ +void VToolNormal::RemoveReferens() +{ doc->DecrementReferens(secondPointId); VToolLinePoint::RemoveReferens(); } diff --git a/tools/drawTools/vtoolnormal.h b/tools/drawTools/vtoolnormal.h index 217328744..0f2b1fd07 100644 --- a/tools/drawTools/vtoolnormal.h +++ b/tools/drawTools/vtoolnormal.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vtoolnormal.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,41 +24,43 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef VTOOLNORMAL_H #define VTOOLNORMAL_H #include "vtoollinepoint.h" -#include "dialogs/dialognormal.h" +#include "../../dialogs/dialognormal.h" class VToolNormal : public VToolLinePoint { Q_OBJECT public: - VToolNormal(VDomDocument *doc, VContainer *data, const qint64 &id, - const QString &typeLine, const QString &formula, - const qreal &angle, const qint64 &firstPointId, - const qint64 &secondPointId, Tool::Sources typeCreation, - QGraphicsItem * parent = 0); - virtual void setDialog(); - static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data); - static void 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, VMainGraphicsScene *scene, - 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); + VToolNormal(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &typeLine, + const QString &formula, const qreal &angle, const qint64 &firstPointId, + const qint64 &secondPointId, const Tool::Sources &typeCreation, + QGraphicsItem * parent = 0); + virtual void setDialog(); + static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, + VContainer *data); + static void 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, VMainGraphicsScene *scene, + VDomDocument *doc, VContainer *data, const Document::Documents &parse, + const Tool::Sources &typeCreation); + static QPointF FindPoint(const QPointF &firstPoint, const QPointF &secondPoint, const qreal &length, + const qreal &angle = 0); + static const QString ToolType; public slots: - virtual void FullUpdateFromFile(); - virtual void FullUpdateFromGui(int result); + virtual void FullUpdateFromFile(); + virtual void FullUpdateFromGui(int result); + virtual void SetFactor(qreal factor); protected: - virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile(); - virtual void RemoveReferens(); + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void AddToFile(); + virtual void RemoveReferens(); private: - qint64 secondPointId; + qint64 secondPointId; QSharedPointer dialogNormal; }; diff --git a/tools/drawTools/vtoolpoint.cpp b/tools/drawTools/vtoolpoint.cpp index afd581fd4..3deec4002 100644 --- a/tools/drawTools/vtoolpoint.cpp +++ b/tools/drawTools/vtoolpoint.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vtoolpoint.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,30 +24,27 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "vtoolpoint.h" -#include -#include -#include -#include +const QString VToolPoint::TagName = QStringLiteral("point"); -VToolPoint::VToolPoint(VDomDocument *doc, VContainer *data, qint64 id, - QGraphicsItem *parent):VDrawTool(doc, data, id), - QGraphicsEllipseItem(parent), radius(toPixel(1.5)), namePoint(0), lineName(0){ +VToolPoint::VToolPoint(VDomDocument *doc, VContainer *data, qint64 id, QGraphicsItem *parent):VDrawTool(doc, data, id), + QGraphicsEllipseItem(parent), radius(toPixel(2)), namePoint(0), lineName(0) +{ namePoint = new VGraphicsSimpleTextItem(this); lineName = new QGraphicsLineItem(this); connect(namePoint, &VGraphicsSimpleTextItem::NameChangePosition, this, &VToolPoint::NameChangePosition); - this->setPen(QPen(Qt::black, widthHairLine)); this->setBrush(QBrush(Qt::NoBrush)); this->setFlag(QGraphicsItem::ItemIsSelectable, true); this->setAcceptHoverEvents(true); RefreshPointGeometry(VAbstractTool::data.GetPoint(id)); } -void VToolPoint::NameChangePosition(const QPointF pos){ +void VToolPoint::NameChangePosition(const QPointF &pos) +{ VPointF point = VAbstractTool::data.GetPoint(id); QPointF p = pos - this->pos(); point.setMx(p.x()); @@ -50,77 +54,86 @@ void VToolPoint::NameChangePosition(const QPointF pos){ VAbstractTool::data.UpdatePoint(id, point); } -void VToolPoint::UpdateNamePosition(qreal mx, qreal my){ +void VToolPoint::UpdateNamePosition(qreal mx, qreal my) +{ QDomElement domElement = doc->elementById(QString().setNum(id)); - if(domElement.isElement()){ - domElement.setAttribute("mx", QString().setNum(toMM(mx))); - domElement.setAttribute("my", QString().setNum(toMM(my))); + if (domElement.isElement()) + { + domElement.setAttribute(AttrMx, QString().setNum(toMM(mx))); + domElement.setAttribute(AttrMy, QString().setNum(toMM(my))); emit toolhaveChange(); } } -void VToolPoint::ChangedActivDraw(const QString newName){ - if(nameActivDraw == newName){ - this->setPen(QPen(Qt::black, widthHairLine)); - 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)); - VDrawTool::ChangedActivDraw(newName); - } else { - this->setPen(QPen(Qt::gray, widthHairLine)); - 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)); - VDrawTool::ChangedActivDraw(newName); +void VToolPoint::ChangedActivDraw(const QString &newName) +{ + bool selectable = false; + if (nameActivDraw == newName) + { + selectable = true; + currentColor = Qt::black; } + else + { + selectable = false; + currentColor = Qt::gray; + } + 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)); - currentColor = baseColor; - } else { - this->setPen(QPen(color, widthHairLine)); - currentColor = color; - } - } +void VToolPoint::ShowTool(qint64 id, Qt::GlobalColor color, bool enable) +{ + ShowItem(this, id, color, enable); } -void VToolPoint::mouseReleaseEvent(QGraphicsSceneMouseEvent *event){ - if(event->button() == Qt::LeftButton){ +void VToolPoint::SetFactor(qreal factor) +{ + VDrawTool::SetFactor(factor); + RefreshPointGeometry(VAbstractTool::data.GetPoint(id)); +} + +void VToolPoint::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +{ + if (event->button() == Qt::LeftButton) + { emit ChoosedTool(id, Scene::Point); } QGraphicsItem::mouseReleaseEvent(event); } -void VToolPoint::hoverMoveEvent(QGraphicsSceneHoverEvent *event){ +void VToolPoint::hoverMoveEvent(QGraphicsSceneHoverEvent *event) +{ Q_UNUSED(event); - this->setPen(QPen(currentColor, widthMainLine)); + this->setPen(QPen(currentColor, widthMainLine/factor)); } -void VToolPoint::hoverLeaveEvent(QGraphicsSceneHoverEvent *event){ +void VToolPoint::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) +{ Q_UNUSED(event); - this->setPen(QPen(currentColor, widthHairLine)); + this->setPen(QPen(currentColor, widthHairLine/factor)); } -void VToolPoint::RefreshPointGeometry(const VPointF &point){ - QRectF rec = QRectF(0, 0, radius*2, radius*2); +void VToolPoint::RefreshPointGeometry(const VPointF &point) +{ + this->setPen(QPen(currentColor, widthHairLine/factor)); + QRectF rec = QRectF(0, 0, radius*2/factor, radius*2/factor); rec.translate(-rec.center().x(), -rec.center().y()); this->setRect(rec); this->setPos(point.toQPointF()); disconnect(namePoint, &VGraphicsSimpleTextItem::NameChangePosition, this, &VToolPoint::NameChangePosition); + QFont font = namePoint->font(); + font.setPointSize(static_cast(namePoint->FontSize()/factor)); + namePoint->setFont(font); namePoint->setText(point.name()); namePoint->setPos(QPointF(point.mx(), point.my())); connect(namePoint, &VGraphicsSimpleTextItem::NameChangePosition, this, @@ -128,18 +141,20 @@ void VToolPoint::RefreshPointGeometry(const VPointF &point){ RefreshLine(); } -void VToolPoint::RefreshLine(){ +void VToolPoint::RefreshLine() +{ QRectF nameRec = namePoint->sceneBoundingRect(); QPointF p1, p2; - LineIntersectCircle(QPointF(), radius, QLineF(QPointF(), nameRec.center()- scenePos()), p1, p2); + LineIntersectCircle(QPointF(), radius/factor, QLineF(QPointF(), nameRec.center()- scenePos()), p1, p2); QPointF pRec = LineIntersectRect(nameRec, QLineF(scenePos(), nameRec.center())); lineName->setLine(QLineF(p1, pRec - scenePos())); - if(QLineF(p1, pRec - scenePos()).length() <= toPixel(4)){ + lineName->setPen(QPen(currentColor, widthHairLine/factor)); + if (QLineF(p1, pRec - scenePos()).length() <= toPixel(4)) + { lineName->setVisible(false); - } else { + } + else + { lineName->setVisible(true); } } - -VToolPoint::~VToolPoint(){ -} diff --git a/tools/drawTools/vtoolpoint.h b/tools/drawTools/vtoolpoint.h index 4b740bd74..c7e26939e 100644 --- a/tools/drawTools/vtoolpoint.h +++ b/tools/drawTools/vtoolpoint.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vtoolpoint.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,25 +24,27 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef VTOOLPOINT_H #define VTOOLPOINT_H #include "vdrawtool.h" -#include "widgets/vgraphicssimpletextitem.h" +#include "../../widgets/vgraphicssimpletextitem.h" -class VToolPoint: public VDrawTool, public QGraphicsEllipseItem{ +class VToolPoint: public VDrawTool, public QGraphicsEllipseItem +{ Q_OBJECT public: - VToolPoint(VDomDocument *doc, VContainer *data, qint64 id, - QGraphicsItem * parent = 0); - virtual ~VToolPoint(); + VToolPoint(VDomDocument *doc, VContainer *data, qint64 id, QGraphicsItem * parent = 0); + virtual ~VToolPoint(){} + static const QString TagName; public slots: - void NameChangePosition(const QPointF pos); - virtual void ChangedActivDraw(const QString newName); + void NameChangePosition(const QPointF &pos); + virtual void ChangedActivDraw(const QString &newName); virtual void FullUpdateFromGui(int result) = 0; virtual void ShowTool(qint64 id, Qt::GlobalColor color, bool enable); + virtual void SetFactor(qreal factor); protected: qreal radius; VGraphicsSimpleTextItem *namePoint; diff --git a/tools/drawTools/vtoolpointofcontact.cpp b/tools/drawTools/vtoolpointofcontact.cpp index a87391f74..9d94bc7e9 100644 --- a/tools/drawTools/vtoolpointofcontact.cpp +++ b/tools/drawTools/vtoolpointofcontact.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vtoolpointofcontact.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,48 +24,55 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "vtoolpointofcontact.h" +#include "../../container/calculator.h" + +const QString VToolPointOfContact::ToolType = QStringLiteral("pointOfContact"); VToolPointOfContact::VToolPointOfContact(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &radius, const qint64 ¢er, const qint64 &firstPointId, const qint64 &secondPointId, - Tool::Sources typeCreation, QGraphicsItem *parent) + const Tool::Sources &typeCreation, QGraphicsItem *parent) : VToolPoint(doc, data, id, parent), radius(radius), center(center), firstPointId(firstPointId), - secondPointId(secondPointId), dialogPointOfContact(QSharedPointer()){ - - if(typeCreation == Tool::FromGui){ + secondPointId(secondPointId), dialogPointOfContact(QSharedPointer()) +{ + if (typeCreation == Tool::FromGui) + { AddToFile(); } } -void VToolPointOfContact::setDialog(){ - Q_ASSERT(!dialogPointOfContact.isNull()); - if(!dialogPointOfContact.isNull()){ - VPointF p = VAbstractTool::data.GetPoint(id); - dialogPointOfContact->setRadius(radius); - dialogPointOfContact->setCenter(center, id); - dialogPointOfContact->setFirstPoint(firstPointId, id); - dialogPointOfContact->setSecondPoint(secondPointId, id); - dialogPointOfContact->setPointName(p.name()); - } +void VToolPointOfContact::setDialog() +{ + Q_ASSERT(dialogPointOfContact.isNull() == false); + VPointF p = VAbstractTool::data.GetPoint(id); + dialogPointOfContact->setRadius(radius); + dialogPointOfContact->setCenter(center, id); + dialogPointOfContact->setFirstPoint(firstPointId, id); + dialogPointOfContact->setSecondPoint(secondPointId, id); + dialogPointOfContact->setPointName(p.name()); } QPointF VToolPointOfContact::FindPoint(const qreal &radius, const QPointF ¢er, const QPointF &firstPoint, - const QPointF &secondPoint){ + const QPointF &secondPoint) +{ QPointF pArc; qreal s = 0.0, s_x, s_y, step = 0.01, distans; - while( s < 1){ + 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)){ + if (fabs(distans*10 - radius*10) < 0.1) + { pArc.rx() = s_x; pArc.ry() = s_y; break; } - if(distans &dialog, VMainGraphicsScene *scene, - VDomDocument *doc, VContainer *data){ + VDomDocument *doc, VContainer *data) +{ QString radius = dialog->getRadius(); qint64 center = dialog->getCenter(); qint64 firstPointId = dialog->getFirstPoint(); @@ -82,7 +97,8 @@ void VToolPointOfContact::Create(const qint64 _id, const QString &radius, const const qint64 &firstPointId, const qint64 &secondPointId, const QString &pointName, const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, - const Document::Documents &parse, Tool::Sources typeCreation){ + const Document::Documents &parse, const Tool::Sources &typeCreation) +{ VPointF centerP = data->GetPoint(center); VPointF firstP = data->GetPoint(firstPointId); VPointF secondP = data->GetPoint(secondPointId); @@ -90,25 +106,38 @@ void VToolPointOfContact::Create(const qint64 _id, const QString &radius, const Calculator cal(data); QString errorMsg; qreal result = cal.eval(radius, &errorMsg); - if(errorMsg.isEmpty()){ - QPointF fPoint = VToolPointOfContact::FindPoint(result*PrintDPI/25.4, centerP.toQPointF(), + if (errorMsg.isEmpty()) + { + QPointF fPoint = VToolPointOfContact::FindPoint(toPixel(result), centerP.toQPointF(), firstP.toQPointF(), secondP.toQPointF()); qint64 id = _id; - if(typeCreation == Tool::FromGui){ + if (typeCreation == Tool::FromGui) + { id = data->AddPoint(VPointF(fPoint.x(), fPoint.y(), pointName, mx, my)); - } else { - data->UpdatePoint(id,VPointF(fPoint.x(), fPoint.y(), pointName, mx, my)); - if(parse != Document::FullParse){ + data->AddLine(firstPointId, id); + data->AddLine(secondPointId, id); + data->AddLine(center, id); + } + else + { + data->UpdatePoint(id, VPointF(fPoint.x(), fPoint.y(), pointName, mx, my)); + data->AddLine(firstPointId, id); + data->AddLine(secondPointId, id); + data->AddLine(center, id); + if (parse != Document::FullParse) + { doc->UpdateToolData(id, data); } } VDrawTool::AddRecord(id, Tool::PointOfContact, doc); - if(parse == Document::FullParse){ + if (parse == Document::FullParse) + { VToolPointOfContact *point = new VToolPointOfContact(doc, data, id, radius, center, firstPointId, secondPointId, typeCreation); scene->addItem(point); connect(point, &VToolPointOfContact::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); connect(point, &VToolPointOfContact::RemoveTool, scene, &VMainGraphicsScene::RemoveTool); + connect(scene, &VMainGraphicsScene::NewFactor, point, &VToolPointOfContact::SetFactor); doc->AddTool(id, point); doc->IncrementReferens(center); doc->IncrementReferens(firstPointId); @@ -117,55 +146,69 @@ void VToolPointOfContact::Create(const qint64 _id, const QString &radius, const } } -void VToolPointOfContact::FullUpdateFromFile(){ +void VToolPointOfContact::FullUpdateFromFile() +{ QDomElement domElement = doc->elementById(QString().setNum(id)); - if(domElement.isElement()){ - radius = domElement.attribute("radius", ""); - center = domElement.attribute("center", "").toLongLong(); - firstPointId = domElement.attribute("firstPoint", "").toLongLong(); - secondPointId = domElement.attribute("secondPoint", "").toLongLong(); + if (domElement.isElement()) + { + radius = domElement.attribute(AttrRadius, ""); + center = domElement.attribute(AttrCenter, "").toLongLong(); + firstPointId = domElement.attribute(AttrFirstPoint, "").toLongLong(); + secondPointId = domElement.attribute(AttrSecondPoint, "").toLongLong(); } RefreshPointGeometry(VAbstractTool::data.GetPoint(id)); } -void VToolPointOfContact::FullUpdateFromGui(int result){ - if(result == QDialog::Accepted){ +void VToolPointOfContact::FullUpdateFromGui(int result) +{ + if (result == QDialog::Accepted) + { QDomElement domElement = doc->elementById(QString().setNum(id)); - if(domElement.isElement()){ - domElement.setAttribute("name", dialogPointOfContact->getPointName()); - domElement.setAttribute("radius", dialogPointOfContact->getRadius()); - domElement.setAttribute("center", QString().setNum(dialogPointOfContact->getCenter())); - domElement.setAttribute("firstPoint", QString().setNum(dialogPointOfContact->getFirstPoint())); - domElement.setAttribute("secondPoint", QString().setNum(dialogPointOfContact->getSecondPoint())); + if (domElement.isElement()) + { + domElement.setAttribute(AttrName, dialogPointOfContact->getPointName()); + domElement.setAttribute(AttrRadius, dialogPointOfContact->getRadius()); + domElement.setAttribute(AttrCenter, QString().setNum(dialogPointOfContact->getCenter())); + domElement.setAttribute(AttrFirstPoint, QString().setNum(dialogPointOfContact->getFirstPoint())); + domElement.setAttribute(AttrSecondPoint, QString().setNum(dialogPointOfContact->getSecondPoint())); emit FullUpdateTree(); } } dialogPointOfContact.clear(); } -void VToolPointOfContact::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ +void VToolPointOfContact::SetFactor(qreal factor) +{ + VDrawTool::SetFactor(factor); + RefreshPointGeometry(VAbstractTool::data.GetPoint(id)); +} + +void VToolPointOfContact::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) +{ ContextMenu(dialogPointOfContact, this, event); } -void VToolPointOfContact::AddToFile(){ +void VToolPointOfContact::AddToFile() +{ VPointF point = VAbstractTool::data.GetPoint(id); - QDomElement domElement = doc->createElement("point"); + QDomElement domElement = doc->createElement(TagName); - AddAttribute(domElement, "id", id); - AddAttribute(domElement, "type", "pointOfContact"); - AddAttribute(domElement, "name", point.name()); - AddAttribute(domElement, "mx", point.mx()/PrintDPI*25.4); - AddAttribute(domElement, "my", point.my()/PrintDPI*25.4); + AddAttribute(domElement, AttrId, id); + AddAttribute(domElement, AttrType, ToolType); + AddAttribute(domElement, AttrName, point.name()); + AddAttribute(domElement, AttrMx, toMM(point.mx())); + AddAttribute(domElement, AttrMy, toMM(point.my())); - AddAttribute(domElement, "radius", radius); - AddAttribute(domElement, "center", center); - AddAttribute(domElement, "firstPoint", firstPointId); - AddAttribute(domElement, "secondPoint", secondPointId); + AddAttribute(domElement, AttrRadius, radius); + AddAttribute(domElement, AttrCenter, center); + AddAttribute(domElement, AttrFirstPoint, firstPointId); + AddAttribute(domElement, AttrSecondPoint, secondPointId); AddToCalculation(domElement); } -void VToolPointOfContact::RemoveReferens(){ +void VToolPointOfContact::RemoveReferens() +{ doc->DecrementReferens(center); doc->DecrementReferens(firstPointId); doc->DecrementReferens(secondPointId); diff --git a/tools/drawTools/vtoolpointofcontact.h b/tools/drawTools/vtoolpointofcontact.h index 4ed8e0c97..54025adde 100644 --- a/tools/drawTools/vtoolpointofcontact.h +++ b/tools/drawTools/vtoolpointofcontact.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vtoolpointofcontact.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,41 +24,44 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef VTOOLPOINTOFCONTACT_H #define VTOOLPOINTOFCONTACT_H #include "vtoolpoint.h" -#include "dialogs/dialogpointofcontact.h" +#include "../../dialogs/dialogpointofcontact.h" class VToolPointOfContact : public VToolPoint { public: - VToolPointOfContact(VDomDocument *doc, VContainer *data, const qint64 &id, - const QString &radius, const qint64 ¢er, const qint64 &firstPointId, - const qint64 &secondPointId, Tool::Sources typeCreation, QGraphicsItem * parent = 0); - virtual void setDialog(); - static QPointF FindPoint(const qreal &radius, const QPointF ¢er, const QPointF &firstPoint, - const QPointF &secondPoint); - static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, - VDomDocument *doc, VContainer *data); - static void Create(const qint64 _id, const QString &radius, const qint64 ¢er, const qint64 &firstPointId, - const qint64 &secondPointId, const QString &pointName, - const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data, const Document::Documents &parse, Tool::Sources typeCreation); + VToolPointOfContact(VDomDocument *doc, VContainer *data, const qint64 &id, + const QString &radius, const qint64 ¢er, + const qint64 &firstPointId, const qint64 &secondPointId, + const Tool::Sources &typeCreation, QGraphicsItem * parent = 0); + virtual void setDialog(); + static QPointF FindPoint(const qreal &radius, const QPointF ¢er, const QPointF &firstPoint, + const QPointF &secondPoint); + static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, + VDomDocument *doc, VContainer *data); + static void Create(const qint64 _id, const QString &radius, const qint64 ¢er, + const qint64 &firstPointId, const qint64 &secondPointId, const QString &pointName, + const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VDomDocument *doc, + VContainer *data, const Document::Documents &parse, const Tool::Sources &typeCreation); + static const QString ToolType; public slots: - virtual void FullUpdateFromFile(); - virtual void FullUpdateFromGui(int result); + virtual void FullUpdateFromFile(); + virtual void FullUpdateFromGui(int result); + virtual void SetFactor(qreal factor); protected: - virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile(); - virtual void RemoveReferens(); + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void AddToFile(); + virtual void RemoveReferens(); private: - QString radius; - qint64 center; - qint64 firstPointId; - qint64 secondPointId; + QString radius; + qint64 center; + qint64 firstPointId; + qint64 secondPointId; QSharedPointer dialogPointOfContact; }; diff --git a/tools/drawTools/vtoolpointofintersection.cpp b/tools/drawTools/vtoolpointofintersection.cpp new file mode 100644 index 000000000..dc0d4d7e8 --- /dev/null +++ b/tools/drawTools/vtoolpointofintersection.cpp @@ -0,0 +1,154 @@ +/************************************************************************ + ** + ** @file vtoolpointofintersection.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "vtoolpointofintersection.h" + +const QString VToolPointOfIntersection::ToolType = QStringLiteral("pointOfIntersection"); + +VToolPointOfIntersection::VToolPointOfIntersection(VDomDocument *doc, VContainer *data, const qint64 &id, + const qint64 &firstPointId, const qint64 &secondPointId, + const Tool::Sources &typeCreation, QGraphicsItem *parent) + :VToolPoint(doc, data, id, parent), firstPointId(firstPointId), secondPointId(secondPointId), + dialogPointOfIntersection(QSharedPointer()) +{ + ignoreFullUpdate = true; + if (typeCreation == Tool::FromGui) + { + AddToFile(); + } +} + +void VToolPointOfIntersection::setDialog() +{ + Q_ASSERT(dialogPointOfIntersection.isNull() == false); + VPointF p = VAbstractTool::data.GetPoint(id); + dialogPointOfIntersection->setFirstPointId(firstPointId, id); + dialogPointOfIntersection->setSecondPointId(secondPointId, id); + dialogPointOfIntersection->setPointName(p.name()); +} + +void VToolPointOfIntersection::Create(QSharedPointer &dialog, VMainGraphicsScene *scene, + VDomDocument *doc, VContainer *data) +{ + qint64 firstPointId = dialog->getFirstPointId(); + qint64 secondPointId = dialog->getSecondPointId(); + QString pointName = dialog->getPointName(); + Create(0, pointName, firstPointId, secondPointId, 5, 10, scene, doc, data, Document::FullParse, Tool::FromGui); +} + +void VToolPointOfIntersection::Create(const qint64 _id, const QString &pointName, const qint64 &firstPointId, + const qint64 &secondPointId, const qreal &mx, const qreal &my, + VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, + const Document::Documents &parse, const Tool::Sources &typeCreation) +{ + VPointF firstPoint = data->GetPoint(firstPointId); + VPointF secondPoint = data->GetPoint(secondPointId); + + QPointF point(firstPoint.x(), secondPoint.y()); + qint64 id = _id; + if (typeCreation == Tool::FromGui) + { + id = data->AddPoint(VPointF(point.x(), point.y(), pointName, mx, my)); + } + else + { + data->UpdatePoint(id, VPointF(point.x(), point.y(), pointName, mx, my)); + if (parse != Document::FullParse) + { + doc->UpdateToolData(id, data); + } + } + VDrawTool::AddRecord(id, Tool::Triangle, doc); + if (parse == Document::FullParse) + { + VToolPointOfIntersection *point = new VToolPointOfIntersection(doc, data, id, firstPointId, + secondPointId, typeCreation); + scene->addItem(point); + connect(point, &VToolPointOfIntersection::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); + connect(point, &VToolPointOfIntersection::RemoveTool, scene, &VMainGraphicsScene::RemoveTool); + connect(scene, &VMainGraphicsScene::NewFactor, point, &VToolPointOfIntersection::SetFactor); + doc->AddTool(id, point); + doc->IncrementReferens(firstPointId); + doc->IncrementReferens(secondPointId); + } +} + +void VToolPointOfIntersection::FullUpdateFromFile() +{ + QDomElement domElement = doc->elementById(QString().setNum(id)); + if (domElement.isElement()) + { + firstPointId = domElement.attribute(AttrFirstPoint, "").toLongLong(); + secondPointId = domElement.attribute(AttrSecondPoint, "").toLongLong(); + } + VToolPoint::RefreshPointGeometry(VDrawTool::data.GetPoint(id)); +} + +void VToolPointOfIntersection::FullUpdateFromGui(int result) +{ + if (result == QDialog::Accepted) + { + QDomElement domElement = doc->elementById(QString().setNum(id)); + if (domElement.isElement()) + { + domElement.setAttribute(AttrName, dialogPointOfIntersection->getPointName()); + domElement.setAttribute(AttrFirstPoint, QString().setNum(dialogPointOfIntersection->getFirstPointId())); + domElement.setAttribute(AttrSecondPoint, QString().setNum(dialogPointOfIntersection->getSecondPointId())); + emit FullUpdateTree(); + } + } + dialogPointOfIntersection.clear(); +} + +void VToolPointOfIntersection::RemoveReferens() +{ + doc->DecrementReferens(firstPointId); + doc->DecrementReferens(secondPointId); +} + +void VToolPointOfIntersection::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) +{ + ContextMenu(dialogPointOfIntersection, this, event); +} + +void VToolPointOfIntersection::AddToFile() +{ + VPointF point = VAbstractTool::data.GetPoint(id); + QDomElement domElement = doc->createElement(TagName); + + AddAttribute(domElement, AttrId, id); + AddAttribute(domElement, AttrType, ToolType); + AddAttribute(domElement, AttrName, point.name()); + AddAttribute(domElement, AttrMx, toMM(point.mx())); + AddAttribute(domElement, AttrMy, toMM(point.my())); + + AddAttribute(domElement, AttrFirstPoint, firstPointId); + AddAttribute(domElement, AttrSecondPoint, secondPointId); + + AddToCalculation(domElement); +} diff --git a/tools/drawTools/vtoolpointofintersection.h b/tools/drawTools/vtoolpointofintersection.h new file mode 100644 index 000000000..f311b5cbe --- /dev/null +++ b/tools/drawTools/vtoolpointofintersection.h @@ -0,0 +1,64 @@ +/************************************************************************ + ** + ** @file vtoolpointofintersection.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef VTOOLPOINTOFINTERSECTION_H +#define VTOOLPOINTOFINTERSECTION_H + +#include "vtoolpoint.h" +#include "../../dialogs/dialogpointofintersection.h" + +class VToolPointOfIntersection : public VToolPoint +{ + Q_OBJECT +public: + VToolPointOfIntersection(VDomDocument *doc, VContainer *data, const qint64 &id, + const qint64 &firstPointId, const qint64 &secondPointId, + const Tool::Sources &typeCreation, QGraphicsItem * parent = 0); + virtual void setDialog(); + static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, + VDomDocument *doc, VContainer *data); + static void Create(const qint64 _id, const QString &pointName, const qint64 &firstPointId, + const qint64 &secondPointId, const qreal &mx, const qreal &my, VMainGraphicsScene *scene, + VDomDocument *doc, VContainer *data, const Document::Documents &parse, + const Tool::Sources &typeCreation); + static const QString ToolType; +public slots: + virtual void FullUpdateFromFile(); + virtual void FullUpdateFromGui(int result); +protected: + virtual void RemoveReferens(); + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void AddToFile(); +private: + Q_DISABLE_COPY(VToolPointOfIntersection) + qint64 firstPointId; + qint64 secondPointId; + QSharedPointer dialogPointOfIntersection; +}; + +#endif // VTOOLPOINTOFINTERSECTION_H diff --git a/tools/drawTools/vtoolshoulderpoint.cpp b/tools/drawTools/vtoolshoulderpoint.cpp index 3b41fe3ef..115cc7b47 100644 --- a/tools/drawTools/vtoolshoulderpoint.cpp +++ b/tools/drawTools/vtoolshoulderpoint.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vtoolshoulderpoint.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,60 +24,67 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "vtoolshoulderpoint.h" -#include +#include "../../container/calculator.h" + +const QString VToolShoulderPoint::ToolType = QStringLiteral("shoulder"); VToolShoulderPoint::VToolShoulderPoint(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &typeLine, const QString &formula, const qint64 &p1Line, - const qint64 &p2Line, const qint64 &pShoulder, Tool::Sources typeCreation, - QGraphicsItem * parent): - VToolLinePoint(doc, data, id, typeLine, formula, p1Line, 0, parent), p2Line(p2Line), pShoulder(pShoulder), - dialogShoulderPoint(QSharedPointer()){ - - if(typeCreation == Tool::FromGui){ + const qint64 &p2Line, const qint64 &pShoulder, const Tool::Sources &typeCreation, + QGraphicsItem * parent) + :VToolLinePoint(doc, data, id, typeLine, formula, p1Line, 0, parent), p2Line(p2Line), pShoulder(pShoulder), + dialogShoulderPoint(QSharedPointer()) +{ + if (typeCreation == Tool::FromGui) + { AddToFile(); } - } -void VToolShoulderPoint::setDialog(){ - Q_ASSERT(!dialogShoulderPoint.isNull()); - if(!dialogShoulderPoint.isNull()){ - VPointF p = VAbstractTool::data.GetPoint(id); - dialogShoulderPoint->setTypeLine(typeLine); - dialogShoulderPoint->setFormula(formula); - dialogShoulderPoint->setP1Line(basePointId, id); - dialogShoulderPoint->setP2Line(p2Line, id); - dialogShoulderPoint->setPShoulder(pShoulder, id); - dialogShoulderPoint->setPointName(p.name()); - } +void VToolShoulderPoint::setDialog() +{ + Q_ASSERT(dialogShoulderPoint.isNull() == false); + VPointF p = VAbstractTool::data.GetPoint(id); + dialogShoulderPoint->setTypeLine(typeLine); + dialogShoulderPoint->setFormula(formula); + dialogShoulderPoint->setP1Line(basePointId, id); + dialogShoulderPoint->setP2Line(p2Line, id); + dialogShoulderPoint->setPShoulder(pShoulder, id); + dialogShoulderPoint->setPointName(p.name()); } QPointF VToolShoulderPoint::FindPoint(const QPointF &p1Line, const QPointF &p2Line, const QPointF &pShoulder, - const qreal &length){ + const qreal &length) +{ QLineF line = QLineF(p1Line, p2Line); - qreal dist = line.length(); - if(dist>length){ - qDebug()<<"A3П2="<length) + { + qDebug()<<"A3П2="<=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(); - } - } + } } void VToolShoulderPoint::Create(QSharedPointer &dialog, VMainGraphicsScene *scene, - VDomDocument *doc, VContainer *data){ + VDomDocument *doc, VContainer *data) +{ QString formula = dialog->getFormula(); qint64 p1Line = dialog->getP1Line(); qint64 p2Line = dialog->getP2Line(); @@ -85,7 +99,8 @@ void VToolShoulderPoint::Create(const qint64 _id, const QString &formula, const const qint64 &p2Line, const qint64 &pShoulder, 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 Document::Documents &parse, const Tool::Sources &typeCreation) +{ VPointF firstPoint = data->GetPoint(p1Line); VPointF secondPoint = data->GetPoint(p2Line); VPointF shoulderPoint = data->GetPoint(pShoulder); @@ -93,28 +108,37 @@ void VToolShoulderPoint::Create(const qint64 _id, const QString &formula, const Calculator cal(data); QString errorMsg; qreal result = cal.eval(formula, &errorMsg); - if(errorMsg.isEmpty()){ + if (errorMsg.isEmpty()) + { QPointF fPoint = VToolShoulderPoint::FindPoint(firstPoint.toQPointF(), secondPoint.toQPointF(), - shoulderPoint.toQPointF(), result*PrintDPI/25.4); + shoulderPoint.toQPointF(), toPixel(result)); qint64 id = _id; - if(typeCreation == Tool::FromGui){ + if (typeCreation == Tool::FromGui) + { id = data->AddPoint(VPointF(fPoint.x(), fPoint.y(), pointName, mx, my)); - } else { - data->UpdatePoint(id,VPointF(fPoint.x(), fPoint.y(), pointName, mx, my)); - if(parse != Document::FullParse){ + data->AddLine(p1Line, id); + data->AddLine(p2Line, id); + } + else + { + data->UpdatePoint(id, VPointF(fPoint.x(), fPoint.y(), pointName, mx, my)); + data->AddLine(p1Line, id); + data->AddLine(p2Line, id); + if (parse != Document::FullParse) + { doc->UpdateToolData(id, data); } } - data->AddLine(p1Line, id); - data->AddLine(p2Line, id); VDrawTool::AddRecord(id, Tool::ShoulderPointTool, doc); - if(parse == Document::FullParse){ + if (parse == Document::FullParse) + { VToolShoulderPoint *point = new VToolShoulderPoint(doc, data, id, typeLine, formula, p1Line, p2Line, pShoulder, typeCreation); scene->addItem(point); connect(point, &VToolShoulderPoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); connect(point, &VToolShoulderPoint::RemoveTool, scene, &VMainGraphicsScene::RemoveTool); + connect(scene, &VMainGraphicsScene::NewFactor, point, &VToolShoulderPoint::SetFactor); doc->AddTool(id, point); doc->IncrementReferens(p1Line); doc->IncrementReferens(p2Line); @@ -123,58 +147,72 @@ void VToolShoulderPoint::Create(const qint64 _id, const QString &formula, const } } -void VToolShoulderPoint::FullUpdateFromFile(){ +void VToolShoulderPoint::FullUpdateFromFile() +{ QDomElement domElement = doc->elementById(QString().setNum(id)); - if(domElement.isElement()){ - typeLine = domElement.attribute("typeLine", ""); - formula = domElement.attribute("length", ""); - basePointId = domElement.attribute("p1Line", "").toLongLong(); - p2Line = domElement.attribute("p2Line", "").toLongLong(); - pShoulder = domElement.attribute("pShoulder", "").toLongLong(); + if (domElement.isElement()) + { + typeLine = domElement.attribute(AttrTypeLine, ""); + formula = domElement.attribute(AttrLength, ""); + basePointId = domElement.attribute(AttrP1Line, "").toLongLong(); + p2Line = domElement.attribute(AttrP2Line, "").toLongLong(); + pShoulder = domElement.attribute(AttrPShoulder, "").toLongLong(); } RefreshGeometry(); } -void VToolShoulderPoint::FullUpdateFromGui(int result){ - if(result == QDialog::Accepted){ +void VToolShoulderPoint::FullUpdateFromGui(int result) +{ + if (result == QDialog::Accepted) + { QDomElement domElement = doc->elementById(QString().setNum(id)); - if(domElement.isElement()){ - domElement.setAttribute("name", dialogShoulderPoint->getPointName()); - domElement.setAttribute("typeLine", dialogShoulderPoint->getTypeLine()); - domElement.setAttribute("length", dialogShoulderPoint->getFormula()); - domElement.setAttribute("p1Line", QString().setNum(dialogShoulderPoint->getP1Line())); - domElement.setAttribute("p2Line", QString().setNum(dialogShoulderPoint->getP2Line())); - domElement.setAttribute("pShoulder", QString().setNum(dialogShoulderPoint->getPShoulder())); + if (domElement.isElement()) + { + domElement.setAttribute(AttrName, dialogShoulderPoint->getPointName()); + domElement.setAttribute(AttrTypeLine, dialogShoulderPoint->getTypeLine()); + domElement.setAttribute(AttrLength, dialogShoulderPoint->getFormula()); + domElement.setAttribute(AttrP1Line, QString().setNum(dialogShoulderPoint->getP1Line())); + domElement.setAttribute(AttrP2Line, QString().setNum(dialogShoulderPoint->getP2Line())); + domElement.setAttribute(AttrPShoulder, QString().setNum(dialogShoulderPoint->getPShoulder())); emit FullUpdateTree(); } } dialogShoulderPoint.clear(); } -void VToolShoulderPoint::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ +void VToolShoulderPoint::SetFactor(qreal factor) +{ + VDrawTool::SetFactor(factor); + RefreshGeometry(); +} + +void VToolShoulderPoint::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) +{ ContextMenu(dialogShoulderPoint, this, event); } -void VToolShoulderPoint::AddToFile(){ +void VToolShoulderPoint::AddToFile() +{ VPointF point = VAbstractTool::data.GetPoint(id); - QDomElement domElement = doc->createElement("point"); + QDomElement domElement = doc->createElement(TagName); - AddAttribute(domElement, "id", id); - AddAttribute(domElement, "type", "shoulder"); - AddAttribute(domElement, "name", point.name()); - AddAttribute(domElement, "mx", point.mx()/PrintDPI*25.4); - AddAttribute(domElement, "my", point.my()/PrintDPI*25.4); + AddAttribute(domElement, AttrId, id); + AddAttribute(domElement, AttrType, ToolType); + AddAttribute(domElement, AttrName, point.name()); + AddAttribute(domElement, AttrMx, toMM(point.mx())); + AddAttribute(domElement, AttrMy, toMM(point.my())); - AddAttribute(domElement, "typeLine", typeLine); - AddAttribute(domElement, "length", formula); - AddAttribute(domElement, "p1Line", basePointId); - AddAttribute(domElement, "p2Line", p2Line); - AddAttribute(domElement, "pShoulder", pShoulder); + AddAttribute(domElement, AttrTypeLine, typeLine); + AddAttribute(domElement, AttrLength, formula); + AddAttribute(domElement, AttrP1Line, basePointId); + AddAttribute(domElement, AttrP2Line, p2Line); + AddAttribute(domElement, AttrPShoulder, pShoulder); AddToCalculation(domElement); } -void VToolShoulderPoint::RemoveReferens(){ +void VToolShoulderPoint::RemoveReferens() +{ doc->DecrementReferens(p2Line); doc->DecrementReferens(pShoulder); VToolLinePoint::RemoveReferens(); diff --git a/tools/drawTools/vtoolshoulderpoint.h b/tools/drawTools/vtoolshoulderpoint.h index 91f682ecb..efede5abd 100644 --- a/tools/drawTools/vtoolshoulderpoint.h +++ b/tools/drawTools/vtoolshoulderpoint.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vtoolshoulderpoint.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,40 +24,42 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef VTOOLSHOULDERPOINT_H #define VTOOLSHOULDERPOINT_H #include "vtoollinepoint.h" -#include "dialogs/dialogshoulderpoint.h" +#include "../../dialogs/dialogshoulderpoint.h" class VToolShoulderPoint : public VToolLinePoint { public: - VToolShoulderPoint(VDomDocument *doc, VContainer *data, const qint64 &id, - const QString &typeLine, const QString &formula, const qint64 &p1Line, - const qint64 &p2Line, const qint64 &pShoulder, 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 void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, - VDomDocument *doc, VContainer *data); - static void 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, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data, const Document::Documents &parse, Tool::Sources typeCreation); + VToolShoulderPoint(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &typeLine, + const QString &formula, const qint64 &p1Line, const qint64 &p2Line, + const qint64 &pShoulder, const 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 void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, + VContainer *data); + static void 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, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, + const Document::Documents &parse, const Tool::Sources &typeCreation); + static const QString ToolType; public slots: - virtual void FullUpdateFromFile(); - virtual void FullUpdateFromGui(int result); + virtual void FullUpdateFromFile(); + virtual void FullUpdateFromGui(int result); + virtual void SetFactor(qreal factor); protected: - virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile(); - virtual void RemoveReferens(); + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void AddToFile(); + virtual void RemoveReferens(); private: - qint64 p2Line; - qint64 pShoulder; + qint64 p2Line; + qint64 pShoulder; QSharedPointer dialogShoulderPoint; }; diff --git a/tools/drawTools/vtoolsinglepoint.cpp b/tools/drawTools/vtoolsinglepoint.cpp index f244d0104..0308f2963 100644 --- a/tools/drawTools/vtoolsinglepoint.cpp +++ b/tools/drawTools/vtoolsinglepoint.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vtoolsinglepoint.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,67 +24,72 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "vtoolsinglepoint.h" -#include -#include -#include -#include -#include -VToolSinglePoint::VToolSinglePoint (VDomDocument *doc, VContainer *data, qint64 id, Tool::Sources typeCreation, - QGraphicsItem * parent ):VToolPoint(doc, data, id, parent), - dialogSinglePoint(QSharedPointer()){ +const QString VToolSinglePoint::ToolType = QStringLiteral("single"); + +VToolSinglePoint::VToolSinglePoint (VDomDocument *doc, VContainer *data, qint64 id, const Tool::Sources &typeCreation, + QGraphicsItem * parent ) + :VToolPoint(doc, data, id, parent), dialogSinglePoint(QSharedPointer()) +{ + ignoreFullUpdate = true; this->setFlag(QGraphicsItem::ItemIsMovable, true); this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); - if(typeCreation == Tool::FromGui){ + if (typeCreation == Tool::FromGui) + { AddToFile(); } } -void VToolSinglePoint::setDialog(){ - Q_ASSERT(!dialogSinglePoint.isNull()); - if(!dialogSinglePoint.isNull()){ - VPointF p = VAbstractTool::data.GetPoint(id); - dialogSinglePoint->setData(p.name(), p.toQPointF()); - } +void VToolSinglePoint::setDialog() +{ + Q_ASSERT(dialogSinglePoint.isNull() == false); + VPointF p = VAbstractTool::data.GetPoint(id); + dialogSinglePoint->setData(p.name(), p.toQPointF()); } -void VToolSinglePoint::AddToFile(){ +void VToolSinglePoint::AddToFile() +{ VPointF point = VAbstractTool::data.GetPoint(id); - QDomElement domElement = doc->createElement("point"); + QDomElement domElement = doc->createElement(TagName); - AddAttribute(domElement, "id", id); - AddAttribute(domElement, "type", "single"); - AddAttribute(domElement, "name", point.name()); - AddAttribute(domElement, "x", toMM(point.x())); - AddAttribute(domElement, "y", toMM(point.y())); - AddAttribute(domElement, "mx", toMM(point.mx())); - AddAttribute(domElement, "my", toMM(point.my())); + AddAttribute(domElement, AttrId, id); + AddAttribute(domElement, AttrType, ToolType); + AddAttribute(domElement, AttrName, point.name()); + AddAttribute(domElement, AttrX, toMM(point.x())); + AddAttribute(domElement, AttrY, toMM(point.y())); + AddAttribute(domElement, AttrMx, toMM(point.mx())); + AddAttribute(domElement, AttrMy, toMM(point.my())); AddToCalculation(domElement); } -QVariant VToolSinglePoint::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value){ - if (change == ItemPositionChange && scene()) { +QVariant VToolSinglePoint::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) +{ + if (change == ItemPositionChange && scene()) + { // value - это новое положение. QPointF newPos = value.toPointF(); QRectF rect = scene()->sceneRect(); - if (!rect.contains(newPos)) { + if (rect.contains(newPos) == false) + { // Сохраняем элемент внутри прямоугольника сцены. newPos.setX(qMin(rect.right(), qMax(newPos.x(), rect.left()))); newPos.setY(qMin(rect.bottom(), qMax(newPos.y(), rect.top()))); return newPos; } } - if (change == ItemPositionHasChanged && scene()) { + if (change == ItemPositionHasChanged && scene()) + { // value - это новое положение. QPointF newPos = value.toPointF(); QDomElement domElement = doc->elementById(QString().setNum(id)); - if(domElement.isElement()){ - domElement.setAttribute("x", QString().setNum(toMM(newPos.x()))); - domElement.setAttribute("y", QString().setNum(toMM(newPos.y()))); + if (domElement.isElement()) + { + domElement.setAttribute(AttrX, QString().setNum(toMM(newPos.x()))); + domElement.setAttribute(AttrY, QString().setNum(toMM(newPos.y()))); //I don't now why but signal does not work. doc->FullUpdateTree(); } @@ -85,29 +97,36 @@ QVariant VToolSinglePoint::itemChange(QGraphicsItem::GraphicsItemChange change, return QGraphicsItem::itemChange(change, value); } -void VToolSinglePoint::decrementReferens(){ - if(_referens > 1){ +void VToolSinglePoint::decrementReferens() +{ + if (_referens > 1) + { --_referens; } } -void VToolSinglePoint::contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ){ +void VToolSinglePoint::contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ) +{ ContextMenu(dialogSinglePoint, this, event, false); } -void VToolSinglePoint::FullUpdateFromFile(){ +void VToolSinglePoint::FullUpdateFromFile() +{ RefreshPointGeometry(VAbstractTool::data.GetPoint(id)); } -void VToolSinglePoint::FullUpdateFromGui(int result){ - if(result == QDialog::Accepted){ +void VToolSinglePoint::FullUpdateFromGui(int result) +{ + if (result == QDialog::Accepted) + { QPointF p = dialogSinglePoint->getPoint(); QString name = dialogSinglePoint->getName(); QDomElement domElement = doc->elementById(QString().setNum(id)); - if(domElement.isElement()){ - domElement.setAttribute("name", name); - domElement.setAttribute("x", QString().setNum(toMM(p.x()))); - domElement.setAttribute("y", QString().setNum(toMM(p.y()))); + if (domElement.isElement()) + { + domElement.setAttribute(AttrName, name); + domElement.setAttribute(AttrX, QString().setNum(toMM(p.x()))); + domElement.setAttribute(AttrY, QString().setNum(toMM(p.y()))); //I don't now why but signal does not work. doc->FullUpdateTree(); } @@ -115,12 +134,22 @@ void VToolSinglePoint::FullUpdateFromGui(int result){ dialogSinglePoint.clear(); } -void VToolSinglePoint::ChangedActivDraw(const QString newName){ - if(nameActivDraw == newName){ +void VToolSinglePoint::ChangedActivDraw(const QString &newName) +{ + if (nameActivDraw == newName) + { this->setFlag(QGraphicsItem::ItemIsSelectable, true); VToolPoint::ChangedActivDraw(newName); - } else { + } + else + { this->setFlag(QGraphicsItem::ItemIsSelectable, false); VToolPoint::ChangedActivDraw(newName); } } + +void VToolSinglePoint::SetFactor(qreal factor) +{ + VDrawTool::SetFactor(factor); + RefreshPointGeometry(VAbstractTool::data.GetPoint(id)); +} diff --git a/tools/drawTools/vtoolsinglepoint.h b/tools/drawTools/vtoolsinglepoint.h index f5b2dad67..d0d482fd4 100644 --- a/tools/drawTools/vtoolsinglepoint.h +++ b/tools/drawTools/vtoolsinglepoint.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vtoolsinglepoint.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,32 +24,34 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef VTOOLSINGLEPOINT_H #define VTOOLSINGLEPOINT_H -#include "dialogs/dialogsinglepoint.h" #include "vtoolpoint.h" +#include "../../dialogs/dialogsinglepoint.h" class VToolSinglePoint : public VToolPoint { Q_OBJECT public: - VToolSinglePoint (VDomDocument *doc, VContainer *data, qint64 id, - Tool::Sources typeCreation, QGraphicsItem * parent = 0 ); - virtual void setDialog(); + VToolSinglePoint (VDomDocument *doc, VContainer *data, qint64 id, const Tool::Sources &typeCreation, + QGraphicsItem * parent = 0 ); + virtual void setDialog(); + static const QString ToolType; public slots: - virtual void FullUpdateFromFile(); - virtual void FullUpdateFromGui(int result); - virtual void ChangedActivDraw(const QString newName); + virtual void FullUpdateFromFile(); + virtual void FullUpdateFromGui(int result); + virtual void ChangedActivDraw(const QString &newName); + virtual void SetFactor(qreal factor); signals: - void FullUpdateTree(); + void FullUpdateTree(); protected: - virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile(); - QVariant itemChange ( GraphicsItemChange change, const QVariant &value ); - virtual void decrementReferens(); + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void AddToFile(); + QVariant itemChange ( GraphicsItemChange change, const QVariant &value ); + virtual void decrementReferens(); private: QSharedPointer dialogSinglePoint; }; diff --git a/tools/drawTools/vtoolspline.cpp b/tools/drawTools/vtoolspline.cpp index 85d80d197..b1ab4c6dd 100644 --- a/tools/drawTools/vtoolspline.cpp +++ b/tools/drawTools/vtoolspline.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vtoolspline.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,24 +24,27 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "vtoolspline.h" -#include -#include "geometry/vspline.h" +#include "../../geometry/vspline.h" +const QString VToolSpline::TagName = QStringLiteral("spline"); +const QString VToolSpline::ToolType = QStringLiteral("simple"); -VToolSpline::VToolSpline(VDomDocument *doc, VContainer *data, qint64 id, - Tool::Sources typeCreation, - QGraphicsItem *parent):VDrawTool(doc, data, id), QGraphicsPathItem(parent), - dialogSpline(QSharedPointer()), controlPoints(QVector()){ +VToolSpline::VToolSpline(VDomDocument *doc, VContainer *data, qint64 id, const Tool::Sources &typeCreation, + QGraphicsItem *parent) + :VDrawTool(doc, data, id), QGraphicsPathItem(parent), dialogSpline(QSharedPointer()), + controlPoints(QVector()) +{ + ignoreFullUpdate = true; VSpline spl = data->GetSpline(id); QPainterPath path; path.addPath(spl.GetPath()); path.setFillRule( Qt::WindingFill ); this->setPath(path); - this->setPen(QPen(Qt::black, widthHairLine)); + this->setPen(QPen(Qt::black, widthHairLine/factor)); this->setFlag(QGraphicsItem::ItemIsSelectable, true); this->setAcceptHoverEvents(true); @@ -54,27 +64,28 @@ VToolSpline::VToolSpline(VDomDocument *doc, VContainer *data, qint64 id, connect(this, &VToolSpline::setEnabledPoint, controlPoint2, &VControlPointSpline::setEnabledPoint); controlPoints.append(controlPoint2); - if(typeCreation == Tool::FromGui){ + if (typeCreation == Tool::FromGui) + { AddToFile(); } } -void VToolSpline::setDialog(){ - Q_ASSERT(!dialogSpline.isNull()); - if(!dialogSpline.isNull()){ - VSpline spl = VAbstractTool::data.GetSpline(id); - dialogSpline->setP1(spl.GetP1()); - dialogSpline->setP4(spl.GetP4()); - dialogSpline->setAngle1(spl.GetAngle1()); - dialogSpline->setAngle2(spl.GetAngle2()); - dialogSpline->setKAsm1(spl.GetKasm1()); - dialogSpline->setKAsm2(spl.GetKasm2()); - dialogSpline->setKCurve(spl.GetKcurve()); - } +void VToolSpline::setDialog() +{ + Q_ASSERT(dialogSpline.isNull() == false); + VSpline spl = VAbstractTool::data.GetSpline(id); + dialogSpline->setP1(spl.GetP1()); + dialogSpline->setP4(spl.GetP4()); + dialogSpline->setAngle1(spl.GetAngle1()); + dialogSpline->setAngle2(spl.GetAngle2()); + dialogSpline->setKAsm1(spl.GetKasm1()); + dialogSpline->setKAsm2(spl.GetKasm2()); + dialogSpline->setKCurve(spl.GetKcurve()); } void VToolSpline::Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data){ + VContainer *data) +{ qint64 p1 = dialog->getP1(); qint64 p4 = dialog->getP4(); qreal kAsm1 = dialog->getKAsm1(); @@ -88,37 +99,48 @@ void VToolSpline::Create(QSharedPointer &dialog, VMainGraphicsScen void VToolSpline::Create(const qint64 _id, const qint64 &p1, const qint64 &p4, const qreal &kAsm1, const qreal kAsm2, const qreal &angle1, const qreal &angle2, const qreal &kCurve, - VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, const Document::Documents &parse, - Tool::Sources typeCreation){ + VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, + const Document::Documents &parse, const Tool::Sources &typeCreation) +{ VSpline spline = VSpline(data->DataPoints(), p1, p4, angle1, angle2, kAsm1, kAsm2, kCurve); qint64 id = _id; - if(typeCreation == Tool::FromGui){ + if (typeCreation == Tool::FromGui) + { id = data->AddSpline(spline); - } else { + data->AddLengthSpline(spline.name(), toMM(spline.GetLength())); + } + else + { data->UpdateSpline(id, spline); - if(parse != Document::FullParse){ + data->AddLengthSpline(spline.name(), toMM(spline.GetLength())); + if (parse != Document::FullParse) + { doc->UpdateToolData(id, data); } } - data->AddLengthSpline(data->GetNameSpline(p1, p4), spline.GetLength()); VDrawTool::AddRecord(id, Tool::SplineTool, doc); - if(parse == Document::FullParse){ + if (parse == Document::FullParse) + { VToolSpline *spl = new VToolSpline(doc, data, id, typeCreation); scene->addItem(spl); connect(spl, &VToolSpline::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); connect(spl, &VToolSpline::RemoveTool, scene, &VMainGraphicsScene::RemoveTool); + connect(scene, &VMainGraphicsScene::NewFactor, spl, &VToolSpline::SetFactor); doc->AddTool(id, spl); doc->IncrementReferens(p1); doc->IncrementReferens(p4); } } -void VToolSpline::FullUpdateFromFile(){ +void VToolSpline::FullUpdateFromFile() +{ RefreshGeometry(); } -void VToolSpline::FullUpdateFromGui(int result){ - if(result == QDialog::Accepted){ +void VToolSpline::FullUpdateFromGui(int result) +{ + if (result == QDialog::Accepted) + { VSpline spl = VSpline (VAbstractTool::data.DataPoints(), dialogSpline->getP1(), dialogSpline->getP4(), dialogSpline->getAngle1(), dialogSpline->getAngle2(), dialogSpline->getKAsm1(), dialogSpline->getKAsm2(), dialogSpline->getKCurve()); @@ -137,85 +159,100 @@ void VToolSpline::FullUpdateFromGui(int result){ spl = VSpline (VAbstractTool::data.DataPoints(), dialogSpline->getP1(), controlPoints[0]->pos(), controlPoints[1]->pos(), dialogSpline->getP4(), dialogSpline->getKCurve()); QDomElement domElement = doc->elementById(QString().setNum(id)); - if(domElement.isElement()){ - domElement.setAttribute("point1", QString().setNum(spl.GetP1())); - domElement.setAttribute("point4", QString().setNum(spl.GetP4())); - domElement.setAttribute("angle1", QString().setNum(spl.GetAngle1())); - domElement.setAttribute("angle2", QString().setNum(spl.GetAngle2())); - domElement.setAttribute("kAsm1", QString().setNum(spl.GetKasm1())); - domElement.setAttribute("kAsm2", QString().setNum(spl.GetKasm2())); - domElement.setAttribute("kCurve", QString().setNum(spl.GetKcurve())); + if (domElement.isElement()) + { + domElement.setAttribute(AttrPoint1, QString().setNum(spl.GetP1())); + domElement.setAttribute(AttrPoint4, QString().setNum(spl.GetP4())); + domElement.setAttribute(AttrAngle1, QString().setNum(spl.GetAngle1())); + domElement.setAttribute(AttrAngle2, QString().setNum(spl.GetAngle2())); + domElement.setAttribute(AttrKAsm1, QString().setNum(spl.GetKasm1())); + domElement.setAttribute(AttrKAsm2, QString().setNum(spl.GetKasm2())); + domElement.setAttribute(AttrKCurve, QString().setNum(spl.GetKcurve())); emit FullUpdateTree(); } } dialogSpline.clear(); } -void VToolSpline::ControlPointChangePosition(const qint32 &indexSpline, SplinePoint::Position position, - const QPointF pos){ +void VToolSpline::ControlPointChangePosition(const qint32 &indexSpline, const SplinePoint::Position &position, + const QPointF &pos) +{ Q_UNUSED(indexSpline); VSpline spl = VAbstractTool::data.GetSpline(id); - if(position == SplinePoint::FirstPoint){ + if (position == SplinePoint::FirstPoint) + { spl.ModifiSpl (spl.GetP1(), pos, spl.GetP3(), spl.GetP4(), spl.GetKcurve()); - } else { + } + else + { spl.ModifiSpl (spl.GetP1(), spl.GetP2(), pos, spl.GetP4(), spl.GetKcurve()); } QDomElement domElement = doc->elementById(QString().setNum(id)); - if(domElement.isElement()){ - domElement.setAttribute("angle1", QString().setNum(spl.GetAngle1())); - domElement.setAttribute("angle2", QString().setNum(spl.GetAngle2())); - domElement.setAttribute("kAsm1", QString().setNum(spl.GetKasm1())); - domElement.setAttribute("kAsm2", QString().setNum(spl.GetKasm2())); - domElement.setAttribute("kCurve", QString().setNum(spl.GetKcurve())); + if (domElement.isElement()) + { + domElement.setAttribute(AttrAngle1, QString().setNum(spl.GetAngle1())); + domElement.setAttribute(AttrAngle2, QString().setNum(spl.GetAngle2())); + domElement.setAttribute(AttrKAsm1, QString().setNum(spl.GetKasm1())); + domElement.setAttribute(AttrKAsm2, QString().setNum(spl.GetKasm2())); + domElement.setAttribute(AttrKCurve, QString().setNum(spl.GetKcurve())); emit FullUpdateTree(); } } -void VToolSpline::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ +void VToolSpline::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) +{ ContextMenu(dialogSpline, this, event); } -void VToolSpline::AddToFile(){ +void VToolSpline::AddToFile() +{ VSpline spl = VAbstractTool::data.GetSpline(id); - QDomElement domElement = doc->createElement("spline"); + QDomElement domElement = doc->createElement(TagName); - AddAttribute(domElement, "id", id); - AddAttribute(domElement, "type", "simple"); - AddAttribute(domElement, "point1", spl.GetP1()); - AddAttribute(domElement, "point4", spl.GetP4()); - AddAttribute(domElement, "angle1", spl.GetAngle1()); - AddAttribute(domElement, "angle2", spl.GetAngle2()); - AddAttribute(domElement, "kAsm1", spl.GetKasm1()); - AddAttribute(domElement, "kAsm2", spl.GetKasm2()); - AddAttribute(domElement, "kCurve", spl.GetKcurve()); + AddAttribute(domElement, AttrId, id); + AddAttribute(domElement, AttrType, ToolType); + AddAttribute(domElement, AttrPoint1, spl.GetP1()); + AddAttribute(domElement, AttrPoint4, spl.GetP4()); + AddAttribute(domElement, AttrAngle1, spl.GetAngle1()); + AddAttribute(domElement, AttrAngle2, spl.GetAngle2()); + AddAttribute(domElement, AttrKAsm1, spl.GetKasm1()); + AddAttribute(domElement, AttrKAsm2, spl.GetKasm2()); + AddAttribute(domElement, AttrKCurve, spl.GetKcurve()); AddToCalculation(domElement); } -void VToolSpline::mouseReleaseEvent(QGraphicsSceneMouseEvent *event){ - if(event->button() == Qt::LeftButton){ +void VToolSpline::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +{ + if (event->button() == Qt::LeftButton) + { emit ChoosedTool(id, Scene::Spline); } QGraphicsItem::mouseReleaseEvent(event); } -void VToolSpline::hoverMoveEvent(QGraphicsSceneHoverEvent *event){ +void VToolSpline::hoverMoveEvent(QGraphicsSceneHoverEvent *event) +{ Q_UNUSED(event); - this->setPen(QPen(currentColor, widthMainLine)); + this->setPen(QPen(currentColor, widthMainLine/factor)); } -void VToolSpline::hoverLeaveEvent(QGraphicsSceneHoverEvent *event){ +void VToolSpline::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) +{ Q_UNUSED(event); - this->setPen(QPen(currentColor, widthHairLine)); + this->setPen(QPen(currentColor, widthHairLine/factor)); } -void VToolSpline::RemoveReferens(){ +void VToolSpline::RemoveReferens() +{ VSpline spl = VAbstractTool::data.GetSpline(id); doc->DecrementReferens(spl.GetP1()); doc->DecrementReferens(spl.GetP4()); } -void VToolSpline::RefreshGeometry(){ +void VToolSpline::RefreshGeometry() +{ + this->setPen(QPen(currentColor, widthHairLine/factor)); VSpline spl = VAbstractTool::data.GetSpline(id); QPainterPath path; path.addPath(spl.GetPath()); @@ -241,30 +278,33 @@ void VToolSpline::RefreshGeometry(){ } -void VToolSpline::ChangedActivDraw(const QString newName){ - if(nameActivDraw == newName){ - this->setPen(QPen(Qt::black, widthHairLine)); - this->setFlag(QGraphicsItem::ItemIsSelectable, true); - this->setAcceptHoverEvents(true); - emit setEnabledPoint(true); - VDrawTool::ChangedActivDraw(newName); - } else { - this->setPen(QPen(Qt::gray, widthHairLine)); - this->setFlag(QGraphicsItem::ItemIsSelectable, false); - this->setAcceptHoverEvents (false); - emit setEnabledPoint(false); - VDrawTool::ChangedActivDraw(newName); +void VToolSpline::ChangedActivDraw(const QString &newName) +{ + bool selectable = false; + if (nameActivDraw == newName) + { + selectable = true; + currentColor = Qt::black; } + else + { + selectable = false; + currentColor = Qt::gray; + } + 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)); - currentColor = baseColor; - } else { - this->setPen(QPen(color, widthHairLine)); - currentColor = color; - } - } +void VToolSpline::ShowTool(qint64 id, Qt::GlobalColor color, bool enable) +{ + ShowItem(this, id, color, enable); +} + +void VToolSpline::SetFactor(qreal factor) +{ + VDrawTool::SetFactor(factor); + RefreshGeometry(); } diff --git a/tools/drawTools/vtoolspline.h b/tools/drawTools/vtoolspline.h index b421b35a0..d4277af40 100644 --- a/tools/drawTools/vtoolspline.h +++ b/tools/drawTools/vtoolspline.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vtoolspline.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,53 +24,55 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef VTOOLSPLINE_H #define VTOOLSPLINE_H #include "vdrawtool.h" #include -#include "dialogs/dialogspline.h" -#include "widgets/vcontrolpointspline.h" -#include "geometry/vsplinepath.h" +#include "../../dialogs/dialogspline.h" +#include "../../widgets/vcontrolpointspline.h" +#include "../../geometry/vsplinepath.h" class VToolSpline:public VDrawTool, public QGraphicsPathItem { Q_OBJECT public: - VToolSpline (VDomDocument *doc, VContainer *data, qint64 id, - Tool::Sources typeCreation, QGraphicsItem * parent = 0 ); + VToolSpline (VDomDocument *doc, VContainer *data, qint64 id, const Tool::Sources &typeCreation, + QGraphicsItem * parent = 0 ); virtual void setDialog(); - static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data); - static void Create(const qint64 _id, const qint64 &p1, const qint64 &p4, const qreal &kAsm1, - const qreal kAsm2, const qreal &angle1, const qreal &angle2, const qreal &kCurve, - VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, const Document::Documents &parse, - Tool::Sources typeCreation); + static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, + VContainer *data); + static void Create(const qint64 _id, const qint64 &p1, const qint64 &p4, const qreal &kAsm1, + const qreal kAsm2, const qreal &angle1, const qreal &angle2, const qreal &kCurve, + VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, + const Document::Documents &parse, const Tool::Sources &typeCreation); + static const QString TagName; + static const QString ToolType; signals: - void RefreshLine ( const qint32 &indexSpline, SplinePoint::Position position, - const QPointF &controlPoint, const QPointF &splinePoint ); - void setEnabledPoint ( bool enable ); + void RefreshLine ( const qint32 &indexSpline, SplinePoint::Position position, const QPointF &controlPoint, + const QPointF &splinePoint ); + void setEnabledPoint ( bool enable ); public slots: - virtual void FullUpdateFromFile (); - virtual void FullUpdateFromGui ( int result ); - void ControlPointChangePosition ( const qint32 &indexSpline, - SplinePoint::Position position, - const QPointF pos); - virtual void ChangedActivDraw ( const QString newName ); - virtual void ShowTool(qint64 id, Qt::GlobalColor color, bool enable); + virtual void FullUpdateFromFile (); + virtual void FullUpdateFromGui ( int result ); + void ControlPointChangePosition (const qint32 &indexSpline, const SplinePoint::Position &position, + const QPointF &pos); + virtual void ChangedActivDraw ( const QString &newName ); + virtual void ShowTool(qint64 id, Qt::GlobalColor color, bool enable); + virtual void SetFactor(qreal factor); protected: - virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile (); - virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); - virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); - virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); - virtual void RemoveReferens(); + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void AddToFile (); + virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); + virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); + virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); + virtual void RemoveReferens(); private: QSharedPointer dialogSpline; QVector controlPoints; - void RefreshGeometry (); + void RefreshGeometry (); }; #endif // VTOOLSPLINE_H diff --git a/tools/drawTools/vtoolsplinepath.cpp b/tools/drawTools/vtoolsplinepath.cpp index b862f6815..bd656dc79 100644 --- a/tools/drawTools/vtoolsplinepath.cpp +++ b/tools/drawTools/vtoolsplinepath.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vtoolsplinepath.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,26 +24,30 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "vtoolsplinepath.h" -#include -VToolSplinePath::VToolSplinePath(VDomDocument *doc, VContainer *data, qint64 id, - Tool::Sources typeCreation, - QGraphicsItem *parent):VDrawTool(doc, data, id), - QGraphicsPathItem(parent), dialogSplinePath(QSharedPointer()), - controlPoints(QVector()){ +const QString VToolSplinePath::TagName = QStringLiteral("spline"); +const QString VToolSplinePath::ToolType = QStringLiteral("path"); + +VToolSplinePath::VToolSplinePath(VDomDocument *doc, VContainer *data, qint64 id, const Tool::Sources &typeCreation, + QGraphicsItem *parent) + :VDrawTool(doc, data, id), QGraphicsPathItem(parent), dialogSplinePath(QSharedPointer()), + controlPoints(QVector()) +{ + ignoreFullUpdate = true; VSplinePath splPath = data->GetSplinePath(id); QPainterPath path; path.addPath(splPath.GetPath()); path.setFillRule( Qt::WindingFill ); this->setPath(path); - this->setPen(QPen(Qt::black, widthHairLine)); + this->setPen(QPen(Qt::black, widthHairLine/factor)); this->setFlag(QGraphicsItem::ItemIsSelectable, true); this->setAcceptHoverEvents(true); - for(qint32 i = 1; i<=splPath.Count(); ++i){ + for (qint32 i = 1; i<=splPath.Count(); ++i) + { VSpline spl = splPath.GetSpline(i); VControlPointSpline *controlPoint = new VControlPointSpline(i, SplinePoint::FirstPoint, spl.GetP2(), spl.GetPointP1().toQPointF(), this); @@ -54,23 +65,25 @@ VToolSplinePath::VToolSplinePath(VDomDocument *doc, VContainer *data, qint64 id, connect(this, &VToolSplinePath::setEnabledPoint, controlPoint, &VControlPointSpline::setEnabledPoint); controlPoints.append(controlPoint); } - if(typeCreation == Tool::FromGui){ + if (typeCreation == Tool::FromGui) + { AddToFile(); } } -void VToolSplinePath::setDialog(){ - Q_ASSERT(!dialogSplinePath.isNull()); - if(!dialogSplinePath.isNull()){ - VSplinePath splPath = VAbstractTool::data.GetSplinePath(id); - dialogSplinePath->SetPath(splPath); - } +void VToolSplinePath::setDialog() +{ + Q_ASSERT(dialogSplinePath.isNull() == false); + VSplinePath splPath = VAbstractTool::data.GetSplinePath(id); + dialogSplinePath->SetPath(splPath); } void VToolSplinePath::Create(QSharedPointer &dialog, VMainGraphicsScene *scene, - VDomDocument *doc, VContainer *data){ + VDomDocument *doc, VContainer *data) +{ VSplinePath path = dialog->GetPath(); - for(qint32 i = 0; i < path.CountPoint(); ++i){ + for (qint32 i = 0; i < path.CountPoint(); ++i) + { doc->IncrementReferens(path[i].P()); } Create(0, path, scene, doc, data, Document::FullParse, Tool::FromGui); @@ -78,35 +91,47 @@ void VToolSplinePath::Create(QSharedPointer &dialog, VMainGrap void VToolSplinePath::Create(const qint64 _id, const VSplinePath &path, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, const Document::Documents &parse, - Tool::Sources typeCreation){ + const Tool::Sources &typeCreation) +{ qint64 id = _id; - if(typeCreation == Tool::FromGui){ + if (typeCreation == Tool::FromGui) + { id = data->AddSplinePath(path); - } else { + data->AddLengthSpline(path.name(), toMM(path.GetLength())); + } + else + { data->UpdateSplinePath(id, path); - if(parse != Document::FullParse){ + data->AddLengthSpline(path.name(), toMM(path.GetLength())); + if (parse != Document::FullParse) + { doc->UpdateToolData(id, data); } } - data->AddLengthSpline(data->GetNameSplinePath(path), path.GetLength()); VDrawTool::AddRecord(id, Tool::SplinePathTool, doc); - if(parse == Document::FullParse){ + if (parse == Document::FullParse) + { VToolSplinePath *spl = new VToolSplinePath(doc, data, id, typeCreation); scene->addItem(spl); connect(spl, &VToolSplinePath::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); connect(spl, &VToolSplinePath::RemoveTool, scene, &VMainGraphicsScene::RemoveTool); + connect(scene, &VMainGraphicsScene::NewFactor, spl, &VToolSplinePath::SetFactor); doc->AddTool(id, spl); } } -void VToolSplinePath::FullUpdateFromFile(){ +void VToolSplinePath::FullUpdateFromFile() +{ RefreshGeometry(); } -void VToolSplinePath::FullUpdateFromGui(int result){ - if(result == QDialog::Accepted){ +void VToolSplinePath::FullUpdateFromGui(int result) +{ + if (result == QDialog::Accepted) + { VSplinePath splPath = dialogSplinePath->GetPath(); - for(qint32 i = 1; i<=splPath.Count(); ++i){ + for (qint32 i = 1; i<=splPath.Count(); ++i) + { VSpline spl = splPath.GetSpline(i); qint32 j = i*2; disconnect(controlPoints[j-2], &VControlPointSpline::ControlPointChangePosition, this, @@ -126,8 +151,9 @@ void VToolSplinePath::FullUpdateFromGui(int result){ CorectControlPoints(spl, splPath, i); QDomElement domElement = doc->elementById(QString().setNum(id)); - if(domElement.isElement()){ - domElement.setAttribute("kCurve", QString().setNum(splPath.getKCurve())); + if (domElement.isElement()) + { + domElement.setAttribute(AttrKCurve, QString().setNum(splPath.getKCurve())); UpdatePathPoint(domElement, splPath); emit FullUpdateTree(); } @@ -137,27 +163,32 @@ void VToolSplinePath::FullUpdateFromGui(int result){ dialogSplinePath.clear(); } -void VToolSplinePath::ControlPointChangePosition(const qint32 &indexSpline, SplinePoint::Position position, - const QPointF pos){ +void VToolSplinePath::ControlPointChangePosition(const qint32 &indexSpline, const SplinePoint::Position &position, + const QPointF &pos) +{ VSplinePath splPath = VAbstractTool::data.GetSplinePath(id); VSpline spl = splPath.GetSpline(indexSpline); - if(position == SplinePoint::FirstPoint){ + if (position == SplinePoint::FirstPoint) + { spl.ModifiSpl (spl.GetP1(), pos, spl.GetP3(), spl.GetP4(), spl.GetKcurve()); - } else { + } + else + { spl.ModifiSpl (spl.GetP1(), spl.GetP2(), pos, spl.GetP4(), spl.GetKcurve()); } CorectControlPoints(spl, splPath, indexSpline); QDomElement domElement = doc->elementById(QString().setNum(id)); - if(domElement.isElement()){ - domElement.setAttribute("kCurve", QString().setNum(splPath.getKCurve())); + if (domElement.isElement()) + { + domElement.setAttribute(AttrKCurve, QString().setNum(splPath.getKCurve())); UpdatePathPoint(domElement, splPath); emit FullUpdateTree(); } } -void VToolSplinePath::CorectControlPoints(const VSpline &spl, VSplinePath &splPath, - const qint32 &indexSpline){ +void VToolSplinePath::CorectControlPoints(const VSpline &spl, VSplinePath &splPath, const qint32 &indexSpline) +{ VSplinePoint p = splPath.GetSplinePoint(indexSpline, SplinePoint::FirstPoint); p.SetAngle(spl.GetAngle1()); p.SetKAsm2(spl.GetKasm1()); @@ -169,110 +200,129 @@ void VToolSplinePath::CorectControlPoints(const VSpline &spl, VSplinePath &splPa splPath.UpdatePoint(indexSpline, SplinePoint::LastPoint, p); } -void VToolSplinePath::UpdatePathPoint(QDomNode& node, VSplinePath &path){ +void VToolSplinePath::UpdatePathPoint(QDomNode& node, VSplinePath &path) +{ QDomNodeList nodeList = node.childNodes(); qint32 num = nodeList.size(); - for(qint32 i = 0; i < num; ++i){ + for (qint32 i = 0; i < num; ++i) + { QDomElement domElement = nodeList.at(i).toElement(); - if(!domElement.isNull()){ + if (domElement.isNull() == false) + { VSplinePoint p = path[i]; - domElement.setAttribute("pSpline", QString().setNum(p.P())); - domElement.setAttribute("kAsm1", QString().setNum(p.KAsm1())); - domElement.setAttribute("kAsm2", QString().setNum(p.KAsm2())); - domElement.setAttribute("angle", QString().setNum(p.Angle2())); + domElement.setAttribute(AttrPSpline, QString().setNum(p.P())); + domElement.setAttribute(AttrKAsm1, QString().setNum(p.KAsm1())); + domElement.setAttribute(AttrKAsm2, QString().setNum(p.KAsm2())); + domElement.setAttribute(AttrAngle, QString().setNum(p.Angle2())); } } } -void VToolSplinePath::ChangedActivDraw(const QString newName){ - if(nameActivDraw == newName){ - this->setPen(QPen(Qt::black, widthHairLine)); - this->setFlag(QGraphicsItem::ItemIsSelectable, true); - this->setAcceptHoverEvents(true); - emit setEnabledPoint(true); - VDrawTool::ChangedActivDraw(newName); - } else { - this->setPen(QPen(Qt::gray, widthHairLine)); - this->setFlag(QGraphicsItem::ItemIsSelectable, false); - this->setAcceptHoverEvents (false); - emit setEnabledPoint(false); - VDrawTool::ChangedActivDraw(newName); +void VToolSplinePath::ChangedActivDraw(const QString &newName) +{ + bool selectable = false; + if (nameActivDraw == newName) + { + selectable = true; + currentColor = Qt::black; } + else + { + selectable = false; + currentColor = Qt::gray; + } + 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)); - currentColor = baseColor; - } else { - this->setPen(QPen(color, widthHairLine)); - currentColor = color; - } - } +void VToolSplinePath::ShowTool(qint64 id, Qt::GlobalColor color, bool enable) +{ + ShowItem(this, id, color, enable); } -void VToolSplinePath::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ +void VToolSplinePath::SetFactor(qreal factor) +{ + VDrawTool::SetFactor(factor); + RefreshGeometry(); +} + +void VToolSplinePath::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) +{ ContextMenu(dialogSplinePath, this, event); } -void VToolSplinePath::AddToFile(){ +void VToolSplinePath::AddToFile() +{ VSplinePath splPath = VAbstractTool::data.GetSplinePath(id); - QDomElement domElement = doc->createElement("spline"); + QDomElement domElement = doc->createElement(TagName); - AddAttribute(domElement, "id", id); - AddAttribute(domElement, "type", "path"); - AddAttribute(domElement, "kCurve", splPath.getKCurve()); + AddAttribute(domElement, AttrId, id); + AddAttribute(domElement, AttrType, ToolType); + AddAttribute(domElement, AttrKCurve, splPath.getKCurve()); - for(qint32 i = 0; i < splPath.CountPoint(); ++i){ + for (qint32 i = 0; i < splPath.CountPoint(); ++i) + { AddPathPoint(domElement, splPath[i]); } AddToCalculation(domElement); } -void VToolSplinePath::AddPathPoint(QDomElement &domElement, const VSplinePoint &splPoint){ - QDomElement pathPoint = doc->createElement("pathPoint"); +void VToolSplinePath::AddPathPoint(QDomElement &domElement, const VSplinePoint &splPoint) +{ + QDomElement pathPoint = doc->createElement(AttrPathPoint); - AddAttribute(pathPoint, "pSpline", splPoint.P()); - AddAttribute(pathPoint, "kAsm1", splPoint.KAsm1()); - AddAttribute(pathPoint, "kAsm2", splPoint.KAsm2()); - AddAttribute(pathPoint, "angle", splPoint.Angle2()); + AddAttribute(pathPoint, AttrPSpline, splPoint.P()); + AddAttribute(pathPoint, AttrKAsm1, splPoint.KAsm1()); + AddAttribute(pathPoint, AttrKAsm2, splPoint.KAsm2()); + AddAttribute(pathPoint, AttrAngle, splPoint.Angle2()); domElement.appendChild(pathPoint); } -void VToolSplinePath::mouseReleaseEvent(QGraphicsSceneMouseEvent *event){ - if(event->button() == Qt::LeftButton){ +void VToolSplinePath::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +{ + if (event->button() == Qt::LeftButton) + { emit ChoosedTool(id, Scene::SplinePath); } QGraphicsItem::mouseReleaseEvent(event); } -void VToolSplinePath::hoverMoveEvent(QGraphicsSceneHoverEvent *event){ +void VToolSplinePath::hoverMoveEvent(QGraphicsSceneHoverEvent *event) +{ Q_UNUSED(event); - this->setPen(QPen(currentColor, widthMainLine)); + this->setPen(QPen(currentColor, widthMainLine/factor)); } -void VToolSplinePath::hoverLeaveEvent(QGraphicsSceneHoverEvent *event){ +void VToolSplinePath::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) +{ Q_UNUSED(event); - this->setPen(QPen(currentColor, widthHairLine)); + this->setPen(QPen(currentColor, widthHairLine/factor)); } -void VToolSplinePath::RemoveReferens(){ +void VToolSplinePath::RemoveReferens() +{ VSplinePath splPath = VAbstractTool::data.GetSplinePath(id); - for(qint32 i = 0; i < splPath.Count(); ++i){ + for (qint32 i = 0; i < splPath.Count(); ++i) + { doc->DecrementReferens(splPath[i].P()); } } -void VToolSplinePath::RefreshGeometry(){ +void VToolSplinePath::RefreshGeometry() +{ + this->setPen(QPen(currentColor, widthHairLine/factor)); VSplinePath splPath = VAbstractTool::data.GetSplinePath(id); QPainterPath path; path.addPath(splPath.GetPath()); path.setFillRule( Qt::WindingFill ); this->setPath(path); - for(qint32 i = 1; i<=splPath.Count(); ++i){ + for (qint32 i = 1; i<=splPath.Count(); ++i) + { VSpline spl = splPath.GetSpline(i); QPointF splinePoint = spl.GetPointP1().toQPointF(); QPointF controlPoint = spl.GetP2(); @@ -293,5 +343,4 @@ void VToolSplinePath::RefreshGeometry(){ connect(controlPoints[j-1], &VControlPointSpline::ControlPointChangePosition, this, &VToolSplinePath::ControlPointChangePosition); } - } diff --git a/tools/drawTools/vtoolsplinepath.h b/tools/drawTools/vtoolsplinepath.h index b880bdfd2..a58ddc2ee 100644 --- a/tools/drawTools/vtoolsplinepath.h +++ b/tools/drawTools/vtoolsplinepath.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vtoolsplinepath.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,55 +24,56 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef VTOOLSPLINEPATH_H #define VTOOLSPLINEPATH_H #include "vdrawtool.h" #include -#include "dialogs/dialogsplinepath.h" -#include "widgets/vcontrolpointspline.h" +#include "../../dialogs/dialogsplinepath.h" +#include "../../widgets/vcontrolpointspline.h" -class VToolSplinePath:public VDrawTool, public QGraphicsPathItem{ +class VToolSplinePath:public VDrawTool, public QGraphicsPathItem +{ Q_OBJECT public: - VToolSplinePath(VDomDocument *doc, VContainer *data, qint64 id, - Tool::Sources typeCreation, - QGraphicsItem * parent = 0); - virtual void setDialog(); - static void Create(QSharedPointer &dialog, - VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data); - static void Create(const qint64 _id, const VSplinePath &path, - VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, - const Document::Documents &parse, Tool::Sources typeCreation); + VToolSplinePath(VDomDocument *doc, VContainer *data, qint64 id, const Tool::Sources &typeCreation, + QGraphicsItem * parent = 0); + virtual void setDialog(); + static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, + VDomDocument *doc, VContainer *data); + static void Create(const qint64 _id, const VSplinePath &path, VMainGraphicsScene *scene, + VDomDocument *doc, VContainer *data, const Document::Documents &parse, + const Tool::Sources &typeCreation); + static const QString TagName; + static const QString ToolType; signals: - void RefreshLine(const qint32 &indexSpline, SplinePoint::Position pos, - const QPointF &controlPoint, const QPointF &splinePoint); - void setEnabledPoint(bool enable); + void RefreshLine(const qint32 &indexSpline, SplinePoint::Position pos, + const QPointF &controlPoint, const QPointF &splinePoint); + void setEnabledPoint(bool enable); public slots: - virtual void FullUpdateFromFile(); - virtual void FullUpdateFromGui(int result); - void ControlPointChangePosition(const qint32 &indexSpline, - SplinePoint::Position position, - const QPointF pos); - virtual void ChangedActivDraw(const QString newName); - virtual void ShowTool(qint64 id, Qt::GlobalColor color, bool enable); + virtual void FullUpdateFromFile(); + virtual void FullUpdateFromGui(int result); + void ControlPointChangePosition(const qint32 &indexSpline, const SplinePoint::Position &position, + const QPointF &pos); + virtual void ChangedActivDraw(const QString &newName); + virtual void ShowTool(qint64 id, Qt::GlobalColor color, bool enable); + virtual void SetFactor(qreal factor); protected: - virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile(); - virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); - virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); - virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); - virtual void RemoveReferens(); + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void AddToFile(); + virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); + virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); + virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); + virtual void RemoveReferens(); private: QSharedPointer dialogSplinePath; QVector controlPoints; - void RefreshGeometry(); - void AddPathPoint(QDomElement &domElement, const VSplinePoint &splPoint); - void UpdatePathPoint(QDomNode& node, VSplinePath &path); - void CorectControlPoints(const VSpline &spl, VSplinePath &splPath, - const qint32 &indexSpline); + void RefreshGeometry(); + void AddPathPoint(QDomElement &domElement, const VSplinePoint &splPoint); + void UpdatePathPoint(QDomNode& node, VSplinePath &path); + void CorectControlPoints(const VSpline &spl, VSplinePath &splPath, const qint32 &indexSpline); }; #endif // VTOOLSPLINEPATH_H diff --git a/tools/drawTools/vtooltriangle.cpp b/tools/drawTools/vtooltriangle.cpp new file mode 100644 index 000000000..7f0c65081 --- /dev/null +++ b/tools/drawTools/vtooltriangle.cpp @@ -0,0 +1,213 @@ +/************************************************************************ + ** + ** @file vtooltriangle.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "vtooltriangle.h" + +const QString VToolTriangle::ToolType = QStringLiteral("triangle"); + +VToolTriangle::VToolTriangle(VDomDocument *doc, VContainer *data, const qint64 &id, + const qint64 &axisP1Id, const qint64 &axisP2Id, const qint64 &firstPointId, + const qint64 &secondPointId, const Tool::Sources &typeCreation, QGraphicsItem *parent) + :VToolPoint(doc, data, id, parent), axisP1Id(axisP1Id), axisP2Id(axisP2Id), firstPointId(firstPointId), + secondPointId(secondPointId), dialogTriangle(QSharedPointer()) +{ + ignoreFullUpdate = true; + if (typeCreation == Tool::FromGui) + { + AddToFile(); + } +} + +void VToolTriangle::setDialog() +{ + Q_ASSERT(dialogTriangle.isNull() == false); + VPointF p = VAbstractTool::data.GetPoint(id); + dialogTriangle->setAxisP1Id(axisP1Id, id); + dialogTriangle->setAxisP2Id(axisP2Id, id); + dialogTriangle->setFirstPointId(firstPointId, id); + dialogTriangle->setSecondPointId(secondPointId, id); + dialogTriangle->setPointName(p.name()); +} + +void VToolTriangle::Create(QSharedPointer &dialog, VMainGraphicsScene *scene, + VDomDocument *doc, VContainer *data) +{ + qint64 axisP1Id = dialog->getAxisP1Id(); + qint64 axisP2Id = dialog->getAxisP2Id(); + qint64 firstPointId = dialog->getFirstPointId(); + qint64 secondPointId = dialog->getSecondPointId(); + QString pointName = dialog->getPointName(); + Create(0, pointName, axisP1Id, axisP2Id, firstPointId, secondPointId, 5, 10, scene, doc, data, + Document::FullParse, Tool::FromGui); +} + +void VToolTriangle::Create(const qint64 _id, const QString &pointName, const qint64 &axisP1Id, + const qint64 &axisP2Id, const qint64 &firstPointId, const qint64 &secondPointId, + const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VDomDocument *doc, + VContainer *data, const Document::Documents &parse, const Tool::Sources &typeCreation) +{ + VPointF axisP1 = data->GetPoint(axisP1Id); + VPointF axisP2 = data->GetPoint(axisP2Id); + VPointF firstPoint = data->GetPoint(firstPointId); + VPointF secondPoint = data->GetPoint(secondPointId); + + QPointF point = FindPoint(axisP1.toQPointF(), axisP2.toQPointF(), firstPoint.toQPointF(), + secondPoint.toQPointF()); + qint64 id = _id; + if (typeCreation == Tool::FromGui) + { + id = data->AddPoint(VPointF(point.x(), point.y(), pointName, mx, my)); + } + else + { + data->UpdatePoint(id, VPointF(point.x(), point.y(), pointName, mx, my)); + if (parse != Document::FullParse) + { + doc->UpdateToolData(id, data); + } + } + VDrawTool::AddRecord(id, Tool::Triangle, doc); + if (parse == Document::FullParse) + { + VToolTriangle *point = new VToolTriangle(doc, data, id, axisP1Id, axisP2Id, firstPointId, + secondPointId, typeCreation); + scene->addItem(point); + connect(point, &VToolTriangle::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); + connect(point, &VToolTriangle::RemoveTool, scene, &VMainGraphicsScene::RemoveTool); + connect(scene, &VMainGraphicsScene::NewFactor, point, &VToolTriangle::SetFactor); + doc->AddTool(id, point); + doc->IncrementReferens(axisP1Id); + doc->IncrementReferens(axisP2Id); + doc->IncrementReferens(firstPointId); + doc->IncrementReferens(secondPointId); + } +} + +QPointF VToolTriangle::FindPoint(const QPointF &axisP1, const QPointF &axisP2, const QPointF &firstPoint, + const QPointF &secondPoint) +{ + qreal c = QLineF(firstPoint, secondPoint).length(); + qreal a = QLineF(axisP2, firstPoint).length(); + qreal b = QLineF(axisP2, secondPoint).length(); + if (fabs(c*c - (a*a + b*b)) < 0.0001) + { + QLineF l1(axisP2, firstPoint); + QLineF l2(axisP2, secondPoint); + if (fabs(l1.angleTo(l2) - 90) < 0.1 || fabs(l2.angleTo(l1) - 90) < 0.1) + { + return axisP2; + } + } + + QLineF line = QLineF(axisP1, axisP2); + qreal step = 0.01; + while (1) + { + line.setLength(line.length()+step); + a = QLineF(line.p2(), firstPoint).length(); + b = QLineF(line.p2(), secondPoint).length(); + if (static_cast(c*c) == static_cast(a*a + b*b)) + { + QLineF l1(axisP2, firstPoint); + QLineF l2(axisP2, secondPoint); + if (fabs(l1.angleTo(l2) - 90) < 0.1 || fabs(l2.angleTo(l1) - 90) < 0.1) + { + return line.p2(); + } + } + if (c*c < a*a + b*b) + { + qWarning()<elementById(QString().setNum(id)); + if (domElement.isElement()) + { + axisP1Id = domElement.attribute(AttrAxisP1, "").toLongLong(); + axisP2Id = domElement.attribute(AttrAxisP2, "").toLongLong(); + firstPointId = domElement.attribute(AttrFirstPoint, "").toLongLong(); + secondPointId = domElement.attribute(AttrSecondPoint, "").toLongLong(); + } + VToolPoint::RefreshPointGeometry(VDrawTool::data.GetPoint(id)); +} + +void VToolTriangle::FullUpdateFromGui(int result) +{ + if (result == QDialog::Accepted) + { + QDomElement domElement = doc->elementById(QString().setNum(id)); + if (domElement.isElement()) + { + domElement.setAttribute(AttrName, dialogTriangle->getPointName()); + domElement.setAttribute(AttrAxisP1, QString().setNum(dialogTriangle->getAxisP1Id())); + domElement.setAttribute(AttrAxisP2, QString().setNum(dialogTriangle->getAxisP2Id())); + domElement.setAttribute(AttrFirstPoint, QString().setNum(dialogTriangle->getFirstPointId())); + domElement.setAttribute(AttrSecondPoint, QString().setNum(dialogTriangle->getSecondPointId())); + emit FullUpdateTree(); + } + + } + dialogTriangle.clear(); +} + +void VToolTriangle::RemoveReferens() +{ + doc->DecrementReferens(axisP1Id); + doc->DecrementReferens(axisP2Id); + doc->DecrementReferens(firstPointId); + doc->DecrementReferens(secondPointId); +} + +void VToolTriangle::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) +{ + ContextMenu(dialogTriangle, this, event); +} + +void VToolTriangle::AddToFile() +{ + VPointF point = VAbstractTool::data.GetPoint(id); + QDomElement domElement = doc->createElement(TagName); + + AddAttribute(domElement, AttrId, id); + AddAttribute(domElement, AttrType, ToolType); + AddAttribute(domElement, AttrName, point.name()); + AddAttribute(domElement, AttrMx, toMM(point.mx())); + AddAttribute(domElement, AttrMy, toMM(point.my())); + + AddAttribute(domElement, AttrAxisP1, axisP1Id); + AddAttribute(domElement, AttrAxisP2, axisP2Id); + AddAttribute(domElement, AttrFirstPoint, firstPointId); + AddAttribute(domElement, AttrSecondPoint, secondPointId); + + AddToCalculation(domElement); +} diff --git a/tools/drawTools/vtooltriangle.h b/tools/drawTools/vtooltriangle.h new file mode 100644 index 000000000..dc848c76b --- /dev/null +++ b/tools/drawTools/vtooltriangle.h @@ -0,0 +1,68 @@ +/************************************************************************ + ** + ** @file vtooltriangle.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef VTOOLTRIANGLE_H +#define VTOOLTRIANGLE_H + +#include "vtoolpoint.h" +#include "../../dialogs/dialogtriangle.h" + +class VToolTriangle : public VToolPoint +{ + Q_OBJECT +public: + VToolTriangle(VDomDocument *doc, VContainer *data, const qint64 &id, const qint64 &axisP1Id, + const qint64 &axisP2Id, const qint64 &firstPointId, const qint64 &secondPointId, + const Tool::Sources &typeCreation, QGraphicsItem * parent = 0); + virtual void setDialog(); + static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, + VContainer *data); + static void Create(const qint64 _id, const QString &pointName, const qint64 &axisP1Id, const qint64 &axisP2Id, + const qint64 &firstPointId, const qint64 &secondPointId, const qreal &mx, const qreal &my, + VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, + const Document::Documents &parse, const Tool::Sources &typeCreation); + static QPointF FindPoint(const QPointF &axisP1, const QPointF &axisP2, const QPointF &firstPoint, + const QPointF &secondPoint); + static const QString ToolType; +public slots: + virtual void FullUpdateFromFile(); + virtual void FullUpdateFromGui(int result); +protected: + virtual void RemoveReferens(); + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void AddToFile(); +private: + Q_DISABLE_COPY(VToolTriangle) + qint64 axisP1Id; + qint64 axisP2Id; + qint64 firstPointId; + qint64 secondPointId; + QSharedPointer dialogTriangle; +}; + +#endif // VTOOLTRIANGLE_H diff --git a/tools/modelingTools/modelingtools.h b/tools/modelingTools/modelingtools.h index 2a051f87a..3203357b1 100644 --- a/tools/modelingTools/modelingtools.h +++ b/tools/modelingTools/modelingtools.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file modelingtools.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,7 +24,7 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef MODELINGTOOLS_H #define MODELINGTOOLS_H @@ -31,8 +38,10 @@ #include "vmodelingnormal.h" #include "vmodelingpointofcontact.h" #include "vmodelingshoulderpoint.h" -#include "vmodelingsinglepoint.h" #include "vmodelingspline.h" #include "vmodelingsplinepath.h" +#include "vmodelingheight.h" +#include "vmodelingtriangle.h" +#include "vmodelingpointofintersection.h" #endif // MODELINGTOOLS_H diff --git a/tools/modelingTools/vmodelingalongline.cpp b/tools/modelingTools/vmodelingalongline.cpp index 76d448dad..fce43cb07 100644 --- a/tools/modelingTools/vmodelingalongline.cpp +++ b/tools/modelingTools/vmodelingalongline.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vmodelingalongline.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,45 +24,51 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "vmodelingalongline.h" -#include -#include -#include "container/calculator.h" +#include "../../container/calculator.h" + +const QString VModelingAlongLine::ToolType = QStringLiteral("alongLine"); VModelingAlongLine::VModelingAlongLine(VDomDocument *doc, VContainer *data, qint64 id, const QString &formula, const qint64 &firstPointId, const qint64 &secondPointId, const QString &typeLine, - Tool::Sources typeCreation, QGraphicsItem *parent): - VModelingLinePoint(doc, data, id, typeLine, formula, firstPointId, 0, parent), - secondPointId(secondPointId), dialogAlongLine(QSharedPointer()){ - - if(typeCreation == Tool::FromGui){ + const Tool::Sources &typeCreation, QGraphicsItem *parent) + :VModelingLinePoint(doc, data, id, typeLine, formula, firstPointId, 0, parent), secondPointId(secondPointId), + dialogAlongLine(QSharedPointer()) +{ + if (typeCreation == Tool::FromGui) + { AddToFile(); } } -void VModelingAlongLine::FullUpdateFromFile(){ +void VModelingAlongLine::FullUpdateFromFile() +{ QDomElement domElement = doc->elementById(QString().setNum(id)); - if(domElement.isElement()){ - typeLine = domElement.attribute("typeLine", ""); - formula = domElement.attribute("length", ""); - basePointId = domElement.attribute("firstPoint", "").toLongLong(); - secondPointId = domElement.attribute("secondPoint", "").toLongLong(); + if (domElement.isElement()) + { + typeLine = domElement.attribute(AttrTypeLine, ""); + formula = domElement.attribute(AttrLength, ""); + basePointId = domElement.attribute(AttrFirstPoint, "").toLongLong(); + secondPointId = domElement.attribute(AttrSecondPoint, "").toLongLong(); } RefreshGeometry(); } -void VModelingAlongLine::FullUpdateFromGui(int result){ - if(result == QDialog::Accepted){ +void VModelingAlongLine::FullUpdateFromGui(int result) +{ + if (result == QDialog::Accepted) + { QDomElement domElement = doc->elementById(QString().setNum(id)); - if(domElement.isElement()){ - domElement.setAttribute("name", dialogAlongLine->getPointName()); - domElement.setAttribute("typeLine", dialogAlongLine->getTypeLine()); - domElement.setAttribute("length", dialogAlongLine->getFormula()); - domElement.setAttribute("firstPoint", QString().setNum(dialogAlongLine->getFirstPointId())); - domElement.setAttribute("secondPoint", QString().setNum(dialogAlongLine->getSecondPointId())); + if (domElement.isElement()) + { + domElement.setAttribute(AttrName, dialogAlongLine->getPointName()); + domElement.setAttribute(AttrTypeLine, dialogAlongLine->getTypeLine()); + domElement.setAttribute(AttrLength, dialogAlongLine->getFormula()); + domElement.setAttribute(AttrFirstPoint, QString().setNum(dialogAlongLine->getFirstPointId())); + domElement.setAttribute(AttrSecondPoint, QString().setNum(dialogAlongLine->getSecondPointId())); emit FullUpdateTree(); } @@ -63,47 +76,50 @@ void VModelingAlongLine::FullUpdateFromGui(int result){ dialogAlongLine.clear(); } -void VModelingAlongLine::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ +void VModelingAlongLine::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) +{ ContextMenu(dialogAlongLine, this, event); } -void VModelingAlongLine::AddToFile(){ +void VModelingAlongLine::AddToFile() +{ VPointF point = VAbstractTool::data.GetModelingPoint(id); - QDomElement domElement = doc->createElement("point"); + QDomElement domElement = doc->createElement(TagName); - 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, AttrId, id); + AddAttribute(domElement, AttrType, ToolType); + AddAttribute(domElement, AttrName, point.name()); + AddAttribute(domElement, AttrMx, toMM(point.mx())); + AddAttribute(domElement, AttrMy, toMM(point.my())); - AddAttribute(domElement, "typeLine", typeLine); - AddAttribute(domElement, "length", formula); - AddAttribute(domElement, "firstPoint", basePointId); - AddAttribute(domElement, "secondPoint", secondPointId); + AddAttribute(domElement, AttrTypeLine, typeLine); + AddAttribute(domElement, AttrLength, formula); + AddAttribute(domElement, AttrFirstPoint, basePointId); + AddAttribute(domElement, AttrSecondPoint, secondPointId); AddToModeling(domElement); } -void VModelingAlongLine::RemoveReferens(){ +void VModelingAlongLine::RemoveReferens() +{ doc->DecrementReferens(secondPointId); VModelingLinePoint::RemoveReferens(); } -void VModelingAlongLine::setDialog(){ - Q_ASSERT(!dialogAlongLine.isNull()); - if(!dialogAlongLine.isNull()){ - VPointF p = VAbstractTool::data.GetModelingPoint(id); - dialogAlongLine->setTypeLine(typeLine); - dialogAlongLine->setFormula(formula); - dialogAlongLine->setFirstPointId(basePointId, id); - dialogAlongLine->setSecondPointId(secondPointId, id); - dialogAlongLine->setPointName(p.name()); - } +void VModelingAlongLine::setDialog() +{ + Q_ASSERT(dialogAlongLine.isNull() == false); + VPointF p = VAbstractTool::data.GetModelingPoint(id); + dialogAlongLine->setTypeLine(typeLine); + dialogAlongLine->setFormula(formula); + dialogAlongLine->setFirstPointId(basePointId, id); + dialogAlongLine->setSecondPointId(secondPointId, id); + dialogAlongLine->setPointName(p.name()); } -VModelingAlongLine *VModelingAlongLine::Create(QSharedPointer &dialog, - VDomDocument *doc, VContainer *data){ +VModelingAlongLine *VModelingAlongLine::Create(QSharedPointer &dialog, VDomDocument *doc, + VContainer *data) +{ QString formula = dialog->getFormula(); qint64 firstPointId = dialog->getFirstPointId(); qint64 secondPointId = dialog->getSecondPointId(); @@ -113,12 +129,12 @@ VModelingAlongLine *VModelingAlongLine::Create(QSharedPointer & Document::FullParse, Tool::FromGui); } -VModelingAlongLine *VModelingAlongLine::Create(const qint64 _id, const QString &pointName, - const QString &typeLine, const QString &formula, - const qint64 &firstPointId, const qint64 &secondPointId, - const qreal &mx, const qreal &my, VDomDocument *doc, - VContainer *data, const Document::Documents &parse, - Tool::Sources typeCreation){ +VModelingAlongLine *VModelingAlongLine::Create(const qint64 _id, const QString &pointName, const QString &typeLine, + const QString &formula, const qint64 &firstPointId, + const qint64 &secondPointId, const qreal &mx, const qreal &my, + VDomDocument *doc, VContainer *data, const Document::Documents &parse, + const Tool::Sources &typeCreation) +{ VModelingAlongLine *point = 0; VPointF firstPoint = data->GetModelingPoint(firstPointId); VPointF secondPoint = data->GetModelingPoint(secondPointId); @@ -126,21 +142,27 @@ VModelingAlongLine *VModelingAlongLine::Create(const qint64 _id, const QString & Calculator cal(data); QString errorMsg; qreal result = cal.eval(formula, &errorMsg); - if(errorMsg.isEmpty()){ + if (errorMsg.isEmpty()) + { line.setLength(toPixel(result)); qint64 id = _id; - if(typeCreation == Tool::FromGui){ + if (typeCreation == Tool::FromGui) + { id = data->AddModelingPoint(VPointF(line.p2().x(), line.p2().y(), pointName, mx, my)); - } else { + } + else + { data->UpdateModelingPoint(id, VPointF(line.p2().x(), line.p2().y(), pointName, mx, my)); - if(parse != Document::FullParse){ + if (parse != Document::FullParse) + { doc->UpdateToolData(id, data); } } data->AddLine(firstPointId, id); data->AddLine(id, secondPointId); - if(parse == Document::FullParse){ + if (parse == Document::FullParse) + { point = new VModelingAlongLine(doc, data, id, formula, firstPointId, secondPointId, typeLine, typeCreation); doc->AddTool(id, point); diff --git a/tools/modelingTools/vmodelingalongline.h b/tools/modelingTools/vmodelingalongline.h index c5d88407d..7bdba7e28 100644 --- a/tools/modelingTools/vmodelingalongline.h +++ b/tools/modelingTools/vmodelingalongline.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vmodelingalongline.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,38 +24,38 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef VMODELINGALONGLINE_H #define VMODELINGALONGLINE_H #include "vmodelinglinepoint.h" -#include "dialogs/dialogalongline.h" +#include "../../dialogs/dialogalongline.h" -class VModelingAlongLine : public VModelingLinePoint{ +class VModelingAlongLine : public VModelingLinePoint +{ Q_OBJECT public: - VModelingAlongLine(VDomDocument *doc, VContainer *data, qint64 id, - const QString &formula, const qint64 &firstPointId, - const qint64 &secondPointId, const QString &typeLine, - Tool::Sources typeCreation, QGraphicsItem * parent = 0); - virtual void setDialog(); - static VModelingAlongLine* Create(QSharedPointer &dialog, VDomDocument *doc, - VContainer *data); - static VModelingAlongLine* Create(const qint64 _id, const QString &pointName, const QString &typeLine, - const QString &formula, const qint64 &firstPointId, - const qint64 &secondPointId, const qreal &mx, const qreal &my, - VDomDocument *doc, VContainer *data, - const Document::Documents &parse, Tool::Sources typeCreation); + VModelingAlongLine(VDomDocument *doc, VContainer *data, qint64 id, + const QString &formula, const qint64 &firstPointId, + const qint64 &secondPointId, const QString &typeLine, + const Tool::Sources &typeCreation, QGraphicsItem * parent = 0); + virtual void setDialog(); + static VModelingAlongLine* Create(QSharedPointer &dialog, VDomDocument *doc, VContainer *data); + static VModelingAlongLine* Create(const qint64 _id, const QString &pointName, const QString &typeLine, + const QString &formula, const qint64 &firstPointId, const qint64 &secondPointId, + const qreal &mx, const qreal &my, VDomDocument *doc, VContainer *data, + const Document::Documents &parse, const Tool::Sources &typeCreation); + static const QString ToolType; public slots: - virtual void FullUpdateFromFile(); - virtual void FullUpdateFromGui(int result); + virtual void FullUpdateFromFile(); + virtual void FullUpdateFromGui(int result); protected: - virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile(); - virtual void RemoveReferens(); + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void AddToFile(); + virtual void RemoveReferens(); private: - qint64 secondPointId; + qint64 secondPointId; QSharedPointer dialogAlongLine; }; diff --git a/tools/modelingTools/vmodelingarc.cpp b/tools/modelingTools/vmodelingarc.cpp index a04ed9310..49ece909d 100644 --- a/tools/modelingTools/vmodelingarc.cpp +++ b/tools/modelingTools/vmodelingarc.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vmodelingarc.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,41 +24,41 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "vmodelingarc.h" -#include -#include "container/calculator.h" +#include "../../container/calculator.h" -VModelingArc::VModelingArc(VDomDocument *doc, VContainer *data, qint64 id, Tool::Sources typeCreation, - QGraphicsItem *parent):VModelingTool(doc, data, id), QGraphicsPathItem(parent), - dialogArc(QSharedPointer()){ - VArc arc = data->GetModelingArc(id); - QPainterPath path; - path.addPath(arc.GetPath()); - path.setFillRule( Qt::WindingFill ); - this->setPath(path); - this->setPen(QPen(Qt::black, widthHairLine)); +const QString VModelingArc::TagName = QStringLiteral("arc"); +const QString VModelingArc::ToolType = QStringLiteral("simple"); + +VModelingArc::VModelingArc(VDomDocument *doc, VContainer *data, qint64 id, const Tool::Sources &typeCreation, + QGraphicsItem *parent) + :VModelingTool(doc, data, id), QGraphicsPathItem(parent), dialogArc(QSharedPointer()) +{ + this->setPen(QPen(baseColor, widthHairLine)); this->setFlag(QGraphicsItem::ItemIsSelectable, true); this->setAcceptHoverEvents(true); + RefreshGeometry(); - if(typeCreation == Tool::FromGui){ + if (typeCreation == Tool::FromGui) + { AddToFile(); } } -void VModelingArc::setDialog(){ - Q_ASSERT(!dialogArc.isNull()); - if(!dialogArc.isNull()){ - VArc arc = VAbstractTool::data.GetModelingArc(id); - dialogArc->SetCenter(arc.GetCenter()); - dialogArc->SetRadius(arc.GetFormulaRadius()); - dialogArc->SetF1(arc.GetFormulaF1()); - dialogArc->SetF2(arc.GetFormulaF2()); - } +void VModelingArc::setDialog() +{ + Q_ASSERT(dialogArc.isNull() == false); + VArc arc = VAbstractTool::data.GetModelingArc(id); + dialogArc->SetCenter(arc.GetCenter()); + dialogArc->SetRadius(arc.GetFormulaRadius()); + dialogArc->SetF1(arc.GetFormulaF1()); + dialogArc->SetF2(arc.GetFormulaF2()); } -VModelingArc* VModelingArc::Create(QSharedPointer &dialog, VDomDocument *doc, VContainer *data){ +VModelingArc* VModelingArc::Create(QSharedPointer &dialog, VDomDocument *doc, VContainer *data) +{ qint64 center = dialog->GetCenter(); QString radius = dialog->GetRadius(); QString f1 = dialog->GetF1(); @@ -59,43 +66,52 @@ VModelingArc* VModelingArc::Create(QSharedPointer &dialog, VDomDocume return Create(0, center, radius, f1, f2, doc, data, Document::FullParse, Tool::FromGui); } -VModelingArc* VModelingArc::Create(const qint64 _id, const qint64 ¢er, const QString &radius, - const QString &f1, const QString &f2, VDomDocument *doc, - VContainer *data, const Document::Documents &parse, Tool::Sources typeCreation){ +VModelingArc* VModelingArc::Create(const qint64 _id, const qint64 ¢er, const QString &radius, const QString &f1, + const QString &f2, VDomDocument *doc, VContainer *data, + const Document::Documents &parse, const Tool::Sources &typeCreation) +{ VModelingArc *toolArc = 0; qreal calcRadius = 0, calcF1 = 0, calcF2 = 0; Calculator cal(data); QString errorMsg; qreal result = cal.eval(radius, &errorMsg); - if(errorMsg.isEmpty()){ - calcRadius = result*PrintDPI/25.4; + if (errorMsg.isEmpty()) + { + calcRadius = toPixel(result); } errorMsg.clear(); result = cal.eval(f1, &errorMsg); - if(errorMsg.isEmpty()){ + if (errorMsg.isEmpty()) + { calcF1 = result; } errorMsg.clear(); result = cal.eval(f2, &errorMsg); - if(errorMsg.isEmpty()){ + if (errorMsg.isEmpty()) + { calcF2 = result; } VArc arc = VArc(data->DataModelingPoints(), center, calcRadius, radius, calcF1, f1, calcF2, f2 ); qint64 id = _id; - if(typeCreation == Tool::FromGui){ + if (typeCreation == Tool::FromGui) + { id = data->AddModelingArc(arc); - } else { + } + else + { data->UpdateModelingArc(id, arc); - if(parse != Document::FullParse){ + if (parse != Document::FullParse) + { doc->UpdateToolData(id, data); } } - data->AddLengthArc(data->GetNameArc(center,id, Draw::Modeling), arc.GetLength()); - if(parse == Document::FullParse){ + data->AddLengthArc(arc.name(), toMM(arc.GetLength())); + if (parse == Document::FullParse) + { toolArc = new VModelingArc(doc, data, id, typeCreation); doc->AddTool(id, toolArc); doc->IncrementReferens(center); @@ -103,65 +119,77 @@ VModelingArc* VModelingArc::Create(const qint64 _id, const qint64 ¢er, const return toolArc; } -void VModelingArc::FullUpdateFromFile(){ +void VModelingArc::FullUpdateFromFile() +{ RefreshGeometry(); } -void VModelingArc::FullUpdateFromGui(int result){ - if(result == QDialog::Accepted){ +void VModelingArc::FullUpdateFromGui(int result) +{ + if (result == QDialog::Accepted) + { QDomElement domElement = doc->elementById(QString().setNum(id)); - if(domElement.isElement()){ - domElement.setAttribute("center", QString().setNum(dialogArc->GetCenter())); - domElement.setAttribute("radius", dialogArc->GetRadius()); - domElement.setAttribute("angle1", dialogArc->GetF1()); - domElement.setAttribute("angle2", dialogArc->GetF2()); + if (domElement.isElement()) + { + domElement.setAttribute(AttrCenter, QString().setNum(dialogArc->GetCenter())); + domElement.setAttribute(AttrRadius, dialogArc->GetRadius()); + domElement.setAttribute(AttrAngle1, dialogArc->GetF1()); + domElement.setAttribute(AttrAngle2, dialogArc->GetF2()); emit FullUpdateTree(); } } dialogArc.clear(); } -void VModelingArc::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ +void VModelingArc::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) +{ ContextMenu(dialogArc, this, event); } -void VModelingArc::AddToFile(){ +void VModelingArc::AddToFile() +{ VArc arc = VAbstractTool::data.GetModelingArc(id); - QDomElement domElement = doc->createElement("arc"); + QDomElement domElement = doc->createElement(TagName); - AddAttribute(domElement, "id", id); - AddAttribute(domElement, "type", "simple"); - AddAttribute(domElement, "center", arc.GetCenter()); - AddAttribute(domElement, "radius", arc.GetFormulaRadius()); - AddAttribute(domElement, "angle1", arc.GetFormulaF1()); - AddAttribute(domElement, "angle2", arc.GetFormulaF2()); + AddAttribute(domElement, AttrId, id); + AddAttribute(domElement, AttrType, ToolType); + AddAttribute(domElement, AttrCenter, arc.GetCenter()); + AddAttribute(domElement, AttrRadius, arc.GetFormulaRadius()); + AddAttribute(domElement, AttrAngle1, arc.GetFormulaF1()); + AddAttribute(domElement, AttrAngle2, arc.GetFormulaF2()); AddToModeling(domElement); } -void VModelingArc::mouseReleaseEvent(QGraphicsSceneMouseEvent *event){ - if(event->button() == Qt::LeftButton){ +void VModelingArc::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +{ + if (event->button() == Qt::LeftButton) + { emit ChoosedTool(id, Scene::Arc); } QGraphicsItem::mouseReleaseEvent(event); } -void VModelingArc::hoverMoveEvent(QGraphicsSceneHoverEvent *event){ +void VModelingArc::hoverMoveEvent(QGraphicsSceneHoverEvent *event) +{ Q_UNUSED(event); this->setPen(QPen(currentColor, widthMainLine)); } -void VModelingArc::hoverLeaveEvent(QGraphicsSceneHoverEvent *event){ +void VModelingArc::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) +{ Q_UNUSED(event); this->setPen(QPen(currentColor, widthHairLine)); } -void VModelingArc::RemoveReferens(){ +void VModelingArc::RemoveReferens() +{ VArc arc = VAbstractTool::data.GetModelingArc(id); doc->DecrementReferens(arc.GetCenter()); } -void VModelingArc::RefreshGeometry(){ +void VModelingArc::RefreshGeometry() +{ VArc arc = VAbstractTool::data.GetModelingArc(id); QPainterPath path; path.addPath(arc.GetPath()); diff --git a/tools/modelingTools/vmodelingarc.h b/tools/modelingTools/vmodelingarc.h index e452f59e1..510ba9d07 100644 --- a/tools/modelingTools/vmodelingarc.h +++ b/tools/modelingTools/vmodelingarc.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vmodelingarc.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,39 +24,42 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef VMODELINGARC_H #define VMODELINGARC_H #include "vmodelingtool.h" #include -#include "dialogs/dialogarc.h" -#include "widgets/vcontrolpointspline.h" +#include "../../dialogs/dialogarc.h" +#include "../../widgets/vcontrolpointspline.h" -class VModelingArc :public VModelingTool, public QGraphicsPathItem{ +class VModelingArc :public VModelingTool, public QGraphicsPathItem +{ Q_OBJECT public: - VModelingArc(VDomDocument *doc, VContainer *data, qint64 id, - Tool::Sources typeCreation, QGraphicsItem * parent = 0); - virtual void setDialog(); - static VModelingArc* Create(QSharedPointer &dialog, VDomDocument *doc, VContainer *data); - static VModelingArc* Create(const qint64 _id, const qint64 ¢er, const QString &radius, - const QString &f1, const QString &f2, VDomDocument *doc, VContainer *data, - const Document::Documents &parse, Tool::Sources typeCreation); + VModelingArc(VDomDocument *doc, VContainer *data, qint64 id, const Tool::Sources &typeCreation, + QGraphicsItem * parent = 0); + virtual void setDialog(); + static VModelingArc* Create(QSharedPointer &dialog, VDomDocument *doc, VContainer *data); + static VModelingArc* Create(const qint64 _id, const qint64 ¢er, const QString &radius, const QString &f1, + const QString &f2, VDomDocument *doc, VContainer *data, + const Document::Documents &parse, const Tool::Sources &typeCreation); + static const QString TagName; + static const QString ToolType; public slots: - virtual void FullUpdateFromFile(); - virtual void FullUpdateFromGui(int result); + virtual void FullUpdateFromFile(); + virtual void FullUpdateFromGui(int result); protected: - virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile(); - virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); - virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); - virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); - virtual void RemoveReferens(); + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void AddToFile(); + virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); + virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); + virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); + virtual void RemoveReferens(); private: QSharedPointer dialogArc; - void RefreshGeometry(); + void RefreshGeometry(); }; #endif // VMODELINGARC_H diff --git a/tools/modelingTools/vmodelingbisector.cpp b/tools/modelingTools/vmodelingbisector.cpp index 158b19ad0..7cdf15366 100644 --- a/tools/modelingTools/vmodelingbisector.cpp +++ b/tools/modelingTools/vmodelingbisector.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vmodelingbisector.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,53 +24,45 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "vmodelingbisector.h" -#include +#include "../drawTools/vtoolbisector.h" +#include "../../container/calculator.h" + +const QString VModelingBisector::ToolType = QStringLiteral("bisector"); VModelingBisector::VModelingBisector(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): - VModelingLinePoint(doc, data, id, typeLine, formula, secondPointId, 0, parent), firstPointId(0), - thirdPointId(0), dialogBisector(QSharedPointer()){ + const qint64 &secondPointId, const qint64 &thirdPointId, const Tool::Sources &typeCreation, + QGraphicsItem *parent) + :VModelingLinePoint(doc, data, id, typeLine, formula, secondPointId, 0, parent), firstPointId(0), + thirdPointId(0), dialogBisector(QSharedPointer()) +{ this->firstPointId = firstPointId; this->thirdPointId = thirdPointId; - if(typeCreation == Tool::FromGui){ + if (typeCreation == Tool::FromGui) + { AddToFile(); } } -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()){ - VPointF p = VAbstractTool::data.GetModelingPoint(id); - dialogBisector->setTypeLine(typeLine); - dialogBisector->setFormula(formula); - dialogBisector->setFirstPointId(firstPointId, id); - dialogBisector->setSecondPointId(basePointId, id); - dialogBisector->setThirdPointId(thirdPointId, id); - dialogBisector->setPointName(p.name()); - } +void VModelingBisector::setDialog() +{ + Q_ASSERT(dialogBisector.isNull() == false); + VPointF p = VAbstractTool::data.GetModelingPoint(id); + dialogBisector->setTypeLine(typeLine); + dialogBisector->setFormula(formula); + dialogBisector->setFirstPointId(firstPointId, id); + dialogBisector->setSecondPointId(basePointId, id); + dialogBisector->setThirdPointId(thirdPointId, id); + dialogBisector->setPointName(p.name()); } VModelingBisector *VModelingBisector::Create(QSharedPointer &dialog, VDomDocument *doc, - VContainer *data){ + VContainer *data) +{ QString formula = dialog->getFormula(); qint64 firstPointId = dialog->getFirstPointId(); qint64 secondPointId = dialog->getSecondPointId(); @@ -79,7 +78,8 @@ VModelingBisector *VModelingBisector::Create(const qint64 _id, const QString &fo const qint64 &thirdPointId, const QString &typeLine, const QString &pointName, const qreal &mx, const qreal &my, VDomDocument *doc, VContainer *data, const Document::Documents &parse, - Tool::Sources typeCreation){ + const Tool::Sources &typeCreation) +{ VModelingBisector *point = 0; VPointF firstPoint = data->GetModelingPoint(firstPointId); VPointF secondPoint = data->GetModelingPoint(secondPointId); @@ -88,20 +88,26 @@ VModelingBisector *VModelingBisector::Create(const qint64 _id, const QString &fo Calculator cal(data); QString errorMsg; qreal result = cal.eval(formula, &errorMsg); - if(errorMsg.isEmpty()){ - QPointF fPoint = VModelingBisector::FindPoint(firstPoint.toQPointF(), secondPoint.toQPointF(), - thirdPoint.toQPointF(), result*PrintDPI/25.4); + if (errorMsg.isEmpty()) + { + QPointF fPoint = VToolBisector::FindPoint(firstPoint.toQPointF(), secondPoint.toQPointF(), + thirdPoint.toQPointF(), toPixel(result)); qint64 id = _id; - if(typeCreation == Tool::FromGui){ + if (typeCreation == Tool::FromGui) + { id = data->AddModelingPoint(VPointF(fPoint.x(), fPoint.y(), pointName, mx, my)); - } else { + } + else + { data->UpdateModelingPoint(id, VPointF(fPoint.x(), fPoint.y(), pointName, mx, my)); - if(parse != Document::FullParse){ + if (parse != Document::FullParse) + { doc->UpdateToolData(id, data); } } data->AddLine(firstPointId, id, Draw::Modeling); - if(parse == Document::FullParse){ + if (parse == Document::FullParse) + { point = new VModelingBisector(doc, data, id, typeLine, formula, firstPointId, secondPointId, thirdPointId, typeCreation); doc->AddTool(id, point); @@ -113,58 +119,66 @@ VModelingBisector *VModelingBisector::Create(const qint64 _id, const QString &fo return point; } -void VModelingBisector::FullUpdateFromFile(){ +void VModelingBisector::FullUpdateFromFile() +{ QDomElement domElement = doc->elementById(QString().setNum(id)); - if(domElement.isElement()){ - typeLine = domElement.attribute("typeLine", ""); - formula = domElement.attribute("length", ""); - firstPointId = domElement.attribute("firstPoint", "").toLongLong(); - basePointId = domElement.attribute("secondPoint", "").toLongLong(); - thirdPointId = domElement.attribute("thirdPoint", "").toLongLong(); + if (domElement.isElement()) + { + typeLine = domElement.attribute(AttrTypeLine, ""); + formula = domElement.attribute(AttrLength, ""); + firstPointId = domElement.attribute(AttrFirstPoint, "").toLongLong(); + basePointId = domElement.attribute(AttrSecondPoint, "").toLongLong(); + thirdPointId = domElement.attribute(AttrThirdPoint, "").toLongLong(); } RefreshGeometry(); } -void VModelingBisector::FullUpdateFromGui(int result){ - if(result == QDialog::Accepted){ +void VModelingBisector::FullUpdateFromGui(int result) +{ + if (result == QDialog::Accepted) + { QDomElement domElement = doc->elementById(QString().setNum(id)); - if(domElement.isElement()){ - domElement.setAttribute("name", dialogBisector->getPointName()); - domElement.setAttribute("typeLine", dialogBisector->getTypeLine()); - domElement.setAttribute("length", dialogBisector->getFormula()); - domElement.setAttribute("firstPoint", QString().setNum(dialogBisector->getFirstPointId())); - domElement.setAttribute("secondPoint", QString().setNum(dialogBisector->getSecondPointId())); - domElement.setAttribute("thirdPoint", QString().setNum(dialogBisector->getThirdPointId())); + if (domElement.isElement()) + { + domElement.setAttribute(AttrName, dialogBisector->getPointName()); + domElement.setAttribute(AttrTypeLine, dialogBisector->getTypeLine()); + domElement.setAttribute(AttrLength, dialogBisector->getFormula()); + domElement.setAttribute(AttrFirstPoint, QString().setNum(dialogBisector->getFirstPointId())); + domElement.setAttribute(AttrSecondPoint, QString().setNum(dialogBisector->getSecondPointId())); + domElement.setAttribute(AttrThirdPoint, QString().setNum(dialogBisector->getThirdPointId())); emit FullUpdateTree(); } } dialogBisector.clear(); } -void VModelingBisector::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ +void VModelingBisector::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) +{ ContextMenu(dialogBisector, this, event); } -void VModelingBisector::AddToFile(){ +void VModelingBisector::AddToFile() +{ VPointF point = VAbstractTool::data.GetModelingPoint(id); - QDomElement domElement = doc->createElement("point"); + QDomElement domElement = doc->createElement(TagName); - AddAttribute(domElement, "id", id); - AddAttribute(domElement, "type", "bisector"); - AddAttribute(domElement, "name", point.name()); - AddAttribute(domElement, "mx", point.mx()/PrintDPI*25.4); - AddAttribute(domElement, "my", point.my()/PrintDPI*25.4); + AddAttribute(domElement, AttrId, id); + AddAttribute(domElement, AttrType, ToolType); + AddAttribute(domElement, AttrName, point.name()); + AddAttribute(domElement, AttrMx, toMM(point.mx())); + AddAttribute(domElement, AttrMy, toMM(point.my())); - AddAttribute(domElement, "typeLine", typeLine); - AddAttribute(domElement, "length", formula); - AddAttribute(domElement, "firstPoint", firstPointId); - AddAttribute(domElement, "secondPoint", basePointId); - AddAttribute(domElement, "thirdPoint", thirdPointId); + AddAttribute(domElement, AttrTypeLine, typeLine); + AddAttribute(domElement, AttrLength, formula); + AddAttribute(domElement, AttrFirstPoint, firstPointId); + AddAttribute(domElement, AttrSecondPoint, basePointId); + AddAttribute(domElement, AttrThirdPoint, thirdPointId); AddToModeling(domElement); } -void VModelingBisector::RemoveReferens(){ +void VModelingBisector::RemoveReferens() +{ doc->DecrementReferens(firstPointId); doc->DecrementReferens(thirdPointId); VModelingLinePoint::RemoveReferens(); diff --git a/tools/modelingTools/vmodelingbisector.h b/tools/modelingTools/vmodelingbisector.h index 8795d90de..cb5196cd2 100644 --- a/tools/modelingTools/vmodelingbisector.h +++ b/tools/modelingTools/vmodelingbisector.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vmodelingbisector.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,42 +24,41 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef VMODELINGBISECTOR_H #define VMODELINGBISECTOR_H #include "vmodelinglinepoint.h" -#include "dialogs/dialogbisector.h" +#include "../../dialogs/dialogbisector.h" -class VModelingBisector : public VModelingLinePoint{ +class VModelingBisector : public VModelingLinePoint +{ Q_OBJECT public: - VModelingBisector(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); - static QPointF FindPoint(const QPointF &firstPoint, const QPointF &secondPoint, - const QPointF &thirdPoint, const qreal& length); - virtual void setDialog(); - static VModelingBisector* Create(QSharedPointer &dialog, VDomDocument *doc, - VContainer *data); - static VModelingBisector* 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, VDomDocument *doc, VContainer *data, - const Document::Documents &parse, Tool::Sources typeCreation); + VModelingBisector(VDomDocument *doc, VContainer *data, const qint64 &id, + const QString &typeLine, const QString &formula, + const qint64 &firstPointId, const qint64 &secondPointId, + const qint64 &thirdPointId, const Tool::Sources &typeCreation, + QGraphicsItem * parent = 0); + virtual void setDialog(); + static VModelingBisector* Create(QSharedPointer &dialog, VDomDocument *doc, VContainer *data); + static VModelingBisector* 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, VDomDocument *doc, + VContainer *data, const Document::Documents &parse, + const Tool::Sources &typeCreation); + static const QString ToolType; public slots: - virtual void FullUpdateFromFile(); - virtual void FullUpdateFromGui(int result); + virtual void FullUpdateFromFile(); + virtual void FullUpdateFromGui(int result); protected: - virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile(); - virtual void RemoveReferens(); + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void AddToFile(); + virtual void RemoveReferens(); private: - qint64 firstPointId; - qint64 thirdPointId; + qint64 firstPointId; + qint64 thirdPointId; QSharedPointer dialogBisector; }; diff --git a/tools/modelingTools/vmodelingendline.cpp b/tools/modelingTools/vmodelingendline.cpp index 17021859d..1886c0672 100644 --- a/tools/modelingTools/vmodelingendline.cpp +++ b/tools/modelingTools/vmodelingendline.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vmodelingendline.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,38 +24,38 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "vmodelingendline.h" -#include -#include -#include "widgets/vmaingraphicsscene.h" +#include "../../container/calculator.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): - VModelingLinePoint(doc, data, id, typeLine, formula, basePointId, angle, parent), - dialogEndLine(QSharedPointer()){ +const QString VModelingEndLine::ToolType = QStringLiteral("endLine"); - if(typeCreation == Tool::FromGui){ +VModelingEndLine::VModelingEndLine(VDomDocument *doc, VContainer *data, const qint64 &id, + const QString &typeLine, const QString &formula, const qreal &angle, + const qint64 &basePointId, const Tool::Sources &typeCreation, QGraphicsItem *parent) + :VModelingLinePoint(doc, data, id, typeLine, formula, basePointId, angle, parent), + dialogEndLine(QSharedPointer()) +{ + if (typeCreation == Tool::FromGui) + { AddToFile(); } } -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()); - } +void VModelingEndLine::setDialog() +{ + Q_ASSERT(dialogEndLine.isNull() == false); + 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 &dialog, VDomDocument *doc, - VContainer *data){ +VModelingEndLine *VModelingEndLine::Create(QSharedPointer &dialog, VDomDocument *doc, VContainer *data) +{ QString pointName = dialog->getPointName(); QString typeLine = dialog->getTypeLine(); QString formula = dialog->getFormula(); @@ -62,27 +69,34 @@ VModelingEndLine *VModelingEndLine::Create(const qint64 _id, const QString &poin const QString &typeLine, const QString &formula, const qreal &angle, const qint64 &basePointId, const qreal &mx, const qreal &my, VDomDocument *doc, VContainer *data, - const Document::Documents &parse, Tool::Sources typeCreation){ + const Document::Documents &parse, const Tool::Sources &typeCreation) +{ VModelingEndLine *point = 0; VPointF basePoint = data->GetModelingPoint(basePointId); QLineF line = QLineF(basePoint.toQPointF(), QPointF(basePoint.x()+100, basePoint.y())); Calculator cal(data); QString errorMsg; qreal result = cal.eval(formula, &errorMsg); - if(errorMsg.isEmpty()){ - line.setLength(result*PrintDPI/25.4); + if (errorMsg.isEmpty()) + { + line.setLength(toPixel(result)); line.setAngle(angle); qint64 id = _id; - if(typeCreation == Tool::FromGui){ + if (typeCreation == Tool::FromGui) + { id = data->AddModelingPoint(VPointF(line.p2().x(), line.p2().y(), pointName, mx, my)); - } else { + } + else + { data->UpdateModelingPoint(id, VPointF(line.p2().x(), line.p2().y(), pointName, mx, my)); - if(parse != Document::FullParse){ + if (parse != Document::FullParse) + { doc->UpdateToolData(id, data); } } data->AddLine(basePointId, id, Draw::Modeling); - if(parse == Document::FullParse){ + if (parse == Document::FullParse) + { point = new VModelingEndLine(doc, data, id, typeLine, formula, angle, basePointId, typeCreation); doc->AddTool(id, point); doc->IncrementReferens(basePointId); @@ -91,50 +105,57 @@ VModelingEndLine *VModelingEndLine::Create(const qint64 _id, const QString &poin return point; } -void VModelingEndLine::FullUpdateFromFile(){ +void VModelingEndLine::FullUpdateFromFile() +{ QDomElement domElement = doc->elementById(QString().setNum(id)); - if(domElement.isElement()){ - typeLine = domElement.attribute("typeLine", ""); - formula = domElement.attribute("length", ""); - basePointId = domElement.attribute("basePoint", "").toLongLong(); - angle = domElement.attribute("angle", "").toInt(); + if (domElement.isElement()) + { + typeLine = domElement.attribute(AttrTypeLine, ""); + formula = domElement.attribute(AttrLength, ""); + basePointId = domElement.attribute(AttrBasePoint, "").toLongLong(); + angle = domElement.attribute(AttrAngle, "").toDouble(); } RefreshGeometry(); } -void VModelingEndLine::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ +void VModelingEndLine::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) +{ ContextMenu(dialogEndLine, this, event); } -void VModelingEndLine::FullUpdateFromGui(int result){ - if(result == QDialog::Accepted){ +void VModelingEndLine::FullUpdateFromGui(int result) +{ + if (result == QDialog::Accepted) + { QDomElement domElement = doc->elementById(QString().setNum(id)); - if(domElement.isElement()){ - domElement.setAttribute("name", dialogEndLine->getPointName()); - domElement.setAttribute("typeLine", dialogEndLine->getTypeLine()); - domElement.setAttribute("length", dialogEndLine->getFormula()); - domElement.setAttribute("angle", QString().setNum(dialogEndLine->getAngle())); - domElement.setAttribute("basePoint", QString().setNum(dialogEndLine->getBasePointId())); + if (domElement.isElement()) + { + domElement.setAttribute(AttrName, dialogEndLine->getPointName()); + domElement.setAttribute(AttrTypeLine, dialogEndLine->getTypeLine()); + domElement.setAttribute(AttrLength, dialogEndLine->getFormula()); + domElement.setAttribute(AttrAngle, QString().setNum(dialogEndLine->getAngle())); + domElement.setAttribute(AttrBasePoint, QString().setNum(dialogEndLine->getBasePointId())); emit FullUpdateTree(); } } dialogEndLine.clear(); } -void VModelingEndLine::AddToFile(){ +void VModelingEndLine::AddToFile() +{ VPointF point = VAbstractTool::data.GetModelingPoint(id); - QDomElement domElement = doc->createElement("point"); + QDomElement domElement = doc->createElement(TagName); - 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, AttrId, id); + AddAttribute(domElement, AttrType, ToolType); + AddAttribute(domElement, AttrName, point.name()); + AddAttribute(domElement, AttrMx, toMM(point.mx())); + AddAttribute(domElement, AttrMy, toMM(point.my())); - AddAttribute(domElement, "typeLine", typeLine); - AddAttribute(domElement, "length", formula); - AddAttribute(domElement, "angle", angle); - AddAttribute(domElement, "basePoint", basePointId); + AddAttribute(domElement, AttrTypeLine, typeLine); + AddAttribute(domElement, AttrLength, formula); + AddAttribute(domElement, AttrAngle, angle); + AddAttribute(domElement, AttrBasePoint, basePointId); AddToModeling(domElement); } diff --git a/tools/modelingTools/vmodelingendline.h b/tools/modelingTools/vmodelingendline.h index 6bd9d110b..2bf52d30a 100644 --- a/tools/modelingTools/vmodelingendline.h +++ b/tools/modelingTools/vmodelingendline.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vmodelingbisector.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,35 +24,35 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef VMODELINGENDLINE_H #define VMODELINGENDLINE_H #include "vmodelinglinepoint.h" -#include "dialogs/dialogendline.h" +#include "../../dialogs/dialogendline.h" -class VModelingEndLine : public VModelingLinePoint{ +class VModelingEndLine : public VModelingLinePoint +{ Q_OBJECT public: - 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 = 0); - virtual void setDialog(); - static VModelingEndLine* Create(QSharedPointer &dialog, VDomDocument *doc, - VContainer *data); - static VModelingEndLine* 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, VDomDocument *doc, VContainer *data, - const Document::Documents &parse, Tool::Sources typeCreation); + VModelingEndLine(VDomDocument *doc, VContainer *data, const qint64 &id, + const QString &typeLine, const QString &formula, const qreal &angle, + const qint64 &basePointId, const Tool::Sources &typeCreation, + QGraphicsItem * parent = 0); + virtual void setDialog(); + static VModelingEndLine* Create(QSharedPointer &dialog, VDomDocument *doc, VContainer *data); + static VModelingEndLine* 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, VDomDocument *doc, VContainer *data, + const Document::Documents &parse, const Tool::Sources &typeCreation); + static const QString ToolType; public slots: - virtual void FullUpdateFromFile(); - virtual void FullUpdateFromGui(int result); + virtual void FullUpdateFromFile(); + virtual void FullUpdateFromGui(int result); protected: - virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile(); + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void AddToFile(); private: QSharedPointer dialogEndLine; }; diff --git a/tools/modelingTools/vmodelingheight.cpp b/tools/modelingTools/vmodelingheight.cpp new file mode 100644 index 000000000..53ae05ac1 --- /dev/null +++ b/tools/modelingTools/vmodelingheight.cpp @@ -0,0 +1,163 @@ +/************************************************************************ + ** + ** @file vmodelingheight.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "vmodelingheight.h" +#include "../drawTools/vtoolheight.h" + +const QString VModelingHeight::ToolType = QStringLiteral("height"); + +VModelingHeight::VModelingHeight(VDomDocument *doc, VContainer *data, const qint64 &id, + const QString &typeLine, const qint64 &basePointId, const qint64 &p1LineId, + const qint64 &p2LineId, const Tool::Sources &typeCreation, + QGraphicsItem * parent) + :VModelingLinePoint(doc, data, id, typeLine, QString(), basePointId, 0, parent), + dialogHeight(QSharedPointer()), p1LineId(p1LineId), p2LineId(p2LineId) +{ + ignoreFullUpdate = true; + if (typeCreation == Tool::FromGui) + { + AddToFile(); + } +} + +void VModelingHeight::setDialog() +{ + Q_ASSERT(dialogHeight.isNull() == false); + 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 &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, const Tool::Sources &typeCreation) +{ + VModelingHeight *point = 0; + VPointF basePoint = data->GetModelingPoint(basePointId); + VPointF p1Line = data->GetModelingPoint(p1LineId); + VPointF p2Line = data->GetModelingPoint(p2LineId); + + QPointF pHeight = VToolHeight::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(AttrTypeLine, ""); + basePointId = domElement.attribute(AttrBasePoint, "").toLongLong(); + p1LineId = domElement.attribute(AttrP1Line, "").toLongLong(); + p2LineId = domElement.attribute(AttrP2Line, "").toLongLong(); + } + RefreshGeometry(); +} + +void VModelingHeight::FullUpdateFromGui(int result) +{ + if (result == QDialog::Accepted) + { + QDomElement domElement = doc->elementById(QString().setNum(id)); + if (domElement.isElement()) + { + domElement.setAttribute(AttrName, dialogHeight->getPointName()); + domElement.setAttribute(AttrTypeLine, dialogHeight->getTypeLine()); + domElement.setAttribute(AttrBasePoint, QString().setNum(dialogHeight->getBasePointId())); + domElement.setAttribute(AttrP1Line, QString().setNum(dialogHeight->getP1LineId())); + domElement.setAttribute(AttrP2Line, 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(TagName); + + AddAttribute(domElement, AttrId, id); + AddAttribute(domElement, AttrType, ToolType); + AddAttribute(domElement, AttrName, point.name()); + AddAttribute(domElement, AttrMx, toMM(point.mx())); + AddAttribute(domElement, AttrMy, toMM(point.my())); + + AddAttribute(domElement, AttrTypeLine, typeLine); + AddAttribute(domElement, AttrBasePoint, basePointId); + AddAttribute(domElement, AttrP1Line, p1LineId); + AddAttribute(domElement, AttrP2Line, p2LineId); + + AddToModeling(domElement); +} diff --git a/tools/modelingTools/vmodelingheight.h b/tools/modelingTools/vmodelingheight.h new file mode 100644 index 000000000..791779e46 --- /dev/null +++ b/tools/modelingTools/vmodelingheight.h @@ -0,0 +1,62 @@ +/************************************************************************ + ** + ** @file vmodelingheight.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#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, const Tool::Sources &typeCreation, + QGraphicsItem * parent = 0); + virtual void setDialog(); + static VModelingHeight* Create(QSharedPointer &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, const Tool::Sources &typeCreation); + static const QString ToolType; +public slots: + virtual void FullUpdateFromFile(); + virtual void FullUpdateFromGui(int result); +protected: + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void AddToFile(); +private: + QSharedPointer dialogHeight; + qint64 p1LineId; + qint64 p2LineId; +}; + +#endif // VMODELINGHEIGHT_H diff --git a/tools/modelingTools/vmodelingline.cpp b/tools/modelingTools/vmodelingline.cpp index 911906f67..619467dd5 100644 --- a/tools/modelingTools/vmodelingline.cpp +++ b/tools/modelingTools/vmodelingline.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vmodelingline.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,15 +24,18 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "vmodelingline.h" -#include + +const QString VModelingLine::TagName = QStringLiteral("line"); VModelingLine::VModelingLine(VDomDocument *doc, VContainer *data, qint64 id, qint64 firstPoint, - qint64 secondPoint, Tool::Sources typeCreation, QGraphicsItem *parent): + qint64 secondPoint, const Tool::Sources &typeCreation, QGraphicsItem *parent): VModelingTool(doc, data, id), QGraphicsLineItem(parent), firstPoint(firstPoint), - secondPoint(secondPoint), dialogLine(QSharedPointer()){ + secondPoint(secondPoint), dialogLine(QSharedPointer()) +{ + ignoreFullUpdate = true; //Лінія VPointF first = data->GetModelingPoint(firstPoint); VPointF second = data->GetModelingPoint(secondPoint); @@ -34,18 +44,20 @@ VModelingLine::VModelingLine(VDomDocument *doc, VContainer *data, qint64 id, qin this->setFlag(QGraphicsItem::ItemIsSelectable, true); this->setAcceptHoverEvents(true); - if(typeCreation == Tool::FromGui){ + if (typeCreation == Tool::FromGui) + { AddToFile(); } } -void VModelingLine::setDialog(){ +void VModelingLine::setDialog() +{ dialogLine->setFirstPoint(firstPoint); dialogLine->setSecondPoint(secondPoint); } -VModelingLine *VModelingLine::Create(QSharedPointer &dialog, VDomDocument *doc, - VContainer *data){ +VModelingLine *VModelingLine::Create(QSharedPointer &dialog, VDomDocument *doc, VContainer *data) +{ qint64 firstPoint = dialog->getFirstPoint(); qint64 secondPoint = dialog->getSecondPoint(); return Create(0, firstPoint, secondPoint, doc, data, Document::FullParse, Tool::FromGui); @@ -53,20 +65,27 @@ VModelingLine *VModelingLine::Create(QSharedPointer &dialog, VDomDoc VModelingLine *VModelingLine::Create(const qint64 &_id, const qint64 &firstPoint, const qint64 &secondPoint, VDomDocument *doc, VContainer *data, const Document::Documents &parse, - Tool::Sources typeCreation){ + const Tool::Sources &typeCreation) +{ VModelingLine *line = 0; - Q_CHECK_PTR(doc); - Q_CHECK_PTR(data); + Q_ASSERT(doc != 0); + Q_ASSERT(data != 0); qint64 id = _id; - if(typeCreation == Tool::FromGui){ + if (typeCreation == Tool::FromGui) + { id = data->getNextId(); - } else { - if(parse != Document::FullParse){ + } + else + { + if (parse != Document::FullParse) + { + data->UpdateId(id); doc->UpdateToolData(id, data); } } data->AddLine(firstPoint, secondPoint, Draw::Modeling); - if(parse == Document::FullParse){ + if (parse == Document::FullParse) + { line = new VModelingLine(doc, data, id, firstPoint, secondPoint, typeCreation); doc->AddTool(id, line); doc->IncrementReferens(firstPoint); @@ -75,53 +94,63 @@ VModelingLine *VModelingLine::Create(const qint64 &_id, const qint64 &firstPoint return line; } -void VModelingLine::FullUpdateFromFile(){ +void VModelingLine::FullUpdateFromFile() +{ QDomElement domElement = doc->elementById(QString().setNum(id)); - if(domElement.isElement()){ - firstPoint = domElement.attribute("firstPoint", "").toLongLong(); - secondPoint = domElement.attribute("secondPoint", "").toLongLong(); + if (domElement.isElement()) + { + firstPoint = domElement.attribute(AttrFirstPoint, "").toLongLong(); + secondPoint = domElement.attribute(AttrSecondPoint, "").toLongLong(); } VPointF first = VAbstractTool::data.GetModelingPoint(firstPoint); VPointF second = VAbstractTool::data.GetModelingPoint(secondPoint); this->setLine(QLineF(first.toQPointF(), second.toQPointF())); } -void VModelingLine::FullUpdateFromGui(int result){ - if(result == QDialog::Accepted){ +void VModelingLine::FullUpdateFromGui(int result) +{ + if (result == QDialog::Accepted) + { QDomElement domElement = doc->elementById(QString().setNum(id)); - if(domElement.isElement()){ - domElement.setAttribute("firstPoint", QString().setNum(dialogLine->getFirstPoint())); - domElement.setAttribute("secondPoint", QString().setNum(dialogLine->getSecondPoint())); + if (domElement.isElement()) + { + domElement.setAttribute(AttrFirstPoint, QString().setNum(dialogLine->getFirstPoint())); + domElement.setAttribute(AttrSecondPoint, QString().setNum(dialogLine->getSecondPoint())); emit FullUpdateTree(); } } dialogLine.clear(); } -void VModelingLine::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ +void VModelingLine::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) +{ ContextMenu(dialogLine, this, event); } -void VModelingLine::AddToFile(){ - QDomElement domElement = doc->createElement("line"); - AddAttribute(domElement, "id", id); - AddAttribute(domElement, "firstPoint", firstPoint); - AddAttribute(domElement, "secondPoint", secondPoint); +void VModelingLine::AddToFile() +{ + QDomElement domElement = doc->createElement(TagName); + AddAttribute(domElement, AttrId, id); + AddAttribute(domElement, AttrFirstPoint, firstPoint); + AddAttribute(domElement, AttrSecondPoint, secondPoint); AddToModeling(domElement); } -void VModelingLine::hoverMoveEvent(QGraphicsSceneHoverEvent *event){ +void VModelingLine::hoverMoveEvent(QGraphicsSceneHoverEvent *event) +{ Q_UNUSED(event); this->setPen(QPen(currentColor, widthMainLine)); } -void VModelingLine::hoverLeaveEvent(QGraphicsSceneHoverEvent *event){ +void VModelingLine::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) +{ Q_UNUSED(event); this->setPen(QPen(currentColor, widthHairLine)); } -void VModelingLine::RemoveReferens(){ +void VModelingLine::RemoveReferens() +{ doc->DecrementReferens(firstPoint); doc->DecrementReferens(secondPoint); } diff --git a/tools/modelingTools/vmodelingline.h b/tools/modelingTools/vmodelingline.h index 881abda27..2798eadb7 100644 --- a/tools/modelingTools/vmodelingline.h +++ b/tools/modelingTools/vmodelingline.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vmodelingline.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,38 +24,41 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef VMODELINGLINE_H #define VMODELINGLINE_H #include "vmodelingtool.h" -#include "QGraphicsLineItem" -#include "dialogs/dialogline.h" +#include +#include "../../dialogs/dialogline.h" -class VModelingLine: public VModelingTool, public QGraphicsLineItem{ +class VModelingLine: public VModelingTool, public QGraphicsLineItem +{ Q_OBJECT public: - VModelingLine(VDomDocument *doc, VContainer *data, qint64 id, qint64 firstPoint, - qint64 secondPoint, Tool::Sources typeCreation, - QGraphicsItem * parent = 0); - virtual void setDialog(); - static VModelingLine* Create(QSharedPointer &dialog, VDomDocument *doc, VContainer *data); - static VModelingLine* Create(const qint64 &_id, const qint64 &firstPoint, const qint64 &secondPoint, - VDomDocument *doc, VContainer *data, const Document::Documents &parse, - Tool::Sources typeCreation); + VModelingLine(VDomDocument *doc, VContainer *data, qint64 id, qint64 firstPoint, + qint64 secondPoint, const Tool::Sources &typeCreation, + QGraphicsItem * parent = 0); + virtual void setDialog(); + static VModelingLine* Create(QSharedPointer &dialog, VDomDocument *doc, VContainer *data); + static VModelingLine* Create(const qint64 &_id, const qint64 &firstPoint, const qint64 &secondPoint, + VDomDocument *doc, VContainer *data, const Document::Documents &parse, + const Tool::Sources &typeCreation); + static const QString TagName; + static const QString ToolType; public slots: - virtual void FullUpdateFromFile(); - virtual void FullUpdateFromGui(int result); + virtual void FullUpdateFromFile(); + virtual void FullUpdateFromGui(int result); protected: - virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile(); - virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); - virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); - virtual void RemoveReferens(); + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void AddToFile(); + virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); + virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); + virtual void RemoveReferens(); private: - qint64 firstPoint; - qint64 secondPoint; + qint64 firstPoint; + qint64 secondPoint; QSharedPointer dialogLine; }; diff --git a/tools/modelingTools/vmodelinglineintersect.cpp b/tools/modelingTools/vmodelinglineintersect.cpp index 51a45e7d0..4a3eec24b 100644 --- a/tools/modelingTools/vmodelinglineintersect.cpp +++ b/tools/modelingTools/vmodelinglineintersect.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vmodelinglineintersect.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,34 +24,39 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "vmodelinglineintersect.h" +const QString VModelingLineIntersect::ToolType = QStringLiteral("lineIntersect"); + VModelingLineIntersect::VModelingLineIntersect(VDomDocument *doc, VContainer *data, const qint64 &id, const qint64 &p1Line1, const qint64 &p2Line1, const qint64 &p1Line2, - const qint64 &p2Line2, Tool::Sources typeCreation, QGraphicsItem *parent): - VModelingPoint(doc, data, id, parent), p1Line1(p1Line1), p2Line1(p2Line1), p1Line2(p1Line2), - p2Line2(p2Line2), dialogLineIntersect(QSharedPointer()){ - if(typeCreation == Tool::FromGui){ + const qint64 &p2Line2, const Tool::Sources &typeCreation, QGraphicsItem *parent) + :VModelingPoint(doc, data, id, parent), p1Line1(p1Line1), p2Line1(p2Line1), p1Line2(p1Line2), + p2Line2(p2Line2), dialogLineIntersect(QSharedPointer()) +{ + ignoreFullUpdate = true; + if (typeCreation == Tool::FromGui) + { AddToFile(); } } -void VModelingLineIntersect::setDialog(){ - Q_ASSERT(!dialogLineIntersect.isNull()); - if(!dialogLineIntersect.isNull()){ - VPointF p = VAbstractTool::data.GetModelingPoint(id); - dialogLineIntersect->setP1Line1(p1Line1); - dialogLineIntersect->setP2Line1(p2Line1); - dialogLineIntersect->setP1Line2(p1Line2); - dialogLineIntersect->setP2Line2(p2Line2); - dialogLineIntersect->setPointName(p.name()); - } +void VModelingLineIntersect::setDialog() +{ + Q_ASSERT(dialogLineIntersect.isNull() == false); + VPointF p = VAbstractTool::data.GetModelingPoint(id); + dialogLineIntersect->setP1Line1(p1Line1); + dialogLineIntersect->setP2Line1(p2Line1); + dialogLineIntersect->setP1Line2(p1Line2); + dialogLineIntersect->setP2Line2(p2Line2); + dialogLineIntersect->setPointName(p.name()); } VModelingLineIntersect *VModelingLineIntersect::Create(QSharedPointer &dialog, - VDomDocument *doc, VContainer *data){ + VDomDocument *doc, VContainer *data) +{ qint64 p1Line1Id = dialog->getP1Line1(); qint64 p2Line1Id = dialog->getP2Line1(); qint64 p1Line2Id = dialog->getP1Line2(); @@ -59,7 +71,8 @@ VModelingLineIntersect *VModelingLineIntersect::Create(const qint64 _id, const q const qint64 &p2Line2Id, const QString &pointName, const qreal &mx, const qreal &my, VDomDocument *doc, VContainer *data, const Document::Documents &parse, - Tool::Sources typeCreation){ + const Tool::Sources &typeCreation) +{ VModelingLineIntersect *point = 0; VPointF p1Line1 = data->GetModelingPoint(p1Line1Id); VPointF p2Line1 = data->GetModelingPoint(p2Line1Id); @@ -70,13 +83,18 @@ VModelingLineIntersect *VModelingLineIntersect::Create(const qint64 _id, const q QLineF line2(p1Line2.toQPointF(), p2Line2.toQPointF()); QPointF fPoint; QLineF::IntersectType intersect = line1.intersect(line2, &fPoint); - if(intersect == QLineF::UnboundedIntersection || intersect == QLineF::BoundedIntersection){ + if (intersect == QLineF::UnboundedIntersection || intersect == QLineF::BoundedIntersection) + { qint64 id = _id; - if(typeCreation == Tool::FromGui){ + if (typeCreation == Tool::FromGui) + { id = data->AddModelingPoint(VPointF(fPoint.x(), fPoint.y(), pointName, mx, my)); - } else { + } + else + { data->UpdateModelingPoint(id, VPointF(fPoint.x(), fPoint.y(), pointName, mx, my)); - if(parse != Document::FullParse){ + if (parse != Document::FullParse) + { doc->UpdateToolData(id, data); } } @@ -84,7 +102,8 @@ VModelingLineIntersect *VModelingLineIntersect::Create(const qint64 _id, const q data->AddLine(id, p2Line1Id, Draw::Modeling); data->AddLine(p1Line2Id, id, Draw::Modeling); data->AddLine(id, p2Line2Id, Draw::Modeling); - if(parse == Document::FullParse){ + if (parse == Document::FullParse) + { point = new VModelingLineIntersect(doc, data, id, p1Line1Id, p2Line1Id, p1Line2Id, p2Line2Id, typeCreation); doc->AddTool(id, point); @@ -97,55 +116,63 @@ VModelingLineIntersect *VModelingLineIntersect::Create(const qint64 _id, const q return point; } -void VModelingLineIntersect::FullUpdateFromFile(){ +void VModelingLineIntersect::FullUpdateFromFile() +{ QDomElement domElement = doc->elementById(QString().setNum(id)); - if(domElement.isElement()){ - p1Line1 = domElement.attribute("p1Line1", "").toLongLong(); - p2Line1 = domElement.attribute("p2Line1", "").toLongLong(); - p1Line2 = domElement.attribute("p1Line2", "").toLongLong(); - p2Line2 = domElement.attribute("p2Line2", "").toLongLong(); + if (domElement.isElement()) + { + p1Line1 = domElement.attribute(AttrP1Line1, "").toLongLong(); + p2Line1 = domElement.attribute(AttrP2Line1, "").toLongLong(); + p1Line2 = domElement.attribute(AttrP1Line2, "").toLongLong(); + p2Line2 = domElement.attribute(AttrP2Line2, "").toLongLong(); } RefreshPointGeometry(VAbstractTool::data.GetModelingPoint(id)); } -void VModelingLineIntersect::FullUpdateFromGui(int result){ - if(result == QDialog::Accepted){ +void VModelingLineIntersect::FullUpdateFromGui(int result) +{ + if (result == QDialog::Accepted) + { QDomElement domElement = doc->elementById(QString().setNum(id)); - if(domElement.isElement()){ - domElement.setAttribute("name", dialogLineIntersect->getPointName()); - domElement.setAttribute("p1Line1", QString().setNum(dialogLineIntersect->getP1Line1())); - domElement.setAttribute("p2Line1", QString().setNum(dialogLineIntersect->getP2Line1())); - domElement.setAttribute("p1Line2", QString().setNum(dialogLineIntersect->getP1Line2())); - domElement.setAttribute("p2Line2", QString().setNum(dialogLineIntersect->getP2Line2())); + if (domElement.isElement()) + { + domElement.setAttribute(AttrName, dialogLineIntersect->getPointName()); + domElement.setAttribute(AttrP1Line1, QString().setNum(dialogLineIntersect->getP1Line1())); + domElement.setAttribute(AttrP2Line1, QString().setNum(dialogLineIntersect->getP2Line1())); + domElement.setAttribute(AttrP1Line2, QString().setNum(dialogLineIntersect->getP1Line2())); + domElement.setAttribute(AttrP2Line2, QString().setNum(dialogLineIntersect->getP2Line2())); emit FullUpdateTree(); } } dialogLineIntersect.clear(); } -void VModelingLineIntersect::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ +void VModelingLineIntersect::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) +{ ContextMenu(dialogLineIntersect, this, event); } -void VModelingLineIntersect::AddToFile(){ +void VModelingLineIntersect::AddToFile() +{ VPointF point = VAbstractTool::data.GetModelingPoint(id); - QDomElement domElement = doc->createElement("point"); + QDomElement domElement = doc->createElement(TagName); - AddAttribute(domElement, "id", id); - AddAttribute(domElement, "type", "lineIntersect"); - AddAttribute(domElement, "name", point.name()); - AddAttribute(domElement, "mx", point.mx()/PrintDPI*25.4); - AddAttribute(domElement, "my", point.my()/PrintDPI*25.4); + AddAttribute(domElement, AttrId, id); + AddAttribute(domElement, AttrType, ToolType); + AddAttribute(domElement, AttrName, point.name()); + AddAttribute(domElement, AttrMx, toMM(point.mx())); + AddAttribute(domElement, AttrMy, toMM(point.my())); - AddAttribute(domElement, "p1Line1", p1Line1); - AddAttribute(domElement, "p2Line1", p2Line1); - AddAttribute(domElement, "p1Line2", p1Line2); - AddAttribute(domElement, "p2Line2", p2Line2); + AddAttribute(domElement, AttrP1Line1, p1Line1); + AddAttribute(domElement, AttrP2Line1, p2Line1); + AddAttribute(domElement, AttrP1Line2, p1Line2); + AddAttribute(domElement, AttrP2Line2, p2Line2); AddToModeling(domElement); } -void VModelingLineIntersect::RemoveReferens(){ +void VModelingLineIntersect::RemoveReferens() +{ doc->DecrementReferens(p1Line1); doc->DecrementReferens(p2Line1); doc->DecrementReferens(p1Line2); diff --git a/tools/modelingTools/vmodelinglineintersect.h b/tools/modelingTools/vmodelinglineintersect.h index e2af48470..b8ca4d2eb 100644 --- a/tools/modelingTools/vmodelinglineintersect.h +++ b/tools/modelingTools/vmodelinglineintersect.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vmodelinglineintersect.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,44 +24,43 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef VMODELINGLINEINTERSECT_H #define VMODELINGLINEINTERSECT_H #include "vmodelingpoint.h" -#include "dialogs/dialoglineintersect.h" +#include "../../dialogs/dialoglineintersect.h" -class VModelingLineIntersect:public VModelingPoint{ +class VModelingLineIntersect:public VModelingPoint +{ Q_OBJECT public: - VModelingLineIntersect(VDomDocument *doc, VContainer *data, - const qint64 &id, const qint64 &p1Line1, - const qint64 &p2Line1, const qint64 &p1Line2, - const qint64 &p2Line2, - Tool::Sources typeCreation, - QGraphicsItem * parent = 0); - virtual void setDialog(); - static VModelingLineIntersect* Create(QSharedPointer &dialog, - VDomDocument *doc,VContainer *data); - static VModelingLineIntersect* Create(const qint64 _id, const qint64 &p1Line1Id, - const qint64 &p2Line1Id, const qint64 &p1Line2Id, - const qint64 &p2Line2Id, const QString &pointName, - const qreal &mx, const qreal &my, VDomDocument *doc, - VContainer *data, const Document::Documents &parse, - Tool::Sources typeCreation); + VModelingLineIntersect(VDomDocument *doc, VContainer *data, const qint64 &id, + const qint64 &p1Line1, const qint64 &p2Line1, + const qint64 &p1Line2, const qint64 &p2Line2, + const Tool::Sources &typeCreation, + QGraphicsItem * parent = 0); + virtual void setDialog(); + static VModelingLineIntersect* Create(QSharedPointer &dialog, VDomDocument *doc, + VContainer *data); + static VModelingLineIntersect* Create(const qint64 _id, const qint64 &p1Line1Id, const qint64 &p2Line1Id, + const qint64 &p1Line2Id, const qint64 &p2Line2Id, const QString &pointName, + const qreal &mx, const qreal &my, VDomDocument *doc, VContainer *data, + const Document::Documents &parse, const Tool::Sources &typeCreation); + static const QString ToolType; public slots: - virtual void FullUpdateFromFile(); - virtual void FullUpdateFromGui(int result); + virtual void FullUpdateFromFile(); + virtual void FullUpdateFromGui(int result); protected: - virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile(); - virtual void RemoveReferens(); + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void AddToFile(); + virtual void RemoveReferens(); private: - qint64 p1Line1; - qint64 p2Line1; - qint64 p1Line2; - qint64 p2Line2; + qint64 p1Line1; + qint64 p2Line1; + qint64 p1Line2; + qint64 p2Line2; QSharedPointer dialogLineIntersect; }; diff --git a/tools/modelingTools/vmodelinglinepoint.cpp b/tools/modelingTools/vmodelinglinepoint.cpp index c326a4079..2c88505ad 100644 --- a/tools/modelingTools/vmodelinglinepoint.cpp +++ b/tools/modelingTools/vmodelinglinepoint.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vmodelinglinepoint.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,40 +24,44 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "vmodelinglinepoint.h" VModelingLinePoint::VModelingLinePoint(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &typeLine, const QString &formula, const qint64 &basePointId, - const qreal &angle, QGraphicsItem *parent): - VModelingPoint(doc, data, id, parent), typeLine(typeLine), formula(formula), angle(angle), - basePointId(basePointId), mainLine(0){ + const qreal &angle, QGraphicsItem *parent) + :VModelingPoint(doc, data, id, parent), typeLine(typeLine), formula(formula), angle(angle), + basePointId(basePointId), mainLine(0) +{ //Лінія, що з'єднує дві точки QPointF point1 = data->GetModelingPoint(basePointId).toQPointF(); QPointF point2 = data->GetModelingPoint(id).toQPointF(); mainLine = new QGraphicsLineItem(QLineF(point1 - point2, QPointF()), this); mainLine->setPen(QPen(Qt::black, widthHairLine)); mainLine->setFlag(QGraphicsItem::ItemStacksBehindParent, true); - if(typeLine == "none"){ + if (typeLine == TypeLineNone) + { mainLine->setVisible(false); - } else { + } + else + { mainLine->setVisible(true); } } -void VModelingLinePoint::RefreshGeometry(){ +void VModelingLinePoint::RefreshGeometry() +{ VModelingPoint::RefreshPointGeometry(VModelingTool::data.GetModelingPoint(id)); QPointF point = VModelingTool::data.GetModelingPoint(id).toQPointF(); QPointF basePoint = VModelingTool::data.GetModelingPoint(basePointId).toQPointF(); mainLine->setLine(QLineF(basePoint - point, QPointF())); - if(typeLine == "none"){ + if (typeLine == TypeLineNone) + { mainLine->setVisible(false); - } else { + } + else + { mainLine->setVisible(true); } } - -void VModelingLinePoint::RemoveReferens(){ - doc->DecrementReferens(basePointId); -} diff --git a/tools/modelingTools/vmodelinglinepoint.h b/tools/modelingTools/vmodelinglinepoint.h index 762ce1fc5..4ca0e9ced 100644 --- a/tools/modelingTools/vmodelinglinepoint.h +++ b/tools/modelingTools/vmodelinglinepoint.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vmodelinglinepoint.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,19 +24,19 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef VMODELINGLINEPOINT_H #define VMODELINGLINEPOINT_H #include "vmodelingpoint.h" -class VModelingLinePoint : public VModelingPoint{ +class VModelingLinePoint : public VModelingPoint +{ Q_OBJECT public: - VModelingLinePoint(VDomDocument *doc, VContainer *data, const qint64 &id, - const QString &typeLine, const QString &formula, - const qint64 &basePointId, const qreal &angle, + VModelingLinePoint(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &typeLine, + const QString &formula, const qint64 &basePointId, const qreal &angle, QGraphicsItem * parent = 0); protected: QString typeLine; @@ -38,7 +45,7 @@ protected: qint64 basePointId; QGraphicsLineItem *mainLine; virtual void RefreshGeometry(); - virtual void RemoveReferens(); + virtual void RemoveReferens() {doc->DecrementReferens(basePointId);} private: Q_DISABLE_COPY(VModelingLinePoint) }; diff --git a/tools/modelingTools/vmodelingnormal.cpp b/tools/modelingTools/vmodelingnormal.cpp index 55edddd10..d0d662b1c 100644 --- a/tools/modelingTools/vmodelingnormal.cpp +++ b/tools/modelingTools/vmodelingnormal.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vmodelingnormal.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,38 +24,40 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "vmodelingnormal.h" +#include "../drawTools/vtoolnormal.h" +#include "../../container/calculator.h" -VModelingNormal::VModelingNormal(VDomDocument *doc, VContainer *data, const qint64 &id, - const QString &typeLine, +const QString VModelingNormal::ToolType = QStringLiteral("normal"); + +VModelingNormal::VModelingNormal(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &typeLine, const QString &formula, const qreal &angle, const qint64 &firstPointId, - const qint64 &secondPointId, Tool::Sources typeCreation, QGraphicsItem *parent): - VModelingLinePoint(doc, data, id, typeLine, formula, firstPointId, angle, parent), - secondPointId(secondPointId), dialogNormal(QSharedPointer()){ - - if(typeCreation == Tool::FromGui){ + const qint64 &secondPointId, const Tool::Sources &typeCreation, QGraphicsItem *parent) + :VModelingLinePoint(doc, data, id, typeLine, formula, firstPointId, angle, parent), + secondPointId(secondPointId), dialogNormal(QSharedPointer()) +{ + if (typeCreation == Tool::FromGui) + { AddToFile(); } - } -void VModelingNormal::setDialog(){ - Q_ASSERT(!dialogNormal.isNull()); - if(!dialogNormal.isNull()){ - VPointF p = VAbstractTool::data.GetModelingPoint(id); - dialogNormal->setTypeLine(typeLine); - dialogNormal->setFormula(formula); - dialogNormal->setAngle(angle); - dialogNormal->setFirstPointId(basePointId, id); - dialogNormal->setSecondPointId(secondPointId, id); - dialogNormal->setPointName(p.name()); - } +void VModelingNormal::setDialog() +{ + Q_ASSERT(dialogNormal.isNull() == false); + VPointF p = VAbstractTool::data.GetModelingPoint(id); + dialogNormal->setTypeLine(typeLine); + dialogNormal->setFormula(formula); + dialogNormal->setAngle(angle); + dialogNormal->setFirstPointId(basePointId, id); + dialogNormal->setSecondPointId(secondPointId, id); + dialogNormal->setPointName(p.name()); } -VModelingNormal* VModelingNormal::Create(QSharedPointer &dialog, VDomDocument *doc, - VContainer *data){ +VModelingNormal* VModelingNormal::Create(QSharedPointer &dialog, VDomDocument *doc, VContainer *data) +{ QString formula = dialog->getFormula(); qint64 firstPointId = dialog->getFirstPointId(); qint64 secondPointId = dialog->getSecondPointId(); @@ -59,32 +68,38 @@ VModelingNormal* VModelingNormal::Create(QSharedPointer &dialog, V Document::FullParse, Tool::FromGui); } -VModelingNormal *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){ +VModelingNormal *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, + const Tool::Sources &typeCreation) +{ VModelingNormal *point = 0; VPointF firstPoint = data->GetModelingPoint(firstPointId); VPointF secondPoint = data->GetModelingPoint(secondPointId); Calculator cal(data); QString errorMsg; qreal result = cal.eval(formula, &errorMsg); - if(errorMsg.isEmpty()){ - QPointF fPoint = VModelingNormal::FindPoint(firstPoint.toQPointF(), secondPoint.toQPointF(), - result*PrintDPI/25.4, angle); + if (errorMsg.isEmpty()) + { + QPointF fPoint = VToolNormal::FindPoint(firstPoint.toQPointF(), secondPoint.toQPointF(), + toPixel(result), angle); qint64 id = _id; - if(typeCreation == Tool::FromGui){ + if (typeCreation == Tool::FromGui) + { id = data->AddModelingPoint(VPointF(fPoint.x(), fPoint.y(), pointName, mx, my)); - } else { + } + else + { data->UpdateModelingPoint(id, VPointF(fPoint.x(), fPoint.y(), pointName, mx, my)); - if(parse != Document::FullParse){ + if (parse != Document::FullParse) + { doc->UpdateToolData(id, data); } } data->AddLine(firstPointId, id, Draw::Modeling); - if(parse == Document::FullParse){ + if (parse == Document::FullParse) + { point = new VModelingNormal(doc, data, id, typeLine, formula, angle, firstPointId, secondPointId, typeCreation); doc->AddTool(id, point); @@ -95,67 +110,66 @@ 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(){ +void VModelingNormal::FullUpdateFromFile() +{ QDomElement domElement = doc->elementById(QString().setNum(id)); - if(domElement.isElement()){ - typeLine = domElement.attribute("typeLine", ""); - formula = domElement.attribute("length", ""); - basePointId = domElement.attribute("firstPoint", "").toLongLong(); - secondPointId = domElement.attribute("secondPoint", "").toLongLong(); - angle = domElement.attribute("angle", "").toInt(); + if (domElement.isElement()) + { + typeLine = domElement.attribute(AttrTypeLine, ""); + formula = domElement.attribute(AttrLength, ""); + basePointId = domElement.attribute(AttrFirstPoint, "").toLongLong(); + secondPointId = domElement.attribute(AttrSecondPoint, "").toLongLong(); + angle = domElement.attribute(AttrAngle, "").toInt(); } RefreshGeometry(); } -void VModelingNormal::FullUpdateFromGui(int result){ - if(result == QDialog::Accepted){ +void VModelingNormal::FullUpdateFromGui(int result) +{ + if (result == QDialog::Accepted) + { QDomElement domElement = doc->elementById(QString().setNum(id)); - if(domElement.isElement()){ - domElement.setAttribute("name", dialogNormal->getPointName()); - domElement.setAttribute("typeLine", dialogNormal->getTypeLine()); - domElement.setAttribute("length", dialogNormal->getFormula()); - domElement.setAttribute("angle", QString().setNum(dialogNormal->getAngle())); - domElement.setAttribute("firstPoint", QString().setNum(dialogNormal->getFirstPointId())); - domElement.setAttribute("secondPoint", QString().setNum(dialogNormal->getSecondPointId())); + if (domElement.isElement()) + { + domElement.setAttribute(AttrName, dialogNormal->getPointName()); + domElement.setAttribute(AttrTypeLine, dialogNormal->getTypeLine()); + domElement.setAttribute(AttrLength, dialogNormal->getFormula()); + domElement.setAttribute(AttrAngle, QString().setNum(dialogNormal->getAngle())); + domElement.setAttribute(AttrFirstPoint, QString().setNum(dialogNormal->getFirstPointId())); + domElement.setAttribute(AttrSecondPoint, QString().setNum(dialogNormal->getSecondPointId())); emit FullUpdateTree(); } } dialogNormal.clear(); } -void VModelingNormal::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ +void VModelingNormal::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) +{ ContextMenu(dialogNormal, this, event); } -void VModelingNormal::AddToFile(){ +void VModelingNormal::AddToFile() +{ VPointF point = VAbstractTool::data.GetModelingPoint(id); - QDomElement domElement = doc->createElement("point"); + QDomElement domElement = doc->createElement(TagName); - AddAttribute(domElement, "id", id); - AddAttribute(domElement, "type", "normal"); - AddAttribute(domElement, "name", point.name()); - AddAttribute(domElement, "mx", point.mx()/PrintDPI*25.4); - AddAttribute(domElement, "my", point.my()/PrintDPI*25.4); + AddAttribute(domElement, AttrId, id); + AddAttribute(domElement, AttrType, ToolType); + AddAttribute(domElement, AttrName, point.name()); + AddAttribute(domElement, AttrMx, toMM(point.mx())); + AddAttribute(domElement, AttrMy, toMM(point.my())); - AddAttribute(domElement, "typeLine", typeLine); - AddAttribute(domElement, "length", formula); - AddAttribute(domElement, "angle", angle); - AddAttribute(domElement, "firstPoint", basePointId); - AddAttribute(domElement, "secondPoint", secondPointId); + AddAttribute(domElement, AttrTypeLine, typeLine); + AddAttribute(domElement, AttrLength, formula); + AddAttribute(domElement, AttrAngle, angle); + AddAttribute(domElement, AttrFirstPoint, basePointId); + AddAttribute(domElement, AttrSecondPoint, secondPointId); AddToModeling(domElement); } -void VModelingNormal::RemoveReferens(){ +void VModelingNormal::RemoveReferens() +{ doc->DecrementReferens(secondPointId); VModelingLinePoint::RemoveReferens(); } diff --git a/tools/modelingTools/vmodelingnormal.h b/tools/modelingTools/vmodelingnormal.h index 906aa797f..3d9062a0e 100644 --- a/tools/modelingTools/vmodelingnormal.h +++ b/tools/modelingTools/vmodelingnormal.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vmodelingnormal.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,41 +24,39 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef VMODELINGNORMAL_H #define VMODELINGNORMAL_H #include "vmodelinglinepoint.h" -#include "dialogs/dialognormal.h" +#include "../../dialogs/dialognormal.h" -class VModelingNormal : public VModelingLinePoint{ +class VModelingNormal : public VModelingLinePoint +{ Q_OBJECT public: - VModelingNormal(VDomDocument *doc, VContainer *data, const qint64 &id, - const QString &typeLine, const QString &formula, - const qreal &angle, const qint64 &firstPointId, - const qint64 &secondPointId, Tool::Sources typeCreation, - QGraphicsItem * parent = 0); - virtual void setDialog(); - static VModelingNormal* Create(QSharedPointer &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); + VModelingNormal(VDomDocument *doc, VContainer *data, const qint64 &id, + const QString &typeLine, const QString &formula, const qreal &angle, + const qint64 &firstPointId, const qint64 &secondPointId, + const Tool::Sources &typeCreation, QGraphicsItem * parent = 0); + virtual void setDialog(); + static VModelingNormal* Create(QSharedPointer &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, + const Tool::Sources &typeCreation); + static const QString ToolType; public slots: - virtual void FullUpdateFromFile(); - virtual void FullUpdateFromGui(int result); + virtual void FullUpdateFromFile(); + virtual void FullUpdateFromGui(int result); protected: - virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile(); - virtual void RemoveReferens(); + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void AddToFile(); + virtual void RemoveReferens(); private: - qint64 secondPointId; + qint64 secondPointId; QSharedPointer dialogNormal; }; diff --git a/tools/modelingTools/vmodelingpoint.cpp b/tools/modelingTools/vmodelingpoint.cpp index a6222e27b..af97dd218 100644 --- a/tools/modelingTools/vmodelingpoint.cpp +++ b/tools/modelingTools/vmodelingpoint.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vmodelingpoint.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,18 +24,16 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "vmodelingpoint.h" -#include -#include -#include -#include -#include "container/vpointf.h" +#include "../../container/vpointf.h" -VModelingPoint::VModelingPoint(VDomDocument *doc, VContainer *data, qint64 id, - QGraphicsItem *parent):VModelingTool(doc, data, id), - QGraphicsEllipseItem(parent), radius(toPixel(1.5)), namePoint(0), lineName(0){ +const QString VModelingPoint::TagName = QStringLiteral("point"); + +VModelingPoint::VModelingPoint(VDomDocument *doc, VContainer *data, qint64 id, QGraphicsItem *parent) + :VModelingTool(doc, data, id), QGraphicsEllipseItem(parent), radius(toPixel(1.5)), namePoint(0), lineName(0) +{ namePoint = new VGraphicsSimpleTextItem(this); lineName = new QGraphicsLineItem(this); connect(namePoint, &VGraphicsSimpleTextItem::NameChangePosition, this, @@ -40,7 +45,8 @@ VModelingPoint::VModelingPoint(VDomDocument *doc, VContainer *data, qint64 id, RefreshPointGeometry(VAbstractTool::data.GetModelingPoint(id)); } -void VModelingPoint::NameChangePosition(const QPointF pos){ +void VModelingPoint::NameChangePosition(const QPointF &pos) +{ VPointF point = VAbstractTool::data.GetModelingPoint(id); QPointF p = pos - this->pos(); point.setMx(p.x()); @@ -50,33 +56,40 @@ void VModelingPoint::NameChangePosition(const QPointF pos){ VAbstractTool::data.UpdatePoint(id, point); } -void VModelingPoint::UpdateNamePosition(qreal mx, qreal my){ +void VModelingPoint::UpdateNamePosition(qreal mx, qreal my) +{ QDomElement domElement = doc->elementById(QString().setNum(id)); - if(domElement.isElement()){ - domElement.setAttribute("mx", QString().setNum(toMM(mx))); - domElement.setAttribute("my", QString().setNum(toMM(my))); + if (domElement.isElement()) + { + domElement.setAttribute(AttrMx, QString().setNum(toMM(mx))); + domElement.setAttribute(AttrMy, QString().setNum(toMM(my))); emit toolhaveChange(); } } -void VModelingPoint::mouseReleaseEvent(QGraphicsSceneMouseEvent *event){ - if(event->button() == Qt::LeftButton){ +void VModelingPoint::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +{ + if (event->button() == Qt::LeftButton) + { emit ChoosedTool(id, Scene::Point); } QGraphicsItem::mouseReleaseEvent(event); } -void VModelingPoint::hoverMoveEvent(QGraphicsSceneHoverEvent *event){ +void VModelingPoint::hoverMoveEvent(QGraphicsSceneHoverEvent *event) +{ Q_UNUSED(event); this->setPen(QPen(currentColor, widthMainLine)); } -void VModelingPoint::hoverLeaveEvent(QGraphicsSceneHoverEvent *event){ +void VModelingPoint::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) +{ Q_UNUSED(event); this->setPen(QPen(currentColor, widthHairLine)); } -void VModelingPoint::RefreshPointGeometry(const VPointF &point){ +void VModelingPoint::RefreshPointGeometry(const VPointF &point) +{ QRectF rec = QRectF(0, 0, radius*2, radius*2); rec.translate(-rec.center().x(), -rec.center().y()); this->setRect(rec); @@ -90,18 +103,19 @@ void VModelingPoint::RefreshPointGeometry(const VPointF &point){ RefreshLine(); } -void VModelingPoint::RefreshLine(){ +void VModelingPoint::RefreshLine() +{ QRectF nameRec = namePoint->sceneBoundingRect(); QPointF p1, p2; LineIntersectCircle(QPointF(), radius, QLineF(QPointF(), nameRec.center()- scenePos()), p1, p2); QPointF pRec = LineIntersectRect(nameRec, QLineF(scenePos(), nameRec.center())); lineName->setLine(QLineF(p1, pRec - scenePos())); - if(QLineF(p1, pRec - scenePos()).length() <= toPixel(4)){ + if (QLineF(p1, pRec - scenePos()).length() <= toPixel(4)) + { lineName->setVisible(false); - } else { + } + else + { lineName->setVisible(true); } } - -VModelingPoint::~VModelingPoint(){ -} diff --git a/tools/modelingTools/vmodelingpoint.h b/tools/modelingTools/vmodelingpoint.h index e3bef5073..e03799136 100644 --- a/tools/modelingTools/vmodelingpoint.h +++ b/tools/modelingTools/vmodelingpoint.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vmodelingpoint.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,22 +24,23 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef VMODELINGPOINT_H #define VMODELINGPOINT_H #include "vmodelingtool.h" -#include "widgets/vgraphicssimpletextitem.h" +#include "../../widgets/vgraphicssimpletextitem.h" -class VModelingPoint: public VModelingTool, public QGraphicsEllipseItem{ +class VModelingPoint: public VModelingTool, public QGraphicsEllipseItem +{ Q_OBJECT public: - VModelingPoint(VDomDocument *doc, VContainer *data, qint64 id, - QGraphicsItem * parent = 0); - virtual ~VModelingPoint(); + VModelingPoint(VDomDocument *doc, VContainer *data, qint64 id, QGraphicsItem * parent = 0); + virtual ~VModelingPoint() {} + static const QString TagName; public slots: - void NameChangePosition(const QPointF pos); + void NameChangePosition(const QPointF &pos); virtual void FullUpdateFromGui(int result) = 0; protected: qreal radius; diff --git a/tools/modelingTools/vmodelingpointofcontact.cpp b/tools/modelingTools/vmodelingpointofcontact.cpp index 35d6e9c2e..9c4ba59b0 100644 --- a/tools/modelingTools/vmodelingpointofcontact.cpp +++ b/tools/modelingTools/vmodelingpointofcontact.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vmodelingpointofcontact.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,58 +24,41 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "vmodelingpointofcontact.h" +#include "../drawTools/vtoolpointofcontact.h" +#include "../../container/calculator.h" + +const QString VModelingPointOfContact::ToolType = QStringLiteral("pointOfContact"); VModelingPointOfContact::VModelingPointOfContact(VDomDocument *doc, VContainer *data, const qint64 &id, - const QString &radius, const qint64 ¢er, - const qint64 &firstPointId, const qint64 &secondPointId, - Tool::Sources typeCreation, QGraphicsItem *parent) + const QString &radius, const qint64 ¢er, + const qint64 &firstPointId, const qint64 &secondPointId, + const Tool::Sources &typeCreation, QGraphicsItem *parent) : VModelingPoint(doc, data, id, parent), radius(radius), center(center), firstPointId(firstPointId), - secondPointId(secondPointId), dialogPointOfContact(QSharedPointer()){ - - if(typeCreation == Tool::FromGui){ + secondPointId(secondPointId), dialogPointOfContact(QSharedPointer()) +{ + if (typeCreation == Tool::FromGui) + { AddToFile(); } } -void VModelingPointOfContact::setDialog(){ - Q_ASSERT(!dialogPointOfContact.isNull()); - if(!dialogPointOfContact.isNull()){ - VPointF p = VAbstractTool::data.GetModelingPoint(id); - dialogPointOfContact->setRadius(radius); - dialogPointOfContact->setCenter(center, id); - dialogPointOfContact->setFirstPoint(firstPointId, id); - dialogPointOfContact->setSecondPoint(secondPointId, id); - dialogPointOfContact->setPointName(p.name()); - } -} - -QPointF VModelingPointOfContact::FindPoint(const qreal &radius, const QPointF ¢er, 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(distanssetRadius(radius); + dialogPointOfContact->setCenter(center, id); + dialogPointOfContact->setFirstPoint(firstPointId, id); + dialogPointOfContact->setSecondPoint(secondPointId, id); + dialogPointOfContact->setPointName(p.name()); } VModelingPointOfContact *VModelingPointOfContact::Create(QSharedPointer &dialog, - VDomDocument *doc, VContainer *data){ + VDomDocument *doc, VContainer *data) +{ QString radius = dialog->getRadius(); qint64 center = dialog->getCenter(); qint64 firstPointId = dialog->getFirstPoint(); @@ -84,7 +74,8 @@ VModelingPointOfContact *VModelingPointOfContact::Create(const qint64 _id, const const QString &pointName, const qreal &mx, const qreal &my, VDomDocument *doc, VContainer *data, const Document::Documents &parse, - Tool::Sources typeCreation){ + const Tool::Sources &typeCreation) +{ VModelingPointOfContact *point = 0; VPointF centerP = data->GetModelingPoint(center); VPointF firstP = data->GetModelingPoint(firstPointId); @@ -93,19 +84,25 @@ VModelingPointOfContact *VModelingPointOfContact::Create(const qint64 _id, const Calculator cal(data); QString errorMsg; qreal result = cal.eval(radius, &errorMsg); - if(errorMsg.isEmpty()){ - QPointF fPoint = VModelingPointOfContact::FindPoint(result*PrintDPI/25.4, centerP.toQPointF(), - firstP.toQPointF(), secondP.toQPointF()); + if (errorMsg.isEmpty()) + { + QPointF fPoint = VToolPointOfContact::FindPoint(toPixel(result), centerP.toQPointF(), + firstP.toQPointF(), secondP.toQPointF()); qint64 id = _id; - if(typeCreation == Tool::FromGui){ + if (typeCreation == Tool::FromGui) + { id = data->AddModelingPoint(VPointF(fPoint.x(), fPoint.y(), pointName, mx, my)); - } else { + } + else + { data->UpdateModelingPoint(id, VPointF(fPoint.x(), fPoint.y(), pointName, mx, my)); - if(parse != Document::FullParse){ + if (parse != Document::FullParse) + { doc->UpdateToolData(id, data); } } - if(parse == Document::FullParse){ + if (parse == Document::FullParse) + { point = new VModelingPointOfContact(doc, data, id, radius, center, firstPointId, secondPointId, typeCreation); doc->AddTool(id, point); @@ -117,55 +114,63 @@ VModelingPointOfContact *VModelingPointOfContact::Create(const qint64 _id, const return point; } -void VModelingPointOfContact::FullUpdateFromFile(){ +void VModelingPointOfContact::FullUpdateFromFile() +{ QDomElement domElement = doc->elementById(QString().setNum(id)); - if(domElement.isElement()){ - radius = domElement.attribute("radius", ""); - center = domElement.attribute("center", "").toLongLong(); - firstPointId = domElement.attribute("firstPoint", "").toLongLong(); - secondPointId = domElement.attribute("secondPoint", "").toLongLong(); + if (domElement.isElement()) + { + radius = domElement.attribute(AttrRadius, ""); + center = domElement.attribute(AttrCenter, "").toLongLong(); + firstPointId = domElement.attribute(AttrFirstPoint, "").toLongLong(); + secondPointId = domElement.attribute(AttrSecondPoint, "").toLongLong(); } RefreshPointGeometry(VAbstractTool::data.GetModelingPoint(id)); } -void VModelingPointOfContact::FullUpdateFromGui(int result){ - if(result == QDialog::Accepted){ +void VModelingPointOfContact::FullUpdateFromGui(int result) +{ + if (result == QDialog::Accepted) + { QDomElement domElement = doc->elementById(QString().setNum(id)); - if(domElement.isElement()){ - domElement.setAttribute("name", dialogPointOfContact->getPointName()); - domElement.setAttribute("radius", dialogPointOfContact->getRadius()); - domElement.setAttribute("center", QString().setNum(dialogPointOfContact->getCenter())); - domElement.setAttribute("firstPoint", QString().setNum(dialogPointOfContact->getFirstPoint())); - domElement.setAttribute("secondPoint", QString().setNum(dialogPointOfContact->getSecondPoint())); + if (domElement.isElement()) + { + domElement.setAttribute(AttrName, dialogPointOfContact->getPointName()); + domElement.setAttribute(AttrRadius, dialogPointOfContact->getRadius()); + domElement.setAttribute(AttrCenter, QString().setNum(dialogPointOfContact->getCenter())); + domElement.setAttribute(AttrFirstPoint, QString().setNum(dialogPointOfContact->getFirstPoint())); + domElement.setAttribute(AttrSecondPoint, QString().setNum(dialogPointOfContact->getSecondPoint())); emit FullUpdateTree(); } } dialogPointOfContact.clear(); } -void VModelingPointOfContact::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ +void VModelingPointOfContact::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) +{ ContextMenu(dialogPointOfContact, this, event); } -void VModelingPointOfContact::AddToFile(){ +void VModelingPointOfContact::AddToFile() +{ VPointF point = VAbstractTool::data.GetModelingPoint(id); - QDomElement domElement = doc->createElement("point"); + QDomElement domElement = doc->createElement(TagName); - AddAttribute(domElement, "id", id); - AddAttribute(domElement, "type", "pointOfContact"); - AddAttribute(domElement, "name", point.name()); - AddAttribute(domElement, "mx", point.mx()/PrintDPI*25.4); - AddAttribute(domElement, "my", point.my()/PrintDPI*25.4); + AddAttribute(domElement, AttrId, id); + AddAttribute(domElement, AttrType, ToolType); + AddAttribute(domElement, AttrName, point.name()); + AddAttribute(domElement, AttrMx, toMM(point.mx())); + AddAttribute(domElement, AttrMy, toMM(point.my())); - AddAttribute(domElement, "radius", radius); - AddAttribute(domElement, "center", center); - AddAttribute(domElement, "firstPoint", firstPointId); - AddAttribute(domElement, "secondPoint", secondPointId); + AddAttribute(domElement, AttrRadius, radius); + AddAttribute(domElement, AttrCenter, center); + AddAttribute(domElement, AttrFirstPoint, firstPointId); + AddAttribute(domElement, AttrSecondPoint, secondPointId); AddToModeling(domElement); } -void VModelingPointOfContact::RemoveReferens(){ +void VModelingPointOfContact::RemoveReferens() +{ doc->DecrementReferens(center); doc->DecrementReferens(firstPointId); doc->DecrementReferens(secondPointId); diff --git a/tools/modelingTools/vmodelingpointofcontact.h b/tools/modelingTools/vmodelingpointofcontact.h index 02302bc45..d9be2cda2 100644 --- a/tools/modelingTools/vmodelingpointofcontact.h +++ b/tools/modelingTools/vmodelingpointofcontact.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vmodelingpointofcontact.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,46 +24,44 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef VMODELINGPOINTOFCONTACT_H #define VMODELINGPOINTOFCONTACT_H #include "vmodelingpoint.h" -#include "dialogs/dialogpointofcontact.h" +#include "../../dialogs/dialogpointofcontact.h" -class VModelingPointOfContact : public VModelingPoint{ +class VModelingPointOfContact : public VModelingPoint +{ Q_OBJECT public: - VModelingPointOfContact(VDomDocument *doc, VContainer *data, - const qint64 &id, const QString &radius, - const qint64 ¢er, - const qint64 &firstPointId, - const qint64 &secondPointId, - Tool::Sources typeCreation, - QGraphicsItem * parent = 0); - virtual void setDialog(); - static QPointF FindPoint(const qreal &radius, const QPointF ¢er, - const QPointF &firstPoint, const QPointF &secondPoint); - static VModelingPointOfContact* Create(QSharedPointer &dialog, - VDomDocument *doc, VContainer *data); - static VModelingPointOfContact* Create(const qint64 _id, const QString &radius, const qint64 ¢er, - const qint64 &firstPointId, const qint64 &secondPointId, - const QString &pointName, const qreal &mx, const qreal &my, - VDomDocument *doc, VContainer *data, - const Document::Documents &parse, Tool::Sources typeCreation); + VModelingPointOfContact(VDomDocument *doc, VContainer *data, const qint64 &id, + const QString &radius, const qint64 ¢er, + const qint64 &firstPointId, const qint64 &secondPointId, + const Tool::Sources &typeCreation, + QGraphicsItem * parent = 0); + virtual void setDialog(); + static VModelingPointOfContact* Create(QSharedPointer &dialog, VDomDocument *doc, + VContainer *data); + static VModelingPointOfContact* Create(const qint64 _id, const QString &radius, const qint64 ¢er, + const qint64 &firstPointId, const qint64 &secondPointId, + const QString &pointName, const qreal &mx, const qreal &my, + VDomDocument *doc, VContainer *data, + const Document::Documents &parse, const Tool::Sources &typeCreation); + static const QString ToolType; public slots: - virtual void FullUpdateFromFile(); - virtual void FullUpdateFromGui(int result); + virtual void FullUpdateFromFile(); + virtual void FullUpdateFromGui(int result); protected: - virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile(); - virtual void RemoveReferens(); + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void AddToFile(); + virtual void RemoveReferens(); private: - QString radius; - qint64 center; - qint64 firstPointId; - qint64 secondPointId; + QString radius; + qint64 center; + qint64 firstPointId; + qint64 secondPointId; QSharedPointer dialogPointOfContact; }; diff --git a/tools/modelingTools/vmodelingpointofintersection.cpp b/tools/modelingTools/vmodelingpointofintersection.cpp new file mode 100644 index 000000000..cfa4006d7 --- /dev/null +++ b/tools/modelingTools/vmodelingpointofintersection.cpp @@ -0,0 +1,152 @@ +/************************************************************************ + ** + ** @file vmodelingpointofintersection.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "vmodelingpointofintersection.h" + +const QString VModelingPointOfIntersection::ToolType = QStringLiteral("pointOfIntersection"); + +VModelingPointOfIntersection::VModelingPointOfIntersection(VDomDocument *doc, VContainer *data, const qint64 &id, + const qint64 &firstPointId, const qint64 &secondPointId, + const Tool::Sources &typeCreation, QGraphicsItem *parent) + :VModelingPoint(doc, data, id, parent), firstPointId(firstPointId), secondPointId(secondPointId), + dialogPointOfIntersection(QSharedPointer()) +{ + ignoreFullUpdate = true; + if (typeCreation == Tool::FromGui) + { + AddToFile(); + } +} + +void VModelingPointOfIntersection::setDialog() +{ + Q_ASSERT(dialogPointOfIntersection.isNull() == false); + VPointF p = VAbstractTool::data.GetPoint(id); + dialogPointOfIntersection->setFirstPointId(firstPointId, id); + dialogPointOfIntersection->setSecondPointId(secondPointId, id); + dialogPointOfIntersection->setPointName(p.name()); +} + +VModelingPointOfIntersection *VModelingPointOfIntersection::Create(QSharedPointer &dialog, + VDomDocument *doc, VContainer *data) +{ + qint64 firstPointId = dialog->getFirstPointId(); + qint64 secondPointId = dialog->getSecondPointId(); + QString pointName = dialog->getPointName(); + return Create(0, pointName, firstPointId, secondPointId, 5, 10, doc, data, Document::FullParse, Tool::FromGui); +} + +VModelingPointOfIntersection *VModelingPointOfIntersection::Create(const qint64 _id, const QString &pointName, + const qint64 &firstPointId, + const qint64 &secondPointId, const qreal &mx, + const qreal &my, VDomDocument *doc, + VContainer *data, const Document::Documents &parse, + const Tool::Sources &typeCreation) +{ + VModelingPointOfIntersection *tool = 0; + VPointF firstPoint = data->GetPoint(firstPointId); + VPointF secondPoint = data->GetPoint(secondPointId); + + QPointF point(firstPoint.x(), secondPoint.y()); + qint64 id = _id; + if (typeCreation == Tool::FromGui) + { + id = data->AddPoint(VPointF(point.x(), point.y(), pointName, mx, my)); + } + else + { + data->UpdatePoint(id, VPointF(point.x(), point.y(), pointName, mx, my)); + if (parse != Document::FullParse) + { + doc->UpdateToolData(id, data); + } + } + if (parse == Document::FullParse) + { + tool = new VModelingPointOfIntersection(doc, data, id, firstPointId, secondPointId, typeCreation); + doc->AddTool(id, tool); + doc->IncrementReferens(firstPointId); + doc->IncrementReferens(secondPointId); + } + return tool; +} + +void VModelingPointOfIntersection::FullUpdateFromFile() +{ + QDomElement domElement = doc->elementById(QString().setNum(id)); + if (domElement.isElement()) + { + firstPointId = domElement.attribute(AttrFirstPoint, "").toLongLong(); + secondPointId = domElement.attribute(AttrSecondPoint, "").toLongLong(); + } + VModelingPoint::RefreshPointGeometry(VModelingTool::data.GetPoint(id)); +} + +void VModelingPointOfIntersection::FullUpdateFromGui(int result) +{ + if (result == QDialog::Accepted) + { + QDomElement domElement = doc->elementById(QString().setNum(id)); + if (domElement.isElement()) + { + domElement.setAttribute(AttrName, dialogPointOfIntersection->getPointName()); + domElement.setAttribute(AttrFirstPoint, QString().setNum(dialogPointOfIntersection->getFirstPointId())); + domElement.setAttribute(AttrSecondPoint, QString().setNum(dialogPointOfIntersection->getSecondPointId())); + emit FullUpdateTree(); + } + } + dialogPointOfIntersection.clear(); +} + +void VModelingPointOfIntersection::RemoveReferens() +{ + doc->DecrementReferens(firstPointId); + doc->DecrementReferens(secondPointId); +} + +void VModelingPointOfIntersection::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) +{ + ContextMenu(dialogPointOfIntersection, this, event); +} + +void VModelingPointOfIntersection::AddToFile() +{ + VPointF point = VAbstractTool::data.GetPoint(id); + QDomElement domElement = doc->createElement(TagName); + + AddAttribute(domElement, AttrId, id); + AddAttribute(domElement, AttrType, ToolType); + AddAttribute(domElement, AttrName, point.name()); + AddAttribute(domElement, AttrMx, toMM(point.mx())); + AddAttribute(domElement, AttrMy, toMM(point.my())); + + AddAttribute(domElement, AttrFirstPoint, firstPointId); + AddAttribute(domElement, AttrSecondPoint, secondPointId); + + AddToModeling(domElement); +} diff --git a/tools/modelingTools/vmodelingpointofintersection.h b/tools/modelingTools/vmodelingpointofintersection.h new file mode 100644 index 000000000..4a859ea84 --- /dev/null +++ b/tools/modelingTools/vmodelingpointofintersection.h @@ -0,0 +1,65 @@ +/************************************************************************ + ** + ** @file vmodelingpointofintersection.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef VMODELINGPOINTOFINTERSECTION_H +#define VMODELINGPOINTOFINTERSECTION_H + +#include "vmodelingpoint.h" +#include "../../dialogs/dialogpointofintersection.h" + +class VModelingPointOfIntersection : public VModelingPoint +{ + Q_OBJECT +public: + VModelingPointOfIntersection(VDomDocument *doc, VContainer *data, const qint64 &id, + const qint64 &firstPointId, const qint64 &secondPointId, + const Tool::Sources &typeCreation, QGraphicsItem * parent = 0); + virtual void setDialog(); + static VModelingPointOfIntersection* Create(QSharedPointer &dialog, VDomDocument *doc, + VContainer *data); + static VModelingPointOfIntersection* Create(const qint64 _id, const QString &pointName, + const qint64 &firstPointId, const qint64 &secondPointId, + const qreal &mx, const qreal &my, VDomDocument *doc, + VContainer *data, const Document::Documents &parse, + const Tool::Sources &typeCreation); + static const QString ToolType; +public slots: + virtual void FullUpdateFromFile(); + virtual void FullUpdateFromGui(int result); +protected: + virtual void RemoveReferens(); + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void AddToFile(); +private: + Q_DISABLE_COPY(VModelingPointOfIntersection) + qint64 firstPointId; + qint64 secondPointId; + QSharedPointer dialogPointOfIntersection; +}; + +#endif // VMODELINGPOINTOFINTERSECTION_H diff --git a/tools/modelingTools/vmodelingshoulderpoint.cpp b/tools/modelingTools/vmodelingshoulderpoint.cpp index d96b5ccdf..ceec80d1b 100644 --- a/tools/modelingTools/vmodelingshoulderpoint.cpp +++ b/tools/modelingTools/vmodelingshoulderpoint.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vmodelingshoulderpoint.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,60 +24,42 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "vmodelingshoulderpoint.h" -#include +#include "../drawTools/vtoolshoulderpoint.h" +#include "../../container/calculator.h" + +const QString VModelingShoulderPoint::ToolType = QStringLiteral("shoulder"); VModelingShoulderPoint::VModelingShoulderPoint(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &typeLine, const QString &formula, const qint64 &p1Line, - const qint64 &p2Line, const qint64 &pShoulder, Tool::Sources typeCreation, - QGraphicsItem * parent): - VModelingLinePoint(doc, data, id, typeLine, formula, p1Line, 0, parent), p2Line(p2Line), - pShoulder(pShoulder), dialogShoulderPoint(QSharedPointer()){ - - if(typeCreation == Tool::FromGui){ + const qint64 &p2Line, const qint64 &pShoulder, const Tool::Sources &typeCreation, + QGraphicsItem * parent) + :VModelingLinePoint(doc, data, id, typeLine, formula, p1Line, 0, parent), p2Line(p2Line), + pShoulder(pShoulder), dialogShoulderPoint(QSharedPointer()) +{ + if (typeCreation == Tool::FromGui) + { AddToFile(); } - } -void VModelingShoulderPoint::setDialog(){ - Q_ASSERT(!dialogShoulderPoint.isNull()); - if(!dialogShoulderPoint.isNull()){ - VPointF p = VAbstractTool::data.GetModelingPoint(id); - dialogShoulderPoint->setTypeLine(typeLine); - dialogShoulderPoint->setFormula(formula); - dialogShoulderPoint->setP1Line(basePointId, id); - dialogShoulderPoint->setP2Line(p2Line, id); - dialogShoulderPoint->setPShoulder(pShoulder, id); - dialogShoulderPoint->setPointName(p.name()); - } -} - -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){ - return line.p2(); - } - } +void VModelingShoulderPoint::setDialog() +{ + Q_ASSERT(dialogShoulderPoint.isNull() == false); + VPointF p = VAbstractTool::data.GetModelingPoint(id); + dialogShoulderPoint->setTypeLine(typeLine); + dialogShoulderPoint->setFormula(formula); + dialogShoulderPoint->setP1Line(basePointId, id); + dialogShoulderPoint->setP2Line(p2Line, id); + dialogShoulderPoint->setPShoulder(pShoulder, id); + dialogShoulderPoint->setPointName(p.name()); } VModelingShoulderPoint *VModelingShoulderPoint::Create(QSharedPointer &dialog, - VDomDocument *doc, VContainer *data){ + VDomDocument *doc, VContainer *data) +{ QString formula = dialog->getFormula(); qint64 p1Line = dialog->getP1Line(); qint64 p2Line = dialog->getP2Line(); @@ -87,7 +76,8 @@ VModelingShoulderPoint *VModelingShoulderPoint::Create(const qint64 _id, const Q const QString &pointName, const qreal &mx, const qreal &my, VDomDocument *doc, VContainer *data, const Document::Documents &parse, - const Tool::Sources &typeCreation){ + const Tool::Sources &typeCreation) +{ VModelingShoulderPoint *point = 0; VPointF firstPoint = data->GetModelingPoint(p1Line); VPointF secondPoint = data->GetModelingPoint(p2Line); @@ -96,21 +86,27 @@ VModelingShoulderPoint *VModelingShoulderPoint::Create(const qint64 _id, const Q Calculator cal(data); 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); + if (errorMsg.isEmpty()) + { + QPointF fPoint = VToolShoulderPoint::FindPoint(firstPoint.toQPointF(), secondPoint.toQPointF(), + shoulderPoint.toQPointF(), toPixel(result)); qint64 id = _id; - if(typeCreation == Tool::FromGui){ + if (typeCreation == Tool::FromGui) + { id = data->AddModelingPoint(VPointF(fPoint.x(), fPoint.y(), pointName, mx, my)); - } else { - data->UpdateModelingPoint(id,VPointF(fPoint.x(), fPoint.y(), pointName, mx, my)); - if(parse != Document::FullParse){ + } + else + { + data->UpdateModelingPoint(id, VPointF(fPoint.x(), fPoint.y(), pointName, mx, my)); + if (parse != Document::FullParse) + { doc->UpdateToolData(id, data); } } data->AddLine(p1Line, id, Draw::Modeling); data->AddLine(p2Line, id, Draw::Modeling); - if(parse == Document::FullParse){ + if (parse == Document::FullParse) + { point = new VModelingShoulderPoint(doc, data, id, typeLine, formula, p1Line, p2Line, pShoulder, typeCreation); doc->AddTool(id, point); @@ -122,58 +118,66 @@ VModelingShoulderPoint *VModelingShoulderPoint::Create(const qint64 _id, const Q return point; } -void VModelingShoulderPoint::FullUpdateFromFile(){ +void VModelingShoulderPoint::FullUpdateFromFile() +{ QDomElement domElement = doc->elementById(QString().setNum(id)); - if(domElement.isElement()){ - typeLine = domElement.attribute("typeLine", ""); - formula = domElement.attribute("length", ""); - basePointId = domElement.attribute("p1Line", "").toLongLong(); - p2Line = domElement.attribute("p2Line", "").toLongLong(); - pShoulder = domElement.attribute("pShoulder", "").toLongLong(); + if (domElement.isElement()) + { + typeLine = domElement.attribute(AttrTypeLine, ""); + formula = domElement.attribute(AttrLength, ""); + basePointId = domElement.attribute(AttrP1Line, "").toLongLong(); + p2Line = domElement.attribute(AttrP2Line, "").toLongLong(); + pShoulder = domElement.attribute(AttrPShoulder, "").toLongLong(); } RefreshGeometry(); } -void VModelingShoulderPoint::FullUpdateFromGui(int result){ - if(result == QDialog::Accepted){ +void VModelingShoulderPoint::FullUpdateFromGui(int result) +{ + if (result == QDialog::Accepted) + { QDomElement domElement = doc->elementById(QString().setNum(id)); - if(domElement.isElement()){ - domElement.setAttribute("name", dialogShoulderPoint->getPointName()); - domElement.setAttribute("typeLine", dialogShoulderPoint->getTypeLine()); - domElement.setAttribute("length", dialogShoulderPoint->getFormula()); - domElement.setAttribute("p1Line", QString().setNum(dialogShoulderPoint->getP1Line())); - domElement.setAttribute("p2Line", QString().setNum(dialogShoulderPoint->getP2Line())); - domElement.setAttribute("pShoulder", QString().setNum(dialogShoulderPoint->getPShoulder())); + if (domElement.isElement()) + { + domElement.setAttribute(AttrName, dialogShoulderPoint->getPointName()); + domElement.setAttribute(AttrTypeLine, dialogShoulderPoint->getTypeLine()); + domElement.setAttribute(AttrLength, dialogShoulderPoint->getFormula()); + domElement.setAttribute(AttrP1Line, QString().setNum(dialogShoulderPoint->getP1Line())); + domElement.setAttribute(AttrP2Line, QString().setNum(dialogShoulderPoint->getP2Line())); + domElement.setAttribute(AttrPShoulder, QString().setNum(dialogShoulderPoint->getPShoulder())); emit FullUpdateTree(); } } dialogShoulderPoint.clear(); } -void VModelingShoulderPoint::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ +void VModelingShoulderPoint::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) +{ ContextMenu(dialogShoulderPoint, this, event); } -void VModelingShoulderPoint::AddToFile(){ +void VModelingShoulderPoint::AddToFile() +{ VPointF point = VAbstractTool::data.GetModelingPoint(id); - QDomElement domElement = doc->createElement("point"); + QDomElement domElement = doc->createElement(TagName); - AddAttribute(domElement, "id", id); - AddAttribute(domElement, "type", "shoulder"); - AddAttribute(domElement, "name", point.name()); - AddAttribute(domElement, "mx", point.mx()/PrintDPI*25.4); - AddAttribute(domElement, "my", point.my()/PrintDPI*25.4); + AddAttribute(domElement, AttrId, id); + AddAttribute(domElement, AttrType, ToolType); + AddAttribute(domElement, AttrName, point.name()); + AddAttribute(domElement, AttrMx, toMM(point.mx())); + AddAttribute(domElement, AttrMy, toMM(point.my())); - AddAttribute(domElement, "typeLine", typeLine); - AddAttribute(domElement, "length", formula); - AddAttribute(domElement, "p1Line", basePointId); - AddAttribute(domElement, "p2Line", p2Line); - AddAttribute(domElement, "pShoulder", pShoulder); + AddAttribute(domElement, AttrTypeLine, typeLine); + AddAttribute(domElement, AttrLength, formula); + AddAttribute(domElement, AttrP1Line, basePointId); + AddAttribute(domElement, AttrP2Line, p2Line); + AddAttribute(domElement, AttrPShoulder, pShoulder); AddToModeling(domElement); } -void VModelingShoulderPoint::RemoveReferens(){ +void VModelingShoulderPoint::RemoveReferens() +{ doc->DecrementReferens(p2Line); doc->DecrementReferens(pShoulder); VModelingLinePoint::RemoveReferens(); diff --git a/tools/modelingTools/vmodelingshoulderpoint.h b/tools/modelingTools/vmodelingshoulderpoint.h index 399c95868..7b9d27027 100644 --- a/tools/modelingTools/vmodelingshoulderpoint.h +++ b/tools/modelingTools/vmodelingshoulderpoint.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vmodelingshoulderpoint.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,44 +24,41 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef VMODELINGSHOULDERPOINT_H #define VMODELINGSHOULDERPOINT_H #include "vmodelinglinepoint.h" -#include "dialogs/dialogshoulderpoint.h" +#include "../../dialogs/dialogshoulderpoint.h" -class VModelingShoulderPoint : public VModelingLinePoint{ +class VModelingShoulderPoint : public VModelingLinePoint +{ Q_OBJECT public: - VModelingShoulderPoint(VDomDocument *doc, VContainer *data, - const qint64 &id, const QString &typeLine, - const QString &formula, const qint64 &p1Line, - const qint64 &p2Line, const qint64 &pShoulder, - 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 &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); + VModelingShoulderPoint(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &typeLine, + const QString &formula, const qint64 &p1Line, const qint64 &p2Line, + const qint64 &pShoulder, const Tool::Sources &typeCreation, + QGraphicsItem * parent = 0); + virtual void setDialog(); + static VModelingShoulderPoint* Create(QSharedPointer &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); + static const QString ToolType; public slots: - virtual void FullUpdateFromFile(); - virtual void FullUpdateFromGui(int result); + virtual void FullUpdateFromFile(); + virtual void FullUpdateFromGui(int result); protected: - virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile(); - virtual void RemoveReferens(); + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void AddToFile(); + virtual void RemoveReferens(); private: - qint64 p2Line; - qint64 pShoulder; + qint64 p2Line; + qint64 pShoulder; QSharedPointer dialogShoulderPoint; }; diff --git a/tools/modelingTools/vmodelingsinglepoint.cpp b/tools/modelingTools/vmodelingsinglepoint.cpp deleted file mode 100644 index df9b1f0f5..000000000 --- a/tools/modelingTools/vmodelingsinglepoint.cpp +++ /dev/null @@ -1,93 +0,0 @@ -#include "vmodelingsinglepoint.h" -#include -#include -#include -#include -#include -#include -#include -#include "options.h" -#include "container/vpointf.h" - -VModelingSinglePoint::VModelingSinglePoint (VDomDocument *doc, VContainer *data, qint64 id, Tool::Sources typeCreation, - QGraphicsItem * parent ):VModelingPoint(doc, data, id, parent), - dialogSinglePoint(QSharedPointer()){ - this->setFlag(QGraphicsItem::ItemIsMovable, true); - this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); - if(typeCreation == Tool::FromGui){ - AddToFile(); - } -} - -void VModelingSinglePoint::setDialog(){ - Q_ASSERT(!dialogSinglePoint.isNull()); - if(!dialogSinglePoint.isNull()){ - VPointF p = VAbstractTool::data.GetPoint(id); - dialogSinglePoint->setData(p.name(), p.toQPointF()); - } -} - -void VModelingSinglePoint::AddToFile(){ - VPointF point = VAbstractTool::data.GetPoint(id); - QDomElement domElement = doc->createElement("point"); - - AddAttribute(domElement, "id", id); - AddAttribute(domElement, "type", "single"); - AddAttribute(domElement, "name", point.name()); - AddAttribute(domElement, "x", toMM(point.x())); - AddAttribute(domElement, "y", toMM(point.y())); - AddAttribute(domElement, "mx", toMM(point.mx())); - AddAttribute(domElement, "my", toMM(point.my())); - - AddToModeling(domElement); -} - -QVariant VModelingSinglePoint::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value){ - if (change == ItemPositionChange && scene()) { - // value - это новое положение. - QPointF newPos = value.toPointF(); - QRectF rect = scene()->sceneRect(); - if (!rect.contains(newPos)) { - // Сохраняем элемент внутри прямоугольника сцены. - newPos.setX(qMin(rect.right(), qMax(newPos.x(), rect.left()))); - newPos.setY(qMin(rect.bottom(), qMax(newPos.y(), rect.top()))); - return newPos; - } - } - if (change == ItemPositionHasChanged && scene()) { - // value - это новое положение. - QPointF newPos = value.toPointF(); - QDomElement domElement = doc->elementById(QString().setNum(id)); - if(domElement.isElement()){ - domElement.setAttribute("x", QString().setNum(toMM(newPos.x()))); - domElement.setAttribute("y", QString().setNum(toMM(newPos.y()))); - //I don't now why but signal does not work. - doc->FullUpdateTree(); - } - } - return QGraphicsItem::itemChange(change, value); -} - -void VModelingSinglePoint::contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ){ - ContextMenu(dialogSinglePoint, this, event, false); -} - -void VModelingSinglePoint::FullUpdateFromFile(){ - RefreshPointGeometry(VAbstractTool::data.GetPoint(id)); -} - -void VModelingSinglePoint::FullUpdateFromGui(int result){ - if(result == QDialog::Accepted){ - QPointF p = dialogSinglePoint->getPoint(); - QString name = dialogSinglePoint->getName(); - QDomElement domElement = doc->elementById(QString().setNum(id)); - if(domElement.isElement()){ - domElement.setAttribute("name", name); - domElement.setAttribute("x", QString().setNum(toMM(p.x()))); - domElement.setAttribute("y", QString().setNum(toMM(p.y()))); - //I don't now why but signal does not work. - doc->FullUpdateTree(); - } - } - dialogSinglePoint.clear(); -} diff --git a/tools/modelingTools/vmodelingsinglepoint.h b/tools/modelingTools/vmodelingsinglepoint.h deleted file mode 100644 index 0695becb3..000000000 --- a/tools/modelingTools/vmodelingsinglepoint.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef VMODELINGSINGLEPOINT_H -#define VMODELINGSINGLEPOINT_H - -#include "container/vcontainer.h" -#include "xml/vdomdocument.h" -#include "dialogs/dialogsinglepoint.h" -#include "vmodelingpoint.h" - -class VModelingSinglePoint : public VModelingPoint -{ - Q_OBJECT -public: - VModelingSinglePoint (VDomDocument *doc, VContainer *data, qint64 id, - Tool::Sources typeCreation, QGraphicsItem * parent = 0 ); - virtual void setDialog(); -public slots: - virtual void FullUpdateFromFile(); - virtual void FullUpdateFromGui(int result); -signals: - void FullUpdateTree(); -protected: - virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile(); - QVariant itemChange ( GraphicsItemChange change, const QVariant &value ); -private: - QSharedPointer dialogSinglePoint; -}; - -#endif // VMODELINGSINGLEPOINT_H diff --git a/tools/modelingTools/vmodelingspline.cpp b/tools/modelingTools/vmodelingspline.cpp index ddefbc81d..951bc7efc 100644 --- a/tools/modelingTools/vmodelingspline.cpp +++ b/tools/modelingTools/vmodelingspline.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vmodelingspline.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,19 +24,20 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "vmodelingspline.h" -#include -#include -#include "geometry/vspline.h" +#include "../../geometry/vspline.h" +const QString VModelingSpline::TagName = QStringLiteral("spline"); +const QString VModelingSpline::ToolType = QStringLiteral("simple"); -VModelingSpline::VModelingSpline(VDomDocument *doc, VContainer *data, qint64 id, - Tool::Sources typeCreation, - QGraphicsItem *parent):VModelingTool(doc, data, id), QGraphicsPathItem(parent), - dialogSpline(QSharedPointer()), controlPoints(QVector()){ - +VModelingSpline::VModelingSpline(VDomDocument *doc, VContainer *data, qint64 id, const Tool::Sources &typeCreation, + QGraphicsItem *parent) + :VModelingTool(doc, data, id), QGraphicsPathItem(parent), + dialogSpline(QSharedPointer()), controlPoints(QVector()) +{ + ignoreFullUpdate = true; VSpline spl = data->GetModelingSpline(id); QPainterPath path; path.addPath(spl.GetPath()); @@ -55,27 +63,27 @@ VModelingSpline::VModelingSpline(VDomDocument *doc, VContainer *data, qint64 id, connect(this, &VModelingSpline::setEnabledPoint, controlPoint2, &VControlPointSpline::setEnabledPoint); controlPoints.append(controlPoint2); - if(typeCreation == Tool::FromGui){ + if (typeCreation == Tool::FromGui) + { AddToFile(); } } -void VModelingSpline::setDialog(){ - Q_ASSERT(!dialogSpline.isNull()); - if(!dialogSpline.isNull()){ - VSpline spl = VAbstractTool::data.GetModelingSpline(id); - dialogSpline->setP1(spl.GetP1()); - dialogSpline->setP4(spl.GetP4()); - dialogSpline->setAngle1(spl.GetAngle1()); - dialogSpline->setAngle2(spl.GetAngle2()); - dialogSpline->setKAsm1(spl.GetKasm1()); - dialogSpline->setKAsm2(spl.GetKasm2()); - dialogSpline->setKCurve(spl.GetKcurve()); - } +void VModelingSpline::setDialog() +{ + Q_ASSERT(dialogSpline.isNull() == false); + VSpline spl = VAbstractTool::data.GetModelingSpline(id); + dialogSpline->setP1(spl.GetP1()); + dialogSpline->setP4(spl.GetP4()); + dialogSpline->setAngle1(spl.GetAngle1()); + dialogSpline->setAngle2(spl.GetAngle2()); + dialogSpline->setKAsm1(spl.GetKasm1()); + dialogSpline->setKAsm2(spl.GetKasm2()); + dialogSpline->setKCurve(spl.GetKcurve()); } -VModelingSpline *VModelingSpline::Create(QSharedPointer &dialog, VDomDocument *doc, - VContainer *data){ +VModelingSpline *VModelingSpline::Create(QSharedPointer &dialog, VDomDocument *doc, VContainer *data) +{ qint64 p1 = dialog->getP1(); qint64 p4 = dialog->getP4(); qreal kAsm1 = dialog->getKAsm1(); @@ -90,20 +98,27 @@ VModelingSpline *VModelingSpline::Create(QSharedPointer &dialog, V VModelingSpline *VModelingSpline::Create(const qint64 _id, const qint64 &p1, const qint64 &p4, const qreal &kAsm1, const qreal kAsm2, const qreal &angle1, const qreal &angle2, const qreal &kCurve, VDomDocument *doc, - VContainer *data, const Document::Documents &parse, Tool::Sources typeCreation){ + VContainer *data, const Document::Documents &parse, + const Tool::Sources &typeCreation) +{ VModelingSpline *spl = 0; VSpline spline = VSpline(data->DataModelingPoints(), p1, p4, angle1, angle2, kAsm1, kAsm2, kCurve); qint64 id = _id; - if(typeCreation == Tool::FromGui){ + if (typeCreation == Tool::FromGui) + { id = data->AddModelingSpline(spline); - } else { + } + else + { data->UpdateModelingSpline(id, spline); - if(parse != Document::FullParse){ + if (parse != Document::FullParse) + { doc->UpdateToolData(id, data); } } - data->AddLengthSpline(data->GetNameSpline(p1, p4, Draw::Modeling), spline.GetLength()); - if(parse == Document::FullParse){ + data->AddLengthSpline(spline.name(), toMM(spline.GetLength())); + if (parse == Document::FullParse) + { spl = new VModelingSpline(doc, data, id, typeCreation); doc->AddTool(id, spl); doc->IncrementReferens(p1); @@ -112,12 +127,15 @@ VModelingSpline *VModelingSpline::Create(const qint64 _id, const qint64 &p1, con return spl; } -void VModelingSpline::FullUpdateFromFile(){ +void VModelingSpline::FullUpdateFromFile() +{ RefreshGeometry(); } -void VModelingSpline::FullUpdateFromGui(int result){ - if(result == QDialog::Accepted){ +void VModelingSpline::FullUpdateFromGui(int result) +{ + if (result == QDialog::Accepted) + { VSpline spl = VSpline (VAbstractTool::data.DataModelingPoints(), dialogSpline->getP1(), dialogSpline->getP4(), dialogSpline->getAngle1(), dialogSpline->getAngle2(), dialogSpline->getKAsm1(), dialogSpline->getKAsm2(), dialogSpline->getKCurve()); @@ -137,14 +155,15 @@ void VModelingSpline::FullUpdateFromGui(int result){ controlPoints[0]->pos(), controlPoints[1]->pos(), dialogSpline->getP4(), dialogSpline->getKCurve()); QDomElement domElement = doc->elementById(QString().setNum(id)); - if(domElement.isElement()){ - domElement.setAttribute("point1", QString().setNum(spl.GetP1())); - domElement.setAttribute("point4", QString().setNum(spl.GetP4())); - domElement.setAttribute("angle1", QString().setNum(spl.GetAngle1())); - domElement.setAttribute("angle2", QString().setNum(spl.GetAngle2())); - domElement.setAttribute("kAsm1", QString().setNum(spl.GetKasm1())); - domElement.setAttribute("kAsm2", QString().setNum(spl.GetKasm2())); - domElement.setAttribute("kCurve", QString().setNum(spl.GetKcurve())); + if (domElement.isElement()) + { + domElement.setAttribute(AttrPoint1, QString().setNum(spl.GetP1())); + domElement.setAttribute(AttrPoint4, QString().setNum(spl.GetP4())); + domElement.setAttribute(AttrAngle1, QString().setNum(spl.GetAngle1())); + domElement.setAttribute(AttrAngle2, QString().setNum(spl.GetAngle2())); + domElement.setAttribute(AttrKAsm1, QString().setNum(spl.GetKasm1())); + domElement.setAttribute(AttrKAsm2, QString().setNum(spl.GetKasm2())); + domElement.setAttribute(AttrKCurve, QString().setNum(spl.GetKcurve())); emit FullUpdateTree(); } } @@ -152,70 +171,83 @@ void VModelingSpline::FullUpdateFromGui(int result){ } void VModelingSpline::ControlPointChangePosition(const qint32 &indexSpline, SplinePoint::Position position, - const QPointF pos){ + const QPointF &pos) +{ Q_UNUSED(indexSpline); VSpline spl = VAbstractTool::data.GetModelingSpline(id); - if(position == SplinePoint::FirstPoint){ + if (position == SplinePoint::FirstPoint) + { spl.ModifiSpl (spl.GetP1(), pos, spl.GetP3(), spl.GetP4(), spl.GetKcurve()); - } else { + } + else + { spl.ModifiSpl (spl.GetP1(), spl.GetP2(), pos, spl.GetP4(), spl.GetKcurve()); } QDomElement domElement = doc->elementById(QString().setNum(id)); - if(domElement.isElement()){ - domElement.setAttribute("angle1", QString().setNum(spl.GetAngle1())); - domElement.setAttribute("angle2", QString().setNum(spl.GetAngle2())); - domElement.setAttribute("kAsm1", QString().setNum(spl.GetKasm1())); - domElement.setAttribute("kAsm2", QString().setNum(spl.GetKasm2())); - domElement.setAttribute("kCurve", QString().setNum(spl.GetKcurve())); + if (domElement.isElement()) + { + domElement.setAttribute(AttrAngle1, QString().setNum(spl.GetAngle1())); + domElement.setAttribute(AttrAngle2, QString().setNum(spl.GetAngle2())); + domElement.setAttribute(AttrKAsm1, QString().setNum(spl.GetKasm1())); + domElement.setAttribute(AttrKAsm2, QString().setNum(spl.GetKasm2())); + domElement.setAttribute(AttrKCurve, QString().setNum(spl.GetKcurve())); emit FullUpdateTree(); } } -void VModelingSpline::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ +void VModelingSpline::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) +{ ContextMenu(dialogSpline, this, event); } -void VModelingSpline::AddToFile(){ +void VModelingSpline::AddToFile() +{ VSpline spl = VAbstractTool::data.GetModelingSpline(id); - QDomElement domElement = doc->createElement("spline"); + QDomElement domElement = doc->createElement(TagName); - AddAttribute(domElement, "id", id); - AddAttribute(domElement, "type", "simple"); - AddAttribute(domElement, "point1", spl.GetP1()); - AddAttribute(domElement, "point4", spl.GetP4()); - AddAttribute(domElement, "angle1", spl.GetAngle1()); - AddAttribute(domElement, "angle2", spl.GetAngle2()); - AddAttribute(domElement, "kAsm1", spl.GetKasm1()); - AddAttribute(domElement, "kAsm2", spl.GetKasm2()); - AddAttribute(domElement, "kCurve", spl.GetKcurve()); + AddAttribute(domElement, AttrId, id); + AddAttribute(domElement, AttrType, ToolType); + AddAttribute(domElement, AttrPoint1, spl.GetP1()); + AddAttribute(domElement, AttrPoint4, spl.GetP4()); + AddAttribute(domElement, AttrAngle1, spl.GetAngle1()); + AddAttribute(domElement, AttrAngle2, spl.GetAngle2()); + AddAttribute(domElement, AttrKAsm1, spl.GetKasm1()); + AddAttribute(domElement, AttrKAsm2, spl.GetKasm2()); + AddAttribute(domElement, AttrKCurve, spl.GetKcurve()); AddToModeling(domElement); } -void VModelingSpline::mouseReleaseEvent(QGraphicsSceneMouseEvent *event){ - if(event->button() == Qt::LeftButton){ +void VModelingSpline::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +{ + if (event->button() == Qt::LeftButton) + { emit ChoosedTool(id, Scene::Spline); } QGraphicsItem::mouseReleaseEvent(event); } -void VModelingSpline::hoverMoveEvent(QGraphicsSceneHoverEvent *event){ +void VModelingSpline::hoverMoveEvent(QGraphicsSceneHoverEvent *event) +{ Q_UNUSED(event); this->setPen(QPen(currentColor, widthMainLine)); } -void VModelingSpline::hoverLeaveEvent(QGraphicsSceneHoverEvent *event){ +void VModelingSpline::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) +{ Q_UNUSED(event); this->setPen(QPen(currentColor, widthHairLine)); } -void VModelingSpline::RemoveReferens(){ +void VModelingSpline::RemoveReferens() +{ VSpline spl = VAbstractTool::data.GetModelingSpline(id); doc->DecrementReferens(spl.GetP1()); doc->DecrementReferens(spl.GetP4()); } -void VModelingSpline::RefreshGeometry(){ +void VModelingSpline::RefreshGeometry() +{ VSpline spl = VAbstractTool::data.GetModelingSpline(id); QPainterPath path; path.addPath(spl.GetPath()); diff --git a/tools/modelingTools/vmodelingspline.h b/tools/modelingTools/vmodelingspline.h index bffdb148b..7173fc501 100644 --- a/tools/modelingTools/vmodelingspline.h +++ b/tools/modelingTools/vmodelingspline.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vmodelingspline.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,51 +24,51 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef VMODELINGSPLINE_H #define VMODELINGSPLINE_H #include "vmodelingtool.h" #include -#include "dialogs/dialogspline.h" -#include "widgets/vcontrolpointspline.h" -#include "geometry/vsplinepath.h" +#include "../../dialogs/dialogspline.h" +#include "../../widgets/vcontrolpointspline.h" +#include "../../geometry/vsplinepath.h" -class VModelingSpline:public VModelingTool, public QGraphicsPathItem{ +class VModelingSpline:public VModelingTool, public QGraphicsPathItem +{ Q_OBJECT public: - VModelingSpline (VDomDocument *doc, VContainer *data, qint64 id, - Tool::Sources typeCreation, QGraphicsItem * parent = 0 ); - virtual void setDialog(); - static VModelingSpline* Create(QSharedPointer &dialog, VDomDocument *doc, - VContainer *data); - static VModelingSpline* Create(const qint64 _id, const qint64 &p1, const qint64 &p4, - const qreal &kAsm1, const qreal kAsm2, const qreal &angle1, - const qreal &angle2, const qreal &kCurve, VDomDocument *doc, - VContainer *data, const Document::Documents &parse, - Tool::Sources typeCreation); + VModelingSpline (VDomDocument *doc, VContainer *data, qint64 id, + const Tool::Sources &typeCreation, QGraphicsItem * parent = 0 ); + virtual void setDialog(); + static VModelingSpline* Create(QSharedPointer &dialog, VDomDocument *doc, VContainer *data); + static VModelingSpline* Create(const qint64 _id, const qint64 &p1, const qint64 &p4, const qreal &kAsm1, + const qreal kAsm2, const qreal &angle1, const qreal &angle2, const qreal &kCurve, + VDomDocument *doc, VContainer *data, const Document::Documents &parse, + const Tool::Sources &typeCreation); + static const QString TagName; + static const QString ToolType; signals: - void RefreshLine ( const qint32 &indexSpline, SplinePoint::Position position, - const QPointF &controlPoint, const QPointF &splinePoint ); - void setEnabledPoint ( bool enable ); + void RefreshLine (const qint32 &indexSpline, SplinePoint::Position position, + const QPointF &controlPoint, const QPointF &splinePoint ); + void setEnabledPoint ( bool enable ); public slots: - virtual void FullUpdateFromFile (); - virtual void FullUpdateFromGui ( int result ); - void ControlPointChangePosition ( const qint32 &indexSpline, - SplinePoint::Position position, - const QPointF pos); + virtual void FullUpdateFromFile (); + virtual void FullUpdateFromGui ( int result ); + void ControlPointChangePosition (const qint32 &indexSpline, SplinePoint::Position position, + const QPointF &pos); protected: - virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile (); - virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); - virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); - virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); - virtual void RemoveReferens(); + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void AddToFile (); + virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); + virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); + virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); + virtual void RemoveReferens(); private: - QSharedPointer dialogSpline; + QSharedPointer dialogSpline; QVector controlPoints; - void RefreshGeometry (); + void RefreshGeometry (); }; #endif // VMODELINGSPLINE_H diff --git a/tools/modelingTools/vmodelingsplinepath.cpp b/tools/modelingTools/vmodelingsplinepath.cpp index 2b024389a..515e80a96 100644 --- a/tools/modelingTools/vmodelingsplinepath.cpp +++ b/tools/modelingTools/vmodelingsplinepath.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vmodelingsplinepath.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,16 +24,19 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "vmodelingsplinepath.h" -#include + +const QString VModelingSplinePath::TagName = QStringLiteral("spline"); +const QString VModelingSplinePath::ToolType = QStringLiteral("path"); VModelingSplinePath::VModelingSplinePath(VDomDocument *doc, VContainer *data, qint64 id, - Tool::Sources typeCreation, - QGraphicsItem *parent):VModelingTool(doc, data, id), - QGraphicsPathItem(parent), dialogSplinePath(QSharedPointer()), - controlPoints(QVector()){ + const Tool::Sources &typeCreation, QGraphicsItem *parent) + :VModelingTool(doc, data, id), QGraphicsPathItem(parent), dialogSplinePath(QSharedPointer()), + controlPoints(QVector()) +{ + ignoreFullUpdate = true; VSplinePath splPath = data->GetModelingSplinePath(id); QPainterPath path; path.addPath(splPath.GetPath()); @@ -36,7 +46,8 @@ VModelingSplinePath::VModelingSplinePath(VDomDocument *doc, VContainer *data, qi this->setFlag(QGraphicsItem::ItemIsSelectable, true); this->setAcceptHoverEvents(true); - for(qint32 i = 1; i<=splPath.Count(); ++i){ + for (qint32 i = 1; i<=splPath.Count(); ++i) + { VSpline spl = splPath.GetSpline(i); VControlPointSpline *controlPoint = new VControlPointSpline(i, SplinePoint::FirstPoint, spl.GetP2(), spl.GetPointP1().toQPointF(), this); @@ -54,57 +65,69 @@ VModelingSplinePath::VModelingSplinePath(VDomDocument *doc, VContainer *data, qi connect(this, &VModelingSplinePath::setEnabledPoint, controlPoint, &VControlPointSpline::setEnabledPoint); controlPoints.append(controlPoint); } - if(typeCreation == Tool::FromGui){ + if (typeCreation == Tool::FromGui) + { AddToFile(); } } -void VModelingSplinePath::setDialog(){ - Q_ASSERT(!dialogSplinePath.isNull()); - if(!dialogSplinePath.isNull()){ - VSplinePath splPath = VAbstractTool::data.GetModelingSplinePath(id); - dialogSplinePath->SetPath(splPath); - } +void VModelingSplinePath::setDialog() +{ + Q_ASSERT(dialogSplinePath.isNull() == false); + VSplinePath splPath = VAbstractTool::data.GetModelingSplinePath(id); + dialogSplinePath->SetPath(splPath); } -VModelingSplinePath *VModelingSplinePath::Create(QSharedPointer &dialog, - VDomDocument *doc, VContainer *data){ +VModelingSplinePath *VModelingSplinePath::Create(QSharedPointer &dialog, VDomDocument *doc, + VContainer *data) +{ VSplinePath path = dialog->GetPath(); - for(qint32 i = 0; i < path.CountPoint(); ++i){ + for (qint32 i = 0; i < path.CountPoint(); ++i) + { doc->IncrementReferens(path[i].P()); } return Create(0, path, doc, data, Document::FullParse, Tool::FromGui); } -VModelingSplinePath * VModelingSplinePath::Create(const qint64 _id, const VSplinePath &path, - VDomDocument *doc, VContainer *data, const Document::Documents &parse, - Tool::Sources typeCreation){ +VModelingSplinePath * VModelingSplinePath::Create(const qint64 _id, const VSplinePath &path, VDomDocument *doc, + VContainer *data, const Document::Documents &parse, + const Tool::Sources &typeCreation) +{ VModelingSplinePath *spl = 0; qint64 id = _id; - if(typeCreation == Tool::FromGui){ + if (typeCreation == Tool::FromGui) + { id = data->AddModelingSplinePath(path); - } else { + } + else + { data->UpdateModelingSplinePath(id, path); - if(parse != Document::FullParse){ + if (parse != Document::FullParse) + { doc->UpdateToolData(id, data); } } - data->AddLengthSpline(data->GetNameSplinePath(path), path.GetLength()); - if(parse == Document::FullParse){ + data->AddLengthSpline(path.name(), toMM(path.GetLength())); + if (parse == Document::FullParse) + { spl = new VModelingSplinePath(doc, data, id, typeCreation); doc->AddTool(id, spl); } return spl; } -void VModelingSplinePath::FullUpdateFromFile(){ +void VModelingSplinePath::FullUpdateFromFile() +{ RefreshGeometry(); } -void VModelingSplinePath::FullUpdateFromGui(int result){ - if(result == QDialog::Accepted){ +void VModelingSplinePath::FullUpdateFromGui(int result) +{ + if (result == QDialog::Accepted) + { VSplinePath splPath = dialogSplinePath->GetPath(); - for(qint32 i = 1; i<=splPath.Count(); ++i){ + for (qint32 i = 1; i<=splPath.Count(); ++i) + { VSpline spl = splPath.GetSpline(i); qint32 j = i*2; disconnect(controlPoints[j-2], &VControlPointSpline::ControlPointChangePosition, this, @@ -124,8 +147,9 @@ void VModelingSplinePath::FullUpdateFromGui(int result){ CorectControlPoints(spl, splPath, i); QDomElement domElement = doc->elementById(QString().setNum(id)); - if(domElement.isElement()){ - domElement.setAttribute("kCurve", QString().setNum(splPath.getKCurve())); + if (domElement.isElement()) + { + domElement.setAttribute(AttrKCurve, QString().setNum(splPath.getKCurve())); UpdatePathPoint(domElement, splPath); emit FullUpdateTree(); } @@ -136,26 +160,31 @@ void VModelingSplinePath::FullUpdateFromGui(int result){ } void VModelingSplinePath::ControlPointChangePosition(const qint32 &indexSpline, SplinePoint::Position position, - const QPointF pos){ + const QPointF &pos) +{ VSplinePath splPath = VAbstractTool::data.GetModelingSplinePath(id); VSpline spl = splPath.GetSpline(indexSpline); - if(position == SplinePoint::FirstPoint){ + if (position == SplinePoint::FirstPoint) + { spl.ModifiSpl (spl.GetP1(), pos, spl.GetP3(), spl.GetP4(), spl.GetKcurve()); - } else { + } + else + { spl.ModifiSpl (spl.GetP1(), spl.GetP2(), pos, spl.GetP4(), spl.GetKcurve()); } CorectControlPoints(spl, splPath, indexSpline); QDomElement domElement = doc->elementById(QString().setNum(id)); - if(domElement.isElement()){ - domElement.setAttribute("kCurve", QString().setNum(splPath.getKCurve())); + if (domElement.isElement()) + { + domElement.setAttribute(AttrKCurve, QString().setNum(splPath.getKCurve())); UpdatePathPoint(domElement, splPath); emit FullUpdateTree(); } } -void VModelingSplinePath::CorectControlPoints(const VSpline &spl, VSplinePath &splPath, - const qint32 &indexSpline){ +void VModelingSplinePath::CorectControlPoints(const VSpline &spl, VSplinePath &splPath, const qint32 &indexSpline) +{ VSplinePoint p = splPath.GetSplinePoint(indexSpline, SplinePoint::FirstPoint); p.SetAngle(spl.GetAngle1()); p.SetKAsm2(spl.GetKasm1()); @@ -167,82 +196,97 @@ void VModelingSplinePath::CorectControlPoints(const VSpline &spl, VSplinePath &s splPath.UpdatePoint(indexSpline, SplinePoint::LastPoint, p); } -void VModelingSplinePath::UpdatePathPoint(QDomNode& node, VSplinePath &path){ +void VModelingSplinePath::UpdatePathPoint(QDomNode& node, VSplinePath &path) +{ QDomNodeList nodeList = node.childNodes(); qint32 num = nodeList.size(); - for(qint32 i = 0; i < num; ++i){ + for (qint32 i = 0; i < num; ++i) + { QDomElement domElement = nodeList.at(i).toElement(); - if(!domElement.isNull()){ + if (domElement.isNull() == false) + { VSplinePoint p = path[i]; - domElement.setAttribute("pSpline", QString().setNum(p.P())); - domElement.setAttribute("kAsm1", QString().setNum(p.KAsm1())); - domElement.setAttribute("kAsm2", QString().setNum(p.KAsm2())); - domElement.setAttribute("angle", QString().setNum(p.Angle2())); + domElement.setAttribute(AttrPSpline, QString().setNum(p.P())); + domElement.setAttribute(AttrKAsm1, QString().setNum(p.KAsm1())); + domElement.setAttribute(AttrKAsm2, QString().setNum(p.KAsm2())); + domElement.setAttribute(AttrAngle, QString().setNum(p.Angle2())); } } } -void VModelingSplinePath::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ +void VModelingSplinePath::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) +{ ContextMenu(dialogSplinePath, this, event); } -void VModelingSplinePath::AddToFile(){ +void VModelingSplinePath::AddToFile() +{ VSplinePath splPath = VAbstractTool::data.GetModelingSplinePath(id); - QDomElement domElement = doc->createElement("spline"); + QDomElement domElement = doc->createElement(TagName); - AddAttribute(domElement, "id", id); - AddAttribute(domElement, "type", "path"); - AddAttribute(domElement, "kCurve", splPath.getKCurve()); + AddAttribute(domElement, AttrId, id); + AddAttribute(domElement, AttrType, ToolType); + AddAttribute(domElement, AttrKCurve, splPath.getKCurve()); - for(qint32 i = 0; i < splPath.CountPoint(); ++i){ + for (qint32 i = 0; i < splPath.CountPoint(); ++i) + { AddPathPoint(domElement, splPath[i]); } AddToModeling(domElement); } -void VModelingSplinePath::AddPathPoint(QDomElement &domElement, const VSplinePoint &splPoint){ - QDomElement pathPoint = doc->createElement("pathPoint"); +void VModelingSplinePath::AddPathPoint(QDomElement &domElement, const VSplinePoint &splPoint) +{ + QDomElement pathPoint = doc->createElement(AttrPathPoint); - AddAttribute(pathPoint, "pSpline", splPoint.P()); - AddAttribute(pathPoint, "kAsm1", splPoint.KAsm1()); - AddAttribute(pathPoint, "kAsm2", splPoint.KAsm2()); - AddAttribute(pathPoint, "angle", splPoint.Angle2()); + AddAttribute(pathPoint, AttrPSpline, splPoint.P()); + AddAttribute(pathPoint, AttrKAsm1, splPoint.KAsm1()); + AddAttribute(pathPoint, AttrKAsm2, splPoint.KAsm2()); + AddAttribute(pathPoint, AttrAngle, splPoint.Angle2()); domElement.appendChild(pathPoint); } -void VModelingSplinePath::mouseReleaseEvent(QGraphicsSceneMouseEvent *event){ - if(event->button() == Qt::LeftButton){ +void VModelingSplinePath::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +{ + if (event->button() == Qt::LeftButton) + { emit ChoosedTool(id, Scene::SplinePath); } QGraphicsItem::mouseReleaseEvent(event); } -void VModelingSplinePath::hoverMoveEvent(QGraphicsSceneHoverEvent *event){ +void VModelingSplinePath::hoverMoveEvent(QGraphicsSceneHoverEvent *event) +{ Q_UNUSED(event); this->setPen(QPen(currentColor, widthMainLine)); } -void VModelingSplinePath::hoverLeaveEvent(QGraphicsSceneHoverEvent *event){ +void VModelingSplinePath::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) +{ Q_UNUSED(event); this->setPen(QPen(currentColor, widthHairLine)); } -void VModelingSplinePath::RemoveReferens(){ +void VModelingSplinePath::RemoveReferens() +{ VSplinePath splPath = VAbstractTool::data.GetModelingSplinePath(id); - for(qint32 i = 0; i < splPath.Count(); ++i){ + for (qint32 i = 0; i < splPath.Count(); ++i) + { doc->DecrementReferens(splPath[i].P()); } } -void VModelingSplinePath::RefreshGeometry(){ +void VModelingSplinePath::RefreshGeometry() +{ VSplinePath splPath = VAbstractTool::data.GetModelingSplinePath(id); QPainterPath path; path.addPath(splPath.GetPath()); path.setFillRule( Qt::WindingFill ); this->setPath(path); - for(qint32 i = 1; i<=splPath.Count(); ++i){ + for (qint32 i = 1; i<=splPath.Count(); ++i) + { VSpline spl = splPath.GetSpline(i); QPointF splinePoint = spl.GetPointP1().toQPointF(); QPointF controlPoint = spl.GetP2(); @@ -263,5 +307,4 @@ void VModelingSplinePath::RefreshGeometry(){ connect(controlPoints[j-1], &VControlPointSpline::ControlPointChangePosition, this, &VModelingSplinePath::ControlPointChangePosition); } - } diff --git a/tools/modelingTools/vmodelingsplinepath.h b/tools/modelingTools/vmodelingsplinepath.h index de3ea52c8..09d77d2ff 100644 --- a/tools/modelingTools/vmodelingsplinepath.h +++ b/tools/modelingTools/vmodelingsplinepath.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vmodelingsplinepath.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,53 +24,52 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef VMODELINGSPLINEPATH_H #define VMODELINGSPLINEPATH_H #include "vmodelingtool.h" #include -#include "dialogs/dialogsplinepath.h" -#include "widgets/vcontrolpointspline.h" +#include "../../dialogs/dialogsplinepath.h" +#include "../../widgets/vcontrolpointspline.h" -class VModelingSplinePath:public VModelingTool, public QGraphicsPathItem{ +class VModelingSplinePath:public VModelingTool, public QGraphicsPathItem +{ Q_OBJECT public: - VModelingSplinePath(VDomDocument *doc, VContainer *data, qint64 id, - Tool::Sources typeCreation, - QGraphicsItem * parent = 0); - virtual void setDialog(); - static VModelingSplinePath* Create(QSharedPointer &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); + VModelingSplinePath(VDomDocument *doc, VContainer *data, qint64 id, const Tool::Sources &typeCreation, + QGraphicsItem * parent = 0); + virtual void setDialog(); + static VModelingSplinePath* Create(QSharedPointer &dialog, VDomDocument *doc, VContainer *data); + static VModelingSplinePath* Create(const qint64 _id, const VSplinePath &path, VDomDocument *doc, + VContainer *data, const Document::Documents &parse, + const Tool::Sources &typeCreation); + static const QString TagName; + static const QString ToolType; signals: - void RefreshLine(const qint32 &indexSpline, SplinePoint::Position pos, - const QPointF &controlPoint, const QPointF &splinePoint); - void setEnabledPoint(bool enable); + void RefreshLine(const qint32 &indexSpline, SplinePoint::Position pos, const QPointF &controlPoint, + const QPointF &splinePoint); + void setEnabledPoint(bool enable); public slots: - virtual void FullUpdateFromFile(); - virtual void FullUpdateFromGui(int result); - void ControlPointChangePosition(const qint32 &indexSpline, - SplinePoint::Position position, - const QPointF pos); + virtual void FullUpdateFromFile(); + virtual void FullUpdateFromGui(int result); + void ControlPointChangePosition(const qint32 &indexSpline, SplinePoint::Position position, + const QPointF &pos); protected: - virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile(); - virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); - virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); - virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); - virtual void RemoveReferens(); + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void AddToFile(); + virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); + virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); + virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); + virtual void RemoveReferens(); private: QSharedPointer dialogSplinePath; QVector controlPoints; - void RefreshGeometry(); - void AddPathPoint(QDomElement &domElement, const VSplinePoint &splPoint); - void UpdatePathPoint(QDomNode& node, VSplinePath &path); - void CorectControlPoints(const VSpline &spl, VSplinePath &splPath, - const qint32 &indexSpline); + void RefreshGeometry(); + void AddPathPoint(QDomElement &domElement, const VSplinePoint &splPoint); + void UpdatePathPoint(QDomNode& node, VSplinePath &path); + void CorectControlPoints(const VSpline &spl, VSplinePath &splPath, const qint32 &indexSpline); }; #endif // VMODELINGSPLINEPATH_H diff --git a/tools/modelingTools/vmodelingtool.cpp b/tools/modelingTools/vmodelingtool.cpp index c651880dd..d3b8f05fd 100644 --- a/tools/modelingTools/vmodelingtool.cpp +++ b/tools/modelingTools/vmodelingtool.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vmodelingtool.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,47 +24,47 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "vmodelingtool.h" #include -VModelingTool::VModelingTool(VDomDocument *doc, VContainer *data, qint64 id, QObject *parent): -VAbstractTool(doc, data, id, parent), ignoreContextMenuEvent(false){ +VModelingTool::VModelingTool(VDomDocument *doc, VContainer *data, qint64 id, QObject *parent) + :VAbstractTool(doc, data, id, parent), ignoreContextMenuEvent(false), ignoreFullUpdate(false) +{ _referens = 0; } -VModelingTool::~VModelingTool(){ -} - -void VModelingTool::setDialog(){ -} - -void VModelingTool::ignoreContextMenu(bool enable){ - ignoreContextMenuEvent = enable; -} - -void VModelingTool::AddToModeling(const QDomElement &domElement){ +void VModelingTool::AddToModeling(const QDomElement &domElement) +{ QDomElement modelingElement; bool ok = doc->GetActivModelingElement(modelingElement); - if(ok){ + if (ok) + { modelingElement.appendChild(domElement); - } else { + } + else + { qCritical()<<"Can't find tag Modeling"<< Q_FUNC_INFO; } emit toolhaveChange(); } -void VModelingTool::decrementReferens(){ - if(_referens > 0){ +void VModelingTool::decrementReferens() +{ + if (_referens > 0) + { --_referens; } - if(_referens <= 0){ + if (_referens <= 0) + { RemoveReferens(); QDomElement domElement = doc->elementById(QString().setNum(id)); - if(domElement.isElement()){ + if (domElement.isElement()) + { QDomNode element = domElement.parentNode(); - if(!element.isNull()){ + if (element.isNull() == false) + { element.removeChild(domElement); } } diff --git a/tools/modelingTools/vmodelingtool.h b/tools/modelingTools/vmodelingtool.h index f5bb4bbc7..53c57236c 100644 --- a/tools/modelingTools/vmodelingtool.h +++ b/tools/modelingTools/vmodelingtool.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vmodelingtool.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,7 +24,7 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef VMODELINGTOOL_H #define VMODELINGTOOL_H @@ -29,56 +36,77 @@ class VModelingTool: public VAbstractTool { Q_OBJECT public: - VModelingTool(VDomDocument *doc, VContainer *data, qint64 id, QObject *parent = 0); - virtual ~VModelingTool(); - virtual void setDialog(); - void ignoreContextMenu(bool enable); + VModelingTool(VDomDocument *doc, VContainer *data, qint64 id, QObject *parent = 0); + virtual ~VModelingTool(){} + virtual void setDialog(){} + inline void ignoreContextMenu(bool enable) {ignoreContextMenuEvent = enable;} public slots: virtual void FullUpdateFromGui(int result)=0; -signals: - void RemoveTool(QGraphicsItem *tool); protected: bool ignoreContextMenuEvent; + bool ignoreFullUpdate; void AddToModeling(const QDomElement &domElement); virtual void decrementReferens(); template void ContextMenu(QSharedPointer &dialog, Tool *tool, QGraphicsSceneContextMenuEvent *event, - bool showRemove = true){ - if(!ignoreContextMenuEvent){ + bool showRemove = true) + { + if (ignoreContextMenuEvent == false) + { QMenu menu; - QAction *actionOption = menu.addAction("Властивості"); - QAction *actionRemove; - if(showRemove){ - actionRemove = menu.addAction("Видалити"); + QAction *actionOption = menu.addAction(tr("Option")); + 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){ - dialog = QSharedPointer(new Dialog(getData())); + if (selectedAction == actionOption) + { + dialog = QSharedPointer(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 == false) + { + 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); + } + } + } } } } diff --git a/tools/modelingTools/vmodelingtriangle.cpp b/tools/modelingTools/vmodelingtriangle.cpp new file mode 100644 index 000000000..57db01474 --- /dev/null +++ b/tools/modelingTools/vmodelingtriangle.cpp @@ -0,0 +1,170 @@ +/************************************************************************ + ** + ** @file vmodelingtriangle.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "vmodelingtriangle.h" +#include "../drawTools/vtooltriangle.h" + +const QString VModelingTriangle::ToolType = QStringLiteral("triangle"); + +VModelingTriangle::VModelingTriangle(VDomDocument *doc, VContainer *data, const qint64 &id, const qint64 &axisP1Id, + const qint64 &axisP2Id, const qint64 &firstPointId, const qint64 &secondPointId, + const Tool::Sources &typeCreation, QGraphicsItem *parent) + :VModelingPoint(doc, data, id, parent), axisP1Id(axisP1Id), axisP2Id(axisP2Id), firstPointId(firstPointId), + secondPointId(secondPointId), dialogTriangle(QSharedPointer()) +{ + if (typeCreation == Tool::FromGui) + { + AddToFile(); + } +} + +void VModelingTriangle::setDialog() +{ + Q_ASSERT(dialogTriangle.isNull() == false); + VPointF p = VAbstractTool::data.GetPoint(id); + dialogTriangle->setAxisP1Id(axisP1Id, id); + dialogTriangle->setAxisP2Id(axisP2Id, id); + dialogTriangle->setFirstPointId(firstPointId, id); + dialogTriangle->setSecondPointId(secondPointId, id); + dialogTriangle->setPointName(p.name()); +} + +VModelingTriangle *VModelingTriangle::Create(QSharedPointer &dialog, VDomDocument *doc, + VContainer *data) +{ + qint64 axisP1Id = dialog->getAxisP1Id(); + qint64 axisP2Id = dialog->getAxisP2Id(); + qint64 firstPointId = dialog->getFirstPointId(); + qint64 secondPointId = dialog->getSecondPointId(); + QString pointName = dialog->getPointName(); + return Create(0, pointName, axisP1Id, axisP2Id, firstPointId, secondPointId, 5, 10, doc, data, Document::FullParse, + Tool::FromGui); +} + +VModelingTriangle *VModelingTriangle::Create(const qint64 _id, const QString &pointName, const qint64 &axisP1Id, + const qint64 &axisP2Id, const qint64 &firstPointId, + const qint64 &secondPointId, const qreal &mx, const qreal &my, + VDomDocument *doc, VContainer *data, const Document::Documents &parse, + const Tool::Sources &typeCreation) +{ + VModelingTriangle *tool = 0; + VPointF axisP1 = data->GetPoint(axisP1Id); + VPointF axisP2 = data->GetPoint(axisP2Id); + VPointF firstPoint = data->GetPoint(firstPointId); + VPointF secondPoint = data->GetPoint(secondPointId); + + QPointF point = VToolTriangle::FindPoint(axisP1.toQPointF(), axisP2.toQPointF(), firstPoint.toQPointF(), + secondPoint.toQPointF()); + qint64 id = _id; + if (typeCreation == Tool::FromGui) + { + id = data->AddPoint(VPointF(point.x(), point.y(), pointName, mx, my)); + } + else + { + data->UpdatePoint(id, VPointF(point.x(), point.y(), pointName, mx, my)); + if (parse != Document::FullParse) + { + doc->UpdateToolData(id, data); + } + } + if (parse == Document::FullParse) + { + tool = new VModelingTriangle(doc, data, id, axisP1Id, axisP2Id, firstPointId, secondPointId, typeCreation); + doc->AddTool(id, tool); + doc->IncrementReferens(axisP1Id); + doc->IncrementReferens(axisP2Id); + doc->IncrementReferens(firstPointId); + doc->IncrementReferens(secondPointId); + } + return tool; +} + +void VModelingTriangle::FullUpdateFromFile() +{ + QDomElement domElement = doc->elementById(QString().setNum(id)); + if (domElement.isElement()) + { + axisP1Id = domElement.attribute(AttrAxisP1, "").toLongLong(); + axisP2Id = domElement.attribute(AttrAxisP2, "").toLongLong(); + firstPointId = domElement.attribute(AttrFirstPoint, "").toLongLong(); + secondPointId = domElement.attribute(AttrSecondPoint, "").toLongLong(); + } + VModelingPoint::RefreshPointGeometry(VModelingTool::data.GetPoint(id)); +} + +void VModelingTriangle::FullUpdateFromGui(int result) +{ + if (result == QDialog::Accepted) + { + QDomElement domElement = doc->elementById(QString().setNum(id)); + if (domElement.isElement()) + { + domElement.setAttribute(AttrName, dialogTriangle->getPointName()); + domElement.setAttribute(AttrAxisP1, QString().setNum(dialogTriangle->getAxisP1Id())); + domElement.setAttribute(AttrAxisP2, QString().setNum(dialogTriangle->getAxisP2Id())); + domElement.setAttribute(AttrFirstPoint, QString().setNum(dialogTriangle->getFirstPointId())); + domElement.setAttribute(AttrSecondPoint, QString().setNum(dialogTriangle->getSecondPointId())); + emit FullUpdateTree(); + } + + } + dialogTriangle.clear(); +} + +void VModelingTriangle::RemoveReferens() +{ + doc->DecrementReferens(axisP1Id); + doc->DecrementReferens(axisP2Id); + doc->DecrementReferens(firstPointId); + doc->DecrementReferens(secondPointId); +} + +void VModelingTriangle::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) +{ + ContextMenu(dialogTriangle, this, event); +} + +void VModelingTriangle::AddToFile() +{ + VPointF point = VAbstractTool::data.GetPoint(id); + QDomElement domElement = doc->createElement(TagName); + + AddAttribute(domElement, AttrId, id); + AddAttribute(domElement, AttrType, ToolType); + AddAttribute(domElement, AttrName, point.name()); + AddAttribute(domElement, AttrMx, toMM(point.mx())); + AddAttribute(domElement, AttrMy, toMM(point.my())); + + AddAttribute(domElement, AttrAxisP1, axisP1Id); + AddAttribute(domElement, AttrAxisP2, axisP2Id); + AddAttribute(domElement, AttrFirstPoint, firstPointId); + AddAttribute(domElement, AttrSecondPoint, secondPointId); + + AddToModeling(domElement); +} diff --git a/tools/modelingTools/vmodelingtriangle.h b/tools/modelingTools/vmodelingtriangle.h new file mode 100644 index 000000000..09dfdfb21 --- /dev/null +++ b/tools/modelingTools/vmodelingtriangle.h @@ -0,0 +1,66 @@ +/************************************************************************ + ** + ** @file vmodelingtriangle.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef VMODELINGTRIANGLE_H +#define VMODELINGTRIANGLE_H + +#include "vmodelingpoint.h" +#include "../drawTools/vtooltriangle.h" +#include "../../dialogs/dialogtriangle.h" + +class VModelingTriangle : public VModelingPoint +{ + Q_OBJECT +public: + VModelingTriangle(VDomDocument *doc, VContainer *data, const qint64 &id, const qint64 &axisP1Id, + const qint64 &axisP2Id, const qint64 &firstPointId, const qint64 &secondPointId, + const Tool::Sources &typeCreation, QGraphicsItem * parent = 0); + virtual void setDialog(); + static VModelingTriangle* Create(QSharedPointer &dialog, VDomDocument *doc, VContainer *data); + static VModelingTriangle* Create(const qint64 _id, const QString &pointName, const qint64 &axisP1Id, + const qint64 &axisP2Id, const qint64 &firstPointId, const qint64 &secondPointId, + const qreal &mx, const qreal &my, VDomDocument *doc, VContainer *data, + const Document::Documents &parse, const Tool::Sources &typeCreation); + static const QString ToolType; +public slots: + virtual void FullUpdateFromFile(); + virtual void FullUpdateFromGui(int result); +protected: + virtual void RemoveReferens(); + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void AddToFile(); +private: + Q_DISABLE_COPY(VModelingTriangle) + qint64 axisP1Id; + qint64 axisP2Id; + qint64 firstPointId; + qint64 secondPointId; + QSharedPointer dialogTriangle; +}; + +#endif // VMODELINGTRIANGLE_H diff --git a/tools/nodeDetails/nodedetails.h b/tools/nodeDetails/nodedetails.h index a331e94b2..d230f7456 100644 --- a/tools/nodeDetails/nodedetails.h +++ b/tools/nodeDetails/nodedetails.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file nodedetails.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,7 +24,7 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef NODEDETAILS_H #define NODEDETAILS_H diff --git a/tools/nodeDetails/vabstractnode.cpp b/tools/nodeDetails/vabstractnode.cpp index ddd667825..48374a891 100644 --- a/tools/nodeDetails/vabstractnode.cpp +++ b/tools/nodeDetails/vabstractnode.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vabstractnode.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,38 +24,53 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "vabstractnode.h" #include -VAbstractNode::VAbstractNode(VDomDocument *doc, VContainer *data, qint64 id, qint64 idNode, - Draw::Draws typeobject, QObject *parent) : - VAbstractTool(doc, data, id, parent), idNode(idNode), typeobject(typeobject){ +const QString VAbstractNode::AttrIdObject = QStringLiteral("idObject"); +const QString VAbstractNode::AttrTypeObject = QStringLiteral("typeObject"); +const QString VAbstractNode::TypeObjectCalculation = QStringLiteral("Calculation"); +const QString VAbstractNode::TypeObjectModeling = QStringLiteral("Modeling"); + +VAbstractNode::VAbstractNode(VDomDocument *doc, VContainer *data, qint64 id, qint64 idNode, Draw::Draws typeobject, + QObject *parent) + : VAbstractTool(doc, data, id, parent), idNode(idNode), typeobject(typeobject) +{ _referens = 0; } -void VAbstractNode::AddToModeling(const QDomElement &domElement){ +void VAbstractNode::AddToModeling(const QDomElement &domElement) +{ QDomElement modelingElement; bool ok = doc->GetActivModelingElement(modelingElement); - if(ok){ + if (ok) + { modelingElement.appendChild(domElement); - } else { - qCritical()<<"Can't find tag Modeling"<< Q_FUNC_INFO; + } + else + { + qCritical()< 0){ +void VAbstractNode::decrementReferens() +{ + if (_referens > 0) + { --_referens; } - if(_referens <= 0){ + if (_referens <= 0) + { doc->DecrementReferens(idNode); QDomElement domElement = doc->elementById(QString().setNum(id)); - if(domElement.isElement()){ + if (domElement.isElement()) + { QDomNode element = domElement.parentNode(); - if(!element.isNull()){ + if (element.isNull() == false) + { element.removeChild(domElement); } } diff --git a/tools/nodeDetails/vabstractnode.h b/tools/nodeDetails/vabstractnode.h index 3cd1a63cc..7fff53e9e 100644 --- a/tools/nodeDetails/vabstractnode.h +++ b/tools/nodeDetails/vabstractnode.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vabstractnode.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,7 +24,7 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef VABSTRACTNODE_H #define VABSTRACTNODE_H @@ -31,6 +38,10 @@ public: VAbstractNode(VDomDocument *doc, VContainer *data, qint64 id, qint64 idNode, Draw::Draws typeobject, QObject *parent = 0 ); virtual ~VAbstractNode() {} + static const QString AttrIdObject; + static const QString AttrTypeObject; + static const QString TypeObjectCalculation; + static const QString TypeObjectModeling; protected: qint64 idNode; Draw::Draws typeobject; diff --git a/tools/nodeDetails/vnodearc.cpp b/tools/nodeDetails/vnodearc.cpp index ea755e7f5..826174a68 100644 --- a/tools/nodeDetails/vnodearc.cpp +++ b/tools/nodeDetails/vnodearc.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vnodearc.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,72 +24,91 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "vnodearc.h" +const QString VNodeArc::TagName = QStringLiteral("arc"); +const QString VNodeArc::ToolType = QStringLiteral("modeling"); + VNodeArc::VNodeArc(VDomDocument *doc, VContainer *data, qint64 id, qint64 idArc, Draw::Draws typeobject, - Tool::Sources typeCreation, QGraphicsItem * parent) : - VAbstractNode(doc, data, id, idArc, typeobject), QGraphicsPathItem(parent){ + const Tool::Sources &typeCreation, QGraphicsItem * parent) + :VAbstractNode(doc, data, id, idArc, typeobject), QGraphicsPathItem(parent) +{ RefreshGeometry(); this->setPen(QPen(baseColor, widthHairLine)); this->setFlag(QGraphicsItem::ItemIsSelectable, true); this->setAcceptHoverEvents(true); - if(typeCreation == Tool::FromGui){ + if (typeCreation == Tool::FromGui) + { AddToFile(); } } -void VNodeArc::Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idArc, - Draw::Draws typeobject, const Document::Documents &parse, Tool::Sources typeCreation){ - if(parse == Document::FullParse){ +void VNodeArc::Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idArc, const Draw::Draws &typeobject, + const Document::Documents &parse, const Tool::Sources &typeCreation) +{ + if (parse == Document::FullParse) + { VNodeArc *arc = new VNodeArc(doc, data, id, idArc, typeobject, typeCreation); - Q_CHECK_PTR(arc); + Q_ASSERT(arc != 0); doc->AddTool(id, arc); doc->IncrementReferens(idArc); - } else { + } + else + { doc->UpdateToolData(id, data); } } -void VNodeArc::FullUpdateFromFile(){ +void VNodeArc::FullUpdateFromFile() +{ RefreshGeometry(); } -void VNodeArc::AddToFile(){ - QDomElement domElement = doc->createElement("arc"); +void VNodeArc::AddToFile() +{ + QDomElement domElement = doc->createElement(TagName); - AddAttribute(domElement, "id", id); - AddAttribute(domElement, "type", "modeling"); - AddAttribute(domElement, "idObject", idNode); - if(typeobject == Draw::Calculation){ - AddAttribute(domElement, "typeObject", "Calculation"); - } else { - AddAttribute(domElement, "typeObject", "Modeling"); + AddAttribute(domElement, AttrId, id); + AddAttribute(domElement, AttrType, ToolType); + AddAttribute(domElement, AttrIdObject, idNode); + if (typeobject == Draw::Calculation) + { + AddAttribute(domElement, AttrTypeObject, TypeObjectCalculation); + } + else + { + AddAttribute(domElement, AttrTypeObject, ToolType ); } AddToModeling(domElement); } -void VNodeArc::mouseReleaseEvent(QGraphicsSceneMouseEvent *event){ - if(event->button() == Qt::LeftButton){ +void VNodeArc::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +{ + if (event->button() == Qt::LeftButton) + { emit ChoosedTool(id, Scene::Arc); } QGraphicsItem::mouseReleaseEvent(event); } -void VNodeArc::hoverMoveEvent(QGraphicsSceneHoverEvent *event){ +void VNodeArc::hoverMoveEvent(QGraphicsSceneHoverEvent *event) +{ Q_UNUSED(event); this->setPen(QPen(currentColor, widthMainLine)); } -void VNodeArc::hoverLeaveEvent(QGraphicsSceneHoverEvent *event){ +void VNodeArc::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) +{ Q_UNUSED(event); this->setPen(QPen(currentColor, widthHairLine)); } -void VNodeArc::RefreshGeometry(){ +void VNodeArc::RefreshGeometry() +{ VArc arc = VAbstractTool::data.GetModelingArc(id); QPainterPath path; path.addPath(arc.GetPath()); diff --git a/tools/nodeDetails/vnodearc.h b/tools/nodeDetails/vnodearc.h index 6776776ad..f71096694 100644 --- a/tools/nodeDetails/vnodearc.h +++ b/tools/nodeDetails/vnodearc.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vnodearc.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,7 +24,7 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef VNODEARC_H #define VNODEARC_H @@ -30,9 +37,11 @@ class VNodeArc :public VAbstractNode, public QGraphicsPathItem Q_OBJECT public: VNodeArc(VDomDocument *doc, VContainer *data, qint64 id, qint64 idArc, Draw::Draws typeobject, - Tool::Sources typeCreation, QGraphicsItem * parent = 0); - static void Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idArc, - Draw::Draws typeobject, const Document::Documents &parse, Tool::Sources typeCreation); + const Tool::Sources &typeCreation, QGraphicsItem * parent = 0); + static void Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idArc, const Draw::Draws &typeobject, + const Document::Documents &parse, const Tool::Sources &typeCreation); + static const QString TagName; + static const QString ToolType; public slots: virtual void FullUpdateFromFile(); protected: diff --git a/tools/nodeDetails/vnodepoint.cpp b/tools/nodeDetails/vnodepoint.cpp index 21426313f..e7495c3c3 100644 --- a/tools/nodeDetails/vnodepoint.cpp +++ b/tools/nodeDetails/vnodepoint.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vnodepoint.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,14 +24,18 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "vnodepoint.h" -VNodePoint::VNodePoint(VDomDocument *doc, VContainer *data, qint64 id, qint64 idPoint, - Draw::Draws typeobject, Tool::Sources typeCreation, QGraphicsItem *parent) - :VAbstractNode(doc, data, id, idPoint, typeobject), QGraphicsEllipseItem(parent), - radius(toPixel(1.5)), namePoint(0), lineName(0){ +const QString VNodePoint::TagName = QStringLiteral("point"); +const QString VNodePoint::ToolType = QStringLiteral("modeling"); + +VNodePoint::VNodePoint(VDomDocument *doc, VContainer *data, qint64 id, qint64 idPoint, Draw::Draws typeobject, + const Tool::Sources &typeCreation, QGraphicsItem *parent) + :VAbstractNode(doc, data, id, idPoint, typeobject), QGraphicsEllipseItem(parent), radius(toPixel(1.5)), + namePoint(0), lineName(0) +{ namePoint = new VGraphicsSimpleTextItem(this); lineName = new QGraphicsLineItem(this); connect(namePoint, &VGraphicsSimpleTextItem::NameChangePosition, this, @@ -34,64 +45,79 @@ VNodePoint::VNodePoint(VDomDocument *doc, VContainer *data, qint64 id, qint64 id this->setFlag(QGraphicsItem::ItemIsSelectable, true); this->setAcceptHoverEvents(true); RefreshPointGeometry(VAbstractTool::data.GetModelingPoint(id)); - if(typeCreation == Tool::FromGui){ + if (typeCreation == Tool::FromGui) + { AddToFile(); } } -void VNodePoint::Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idPoint, - Draw::Draws typeobject, const Document::Documents &parse, Tool::Sources typeCreation){ - if(parse == Document::FullParse){ +void VNodePoint::Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idPoint, const Draw::Draws &typeobject, + const Document::Documents &parse, const Tool::Sources &typeCreation) +{ + if (parse == Document::FullParse) + { VNodePoint *point = new VNodePoint(doc, data, id, idPoint, typeobject, typeCreation); - Q_CHECK_PTR(point); + Q_ASSERT(point != 0); doc->AddTool(id, point); doc->IncrementReferens(idPoint); - } else { + } + else + { doc->UpdateToolData(id, data); } } -void VNodePoint::FullUpdateFromFile(){ +void VNodePoint::FullUpdateFromFile() +{ RefreshPointGeometry(VAbstractTool::data.GetModelingPoint(id)); } -void VNodePoint::AddToFile(){ +void VNodePoint::AddToFile() +{ VPointF point = VAbstractTool::data.GetModelingPoint(id); - QDomElement domElement = doc->createElement("point"); + QDomElement domElement = doc->createElement(TagName); - AddAttribute(domElement, "id", id); - AddAttribute(domElement, "type", "modeling"); - AddAttribute(domElement, "idObject", idNode); - if(typeobject == Draw::Calculation){ - AddAttribute(domElement, "typeObject", "Calculation"); - } else { - AddAttribute(domElement, "typeObject", "Modeling"); + AddAttribute(domElement, AttrId, id); + AddAttribute(domElement, AttrType, ToolType); + AddAttribute(domElement, AttrIdObject, idNode); + if (typeobject == Draw::Calculation) + { + AddAttribute(domElement, AttrTypeObject, TypeObjectCalculation); } - AddAttribute(domElement, "mx", toMM(point.mx())); - AddAttribute(domElement, "my", toMM(point.my())); + else + { + AddAttribute(domElement, AttrTypeObject, TypeObjectModeling); + } + AddAttribute(domElement, AttrMx, toMM(point.mx())); + AddAttribute(domElement, AttrMy, toMM(point.my())); AddToModeling(domElement); } -void VNodePoint::mouseReleaseEvent(QGraphicsSceneMouseEvent *event){ - if(event->button() == Qt::LeftButton){ +void VNodePoint::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +{ + if (event->button() == Qt::LeftButton) + { emit ChoosedTool(id, Scene::Point); } QGraphicsItem::mouseReleaseEvent(event); } -void VNodePoint::hoverMoveEvent(QGraphicsSceneHoverEvent *event){ +void VNodePoint::hoverMoveEvent(QGraphicsSceneHoverEvent *event) +{ Q_UNUSED(event); this->setPen(QPen(currentColor, widthMainLine)); } -void VNodePoint::hoverLeaveEvent(QGraphicsSceneHoverEvent *event){ +void VNodePoint::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) +{ Q_UNUSED(event); this->setPen(QPen(currentColor, widthHairLine)); } -void VNodePoint::NameChangePosition(const QPointF pos){ +void VNodePoint::NameChangePosition(const QPointF &pos) +{ VPointF point = VAbstractTool::data.GetModelingPoint(id); QPointF p = pos - this->pos(); point.setMx(p.x()); @@ -101,16 +127,19 @@ void VNodePoint::NameChangePosition(const QPointF pos){ VAbstractTool::data.UpdatePoint(id, point); } -void VNodePoint::UpdateNamePosition(qreal mx, qreal my){ +void VNodePoint::UpdateNamePosition(qreal mx, qreal my) +{ QDomElement domElement = doc->elementById(QString().setNum(id)); - if(domElement.isElement()){ - domElement.setAttribute("mx", QString().setNum(toMM(mx))); - domElement.setAttribute("my", QString().setNum(toMM(my))); + if (domElement.isElement()) + { + domElement.setAttribute(AttrMx, QString().setNum(toMM(mx))); + domElement.setAttribute(AttrMy, QString().setNum(toMM(my))); emit toolhaveChange(); } } -void VNodePoint::RefreshPointGeometry(const VPointF &point){ +void VNodePoint::RefreshPointGeometry(const VPointF &point) +{ QRectF rec = QRectF(0, 0, radius*2, radius*2); rec.translate(-rec.center().x(), -rec.center().y()); this->setRect(rec); @@ -125,15 +154,19 @@ void VNodePoint::RefreshPointGeometry(const VPointF &point){ RefreshLine(); } -void VNodePoint::RefreshLine(){ +void VNodePoint::RefreshLine() +{ QRectF nameRec = namePoint->sceneBoundingRect(); QPointF p1, p2; LineIntersectCircle(QPointF(), radius, QLineF(QPointF(), nameRec.center()- scenePos()), p1, p2); QPointF pRec = LineIntersectRect(nameRec, QLineF(scenePos(), nameRec.center())); lineName->setLine(QLineF(p1, pRec - scenePos())); - if(QLineF(p1, pRec - scenePos()).length() <= toPixel(4)){ + if (QLineF(p1, pRec - scenePos()).length() <= toPixel(4)) + { lineName->setVisible(false); - } else { + } + else + { lineName->setVisible(true); } } diff --git a/tools/nodeDetails/vnodepoint.h b/tools/nodeDetails/vnodepoint.h index f7e963a97..7874715c6 100644 --- a/tools/nodeDetails/vnodepoint.h +++ b/tools/nodeDetails/vnodepoint.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vnodepoint.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,38 +24,38 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef VNODEPOINT_H #define VNODEPOINT_H #include "vabstractnode.h" -#include "widgets/vgraphicssimpletextitem.h" +#include "../../widgets/vgraphicssimpletextitem.h" class VNodePoint: public VAbstractNode, public QGraphicsEllipseItem { Q_OBJECT public: - VNodePoint(VDomDocument *doc, VContainer *data, qint64 id, qint64 idPoint, - Draw::Draws typeobject, Tool::Sources typeCreation, - QGraphicsItem * parent = 0 ); - static void Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idPoint, - Draw::Draws typeobject, const Document::Documents &parse, - Tool::Sources typeCreation); + VNodePoint(VDomDocument *doc, VContainer *data, qint64 id, qint64 idPoint, Draw::Draws typeobject, + const Tool::Sources &typeCreation, QGraphicsItem * parent = 0 ); + static void Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idPoint, const Draw::Draws &typeobject, + const Document::Documents &parse, const Tool::Sources &typeCreation); + static const QString TagName; + static const QString ToolType; public slots: - virtual void FullUpdateFromFile(); - void NameChangePosition(const QPointF pos); + virtual void FullUpdateFromFile(); + void NameChangePosition(const QPointF &pos); protected: - qreal radius; + qreal radius; VGraphicsSimpleTextItem *namePoint; QGraphicsLineItem *lineName; - virtual void AddToFile(); - virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); - virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); - virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); - virtual void UpdateNamePosition(qreal mx, qreal my); - virtual void RefreshPointGeometry(const VPointF &point); - void RefreshLine(); + virtual void AddToFile(); + virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); + virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); + virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); + virtual void UpdateNamePosition(qreal mx, qreal my); + virtual void RefreshPointGeometry(const VPointF &point); + void RefreshLine(); private: Q_DISABLE_COPY(VNodePoint) }; diff --git a/tools/nodeDetails/vnodespline.cpp b/tools/nodeDetails/vnodespline.cpp index b48470f83..26dd21a01 100644 --- a/tools/nodeDetails/vnodespline.cpp +++ b/tools/nodeDetails/vnodespline.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vnodespline.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,74 +24,93 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "vnodespline.h" -VNodeSpline::VNodeSpline(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline, - Draw::Draws typeobject, Tool::Sources typeCreation, QGraphicsItem * parent) : - VAbstractNode(doc, data, id, idSpline, typeobject), QGraphicsPathItem(parent){ +const QString VNodeSpline::TagName = QStringLiteral("spline"); +const QString VNodeSpline::ToolType = QStringLiteral("modelingSpline"); + +VNodeSpline::VNodeSpline(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline, Draw::Draws typeobject, + const Tool::Sources &typeCreation, QGraphicsItem * parent) + :VAbstractNode(doc, data, id, idSpline, typeobject), QGraphicsPathItem(parent) +{ RefreshGeometry(); this->setPen(QPen(baseColor, widthHairLine)); this->setFlag(QGraphicsItem::ItemIsSelectable, true); this->setAcceptHoverEvents(true); - if(typeCreation == Tool::FromGui){ + if (typeCreation == Tool::FromGui) + { AddToFile(); } } VNodeSpline *VNodeSpline::Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline, - Draw::Draws typeobject, const Document::Documents &parse, - Tool::Sources typeCreation){ + const Draw::Draws &typeobject, const Document::Documents &parse, + const Tool::Sources &typeCreation) +{ VNodeSpline *spl = 0; - if(parse == Document::FullParse){ + if (parse == Document::FullParse) + { spl = new VNodeSpline(doc, data, id, idSpline, typeobject, typeCreation); doc->AddTool(id, spl); doc->IncrementReferens(idSpline); - } else { + } + else + { doc->UpdateToolData(id, data); } return spl; } -void VNodeSpline::FullUpdateFromFile(){ +void VNodeSpline::FullUpdateFromFile() +{ RefreshGeometry(); } -void VNodeSpline::AddToFile(){ - QDomElement domElement = doc->createElement("spline"); +void VNodeSpline::AddToFile() +{ + QDomElement domElement = doc->createElement(TagName); - AddAttribute(domElement, "id", id); - AddAttribute(domElement, "type", "modelingSpline"); - AddAttribute(domElement, "idObject", idNode); - if(typeobject == Draw::Calculation){ - AddAttribute(domElement, "typeObject", "Calculation"); - } else { - AddAttribute(domElement, "typeObject", "Modeling"); + AddAttribute(domElement, AttrId, id); + AddAttribute(domElement, AttrType, ToolType); + AddAttribute(domElement, AttrIdObject, idNode); + if (typeobject == Draw::Calculation) + { + AddAttribute(domElement, AttrTypeObject, TypeObjectCalculation); + } + else + { + AddAttribute(domElement, AttrTypeObject, TypeObjectModeling); } AddToModeling(domElement); } -void VNodeSpline::mouseReleaseEvent(QGraphicsSceneMouseEvent *event){ - if(event->button() == Qt::LeftButton){ +void VNodeSpline::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +{ + if (event->button() == Qt::LeftButton) + { emit ChoosedTool(id, Scene::Spline); } QGraphicsItem::mouseReleaseEvent(event); } -void VNodeSpline::hoverMoveEvent(QGraphicsSceneHoverEvent *event){ +void VNodeSpline::hoverMoveEvent(QGraphicsSceneHoverEvent *event) +{ Q_UNUSED(event); this->setPen(QPen(currentColor, widthMainLine)); } -void VNodeSpline::hoverLeaveEvent(QGraphicsSceneHoverEvent *event){ +void VNodeSpline::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) +{ Q_UNUSED(event); this->setPen(QPen(currentColor, widthHairLine)); } -void VNodeSpline::RefreshGeometry(){ +void VNodeSpline::RefreshGeometry() +{ VSpline spl = VAbstractTool::data.GetModelingSpline(id); QPainterPath path; path.addPath(spl.GetPath()); diff --git a/tools/nodeDetails/vnodespline.h b/tools/nodeDetails/vnodespline.h index 5e076f9ec..fc8dcb202 100644 --- a/tools/nodeDetails/vnodespline.h +++ b/tools/nodeDetails/vnodespline.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vnodespline.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,7 +24,7 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef VNODESPLINE_H #define VNODESPLINE_H @@ -29,19 +36,22 @@ class VNodeSpline:public VAbstractNode, public QGraphicsPathItem { Q_OBJECT public: - VNodeSpline(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline, Draw::Draws typeobject, - Tool::Sources typeCreation, QGraphicsItem * parent = 0); + VNodeSpline(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline, Draw::Draws typeobject, + const Tool::Sources &typeCreation, QGraphicsItem * parent = 0); static VNodeSpline *Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline, - Draw::Draws typeobject, const Document::Documents &parse, Tool::Sources typeCreation); + const Draw::Draws &typeobject, const Document::Documents &parse, + const Tool::Sources &typeCreation); + static const QString TagName; + static const QString ToolType; public slots: - virtual void FullUpdateFromFile (); + virtual void FullUpdateFromFile (); protected: - virtual void AddToFile (); - virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); + virtual void AddToFile (); + virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); private: - void RefreshGeometry (); + void RefreshGeometry (); }; #endif // VNODESPLINE_H diff --git a/tools/nodeDetails/vnodesplinepath.cpp b/tools/nodeDetails/vnodesplinepath.cpp index 493f5a397..8defab838 100644 --- a/tools/nodeDetails/vnodesplinepath.cpp +++ b/tools/nodeDetails/vnodesplinepath.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vnodesplinepath.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,78 +24,97 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "vnodesplinepath.h" +const QString VNodeSplinePath::TagName = QStringLiteral("spline"); +const QString VNodeSplinePath::ToolType = QStringLiteral("modelingPath"); + VNodeSplinePath::VNodeSplinePath(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline, - Draw::Draws typeobject, Tool::Sources typeCreation, - QGraphicsItem * parent) : - VAbstractNode(doc, data, id, idSpline, typeobject), QGraphicsPathItem(parent){ + Draw::Draws typeobject, const Tool::Sources &typeCreation, QGraphicsItem * parent) + :VAbstractNode(doc, data, id, idSpline, typeobject), QGraphicsPathItem(parent) +{ RefreshGeometry(); this->setPen(QPen(baseColor, widthHairLine)); this->setFlag(QGraphicsItem::ItemIsSelectable, true); this->setAcceptHoverEvents(true); - if(typeCreation == Tool::FromGui){ + if (typeCreation == Tool::FromGui) + { AddToFile(); } } void VNodeSplinePath::Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline, - Draw::Draws typeobject, const Document::Documents &parse, - Tool::Sources typeCreation){ - if(parse == Document::FullParse){ + const Draw::Draws &typeobject, const Document::Documents &parse, + const Tool::Sources &typeCreation) +{ + if (parse == Document::FullParse) + { VNodeSplinePath *splPath = new VNodeSplinePath(doc, data, id, idSpline, typeobject, typeCreation); - Q_CHECK_PTR(splPath); + Q_ASSERT(splPath != 0); doc->AddTool(id, splPath); VSplinePath path = data->GetModelingSplinePath(id); const QVector *points = path.GetPoint(); - for(qint32 i = 0; isize(); ++i){ + for (qint32 i = 0; isize(); ++i) + { doc->IncrementReferens(points->at(i).P()); } - } else { + } + else + { doc->UpdateToolData(id, data); } } -void VNodeSplinePath::FullUpdateFromFile(){ +void VNodeSplinePath::FullUpdateFromFile() +{ RefreshGeometry(); } -void VNodeSplinePath::AddToFile(){ - QDomElement domElement = doc->createElement("spline"); +void VNodeSplinePath::AddToFile() +{ + QDomElement domElement = doc->createElement(TagName); - AddAttribute(domElement, "id", id); - AddAttribute(domElement, "type", "modelingPath"); - AddAttribute(domElement, "idObject", idNode); - if(typeobject == Draw::Calculation){ - AddAttribute(domElement, "typeObject", "Calculation"); - } else { - AddAttribute(domElement, "typeObject", "Modeling"); + AddAttribute(domElement, AttrId, id); + AddAttribute(domElement, AttrType, ToolType); + AddAttribute(domElement, AttrIdObject, idNode); + if (typeobject == Draw::Calculation) + { + AddAttribute(domElement, AttrTypeObject, TypeObjectCalculation); + } + else + { + AddAttribute(domElement, AttrTypeObject, TypeObjectModeling); } AddToModeling(domElement); } -void VNodeSplinePath::mouseReleaseEvent(QGraphicsSceneMouseEvent *event){ - if(event->button() == Qt::LeftButton){ +void VNodeSplinePath::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +{ + if (event->button() == Qt::LeftButton) + { emit ChoosedTool(id, Scene::SplinePath); } QGraphicsItem::mouseReleaseEvent(event); } -void VNodeSplinePath::hoverMoveEvent(QGraphicsSceneHoverEvent *event){ +void VNodeSplinePath::hoverMoveEvent(QGraphicsSceneHoverEvent *event) +{ Q_UNUSED(event); this->setPen(QPen(currentColor, widthMainLine)); } -void VNodeSplinePath::hoverLeaveEvent(QGraphicsSceneHoverEvent *event){ +void VNodeSplinePath::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) +{ Q_UNUSED(event); this->setPen(QPen(currentColor, widthHairLine)); } -void VNodeSplinePath::RefreshGeometry(){ +void VNodeSplinePath::RefreshGeometry() +{ VSplinePath splPath = VAbstractTool::data.GetModelingSplinePath(id); QPainterPath path; path.addPath(splPath.GetPath()); diff --git a/tools/nodeDetails/vnodesplinepath.h b/tools/nodeDetails/vnodesplinepath.h index 21b09dd36..f5b0c9cba 100644 --- a/tools/nodeDetails/vnodesplinepath.h +++ b/tools/nodeDetails/vnodesplinepath.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vnodesplinepath.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,7 +24,7 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef VNODESPLINEPATH_H #define VNODESPLINEPATH_H @@ -30,10 +37,11 @@ class VNodeSplinePath : public VAbstractNode, public QGraphicsPathItem Q_OBJECT public: VNodeSplinePath(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline, - Draw::Draws typeobject, Tool::Sources typeCreation, - QGraphicsItem * parent = 0); - static void Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline, - Draw::Draws typeobject, const Document::Documents &parse, Tool::Sources typeCreation); + Draw::Draws typeobject, const Tool::Sources &typeCreation, QGraphicsItem * parent = 0); + static void Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline, const Draw::Draws &typeobject, + const Document::Documents &parse, const Tool::Sources &typeCreation); + static const QString TagName; + static const QString ToolType; public slots: virtual void FullUpdateFromFile(); protected: diff --git a/tools/tools.h b/tools/tools.h index 0c2a63142..69adbf1ce 100644 --- a/tools/tools.h +++ b/tools/tools.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file tools.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,7 +24,7 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef TOOLS_H #define TOOLS_H diff --git a/tools/tools.pri b/tools/tools.pri new file mode 100644 index 000000000..818066245 --- /dev/null +++ b/tools/tools.pri @@ -0,0 +1,93 @@ +HEADERS += \ + tools/vtooldetail.h \ + tools/vdatatool.h \ + tools/vabstracttool.h \ + tools/tools.h \ + tools/drawTools/vtooltriangle.h \ + tools/drawTools/vtoolsplinepath.h \ + tools/drawTools/vtoolspline.h \ + tools/drawTools/vtoolsinglepoint.h \ + tools/drawTools/vtoolshoulderpoint.h \ + tools/drawTools/vtoolpointofintersection.h \ + tools/drawTools/vtoolpointofcontact.h \ + tools/drawTools/vtoolpoint.h \ + tools/drawTools/vtoolnormal.h \ + tools/drawTools/vtoollinepoint.h \ + tools/drawTools/vtoollineintersect.h \ + tools/drawTools/vtoolline.h \ + tools/drawTools/vtoolheight.h \ + tools/drawTools/vtoolendline.h \ + tools/drawTools/vtoolbisector.h \ + tools/drawTools/vtoolarc.h \ + tools/drawTools/vtoolalongline.h \ + tools/drawTools/vdrawtool.h \ + tools/drawTools/drawtools.h \ + tools/modelingTools/vmodelingtriangle.h \ + tools/modelingTools/vmodelingtool.h \ + tools/modelingTools/vmodelingsplinepath.h \ + tools/modelingTools/vmodelingspline.h \ + tools/modelingTools/vmodelingshoulderpoint.h \ + tools/modelingTools/vmodelingpointofintersection.h \ + tools/modelingTools/vmodelingpointofcontact.h \ + tools/modelingTools/vmodelingpoint.h \ + tools/modelingTools/vmodelingnormal.h \ + tools/modelingTools/vmodelinglinepoint.h \ + tools/modelingTools/vmodelinglineintersect.h \ + tools/modelingTools/vmodelingline.h \ + tools/modelingTools/vmodelingheight.h \ + tools/modelingTools/vmodelingendline.h \ + tools/modelingTools/vmodelingbisector.h \ + tools/modelingTools/vmodelingarc.h \ + tools/modelingTools/vmodelingalongline.h \ + tools/modelingTools/modelingtools.h \ + tools/nodeDetails/vnodesplinepath.h \ + tools/nodeDetails/vnodespline.h \ + tools/nodeDetails/vnodepoint.h \ + tools/nodeDetails/vnodearc.h \ + tools/nodeDetails/vabstractnode.h \ + tools/nodeDetails/nodedetails.h + +SOURCES += \ + tools/vtooldetail.cpp \ + tools/vdatatool.cpp \ + tools/vabstracttool.cpp \ + tools/drawTools/vtooltriangle.cpp \ + tools/drawTools/vtoolsplinepath.cpp \ + tools/drawTools/vtoolspline.cpp \ + tools/drawTools/vtoolsinglepoint.cpp \ + tools/drawTools/vtoolshoulderpoint.cpp \ + tools/drawTools/vtoolpointofintersection.cpp \ + tools/drawTools/vtoolpointofcontact.cpp \ + tools/drawTools/vtoolpoint.cpp \ + tools/drawTools/vtoolnormal.cpp \ + tools/drawTools/vtoollinepoint.cpp \ + tools/drawTools/vtoollineintersect.cpp \ + tools/drawTools/vtoolline.cpp \ + tools/drawTools/vtoolheight.cpp \ + tools/drawTools/vtoolendline.cpp \ + tools/drawTools/vtoolbisector.cpp \ + tools/drawTools/vtoolarc.cpp \ + tools/drawTools/vtoolalongline.cpp \ + tools/drawTools/vdrawtool.cpp \ + tools/modelingTools/vmodelingtriangle.cpp \ + tools/modelingTools/vmodelingtool.cpp \ + tools/modelingTools/vmodelingsplinepath.cpp \ + tools/modelingTools/vmodelingspline.cpp \ + tools/modelingTools/vmodelingshoulderpoint.cpp \ + tools/modelingTools/vmodelingpointofintersection.cpp \ + tools/modelingTools/vmodelingpointofcontact.cpp \ + tools/modelingTools/vmodelingpoint.cpp \ + tools/modelingTools/vmodelingnormal.cpp \ + tools/modelingTools/vmodelinglinepoint.cpp \ + tools/modelingTools/vmodelinglineintersect.cpp \ + tools/modelingTools/vmodelingline.cpp \ + tools/modelingTools/vmodelingheight.cpp \ + tools/modelingTools/vmodelingendline.cpp \ + tools/modelingTools/vmodelingbisector.cpp \ + tools/modelingTools/vmodelingarc.cpp \ + tools/modelingTools/vmodelingalongline.cpp \ + tools/nodeDetails/vnodesplinepath.cpp \ + tools/nodeDetails/vnodespline.cpp \ + tools/nodeDetails/vnodepoint.cpp \ + tools/nodeDetails/vnodearc.cpp \ + tools/nodeDetails/vabstractnode.cpp diff --git a/tools/vabstracttool.cpp b/tools/vabstracttool.cpp index 50838f4d7..0d52f3faf 100644 --- a/tools/vabstracttool.cpp +++ b/tools/vabstracttool.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vabstracttool.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,89 +24,108 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "vabstracttool.h" -#include -VAbstractTool::VAbstractTool(VDomDocument *doc, VContainer *data, qint64 id, QObject *parent): - VDataTool(data, parent), doc(doc), id(id), baseColor(Qt::black), currentColor(Qt::black){ +const QString VAbstractTool::AttrId = QStringLiteral("id"); +const QString VAbstractTool::AttrType = QStringLiteral("type"); +const QString VAbstractTool::AttrMx = QStringLiteral("mx"); +const QString VAbstractTool::AttrMy = QStringLiteral("my"); +const QString VAbstractTool::AttrName = QStringLiteral("name"); +const QString VAbstractTool::AttrX = QStringLiteral("x"); +const QString VAbstractTool::AttrY = QStringLiteral("y"); +const QString VAbstractTool::AttrTypeLine = QStringLiteral("typeLine"); +const QString VAbstractTool::AttrLength = QStringLiteral("length"); +const QString VAbstractTool::AttrBasePoint = QStringLiteral("basePoint"); +const QString VAbstractTool::AttrFirstPoint = QStringLiteral("firstPoint"); +const QString VAbstractTool::AttrSecondPoint = QStringLiteral("secondPoint"); +const QString VAbstractTool::AttrThirdPoint = QStringLiteral("thirdPoint"); +const QString VAbstractTool::AttrCenter = QStringLiteral("center"); +const QString VAbstractTool::AttrRadius = QStringLiteral("radius"); +const QString VAbstractTool::AttrAngle = QStringLiteral("angle"); +const QString VAbstractTool::AttrAngle1 = QStringLiteral("angle1"); +const QString VAbstractTool::AttrAngle2 = QStringLiteral("angle2"); +const QString VAbstractTool::AttrP1Line = QStringLiteral("p1Line"); +const QString VAbstractTool::AttrP2Line = QStringLiteral("p2Line"); +const QString VAbstractTool::AttrP1Line1 = QStringLiteral("p1Line1"); +const QString VAbstractTool::AttrP2Line1 = QStringLiteral("p2Line1"); +const QString VAbstractTool::AttrP1Line2 = QStringLiteral("p1Line2"); +const QString VAbstractTool::AttrP2Line2 = QStringLiteral("p2Line2"); +const QString VAbstractTool::AttrPShoulder = QStringLiteral("pShoulder"); +const QString VAbstractTool::AttrPoint1 = QStringLiteral("point1"); +const QString VAbstractTool::AttrPoint4 = QStringLiteral("point4"); +const QString VAbstractTool::AttrKAsm1 = QStringLiteral("kAsm1"); +const QString VAbstractTool::AttrKAsm2 = QStringLiteral("kAsm2"); +const QString VAbstractTool::AttrKCurve = QStringLiteral("kCurve"); +const QString VAbstractTool::AttrPathPoint = QStringLiteral("pathPoint"); +const QString VAbstractTool::AttrPSpline = QStringLiteral("pSpline"); +const QString VAbstractTool::AttrAxisP1 = QStringLiteral("axisP1"); +const QString VAbstractTool::AttrAxisP2 = QStringLiteral("axisP2"); +const QString VAbstractTool::TypeLineNone = QStringLiteral("none"); +const QString VAbstractTool::TypeLineLine = QStringLiteral("hair"); +VAbstractTool::VAbstractTool(VDomDocument *doc, VContainer *data, qint64 id, QObject *parent) + :VDataTool(data, parent), doc(doc), id(id), baseColor(Qt::black), currentColor(Qt::black) +{ connect(this, &VAbstractTool::toolhaveChange, this->doc, &VDomDocument::haveLiteChange); connect(this->doc, &VDomDocument::FullUpdateFromFile, this, &VAbstractTool::FullUpdateFromFile); connect(this, &VAbstractTool::FullUpdateTree, this->doc, &VDomDocument::FullUpdateTree); } -void VAbstractTool::AddAttribute(QDomElement &domElement, const QString &name, const qint64 &value){ - QDomAttr domAttr = doc->createAttribute(name); - domAttr.setValue(QString().setNum(value)); - domElement.setAttributeNode(domAttr); -} - -void VAbstractTool::AddAttribute(QDomElement &domElement, const QString &name, const qint32 &value){ - QDomAttr domAttr = doc->createAttribute(name); - domAttr.setValue(QString().setNum(value)); - domElement.setAttributeNode(domAttr); -} - -void VAbstractTool::AddAttribute(QDomElement &domElement, const QString &name, const qreal &value){ - QDomAttr domAttr = doc->createAttribute(name); - domAttr.setValue(QString().setNum(value)); - domElement.setAttributeNode(domAttr); -} - -void VAbstractTool::AddAttribute(QDomElement &domElement, const QString &name, const QString &value){ - QDomAttr domAttr = doc->createAttribute(name); - domAttr.setValue(value); - domElement.setAttributeNode(domAttr); -} - -VAbstractTool::~VAbstractTool(){ -} - -QPointF VAbstractTool::LineIntersectRect(QRectF rec, QLineF line){ +QPointF VAbstractTool::LineIntersectRect(QRectF rec, QLineF line) +{ qreal x1, y1, x2, y2; rec.getCoords(&x1, &y1, &x2, &y2); QPointF point; - QLineF::IntersectType type = line.intersect(QLineF(QPointF(x1,y1), QPointF(x1,y2)),&point); - if ( type == QLineF::BoundedIntersection ){ + QLineF::IntersectType type = line.intersect(QLineF(QPointF(x1, y1), QPointF(x1, y2)), &point); + if ( type == QLineF::BoundedIntersection ) + { return point; } - type = line.intersect(QLineF(QPointF(x1,y1), QPointF(x2,y1)),&point); - if ( type == QLineF::BoundedIntersection ){ + type = line.intersect(QLineF(QPointF(x1, y1), QPointF(x2, y1)), &point); + if ( type == QLineF::BoundedIntersection ) + { return point; } - type = line.intersect(QLineF(QPointF(x1,y2), QPointF(x2,y2)),&point); - if ( type == QLineF::BoundedIntersection ){ + type = line.intersect(QLineF(QPointF(x1, y2), QPointF(x2, y2)), &point); + if ( type == QLineF::BoundedIntersection ) + { return point; } - type = line.intersect(QLineF(QPointF(x2,y1), QPointF(x2,y2)),&point); - if ( type == QLineF::BoundedIntersection ){ + type = line.intersect(QLineF(QPointF(x2, y1), QPointF(x2, y2)), &point); + if ( type == QLineF::BoundedIntersection ) + { return point; } - Q_ASSERT_X(type != QLineF::BoundedIntersection, Q_FUNC_INFO, "Немає точки перетину."); + Q_ASSERT_X(type != QLineF::BoundedIntersection, Q_FUNC_INFO, "There is no point of intersection."); return point; } -qint32 VAbstractTool::LineIntersectCircle(QPointF center, qreal radius, QLineF line, QPointF &p1, - QPointF &p2){ +qint32 VAbstractTool::LineIntersectCircle(const QPointF ¢er, qreal radius, const QLineF &line, QPointF &p1, + 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); // сколько всего решений? qint32 flag = 0; qreal d = QLineF (center, p).length(); - if (qAbs (d - radius) <= eps){ + if (qAbs (d - radius) <= eps) + { flag = 1; - } else { - if (radius > d){ + } + else + { + if (radius > d) + { flag = 2; - } else { + } + else + { return 0; } } @@ -112,32 +138,50 @@ qint32 VAbstractTool::LineIntersectCircle(QPointF center, qreal radius, QLineF l return flag; } -QPointF VAbstractTool::ClosestPoint(QLineF line, QPointF p){ +QPointF VAbstractTool::ClosestPoint(const QLineF &line, const QPointF &p) +{ QLineF lineP2pointFrom = QLineF(line.p2(), p); qreal angle = 180-line.angleTo(lineP2pointFrom)-90; QLineF pointFromlineP2 = QLineF(p, line.p2()); pointFromlineP2.setAngle(pointFromlineP2.angle()+angle); QPointF point; - QLineF::IntersectType type = pointFromlineP2.intersect(line,&point); - if ( type == QLineF::BoundedIntersection ){ + QLineF::IntersectType type = pointFromlineP2.intersect(line, &point); + if ( type == QLineF::BoundedIntersection ) + { return point; - } else{ - if ( type == QLineF::NoIntersection || type == QLineF::UnboundedIntersection ){ - Q_ASSERT_X(type != QLineF::BoundedIntersection, Q_FUNC_INFO, "Немає точки перетину."); + } + else + { + if ( type == QLineF::NoIntersection || type == QLineF::UnboundedIntersection ) + { + Q_ASSERT_X(type != QLineF::BoundedIntersection, Q_FUNC_INFO, "Don't have point of intersection."); return point; } } return point; } -QPointF VAbstractTool::addVector(QPointF p, QPointF p1, QPointF p2, qreal k){ +QPointF VAbstractTool::addVector(const QPointF &p, const QPointF &p1, const QPointF &p2, qreal k) +{ return QPointF (p.x() + (p2.x() - p1.x()) * k, p.y() + (p2.y() - p1.y()) * k); } -const VContainer *VAbstractTool::getData()const{ - return &data; +void VAbstractTool::RemoveAllChild(QDomElement &domElement) +{ + if ( domElement.hasChildNodes() ) + { + while ( domElement.childNodes().length() >= 1 ) + { + domElement.removeChild( domElement.firstChild() ); + } + } } -qint64 VAbstractTool::getId() const{ - return id; +void VAbstractTool::LineCoefficients(const QLineF &line, qreal *a, qreal *b, qreal *c) +{ + //коефіцієнти для рівняння відрізку + QPointF p1 = line.p1(); + *a = line.p2().y() - p1.y(); + *b = p1.x() - line.p2().x(); + *c = - *a * p1.x() - *b * p1.y(); } diff --git a/tools/vabstracttool.h b/tools/vabstracttool.h index 2391e053b..f3a2ea372 100644 --- a/tools/vabstracttool.h +++ b/tools/vabstracttool.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vabstracttool.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,45 +24,95 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef VABSTRACTTOOL_H #define VABSTRACTTOOL_H -#include "xml/vdomdocument.h" #include "vdatatool.h" +#include "../xml/vdomdocument.h" -class VAbstractTool: public VDataTool{ +class VAbstractTool: public VDataTool +{ Q_OBJECT public: - VAbstractTool(VDomDocument *doc, VContainer *data, qint64 id, QObject *parent = 0); - virtual ~VAbstractTool(); - static QPointF LineIntersectRect(QRectF rec, QLineF line); - static qint32 LineIntersectCircle(QPointF center, qreal radius, QLineF line, QPointF &p1, - QPointF &p2); - static QPointF ClosestPoint(QLineF line, QPointF p); - static QPointF addVector (QPointF p, QPointF p1, QPointF p2, qreal k); - qint64 getId() const; - + VAbstractTool(VDomDocument *doc, VContainer *data, qint64 id, QObject *parent = 0); + virtual ~VAbstractTool() {} + static QPointF LineIntersectRect(QRectF rec, QLineF line); + static qint32 LineIntersectCircle(const QPointF ¢er, qreal radius, const QLineF &line, QPointF &p1, + QPointF &p2); + static QPointF ClosestPoint(const QLineF &line, const QPointF &p); + static QPointF addVector (const QPointF &p, const QPointF &p1, const QPointF &p2, qreal k); + inline qint64 getId() const {return id;} + static void LineCoefficients(const QLineF &line, qreal *a, qreal *b, qreal *c); + static const QString AttrId; + static const QString AttrType; + static const QString AttrMx; + static const QString AttrMy; + static const QString AttrName; + static const QString AttrX; + static const QString AttrY; + static const QString AttrTypeLine; + static const QString AttrLength; + static const QString AttrBasePoint; + static const QString AttrFirstPoint; + static const QString AttrSecondPoint; + static const QString AttrThirdPoint; + static const QString AttrCenter; + static const QString AttrRadius; + static const QString AttrAngle; + static const QString AttrAngle1; + static const QString AttrAngle2; + static const QString AttrP1Line; + static const QString AttrP2Line; + static const QString AttrP1Line1; + static const QString AttrP2Line1; + static const QString AttrP1Line2; + static const QString AttrP2Line2; + static const QString AttrPShoulder; + static const QString AttrPoint1; + static const QString AttrPoint4; + static const QString AttrKAsm1; + static const QString AttrKAsm2; + static const QString AttrKCurve; + static const QString AttrPathPoint; + static const QString AttrPSpline; + static const QString AttrAxisP1; + static const QString AttrAxisP2; + static const QString TypeLineNone; + static const QString TypeLineLine; public slots: - virtual void FullUpdateFromFile()=0; + virtual void FullUpdateFromFile()=0; signals: - void toolhaveChange(); - void ChoosedTool(qint64 id, Scene::Scenes type); - void FullUpdateTree(); + void toolhaveChange(); + void ChoosedTool(qint64 id, Scene::Scenes type); + void FullUpdateTree(); + void RemoveTool(QGraphicsItem *tool); protected: - VDomDocument *doc; - const qint64 id; - const Qt::GlobalColor baseColor; - Qt::GlobalColor currentColor; - virtual void AddToFile()=0; - void AddAttribute(QDomElement &domElement, const QString &name, const qint64 &value); - void AddAttribute(QDomElement &domElement, const QString &name, const qint32 &value); - void AddAttribute(QDomElement &domElement, const QString &name, const qreal &value); - void AddAttribute(QDomElement &domElement, const QString &name, const QString &value); - const VContainer *getData() const; - virtual void RemoveReferens(){} + VDomDocument *doc; + const qint64 id; + const Qt::GlobalColor baseColor; + Qt::GlobalColor currentColor; + virtual void AddToFile()=0; + inline const VContainer *getData() const {return &data;} + virtual void RemoveReferens(){} + void RemoveAllChild(QDomElement &domElement); + template + void AddAttribute(QDomElement &domElement, const QString &name, const T &value) + { + QDomAttr domAttr = doc->createAttribute(name); + domAttr.setValue(QString().setNum(value)); + domElement.setAttributeNode(domAttr); + } private: Q_DISABLE_COPY(VAbstractTool) }; + +template <> +inline void VAbstractTool::AddAttribute(QDomElement &domElement, const QString &name, const QString &value) +{ + QDomAttr domAttr = doc->createAttribute(name); + domAttr.setValue(value); + domElement.setAttributeNode(domAttr); +} #endif // VABSTRACTTOOL_H diff --git a/tools/vdatatool.cpp b/tools/vdatatool.cpp index eb5d6cf20..58a6eb39f 100644 --- a/tools/vdatatool.cpp +++ b/tools/vdatatool.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vdatatool.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,22 +24,21 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "vdatatool.h" -VDataTool &VDataTool::operator =(const VDataTool &tool){ +VDataTool &VDataTool::operator =(const VDataTool &tool) +{ data = tool.getData(); _referens = tool.referens(); return *this; } -void VDataTool::setData(const VContainer *value){ - data = *value; -} - -void VDataTool::decrementReferens(){ - if(_referens > 0){ +void VDataTool::decrementReferens() +{ + if (_referens > 0) + { --_referens; } } diff --git a/tools/vdatatool.h b/tools/vdatatool.h index eed3f4e60..86d0b2927 100644 --- a/tools/vdatatool.h +++ b/tools/vdatatool.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vdatatool.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,23 +24,23 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef VDATATOOL_H #define VDATATOOL_H -#include "container/vcontainer.h" +#include "../container/vcontainer.h" //We need QObject class because we use qobject_cast. -class VDataTool : public QObject{ +class VDataTool : public QObject +{ Q_OBJECT public: - explicit VDataTool(VContainer *data, QObject *parent = 0) - : QObject(parent), data(*data), _referens(1){} + VDataTool(VContainer *data, QObject *parent = 0): QObject(parent), data(*data), _referens(1){} virtual ~VDataTool(){} VDataTool &operator= (const VDataTool &tool); inline VContainer getData() const { return data; } - void setData(const VContainer *value); + inline void setData(const VContainer *value) {data = *value;} virtual inline qint64 referens() const {return _referens;} virtual inline void incrementReferens(){++_referens;} virtual void decrementReferens(); diff --git a/tools/vgraphicspoint.cpp b/tools/vgraphicspoint.cpp deleted file mode 100644 index df82f6f1e..000000000 --- a/tools/vgraphicspoint.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include "vgraphicspoint.h" -#include "options.h" - -VGraphicsPoint::VGraphicsPoint(QGraphicsItem *parent): QGraphicsEllipseItem(parent), - radius(toPixel(1.5)), namePoint(0), lineName(0){ - //namePoint = new VGraphicsSimpleTextItem(this); - lineName = new QGraphicsLineItem(this); - this->setPen(QPen(Qt::black, widthHairLine)); - this->setBrush(QBrush(Qt::NoBrush)); - this->setFlag(QGraphicsItem::ItemIsSelectable, true); - this->setAcceptHoverEvents(true); -} - -VGraphicsPoint::~VGraphicsPoint(){ -} - - -void VGraphicsPoint::RefreshLine(){ - QRectF nameRec = namePoint->sceneBoundingRect(); - QPointF p1, p2; - LineIntersectCircle(QPointF(), radius, QLineF(QPointF(), nameRec.center()- scenePos()), p1, p2); - QPointF pRec = LineIntersectRect(nameRec, QLineF(scenePos(), nameRec.center())); - lineName->setLine(QLineF(p1, pRec - scenePos())); - if(QLineF(p1, pRec - scenePos()).length() <= toPixel(4)){ - lineName->setVisible(false); - } else { - lineName->setVisible(true); - } -} - -void VGraphicsPoint::hoverMoveEvent(QGraphicsSceneHoverEvent *event){ - Q_UNUSED(event); - this->setPen(QPen(Qt::black, widthMainLine)); -} - -void VGraphicsPoint::hoverLeaveEvent(QGraphicsSceneHoverEvent *event){ - Q_UNUSED(event); - this->setPen(QPen(Qt::black, widthHairLine)); -} diff --git a/tools/vgraphicspoint.h b/tools/vgraphicspoint.h deleted file mode 100644 index 4bd108524..000000000 --- a/tools/vgraphicspoint.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef VGRAPHICSPOINT_H -#define VGRAPHICSPOINT_H - -#include -#include -#include "widgets/vgraphicssimpletextitem.h" -#include "../container/vpointf.h" - -class VGraphicsPoint: public QGraphicsEllipseItem -{ -public: - VGraphicsPoint(QGraphicsItem *parent); - virtual ~VGraphicsPoint(); -public slots: - virtual void NameChangePosition(const QPointF pos)=0; -protected: - qreal radius; - VGraphicsSimpleTextItem *namePoint; - QGraphicsLineItem *lineName; - virtual void UpdateNamePosition(qreal mx, qreal my)=0; - void RefreshLine(); - virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); - virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); - virtual void RefreshPointGeometry(const VPointF &point)=0; -private: - VGraphicsPoint(const VGraphicsPoint &point); - const VGraphicsPoint &operator=(const VGraphicsPoint &point); - QPointF LineIntersectRect(QRectF rec, QLineF line) const; - qint32 LineIntersectCircle(QPointF center, qreal radius, QLineF line, QPointF &p1, - QPointF &p2) const; - QPointF ClosestPoint(QLineF line, QPointF p) const; - QPointF addVector (QPointF p, QPointF p1, QPointF p2, qreal k) const; -}; - -#endif // VGRAPHICSPOINT_H diff --git a/tools/vtooldetail.cpp b/tools/vtooldetail.cpp index c69be08b0..3556182cf 100644 --- a/tools/vtooldetail.cpp +++ b/tools/vtooldetail.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vtooldetail.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,142 +24,90 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "vtooldetail.h" #include "nodeDetails/nodedetails.h" -#include #include "modelingTools/vmodelingtool.h" #include "modelingTools/modelingtools.h" -VToolDetail::VToolDetail(VDomDocument *doc, VContainer *data, const qint64 &id, Tool::Sources typeCreation, +const QString VToolDetail::TagName = QStringLiteral("detail"); +const QString VToolDetail::TagNode = QStringLiteral("node"); +const QString VToolDetail::AttrSupplement = QStringLiteral("supplement"); +const QString VToolDetail::AttrClosed = QStringLiteral("closed"); +const QString VToolDetail::AttrWidth = QStringLiteral("width"); +const QString VToolDetail::AttrIdObject = QStringLiteral("idObject"); +const QString VToolDetail::AttrNodeType = QStringLiteral("nodeType"); +const QString VToolDetail::NodeTypeContour = QStringLiteral("Contour"); +const QString VToolDetail::NodeTypeModeling = QStringLiteral("Modeling"); + +VToolDetail::VToolDetail(VDomDocument *doc, VContainer *data, const qint64 &id, const Tool::Sources &typeCreation, VMainGraphicsScene *scene, QGraphicsItem *parent) :VAbstractTool(doc, data, id), QGraphicsPathItem(parent), dialogDetail(QSharedPointer()), - sceneDetails(scene){ + sceneDetails(scene) +{ VDetail detail = data->GetDetail(id); - QHash* tools = doc->getTools(); - Q_CHECK_PTR(tools); - for(qint32 i = 0; i< detail.CountNode(); ++i){ - switch(detail[i].getTypeTool()){ - case(Tool::NodePoint):{ - VNodePoint *point = qobject_cast(tools->value(detail[i].getId())); - Q_CHECK_PTR(point); - connect(point, &VNodePoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); - point->setParentItem(this); - break; - } - case(Tool::NodeArc):{ - VNodeArc *arc = qobject_cast(tools->value(detail[i].getId())); - Q_CHECK_PTR(arc); - connect(arc, &VNodeArc::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); - arc->setParentItem(this); - break; - } - case(Tool::NodeSpline):{ - VNodeSpline *spl = qobject_cast(tools->value(detail[i].getId())); - Q_CHECK_PTR(spl); - connect(spl, &VNodeSpline::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); - spl->setParentItem(this); - break; - } - case(Tool::NodeSplinePath):{ - VNodeSplinePath *splPath = qobject_cast(tools->value(detail[i].getId())); - Q_CHECK_PTR(splPath); - connect(splPath, &VNodeSplinePath::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); - splPath->setParentItem(this); - break; - } - case(Tool::AlongLineTool):{ - VModelingAlongLine *tool = qobject_cast(tools->value(detail[i].getId())); - Q_CHECK_PTR(tool); - connect(tool, &VModelingAlongLine::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); - connect(tool, &VModelingAlongLine::RemoveTool, scene, &VMainGraphicsScene::RemoveTool); - tool->setParentItem(this); - break; - } - case(Tool::ArcTool):{ - VModelingArc *tool = qobject_cast(tools->value(detail[i].getId())); - Q_CHECK_PTR(tool); - connect(tool, &VModelingArc::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); - connect(tool, &VModelingArc::RemoveTool, scene, &VMainGraphicsScene::RemoveTool); - tool->setParentItem(this); - break; - } - case(Tool::BisectorTool):{ - VModelingBisector *tool = qobject_cast(tools->value(detail[i].getId())); - Q_CHECK_PTR(tool); - connect(tool, &VModelingBisector::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); - connect(tool, &VModelingBisector::RemoveTool, scene, &VMainGraphicsScene::RemoveTool); - tool->setParentItem(this); - break; - } - case(Tool::EndLineTool):{ - VModelingEndLine *tool = qobject_cast(tools->value(detail[i].getId())); - Q_CHECK_PTR(tool); - connect(tool, &VModelingEndLine::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); - connect(tool, &VModelingEndLine::RemoveTool, scene, &VMainGraphicsScene::RemoveTool); - tool->setParentItem(this); - break; - } - case(Tool::LineIntersectTool):{ - VModelingLineIntersect *tool = qobject_cast(tools->value(detail[i].getId())); - Q_CHECK_PTR(tool); - connect(tool, &VModelingLineIntersect::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); - connect(tool, &VModelingLineIntersect::RemoveTool, scene, &VMainGraphicsScene::RemoveTool); - tool->setParentItem(this); - break; - } - case(Tool::LineTool):{ - VModelingLine *tool = qobject_cast(tools->value(detail[i].getId())); - Q_CHECK_PTR(tool); - connect(tool, &VModelingLine::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); - connect(tool, &VModelingLine::RemoveTool, scene, &VMainGraphicsScene::RemoveTool); - tool->setParentItem(this); - break; - } - case(Tool::NormalTool):{ - VModelingNormal *tool = qobject_cast(tools->value(detail[i].getId())); - Q_CHECK_PTR(tool); - connect(tool, &VModelingNormal::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); - connect(tool, &VModelingNormal::RemoveTool, scene, &VMainGraphicsScene::RemoveTool); - tool->setParentItem(this); - break; - } - case(Tool::PointOfContact):{ - VModelingPointOfContact *tool = qobject_cast(tools->value(detail[i].getId())); - Q_CHECK_PTR(tool); - connect(tool, &VModelingPointOfContact::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); - connect(tool, &VModelingPointOfContact::RemoveTool, scene, &VMainGraphicsScene::RemoveTool); - tool->setParentItem(this); - break; - } - case(Tool::ShoulderPointTool):{ - VModelingShoulderPoint *tool = qobject_cast(tools->value(detail[i].getId())); - Q_CHECK_PTR(tool); - connect(tool, &VModelingShoulderPoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); - connect(tool, &VModelingShoulderPoint::RemoveTool, scene, &VMainGraphicsScene::RemoveTool); - tool->setParentItem(this); - break; - } - case(Tool::SplinePathTool):{ - VModelingSplinePath *tool = qobject_cast(tools->value(detail[i].getId())); - Q_CHECK_PTR(tool); - connect(tool, &VModelingSplinePath::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); - connect(tool, &VModelingSplinePath::RemoveTool, scene, &VMainGraphicsScene::RemoveTool); - tool->setParentItem(this); - break; - } - case(Tool::SplineTool):{ - VModelingSpline *tool = qobject_cast(tools->value(detail[i].getId())); - Q_CHECK_PTR(tool); - connect(tool, &VModelingSpline::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); - connect(tool, &VModelingSpline::RemoveTool, scene, &VMainGraphicsScene::RemoveTool); - tool->setParentItem(this); - break; - } - default: - qWarning()<<"Get wrong tool type. Ignore."; - break; + for (ptrdiff_t i = 0; i< detail.CountNode(); ++i) + { + switch (detail[i].getTypeTool()) + { + case (Tool::NodePoint): + InitTool(scene, detail[i]); + break; + case (Tool::NodeArc): + InitTool(scene, detail[i]); + break; + case (Tool::NodeSpline): + InitTool(scene, detail[i]); + break; + case (Tool::NodeSplinePath): + InitTool(scene, detail[i]); + break; + case (Tool::AlongLineTool): + InitTool(scene, detail[i]); + break; + case (Tool::ArcTool): + InitTool(scene, detail[i]); + break; + case (Tool::BisectorTool): + InitTool(scene, detail[i]); + break; + case (Tool::EndLineTool): + InitTool(scene, detail[i]); + break; + case (Tool::LineIntersectTool): + InitTool(scene, detail[i]); + break; + case (Tool::LineTool): + InitTool(scene, detail[i]); + break; + case (Tool::NormalTool): + InitTool(scene, detail[i]); + break; + case (Tool::PointOfContact): + InitTool(scene, detail[i]); + break; + case (Tool::ShoulderPointTool): + InitTool(scene, detail[i]); + break; + case (Tool::SplinePathTool): + InitTool(scene, detail[i]); + break; + case (Tool::SplineTool): + InitTool(scene, detail[i]); + break; + case (Tool::Height): + InitTool(scene, detail[i]); + break; + case (Tool::Triangle): + InitTool(scene, detail[i]); + break; + case (Tool::PointOfIntersection): + InitTool(scene, detail[i]); + break; + default: + qWarning()<<"Get wrong tool type. Ignore."; + break; } doc->IncrementReferens(detail[i].getId()); } @@ -161,79 +116,98 @@ VToolDetail::VToolDetail(VDomDocument *doc, VContainer *data, const qint64 &id, RefreshGeometry(); this->setPos(detail.getMx(), detail.getMy()); this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); - if(typeCreation == Tool::FromGui){ + if (typeCreation == Tool::FromGui) + { AddToFile(); } } -void VToolDetail::setDialog(){ - Q_ASSERT(!dialogDetail.isNull()); - if(!dialogDetail.isNull()){ - VDetail detail = VAbstractTool::data.GetDetail(id); - dialogDetail->setDetails(detail); - } +void VToolDetail::setDialog() +{ + Q_ASSERT(dialogDetail.isNull() == false); + VDetail detail = VAbstractTool::data.GetDetail(id); + dialogDetail->setDetails(detail); } -void VToolDetail::Create(QSharedPointer &dialog, VMainGraphicsScene *scene, - VDomDocument *doc, VContainer *data){ +void VToolDetail::Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, + VContainer *data) +{ VDetail detail = dialog->getDetails(); VDetail det; - for(qint32 i = 0; i< detail.CountNode(); ++i){ + for (ptrdiff_t i = 0; i< detail.CountNode(); ++i) + { qint64 id = 0; - switch(detail[i].getTypeTool()){ - case(Tool::NodePoint):{ - VPointF point; - if(detail[i].getMode() == Draw::Calculation){ - point = data->GetPoint(detail[i].getId()); - } else { - point = data->GetModelingPoint(detail[i].getId()); + switch (detail[i].getTypeTool()) + { + case (Tool::NodePoint): + { + VPointF point; + if (detail[i].getMode() == Draw::Calculation) + { + point = data->GetPoint(detail[i].getId()); + } + else + { + point = data->GetModelingPoint(detail[i].getId()); + } + id = data->AddModelingPoint(point); + VNodePoint::Create(doc, data, id, detail[i].getId(), detail[i].getMode(), + Document::FullParse, Tool::FromGui); } - id = data->AddModelingPoint(point); - VNodePoint::Create(doc, data, id, detail[i].getId(), detail[i].getMode(), - Document::FullParse, Tool::FromGui); - } break; - case(Tool::NodeArc):{ - VArc arc; - if(detail[i].getMode() == Draw::Calculation){ - arc = data->GetArc(detail[i].getId()); - } else { - arc = data->GetModelingArc(detail[i].getId()); + case (Tool::NodeArc): + { + VArc arc; + if (detail[i].getMode() == Draw::Calculation) + { + arc = data->GetArc(detail[i].getId()); + } + else + { + arc = data->GetModelingArc(detail[i].getId()); + } + id = data->AddModelingArc(arc); + VNodeArc::Create(doc, data, id, detail[i].getId(), detail[i].getMode(), + Document::FullParse, Tool::FromGui); } - id = data->AddModelingArc(arc); - VNodeArc::Create(doc, data, id, detail[i].getId(), detail[i].getMode(), - Document::FullParse, Tool::FromGui); - } break; - case(Tool::NodeSpline):{ - VSpline spline; - if(detail[i].getMode() == Draw::Calculation){ - spline = data->GetSpline(detail[i].getId()); - } else { - spline = data->GetModelingSpline(detail[i].getId()); - } - id = data->AddModelingSpline(spline); - VNodeSpline::Create(doc, data, id, detail[i].getId(), detail[i].getMode(), - Document::FullParse, Tool::FromGui); - } - break; - case(Tool::NodeSplinePath):{ - VSplinePath splinePath; - if(detail[i].getMode() == Draw::Calculation){ - splinePath = data->GetSplinePath(detail[i].getId()); - } else { - splinePath = data->GetModelingSplinePath(detail[i].getId()); - } - id = data->AddModelingSplinePath(splinePath); - VNodeSplinePath::Create(doc, data, id, detail[i].getId(), detail[i].getMode(), + case (Tool::NodeSpline): + { + VSpline spline; + if (detail[i].getMode() == Draw::Calculation) + { + spline = data->GetSpline(detail[i].getId()); + } + else + { + spline = data->GetModelingSpline(detail[i].getId()); + } + id = data->AddModelingSpline(spline); + VNodeSpline::Create(doc, data, id, detail[i].getId(), detail[i].getMode(), Document::FullParse, Tool::FromGui); - } + } break; - default: - qWarning()<<"May be wrong tool type!!! Ignoring."<GetSplinePath(detail[i].getId()); + } + else + { + splinePath = data->GetModelingSplinePath(detail[i].getId()); + } + id = data->AddModelingSplinePath(splinePath); + VNodeSplinePath::Create(doc, data, id, detail[i].getId(), detail[i].getMode(), + Document::FullParse, Tool::FromGui); + } break; + default: + qWarning()<<"May be wrong tool type!!! Ignoring."< &dialog, VMainGraphicsScen } void VToolDetail::Create(const qint64 _id, VDetail &newDetail, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data, const Document::Documents &parse, Tool::Sources typeCreation){ + VContainer *data, const Document::Documents &parse, const Tool::Sources &typeCreation) +{ qint64 id = _id; - if(typeCreation == Tool::FromGui){ + if (typeCreation == Tool::FromGui) + { id = data->AddDetail(newDetail); - } else { + } + else + { data->UpdateDetail(id, newDetail); - if(parse != Document::FullParse){ + if (parse != Document::FullParse) + { doc->UpdateToolData(id, data); } } - if(parse == Document::FullParse){ + if (parse == Document::FullParse) + { VToolDetail *detail = new VToolDetail(doc, data, id, typeCreation, scene); scene->addItem(detail); connect(detail, &VToolDetail::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); @@ -261,43 +241,72 @@ void VToolDetail::Create(const qint64 _id, VDetail &newDetail, VMainGraphicsScen } } -void VToolDetail::FullUpdateFromFile(){ +void VToolDetail::FullUpdateFromFile() +{ RefreshGeometry(); } -void VToolDetail::FullUpdateFromGui(int result){ - Q_UNUSED(result); +void VToolDetail::FullUpdateFromGui(int result) +{ + if (result == QDialog::Accepted) + { + QDomElement domElement = doc->elementById(QString().setNum(id)); + if (domElement.isElement()) + { + VDetail det = dialogDetail->getDetails(); + domElement.setAttribute(AttrName, det.getName()); + domElement.setAttribute(AttrSupplement, QString().setNum(det.getSupplement())); + domElement.setAttribute(AttrClosed, QString().setNum(det.getClosed())); + domElement.setAttribute(AttrWidth, QString().setNum(det.getWidth())); + RemoveAllChild(domElement); + for (ptrdiff_t i = 0; i < det.CountNode(); ++i) + { + AddNode(domElement, det[i]); + } + emit FullUpdateTree(); + } + } + dialogDetail.clear(); } -void VToolDetail::AddToFile(){ +void VToolDetail::AddToFile() +{ VDetail detail = VAbstractTool::data.GetDetail(id); - QDomElement domElement = doc->createElement("detail"); + QDomElement domElement = doc->createElement(TagName); - AddAttribute(domElement, "id", id); - AddAttribute(domElement, "name", detail.getName()); - AddAttribute(domElement, "mx", detail.getMx()); - AddAttribute(domElement, "my", detail.getMy()); + AddAttribute(domElement, AttrId, id); + AddAttribute(domElement, AttrName, detail.getName()); + AddAttribute(domElement, AttrMx, toMM(detail.getMx())); + AddAttribute(domElement, AttrMy, toMM(detail.getMy())); + AddAttribute(domElement, AttrSupplement, detail.getSupplement()); + AddAttribute(domElement, AttrClosed, detail.getClosed()); + AddAttribute(domElement, AttrWidth, detail.getWidth()); - for(qint32 i = 0; i < detail.CountNode(); ++i){ + for (ptrdiff_t i = 0; i < detail.CountNode(); ++i) + { AddNode(domElement, detail[i]); } QDomElement element; bool ok = doc->GetActivDetailsElement(element); - if(ok){ + if (ok) + { element.appendChild(domElement); } } -QVariant VToolDetail::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value){ - if (change == ItemPositionHasChanged && scene()) { +QVariant VToolDetail::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) +{ + if (change == ItemPositionHasChanged && scene()) + { // value - это новое положение. QPointF newPos = value.toPointF(); //qDebug()<elementById(QString().setNum(id)); - if(domElement.isElement()){ - domElement.setAttribute("mx", QString().setNum(toMM(newPos.x()))); - domElement.setAttribute("my", QString().setNum(toMM(newPos.y()))); + if (domElement.isElement()) + { + domElement.setAttribute(AttrMx, QString().setNum(toMM(newPos.x()))); + domElement.setAttribute(AttrMy, QString().setNum(toMM(newPos.y()))); //I don't now why but signal does not work. doc->FullUpdateTree(); } @@ -305,43 +314,47 @@ QVariant VToolDetail::itemChange(QGraphicsItem::GraphicsItemChange change, const return QGraphicsItem::itemChange(change, value); } -void VToolDetail::mouseReleaseEvent(QGraphicsSceneMouseEvent *event){ - if(event->button() == Qt::LeftButton){ +void VToolDetail::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +{ + if (event->button() == Qt::LeftButton) + { emit ChoosedTool(id, Scene::Detail); } QGraphicsItem::mouseReleaseEvent(event); } -void VToolDetail::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ +void VToolDetail::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) +{ QMenu menu; - //QAction *actionOption = menu.addAction(tr("Options")); + QAction *actionOption = menu.addAction(tr("Options")); QAction *actionRemove = menu.addAction(tr("Delete")); - if(_referens > 1){ + if (_referens > 1) + { actionRemove->setEnabled(false); - } else { + } + else + { actionRemove->setEnabled(true); } QAction *selectedAction = menu.exec(event->screenPos()); -// if(selectedAction == actionOption){ -// dialog = QSharedPointer(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); - -// tool->setDialog(); - -// dialog->show(); -// } - if(selectedAction == actionRemove){ - + if (selectedAction == actionOption) + { + dialogDetail = QSharedPointer(new DialogDetail(getData(), Draw::Modeling)); + connect(qobject_cast< VMainGraphicsScene * >(this->scene()), &VMainGraphicsScene::ChoosedObject, + dialogDetail.data(), &DialogDetail::ChoosedObject); + connect(dialogDetail.data(), &DialogDetail::DialogClosed, this, &VToolDetail::FullUpdateFromGui); + setDialog(); + dialogDetail->show(); + } + if (selectedAction == actionRemove) + { //remove form xml file QDomElement domElement = doc->elementById(QString().setNum(id)); - if(domElement.isElement()){ + if (domElement.isElement()) + { QDomNode element = domElement.parentNode(); - if(!element.isNull()){ + if (element.isNull() == false) + { //deincrement referens RemoveReferens(); element.removeChild(domElement); @@ -349,85 +362,120 @@ void VToolDetail::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ emit FullUpdateTree(); //remove form scene emit RemoveTool(this); - } else { + } + else + { qWarning()<<"parentNode isNull"<createElement(TagNode); - AddAttribute(nod, "idObject", node.getId()); - if(node.getTypeNode() == NodeDetail::Contour){ - AddAttribute(nod, "nodeType", "Contour"); - } else { - AddAttribute(nod, "nodeType", "Modeling"); + AddAttribute(nod, AttrIdObject, node.getId()); + AddAttribute(nod, AttrMx, toMM(node.getMx())); + AddAttribute(nod, AttrMy, toMM(node.getMy())); + if (node.getTypeNode() == NodeDetail::Contour) + { + AddAttribute(nod, AttrNodeType, NodeTypeContour); } - switch(node.getTypeTool()){ - case(Tool::AlongLineTool): - AddAttribute(nod, "type", "AlongLineTool"); - break; - case(Tool::ArcTool): - AddAttribute(nod, "type", "ArcTool"); - break; - case(Tool::BisectorTool): - AddAttribute(nod, "type", "BisectorTool"); - break; - case(Tool::EndLineTool): - AddAttribute(nod, "type", "EndLineTool"); - break; - case(Tool::LineIntersectTool): - AddAttribute(nod, "type", "LineIntersectTool"); - break; - case(Tool::LineTool): - AddAttribute(nod, "type", "LineTool"); - break; - case(Tool::NodeArc): - AddAttribute(nod, "type", "NodeArc"); - break; - case(Tool::NodePoint): - AddAttribute(nod, "type", "NodePoint"); - break; - case(Tool::NodeSpline): - AddAttribute(nod, "type", "NodeSpline"); - break; - case(Tool::NodeSplinePath): - AddAttribute(nod, "type", "NodeSplinePath"); - break; - case(Tool::NormalTool): - AddAttribute(nod, "type", "NormalTool"); - break; - case(Tool::PointOfContact): - AddAttribute(nod, "type", "PointOfContact"); - break; - case(Tool::ShoulderPointTool): - AddAttribute(nod, "type", "ShoulderPointTool"); - break; - case(Tool::SplinePathTool): - AddAttribute(nod, "type", "SplinePathTool"); - break; - case(Tool::SplineTool): - AddAttribute(nod, "type", "SplineTool"); - break; - default: - qWarning()<<"May be wrong tool type!!! Ignoring."<setPath(path); } + +template +void VToolDetail::InitTool(VMainGraphicsScene *scene, const VNodeDetail &node) +{ + QHash* tools = doc->getTools(); + Q_ASSERT(tools != 0); + Tool *tool = qobject_cast(tools->value(node.getId())); + Q_ASSERT(tool != 0); + connect(tool, &Tool::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); + connect(tool, &Tool::RemoveTool, scene, &VMainGraphicsScene::RemoveTool); + tool->setParentItem(this); +} diff --git a/tools/vtooldetail.h b/tools/vtooldetail.h index a0441e48f..b0079d5b8 100644 --- a/tools/vtooldetail.h +++ b/tools/vtooldetail.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vtooldetail.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,29 +24,31 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef VTOOLDETAIL_H #define VTOOLDETAIL_H #include "vabstracttool.h" #include -#include "dialogs/dialogdetail.h" +#include "../dialogs/dialogdetail.h" -class VToolDetail: public VAbstractTool, public QGraphicsPathItem{ +class VToolDetail: public VAbstractTool, public QGraphicsPathItem +{ Q_OBJECT public: VToolDetail(VDomDocument *doc, VContainer *data, const qint64 &id, - Tool::Sources typeCreation, VMainGraphicsScene *scene, + const Tool::Sources &typeCreation, VMainGraphicsScene *scene, QGraphicsItem * parent = 0); virtual void setDialog(); static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data); static void Create(const qint64 _id, VDetail &newDetail, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, const Document::Documents &parse, - Tool::Sources typeCreation); + const Tool::Sources &typeCreation); template - void AddTool(T *tool, const qint64 &id, Tool::Tools typeTool){ + void AddTool(T *tool, const qint64 &id, Tool::Tools typeTool) + { tool->setParentItem(this); connect(tool, &T::ChoosedTool, sceneDetails, &VMainGraphicsScene::ChoosedItem); VNodeDetail node(id, typeTool, Draw::Modeling, NodeDetail::Modeling); @@ -47,10 +56,20 @@ public: det.append(node); VAbstractTool::data.UpdateDetail(this->id, det); QDomElement domElement = doc->elementById(QString().setNum(this->id)); - if(domElement.isElement()){ + if (domElement.isElement()) + { AddNode(domElement, node); } } + static const QString TagName; + static const QString TagNode; + static const QString AttrSupplement; + static const QString AttrClosed; + static const QString AttrWidth; + static const QString AttrIdObject; + static const QString AttrNodeType; + static const QString NodeTypeContour; + static const QString NodeTypeModeling; public slots: virtual void FullUpdateFromFile (); virtual void FullUpdateFromGui(int result); @@ -68,6 +87,8 @@ private: VMainGraphicsScene *sceneDetails; void RefreshGeometry (); void AddNode(QDomElement &domElement, VNodeDetail &node); + template + void InitTool(VMainGraphicsScene *scene, const VNodeDetail &node); }; #endif // VTOOLDETAIL_H diff --git a/translations/valentina_ru.ts b/translations/valentina_ru.ts index e3489ae30..72d64a1ff 100644 --- a/translations/valentina_ru.ts +++ b/translations/valentina_ru.ts @@ -120,7 +120,7 @@ - + Select second point of line @@ -245,10 +245,14 @@ - Length of arcs Длина дуг + + + Length of curves + Длина кривых + Angle of lines @@ -260,7 +264,7 @@ - + Value angle of line. @@ -394,12 +398,12 @@ - + Select second point of angle - + Select third point of angle @@ -412,22 +416,51 @@ Деталь - - Name detail - Имя детали + + Bias X + - + + Bias Y + + + + + Option + + + + + Name of detail + + + + + Supplement for seams + + + + + Width + + + + Name detail + Имя детали + + + Closed Замкнутая - + Get wrong scene object. Ignore. - + Get wrong tools. Ignore. @@ -554,6 +587,57 @@ + + DialogHeight + + + Dialog + + + + + Name new point + Имя новой точки + + + + Base point + Базовая точка + + + + + + + First point of line + + + + + Second point of line + + + + + Type line + Тип линии + + + + Show line from first point to our point + + + + + Select first point of line + + + + + Select second point of line + + + DialogHistory @@ -563,7 +647,7 @@ - + Tool Инструмент @@ -624,7 +708,17 @@ - + + Point of perpendical from point %1 to line %2_%3 + + + + + Triangle: axis %1_%2, points %3 and %4 + + + + Get wrong tool type. Ignore. @@ -644,23 +738,23 @@ - - - + + + Denotation Обозначение - + The calculated value Расчитаное значение - - - + + + Base value Базовое значение @@ -676,97 +770,102 @@ - - - - - + + + + + Description Опис - - - + + + In size В размерах - - - + + + In growth В ростах - - + + ... - + Lines Линии - - + + Line Линия - + Length of the line Длина линии - + Curves Кривые - - + + Curve Кривая - + Length of the curve Длина кривой - + Arcs Дуги - - + + Arc Дуга - + Length of arc Длина дуги - + Denotation %1 - - + + Can't convert toDouble value. + + + + + Calculated value - - - + + + Length Длина @@ -789,7 +888,7 @@ Вторая точка - + Select second point @@ -829,17 +928,17 @@ Вторая линия - + Select second point of first line - + Select first point of second line - + Select second point of second line @@ -966,7 +1065,7 @@ - + Select second point of line @@ -1080,16 +1179,54 @@ - + Select second point of line - + Select point of center of arc + + DialogPointOfIntersection + + + Dialog + + + + + Name new point + Имя новой точки + + + + Point vertically + + + + + First point of angle + + + + + Point horizontally + + + + + Second point of angle + + + + + Select point horizontally + + + DialogShoulderPoint @@ -1196,12 +1333,12 @@ - + Select second point of line - + Select point of shoulder @@ -1334,7 +1471,7 @@ Коефициент кривизные кривой - + Select point of curve path @@ -1342,33 +1479,114 @@ DialogTool - + Wrong details id. - - - + + + Line Линия - - + + No line - + + Can't find point by name + + + + Error - + + Growth + + + + + Size + + + + Line length + + + Arc length + + + + + Curve length + + + + + DialogTriangle + + + Dialog + + + + + Name new point + Имя новой точки + + + + First point of axis + + + + + + + + First point of line + + + + + Second point of axis + + + + + First point + Первая точка + + + + Second point + Вторая точка + + + + Select second point of axis + + + + + Select first point + + + + + Select second point + + MainWindow @@ -1388,7 +1606,7 @@ Точка - + Tool point of normal. @@ -1399,12 +1617,15 @@ - - - - - - + + + + + + + + + ... @@ -1414,449 +1635,496 @@ - + Tool point on the end line. - + Tool point along line. - + Tool point of bisector. - + Tool point of contact. - + + Tool point of height. + + + + + Tool triangle. + + + + Tools for creating lines. - + Line Линия - + Tool line. - + Tool point of line intersection. - + Tools for creating curves. - + Curve Кривая - + Tool curve. - + Tool path curve. - + Tools for creating arcs. - + Arc Дуга - + Tool arc. - + Tools for creating details. - + Detail Деталь - + Tool new detail. - + File - + Help - + Drawing - + toolBar - + toolBar_2 - + toolBar_3 - + New Новое - + Create a new pattern Создать новое лекало - + Open Открыть - + Open file with pattern Открыть файл с лекалом - + Save Сохранить - + Save pattern Сохранить лекало - - + + Save as Сохранить как - + Save not yet saved pattern Сохранить еще не сохраненное лекало - + Draw Рисование - + Draw mode Режим рисования - + Details Детали - + Deatils mode Режим деталей - - + + Tools pointer Инструмент указатель - + New drawing Новый чертеж - + Add new drawing Добавить новый чертеж - - + + Change the name of drawing Изменить имя чертежа - + Table of variables Таблица переменных - + Tables of variables Таблици переменных - + History История - + Layout Роскладка - + Create layout Создать раскладку - - + + About Qt - - + + About Valentina - + Exit - + Drawing %1 Чертеж %1 - - + + Drawing: Чертеж: - + Enter a name for the drawing. Введите имя чертежа. - - + + Error. Drawing of same name already exists. Ошибка. Чертеж с таким именем уже существует. - + Error creating drawing with the name Ошибка создания чертежа с именем - + Enter a new name for the drawing. Введите новое имя для чертежа. - - + + Error saving change!!! + + + + + Can't save new name of drawing + + + + + Select point - + Select first point + - - + Select first point of line - + Select first point of angle - + Select first point of first line - + Select first point curve - + Select point of center of arc - + Select point of curve path - - Valentina v.0.1.0 - - - - + The pattern has been modified. - + Do you want to save your changes? - + Growth: Рост: - + Size: Размер: - + Drawing: Чертеж: - + Lekalo files (*.xml);;All files (*.*) - - + + Lekalo files (*.xml) Файл лекала (*.xml) - + Error saving file. Can't save file. - + Open file Открыть файл - + Got empty file name. - + Could not copy temp file to pattern file - + Could not remove pattern file - + Can't open pattern file. File name empty Не могу открыть файл лекала. Пустое имя файла - - - - - - - + + + + + + + + Error! Ошибка! - + Create new drawing for start working. - + Select points, arcs, curves clockwise. - + + Select base point + + + + + Select first point of axis + + + + + Select point vertically + + + + + Based on Qt %2 (32 bit) + + + + + Built on %3 at %4 + + + + + <h1>%1</h1> %2 <br/><br/> %3 <br/><br/> %4 + + + + Error parsing file. Ошибка парсинга файла. - + Error can't convert value. Ошибка, не могу конвертовать значение. - + Error empty parameter. Ошибка, пустой параметр. - + Error wrong id. Ошибка, неправильный id. - + + Error don't unique id. - + Error parsing pattern file. Ошибка парсинга файла лекала. - + Error in line %1 column %2 Ошибка в линии %1 столбец %2 @@ -1880,6 +2148,7 @@ + Save layout Создать раскладку @@ -1952,57 +2221,89 @@ Стоп - + SVG Generator Example Drawing SVG Generator Example Drawing - + An SVG drawing created by the SVG Generator Example provided with Qt. An SVG drawing created by the SVG Generator Example provided with Qt. + + VAbstractNode + + + Can't find tag Modeling + + + VApplication - - - - - + + + + + + Error! Ошибка! - + Error parsing file. Program will be terminated. Ошибка парсинга файла. Програма будет закрыта. - + Error bad id. Program will be terminated. Ошибка, неправильный id. Програма будет закрыта. - + Error can't convert value. Program will be terminated. Ошибка не могу конвертировать значение. Програма будет закрыта. - + Error empty parameter. Program will be terminated. Ошибка пустой параметр. Програма будет закрыта. - + Error wrong id. Program will be terminated. Ошибка неправельный id. Програма будет закрыта. + + + Something wrong!! + + + + + VArc + + + Can't find id = %1 in table. + + + + + Angle of arc can't be 0 degree. + + + + + Arc have not this number of part. + + VContainer - + Can't find object Не могу найти объект @@ -2010,115 +2311,140 @@ VDomDocument - + Got wrong parameter id. Need only id > 0. Получен неправельный параметр id. Допустимы только id > 0. - + Can't convert toLongLong parameter Не могу конвертировать toLongLong параметр - + Got empty parameter Получен пустой параметр - + Can't convert toDouble parameter Не могу конвертировать toDouble параметр - + This id is not unique. - + Error creating or updating detail Ошибка создания или обновления детали - + Error creating or updating single point Ошибка создания или обновления базовой точки - + Error creating or updating point of end line Ошибка создания или обновления точки на конце линии - + Error creating or updating point along line Ошибка создания или обновления точки вдоль линии - + Error creating or updating point of shoulder Ошибка создания или обновления точки плеча - + Error creating or updating point of normal Ошибка создания или обновления точки нормали - + Error creating or updating point of bisector Ошибка создания или обновления точки бисектрисы - + Error creating or updating point of lineintersection Ошибка создания или обновления точки пересичения линий - + Error creating or updating point of contact Ошибка создания или обновления точки прикосновения - + Error creating or updating modeling point Ошибка создания или обновления точки - + + Error creating or updating height + + + + + Error creating or updating triangle + + + + + Error creating or updating point of intersection + + + + Error creating or updating line Ошибка создания или обновления линии - + Error creating or updating simple curve Ошибка создания или обновления кривой - + Error creating or updating curve path Ошибка создания или обновления сложной кривой - + Error creating or updating modeling simple curve Ошибка создания или обновления модельной кривой - + Error creating or updating modeling curve path Ошибка создания или обновления сложной модельной кривой - + Error creating or updating simple arc Ошибка создания или обновления дуги - + Error creating or updating modeling arc Ошибка создания или обновления модельной дуги + + + Error! + Ошибка! + + + + Error parsing file. + Ошибка парсинга файла. + Can't get parent for object id = %1 Не могу получить родителя объекта id = %1 @@ -2127,37 +2453,86 @@ VDrawTool - + Options Параметры - + Delete Удалить + + + Can not find the element after which you want to insert. + + + + + Can't find tag Calculation + + + + + VModelingTool + + + Option + + + + + Delete + Удалить + VSplinePath - + Not enough points to create the spline. Не достаточно точок для создания кривой. - - - + + + This spline is not exist. Такой кривой не существует. + + VTableGraphicsView + + + detail don't find + + + + + detail find + + + VToolDetail - + + Options + Параметры + + + Delete Удалить + + VToolTriangle + + + Can't find point. + + + diff --git a/translations/valentina_uk.ts b/translations/valentina_uk.ts index 9040a6444..6d8446548 100644 --- a/translations/valentina_uk.ts +++ b/translations/valentina_uk.ts @@ -120,7 +120,7 @@ Змінні. Подвійний клік для вибору. - + Select second point of line Виберіть другу точку лінії @@ -245,10 +245,14 @@ - Length of arcs Довжина дуг + + + Length of curves + + Angle of lines @@ -260,7 +264,7 @@ Змінні - + Value angle of line. Значення дуги лінії. @@ -394,12 +398,12 @@ Змінні. Подвійний клік для вибору. - + Select second point of angle Виберіть другу точку кута - + Select third point of angle Виберіть третю точку кута @@ -412,22 +416,51 @@ Деталь - - Name detail - Ім'я деталі + + Bias X + - + + Bias Y + + + + + Option + + + + + Name of detail + + + + + Supplement for seams + + + + + Width + + + + Name detail + Ім'я деталі + + + Closed Замкнена - + Get wrong scene object. Ignore. Отримано непаравильний об'єкт сцени. Ігноровано. - + Get wrong tools. Ignore. Отримано неправильний інструмент. Ігноровано. @@ -554,6 +587,57 @@ Змінні. Подвійний клік для вибору. + + DialogHeight + + + Dialog + + + + + Name new point + Ім'я нової точки + + + + Base point + Базова точка + + + + + + + First point of line + Перша точка лінії + + + + Second point of line + Друга точка лінії + + + + Type line + Тип лінії + + + + Show line from first point to our point + Показати лінію від першої точки до нашої точки + + + + Select first point of line + Виберість першу точку лінії + + + + Select second point of line + Виберіть другу точку лінії + + DialogHistory @@ -563,7 +647,7 @@ - + Tool Інструмент @@ -624,7 +708,17 @@ %4 - Точка дотику дуги з центром в точці %1 і лінії %2_%3 - + + Point of perpendical from point %1 to line %2_%3 + + + + + Triangle: axis %1_%2, points %3 and %4 + + + + Get wrong tool type. Ignore. Отримано неправильний тип інструменту. Ігноруємо. @@ -644,23 +738,23 @@ - - - + + + Denotation Позначення - + The calculated value Розраховане значення - - - + + + Base value Базове значення @@ -676,97 +770,102 @@ - - - - - + + + + + Description Опис - - - + + + In size В розмірах - - - + + + In growth В ростах - - + + ... - + Lines Лінії - - + + Line Лінія - + Length of the line Довжина лінії - + Curves Криві - - + + Curve Крива - + Length of the curve Довжина кривої - + Arcs Дуги - - + + Arc Дуга - + Length of arc Довжина дуги - + Denotation %1 Позначення %1 - - + + Can't convert toDouble value. + + + + + Calculated value Розраховане значення - - - + + + Length Довжина @@ -789,7 +888,7 @@ Друга точка - + Select second point Виберіть другу точку @@ -829,17 +928,17 @@ Друга лінія - + Select second point of first line Виберіть другу точка першої лінії - + Select first point of second line Виберіть першу точку другої лінії - + Select second point of second line Виберіть другу точку другої лінії @@ -966,7 +1065,7 @@ Змінні. Подвійний клік для вибору. - + Select second point of line Виберіть другу точку лінії @@ -1080,16 +1179,54 @@ Змінні. Подвійний клік для вибору. - + Select second point of line Виберіть другу точку лінії - + Select point of center of arc Виберіть точку центру дуги + + DialogPointOfIntersection + + + Dialog + + + + + Name new point + Ім'я нової точки + + + + Point vertically + + + + + First point of angle + Перша точка кута + + + + Point horizontally + + + + + Second point of angle + Друга точка кута + + + + Select point horizontally + + + DialogShoulderPoint @@ -1196,12 +1333,12 @@ Змінні. Подвійний клік для вибору. - + Select second point of line Виберіть другу точку лінії - + Select point of shoulder Виберіть точку плеча @@ -1334,7 +1471,7 @@ Коефіцієнт кривизни кривої - + Select point of curve path Виберіть точку складної кривої @@ -1342,33 +1479,114 @@ DialogTool - + Wrong details id. Неправильний id деталі. - - - + + + Line Лінія - - + + No line Без лінії - + + Can't find point by name + + + + Error Помилка - + + Growth + + + + + Size + + + + Line length Довжина лінії + + + Arc length + + + + + Curve length + + + + + DialogTriangle + + + Dialog + + + + + Name new point + Ім'я нової точки + + + + First point of axis + + + + + + + + First point of line + Перша точка лінії + + + + Second point of axis + + + + + First point + Перша точка + + + + Second point + Друга точка + + + + Select second point of axis + + + + + Select first point + Виберість першу точку + + + + Select second point + Виберіть другу точку + MainWindow @@ -1388,7 +1606,7 @@ Точка - + Tool point of normal. Інструмент точка перпендикуляра. @@ -1399,12 +1617,15 @@ - - - - - - + + + + + + + + + ... @@ -1414,322 +1635,342 @@ Інструмент точка плеча. - + Tool point on the end line. Інструмент точка на кінці лінії. - + Tool point along line. Інструмент точка вздовж лінії. - + Tool point of bisector. Інструмент точка бісектриси кута. - + Tool point of contact. Інструмент точка дотику. - + + Tool point of height. + + + + + Tool triangle. + + + + Tools for creating lines. Інструменти для створення ліній. - + Line Лінія - + Tool line. Інструмент лінія. - + Tool point of line intersection. Інструмент точка перетину ліній. - + Tools for creating curves. Інструменти для створення кривих. - + Curve Крива - + Tool curve. Інструмент крива. - + Tool path curve. Інструмент складна крива. - + Tools for creating arcs. Інструменти для створення дуг. - + Arc Дуга - + Tool arc. Інструмент дуга. - + Tools for creating details. Інструменти для створення деталей. - + Detail Деталь - + Tool new detail. Інструмент нова деталь. - + File Файл - + Help Допомога - + Drawing Креслення - + toolBar - + toolBar_2 - + toolBar_3 - + New Новий - + Create a new pattern Створити нове лекало - + Open Відкрити - + Open file with pattern Відкрити файл з лекалами - + Save Зберегти - + Save pattern Зберегти лекало - - + + Save as Зберегти як - + Save not yet saved pattern Зберегти ще не збережене лекало - + Draw Малювання - + Draw mode Режим малювання - + Details Деталь - + Deatils mode Режим деталей - - + + Tools pointer Інструмент вказівник - + New drawing Нове креслення - + Add new drawing Додати нове креслення - - + + Change the name of drawing Змінити ім'я креслення - + Table of variables Таблиця змінних - + Tables of variables Таблиці змінних - + History Історія - + Layout Розкладки - + Create layout Створити розкладку - - + + About Qt Про Qt - - + + About Valentina Про Valentina - + Exit Вихід - + Drawing %1 Креслення %1 - - + + Drawing: Креслення: - + Enter a name for the drawing. Введіть ім'я креслення. - - + + Error. Drawing of same name already exists. Помилка. Креслення з таким ім'ям вже існує. - + Error creating drawing with the name Помилка створення креслення з ім'ям - + Enter a new name for the drawing. Введіть нове ім'я креслення. - - + + Error saving change!!! + + + + + Can't save new name of drawing + + + + + Select point Виберість точку - + Select first point Виберість першу точку + - - + Select first point of line Виберість першу точку лінії - + Select first point of angle Виберіть першу точку кута - + Select first point of first line Виберіть першу точку першої лінії - + Select first point curve Виберіть першу точку кривої - + Select point of center of arc Виберіть точку центру дуги - + Select point of curve path Виберіть точку складної кривої @@ -1738,129 +1979,160 @@ Виберіть точки, дуги, криві і д - Valentina v.0.1.0 - Valentina v.0.1.0 + Valentina v.0.1.0 - + The pattern has been modified. Лекало було зміненно. - + Do you want to save your changes? Ви хочете зберегти зміни? - + Growth: Зріст: - + Size: Розмір: - + Drawing: Креслення: - + Lekalo files (*.xml);;All files (*.*) Файли лекала (*.xml);;Всі файли (*.*) - - + + Lekalo files (*.xml) Файл лекала (*.xml) - + Error saving file. Can't save file. Помилка збереження файлу. Не можу зберегти файл. - + Open file Відкрити файл - + Got empty file name. Отримано пусте імя файлу. - + Could not copy temp file to pattern file Не можу копіювати тимчасовий файл до файлу лекала - + Could not remove pattern file Не можу видалити файл лекала - + Can't open pattern file. File name empty Не можу відкрити файл лекала. Пусте ім'я файлу - - - - - - - + + + + + + + + Error! Помилка! - + Create new drawing for start working. Створіть нове креслення для початку роботи. - + Select points, arcs, curves clockwise. Виберіть точки, дуги, криві загодинниковою стрілкою. - + + Select base point + + + + + Select first point of axis + + + + + Select point vertically + + + + + Based on Qt %2 (32 bit) + + + + + Built on %3 at %4 + + + + + <h1>%1</h1> %2 <br/><br/> %3 <br/><br/> %4 + + + + Error parsing file. Помилка парсингу файла. - + Error can't convert value. Помилка, не можу конвертувати значення. - + Error empty parameter. Помилка, пустий параметр. - + Error wrong id. Помикла, неправильний id. - + + Error don't unique id. Помилка, не унікальний id. - + Error parsing pattern file. Помилка парсінгу файлу лекала. - + Error in line %1 column %2 Помилка в лінії %1 стовпчик %2 @@ -1884,6 +2156,7 @@ + Save layout Зберегти розкладку @@ -1956,57 +2229,89 @@ Зупинити - + SVG Generator Example Drawing - + An SVG drawing created by the SVG Generator Example provided with Qt. + + VAbstractNode + + + Can't find tag Modeling + + + VApplication - - - - - + + + + + + Error! Помилка! - + Error parsing file. Program will be terminated. Помилка парсінгу файла. Програма буде закрита. - + Error bad id. Program will be terminated. Помилка неправильний id. Програма буде закрита. - + Error can't convert value. Program will be terminated. Помилка конвертації значення. Програма буде закрита. - + Error empty parameter. Program will be terminated. Помилка пустий параметр. Програма буде закрита. - + Error wrong id. Program will be terminated. Помилка неправильний id. Програма буде закрита. + + + Something wrong!! + + + + + VArc + + + Can't find id = %1 in table. + + + + + Angle of arc can't be 0 degree. + + + + + Arc have not this number of part. + + VContainer - + Can't find object Не можу знайти об'єкт @@ -2014,115 +2319,140 @@ VDomDocument - + Got wrong parameter id. Need only id > 0. Отримано неправильний id. Допускаються тільки id > 0. - + Can't convert toLongLong parameter Не можу конвертувати toLongLong параметру - + Got empty parameter Отримано пустий параметр - + Can't convert toDouble parameter Не можу конвертувати toDouble параметру - + This id is not unique. Цей id не унікальний. - + Error creating or updating detail Помилка створення чи оновлення деталі - + Error creating or updating single point Помилка створення чи оновлення простої точки - + Error creating or updating point of end line Помилка створення чи оновлення точки кінця відрізку - + Error creating or updating point along line Помилка створення чи оновлення точки вздовж лінії - + Error creating or updating point of shoulder Помилка створення чи оновлення точки плеча - + Error creating or updating point of normal Помилка створення чи оновлення точки нормалі - + Error creating or updating point of bisector Помилка створення чи оновлення точки бісектриси - + Error creating or updating point of lineintersection Помилка створення чи оновлення точки перетину ліній - + Error creating or updating point of contact Помилка створення чи оновлення точки дотику - + Error creating or updating modeling point Помилка створення чи оновлення модельної точки - + + Error creating or updating height + + + + + Error creating or updating triangle + + + + + Error creating or updating point of intersection + + + + Error creating or updating line Помилка створення чи оновлення лінії - + Error creating or updating simple curve Помилка створення чи оновлення кривої - + Error creating or updating curve path Помилка створення чи оновлення шляху кривих - + Error creating or updating modeling simple curve Помилка створення чи оновлення модельної кривої - + Error creating or updating modeling curve path Помилка створення чи оновлення модельного шляху кривих - + Error creating or updating simple arc Помилка створення чи оновлення дуги - + Error creating or updating modeling arc Помилка створення чи оновлення модельної дуги + + + Error! + Помилка! + + + + Error parsing file. + Помилка парсингу файла. + Can't get parent for object id = %1 Не можу отримати батька для об'єкту id = %1 @@ -2131,37 +2461,86 @@ VDrawTool - + Options Параметри - + Delete Видалити + + + Can not find the element after which you want to insert. + + + + + Can't find tag Calculation + + + + + VModelingTool + + + Option + + + + + Delete + Видалити + VSplinePath - + Not enough points to create the spline. Не достатньо точок для створення кривої. - - - + + + This spline is not exist. Такий сплайн не існує. + + VTableGraphicsView + + + detail don't find + + + + + detail find + + + VToolDetail - + + Options + Параметри + + + Delete Видалити + + VToolTriangle + + + Can't find point. + + + diff --git a/version.h b/version.h new file mode 100644 index 000000000..fb95d4e3b --- /dev/null +++ b/version.h @@ -0,0 +1,41 @@ +/************************************************************************ + ** + ** @file version.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef VERSION_H +#define VERSION_H + +#include + +extern const int MAJOR_VERSION = 0; +extern const int MINOR_VERSION = 2; +extern const int DEBUG_VERSION = 0; + +extern const QString APP_VERSION(QStringLiteral("%1.%2.%3").arg(MAJOR_VERSION).arg(MINOR_VERSION).arg(DEBUG_VERSION)); +extern const QString WARRANTY(QT_TR_NOOP("The program is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE " + "WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.")); +#endif // VERSION_H diff --git a/widgets/delegate.cpp b/widgets/delegate.cpp deleted file mode 100644 index f3b2d0de5..000000000 --- a/widgets/delegate.cpp +++ /dev/null @@ -1,90 +0,0 @@ - /**************************************************************************** - ** - ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). - ** Contact: http://www.qt-project.org/legal - ** - ** This file is part of the examples of the Qt Toolkit. - ** - ** $QT_BEGIN_LICENSE:BSD$ - ** You may use this file under the terms of the BSD license as follows: - ** - ** "Redistribution and use in source and binary forms, with or without - ** modification, are permitted provided that the following conditions are - ** met: - ** * Redistributions of source code must retain the above copyright - ** notice, this list of conditions and the following disclaimer. - ** * Redistributions in binary form must reproduce the above copyright - ** notice, this list of conditions and the following disclaimer in - ** the documentation and/or other materials provided with the - ** distribution. - ** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names - ** of its contributors may be used to endorse or promote products derived - ** from this software without specific prior written permission. - ** - ** - ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." - ** - ** $QT_END_LICENSE$ - ** - ****************************************************************************/ - - /* - delegate.cpp - - A delegate that allows the user to change integer values from the model - using a spin box widget. - */ - -#include -#include "delegate.h" - - SpinBoxDelegate::SpinBoxDelegate(QObject *parent) - : QItemDelegate(parent) - { - } - - QWidget *SpinBoxDelegate::createEditor(QWidget *parent, - const QStyleOptionViewItem &/* option */, - const QModelIndex &/* index */) const - { - QSpinBox *editor = new QSpinBox(parent); - editor->setMinimum(0); - editor->setMaximum(1000); - - return editor; - } - - void SpinBoxDelegate::setEditorData(QWidget *editor, - const QModelIndex &index) const - { - int value = index.model()->data(index, Qt::EditRole).toInt(); - - QSpinBox *spinBox = static_cast(editor); - spinBox->setValue(value); - } - - void SpinBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, - const QModelIndex &index) const - { - QSpinBox *spinBox = static_cast(editor); - spinBox->interpretText(); - int value = spinBox->value(); - - model->setData(index, value, Qt::EditRole); - } - - void SpinBoxDelegate::updateEditorGeometry(QWidget *editor, - const QStyleOptionViewItem &option, const QModelIndex &/* index */) const - { - editor->setGeometry(option.rect); - } diff --git a/widgets/doubledelegate.cpp b/widgets/doubledelegate.cpp index 3b0932624..7e5529553 100644 --- a/widgets/doubledelegate.cpp +++ b/widgets/doubledelegate.cpp @@ -1,42 +1,30 @@ - /**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). - ** Contact: http://www.qt-project.org/legal + ** @file doubledelegate.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of the examples of the Qt Toolkit. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** $QT_BEGIN_LICENSE:BSD$ - ** You may use this file under the terms of the BSD license as follows: + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. ** - ** "Redistribution and use in source and binary forms, with or without - ** modification, are permitted provided that the following conditions are - ** met: - ** * Redistributions of source code must retain the above copyright - ** notice, this list of conditions and the following disclaimer. - ** * Redistributions in binary form must reproduce the above copyright - ** notice, this list of conditions and the following disclaimer in - ** the documentation and/or other materials provided with the - ** distribution. - ** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names - ** of its contributors may be used to endorse or promote products derived - ** from this software without specific prior written permission. + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . ** - ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." - ** - ** $QT_END_LICENSE$ - ** - ****************************************************************************/ + *************************************************************************/ /* doubledelegate.cpp @@ -45,46 +33,39 @@ using a spin box widget. */ -#include #include "doubledelegate.h" - DoubleSpinBoxDelegate::DoubleSpinBoxDelegate(QObject *parent) - : QItemDelegate(parent) - { - } +QWidget *DoubleSpinBoxDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, + const QModelIndex &index ) const +{ + Q_UNUSED(option); + Q_UNUSED(index); + QDoubleSpinBox *editor = new QDoubleSpinBox(parent); + editor->setMinimum(-10000.0); + editor->setMaximum(10000.0); + return editor; +} - QWidget *DoubleSpinBoxDelegate::createEditor(QWidget *parent, - const QStyleOptionViewItem &/* option */, - const QModelIndex &/* index */) const - { - QDoubleSpinBox *editor = new QDoubleSpinBox(parent); - editor->setMinimum(-1000.0); - editor->setMaximum(1000.0); +void DoubleSpinBoxDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const +{ + qreal value = index.model()->data(index, Qt::EditRole).toDouble(); - return editor; - } + QDoubleSpinBox *spinBox = static_cast(editor); + spinBox->setValue(value); +} - void DoubleSpinBoxDelegate::setEditorData(QWidget *editor, - const QModelIndex &index) const - { - int value = index.model()->data(index, Qt::EditRole).toInt(); +void DoubleSpinBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const +{ + QDoubleSpinBox *spinBox = static_cast(editor); + spinBox->interpretText(); + qreal value = spinBox->value(); - QDoubleSpinBox *spinBox = static_cast(editor); - spinBox->setValue(value); - } + model->setData(index, value, Qt::EditRole); +} - void DoubleSpinBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, - const QModelIndex &index) const - { - QDoubleSpinBox *spinBox = static_cast(editor); - spinBox->interpretText(); - qreal value = spinBox->value(); - - model->setData(index, value, Qt::EditRole); - } - - void DoubleSpinBoxDelegate::updateEditorGeometry(QWidget *editor, - const QStyleOptionViewItem &option, const QModelIndex &/* index */) const - { - editor->setGeometry(option.rect); - } +void DoubleSpinBoxDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, + const QModelIndex &index) const +{ + Q_UNUSED(index) + editor->setGeometry(option.rect); +} diff --git a/widgets/doubledelegate.h b/widgets/doubledelegate.h index a86b54f63..c4bc8ac49 100644 --- a/widgets/doubledelegate.h +++ b/widgets/doubledelegate.h @@ -1,67 +1,45 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). - ** Contact: http://www.qt-project.org/legal + ** @file doubledelegate.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of the examples of the Qt Toolkit. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** $QT_BEGIN_LICENSE:BSD$ - ** You may use this file under the terms of the BSD license as follows: + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. ** - ** "Redistribution and use in source and binary forms, with or without - ** modification, are permitted provided that the following conditions are - ** met: - ** * Redistributions of source code must retain the above copyright - ** notice, this list of conditions and the following disclaimer. - ** * Redistributions in binary form must reproduce the above copyright - ** notice, this list of conditions and the following disclaimer in - ** the documentation and/or other materials provided with the - ** distribution. - ** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names - ** of its contributors may be used to endorse or promote products derived - ** from this software without specific prior written permission. + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . ** - ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." - ** - ** $QT_END_LICENSE$ - ** - ****************************************************************************/ + *************************************************************************/ #ifndef DOUBLEDELEGATE_H #define DOUBLEDELEGATE_H #include -#include -#include -#include -#include -class DoubleSpinBoxDelegate : public QItemDelegate{ +class DoubleSpinBoxDelegate : public QItemDelegate +{ Q_OBJECT - public: - DoubleSpinBoxDelegate(QObject *parent = 0); - - QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, - const QModelIndex &index) const; - - void setEditorData(QWidget *editor, const QModelIndex &index) const; - void setModelData(QWidget *editor, QAbstractItemModel *model, - const QModelIndex &index) const; - - void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, - const QModelIndex &index) const; + DoubleSpinBoxDelegate(QObject *parent = 0): QItemDelegate(parent){} + QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const; + void setEditorData(QWidget *editor, const QModelIndex &index) const; + void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const; + void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const; }; #endif diff --git a/widgets/vapplication.cpp b/widgets/vapplication.cpp index b8f658bcc..34327663f 100644 --- a/widgets/vapplication.cpp +++ b/widgets/vapplication.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vapplication.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,27 +24,24 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "vapplication.h" -#include -#include -#include "exception/vexceptionobjecterror.h" -#include "exception/vexceptionbadid.h" -#include "exception/vexceptionconversionerror.h" -#include "exception/vexceptionemptyparameter.h" -#include "exception/vexceptionwrongparameterid.h" - -VApplication::VApplication(int & argc, char ** argv) : - QApplication(argc, argv){ -} +#include "../exception/vexceptionobjecterror.h" +#include "../exception/vexceptionbadid.h" +#include "../exception/vexceptionconversionerror.h" +#include "../exception/vexceptionemptyparameter.h" +#include "../exception/vexceptionwrongparameterid.h" // reimplemented from QApplication so we can throw exceptions in slots -bool VApplication::notify(QObject *receiver, QEvent *event){ - try { +bool VApplication::notify(QObject *receiver, QEvent *event) +{ + try + { return QApplication::notify(receiver, event); } - catch(const VExceptionObjectError &e){ + catch (const VExceptionObjectError &e) + { QMessageBox msgBox; msgBox.setWindowTitle(tr("Error!")); msgBox.setText(tr("Error parsing file. Program will be terminated.")); @@ -49,7 +53,8 @@ bool VApplication::notify(QObject *receiver, QEvent *event){ msgBox.exec(); abort(); } - catch(const VExceptionBadId &e){ + catch (const VExceptionBadId &e) + { QMessageBox msgBox; msgBox.setWindowTitle(tr("Error!")); msgBox.setText(tr("Error bad id. Program will be terminated.")); @@ -60,7 +65,8 @@ bool VApplication::notify(QObject *receiver, QEvent *event){ msgBox.exec(); abort(); } - catch(const VExceptionConversionError &e){ + catch (const VExceptionConversionError &e) + { QMessageBox msgBox; msgBox.setWindowTitle(tr("Error!")); msgBox.setText(tr("Error can't convert value. Program will be terminated.")); @@ -71,7 +77,8 @@ bool VApplication::notify(QObject *receiver, QEvent *event){ msgBox.exec(); abort(); } - catch(const VExceptionEmptyParameter &e){ + catch (const VExceptionEmptyParameter &e) + { QMessageBox msgBox; msgBox.setWindowTitle(tr("Error!")); msgBox.setText(tr("Error empty parameter. Program will be terminated.")); @@ -83,7 +90,8 @@ bool VApplication::notify(QObject *receiver, QEvent *event){ msgBox.exec(); abort(); } - catch(const VExceptionWrongParameterId &e){ + catch (const VExceptionWrongParameterId &e) + { QMessageBox msgBox; msgBox.setWindowTitle(tr("Error!")); msgBox.setText(tr("Error wrong id. Program will be terminated.")); @@ -95,7 +103,19 @@ bool VApplication::notify(QObject *receiver, QEvent *event){ msgBox.exec(); abort(); } - catch(std::exception& e) { + catch (const VException &e) + { + QMessageBox msgBox; + msgBox.setWindowTitle(tr("Error!")); + msgBox.setText(tr("Something wrong!!")); + msgBox.setInformativeText(e.ErrorMessage()); + msgBox.setStandardButtons(QMessageBox::Ok); + msgBox.setDefaultButton(QMessageBox::Ok); + msgBox.setIcon(QMessageBox::Critical); + msgBox.exec(); + } + catch (std::exception& e) + { qCritical() << "Exception thrown:" << e.what(); } return false; diff --git a/widgets/vapplication.h b/widgets/vapplication.h index 80d3f516c..359dd1806 100644 --- a/widgets/vapplication.h +++ b/widgets/vapplication.h @@ -1,3 +1,31 @@ +/************************************************************************ + ** + ** @file vapplication.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + #ifndef VAPPLICATION_H #define VAPPLICATION_H @@ -7,8 +35,8 @@ class VApplication : public QApplication { Q_OBJECT public: - VApplication(int &argc, char ** argv); - virtual ~VApplication() { } + VApplication(int &argc, char ** argv): QApplication(argc, argv){} + virtual ~VApplication() {} virtual bool notify(QObject * receiver, QEvent * event); }; diff --git a/widgets/vcontrolpointspline.cpp b/widgets/vcontrolpointspline.cpp index fceaac561..8a81c7f0e 100644 --- a/widgets/vcontrolpointspline.cpp +++ b/widgets/vcontrolpointspline.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vcontrolpointspline.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,18 +24,15 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "vcontrolpointspline.h" -#include -#include -#include -#include VControlPointSpline::VControlPointSpline(const qint32 &indexSpline, SplinePoint::Position position, const QPointF &controlPoint, const QPointF &splinePoint, - QGraphicsItem *parent):QGraphicsEllipseItem(parent), - radius(1.5*PrintDPI/25.4), controlLine(0), indexSpline(indexSpline), position(position){ + QGraphicsItem *parent) + :QGraphicsEllipseItem(parent), radius(toPixel(1.5)), controlLine(0), indexSpline(indexSpline), position(position) +{ //create circle QRectF rec = QRectF(0, 0, radius*2, radius*2); rec.translate(-rec.center().x(), -rec.center().y()); @@ -49,18 +53,22 @@ VControlPointSpline::VControlPointSpline(const qint32 &indexSpline, SplinePoint: controlLine->setFlag(QGraphicsItem::ItemStacksBehindParent, true); } -void VControlPointSpline::hoverMoveEvent(QGraphicsSceneHoverEvent *event){ +void VControlPointSpline::hoverMoveEvent(QGraphicsSceneHoverEvent *event) +{ Q_UNUSED(event); this->setPen(QPen(Qt::black, widthMainLine)); } -void VControlPointSpline::hoverLeaveEvent(QGraphicsSceneHoverEvent *event){ +void VControlPointSpline::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) +{ Q_UNUSED(event); this->setPen(QPen(Qt::black, widthHairLine)); } -QVariant VControlPointSpline::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value){ - if (change == ItemPositionChange && scene()) { +QVariant VControlPointSpline::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) +{ + if (change == ItemPositionChange && scene()) + { // value - new position. QPointF newPos = value.toPointF(); emit ControlPointChangePosition(indexSpline, position, newPos); @@ -68,8 +76,9 @@ QVariant VControlPointSpline::itemChange(QGraphicsItem::GraphicsItemChange chang return QGraphicsItem::itemChange(change, value); } -qint32 VControlPointSpline::LineIntersectCircle(QPointF center, qreal radius, QLineF line, QPointF &p1, - QPointF &p2) const{ +qint32 VControlPointSpline::LineIntersectCircle(const QPointF ¢er, qreal radius, const QLineF &line, QPointF &p1, + QPointF &p2) const +{ const qreal eps = 1e-8; //коефіцієнти для рівняння відрізку qreal a = line.p2().y() - line.p1().y(); @@ -81,12 +90,18 @@ qint32 VControlPointSpline::LineIntersectCircle(QPointF center, qreal radius, QL // сколько всего решений? qint32 flag = 0; qreal d = QLineF (center, p).length(); - if (qAbs (d - radius) <= eps){ + if (qAbs (d - radius) <= eps) + { flag = 1; - } else { - if (radius > d){ + } + else + { + if (radius > d) + { flag = 2; - } else { + } + else + { return 0; } } @@ -99,17 +114,22 @@ qint32 VControlPointSpline::LineIntersectCircle(QPointF center, qreal radius, QL return flag; } -QPointF VControlPointSpline::ClosestPoint(QLineF line, QPointF p) const{ +QPointF VControlPointSpline::ClosestPoint(const QLineF &line, const QPointF &p) const +{ QLineF lineP2pointFrom = QLineF(line.p2(), p); qreal angle = 180-line.angleTo(lineP2pointFrom)-90; QLineF pointFromlineP2 = QLineF(p, line.p2()); pointFromlineP2.setAngle(pointFromlineP2.angle()+angle); QPointF point; - QLineF::IntersectType type = pointFromlineP2.intersect(line,&point); - if ( type == QLineF::BoundedIntersection ){ + QLineF::IntersectType type = pointFromlineP2.intersect(line, &point); + if ( type == QLineF::BoundedIntersection ) + { return point; - } else{ - if ( type == QLineF::NoIntersection || type == QLineF::UnboundedIntersection ){ + } + else + { + if ( type == QLineF::NoIntersection || type == QLineF::UnboundedIntersection ) + { Q_ASSERT_X(type != QLineF::BoundedIntersection, Q_FUNC_INFO, "Немає точки перетину."); return point; } @@ -117,26 +137,33 @@ QPointF VControlPointSpline::ClosestPoint(QLineF line, QPointF p) const{ return point; } -QPointF VControlPointSpline::addVector(QPointF p, QPointF p1, QPointF p2, qreal k) const{ +QPointF VControlPointSpline::addVector(const QPointF &p, const QPointF &p1, const QPointF &p2, qreal k) const +{ return QPointF (p.x() + (p2.x() - p1.x()) * k, p.y() + (p2.y() - p1.y()) * k); } void VControlPointSpline::RefreshLine(const qint32 &indexSpline, SplinePoint::Position pos, - const QPointF &controlPoint, const QPointF &splinePoint){ - if(this->indexSpline == indexSpline && this->position == pos){ + const QPointF &controlPoint, const QPointF &splinePoint) +{ + if (this->indexSpline == indexSpline && this->position == pos) + { QPointF p1, p2; LineIntersectCircle(QPointF(), radius, QLineF( QPointF(), splinePoint-controlPoint), p1, p2); controlLine->setLine(QLineF(splinePoint-controlPoint, p1)); } } -void VControlPointSpline::setEnabledPoint(bool enable){ - if(enable == true){ +void VControlPointSpline::setEnabledPoint(bool enable) +{ + if (enable == true) + { this->setPen(QPen(Qt::black, widthHairLine)); this->setFlag(QGraphicsItem::ItemIsSelectable, true); this->setFlag(QGraphicsItem::ItemIsMovable, true); this->setAcceptHoverEvents(true); - } else { + } + else + { this->setPen(QPen(Qt::gray, widthHairLine)); this->setFlag(QGraphicsItem::ItemIsSelectable, false); this->setFlag(QGraphicsItem::ItemIsMovable, false); diff --git a/widgets/vcontrolpointspline.h b/widgets/vcontrolpointspline.h index 231f8220a..fddc4ccec 100644 --- a/widgets/vcontrolpointspline.h +++ b/widgets/vcontrolpointspline.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vcontrolpointspline.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,44 +24,43 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef VCONTROLPOINTSPLINE_H #define VCONTROLPOINTSPLINE_H #include -#include #include -#include "geometry/vsplinepath.h" +#include "../geometry/vsplinepath.h" class VControlPointSpline : public QObject, public QGraphicsEllipseItem { Q_OBJECT public: - VControlPointSpline(const qint32 &indexSpline, SplinePoint::Position position, - const QPointF &controlPoint, const QPointF &splinePoint, - QGraphicsItem * parent = 0); + VControlPointSpline(const qint32 &indexSpline, SplinePoint::Position position, + const QPointF &controlPoint, const QPointF &splinePoint, + QGraphicsItem * parent = 0); signals: - void ControlPointChangePosition(const qint32 &indexSpline, SplinePoint::Position position, - const QPointF pos); + void ControlPointChangePosition(const qint32 &indexSpline, SplinePoint::Position position, + const QPointF pos); public slots: - void RefreshLine(const qint32 &indexSpline, SplinePoint::Position pos, - const QPointF &controlPoint, const QPointF &splinePoint); - void setEnabledPoint(bool enable); + void RefreshLine(const qint32 &indexSpline, SplinePoint::Position pos, const QPointF &controlPoint, + const QPointF &splinePoint); + void setEnabledPoint(bool enable); protected: - qreal radius; - QGraphicsLineItem *controlLine; - virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); - virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); - QVariant itemChange ( GraphicsItemChange change, const QVariant &value ); + qreal radius; + QGraphicsLineItem *controlLine; + virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); + virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); + QVariant itemChange ( GraphicsItemChange change, const QVariant &value ); private: Q_DISABLE_COPY(VControlPointSpline) - qint32 indexSpline; + qint32 indexSpline; SplinePoint::Position position; - qint32 LineIntersectCircle(QPointF center, qreal radius, QLineF line, QPointF &p1, - QPointF &p2) const; - QPointF ClosestPoint(QLineF line, QPointF p) const; - QPointF addVector (QPointF p, QPointF p1, QPointF p2, qreal k) const; + qint32 LineIntersectCircle(const QPointF ¢er, qreal radius, const QLineF &line, QPointF &p1, + QPointF &p2) const; + QPointF ClosestPoint(const QLineF &line, const QPointF &p) const; + QPointF addVector (const QPointF &p, const QPointF &p1, const QPointF &p2, qreal k) const; }; diff --git a/widgets/vgraphicssimpletextitem.cpp b/widgets/vgraphicssimpletextitem.cpp index a37aba2fc..5e34555ce 100644 --- a/widgets/vgraphicssimpletextitem.cpp +++ b/widgets/vgraphicssimpletextitem.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vgraphicssimpletextitem.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,41 +24,50 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "vgraphicssimpletextitem.h" -#include -#include -VGraphicsSimpleTextItem::VGraphicsSimpleTextItem(QGraphicsItem * parent):QGraphicsSimpleTextItem(parent){ +VGraphicsSimpleTextItem::VGraphicsSimpleTextItem(QGraphicsItem * parent) + :QGraphicsSimpleTextItem(parent), fontSize(0) +{ this->setFlag(QGraphicsItem::ItemIsMovable, true); this->setFlag(QGraphicsItem::ItemIsSelectable, true); this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); this->setAcceptHoverEvents(true); + QFont font = this->font(); + font.setPointSize(font.pointSize()+3); + fontSize = font.pointSize(); + this->setFont(font); } VGraphicsSimpleTextItem::VGraphicsSimpleTextItem( const QString & text, QGraphicsItem * parent ) - :QGraphicsSimpleTextItem(text, parent){ + :QGraphicsSimpleTextItem(text, parent), fontSize(0) +{ this->setFlag(QGraphicsItem::ItemIsMovable, true); this->setFlag(QGraphicsItem::ItemIsSelectable, true); this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); this->setAcceptHoverEvents(true); } -QVariant VGraphicsSimpleTextItem::itemChange(GraphicsItemChange change, const QVariant &value){ - if (change == ItemPositionChange && scene()) { +QVariant VGraphicsSimpleTextItem::itemChange(GraphicsItemChange change, const QVariant &value) +{ + if (change == ItemPositionChange && scene()) + { QPointF newPos = value.toPointF() + this->parentItem()->pos(); emit NameChangePosition(newPos); } return QGraphicsItem::itemChange(change, value); } -void VGraphicsSimpleTextItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event){ +void VGraphicsSimpleTextItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) +{ Q_UNUSED(event); this->setBrush(Qt::green); } -void VGraphicsSimpleTextItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event){ +void VGraphicsSimpleTextItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) +{ Q_UNUSED(event); this->setBrush(Qt::black); } diff --git a/widgets/vgraphicssimpletextitem.h b/widgets/vgraphicssimpletextitem.h index e3f31d0bf..3f3b2a2a8 100644 --- a/widgets/vgraphicssimpletextitem.h +++ b/widgets/vgraphicssimpletextitem.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vgraphicssimpletextitem.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,7 +24,7 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef VGRAPHICSSIMPLETEXTITEM_H #define VGRAPHICSSIMPLETEXTITEM_H @@ -30,12 +37,15 @@ class VGraphicsSimpleTextItem : public QObject, public QGraphicsSimpleTextItem public: VGraphicsSimpleTextItem(QGraphicsItem * parent = 0); VGraphicsSimpleTextItem( const QString & text, QGraphicsItem * parent = 0 ); + qint32 FontSize()const {return fontSize;} signals: void NameChangePosition(const QPointF pos); protected: QVariant itemChange ( GraphicsItemChange change, const QVariant &value ); virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); +private: + qint32 fontSize; }; #endif // VGRAPHICSSIMPLETEXTITEM_H diff --git a/widgets/vitem.cpp b/widgets/vitem.cpp index 917bd26ae..37c6614cc 100644 --- a/widgets/vitem.cpp +++ b/widgets/vitem.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vitem.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,43 +24,50 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "vitem.h" #include -#include -#include "options.h" -VItem::VItem():numInOutList(0){ +VItem::VItem (const QPainterPath & path, int numInList, QGraphicsItem * parent ) + :QGraphicsPathItem ( path, parent ), numInOutList(numInList), paper(0) +{ } -VItem::VItem ( int numInList, QGraphicsItem * parent ):QGraphicsPathItem ( parent ), - numInOutList(numInList){ -} - -VItem::VItem (const QPainterPath & path, int numInList, QGraphicsItem * parent ): - QGraphicsPathItem ( path, parent ), numInOutList(numInList){ -} - -void VItem::checkItemChange(){ - QRectF rect = parentItem()->sceneBoundingRect(); +void VItem::checkItemChange() +{ + QRectF rect; + if(paper == 0){ + qDebug()<<"Don't set paper for detail!!!!"; + rect = this->scene()->sceneRect(); + } + else + { + rect = paper->sceneBoundingRect(); + } QRectF myrect = sceneBoundingRect(); - if( rect.contains( myrect )==true ){ + if ( rect.contains( myrect )==true ) + { qDebug()<<"Не виходить за рамки листа"; setPen(QPen(Qt::black, widthMainLine)); emit itemOut( numInOutList, false ); - } else { + } + else + { qDebug()<<"Виходить за рамки листа"; setPen(QPen(Qt::red, widthMainLine)); emit itemOut( numInOutList, true ); } QList list = QGraphicsItem::collidingItems (); - if( list.size() - 2 > 0 ){ + if ( list.size() - 2 > 0 ) + { list.append( this ); setPen(QPen(Qt::red, widthMainLine)); qDebug()<<"Деталь перетинається з іншими деталями "< itemList; itemList.append( this ); qDebug()<<"Деталь більше не перетинається з іншими деталями "< -#include -#include -#include -VMainGraphicsScene::VMainGraphicsScene():QGraphicsScene(), horScrollBar(0), verScrollBar(0){ -} +VMainGraphicsScene::VMainGraphicsScene() + :QGraphicsScene(), horScrollBar(0), verScrollBar(0), scaleFactor(1){} -VMainGraphicsScene::VMainGraphicsScene(const QRectF & sceneRect, QObject * parent): - QGraphicsScene ( sceneRect, parent ), horScrollBar(0), verScrollBar(0){ -} +VMainGraphicsScene::VMainGraphicsScene(const QRectF & sceneRect, QObject * parent) + :QGraphicsScene ( sceneRect, parent ), horScrollBar(0), verScrollBar(0), scaleFactor(1){} -void VMainGraphicsScene::mouseMoveEvent(QGraphicsSceneMouseEvent* event){ +void VMainGraphicsScene::mouseMoveEvent(QGraphicsSceneMouseEvent* event) +{ emit mouseMove(event->scenePos()); QGraphicsScene::mouseMoveEvent(event); } -void VMainGraphicsScene::mousePressEvent(QGraphicsSceneMouseEvent *event){ +void VMainGraphicsScene::mousePressEvent(QGraphicsSceneMouseEvent *event) +{ emit mousePress(event->scenePos()); QGraphicsScene::mousePressEvent(event); } -void VMainGraphicsScene::ChoosedItem(qint64 id, Scene::Scenes type){ +void VMainGraphicsScene::ChoosedItem(qint64 id, const Scene::Scenes &type) +{ emit ChoosedObject(id, type); } -void VMainGraphicsScene::RemoveTool(QGraphicsItem *tool){ - this->removeItem(tool); -} - -qint32 VMainGraphicsScene::getVerScrollBar() const{ - return verScrollBar; -} - -void VMainGraphicsScene::setVerScrollBar(const qint32 &value){ - verScrollBar = value; -} - -qint32 VMainGraphicsScene::getHorScrollBar() const{ - return horScrollBar; -} - -void VMainGraphicsScene::setHorScrollBar(const qint32 &value){ - horScrollBar = value; +void VMainGraphicsScene::SetFactor(qreal factor) +{ + scaleFactor=scaleFactor*factor; + emit NewFactor(scaleFactor); } diff --git a/widgets/vmaingraphicsscene.h b/widgets/vmaingraphicsscene.h index 41ec68d89..8d605d64d 100644 --- a/widgets/vmaingraphicsscene.h +++ b/widgets/vmaingraphicsscene.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vmaingraphicsscene.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,41 +24,39 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef VMAINGRAPHICSSCENE_H #define VMAINGRAPHICSSCENE_H #include -#include -#include -#include "options.h" class VMainGraphicsScene : public QGraphicsScene { Q_OBJECT public: - VMainGraphicsScene(); - VMainGraphicsScene(const QRectF & sceneRect, QObject * parent = 0); - qint32 getHorScrollBar() const; - void setHorScrollBar(const qint32 &value); - - qint32 getVerScrollBar() const; - void setVerScrollBar(const qint32 &value); - + VMainGraphicsScene(); + VMainGraphicsScene(const QRectF & sceneRect, QObject * parent = 0); + inline qint32 getHorScrollBar() const {return horScrollBar;} + inline void setHorScrollBar(const qint32 &value) {horScrollBar = value;} + inline qint32 getVerScrollBar() const {return verScrollBar;} + inline void setVerScrollBar(const qint32 &value) {verScrollBar = value;} public slots: - void ChoosedItem(qint64 id, Scene::Scenes type); - void RemoveTool(QGraphicsItem *tool); + void ChoosedItem(qint64 id, const Scene::Scenes &type); + inline void RemoveTool(QGraphicsItem *tool) {this->removeItem(tool);} + void SetFactor(qreal factor); protected: - void mouseMoveEvent(QGraphicsSceneMouseEvent* event); - void mousePressEvent(QGraphicsSceneMouseEvent *event); + void mouseMoveEvent(QGraphicsSceneMouseEvent* event); + void mousePressEvent(QGraphicsSceneMouseEvent *event); signals: - void mouseMove(QPointF scenePos); - void mousePress(QPointF scenePos); - void ChoosedObject(qint64 id, Scene::Scenes type); + void mouseMove(QPointF scenePos); + void mousePress(QPointF scenePos); + void ChoosedObject(qint64 id, Scene::Scenes type); + void NewFactor(qreal factor); private: - qint32 horScrollBar; - qint32 verScrollBar; + qint32 horScrollBar; + qint32 verScrollBar; + qreal scaleFactor; }; #endif // VMAINGRAPHICSSCENE_H diff --git a/widgets/vmaingraphicsview.cpp b/widgets/vmaingraphicsview.cpp index 694a12984..8fc8fe703 100644 --- a/widgets/vmaingraphicsview.cpp +++ b/widgets/vmaingraphicsview.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vmaingraphicsview.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,36 +24,95 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "vmaingraphicsview.h" -#include -#include -#include -VMainGraphicsView::VMainGraphicsView(QWidget *parent) : - QGraphicsView(parent){ - QGraphicsView::setResizeAnchor(QGraphicsView::AnchorUnderMouse); - setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); +VMainGraphicsView::VMainGraphicsView(QWidget *parent) + :QGraphicsView(parent), _numScheduledScalings(0) +{ + this->setResizeAnchor(QGraphicsView::AnchorUnderMouse); + this->setTransformationAnchor(QGraphicsView::AnchorUnderMouse); + this->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); } -void VMainGraphicsView::wheelEvent(QWheelEvent *event){ - if (QApplication::keyboardModifiers() == Qt::ControlModifier){ - // Если нажата клавиша CTRL этот код выполнится - if ((event->delta())>0){ - ZoomIn(); - } else if ((event->delta())<0){ - ZoomOut(); +void VMainGraphicsView::wheelEvent(QWheelEvent *event) +{ + int numDegrees = event->delta() / 8; + int numSteps = numDegrees / 15; // see QWheelEvent documentation + _numScheduledScalings += numSteps; + if (_numScheduledScalings * numSteps < 0) + { // if user moved the wheel in another direction, we reset + _numScheduledScalings = numSteps; // previously scheduled scalings + } + + QTimeLine *anim = new QTimeLine(350, this); + anim->setUpdateInterval(20); + + connect(anim, &QTimeLine::valueChanged, this, &VMainGraphicsView::scalingTime); + connect(anim, &QTimeLine::finished, this, &VMainGraphicsView::animFinished); + anim->start(); +} + +void VMainGraphicsView::scalingTime(qreal x) +{ + Q_UNUSED(x); + qreal factor = 1.0 + static_cast(_numScheduledScalings) / 300.0; + if (QApplication::keyboardModifiers() == Qt::ControlModifier) + {// If you press CTRL this code will execute + scale(factor, factor); + emit NewFactor(factor); + } + else + { + if (_numScheduledScalings < 0) + { + verticalScrollBar()->setValue(qRound(verticalScrollBar()->value() + factor*3.5)); + emit NewFactor(factor); + } + else + { + if (verticalScrollBar()->value() > 0) + { + verticalScrollBar()->setValue(qRound(verticalScrollBar()->value() - factor*3.5)); + emit NewFactor(factor); + } } - } else { - verticalScrollBar()->setValue(verticalScrollBar()->value() - event->delta()); } } -void VMainGraphicsView::ZoomIn(){ - scale(1.1,1.1); +void VMainGraphicsView::animFinished() +{ + if (_numScheduledScalings > 0) + { + _numScheduledScalings--; + } + else + { + _numScheduledScalings++; + } + sender()->~QObject(); } -void VMainGraphicsView::ZoomOut(){ - scale(1/1.1,1/1.1); +void VMainGraphicsView::mousePressEvent(QMouseEvent *mousePress) +{ + if (mousePress->button() & Qt::LeftButton) + { + switch (QGuiApplication::keyboardModifiers()) + { + case Qt::ControlModifier: + QGraphicsView::setDragMode(QGraphicsView::ScrollHandDrag); + QGraphicsView::mousePressEvent(mousePress); + break; + default: + QGraphicsView::mousePressEvent(mousePress); + break; + } + } +} + +void VMainGraphicsView::mouseReleaseEvent(QMouseEvent *event) +{ + QGraphicsView::mouseReleaseEvent ( event ); + QGraphicsView::setDragMode( QGraphicsView::RubberBandDrag ); } diff --git a/widgets/vmaingraphicsview.h b/widgets/vmaingraphicsview.h index 67cf3f679..c4bb43956 100644 --- a/widgets/vmaingraphicsview.h +++ b/widgets/vmaingraphicsview.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vmaingraphicsview.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,7 +24,7 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef VMAINGRAPHICSVIEW_H #define VMAINGRAPHICSVIEW_H @@ -29,25 +36,21 @@ class VMainGraphicsView : public QGraphicsView Q_OBJECT public: explicit VMainGraphicsView(QWidget *parent = 0); - signals: + void NewFactor(qreal factor); +public slots: + void scalingTime(qreal x); + void animFinished(); protected: /** * @brief wheelEvent обробник повороту колеса мишки. * @param event передається подія. */ - void wheelEvent ( QWheelEvent * event ); - -public slots: - /** - * @brief ZoomIn збільшує масштаб листа. - */ - void ZoomIn(); - /** - * @brief ZoomOut зменшує масштаб листа. - */ - void ZoomOut(); - + void wheelEvent ( QWheelEvent * event ); + void mousePressEvent(QMouseEvent *mousePress); + void mouseReleaseEvent(QMouseEvent *event); +private: + qint32 _numScheduledScalings; }; #endif // VMAINGRAPHICSVIEW_H diff --git a/widgets/vtablegraphicsview.cpp b/widgets/vtablegraphicsview.cpp index b2f9d57f1..a60b22567 100644 --- a/widgets/vtablegraphicsview.cpp +++ b/widgets/vtablegraphicsview.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vtablegraphicsview.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,43 +24,44 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "vtablegraphicsview.h" -#include -#include -#include -#include -#include -VTableGraphicsView::VTableGraphicsView(QGraphicsScene* pScene, QWidget *parent) : - QGraphicsView(pScene, parent){ +VTableGraphicsView::VTableGraphicsView(QGraphicsScene* pScene, QWidget *parent) + :QGraphicsView(pScene, parent) +{ QGraphicsView::setResizeAnchor(QGraphicsView::AnchorUnderMouse); connect(pScene, &QGraphicsScene::selectionChanged, this, &VTableGraphicsView::selectionChanged); } -void VTableGraphicsView::selectionChanged(){ +void VTableGraphicsView::selectionChanged() +{ QList listSelectedItems = scene()->selectedItems(); - if( listSelectedItems.isEmpty() == true ){ - qDebug() << "деталь не знайдено"; + if ( listSelectedItems.isEmpty() == true ) + { + qDebug() << tr("detail don't find"); emit itemChect(true); - } else { - qDebug() << "деталь знайдено"; + } + else + { + qDebug() << tr("detail find"); emit itemChect(false); } } -void VTableGraphicsView::rotateItems(){ - rotateIt(); -} - -void VTableGraphicsView::MirrorItem(){ +void VTableGraphicsView::MirrorItem() +{ QList list = scene()->selectedItems(); - if(list.size()>0){ - for( qint32 i = 0; i < list.count(); ++i ){ - QRectF itemRectOld = list.at(i)->sceneBoundingRect(); + if (list.size()>0) + { + for ( qint32 i = 0; i < list.count(); ++i ) + { + QGraphicsItem *item = list.at(i); + Q_ASSERT(item != 0); + QRectF itemRectOld = item->sceneBoundingRect(); //Get the current transform - QTransform transform(list.at(i)->transform()); + QTransform transform(item->transform()); qreal m11 = transform.m11(); // Horizontal scaling qreal m12 = transform.m12(); // Vertical shearing @@ -72,110 +80,128 @@ void VTableGraphicsView::MirrorItem(){ transform.setMatrix(m11, m12, m13, m21, m22, m23, m31, m32, m33); // Set the items transformation - list.at(i)->setTransform(transform); - QRectF itemRectNew = list.at(i)->sceneBoundingRect(); + item->setTransform(transform); + QRectF itemRectNew = item->sceneBoundingRect(); qreal dx, dy; dx = itemRectOld.center().x()-itemRectNew.center().x(); dy = itemRectOld.center().y()-itemRectNew.center().y(); - list.at(i)->moveBy(dx, dy); + item->moveBy(dx, dy); } } } -void VTableGraphicsView::ZoomIn(){ - scale(1.1,1.1); -} - -void VTableGraphicsView::ZoomOut(){ - scale(1/1.1,1/1.1); -} - -void VTableGraphicsView::wheelEvent(QWheelEvent *event){ - if (QGuiApplication::keyboardModifiers() == Qt::ControlModifier){ +void VTableGraphicsView::wheelEvent(QWheelEvent *event) +{ + if (QGuiApplication::keyboardModifiers() == Qt::ControlModifier) + { // Если нажата клавиша CTRL этот код выполнится - if ((event->delta())>0){ + if ((event->delta())>0) + { ZoomIn(); - } else if ((event->delta())<0){ + } + else if ((event->delta())<0) + { ZoomOut(); } - } else { + } + else + { verticalScrollBar()->setValue(verticalScrollBar()->value()-event->delta()); } } -void VTableGraphicsView::mousePressEvent(QMouseEvent *mousePress){ - if(mousePress->button() & Qt::LeftButton){ - switch(QGuiApplication::keyboardModifiers()){ - case Qt::ControlModifier: - QGraphicsView::setDragMode(QGraphicsView::ScrollHandDrag); - QGraphicsView::mousePressEvent(mousePress); - break; - default: - QGraphicsView::mousePressEvent(mousePress); - break; +void VTableGraphicsView::mousePressEvent(QMouseEvent *mousePress) +{ + if (mousePress->button() & Qt::LeftButton) + { + switch (QGuiApplication::keyboardModifiers()) + { + case Qt::ControlModifier: + QGraphicsView::setDragMode(QGraphicsView::ScrollHandDrag); + QGraphicsView::mousePressEvent(mousePress); + break; + default: + QGraphicsView::mousePressEvent(mousePress); + break; } } } -void VTableGraphicsView::mouseReleaseEvent(QMouseEvent *event){ +void VTableGraphicsView::mouseReleaseEvent(QMouseEvent *event) +{ QGraphicsView::mouseReleaseEvent ( event ); QGraphicsView::setDragMode( QGraphicsView::RubberBandDrag ); } -void VTableGraphicsView::keyPressEvent(QKeyEvent *event){ - switch(event->key()){ - case Qt::Key_Space: - rotateIt(); - break; - case Qt::Key_Left: - MoveItem(VTableGraphicsView::Left); - break; - case Qt::Key_Right: - MoveItem(VTableGraphicsView::Right); - break; - case Qt::Key_Up: - MoveItem(VTableGraphicsView::Up); - break; - case Qt::Key_Down: - MoveItem(VTableGraphicsView::Down); - break; +void VTableGraphicsView::keyPressEvent(QKeyEvent *event) +{ + switch (event->key()) + { + case Qt::Key_Space: + rotateIt(); + break; + case Qt::Key_Left: + MoveItem(VTableGraphicsView::Left); + break; + case Qt::Key_Right: + MoveItem(VTableGraphicsView::Right); + break; + case Qt::Key_Up: + MoveItem(VTableGraphicsView::Up); + break; + case Qt::Key_Down: + MoveItem(VTableGraphicsView::Down); + break; + default: + break; } QGraphicsView::keyPressEvent ( event ); } -void VTableGraphicsView::rotateIt(){ +void VTableGraphicsView::rotateIt() +{ QList list = scene()->selectedItems(); - if(list.size()>0){ - for( qint32 i = 0; i < list.count(); ++i ){ - list.at(i)->setTransformOriginPoint(list.at(i)->boundingRect().center()); - list.at(i)->setRotation(list.at(i)->rotation() + 180); + if (list.size()>0) + { + for ( qint32 i = 0; i < list.count(); ++i ) + { + QGraphicsItem *item = list.at(i); + Q_ASSERT(item != 0); + item->setTransformOriginPoint(item->boundingRect().center()); + item->setRotation(item->rotation() + 180); } } } -void VTableGraphicsView::MoveItem(VTableGraphicsView::typeMove_e move){ +void VTableGraphicsView::MoveItem(VTableGraphicsView::typeMove_e move) +{ qreal dx = 0, dy = 0; - switch(move){ - case VTableGraphicsView::Left: - dx = -3; - dy = 0; - break; - case VTableGraphicsView::Right: - dx = 3; - dy = 0; - break; - case VTableGraphicsView::Up: - dx = 0; - dy = -3; - break; - case VTableGraphicsView::Down: - dx = 0; - dy = 3; - break; + switch (move) + { + case VTableGraphicsView::Left: + dx = -3; + dy = 0; + break; + case VTableGraphicsView::Right: + dx = 3; + dy = 0; + break; + case VTableGraphicsView::Up: + dx = 0; + dy = -3; + break; + case VTableGraphicsView::Down: + dx = 0; + dy = 3; + break; + default: + break; } QList listSelectedItems = scene()->selectedItems(); - if(listSelectedItems.size()>0){ - for( qint32 i = 0; i < listSelectedItems.count(); ++i ){ + if (listSelectedItems.size()>0) + { + for ( qint32 i = 0; i < listSelectedItems.count(); ++i ) + { listSelectedItems.at(i)->moveBy(dx, dy); } } diff --git a/widgets/vtablegraphicsview.h b/widgets/vtablegraphicsview.h index ef86ebeff..da6f9a5fa 100644 --- a/widgets/vtablegraphicsview.h +++ b/widgets/vtablegraphicsview.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vtablegraphicsview.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,7 +24,7 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef VTABLEGRAPHICSVIEW_H #define VTABLEGRAPHICSVIEW_H @@ -29,65 +36,64 @@ class VTableGraphicsView : public QGraphicsView Q_OBJECT public: enum typeMove_e { Left, Right, Up, Down }; - explicit VTableGraphicsView(QGraphicsScene* pScene, QWidget *parent = 0); - + VTableGraphicsView(QGraphicsScene* pScene, QWidget *parent = 0); signals: /** * @brief itemChect Сигнал, що посилається коли змінюється стан вибору деталі. * @param flag Зберігає стан вибору деталі: false - знайдено, true - не знайдено. */ - void itemChect( bool flag ); + void itemChect( bool flag ); public slots: /** * @brief selectionChanged Слот виконується при зміні стану вибору деталей. */ - void selectionChanged(); + void selectionChanged(); /** * @brief rotateItems слот, який виконується при натисненні кнопки повороту деталі. */ - void rotateItems(); + inline void rotateItems() {rotateIt();} /** * @brief MirrorItem дзеркалить об'єкт відносно вертикальної вісі семетрії об'єкта. */ - void MirrorItem(); + void MirrorItem(); /** * @brief ZoomIn збільшує масштаб листа. */ - void ZoomIn(); + inline void ZoomIn() {scale(1.1, 1.1);} /** * @brief ZoomOut зменшує масштаб листа. */ - void ZoomOut(); + inline void ZoomOut() {scale(1/1.1, 1/1.1);} protected: /** * @brief wheelEvent обробник повороту колеса мишки. * @param event передається подія. */ - void wheelEvent ( QWheelEvent * event ); + void wheelEvent ( QWheelEvent * event ); /** * @brief mousePressEvent обробник натиснення кнопки миші. * @param mousePress передається подія. */ - void mousePressEvent(QMouseEvent *mousePress); + void mousePressEvent(QMouseEvent *mousePress); /** * @brief mouseReleaseEvent обробник відпускання кнопки миші. * @param event передається подія */ - void mouseReleaseEvent ( QMouseEvent * event ); + void mouseReleaseEvent ( QMouseEvent * event ); /** * @brief keyPressEvent обробник натиснення клавіші. * @param event передається подія. */ - void keyPressEvent ( QKeyEvent * event ); + void keyPressEvent ( QKeyEvent * event ); /** * @brief rotateIt виконує поворот вибраних деталей на 180 градусів. */ - void rotateIt(); + void rotateIt(); /** * @brief MoveItem переміщує виділені об'єкти сцени. * @param move напрямок переміщення. */ - void MoveItem( VTableGraphicsView::typeMove_e move ); + void MoveItem( VTableGraphicsView::typeMove_e move ); }; diff --git a/widgets/widgets.pri b/widgets/widgets.pri new file mode 100644 index 000000000..4b908b906 --- /dev/null +++ b/widgets/widgets.pri @@ -0,0 +1,19 @@ +HEADERS += \ + widgets/vtablegraphicsview.h \ + widgets/vmaingraphicsview.h \ + widgets/vmaingraphicsscene.h \ + widgets/vitem.h \ + widgets/vgraphicssimpletextitem.h \ + widgets/vcontrolpointspline.h \ + widgets/vapplication.h \ + widgets/doubledelegate.h + +SOURCES += \ + widgets/vtablegraphicsview.cpp \ + widgets/vmaingraphicsview.cpp \ + widgets/vmaingraphicsscene.cpp \ + widgets/vitem.cpp \ + widgets/vgraphicssimpletextitem.cpp \ + widgets/vcontrolpointspline.cpp \ + widgets/vapplication.cpp \ + widgets/doubledelegate.cpp diff --git a/xml/vdomdocument.cpp b/xml/vdomdocument.cpp index cc8d87e01..55071e861 100644 --- a/xml/vdomdocument.cpp +++ b/xml/vdomdocument.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vdomdocument.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,79 +24,81 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "vdomdocument.h" -#include -#include "tools/drawTools/drawtools.h" -#include "tools/nodeDetails/nodedetails.h" -#include "tools/modelingTools/modelingtools.h" -#include "tools/vtooldetail.h" -#include "options.h" -#include "container/calculator.h" -#include "geometry/vsplinepoint.h" -#include "exception/vexceptionwrongparameterid.h" -#include "exception/vexceptionconversionerror.h" -#include "exception/vexceptionemptyparameter.h" -#include "exception/vexceptionbadid.h" -#include "exception/vexceptionobjecterror.h" -#include "exception/vexceptionuniqueid.h" -#include +#include "../exception/vexceptionwrongparameterid.h" +#include "../exception/vexceptionconversionerror.h" +#include "../exception/vexceptionemptyparameter.h" +#include "../exception/vexceptionuniqueid.h" +#include "../tools/vtooldetail.h" +#include "../exception/vexceptionobjecterror.h" +#include "../exception/vexceptionbadid.h" +#include "../tools/drawTools/drawtools.h" +#include "../tools/modelingTools/modelingtools.h" +#include "../tools/nodeDetails/vnodepoint.h" +#include "../tools/nodeDetails/vnodespline.h" +#include "../tools/nodeDetails/vnodesplinepath.h" +#include "../tools/nodeDetails/vnodearc.h" -VDomDocument::VDomDocument(VContainer *data, QComboBox *comboBoxDraws, Draw::Draws *mode) : QDomDocument(), - map(QHash()), nameActivDraw(QString()), data(data), +VDomDocument::VDomDocument(VContainer *data, QComboBox *comboBoxDraws, Draw::Draws *mode) + : QDomDocument(), map(QHash()), nameActivDraw(QString()), data(data), tools(QHash()), history(QVector()), cursor(0), - comboBoxDraws(comboBoxDraws), mode(mode){ -} + comboBoxDraws(comboBoxDraws), mode(mode){} VDomDocument::VDomDocument(const QString& name, VContainer *data, QComboBox *comboBoxDraws, - Draw::Draws *mode) : - QDomDocument(name), map(QHash()), nameActivDraw(QString()), data(data), + Draw::Draws *mode) + :QDomDocument(name), map(QHash()), nameActivDraw(QString()), data(data), tools(QHash()), history(QVector()), cursor(0), - comboBoxDraws(comboBoxDraws), mode(mode){ -} + comboBoxDraws(comboBoxDraws), mode(mode){} VDomDocument::VDomDocument(const QDomDocumentType& doctype, VContainer *data, QComboBox *comboBoxDraws, - Draw::Draws *mode) : - QDomDocument(doctype), map(QHash()), nameActivDraw(QString()), data(data), + Draw::Draws *mode) + :QDomDocument(doctype), map(QHash()), nameActivDraw(QString()), data(data), tools(QHash()), history(QVector()), cursor(0), - comboBoxDraws(comboBoxDraws), mode(mode){ -} + comboBoxDraws(comboBoxDraws), mode(mode){} -VDomDocument::~VDomDocument(){ -} - -QDomElement VDomDocument::elementById(const QString& id){ - if (map.contains(id)) { +QDomElement VDomDocument::elementById(const QString& id) +{ + if (map.contains(id)) + { QDomElement e = map[id]; - if (e.parentNode().nodeType() != QDomNode::BaseNode) { + if (e.parentNode().nodeType() != QDomNode::BaseNode) + { return e; } map.remove(id); } bool res = this->find(this->documentElement(), id); - if (res) { + if (res) + { return map[id]; } return QDomElement(); } -bool VDomDocument::find(QDomElement node, const QString& id){ - if (node.hasAttribute("id")) { +bool VDomDocument::find(const QDomElement &node, const QString& id) +{ + if (node.hasAttribute("id")) + { QString value = node.attribute("id"); this->map[value] = node; - if (value == id) { + if (value == id) + { return true; } } - for (qint32 i=0; ifind(n.toElement(), id); - if (res) { + if (res) + { return true; } } @@ -98,7 +107,8 @@ bool VDomDocument::find(QDomElement node, const QString& id){ return false; } -void VDomDocument::CreateEmptyFile(){ +void VDomDocument::CreateEmptyFile() +{ QDomElement domElement = this->createElement("lekalo"); this->appendChild(domElement); QDomNode xmlNode = this->createProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\""); @@ -107,17 +117,22 @@ void VDomDocument::CreateEmptyFile(){ domElement.appendChild(incrElement); } -bool VDomDocument::CheckNameDraw(const QString& name) const{ - Q_ASSERT_X(!name.isEmpty(), "CheckNameDraw", "name draw is empty"); +bool VDomDocument::CheckNameDraw(const QString& name) const +{ + Q_ASSERT_X(name.isEmpty() == false, "CheckNameDraw", "name draw is empty"); QDomNodeList elements = this->documentElement().elementsByTagName( "draw" ); - if(elements.size() == 0){ + if (elements.size() == 0) + { return false; } - for ( qint32 i = 0; i < elements.count(); i++ ){ + for ( qint32 i = 0; i < elements.count(); i++ ) + { QDomElement elem = elements.at( i ).toElement(); - if(!elem.isNull()){ + if (elem.isNull() == false) + { QString fieldName = elem.attribute( "name" ); - if ( fieldName == name ){ + if ( fieldName == name ) + { return true; } } @@ -125,12 +140,15 @@ bool VDomDocument::CheckNameDraw(const QString& name) const{ return false; } -bool VDomDocument::appendDraw(const QString& name){ - Q_ASSERT_X(!name.isEmpty(), "appendDraw", "name draw is empty"); - if(name.isEmpty()){ +bool VDomDocument::appendDraw(const QString& name) +{ + Q_ASSERT_X(name.isEmpty() == false, "appendDraw", "name draw is empty"); + if (name.isEmpty()) + { return false; } - if(CheckNameDraw(name)== false){ + if (CheckNameDraw(name)== false) + { QDomElement rootElement = this->documentElement(); QDomElement drawElement = this->createElement("draw"); @@ -147,55 +165,79 @@ bool VDomDocument::appendDraw(const QString& name){ rootElement.appendChild(drawElement); - if(nameActivDraw.isEmpty()){ + if (nameActivDraw.isEmpty()) + { SetActivDraw(name); - } else { + } + else + { ChangeActivDraw(name); } return true; - } else { + } + else + { return false; } return false; } -void VDomDocument::ChangeActivDraw(const QString& name, Document::Documents parse){ - Q_ASSERT_X(!name.isEmpty(), "ChangeActivDraw", "name draw is empty"); - if(CheckNameDraw(name) == true){ +void VDomDocument::ChangeActivDraw(const QString& name, const Document::Documents &parse) +{ + Q_ASSERT_X(name.isEmpty() == false, "ChangeActivDraw", "name draw is empty"); + if (CheckNameDraw(name) == true) + { this->nameActivDraw = name; - if(parse == Document::FullParse){ + if (parse == Document::FullParse) + { emit ChangedActivDraw(name); } } } -void VDomDocument::SetNameDraw(const QString& name){ - Q_ASSERT_X(!name.isEmpty(), "SetNameDraw", "name draw is empty"); +bool VDomDocument::SetNameDraw(const QString& name) +{ + Q_ASSERT_X(name.isEmpty() == false, "SetNameDraw", "name draw is empty"); QString oldName = nameActivDraw; - nameActivDraw = name; - emit ChangedNameDraw(oldName, nameActivDraw); + QDomElement element; + if (GetActivDrawElement(element)) + { + nameActivDraw = name; + element.setAttribute("name", nameActivDraw); + emit haveChange(); + emit ChangedNameDraw(oldName, nameActivDraw); + return true; + } + else + { + qWarning()<<"Can't find activ draw"<nameActivDraw = name; } -QString VDomDocument::GetNameActivDraw() const{ - return nameActivDraw; -} - -bool VDomDocument::GetActivDrawElement(QDomElement &element){ - if(!nameActivDraw.isEmpty()){ +bool VDomDocument::GetActivDrawElement(QDomElement &element) +{ + if (nameActivDraw.isEmpty() == false) + { QDomNodeList elements = this->documentElement().elementsByTagName( "draw" ); - if(elements.size() == 0){ + if (elements.size() == 0) + { return false; } - for ( qint32 i = 0; i < elements.count(); i++ ){ + for ( qint32 i = 0; i < elements.count(); i++ ) + { element = elements.at( i ).toElement(); - if(!element.isNull()){ + if (element.isNull() == false) + { QString fieldName = element.attribute( "name" ); - if ( fieldName == nameActivDraw ){ + if ( fieldName == nameActivDraw ) + { return true; } } @@ -204,58 +246,80 @@ bool VDomDocument::GetActivDrawElement(QDomElement &element){ return false; } -bool VDomDocument::GetActivCalculationElement(QDomElement &element){ +bool VDomDocument::GetActivCalculationElement(QDomElement &element) +{ bool ok = GetActivNodeElement("calculation", element); - if(ok){ + if (ok) + { return true; - } else { + } + else + { return false; } } -bool VDomDocument::GetActivModelingElement(QDomElement &element){ +bool VDomDocument::GetActivModelingElement(QDomElement &element) +{ bool ok = GetActivNodeElement("modeling", element); - if(ok){ + if (ok) + { return true; - } else { + } + else + { return false; } } -bool VDomDocument::GetActivDetailsElement(QDomElement &element){ +bool VDomDocument::GetActivDetailsElement(QDomElement &element) +{ bool ok = GetActivNodeElement("details", element); - if(ok){ + if (ok) + { return true; - } else { + } + else + { return false; } } -bool VDomDocument::GetActivNodeElement(const QString& name, QDomElement &element){ - Q_ASSERT_X(!name.isEmpty(), "GetActivNodeElement", "name draw is empty"); +bool VDomDocument::GetActivNodeElement(const QString& name, QDomElement &element) +{ + Q_ASSERT_X(name.isEmpty() == false, "GetActivNodeElement", "name draw is empty"); QDomElement drawElement; bool drawOk = this->GetActivDrawElement(drawElement); - if(drawOk == true){ + if (drawOk == true) + { QDomNodeList listElement = drawElement.elementsByTagName(name); - if(listElement.size() == 0 || listElement.size() > 1){ + if (listElement.size() == 0 || listElement.size() > 1) + { return false; } element = listElement.at( 0 ).toElement(); - if(!element.isNull()){ + if (element.isNull() == false) + { return true; - } else { + } + else + { return false; } - } else { + } + else + { return false; } } -void VDomDocument::Parse(Document::Documents parse, VMainGraphicsScene *sceneDraw, - VMainGraphicsScene *sceneDetail){ - Q_CHECK_PTR(sceneDraw); - Q_CHECK_PTR(sceneDetail); - if(parse == Document::FullParse){ +void VDomDocument::Parse(const Document::Documents &parse, VMainGraphicsScene *sceneDraw, + VMainGraphicsScene *sceneDetail) +{ + Q_ASSERT(sceneDraw != 0); + Q_ASSERT(sceneDetail != 0); + if (parse == Document::FullParse) + { TestUniqueId(); data->Clear(); nameActivDraw.clear(); @@ -272,24 +336,35 @@ void VDomDocument::Parse(Document::Documents parse, VMainGraphicsScene *sceneDra history.clear(); QDomElement rootElement = this->documentElement(); QDomNode domNode = rootElement.firstChild(); - while(!domNode.isNull()){ - if(domNode.isElement()){ + while (domNode.isNull() == false) + { + if (domNode.isElement()) + { QDomElement domElement = domNode.toElement(); - if(!domElement.isNull()){ - if(domElement.tagName()=="draw"){ - if(parse == Document::FullParse){ - if(nameActivDraw.isEmpty()){ + if (domElement.isNull() == false) + { + if (domElement.tagName()=="draw") + { + if (parse == Document::FullParse) + { + if (nameActivDraw.isEmpty()) + { SetActivDraw(domElement.attribute("name")); - } else { + } + else + { ChangeActivDraw(domElement.attribute("name")); } comboBoxDraws->addItem(domElement.attribute("name")); - } else { + } + else + { ChangeActivDraw(domElement.attribute("name"), Document::LiteParse); } ParseDrawElement(sceneDraw, sceneDetail, domElement, parse); } - if(domElement.tagName()=="increments"){ + if (domElement.tagName()=="increments") + { ParseIncrementsElement(domElement); } } @@ -298,21 +373,18 @@ void VDomDocument::Parse(Document::Documents parse, VMainGraphicsScene *sceneDra } } -QHash *VDomDocument::getTools(){ - return &tools; -} - -QVector *VDomDocument::getHistory(){ - return &history; -} - -void VDomDocument::ParseIncrementsElement(const QDomNode &node){ +void VDomDocument::ParseIncrementsElement(const QDomNode &node) +{ QDomNode domNode = node.firstChild(); - while(!domNode.isNull()){ - if(domNode.isElement()){ + while (domNode.isNull() == false) + { + if (domNode.isElement()) + { QDomElement domElement = domNode.toElement(); - if(!domElement.isNull()){ - if(domElement.tagName() == "increment"){ + if (domElement.isNull() == false) + { + if (domElement.tagName() == "increment") + { qint64 id = GetParametrId(domElement); QString name = GetParametrString(domElement, "name"); qreal base = GetParametrDouble(domElement, "base"); @@ -329,86 +401,107 @@ void VDomDocument::ParseIncrementsElement(const QDomNode &node){ } } -qint64 VDomDocument::GetParametrId(const QDomElement &domElement) const{ - Q_ASSERT_X(!domElement.isNull(), Q_FUNC_INFO, "domElement is null"); +qint64 VDomDocument::GetParametrId(const QDomElement &domElement) const +{ + Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null"); qint64 id = GetParametrLongLong(domElement, "id"); - if(id <= 0){ + if (id <= 0) + { throw VExceptionWrongParameterId(tr("Got wrong parameter id. Need only id > 0."), domElement); } return id; } -qint64 VDomDocument::GetParametrLongLong(const QDomElement &domElement, const QString &name) const{ - Q_ASSERT_X(!name.isEmpty(), Q_FUNC_INFO, "name of parametr is empty"); - Q_ASSERT_X(!domElement.isNull(), Q_FUNC_INFO, "domElement is null"); +qint64 VDomDocument::GetParametrLongLong(const QDomElement &domElement, const QString &name) const +{ + Q_ASSERT_X(name.isEmpty() == false, Q_FUNC_INFO, "name of parametr is empty"); + Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null"); bool ok = false; QString parametr = GetParametrString(domElement, name); qint64 id = parametr.toLongLong(&ok); - if(ok == false){ + if (ok == false) + { throw VExceptionConversionError(tr("Can't convert toLongLong parameter"), name); } return id; } -QString VDomDocument::GetParametrString(const QDomElement &domElement, const QString &name) const{ - Q_ASSERT_X(!name.isEmpty(), Q_FUNC_INFO, "name of parametr is empty"); - Q_ASSERT_X(!domElement.isNull(), Q_FUNC_INFO, "domElement is null"); +QString VDomDocument::GetParametrString(const QDomElement &domElement, const QString &name) const +{ + Q_ASSERT_X(name.isEmpty() == false, Q_FUNC_INFO, "name of parametr is empty"); + Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null"); QString parameter = domElement.attribute(name, ""); - if(parameter.isEmpty()){ + if (parameter.isEmpty()) + { throw VExceptionEmptyParameter(tr("Got empty parameter"), name, domElement); } return parameter; } -qreal VDomDocument::GetParametrDouble(const QDomElement &domElement, const QString &name) const{ - Q_ASSERT_X(!name.isEmpty(), Q_FUNC_INFO, "name of parametr is empty"); - Q_ASSERT_X(!domElement.isNull(), Q_FUNC_INFO, "domElement is null"); +qreal VDomDocument::GetParametrDouble(const QDomElement &domElement, const QString &name) const +{ + Q_ASSERT_X(name.isEmpty() == false, Q_FUNC_INFO, "name of parametr is empty"); + Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null"); bool ok = false; QString parametr = GetParametrString(domElement, name); - qreal param = parametr.toDouble(&ok); - if(ok == false){ + qreal param = parametr.replace(",", ".").toDouble(&ok); + if (ok == false) + { throw VExceptionConversionError(tr("Can't convert toDouble parameter"), name); } return param; } -void VDomDocument::TestUniqueId() const{ +void VDomDocument::TestUniqueId() const +{ QVector vector; CollectId(this->documentElement(), vector); } -void VDomDocument::CollectId(QDomElement node, QVector &vector) const{ - if (node.hasAttribute("id")) { +void VDomDocument::CollectId(const QDomElement &node, QVector &vector) const +{ + if (node.hasAttribute("id")) + { qint64 id = GetParametrId(node); - if(vector.contains(id)){ + if (vector.contains(id)) + { throw VExceptionUniqueId(tr("This id is not unique."), node); } vector.append(id); } - for (qint32 i=0; iClearObject(); ParseDrawMode(sceneDraw, sceneDetail, domElement, parse, Draw::Calculation); } - if(domElement.tagName() == "modeling"){ + if (domElement.tagName() == "modeling") + { ParseDrawMode(sceneDraw, sceneDetail, domElement, parse, Draw::Modeling); } - if(domElement.tagName() == "details"){ + if (domElement.tagName() == "details") + { ParseDetails(sceneDetail, domElement, parse); } } @@ -418,110 +511,175 @@ void VDomDocument::ParseDrawElement(VMainGraphicsScene *sceneDraw, VMainGraphics } void VDomDocument::ParseDrawMode(VMainGraphicsScene *sceneDraw, VMainGraphicsScene *sceneDetail, - const QDomNode& node, const Document::Documents &parse, - Draw::Draws mode){ - Q_CHECK_PTR(sceneDraw); - Q_CHECK_PTR(sceneDetail); + const QDomNode& node, const Document::Documents &parse, const Draw::Draws &mode) +{ + Q_ASSERT(sceneDraw != 0); + Q_ASSERT(sceneDetail != 0); VMainGraphicsScene *scene = 0; - if(mode == Draw::Calculation){ + if (mode == Draw::Calculation) + { scene = sceneDraw; - } else { + } + else + { scene = sceneDetail; } QDomNodeList nodeList = node.childNodes(); qint32 num = nodeList.size(); - for(qint32 i = 0; i < num; ++i){ + for (qint32 i = 0; i < num; ++i) + { QDomElement domElement = nodeList.at(i).toElement(); - if(!domElement.isNull()){ - if(domElement.tagName() == "point"){ + if (domElement.isNull() == false) + { + if (domElement.tagName() == "point") + { ParsePointElement(scene, domElement, parse, domElement.attribute("type", ""), mode); + continue; } - if(domElement.tagName() == "line"){ + if (domElement.tagName() == "line") + { ParseLineElement(scene, domElement, parse, mode); + continue; } - if(domElement.tagName() == "spline"){ + if (domElement.tagName() == "spline") + { ParseSplineElement(scene, domElement, parse, domElement.attribute("type", ""), mode); + continue; } - if(domElement.tagName() == "arc"){ + if (domElement.tagName() == "arc") + { ParseArcElement(scene, domElement, parse, domElement.attribute("type", ""), mode); + continue; } } } } void VDomDocument::ParseDetailElement(VMainGraphicsScene *sceneDetail, const QDomElement &domElement, - const Document::Documents &parse){ - Q_CHECK_PTR(sceneDetail); - Q_ASSERT_X(!domElement.isNull(), Q_FUNC_INFO, "domElement is null"); - try{ + const Document::Documents &parse) +{ + Q_ASSERT(sceneDetail != 0); + Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null"); + try + { VDetail detail; VDetail oldDetail; qint64 id = GetParametrId(domElement); detail.setName(GetParametrString(domElement, "name")); detail.setMx(toPixel(GetParametrDouble(domElement, "mx"))); detail.setMy(toPixel(GetParametrDouble(domElement, "my"))); + detail.setSupplement(GetParametrLongLong(domElement, "supplement")); + detail.setWidth(GetParametrDouble(domElement, "width")); + detail.setClosed(GetParametrLongLong(domElement, "closed")); QDomNodeList nodeList = domElement.childNodes(); qint32 num = nodeList.size(); - for(qint32 i = 0; i < num; ++i){ + for (qint32 i = 0; i < num; ++i) + { QDomElement element = nodeList.at(i).toElement(); - if(!element.isNull()){ - if(element.tagName() == "node"){ + if (element.isNull() == false) + { + if (element.tagName() == "node") + { qint64 id = GetParametrLongLong(element, "idObject"); + qreal mx = toPixel(GetParametrDouble(element, "mx")); + qreal my = toPixel(GetParametrDouble(element, "my")); Tool::Tools tool; Draw::Draws mode; NodeDetail::NodeDetails nodeType = NodeDetail::Contour; QString t = GetParametrString(element, "type"); - if(t == "NodePoint"){ + if (t == "NodePoint") + { tool = Tool::NodePoint; VPointF point = data->GetModelingPoint(id); mode = point.getMode(); oldDetail.append(VNodeDetail(point.getIdObject(), tool, mode, NodeDetail::Contour)); - } else if(t == "NodeArc"){ + } + else if (t == "NodeArc") + { tool = Tool::NodeArc; VArc arc = data->GetModelingArc(id); mode = arc.getMode(); oldDetail.append(VNodeDetail(arc.getIdObject(), tool, mode, NodeDetail::Contour)); - } else if(t == "NodeSpline"){ + } + else if (t == "NodeSpline") + { tool = Tool::NodeSpline; VSpline spl = data->GetModelingSpline(id); mode = spl.getMode(); oldDetail.append(VNodeDetail(spl.getIdObject(), tool, mode, NodeDetail::Contour)); - } else if(t == "NodeSplinePath"){ + } + else if (t == "NodeSplinePath") + { tool = Tool::NodeSplinePath; VSplinePath splPath = data->GetModelingSplinePath(id); mode = splPath.getMode(); oldDetail.append(VNodeDetail(splPath.getIdObject(), tool, mode, NodeDetail::Contour)); - } else if(t == "AlongLineTool"){ + } + else if (t == "AlongLineTool") + { tool = Tool::AlongLineTool; - } else if(t == "ArcTool"){ + } + else if (t == "ArcTool") + { tool = Tool::ArcTool; - } else if(t == "BisectorTool"){ + } + else if (t == "BisectorTool") + { tool = Tool::BisectorTool; - } else if(t == "EndLineTool"){ + } + else if (t == "EndLineTool") + { tool = Tool::EndLineTool; - } else if(t == "LineIntersectTool"){ + } + else if (t == "LineIntersectTool") + { tool = Tool::LineIntersectTool; - } else if(t == "LineTool"){ + } + else if (t == "LineTool") + { tool = Tool::LineTool; - } else if(t == "NormalTool"){ + } + else if (t == "NormalTool") + { tool = Tool::NormalTool; - } else if(t == "PointOfContact"){ + } + else if (t == "PointOfContact") + { tool = Tool::PointOfContact; - } else if(t == "ShoulderPointTool"){ + } + else if (t == "ShoulderPointTool") + { tool = Tool::ShoulderPointTool; - } else if(t == "SplinePathTool"){ + } + else if (t == "SplinePathTool") + { tool = Tool::SplinePathTool; - } else if(t == "SplineTool"){ + } + else if (t == "SplineTool") + { tool = Tool::SplineTool; } - detail.append(VNodeDetail(id, tool, mode, nodeType)); + else if (t == "Height") + { + tool = Tool::Height; + } + else if (t == "Triangle") + { + tool = Tool::Triangle; + } + else if (t == "PointOfIntersection") + { + tool = Tool::PointOfIntersection; + } + detail.append(VNodeDetail(id, tool, Draw::Modeling, nodeType, mx, my)); } } } VToolDetail::Create(id, detail, sceneDetail, this, data, parse, Tool::FromFile); } - catch(const VExceptionBadId &e){ + catch (const VExceptionBadId &e) + { VExceptionObjectError excep(tr("Error creating or updating detail"), domElement); excep.AddMoreInformation(e.ErrorMessage()); throw excep; @@ -529,15 +687,20 @@ void VDomDocument::ParseDetailElement(VMainGraphicsScene *sceneDetail, const QDo } void VDomDocument::ParseDetails(VMainGraphicsScene *sceneDetail, const QDomElement &domElement, - const Document::Documents &parse){ - Q_CHECK_PTR(sceneDetail); - Q_ASSERT_X(!domElement.isNull(), Q_FUNC_INFO, "domElement is null"); + const Document::Documents &parse) +{ + Q_ASSERT(sceneDetail != 0); + Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null"); QDomNode domNode = domElement.firstChild(); - while(!domNode.isNull()){ - if(domNode.isElement()){ + while (domNode.isNull() == false) + { + if (domNode.isElement()) + { QDomElement domElement = domNode.toElement(); - if(!domElement.isNull()){ - if(domElement.tagName() == "detail"){ + if (domElement.isNull() == false) + { + if (domElement.tagName() == "detail") + { ParseDetailElement(sceneDetail, domElement, parse); } } @@ -547,13 +710,15 @@ void VDomDocument::ParseDetails(VMainGraphicsScene *sceneDetail, const QDomEleme } void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElement& domElement, - const Document::Documents &parse, const QString& type, - Draw::Draws mode){ - Q_CHECK_PTR(scene); - Q_ASSERT_X(!domElement.isNull(), Q_FUNC_INFO, "domElement is null"); - Q_ASSERT_X(!type.isEmpty(), Q_FUNC_INFO, "type of point is empty"); - if(type == "single"){ - try{ + const Document::Documents &parse, const QString& type, const Draw::Draws &mode) +{ + Q_ASSERT(scene != 0); + Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null"); + Q_ASSERT_X(type.isEmpty() == false, Q_FUNC_INFO, "type of point is empty"); + if (type == "single") + { + try + { qint64 id = GetParametrId(domElement); QString name = GetParametrString(domElement, "name"); qreal x = toPixel(GetParametrDouble(domElement, "x")); @@ -563,26 +728,32 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen data->UpdatePoint(id, VPointF(x, y, name, mx, my)); VDrawTool::AddRecord(id, Tool::SinglePointTool, this); - if(parse != Document::FullParse){ + if (parse != Document::FullParse) + { UpdateToolData(id, data); } - if(parse == Document::FullParse){ + if (parse == Document::FullParse) + { VToolSinglePoint *spoint = new VToolSinglePoint(this, data, id, Tool::FromFile); - Q_CHECK_PTR(spoint); + Q_ASSERT(spoint != 0); scene->addItem(spoint); connect(spoint, &VToolSinglePoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); + connect(scene, &VMainGraphicsScene::NewFactor, spoint, &VToolSinglePoint::SetFactor); tools[id] = spoint; } return; } - catch(const VExceptionBadId &e){ + catch (const VExceptionBadId &e) + { VExceptionObjectError excep(tr("Error creating or updating single point"), domElement); excep.AddMoreInformation(e.ErrorMessage()); throw excep; } } - if(type == "endLine"){ - try{ + if (type == "endLine") + { + try + { qint64 id = GetParametrId(domElement); QString name = GetParametrString(domElement, "name"); qreal mx = toPixel(GetParametrDouble(domElement, "mx")); @@ -591,23 +762,29 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen QString formula = GetParametrString(domElement, "length"); qint64 basePointId = GetParametrLongLong(domElement, "basePoint"); qreal angle = GetParametrDouble(domElement, "angle"); - if(mode == Draw::Calculation){ + if (mode == Draw::Calculation) + { VToolEndLine::Create(id, name, typeLine, formula, angle, basePointId, mx, my, scene, this, data, parse, Tool::FromFile); - } else { + } + else + { VModelingEndLine::Create(id, name, typeLine, formula, angle, basePointId, mx, my, this, data, parse, Tool::FromFile); } return; } - catch(const VExceptionBadId &e){ + catch (const VExceptionBadId &e) + { VExceptionObjectError excep(tr("Error creating or updating point of end line"), domElement); excep.AddMoreInformation(e.ErrorMessage()); throw excep; } } - if(type == "alongLine"){ - try{ + if (type == "alongLine") + { + try + { qint64 id = GetParametrId(domElement); QString name = GetParametrString(domElement, "name"); qreal mx = toPixel(GetParametrDouble(domElement, "mx")); @@ -617,23 +794,29 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen qint64 firstPointId = GetParametrLongLong(domElement, "firstPoint"); qint64 secondPointId = GetParametrLongLong(domElement, "secondPoint"); - if(mode == Draw::Calculation){ + if (mode == Draw::Calculation) + { VToolAlongLine::Create(id, name, typeLine, formula, firstPointId, secondPointId, mx, my, scene, this, data, parse, Tool::FromFile); - } else { + } + else + { VModelingAlongLine::Create(id, name, typeLine, formula, firstPointId, secondPointId, mx, my, this, data, parse, Tool::FromFile); } return; } - catch(const VExceptionBadId &e){ + catch (const VExceptionBadId &e) + { VExceptionObjectError excep(tr("Error creating or updating point along line"), domElement); excep.AddMoreInformation(e.ErrorMessage()); throw excep; } } - if(type == "shoulder"){ - try{ + if (type == "shoulder") + { + try + { qint64 id = GetParametrId(domElement); QString name = GetParametrString(domElement, "name"); qreal mx = toPixel(GetParametrDouble(domElement, "mx")); @@ -644,23 +827,29 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen qint64 p2Line = GetParametrLongLong(domElement, "p2Line"); qint64 pShoulder = GetParametrLongLong(domElement, "pShoulder"); - if(mode == Draw::Calculation){ + if (mode == Draw::Calculation) + { VToolShoulderPoint::Create(id, formula, p1Line, p2Line, pShoulder, typeLine, name, mx, my, scene, this, data, parse, Tool::FromFile); - } else { + } + else + { VModelingShoulderPoint::Create(id, formula, p1Line, p2Line, pShoulder, typeLine, name, mx, my, this, data, parse, Tool::FromFile); } return; } - catch(const VExceptionBadId &e){ + catch (const VExceptionBadId &e) + { VExceptionObjectError excep(tr("Error creating or updating point of shoulder"), domElement); excep.AddMoreInformation(e.ErrorMessage()); throw excep; } } - if(type == "normal"){ - try{ + if (type == "normal") + { + try + { qint64 id = GetParametrId(domElement); QString name = GetParametrString(domElement, "name"); qreal mx = toPixel(GetParametrDouble(domElement, "mx")); @@ -671,23 +860,29 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen qint64 secondPointId = GetParametrLongLong(domElement, "secondPoint"); qreal angle = GetParametrDouble(domElement, "angle"); - if(mode == Draw::Calculation){ + if (mode == Draw::Calculation) + { VToolNormal::Create(id, formula, firstPointId, secondPointId, typeLine, name, angle, mx, my, scene, this, data, parse, Tool::FromFile); - } else { + } + else + { VModelingNormal::Create(id, formula, firstPointId, secondPointId, typeLine, name, angle, mx, my, this, data, parse, Tool::FromFile); } return; } - catch(const VExceptionBadId &e){ + catch (const VExceptionBadId &e) + { VExceptionObjectError excep(tr("Error creating or updating point of normal"), domElement); excep.AddMoreInformation(e.ErrorMessage()); throw excep; } } - if(type == "bisector"){ - try{ + if (type == "bisector") + { + try + { qint64 id = GetParametrId(domElement); QString name = GetParametrString(domElement, "name"); qreal mx = toPixel(GetParametrDouble(domElement, "mx")); @@ -698,23 +893,29 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen qint64 secondPointId = GetParametrLongLong(domElement, "secondPoint"); qint64 thirdPointId = GetParametrLongLong(domElement, "thirdPoint"); - if(mode == Draw::Calculation){ + if (mode == Draw::Calculation) + { VToolBisector::Create(id, formula, firstPointId, secondPointId, thirdPointId, typeLine, name, mx, my, scene, this, data, parse, Tool::FromFile); - } else { + } + else + { VModelingBisector::Create(id, formula, firstPointId, secondPointId, thirdPointId, typeLine, name, mx, my, this, data, parse, Tool::FromFile); } return; } - catch(const VExceptionBadId &e){ + catch (const VExceptionBadId &e) + { VExceptionObjectError excep(tr("Error creating or updating point of bisector"), domElement); excep.AddMoreInformation(e.ErrorMessage()); throw excep; } } - if(type == "lineIntersect"){ - try{ + if (type == "lineIntersect") + { + try + { qint64 id = GetParametrId(domElement); QString name = GetParametrString(domElement, "name"); qreal mx = toPixel(GetParametrDouble(domElement, "mx")); @@ -724,23 +925,29 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen qint64 p1Line2Id = GetParametrLongLong(domElement, "p1Line2"); qint64 p2Line2Id = GetParametrLongLong(domElement, "p2Line2"); - if(mode == Draw::Calculation){ + if (mode == Draw::Calculation) + { VToolLineIntersect::Create(id, p1Line1Id, p2Line1Id, p1Line2Id, p2Line2Id, name, mx, my, scene, this, data, parse, Tool::FromFile); - } else { + } + else + { VModelingLineIntersect::Create(id, p1Line1Id, p2Line1Id, p1Line2Id, p2Line2Id, name, mx, my, this, data, parse, Tool::FromFile); } return; } - catch(const VExceptionBadId &e){ + catch (const VExceptionBadId &e) + { VExceptionObjectError excep(tr("Error creating or updating point of lineintersection"), domElement); excep.AddMoreInformation(e.ErrorMessage()); throw excep; } } - if(type == "pointOfContact"){ - try{ + if (type == "pointOfContact") + { + try + { qint64 id = GetParametrId(domElement); QString name = GetParametrString(domElement, "name"); qreal mx = toPixel(GetParametrDouble(domElement, "mx")); @@ -750,32 +957,41 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen qint64 firstPointId = GetParametrLongLong(domElement, "firstPoint"); qint64 secondPointId = GetParametrLongLong(domElement, "secondPoint"); - if(mode == Draw::Calculation){ + if (mode == Draw::Calculation) + { VToolPointOfContact::Create(id, radius, center, firstPointId, secondPointId, name, mx, my, scene, this, data, parse, Tool::FromFile); - } else { + } + else + { VModelingPointOfContact::Create(id, radius, center, firstPointId, secondPointId, name, mx, my, this, data, parse, Tool::FromFile); } return; } - catch(const VExceptionBadId &e){ + catch (const VExceptionBadId &e) + { VExceptionObjectError excep(tr("Error creating or updating point of contact"), domElement); excep.AddMoreInformation(e.ErrorMessage()); throw excep; } } - if(type == "modeling"){ - try{ + if (type == "modeling") + { + try + { qint64 id = GetParametrId(domElement); qint64 idObject = GetParametrLongLong(domElement, "idObject"); QString tObject = GetParametrString(domElement, "typeObject"); VPointF point; Draw::Draws typeObject; - if(tObject == "Calculation"){ + if (tObject == "Calculation") + { typeObject = Draw::Calculation; point = data->GetPoint(idObject ); - } else { + } + else + { typeObject = Draw::Modeling; point = data->GetModelingPoint(idObject); } @@ -786,31 +1002,131 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen VNodePoint::Create(this, data, id, idObject, mode, parse, Tool::FromFile); return; } - catch(const VExceptionBadId &e){ + catch (const VExceptionBadId &e) + { VExceptionObjectError excep(tr("Error creating or updating modeling point"), domElement); excep.AddMoreInformation(e.ErrorMessage()); 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; + } + } + if (type == "triangle") + { + try + { + qint64 id = GetParametrId(domElement); + QString name = GetParametrString(domElement, "name"); + qreal mx = toPixel(GetParametrDouble(domElement, "mx")); + qreal my = toPixel(GetParametrDouble(domElement, "my")); + qint64 axisP1Id = GetParametrLongLong(domElement, "axisP1"); + qint64 axisP2Id = GetParametrLongLong(domElement, "axisP2"); + qint64 firstPointId = GetParametrLongLong(domElement, "firstPoint"); + qint64 secondPointId = GetParametrLongLong(domElement, "secondPoint"); + + if (mode == Draw::Calculation) + { + VToolTriangle::Create(id, name, axisP1Id, axisP2Id, firstPointId, secondPointId, mx, my, + scene, this, data, parse, Tool::FromFile); + } + else + { + VModelingTriangle::Create(id, name, axisP1Id, axisP2Id, firstPointId, secondPointId, mx, my, + this, data, parse, Tool::FromFile); + } + return; + } + catch (const VExceptionBadId &e) + { + VExceptionObjectError excep(tr("Error creating or updating triangle"), domElement); + excep.AddMoreInformation(e.ErrorMessage()); + throw excep; + } + } + if (type == "pointOfIntersection") + { + try + { + qint64 id = GetParametrId(domElement); + QString name = GetParametrString(domElement, "name"); + qreal mx = toPixel(GetParametrDouble(domElement, "mx")); + qreal my = toPixel(GetParametrDouble(domElement, "my")); + qint64 firstPointId = GetParametrLongLong(domElement, "firstPoint"); + qint64 secondPointId = GetParametrLongLong(domElement, "secondPoint"); + + if (mode == Draw::Calculation) + { + VToolPointOfIntersection::Create(id, name, firstPointId, secondPointId, mx, my, scene, this, data, + parse, Tool::FromFile); + } + else + { + VModelingPointOfIntersection::Create(id, name, firstPointId, secondPointId, mx, my, this, data, + parse, Tool::FromFile); + } + return; + } + catch (const VExceptionBadId &e) + { + VExceptionObjectError excep(tr("Error creating or updating point of intersection"), domElement); + excep.AddMoreInformation(e.ErrorMessage()); + throw excep; + } + } } void VDomDocument::ParseLineElement(VMainGraphicsScene *scene, const QDomElement &domElement, - const Document::Documents &parse, Draw::Draws mode){ - Q_CHECK_PTR(scene); - Q_ASSERT_X(!domElement.isNull(), Q_FUNC_INFO, "domElement is null"); - try{ + const Document::Documents &parse, const Draw::Draws &mode) +{ + Q_ASSERT(scene != 0); + Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null"); + try + { qint64 id = GetParametrId(domElement); qint64 firstPoint = GetParametrLongLong(domElement, "firstPoint"); qint64 secondPoint = GetParametrLongLong(domElement, "secondPoint"); - if(mode == Draw::Calculation){ + if (mode == Draw::Calculation) + { VToolLine::Create(id, firstPoint, secondPoint, scene, this, data, parse, Tool::FromFile); - } else { + } + else + { VModelingLine::Create(id, firstPoint, secondPoint, this, data, parse, Tool::FromFile); } } - catch(const VExceptionBadId &e){ + catch (const VExceptionBadId &e) + { VExceptionObjectError excep(tr("Error creating or updating line"), domElement); excep.AddMoreInformation(e.ErrorMessage()); throw excep; @@ -818,13 +1134,15 @@ void VDomDocument::ParseLineElement(VMainGraphicsScene *scene, const QDomElement } void VDomDocument::ParseSplineElement(VMainGraphicsScene *scene, const QDomElement &domElement, - const Document::Documents &parse, const QString &type, - Draw::Draws mode){ - Q_CHECK_PTR(scene); - Q_ASSERT_X(!domElement.isNull(), Q_FUNC_INFO, "domElement is null"); - Q_ASSERT_X(!type.isEmpty(), Q_FUNC_INFO, "type of spline is empty"); - if(type == "simple"){ - try{ + const Document::Documents &parse, const QString &type, const Draw::Draws &mode) +{ + Q_ASSERT(scene != 0); + Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null"); + Q_ASSERT_X(type.isEmpty() == false, Q_FUNC_INFO, "type of spline is empty"); + if (type == "simple") + { + try + { qint64 id = GetParametrId(domElement); qint64 point1 = GetParametrLongLong(domElement, "point1"); qint64 point4 = GetParametrLongLong(domElement, "point4"); @@ -834,70 +1152,89 @@ void VDomDocument::ParseSplineElement(VMainGraphicsScene *scene, const QDomEleme qreal kAsm2 = GetParametrDouble(domElement, "kAsm2"); qreal kCurve = GetParametrDouble(domElement, "kCurve"); - if(mode == Draw::Calculation){ + if (mode == Draw::Calculation) + { VToolSpline::Create(id, point1, point4, kAsm1, kAsm2, angle1, angle2, kCurve, scene, this, data, parse, Tool::FromFile); - } else { + } + else + { VModelingSpline::Create(id, point1, point4, kAsm1, kAsm2, angle1, angle2, kCurve, this, data, parse, Tool::FromFile); } return; } - catch(const VExceptionBadId &e){ + catch (const VExceptionBadId &e) + { VExceptionObjectError excep(tr("Error creating or updating simple curve"), domElement); excep.AddMoreInformation(e.ErrorMessage()); throw excep; } } - if(type == "path"){ - try{ + if (type == "path") + { + try + { qint64 id = GetParametrId(domElement); qreal kCurve = GetParametrDouble(domElement, "kCurve"); VSplinePath path(data->DataPoints(), kCurve); QDomNodeList nodeList = domElement.childNodes(); qint32 num = nodeList.size(); - for(qint32 i = 0; i < num; ++i){ + for (qint32 i = 0; i < num; ++i) + { QDomElement element = nodeList.at(i).toElement(); - if(!element.isNull()){ - if(element.tagName() == "pathPoint"){ + if (element.isNull() == false) + { + if (element.tagName() == "pathPoint") + { qreal kAsm1 = GetParametrDouble(element, "kAsm1"); qreal angle = GetParametrDouble(element, "angle"); qreal kAsm2 = GetParametrDouble(element, "kAsm2"); qint64 pSpline = GetParametrLongLong(element, "pSpline"); VSplinePoint splPoint(pSpline, kAsm1, angle, kAsm2); path.append(splPoint); - if(parse == Document::FullParse){ + if (parse == Document::FullParse) + { IncrementReferens(pSpline); } } } } - if(mode == Draw::Calculation){ + if (mode == Draw::Calculation) + { VToolSplinePath::Create(id, path, scene, this, data, parse, Tool::FromFile); - } else { + } + else + { VModelingSplinePath::Create(id, path, this, data, parse, Tool::FromFile); } return; } - catch(const VExceptionBadId &e){ + catch (const VExceptionBadId &e) + { VExceptionObjectError excep(tr("Error creating or updating curve path"), domElement); excep.AddMoreInformation(e.ErrorMessage()); throw excep; } } - if(type == "modelingSpline"){ - try{ + if (type == "modelingSpline") + { + try + { qint64 id = GetParametrId(domElement); qint64 idObject = GetParametrLongLong(domElement, "idObject"); QString tObject = GetParametrString(domElement, "typeObject"); VSpline spl; Draw::Draws typeObject; - if(tObject == "Calculation"){ + if (tObject == "Calculation") + { typeObject = Draw::Calculation; spl = data->GetSpline(idObject); - } else { + } + else + { typeObject = Draw::Modeling; spl = data->GetModelingSpline(idObject); } @@ -907,23 +1244,29 @@ void VDomDocument::ParseSplineElement(VMainGraphicsScene *scene, const QDomEleme VNodeSpline::Create(this, data, id, idObject, mode, parse, Tool::FromFile); return; } - catch(const VExceptionBadId &e){ + catch (const VExceptionBadId &e) + { VExceptionObjectError excep(tr("Error creating or updating modeling simple curve"), domElement); excep.AddMoreInformation(e.ErrorMessage()); throw excep; } } - if(type == "modelingPath"){ - try{ + if (type == "modelingPath") + { + try + { qint64 id = GetParametrId(domElement); qint64 idObject = GetParametrLongLong(domElement, "idObject"); QString tObject = GetParametrString(domElement, "typeObject"); VSplinePath path; Draw::Draws typeObject; - if(tObject == "Calculation"){ + if (tObject == "Calculation") + { typeObject = Draw::Calculation; path = data->GetSplinePath(idObject); - } else { + } + else + { typeObject = Draw::Modeling; path = data->GetModelingSplinePath(idObject); } @@ -933,7 +1276,8 @@ void VDomDocument::ParseSplineElement(VMainGraphicsScene *scene, const QDomEleme VNodeSplinePath::Create(this, data, id, idObject, mode, parse, Tool::FromFile); return; } - catch(const VExceptionBadId &e){ + catch (const VExceptionBadId &e) + { VExceptionObjectError excep(tr("Error creating or updating modeling curve path"), domElement); excep.AddMoreInformation(e.ErrorMessage()); throw excep; @@ -942,43 +1286,55 @@ void VDomDocument::ParseSplineElement(VMainGraphicsScene *scene, const QDomEleme } void VDomDocument::ParseArcElement(VMainGraphicsScene *scene, const QDomElement &domElement, - const Document::Documents &parse, const QString &type, Draw::Draws mode){ - Q_CHECK_PTR(scene); - Q_ASSERT_X(!domElement.isNull(), Q_FUNC_INFO, "domElement is null"); - Q_ASSERT_X(!type.isEmpty(), Q_FUNC_INFO, "type of spline is empty"); - if(type == "simple"){ - try{ + const Document::Documents &parse, const QString &type, const Draw::Draws &mode) +{ + Q_ASSERT(scene != 0); + Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null"); + Q_ASSERT_X(type.isEmpty() == false, Q_FUNC_INFO, "type of spline is empty"); + if (type == "simple") + { + try + { qint64 id = GetParametrId(domElement); qint64 center = GetParametrLongLong(domElement, "center"); QString radius = GetParametrString(domElement, "radius"); QString f1 = GetParametrString(domElement, "angle1"); QString f2 = GetParametrString(domElement, "angle2"); - if(mode == Draw::Calculation){ + if (mode == Draw::Calculation) + { VToolArc::Create(id, center, radius, f1, f2, scene, this, data, parse, Tool::FromFile); - } else { + } + else + { VModelingArc::Create(id, center, radius, f1, f2, this, data, parse, Tool::FromFile); } return; } - catch(const VExceptionBadId &e){ + catch (const VExceptionBadId &e) + { VExceptionObjectError excep(tr("Error creating or updating simple arc"), domElement); excep.AddMoreInformation(e.ErrorMessage()); throw excep; } } - if(type == "modeling"){ - try{ + if (type == "modeling") + { + try + { qint64 id = GetParametrId(domElement); qint64 idObject = GetParametrLongLong(domElement, "idObject"); QString tObject = GetParametrString(domElement, "typeObject"); VArc arc; Draw::Draws typeObject; - if(tObject == "Calculation"){ + if (tObject == "Calculation") + { typeObject = Draw::Calculation; arc = data->GetArc(idObject); - } else { + } + else + { typeObject = Draw::Modeling; arc = data->GetModelingArc(idObject); } @@ -988,7 +1344,8 @@ void VDomDocument::ParseArcElement(VMainGraphicsScene *scene, const QDomElement VNodeArc::Create(this, data, id, idObject, mode, parse, Tool::FromFile); return; } - catch(const VExceptionBadId &e){ + catch (const VExceptionBadId &e) + { VExceptionObjectError excep(tr("Error creating or updating modeling arc"), domElement); excep.AddMoreInformation(e.ErrorMessage()); throw excep; @@ -996,14 +1353,17 @@ void VDomDocument::ParseArcElement(VMainGraphicsScene *scene, const QDomElement } } -void VDomDocument::FullUpdateTree(){ +void VDomDocument::FullUpdateTree() +{ VMainGraphicsScene *scene = new VMainGraphicsScene(); - Q_CHECK_PTR(scene); - try{ + Q_ASSERT(scene != 0); + try + { data->ClearObject(); Parse(Document::LiteParse, scene, scene); } - catch (const std::bad_alloc &) { + catch (const std::bad_alloc &) + { delete scene; QMessageBox msgBox; msgBox.setWindowTitle(tr("Error!")); @@ -1015,7 +1375,8 @@ void VDomDocument::FullUpdateTree(){ msgBox.exec(); return; } - catch(...){ + catch (...) + { delete scene; throw; } @@ -1026,46 +1387,54 @@ void VDomDocument::FullUpdateTree(){ emit haveChange(); } -void VDomDocument::haveLiteChange(){ +void VDomDocument::haveLiteChange() +{ emit haveChange(); } -void VDomDocument::ShowHistoryTool(qint64 id, Qt::GlobalColor color, bool enable){ +void VDomDocument::ShowHistoryTool(qint64 id, Qt::GlobalColor color, bool enable) +{ emit ShowTool(id, color, enable); } -qint64 VDomDocument::getCursor() const{ - return cursor; -} - -void VDomDocument::setCursor(const qint64 &value){ +void VDomDocument::setCursor(const qint64 &value) +{ cursor = value; emit ChangedCursor(cursor); } -void VDomDocument::setCurrentData(){ - if(*mode == Draw::Calculation){ +void VDomDocument::setCurrentData() +{ + if (*mode == Draw::Calculation) + { QString nameDraw = comboBoxDraws->itemText(comboBoxDraws->currentIndex()); - if(nameActivDraw != nameDraw){ + if (nameActivDraw != nameDraw) + { nameActivDraw = nameDraw; qint64 id = 0; - if(history.size() == 0){ + if (history.size() == 0) + { return; } - for(qint32 i = 0; i < history.size(); ++i){ + for (qint32 i = 0; i < history.size(); ++i) + { VToolRecord tool = history.at(i); - if(tool.getNameDraw() == nameDraw){ + if (tool.getNameDraw() == nameDraw) + { id = tool.getId(); } } - if(id == 0){ + if (id == 0) + { VToolRecord tool = history.at(history.size()-1); id = tool.getId(); - if(id == 0){ + if (id == 0) + { return; } } - if(tools.size() > 0){ + if (tools.size() > 0) + { VDataTool *vTool = tools.value(id); data->setData(vTool->getData()); } @@ -1073,30 +1442,34 @@ void VDomDocument::setCurrentData(){ } } -void VDomDocument::AddTool(const qint64 &id, VDataTool *tool){ +void VDomDocument::AddTool(const qint64 &id, VDataTool *tool) +{ Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0"); - Q_CHECK_PTR(tool); + Q_ASSERT(tool != 0); tools.insert(id, tool); } -void VDomDocument::UpdateToolData(const qint64 &id, VContainer *data){ +void VDomDocument::UpdateToolData(const qint64 &id, VContainer *data) +{ Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0"); - Q_CHECK_PTR(data); + Q_ASSERT(data != 0); VDataTool *tool = tools.value(id); - Q_CHECK_PTR(tool); + Q_ASSERT(tool != 0); tool->VDataTool::setData(data); } -void VDomDocument::IncrementReferens(qint64 id) const{ +void VDomDocument::IncrementReferens(qint64 id) const +{ Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0"); VDataTool *tool = tools.value(id); - Q_CHECK_PTR(tool); + Q_ASSERT(tool != 0); tool->incrementReferens(); } -void VDomDocument::DecrementReferens(qint64 id) const{ +void VDomDocument::DecrementReferens(qint64 id) const +{ Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0"); VDataTool *tool = tools.value(id); - Q_CHECK_PTR(tool); + Q_ASSERT(tool != 0); tool->decrementReferens(); } diff --git a/xml/vdomdocument.h b/xml/vdomdocument.h index 79cbc5625..1042beb9a 100644 --- a/xml/vdomdocument.h +++ b/xml/vdomdocument.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vdomdocument.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,105 +24,110 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef VDOMDOCUMENT_H #define VDOMDOCUMENT_H #include -#include -#include -#include "widgets/vmaingraphicsscene.h" -#include "tools/vdatatool.h" +#include "../container/vcontainer.h" +#include "../widgets/vmaingraphicsscene.h" +#include "../tools/vdatatool.h" #include "vtoolrecord.h" -namespace Document { +namespace Document +{ enum Document { LiteParse, FullParse}; Q_DECLARE_FLAGS(Documents, Document) } Q_DECLARE_OPERATORS_FOR_FLAGS(Document::Documents) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" -class VDomDocument : public QObject, public QDomDocument{ +#ifdef Q_CC_GNU + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Weffc++" +#endif +class VDomDocument : public QObject, public QDomDocument +{ Q_OBJECT public: - VDomDocument(VContainer *data,QComboBox *comboBoxDraws, Draw::Draws *mode); - VDomDocument(const QString& name, VContainer *data, QComboBox *comboBoxDraws, - Draw::Draws *mode); - VDomDocument(const QDomDocumentType& doctype, VContainer *data, QComboBox *comboBoxDraws, - Draw::Draws *mode); - ~VDomDocument(); - QDomElement elementById(const QString& id); - void CreateEmptyFile(); - void ChangeActivDraw(const QString& name, Document::Documents parse = Document::FullParse); - QString GetNameActivDraw() const; - bool GetActivDrawElement(QDomElement &element); - bool GetActivCalculationElement(QDomElement &element); - bool GetActivModelingElement(QDomElement &element); - bool GetActivDetailsElement(QDomElement &element); - bool appendDraw(const QString& name); - void SetNameDraw(const QString& name); - void Parse(Document::Documents parse, VMainGraphicsScene *sceneDraw, VMainGraphicsScene *sceneDetail); - QHash* getTools(); - QVector *getHistory(); - qint64 getCursor() const; - void setCursor(const qint64 &value); - void setCurrentData(); - void AddTool(const qint64 &id, VDataTool *tool); - void UpdateToolData(const qint64 &id, VContainer *data); - void IncrementReferens(qint64 id) const; - void DecrementReferens(qint64 id) const; + VDomDocument(VContainer *data, QComboBox *comboBoxDraws, Draw::Draws *mode); + VDomDocument(const QString& name, VContainer *data, QComboBox *comboBoxDraws, Draw::Draws *mode); + VDomDocument(const QDomDocumentType& doctype, VContainer *data, QComboBox *comboBoxDraws, + Draw::Draws *mode); + ~VDomDocument(){} + QDomElement elementById(const QString& id); + void CreateEmptyFile(); + void ChangeActivDraw(const QString& name, const Document::Documents &parse = Document::FullParse); + inline QString GetNameActivDraw() const {return nameActivDraw;} + bool GetActivDrawElement(QDomElement &element); + bool GetActivCalculationElement(QDomElement &element); + bool GetActivModelingElement(QDomElement &element); + bool GetActivDetailsElement(QDomElement &element); + bool appendDraw(const QString& name); + bool SetNameDraw(const QString& name); + void Parse(const Document::Documents &parse, VMainGraphicsScene *sceneDraw, + VMainGraphicsScene *sceneDetail); + inline QHash* getTools() {return &tools;} + inline QVector *getHistory() {return &history;} + inline qint64 getCursor() const {return cursor;} + void setCursor(const qint64 &value); + void setCurrentData(); + void AddTool(const qint64 &id, VDataTool *tool); + void UpdateToolData(const qint64 &id, VContainer *data); + void IncrementReferens(qint64 id) const; + void DecrementReferens(qint64 id) const; + void TestUniqueId() const; signals: - void ChangedActivDraw(const QString newName); - void ChangedNameDraw(const QString oldName, const QString newName); - void FullUpdateFromFile(); - void haveChange(); - void ShowTool(qint64 id, Qt::GlobalColor color, bool enable); - void ChangedCursor(qint64 id); + void ChangedActivDraw(const QString &newName); + void ChangedNameDraw(const QString oldName, const QString newName); + void FullUpdateFromFile(); + void haveChange(); + void ShowTool(qint64 id, Qt::GlobalColor color, bool enable); + void ChangedCursor(qint64 id); public slots: - void FullUpdateTree(); - void haveLiteChange(); - void ShowHistoryTool(qint64 id, Qt::GlobalColor color, bool enable); + void FullUpdateTree(); + void haveLiteChange(); + void ShowHistoryTool(qint64 id, Qt::GlobalColor color, bool enable); private: Q_DISABLE_COPY(VDomDocument) QHash map; - QString nameActivDraw; - VContainer *data; + QString nameActivDraw; + VContainer *data; QHash tools; QVector history; - qint64 cursor; - QComboBox *comboBoxDraws; - Draw::Draws *mode; - bool find(QDomElement node, const QString& id); - bool CheckNameDraw(const QString& name) const; - void SetActivDraw(const QString& name); - bool GetActivNodeElement(const QString& name, QDomElement& element); - void ParseDrawElement(VMainGraphicsScene *sceneDraw, VMainGraphicsScene *sceneDetail, - const QDomNode& node, const Document::Documents &parse); - void ParseDrawMode(VMainGraphicsScene *sceneDraw, VMainGraphicsScene *sceneDetail, - const QDomNode& node, const Document::Documents &parse, Draw::Draws mode); - void ParseDetailElement(VMainGraphicsScene *sceneDetail, const QDomElement &domElement, - const Document::Documents &parse); - void ParseDetails(VMainGraphicsScene *sceneDetail, const QDomElement &domElement, - const Document::Documents &parse); - void ParsePointElement(VMainGraphicsScene *scene, const QDomElement& domElement, - const Document::Documents &parse, const QString &type, Draw::Draws mode); - void ParseLineElement(VMainGraphicsScene *scene, const QDomElement& domElement, - const Document::Documents &parse, Draw::Draws mode); - void ParseSplineElement(VMainGraphicsScene *scene, const QDomElement& domElement, - const Document::Documents &parse, const QString& type, Draw::Draws mode); - void ParseArcElement(VMainGraphicsScene *scene, const QDomElement& domElement, - const Document::Documents &parse, const QString& type, Draw::Draws mode); - void ParseIncrementsElement(const QDomNode& node); - qint64 GetParametrId(const QDomElement& domElement) const; - qint64 GetParametrLongLong(const QDomElement& domElement, const QString &name) const; - QString GetParametrString(const QDomElement& domElement, const QString &name) const; - qreal GetParametrDouble(const QDomElement& domElement, const QString &name) const; - void TestUniqueId() const; - void CollectId(QDomElement node, QVector &vector)const; + qint64 cursor; + QComboBox *comboBoxDraws; + Draw::Draws *mode; + bool find(const QDomElement &node, const QString& id); + bool CheckNameDraw(const QString& name) const; + void SetActivDraw(const QString& name); + bool GetActivNodeElement(const QString& name, QDomElement& element); + void ParseDrawElement(VMainGraphicsScene *sceneDraw, VMainGraphicsScene *sceneDetail, + const QDomNode& node, const Document::Documents &parse); + void ParseDrawMode(VMainGraphicsScene *sceneDraw, VMainGraphicsScene *sceneDetail, + const QDomNode& node, const Document::Documents &parse, const Draw::Draws &mode); + void ParseDetailElement(VMainGraphicsScene *sceneDetail, const QDomElement &domElement, + const Document::Documents &parse); + void ParseDetails(VMainGraphicsScene *sceneDetail, const QDomElement &domElement, + const Document::Documents &parse); + void ParsePointElement(VMainGraphicsScene *scene, const QDomElement& domElement, + const Document::Documents &parse, const QString &type, const Draw::Draws &mode); + void ParseLineElement(VMainGraphicsScene *scene, const QDomElement& domElement, + const Document::Documents &parse, const Draw::Draws &mode); + void ParseSplineElement(VMainGraphicsScene *scene, const QDomElement& domElement, + const Document::Documents &parse, const QString& type, const Draw::Draws &mode); + void ParseArcElement(VMainGraphicsScene *scene, const QDomElement& domElement, + const Document::Documents &parse, const QString& type, const Draw::Draws &mode); + void ParseIncrementsElement(const QDomNode& node); + qint64 GetParametrId(const QDomElement& domElement) const; + qint64 GetParametrLongLong(const QDomElement& domElement, const QString &name) const; + QString GetParametrString(const QDomElement& domElement, const QString &name) const; + qreal GetParametrDouble(const QDomElement& domElement, const QString &name) const; + void CollectId(const QDomElement &node, QVector &vector)const; }; -#pragma GCC diagnostic pop +#ifdef Q_CC_GNU + #pragma GCC diagnostic pop +#endif #endif // VDOMDOCUMENT_H diff --git a/xml/vtoolrecord.cpp b/xml/vtoolrecord.cpp index 5fe3279b4..e5e69ac0a 100644 --- a/xml/vtoolrecord.cpp +++ b/xml/vtoolrecord.cpp @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vtoolrecord.cpp + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,37 +24,12 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #include "vtoolrecord.h" -VToolRecord::VToolRecord():id(0), typeTool(Tool::ArrowTool), nameDraw(QString()){ -} +VToolRecord::VToolRecord() + :id(0), typeTool(Tool::ArrowTool), nameDraw(QString()){} -VToolRecord::VToolRecord(const qint64 &id, const Tool::Tools &typeTool, const QString &nameDraw):id(id), - typeTool(typeTool), nameDraw(nameDraw){ -} - -QString VToolRecord::getNameDraw() const{ - return nameDraw; -} - -void VToolRecord::setNameDraw(const QString &value){ - nameDraw = value; -} - -Tool::Tools VToolRecord::getTypeTool() const{ - return typeTool; -} - -void VToolRecord::setTypeTool(const Tool::Tools &value){ - typeTool = value; -} - -qint64 VToolRecord::getId() const{ - return id; -} - -void VToolRecord::setId(const qint64 &value){ - id = value; -} +VToolRecord::VToolRecord(const qint64 &id, const Tool::Tools &typeTool, const QString &nameDraw) + :id(id), typeTool(typeTool), nameDraw(nameDraw){} diff --git a/xml/vtoolrecord.h b/xml/vtoolrecord.h index 6292aab9f..a2f964970 100644 --- a/xml/vtoolrecord.h +++ b/xml/vtoolrecord.h @@ -1,15 +1,22 @@ -/**************************************************************************** +/************************************************************************ ** - ** Copyright (C) 2013 Valentina project All Rights Reserved. + ** @file vtoolrecord.h + ** @author Roman Telezhinsky + ** @date November 15, 2013 ** - ** This file is part of Valentina. + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013 Valentina project + ** All Rights Reserved. ** - ** Tox is free software: you can redistribute it and/or modify + ** Valentina is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** - ** Tox is distributed in the hope that it will be useful, + ** Valentina is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. @@ -17,32 +24,26 @@ ** You should have received a copy of the GNU General Public License ** along with Valentina. If not, see . ** - ****************************************************************************/ + *************************************************************************/ #ifndef VTOOLRECORD_H #define VTOOLRECORD_H -#include -#include "options.h" - class VToolRecord { public: - VToolRecord(); - VToolRecord(const qint64 &id, const Tool::Tools &typeTool, const QString &nameDraw); - qint64 getId() const; - void setId(const qint64 &value); - - Tool::Tools getTypeTool() const; - void setTypeTool(const Tool::Tools &value); - - QString getNameDraw() const; - void setNameDraw(const QString &value); - + VToolRecord(); + VToolRecord(const qint64 &id, const Tool::Tools &typeTool, const QString &nameDraw); + inline qint64 getId() const {return id;} + inline void setId(const qint64 &value) {id = value;} + inline Tool::Tools getTypeTool() const {return typeTool;} + inline void setTypeTool(const Tool::Tools &value) {typeTool = value;} + inline QString getNameDraw() const {return nameDraw;} + inline void setNameDraw(const QString &value) {nameDraw = value;} private: - qint64 id; - Tool::Tools typeTool; - QString nameDraw; + qint64 id; + Tool::Tools typeTool; + QString nameDraw; }; #endif // VTOOLRECORD_H diff --git a/xml/xml.pri b/xml/xml.pri new file mode 100644 index 000000000..71489d606 --- /dev/null +++ b/xml/xml.pri @@ -0,0 +1,7 @@ +HEADERS += \ + xml/vtoolrecord.h \ + xml/vdomdocument.h + +SOURCES += \ + xml/vtoolrecord.cpp \ + xml/vdomdocument.cpp