diff --git a/Valentina.pro b/Valentina.pro index 6330a08f1..d15f58aec 100644 --- a/Valentina.pro +++ b/Valentina.pro @@ -4,9 +4,7 @@ # #------------------------------------------------- -QT += core gui xml - -greaterThan(QT_MAJOR_VERSION, 4): QT += widgets +QT += core gui widgets xml svg printsupport TARGET = Valentina TEMPLATE = app @@ -68,7 +66,10 @@ SOURCES += main.cpp\ tools/vmodelingpoint.cpp \ tools/vmodelingspline.cpp \ tools/vmodelingarc.cpp \ - tools/vmodelingsplinepath.cpp + tools/vmodelingsplinepath.cpp \ + widgets/vtablegraphicsview.cpp \ + widgets/vitem.cpp \ + tablewindow.cpp HEADERS += mainwindow.h \ widgets/vmaingraphicsscene.h \ @@ -127,7 +128,10 @@ HEADERS += mainwindow.h \ tools/vmodelingpoint.h \ tools/vmodelingspline.h \ tools/vmodelingarc.h \ - tools/vmodelingsplinepath.h + tools/vmodelingsplinepath.h \ + widgets/vtablegraphicsview.h \ + widgets/vitem.h \ + tablewindow.h FORMS += mainwindow.ui \ dialogs/dialogsinglepoint.ui \ @@ -144,7 +148,8 @@ FORMS += mainwindow.ui \ dialogs/dialogsplinepath.ui \ dialogs/dialoghistory.ui \ dialogs/dialogpointofcontact.ui \ - dialogs/dialogdetail.ui + dialogs/dialogdetail.ui \ + tablewindow.ui RESOURCES += \ icon.qrc \ diff --git a/container/vcontainer.cpp b/container/vcontainer.cpp index 65eff3b55..353ea35e2 100644 --- a/container/vcontainer.cpp +++ b/container/vcontainer.cpp @@ -29,6 +29,18 @@ const VContainer &VContainer::operator =(const VContainer &data){ return *this; } +VContainer::VContainer(const VContainer &data):base(QMap()), points(QMap()), + modelingPoints(QMap()), + standartTable(QMap()), incrementTable(QMap()), + lengthLines(QMap()), lineAngles(QMap()), splines(QMap()), + modelingSplines(QMap()), + lengthSplines(QMap()), arcs(QMap()), modelingArcs(QMap()), + lengthArcs(QMap()), + splinePaths(QMap()), modelingSplinePaths(QMap()), + details(QMap()){ + setData(data); +} + void VContainer::setData(const VContainer &data){ base = *data.DataBase(); points = *data.DataPoints(); @@ -169,6 +181,52 @@ void VContainer::IncrementReferens(qint64 id, Scene::Type obj){ } } +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(Scene::Line): + break; + case(Scene::Point):{ + VPointF point = GetModelingPoint(detail[i].getId()); + points.append(point.toQPointF()); + } + break; + case(Scene::Arc):{ + VArc arc = GetModelingArc(detail[i].getId()); + points << arc.GetPoints(); + } + break; + case(Scene::Spline):{ + VSpline spline = GetModelingSpline(detail[i].getId()); + points << spline.GetPoints(); + } + break; + case(Scene::SplinePath):{ + VSplinePath splinePath = GetModelingSplinePath(detail[i].getId()); + points << splinePath.GetPathPoints(); + } + break; + } + } + QPainterPath path; + path.moveTo(points[0]); + for (qint32 i = 1; i < points.count(); ++i){ + path.lineTo(points[i]); + } + path.lineTo(points[0]); + return path; +} + +void VContainer::PrepareDetails(QVector &list) const{ + QMapIterator iDetail(details); + while (iDetail.hasNext()) { + iDetail.next(); + list.append(new VItem(ContourPath(iDetail.key()), list.size())); + } +} + void VContainer::RemoveIncrementTableRow(const QString& name){ incrementTable.remove(name); } diff --git a/container/vcontainer.h b/container/vcontainer.h index 5a4ff5cc5..b0b0d053b 100644 --- a/container/vcontainer.h +++ b/container/vcontainer.h @@ -17,6 +17,7 @@ #include "../geometry/varc.h" #include "../geometry/vsplinepath.h" #include "../geometry/vdetail.h" +#include "../widgets/vitem.h" /** * @brief The VContainer class @@ -29,6 +30,7 @@ public: */ VContainer(); const VContainer &operator=(const VContainer &data); + VContainer(const VContainer &data); void setData(const VContainer &data); /** * @brief GetPoint @@ -118,6 +120,8 @@ public: const QMap *DataDetails() const; void UpdateId(qint64 newId); void IncrementReferens(qint64 id, Scene::Type obj); + QPainterPath ContourPath(qint64 idDetail) const; + void PrepareDetails(QVector & list)const; private: static qint64 _id; QMap base; diff --git a/geometry/vdetail.cpp b/geometry/vdetail.cpp index 44e6f64ea..34d30d958 100644 --- a/geometry/vdetail.cpp +++ b/geometry/vdetail.cpp @@ -27,32 +27,26 @@ VNodeDetail &VDetail::operator [](int indx){ return nodes[indx]; } -qreal VDetail::getMy() const -{ +qreal VDetail::getMy() const{ return my; } -void VDetail::setMy(const qreal &value) -{ +void VDetail::setMy(const qreal &value){ my = value; } -qreal VDetail::getMx() const -{ +qreal VDetail::getMx() const{ return mx; } -void VDetail::setMx(const qreal &value) -{ +void VDetail::setMx(const qreal &value){ mx = value; } -QString VDetail::getName() const -{ +QString VDetail::getName() const{ return name; } -void VDetail::setName(const QString &value) -{ +void VDetail::setName(const QString &value){ name = value; } diff --git a/geometry/vdetail.h b/geometry/vdetail.h index b7d074554..95cf3e9cb 100644 --- a/geometry/vdetail.h +++ b/geometry/vdetail.h @@ -4,6 +4,7 @@ #include "vnodedetail.h" #include #include +#include class VDetail { diff --git a/icon.qrc b/icon.qrc index 111777384..739f4bdee 100644 --- a/icon.qrc +++ b/icon.qrc @@ -32,5 +32,7 @@ icon/32x32/put_after.png icon/32x32/point_of_contact.png icon/32x32/new_detail.png + icon/32x32/layout.png + icon/16x16/mirror.png diff --git a/icon/16x16/mirror.png b/icon/16x16/mirror.png new file mode 100644 index 000000000..63ad5188f Binary files /dev/null and b/icon/16x16/mirror.png differ diff --git a/icon/32x32/layout.png b/icon/32x32/layout.png new file mode 100644 index 000000000..9da8385e6 Binary files /dev/null and b/icon/32x32/layout.png differ diff --git a/main.cpp b/main.cpp index bca09f559..aebdb7d35 100644 --- a/main.cpp +++ b/main.cpp @@ -1,9 +1,7 @@ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" #include "mainwindow.h" #include #include -#pragma GCC diagnostic pop +#include "tablewindow.h" void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg){ QByteArray localMsg = msg.toLocal8Bit(); @@ -32,6 +30,9 @@ int main(int argc, char *argv[]){ QApplication app(argc, argv); MainWindow w; app.setWindowIcon(QIcon(":/icon/64x64/icon64x64.png")); + TableWindow table; + QObject::connect(&w, &MainWindow::ModelChosen, &table, &TableWindow::ModelChosen); + QObject::connect(&table, &TableWindow::closed, &w, &MainWindow::tableClosed); w.show(); return app.exec(); diff --git a/mainwindow.cpp b/mainwindow.cpp index 139b6fa7b..1c5445003 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -69,7 +69,6 @@ MainWindow::MainWindow(QWidget *parent) : connect(ui->actionOpen, &QAction::triggered, this, &MainWindow::ActionOpen); connect(ui->actionNew, &QAction::triggered, this, &MainWindow::ActionNew); connect(ui->actionTable, &QAction::triggered, this, &MainWindow::ActionTable); - connect(ui->actionHistory, &QAction::triggered, this, &MainWindow::ActionHistory); connect(ui->toolButtonEndLine, &QToolButton::clicked, this, &MainWindow::ToolEndLine); connect(ui->toolButtonLine, &QToolButton::clicked, this, &MainWindow::ToolLine); connect(ui->toolButtonAlongLine, &QToolButton::clicked, this, &MainWindow::ToolAlongLine); @@ -85,7 +84,7 @@ MainWindow::MainWindow(QWidget *parent) : data = new VContainer; - doc = new VDomDocument(data, comboBoxDraws); + doc = new VDomDocument(data, comboBoxDraws, &mode); doc->CreateEmptyFile(); connect(doc, &VDomDocument::haveChange, this, &MainWindow::haveChange); @@ -364,6 +363,11 @@ void MainWindow::ClosedDialogDetail(int result){ ArrowTool(); } +void MainWindow::tableClosed(){ + show(); + MinimumScrollBar(); +} + void MainWindow::showEvent( QShowEvent *event ){ QMainWindow::showEvent( event ); if( event->spontaneous() ){ @@ -374,10 +378,7 @@ void MainWindow::showEvent( QShowEvent *event ){ return; } // do your init stuff here - QScrollBar *horScrollBar = view->horizontalScrollBar(); - horScrollBar->setValue(horScrollBar->minimum()); - QScrollBar *verScrollBar = view->verticalScrollBar(); - verScrollBar->setValue(verScrollBar->minimum()); + MinimumScrollBar(); isInitialized = true;//перший показ вікна вже відбувся } @@ -441,6 +442,10 @@ void MainWindow::ToolBarDraws(){ ui->toolBarDraws->addAction(ui->actionHistory); ui->actionHistory->setEnabled(false); + connect(ui->actionHistory, &QAction::triggered, this, &MainWindow::ActionHistory); + + ui->toolBarDraws->addAction(ui->actionLayout); + connect(ui->actionLayout, &QAction::triggered, this, &MainWindow::ActionLayout); } void MainWindow::currentDrawChanged( int index ){ @@ -567,6 +572,7 @@ void MainWindow::ActionDraw(bool checked){ currentScene = sceneDraw; view->setScene(currentScene); mode = Draw::Calculation; + doc->setCurrentData(); } else { ui->actionDraw->setChecked(true); } @@ -735,6 +741,14 @@ void MainWindow::ActionHistory(bool checked){ } } +void MainWindow::ActionLayout(bool checked){ + Q_UNUSED(checked); + hide(); + QVector listDetails; + data->PrepareDetails(listDetails); + emit ModelChosen(listDetails); +} + void MainWindow::ClosedActionHistory(){ ui->actionHistory->setChecked(false); delete dialogHistory; @@ -755,6 +769,13 @@ void MainWindow::SetEnableTool(bool enable){ ui->toolButtonNewDetail->setEnabled(enable); } +void MainWindow::MinimumScrollBar(){ + QScrollBar *horScrollBar = view->horizontalScrollBar(); + horScrollBar->setValue(horScrollBar->minimum()); + QScrollBar *verScrollBar = view->verticalScrollBar(); + verScrollBar->setValue(verScrollBar->minimum()); +} + MainWindow::~MainWindow(){ CanselTool(); delete ui; diff --git a/mainwindow.h b/mainwindow.h index 5d6b43a27..28253430c 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -35,6 +35,7 @@ #pragma GCC diagnostic pop #include "container/vcontainer.h" #include "options.h" +#include "widgets/vitem.h" namespace Ui { class MainWindow; @@ -64,6 +65,7 @@ public slots: void ActionTable(bool checked); void ClosedActionTable(); void ActionHistory(bool checked); + void ActionLayout(bool checked); void ClosedActionHistory(); void ToolEndLine(bool checked); void ClosedDialogEndLine(int result); @@ -89,6 +91,17 @@ public slots: void ClosedDialogPointOfContact(int result); void ToolDetail(bool checked); void ClosedDialogDetail(int result); + /** + * @brief tableClosed Слот, що виконується при отриманні сигналу закриття вікна укладання + *деталей моделі. + */ + void tableClosed(); +signals: + /** + * @brief ModelChosen Сигнал, що висилається після розрахунку всіх деталей моделі. + * @param listDetails Список детайле моделі. + */ + void ModelChosen(QVector listDetails); protected: virtual void keyPressEvent ( QKeyEvent * event ); virtual void showEvent( QShowEvent *event ); @@ -132,7 +145,8 @@ private: void SetEnableTool(bool enable); template void SetToolButton(bool checked, Tools::Enum t, const QString &cursor, QSharedPointer &dialog, - Func closeDialogSlot); + Func closeDialogSlot); + void MinimumScrollBar(); }; #endif // MAINWINDOW_H diff --git a/mainwindow.ui b/mainwindow.ui index a7603ca1b..3be0957ff 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -37,7 +37,7 @@ 0 0 - 150 + 144 104 @@ -641,6 +641,15 @@ History + + + + :/icon/32x32/layout.png:/icon/32x32/layout.png + + + Розкладка + + diff --git a/tablewindow.cpp b/tablewindow.cpp new file mode 100644 index 000000000..dc5e5202e --- /dev/null +++ b/tablewindow.cpp @@ -0,0 +1,354 @@ +#include "tablewindow.h" +#include "ui_tablewindow.h" +#include +#include +#include "widgets/vtablegraphicsview.h" +#include +#include "options.h" +#include +#undef PaperSize +#include + +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()){ + 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(823), toPixel(1171)); + currentScene = new QGraphicsScene(sceneRect); + QBrush *brush = new QBrush(); + brush->setStyle( Qt::SolidPattern ); + brush->setColor( QColor( Qt::gray ) ); + currentScene->setBackgroundBrush( *brush ); + VTableGraphicsView* view = new VTableGraphicsView(currentScene); + 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); + connect(ui->actionZoomIn, &QAction::triggered, view, &VTableGraphicsView::ZoomIn); + connect(ui->actionZoomOut, &QAction::triggered, view, &VTableGraphicsView::ZoomOut); + connect(ui->actionStop, &QAction::triggered, this, &TableWindow::StopTable); + connect(ui->actionSave, &QAction::triggered, this, &TableWindow::saveScene); + connect(ui->actionNext, &QAction::triggered, this, &TableWindow::GetNextDetail); + connect(ui->actionAdd, &QAction::triggered, this, &TableWindow::AddLength); + connect(ui->actionRemove, &QAction::triggered, this, &TableWindow::RemoveLength); + connect(view, &VTableGraphicsView::itemChect, this, &TableWindow::itemChect); +} + +TableWindow::~TableWindow(){ + delete ui; +} + +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->setBrush(QBrush(Qt::black)); + currentScene->addItem(shadowPaper); + paper = new QGraphicsRectItem(QRectF(x1,y1,x2, y2)); + paper->setPen(QPen(Qt::black, toPixel(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(this, SIGNAL(LengthChanged()), Detail, SLOT(LengthChanged())); + Detail->setPen(QPen(Qt::black, toPixel(widthMainLine))); + 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->setSelected(true); + indexDetail++; + if(indexDetail==listDetails.count()){ + ui->actionSave->setEnabled(true); + } + } + numberDetal->setText(QString("Залишилось %1 деталей.").arg(listDetails.count()-indexDetail)); +} + +/* + * Отримуємо деталі розрахованої моделі для подальшого укладання. + */ +void TableWindow::ModelChosen(QVector listDetails){ + this->listDetails = listDetails; + listOutItems = new QBitArray(this->listDetails.count()); + AddPaper(); + indexDetail = 0; + AddDetail(); + show(); +} + +void TableWindow::closeEvent(QCloseEvent *event){ + event->ignore(); + StopTable(); +} + +void TableWindow::moveToCenter(){ + QRect rect = frameGeometry(); + rect.moveCenter(QDesktopWidget().availableGeometry().center()); + move(rect.topLeft()); +} + +void TableWindow::showEvent ( QShowEvent * event ){ + QMainWindow::showEvent(event); + moveToCenter(); +} + +void TableWindow::StopTable(){ + hide(); + currentScene->clear(); + delete listOutItems; + listDetails.clear(); + //sceneRect = QRectF(0, 0, 230*resol/25.9, 327*resol/25.9); + sceneRect = QRectF(0, 0, toPixel(823), toPixel(1171)); + emit closed(); +} + +void TableWindow::saveScene(){ + QString name = QFileDialog::getSaveFileName(0, "Зберегти розкладку", "", "Images (*.png);;Svg files (*.svg);;Ps files (*.ps)"); + 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()); + + QFileInfo fi(name); + if(fi.suffix() == "svg"){ + SvgFile(name); + } else if(fi.suffix() == "png"){ + PngFile(name); + } else if(fi.suffix() == "ps"){ + PsFile(name); + } +// 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)); +} + +void TableWindow::itemChect(bool flag){ + ui->actionTurn->setDisabled(flag); + ui->actionMirror->setDisabled(flag); +} + +void TableWindow::checkNext(){ + if(outItems == true && collidingItems == true){ + colission->setText("Колізій не знайдено."); + if(indexDetail==listDetails.count()){ + ui->actionSave->setEnabled(true); + ui->actionNext->setDisabled(true); + } else { + ui->actionNext->setDisabled(false); + ui->actionSave->setEnabled(false); + } + } 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){ + outItems=false; + qDebug()<<"itemOut::outItems="< 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){ + VItem * bitem = qgraphicsitem_cast ( listCollidingItems.at(i) ); + if (bitem == 0){ + qDebug()<<"Не можу привести тип об'єкту"; + } else { + bitem->setPen(QPen(Qt::black, toPixel(widthMainLine))); + } + listCollidingItems.removeAt(i); + } + } + } else if(listCollidingItems.size()==1){ + VItem * bitem = qgraphicsitem_cast ( listCollidingItems.at(0) ); + if (bitem == 0){ + qDebug()<<"Не можу привести тип об'єкту"; + } else { + bitem->setPen(QPen(Qt::black, toPixel(widthMainLine))); + } + listCollidingItems.clear(); + collidingItems = true; + } + } else { + collidingItems = true; + } + } else { + collidingItems = true; + } + } else if(number==1){ + if(list.contains(paper)==true){ + list.removeAt(list.indexOf(paper)); + } + 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){ + listCollidingItems.append(list.at(i)); + } + } + collidingItems = false; + } + qDebug()<<"itemColliding::outItems="<sceneRect(); + rect.setHeight(rect.height()+toPixel(279)); + currentScene->setSceneRect(rect); + rect = shadowPaper->rect(); + rect.setHeight(rect.height()+toPixel(279)); + shadowPaper->setRect(rect); + rect = paper->rect(); + rect.setHeight(rect.height()+toPixel(279)); + paper->setRect(rect); + ui->actionRemove->setEnabled(true); + emit LengthChanged(); +} + +void TableWindow::RemoveLength(){ + if(sceneRect.height()<=currentScene->sceneRect().height()-100){ + QRectF rect = currentScene->sceneRect(); + rect.setHeight(rect.height()-toPixel(279)); + currentScene->setSceneRect(rect); + rect = shadowPaper->rect(); + rect.setHeight(rect.height()-toPixel(279)); + shadowPaper->setRect(rect); + rect = paper->rect(); + rect.setHeight(rect.height()-toPixel(279)); + paper->setRect(rect); + if(sceneRect.height()==currentScene->sceneRect().height()){ + ui->actionRemove->setDisabled(true); + } + emit LengthChanged(); + } 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 ){ + AddDetail(); + qDebug()<<"Додали деталь."; + } + } + QMainWindow::keyPressEvent ( event ); +} + + +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.")); + 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.setBrush ( QBrush ( Qt::NoBrush ) ); + currentScene->render(&painter); + painter.end(); +} + +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(w, h), QImage::Format_ARGB32); // Create the image with the exact size of the shrunk scene + 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.setBrush ( QBrush ( Qt::NoBrush ) ); + currentScene->render(&painter); + image.save(name); +} + +void TableWindow::PsFile(const QString &name) const{ + + QPrinter printer(QPrinter::HighResolution); + //printer.setOutputFormat(QPrinter::PostScriptFormat); + + printer.setOutputFileName(name); + QRectF r = paper->rect(); + qreal x=0, y=0, w=0, h=0; + r.getRect(&x,&y,&w,&h); + printer.setResolution(PrintDPI); + qDebug()<render(&painter); + painter.end(); +} diff --git a/tablewindow.h b/tablewindow.h new file mode 100644 index 000000000..e902bbb28 --- /dev/null +++ b/tablewindow.h @@ -0,0 +1,170 @@ +#ifndef TABLEWINDOW_H +#define TABLEWINDOW_H + +#include +#include +#include "widgets/vitem.h" + +namespace Ui { + class TableWindow; +} + +/** + * @brief TableWindow клас вікна створення розкладки. + */ +class TableWindow : public QMainWindow{ + Q_OBJECT +public: + /** + * @brief numberDetal Виводиться кількість деталей що ще залишилися. + */ + QLabel* numberDetal; + /** + * @brief colission Виводиться чи є колізії. + */ + QLabel* colission; + /** + * @brief TableWindow Конструктор класу вікна створення розкладки. + * @param parent Батько об'єкту. За замовчуванням = 0. + */ + explicit TableWindow(QWidget *parent = 0); + /** + * @brief ~TableWindow Деструктор класу вікна. + */ + ~TableWindow(); +public slots: + /** + * @brief ModelChosen Слот, що виконується при отриманні сигналу про розрахунок всіх деталей + *моделі. + * @param listDetails Список моделей деталі. + */ + void ModelChosen(QVector listDetails); + /** + * @brief StopTable Слот, що виконується при хованні вікна. Виконує неохідні очищення і ховає + *вікно. + */ + void StopTable(); + /** + * @brief saveScene Слот виконується при натисненні кнопки зберегти. + */ + void saveScene(); + /** + * @brief GetNextDetail Слот виконується при натисненні кнопки наступна деталь. + */ + void GetNextDetail(); + /** + * @brief itemChect Відключає можливість виклику перевороту, якщо не вибрано жодної деталі. + * @param flag Булеве значення що регулює стан кнопки. + */ + void itemChect(bool flag); + /** + * @brief itemOut Слот, що виконується при отриманні сигналу виходу за межі листа. + * @param number Номер деталі в списку що вийшла за межі. + * @param flag Зберігає стан деталі. + */ + void itemOut(int number, bool flag); + /** + * @brief itemColliding Сигнал, що виконується при отриманні сигналу колізії об'єктів. + * @param list Список об'єктів що перетинаються. + * @param number 0 - включити до списку деталей що перетинаються, 1 - виключити зі списку. + */ + void itemColliding(QList list, int number); + /** + * @brief AddLength Збільшує довжину листа на певне значення за один раз. + */ + void AddLength(); + /** + * @brief RemoveLength Зменшує довжину листа на певне знечення за один раз. + *Зменшення відбувається до мінімально заданого значення. + */ + void RemoveLength(); +signals: + /** + * @brief closed Сигнал посилається при хованні вікна. + */ + void closed(); + /** + * @brief LengthChanged Сигнал посилається при зміні розміру листа. + */ + void LengthChanged(); +protected: + /** + * @brief closeEvent Перехоплення події закриття. + * @param event Подія що отримується. + */ + void closeEvent(QCloseEvent *event); + /** + * @brief moveToCenter Переміщує вікно у центер екрану. + */ + void moveToCenter(); + /** + * @brief showEvent Перехоплення події показу вікна для розміщення його поцентру. + * @param event Подія що отримується. + */ + void showEvent ( QShowEvent * event ); + void keyPressEvent ( QKeyEvent * event ); +private: + /** + * @brief ui Змінна для доступу до об'єктів вікна. + */ + Ui::TableWindow* ui; + /** + * @brief listDetails Список деталей на укладання. + */ + QVector listDetails; + /** + * @brief outItems Змінна зберігає показує чи маємо деталі що виходять за межі листа. + */ + bool outItems; + /** + * @brief collidingItems Змінна показує чи маємо деталі що перетинаються. + */ + bool collidingItems; + /** + * @brief currentScene Зберігається покажчик на сцену. + */ + QGraphicsScene* currentScene; + /** + * @brief paper Зберігається покажчик на прямокутник що імітує листа паперу. + */ + QGraphicsRectItem* paper; + /** + * @brief shadowPaper Зберігається покажчик на прямокутник що імітує тінь листа паперу. + */ + QGraphicsRectItem* shadowPaper; + /** + * @brief checkNext Метод регулює стан кнопки Next. + */ + void checkNext(); + /** + * @brief listOutItems Список стану виходу за лист кожної деталі. + */ + QBitArray* listOutItems; + /** + * @brief listCollidingItems Список що зберігає деталі що перетинаються між собою. + */ + QList listCollidingItems; + /** + * @brief AddPaper Додає на сцену лист паперу з тінню. + */ + void AddPaper(); + /** + * @brief AddDetail Додає наступну деталь. + */ + void AddDetail(); + /** + * @brief indexDetail Індекс деталі в списку, що буде викладатися наступного разу. + */ + qint32 indexDetail; + /** + * @brief sceneRect Мінімальний розмір листа паперу що буде показуватися на сцені. + */ + QRectF sceneRect; + TableWindow(const TableWindow &window); + const TableWindow &operator=(const TableWindow& window); + void SvgFile(const QString &name)const; + void PngFile(const QString &name)const; + void PsFile(const QString &name)const; +}; + +#endif // TABLEWINDOW_H diff --git a/tablewindow.ui b/tablewindow.ui new file mode 100644 index 000000000..f26a00dae --- /dev/null +++ b/tablewindow.ui @@ -0,0 +1,186 @@ + + + TableWindow + + + + 0 + 0 + 1000 + 730 + + + + Створення розкладки + + + + + QLayout::SetMinAndMaxSize + + + 9 + + + + + + toolBar + + + + 16 + 16 + + + + Qt::ToolButtonIconOnly + + + TopToolBarArea + + + false + + + + + + + + + + + + + + + false + + + + + + + + Зберегти + + + Зберегти розкладку + + + + + + + + + + Наступна + + + Наступна деталь + + + + + false + + + + + + + + Перевернути + + + Перевернути деталь на 180 градусів + + + + + + + + + + Stop + + + Припинити укладання + + + + + + + + + + Збільшити лист + + + Збільшити довжину листа + + + + + false + + + + + + + + Зменшити лист + + + Зменшити довжину листа + + + + + false + + + + :/icon/16x16/mirror.png:/icon/16x16/mirror.png + + + Відзеркалити + + + Дзеркальне зображення деталі + + + + + + + + + + Збільшити + + + Збільшити + + + + + + + + + + Зменшити + + + + + + + + diff --git a/tools/vabstracttool.cpp b/tools/vabstracttool.cpp index dde80e47e..ae66fd83e 100644 --- a/tools/vabstracttool.cpp +++ b/tools/vabstracttool.cpp @@ -103,10 +103,6 @@ const VContainer *VAbstractTool::getData()const{ return &data; } -void VAbstractTool::setData(const VContainer &value){ - data = value; -} - void VAbstractTool::setDialog(){ } diff --git a/tools/vabstracttool.h b/tools/vabstracttool.h index 4cc497fe5..589d01413 100644 --- a/tools/vabstracttool.h +++ b/tools/vabstracttool.h @@ -56,7 +56,6 @@ protected: void AddAttribute(QDomElement &domElement, const QString &name, const QString &value); void AddToDraw(const QDomElement &domElement); const VContainer *getData() const; - void setData(const VContainer &value); template void ContextMenu(QSharedPointer &dialog, Tool *tool, QGraphicsSceneContextMenuEvent *event, bool showRemove = true){ diff --git a/tools/vdatatool.cpp b/tools/vdatatool.cpp index ed9de74e9..31f26ac12 100644 --- a/tools/vdatatool.cpp +++ b/tools/vdatatool.cpp @@ -20,5 +20,6 @@ VContainer VDataTool::getData() const{ } void VDataTool::setData(const VContainer *value){ + data.Clear(); data = *value; } diff --git a/tools/vmodelingarc.cpp b/tools/vmodelingarc.cpp index 6b2e1b4fc..3ca7f6956 100644 --- a/tools/vmodelingarc.cpp +++ b/tools/vmodelingarc.cpp @@ -51,8 +51,8 @@ void VModelingArc::ShowTool(qint64 id, Qt::GlobalColor color, bool enable){ } } -void VModelingArc::FullUpdateFromGui(int result) -{ +void VModelingArc::FullUpdateFromGui(int result){ + Q_UNUSED(result); } void VModelingArc::AddToFile(){ diff --git a/tools/vmodelingpoint.cpp b/tools/vmodelingpoint.cpp index 8721b57a0..d9c916452 100644 --- a/tools/vmodelingpoint.cpp +++ b/tools/vmodelingpoint.cpp @@ -32,8 +32,8 @@ void VModelingPoint::FullUpdateFromFile(){ RefreshGeometry(); } -void VModelingPoint::FullUpdateFromGui(int result) -{ +void VModelingPoint::FullUpdateFromGui(int result){ + Q_UNUSED(result); } void VModelingPoint::AddToFile(){ diff --git a/tools/vmodelingspline.cpp b/tools/vmodelingspline.cpp index 612e4b5fa..b448442b3 100644 --- a/tools/vmodelingspline.cpp +++ b/tools/vmodelingspline.cpp @@ -52,8 +52,8 @@ void VModelingSpline::ShowTool(qint64 id, Qt::GlobalColor color, bool enable){ } } -void VModelingSpline::FullUpdateFromGui(int result) -{ +void VModelingSpline::FullUpdateFromGui(int result){ + Q_UNUSED(result); } void VModelingSpline::AddToFile(){ diff --git a/tools/vmodelingsplinepath.cpp b/tools/vmodelingsplinepath.cpp index e2cb3bcad..e0cd6beef 100644 --- a/tools/vmodelingsplinepath.cpp +++ b/tools/vmodelingsplinepath.cpp @@ -53,8 +53,8 @@ void VModelingSplinePath::ShowTool(qint64 id, Qt::GlobalColor color, bool enable } } -void VModelingSplinePath::FullUpdateFromGui(int result) -{ +void VModelingSplinePath::FullUpdateFromGui(int result){ + Q_UNUSED(result); } void VModelingSplinePath::AddToFile(){ diff --git a/tools/vtoolalongline.cpp b/tools/vtoolalongline.cpp index a17ea34c4..7fea11336 100644 --- a/tools/vtoolalongline.cpp +++ b/tools/vtoolalongline.cpp @@ -118,7 +118,6 @@ void VToolAlongLine::Create(const qint64 _id, const QString &pointName, const QS VDataTool *tool = tools->value(id); if(tool != 0){ tool->VDataTool::setData(data); - tools->insert(id, tool); data->IncrementReferens(id, Scene::Point); } } diff --git a/tools/vtoolarc.cpp b/tools/vtoolarc.cpp index 635e815f4..2cdd9aa83 100644 --- a/tools/vtoolarc.cpp +++ b/tools/vtoolarc.cpp @@ -80,7 +80,6 @@ void VToolArc::Create(const qint64 _id, const qint64 ¢er, const QString &rad VDataTool *tool = tools->value(id); if(tool != 0){ tool->VDataTool::setData(data); - tools->insert(id, tool); data->IncrementReferens(id, Scene::Arc); } } diff --git a/tools/vtoolbisector.cpp b/tools/vtoolbisector.cpp index 8f3897bc8..13cd68072 100644 --- a/tools/vtoolbisector.cpp +++ b/tools/vtoolbisector.cpp @@ -80,7 +80,6 @@ void VToolBisector::Create(const qint64 _id, const QString &formula, const qint6 VDataTool *tool = tools->value(id); if(tool != 0){ tool->VDataTool::setData(data); - tools->insert(id, tool); data->IncrementReferens(id, Scene::Point); } } diff --git a/tools/vtooldetail.cpp b/tools/vtooldetail.cpp index cbafd9428..355dbbd50 100644 --- a/tools/vtooldetail.cpp +++ b/tools/vtooldetail.cpp @@ -142,14 +142,12 @@ void VToolDetail::Create(const qint64 _id, VDetail &newDetail, VDetail &oldDetai VDataTool *tool = tools->value(id); if(tool != 0){ tool->VDataTool::setData(data); - tools->insert(id, tool); } for(qint32 i = 0; i< newDetail.CountNode(); ++i){ VDataTool *tool = tools->value(newDetail[i].getId()); if(tool != 0){ tool->VDataTool::setData(data); - tools->insert(id, tool); } } } @@ -168,8 +166,8 @@ void VToolDetail::FullUpdateFromFile(){ RefreshGeometry(); } -void VToolDetail::FullUpdateFromGui(int result) -{ +void VToolDetail::FullUpdateFromGui(int result){ + Q_UNUSED(result); } void VToolDetail::AddToFile(){ @@ -213,16 +211,18 @@ void VToolDetail::AddNode(QDomElement &domElement, VNodeDetail &node){ AddAttribute(nod, "id", node.getId()); switch(node.getTypeTool()){ - case(Scene::Point): + case(Scene::Line): + break; + case(Scene::Point): AddAttribute(nod, "type", "Point"); break; - case(Scene::Arc): + case(Scene::Arc): AddAttribute(nod, "type", "Arc"); break; - case(Scene::Spline): + case(Scene::Spline): AddAttribute(nod, "type", "Spline"); break; - case(Scene::SplinePath): + case(Scene::SplinePath): AddAttribute(nod, "type", "SplinePath"); break; } @@ -231,38 +231,6 @@ void VToolDetail::AddNode(QDomElement &domElement, VNodeDetail &node){ } void VToolDetail::RefreshGeometry(){ - QVector points; - VDetail detail = VAbstractTool::data.GetDetail(id); - for(qint32 i = 0; i< detail.CountNode(); ++i){ - switch(detail[i].getTypeTool()){ - case(Scene::Point):{ - VPointF point = VAbstractTool::data.GetModelingPoint(detail[i].getId()); - points.append(point.toQPointF()); - } - break; - case(Scene::Arc):{ - VArc arc = VAbstractTool::data.GetModelingArc(detail[i].getId()); - points << arc.GetPoints(); - } - break; - case(Scene::Spline):{ - VSpline spline = VAbstractTool::data.GetModelingSpline(detail[i].getId()); - points << spline.GetPoints(); - } - break; - case(Scene::SplinePath):{ - VSplinePath splinePath = VAbstractTool::data.GetModelingSplinePath(detail[i].getId()); - points << splinePath.GetPathPoints(); - } - break; - } - } - QPainterPath path; - path.moveTo(points[0]); - for (qint32 i = 1; i < points.count(); ++i){ - path.lineTo(points[i]); - } - path.lineTo(points[0]); + QPainterPath path = VAbstractTool::data.ContourPath(id); this->setPath(path); - //this->setPos(detail.getMx(), detail.getMy()); } diff --git a/tools/vtoolendline.cpp b/tools/vtoolendline.cpp index 2235c70dd..6c207cd7a 100644 --- a/tools/vtoolendline.cpp +++ b/tools/vtoolendline.cpp @@ -63,7 +63,6 @@ void VToolEndLine::Create(const qint64 _id, const QString &pointName, const QStr VDataTool *tool = tools->value(id); if(tool != 0){ tool->VDataTool::setData(data); - tools->insert(id, tool); data->IncrementReferens(id, Scene::Point); } } diff --git a/tools/vtoolline.cpp b/tools/vtoolline.cpp index 9e239e00c..bf54a8faa 100644 --- a/tools/vtoolline.cpp +++ b/tools/vtoolline.cpp @@ -50,7 +50,6 @@ void VToolLine::Create(const qint64 &id, const qint64 &firstPoint, const qint64 VDataTool *tool = tools->value(id); Q_CHECK_PTR(tool); tool->VDataTool::setData(data); - tools->insert(id, tool); } VAbstractTool::AddRecord(id, Tools::LineTool, doc); if(mode == Draw::Modeling){ diff --git a/tools/vtoollineintersect.cpp b/tools/vtoollineintersect.cpp index 5bf915b51..48f45290f 100644 --- a/tools/vtoollineintersect.cpp +++ b/tools/vtoollineintersect.cpp @@ -64,7 +64,6 @@ void VToolLineIntersect::Create(const qint64 _id, const qint64 &p1Line1Id, const VDataTool *tool = tools->value(id); if(tool != 0){ tool->VDataTool::setData(data); - tools->insert(id, tool); data->IncrementReferens(id, Scene::Point); } } diff --git a/tools/vtoolnormal.cpp b/tools/vtoolnormal.cpp index 57e87cb42..7ee78ab94 100644 --- a/tools/vtoolnormal.cpp +++ b/tools/vtoolnormal.cpp @@ -68,7 +68,6 @@ void VToolNormal::Create(const qint64 _id, const QString &formula, const qint64 VDataTool *tool = tools->value(id); if(tool != 0){ tool->VDataTool::setData(data); - tools->insert(id, tool); data->IncrementReferens(id, Scene::Point); } } diff --git a/tools/vtoolpointofcontact.cpp b/tools/vtoolpointofcontact.cpp index 19ccd1747..00261faf1 100644 --- a/tools/vtoolpointofcontact.cpp +++ b/tools/vtoolpointofcontact.cpp @@ -83,7 +83,6 @@ void VToolPointOfContact::Create(const qint64 _id, const QString &radius, const VDataTool *tool = tools->value(id); if(tool != 0){ tool->VDataTool::setData(data); - tools->insert(id, tool); data->IncrementReferens(id, Scene::Point); } } diff --git a/tools/vtoolshoulderpoint.cpp b/tools/vtoolshoulderpoint.cpp index f95453ccf..269cdf4c3 100644 --- a/tools/vtoolshoulderpoint.cpp +++ b/tools/vtoolshoulderpoint.cpp @@ -92,7 +92,6 @@ void VToolShoulderPoint::Create(const qint64 _id, const QString &formula, const VDataTool *tool = tools->value(id); if(tool != 0){ tool->VDataTool::setData(data); - tools->insert(id, tool); data->IncrementReferens(id, Scene::Point); } } diff --git a/tools/vtoolspline.cpp b/tools/vtoolspline.cpp index d572056c2..801868191 100644 --- a/tools/vtoolspline.cpp +++ b/tools/vtoolspline.cpp @@ -87,7 +87,6 @@ void VToolSpline::Create(const qint64 _id, const qint64 &p1, const qint64 &p4, c VDataTool *tool = tools->value(id); if(tool != 0){ tool->VDataTool::setData(data); - tools->insert(id, tool); data->IncrementReferens(id, Scene::Spline); } } diff --git a/tools/vtoolsplinepath.cpp b/tools/vtoolsplinepath.cpp index 00dd9c8db..18d5a0fe6 100644 --- a/tools/vtoolsplinepath.cpp +++ b/tools/vtoolsplinepath.cpp @@ -65,7 +65,6 @@ void VToolSplinePath::Create(const qint64 _id, const VSplinePath &path, VMainGra VDataTool *tool = tools->value(id); if(tool != 0){ tool->VDataTool::setData(data); - tools->insert(id, tool); data->IncrementReferens(id, Scene::SplinePath); } } diff --git a/widgets/vitem.cpp b/widgets/vitem.cpp new file mode 100644 index 000000000..a7e18cc6f --- /dev/null +++ b/widgets/vitem.cpp @@ -0,0 +1,62 @@ +#include "vitem.h" +#include +#include +#include "../options.h" + +VItem::VItem():numInOutList(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(); + QRectF myrect = sceneBoundingRect(); + if( rect.contains( myrect )==true ){ + qDebug()<<"Не виходить за рамки листа"; + setPen(QPen(Qt::black, widthMainLine)); + emit itemOut( numInOutList, false ); + } else { + qDebug()<<"Виходить за рамки листа"; + setPen(QPen(Qt::red, widthMainLine)); + emit itemOut( numInOutList, true ); + } + QList list = QGraphicsItem::collidingItems (); + if( list.size() - 2 > 0 ){ + list.append( this ); + setPen(QPen(Qt::red, widthMainLine)); + qDebug()<<"Деталь перетинається з іншими деталями "< itemList; + itemList.append( this ); + qDebug()<<"Деталь більше не перетинається з іншими деталями "< +#include +#include +#include +#include + +VTableGraphicsView::VTableGraphicsView(QGraphicsScene* pScene, QWidget *parent) : + QGraphicsView(pScene, parent){ + QGraphicsView::setResizeAnchor(QGraphicsView::AnchorUnderMouse); + connect(pScene, &QGraphicsScene::selectionChanged, this, &VTableGraphicsView::selectionChanged); +} + +void VTableGraphicsView::selectionChanged(){ + QList listSelectedItems = scene()->selectedItems(); + if( listSelectedItems.isEmpty() == true ){ + qDebug() << "деталь не знайдено"; + emit itemChect(true); + } else { + qDebug() << "деталь знайдено"; + emit itemChect(false); + } +} + +void VTableGraphicsView::rotateItems(){ + rotateIt(); +} + +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(); + //Get the current transform + QTransform transform(list.at(i)->transform()); + + qreal m11 = transform.m11(); // Horizontal scaling + qreal m12 = transform.m12(); // Vertical shearing + qreal m13 = transform.m13(); // Horizontal Projection + qreal m21 = transform.m21(); // Horizontal shearing + qreal m22 = transform.m22(); // vertical scaling + qreal m23 = transform.m23(); // Vertical Projection + qreal m31 = transform.m31(); // Horizontal Position (DX) + qreal m32 = transform.m32(); // Vertical Position (DY) + qreal m33 = transform.m33(); // Addtional Projection Factor + + // Horizontal flip + m11 = -m11; + + // Write back to the matrix + 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(); + qreal dx, dy; + dx = itemRectOld.center().x()-itemRectNew.center().x(); + dy = itemRectOld.center().y()-itemRectNew.center().y(); + list.at(i)->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){ + // Если нажата клавиша CTRL этот код выполнится + if ((event->delta())>0){ + ZoomIn(); + } else if ((event->delta())<0){ + ZoomOut(); + } + } 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::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; + } + QGraphicsView::keyPressEvent ( event ); +} + +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); + } + } +} + +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; + } + QList listSelectedItems = scene()->selectedItems(); + 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 new file mode 100644 index 000000000..e0ad77bac --- /dev/null +++ b/widgets/vtablegraphicsview.h @@ -0,0 +1,73 @@ +#ifndef VTABLEGRAPHICSVIEW_H +#define VTABLEGRAPHICSVIEW_H + +#include + +class VTableGraphicsView : public QGraphicsView +{ + Q_OBJECT +public: + enum typeMove_e { Left, Right, Up, Down }; + explicit VTableGraphicsView(QGraphicsScene* pScene, QWidget *parent = 0); + +signals: + /** + * @brief itemChect Сигнал, що посилається коли змінюється стан вибору деталі. + * @param flag Зберігає стан вибору деталі: false - знайдено, true - не знайдено. + */ + void itemChect( bool flag ); +public slots: + /** + * @brief selectionChanged Слот виконується при зміні стану вибору деталей. + */ + void selectionChanged(); + /** + * @brief rotateItems слот, який виконується при натисненні кнопки повороту деталі. + */ + void rotateItems(); + /** + * @brief MirrorItem дзеркалить об'єкт відносно вертикальної вісі семетрії об'єкта. + */ + void MirrorItem(); + /** + * @brief ZoomIn збільшує масштаб листа. + */ + void ZoomIn(); + /** + * @brief ZoomOut зменшує масштаб листа. + */ + void ZoomOut(); +protected: + /** + * @brief wheelEvent обробник повороту колеса мишки. + * @param event передається подія. + */ + void wheelEvent ( QWheelEvent * event ); + /** + * @brief mousePressEvent обробник натиснення кнопки миші. + * @param mousePress передається подія. + */ + void mousePressEvent(QMouseEvent *mousePress); + /** + * @brief mouseReleaseEvent обробник відпускання кнопки миші. + * @param event передається подія + */ + void mouseReleaseEvent ( QMouseEvent * event ); + /** + * @brief keyPressEvent обробник натиснення клавіші. + * @param event передається подія. + */ + void keyPressEvent ( QKeyEvent * event ); + /** + * @brief rotateIt виконує поворот вибраних деталей на 180 градусів. + */ + void rotateIt(); + /** + * @brief MoveItem переміщує виділені об'єкти сцени. + * @param move напрямок переміщення. + */ + void MoveItem( VTableGraphicsView::typeMove_e move ); + +}; + +#endif // VTABLEGRAPHICSVIEW_H diff --git a/xml/vdomdocument.cpp b/xml/vdomdocument.cpp index 7b4b2b798..f4cef2937 100644 --- a/xml/vdomdocument.cpp +++ b/xml/vdomdocument.cpp @@ -20,22 +20,24 @@ -VDomDocument::VDomDocument(VContainer *data, QComboBox *comboBoxDraws) : QDomDocument(), +VDomDocument::VDomDocument(VContainer *data, QComboBox *comboBoxDraws, Draw::Mode *mode) : QDomDocument(), map(QMap()), nameActivDraw(QString()), data(data), tools(QMap()), history(QVector()), cursor(0), - comboBoxDraws(comboBoxDraws){ + comboBoxDraws(comboBoxDraws), mode(mode){ } -VDomDocument::VDomDocument(const QString& name, VContainer *data, QComboBox *comboBoxDraws) : +VDomDocument::VDomDocument(const QString& name, VContainer *data, QComboBox *comboBoxDraws, + Draw::Mode *mode) : QDomDocument(name), map(QMap()), nameActivDraw(QString()), data(data), tools(QMap()), history(QVector()), cursor(0), - comboBoxDraws(comboBoxDraws){ + comboBoxDraws(comboBoxDraws), mode(mode){ } -VDomDocument::VDomDocument(const QDomDocumentType& doctype, VContainer *data, QComboBox *comboBoxDraws) : +VDomDocument::VDomDocument(const QDomDocumentType& doctype, VContainer *data, QComboBox *comboBoxDraws, + Draw::Mode *mode) : QDomDocument(doctype), map(QMap()), nameActivDraw(QString()), data(data), tools(QMap()), history(QVector()), cursor(0), - comboBoxDraws(comboBoxDraws){ + comboBoxDraws(comboBoxDraws), mode(mode){ } VDomDocument::~VDomDocument(){ @@ -748,29 +750,31 @@ void VDomDocument::setCursor(const qint64 &value){ } void VDomDocument::setCurrentData(){ - QString nameDraw = comboBoxDraws->itemText(comboBoxDraws->currentIndex()); - if(nameActivDraw != nameDraw){ - nameActivDraw = nameDraw; - qint64 id = 0; - if(history.size() == 0){ - return; - } - for(qint32 i = 0; i < history.size(); ++i){ - VToolRecord tool = history.at(i); - if(tool.getNameDraw() == nameDraw){ - id = tool.getId(); - } - } - if(id == 0){ - VToolRecord tool = history.at(history.size()-1); - id = tool.getId(); - if(id == 0){ + if(*mode == Draw::Calculation){ + QString nameDraw = comboBoxDraws->itemText(comboBoxDraws->currentIndex()); + if(nameActivDraw != nameDraw){ + nameActivDraw = nameDraw; + qint64 id = 0; + if(history.size() == 0){ return; } - } - if(tools.size() > 0){ - VDataTool *vTool = tools.value(id); - data->setData(vTool->getData()); + for(qint32 i = 0; i < history.size(); ++i){ + VToolRecord tool = history.at(i); + if(tool.getNameDraw() == nameDraw){ + id = tool.getId(); + } + } + if(id == 0){ + VToolRecord tool = history.at(history.size()-1); + id = tool.getId(); + if(id == 0){ + return; + } + } + if(tools.size() > 0){ + VDataTool *vTool = tools.value(id); + data->setData(vTool->getData()); + } } } } diff --git a/xml/vdomdocument.h b/xml/vdomdocument.h index 617024674..d67cd0649 100644 --- a/xml/vdomdocument.h +++ b/xml/vdomdocument.h @@ -30,9 +30,11 @@ class VDomDocument : public QObject, public QDomDocument { Q_OBJECT public: - VDomDocument(VContainer *data,QComboBox *comboBoxDraws); - VDomDocument(const QString& name, VContainer *data,QComboBox *comboBoxDraws); - VDomDocument(const QDomDocumentType& doctype, VContainer *data, QComboBox *comboBoxDraws); + VDomDocument(VContainer *data,QComboBox *comboBoxDraws, Draw::Mode *mode); + VDomDocument(const QString& name, VContainer *data, QComboBox *comboBoxDraws, + Draw::Mode *mode); + VDomDocument(const QDomDocumentType& doctype, VContainer *data, QComboBox *comboBoxDraws, + Draw::Mode *mode); ~VDomDocument(); QDomElement elementById(const QString& id); void CreateEmptyFile(); @@ -70,6 +72,7 @@ private: QVector history; qint64 cursor; QComboBox *comboBoxDraws; + Draw::Mode *mode; VDomDocument(const VDomDocument & doc); const VDomDocument &operator=(const VDomDocument& doc); bool find(QDomElement node, const QString& id);