# HG changeset patch # User Alexis Jeandet # Date 2015-06-19 20:02:47 # Node ID 72560b13551af2ecaa74dc1811c46f43e75a3011 # Parent e725b52b6a877c95993e6caa1a71bcab4d2bff17 Added Polygon drawing but huge perf issue, to be solved. diff --git a/qilib/qicadlisplikelexique.cpp b/qilib/qicadlisplikelexique.cpp --- a/qilib/qicadlisplikelexique.cpp +++ b/qilib/qicadlisplikelexique.cpp @@ -49,6 +49,7 @@ const char* feature1_c = "(feature1 const char* feature2_c = "(feature2"; const char* field_c = "(field"; const char* fields_c = "(fields"; +const char* filled_polygon_c = "(filled_polygon"; const char* font_c = "(font"; const char* fp_circle_c = "(fp_circle"; const char* fp_line_c = "(fp_line"; @@ -112,8 +113,10 @@ const char* plotinvisibletext_c = " const char* plotothertext_c = "(plotothertext"; const char* plotreference_c = "(plotreference"; const char* plotvalue_c = "(plotvalue"; +const char* polygon_c = "(polygon"; const char* psa4output_c = "(psa4output"; const char* psnegative_c = "(psnegative"; +const char* pts_c = "(pts"; const char* ref_c = "(ref"; const char* rotate = "(rota"; const char* scale_c = "(scale"; @@ -158,6 +161,7 @@ const char* viasonmask_c = "(viason const char* visible_elements_c = "(visible_elements"; const char* width_c = "(width"; const char* xyz = "(x"; +const char* xy_c = "(xy"; const char* zone_45_only_c = "(zone_45_only"; const char* zone_clearance_c = "(zone_clearance"; const char* zone_c = "(zone"; diff --git a/qilib/qicadlisplikelexique.h b/qilib/qicadlisplikelexique.h --- a/qilib/qicadlisplikelexique.h +++ b/qilib/qicadlisplikelexique.h @@ -59,6 +59,7 @@ extern "C" const char* feature1_c; extern "C" const char* feature2_c; extern "C" const char* field_c; extern "C" const char* fields_c; +extern "C" const char* filled_polygon_c; extern "C" const char* font_c; extern "C" const char* fp_circle_c; extern "C" const char* fp_line_c; @@ -122,8 +123,10 @@ extern "C" const char* plotinvisiblete extern "C" const char* plotothertext_c; extern "C" const char* plotreference_c; extern "C" const char* plotvalue_c; +extern "C" const char* polygon_c; extern "C" const char* psa4output_c; extern "C" const char* psnegative_c; +extern "C" const char* pts_c; extern "C" const char* ref_c; extern "C" const char* rotate; extern "C" const char* scale_c; @@ -168,6 +171,7 @@ extern "C" const char* viasonmask_c; extern "C" const char* visible_elements_c; extern "C" const char* width_c; extern "C" const char* xyz; +extern "C" const char* xy_c; extern "C" const char* zone_45_only_c; extern "C" const char* zone_clearance_c; extern "C" const char* zone_c; diff --git a/qilib/qicadpcb.cpp b/qilib/qicadpcb.cpp --- a/qilib/qicadpcb.cpp +++ b/qilib/qicadpcb.cpp @@ -1120,10 +1120,118 @@ void QIlib::QIcadPcbZone::setNode(QIlib: if(node->name==QIlib::Lexique::zone_c) { this->p_node = node; + for(int i=0;inodes.count();i++) + { + if(node->nodes.at(i)->name==QIlib::Lexique::polygon_c) + { + this->polygon.setNode(node->nodes.at(i)); + } + if(node->nodes.at(i)->name==QIlib::Lexique::filled_polygon_c) + { + this->filledPolygon.setNode(node->nodes.at(i)); + } + if(node->nodes.at(i)->name==QIlib::Lexique::layer_c) + { + this->layer.setNode(node->nodes.at(i)); + } + } + } +} + + +QIlib::QIcadPcbPolygonPoint::QIcadPcbPolygonPoint(QIlib::AbstractNode *node) + :QIcadAbstractNodeWrapper(node) +{ + this->p_pos.setX(0.0); + this->p_pos.setY(0.0); + this->setNode(node); +} + +void QIlib::QIcadPcbPolygonPoint::setNode(QIlib::AbstractNode *node) +{ + if(node->name==QIlib::Lexique::xy_c) + { + this->p_node = node; + this->p_pos = nodeTo2DCoords(node); } } +QIlib::QIcadPcbPolygon::QIcadPcbPolygon(QIlib::AbstractNode *node) + :QIcadAbstractNodeWrapper(node) +{ + this->setNode(node); +} + +void QIlib::QIcadPcbPolygon::setNode(QIlib::AbstractNode *node) +{ + if(node->name==QIlib::Lexique::polygon_c) + { + this->p_node = node; + this->p_filled = false; + for(int i=0;inodes.count();i++) + { + if(node->nodes.at(i)->name==QIlib::Lexique::pts_c) + { + this->points.setNode(node->nodes.at(i)); + } + } + } + if(node->name==QIlib::Lexique::filled_polygon_c) + { + this->p_node = node; + this->p_filled = true; + for(int i=0;inodes.count();i++) + { + if(node->nodes.at(i)->name==QIlib::Lexique::pts_c) + { + this->points.setNode(node->nodes.at(i)); + } + } + } +} + +QIlib::QIcadPcbPolygonPoints::QIcadPcbPolygonPoints(QIlib::AbstractNode *node) + :QIcadAbstractNodeWrapper(node) +{ + this->setNode(node); +} + +void QIlib::QIcadPcbPolygonPoints::setNode(QIlib::AbstractNode *node) +{ + this->clrPoints(); + if(node->name==QIlib::Lexique::pts_c) + { + this->p_node = node; + for(int i=0;inodes.count();i++) + { + if(node->nodes.at(i)->name==QIlib::Lexique::xy_c) + { + this->apendPoint(node->nodes.at(i)); + } + } + } +} + +void QIlib::QIcadPcbPolygonPoints::clrPoints() +{ + while(points.count()) + { + QIcadPcbPolygonPoint* point; + point = points.last(); + points.removeLast(); + delete point; + } +} + +void QIlib::QIcadPcbPolygonPoints::apendPoint(QIlib::AbstractNode *node) +{ + if(node->name==QIlib::Lexique::xy_c) + { + this->points.append(new QIcadPcbPolygonPoint(node)); + } +} + const QPointF QIlib::nodeTo2DCoords(QIlib::AbstractNode *node) { QPointF point; @@ -1193,3 +1301,8 @@ const QSizeF QIlib::nodeTo2DSize(QIlib:: } return size; } + + + + + diff --git a/qilib/qicadpcb.h b/qilib/qicadpcb.h --- a/qilib/qicadpcb.h +++ b/qilib/qicadpcb.h @@ -363,11 +363,52 @@ public: void setNode(QIlib::AbstractNode* node); }; + +class QIcadPcbPolygonPoint : public QIcadAbstractNodeWrapper +{ +public: + QIcadPcbPolygonPoint(QIlib::AbstractNode* node); + QIcadPcbPolygonPoint(){} + void setNode(QIlib::AbstractNode* node); + const QPointF& pos(){return p_pos;} +private: + QPointF p_pos; +}; + + +class QIcadPcbPolygonPoints : public QIcadAbstractNodeWrapper +{ +public: + QIcadPcbPolygonPoints(QIlib::AbstractNode* node); + QIcadPcbPolygonPoints(){} + void setNode(QIlib::AbstractNode* node); + QList points; + void clrPoints(); + void apendPoint(QIlib::AbstractNode* node); +private: + QPointF p_pos; +}; + +class QIcadPcbPolygon : public QIcadAbstractNodeWrapper +{ +public: + QIcadPcbPolygon(QIlib::AbstractNode* node); + QIcadPcbPolygon(){} + QIcadPcbPolygonPoints points; + void setNode(QIlib::AbstractNode* node); + bool isFilled(){return p_filled;} +private: + bool p_filled; +}; + class QIcadPcbZone : public QIcadAbstractNodeWrapper { public: QIcadPcbZone(QIlib::AbstractNode* node); QIcadPcbZone(){} + QIcadPcbPolygon polygon; + QIcadPcbPolygon filledPolygon; + QIcadAbstractNodeWrapper layer; void setNode(QIlib::AbstractNode* node); }; diff --git a/test/PCBView/PCBView.pro b/test/PCBView/PCBView.pro --- a/test/PCBView/PCBView.pro +++ b/test/PCBView/PCBView.pro @@ -25,18 +25,20 @@ LIBS += -L../../bin -lQIlib SOURCES += main.cpp\ mainwindow.cpp \ pcbgraphicview.cpp \ - pcbrectpad.cpp \ pcbmodule.cpp \ pcbline.cpp \ pcbcontext.cpp \ - pcbvia.cpp + pcbvia.cpp \ + pcbpad.cpp \ + pcbzone.cpp HEADERS += mainwindow.h \ pcbgraphicview.h \ - pcbrectpad.h \ pcbmodule.h \ pcbline.h \ pcbcontext.h \ - pcbvia.h + pcbvia.h \ + pcbpad.h \ + pcbzone.h FORMS += mainwindow.ui diff --git a/test/PCBView/mainwindow.cpp b/test/PCBView/mainwindow.cpp --- a/test/PCBView/mainwindow.cpp +++ b/test/PCBView/mainwindow.cpp @@ -24,6 +24,7 @@ #include "pcbmodule.h" #include "pcbline.h" #include "pcbvia.h" +#include "pcbzone.h" #include @@ -33,6 +34,7 @@ MainWindow::MainWindow(QWidget *parent) { ui->setupUi(this); this->p_scene = new QGraphicsScene(); +// this->p_scene->setItemIndexMethod(QGraphicsScene::NoIndex); this->context = new PCBContext(); this->ui->graphicsView->setScene(this->p_scene); this->pcbDriver =NULL; @@ -78,10 +80,7 @@ void MainWindow::loadFile(const QString pcbDriver = new QIlib::QIcadPcb(); this->context->clear(); this->p_scene->clear(); -// pcbDriver.parsePcb("/opt/kicadTools/test/testFiles/pcb2.kicad_pcb"); -// pcbDriver.parsePcb("/home/jeandet/Documents/PCB/ADC_STAMP/ADC_STAMP.kicad_pcb"); pcbDriver->parsePcb(file); -// pcbDriver.parsePcb("/usr/share/kicad/demos/kit-dev-coldfire-xilinx_5213/kit-dev-coldfire-xilinx_5213.kicad_pcb"); for(int i=0;ipcbRoot->layers.layers.count();i++) { this->context->addlayer(pcbDriver->pcbRoot->layers.layers.at(i)->name(),pcbDriver->pcbRoot->layers.layers.at(i)->index()); @@ -102,4 +101,8 @@ void MainWindow::loadFile(const QString { this->p_scene->addItem(new PCBVia(pcbDriver->pcbRoot->vias.at(i),this->context)); } + for(int i=0;ipcbRoot->zones.count();i++) + { + this->p_scene->addItem(new PCBZone(pcbDriver->pcbRoot->zones.at(i),this->context)); + } } diff --git a/test/PCBView/pcbgraphicview.cpp b/test/PCBView/pcbgraphicview.cpp --- a/test/PCBView/pcbgraphicview.cpp +++ b/test/PCBView/pcbgraphicview.cpp @@ -23,11 +23,12 @@ #include #include +#include +#include PCBGraphicView::PCBGraphicView(QWidget *parent) :QGraphicsView(parent) { - this->setRenderHint(QPainter::Antialiasing, true); this->setDragMode(QGraphicsView::RubberBandDrag); this->setOptimizationFlags(QGraphicsView::DontSavePainterState); @@ -37,10 +38,10 @@ PCBGraphicView::PCBGraphicView(QWidget * this->setTransformationAnchor(AnchorUnderMouse); this->scale(qreal(0.8), qreal(0.8)); this->setRubberBandSelectionMode(Qt::ContainsItemBoundingRect); - this->setDragMode(RubberBandDrag); this->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); this->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - +// this->setViewport(new QOpenGLWidget()); + QPixmapCache::setCacheLimit(1024*1024*4); this->ctrl_pressed = false; this->shift_pressed = false; } @@ -82,22 +83,23 @@ void PCBGraphicView::keyReleaseEvent(QKe void PCBGraphicView::wheelEvent(QWheelEvent *event) { - - if (event->modifiers() & Qt::ControlModifier) - { - if (event->orientation()== Qt::Vertical) - scaleView(pow((double)2, event->delta() / 240.0)); - } - else - { - if (event->modifiers() & Qt::ShiftModifier) + if (event->modifiers() & Qt::ControlModifier) { - QWheelEvent* tempevent = new QWheelEvent(event->pos(),(event->delta()/10),event->buttons(),event->modifiers(),Qt::Horizontal); - QGraphicsView::wheelEvent(tempevent); + event->accept(); + if (event->orientation()== Qt::Vertical) + scaleView(pow((double)2, event->delta() / 240.0)); } else - QGraphicsView::wheelEvent(event); - } + { + if (event->modifiers() & Qt::ShiftModifier) + { + event->accept(); + QWheelEvent* tempevent = new QWheelEvent(event->pos(),(event->delta()/10),event->buttons(),event->modifiers(),Qt::Horizontal); + QGraphicsView::wheelEvent(tempevent); + } + else + QGraphicsView::wheelEvent(event); + } } diff --git a/test/PCBView/pcbgraphicview.h b/test/PCBView/pcbgraphicview.h --- a/test/PCBView/pcbgraphicview.h +++ b/test/PCBView/pcbgraphicview.h @@ -28,6 +28,7 @@ #include #include #include +#include class PCBGraphicView : public QGraphicsView { diff --git a/test/PCBView/pcbmodule.cpp b/test/PCBView/pcbmodule.cpp --- a/test/PCBView/pcbmodule.cpp +++ b/test/PCBView/pcbmodule.cpp @@ -21,15 +21,13 @@ ----------------------------------------------------------------------------*/ #include "pcbmodule.h" #include "pcbline.h" -#include "pcbrectpad.h" +#include "pcbpad.h" PCBModule::PCBModule(QIlib::QIcadPcbModule *moduleNode, PCBContext *context) :QGraphicsItemGroup(),context(context) { this->setCacheMode(QGraphicsItem::DeviceCoordinateCache); this->setFlags(ItemIsMovable|ItemIsSelectable|ItemIsFocusable); -// this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); -// this->addToGroup(new QGraphicsRectItem(0,0,2,2)); this->setPos(moduleNode->pos()); for(int i=0;ifp_lines.count();i++) { @@ -37,7 +35,7 @@ PCBModule::PCBModule(QIlib::QIcadPcbModu } for(int i=0;ipads.count();i++) { - this->addToGroup(new PCBRectPad((QIlib::QIcadPcbPad*)moduleNode->pads.at(i),moduleNode->pos(),context)); + this->addToGroup(new PCBPad((QIlib::QIcadPcbPad*)moduleNode->pads.at(i),moduleNode->pos(),context)); } this->setRotation(moduleNode->angle()); } diff --git a/test/PCBView/pcbrectpad.cpp b/test/PCBView/pcbpad.cpp rename from test/PCBView/pcbrectpad.cpp rename to test/PCBView/pcbpad.cpp --- a/test/PCBView/pcbrectpad.cpp +++ b/test/PCBView/pcbpad.cpp @@ -19,10 +19,10 @@ /*-- Author : Alexis Jeandet -- Mail : alexis.jeandet@member.fsf.org ----------------------------------------------------------------------------*/ -#include "pcbrectpad.h" +#include "pcbpad.h" #include -PCBRectPad::PCBRectPad(QIlib::QIcadPcbPad *padNode, PCBContext *context) +PCBPad::PCBPad(QIlib::QIcadPcbPad *padNode, PCBContext *context) :QGraphicsItemGroup(),padNode(padNode),context(context) { this->init(QPointF(0.0,0.0)); @@ -30,13 +30,13 @@ PCBRectPad::PCBRectPad(QIlib::QIcadPcbPa -PCBRectPad::PCBRectPad(QIlib::QIcadPcbPad *padNode, QPointF offset, PCBContext *context) +PCBPad::PCBPad(QIlib::QIcadPcbPad *padNode, QPointF offset, PCBContext *context) :QGraphicsItemGroup(),padNode(padNode),context(context) { this->init(offset); } -void PCBRectPad::init( QPointF offset) +void PCBPad::init( QPointF offset) { this->setCacheMode(QGraphicsItem::DeviceCoordinateCache); offset-=QPointF(this->padNode->size().width()/2,this->padNode->size().height()/2); diff --git a/test/PCBView/pcbrectpad.h b/test/PCBView/pcbpad.h rename from test/PCBView/pcbrectpad.h rename to test/PCBView/pcbpad.h --- a/test/PCBView/pcbrectpad.h +++ b/test/PCBView/pcbpad.h @@ -19,8 +19,8 @@ /*-- Author : Alexis Jeandet -- Mail : alexis.jeandet@member.fsf.org ----------------------------------------------------------------------------*/ -#ifndef PCBRECTPAD_H -#define PCBRECTPAD_H +#ifndef PCBPAD_H +#define PCBPAD_H #include #include @@ -29,11 +29,11 @@ #include #include -class PCBRectPad : public QGraphicsItemGroup +class PCBPad : public QGraphicsItemGroup { public: - PCBRectPad(QIlib::QIcadPcbPad* padNode,PCBContext* context); - PCBRectPad(QIlib::QIcadPcbPad* padNode,QPointF offset,PCBContext* context); + PCBPad(QIlib::QIcadPcbPad* padNode,PCBContext* context); + PCBPad(QIlib::QIcadPcbPad* padNode,QPointF offset,PCBContext* context); private: void init(QPointF offset); @@ -45,4 +45,4 @@ private: PCBContext* context; }; -#endif // PCBRECTPAD_H +#endif // PCBPAD_H diff --git a/test/PCBView/pcbvia.cpp b/test/PCBView/pcbvia.cpp --- a/test/PCBView/pcbvia.cpp +++ b/test/PCBView/pcbvia.cpp @@ -37,11 +37,11 @@ PCBVia::PCBVia(QIlib::QIcadPcbVia *viaNo void PCBVia::init(QPointF offset) { + this->setCacheMode(QGraphicsItem::DeviceCoordinateCache); + this->setFlags(ItemIsMovable|ItemIsSelectable|ItemIsFocusable); this->path.addEllipse(this->viaNode->pos(),this->viaNode->size().width()/2,this->viaNode->size().height()/2); double thickness = (this->viaNode->size().width()-this->viaNode->drill())/2; this->path.addEllipse(this->viaNode->pos(),(this->viaNode->size().width()/2)-thickness,(this->viaNode->size().height()/2)-thickness); - this->setCacheMode(QGraphicsItem::DeviceCoordinateCache); - this->setFlags(ItemIsMovable|ItemIsSelectable|ItemIsFocusable); offset-=QPointF(this->viaNode->size().width()/2,this->viaNode->size().height()/2); for(int i=0;iviaNode->layers().count();i++) diff --git a/test/PCBView/pcbzone.cpp b/test/PCBView/pcbzone.cpp new file mode 100644 --- /dev/null +++ b/test/PCBView/pcbzone.cpp @@ -0,0 +1,62 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the Kicad Tools Software +-- Copyright (C) 2015, Plasma Physics Laboratory - CNRS +-- +-- This program 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 2 of the License, or +-- (at your option) any later version. +-- +-- This program 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 this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-------------------------------------------------------------------------------*/ +/*-- Author : Alexis Jeandet +-- Mail : alexis.jeandet@member.fsf.org +----------------------------------------------------------------------------*/ +#include "pcbzone.h" +#include +#include + +PCBZone::PCBZone(QIlib::QIcadPcbZone *zoneNode, PCBContext *context) + :QGraphicsItemGroup(),zoneNode(zoneNode),context(context) +{ + this->init(); +} + +void PCBZone::init() +{ + this->setFlags(ItemIsMovable|ItemIsSelectable|ItemIsFocusable); + QPolygonF poly; + for(int i=0;izoneNode->filledPolygon.points.points.count();i++) + { + poly.append(this->zoneNode->filledPolygon.points.points.at(i)->pos()); + } + QGraphicsPixmapItem* test=new QGraphicsPixmapItem(); + QPixmap pix; + QPainter painter; + QGraphicsPolygonItem* polygonItem = new QGraphicsPolygonItem(); + QPen pen = polygonItem->pen(); + pen.setWidthF(0.01); + + polygonItem->setPen(pen); + QBrush brush = polygonItem->brush(); + brush.setStyle(Qt::SolidPattern); + brush.setColor(context->layerColor(this->zoneNode->layer.value())); + polygonItem->setBrush(brush); + polygonItem->setZValue(-context->layer(this->zoneNode->layer.value())); + polygonItem->setPolygon(poly); + polygonItem->setCacheMode(QGraphicsItem::DeviceCoordinateCache); +// test->setPixmap(polygonItem->); + //voir doc/qt/... +// polygonItem->paint(); + this->addToGroup(polygonItem); + + this->setCacheMode(QGraphicsItem::DeviceCoordinateCache); + setOpacity(0.6); +} diff --git a/test/PCBView/pcbzone.h b/test/PCBView/pcbzone.h new file mode 100644 --- /dev/null +++ b/test/PCBView/pcbzone.h @@ -0,0 +1,43 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the Kicad Tools Software +-- Copyright (C) 2015, Plasma Physics Laboratory - CNRS +-- +-- This program 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 2 of the License, or +-- (at your option) any later version. +-- +-- This program 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 this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-------------------------------------------------------------------------------*/ +/*-- Author : Alexis Jeandet +-- Mail : alexis.jeandet@member.fsf.org +----------------------------------------------------------------------------*/ +#ifndef PCBZONE_H +#define PCBZONE_H +#include +#include +#include +#include +#include +#include +#include + +class PCBZone: public QGraphicsItemGroup +{ +public: + PCBZone(QIlib::QIcadPcbZone* zoneNode,PCBContext* context); +private: + void init(); + QIlib::QIcadPcbZone* zoneNode; + int layer; + PCBContext* context; +}; + +#endif // PCBZONE_H