##// END OF EJS Templates
Non working pad rendering.. Rotation issue.
jeandet -
r12:93ef9e74723d default
parent child
Show More
@@ -886,7 +886,7 void QIlib::QIcadPcbPad::setNode(QIlib::
886 {
886 {
887 this->p_shape = circle;
887 this->p_shape = circle;
888 }
888 }
889
889 this->p_padNumber = nodeValueToInt(node,0);
890 }
890 }
891 for(int i=0;i<node->nodes.count();i++)
891 for(int i=0;i<node->nodes.count();i++)
892 {
892 {
@@ -894,6 +894,7 void QIlib::QIcadPcbPad::setNode(QIlib::
894 {
894 {
895 this->at.setNode(node->nodes.at(i));
895 this->at.setNode(node->nodes.at(i));
896 this->p_pos = nodeTo2DCoords(node->nodes.at(i));
896 this->p_pos = nodeTo2DCoords(node->nodes.at(i));
897 this->p_angle = nodeValueToDouble(node->nodes.at(i),2);
897 }
898 }
898 if(node->nodes.at(i)->name==QIlib::Lexique::size_c)
899 if(node->nodes.at(i)->name==QIlib::Lexique::size_c)
899 {
900 {
@@ -238,11 +238,15 public:
238 const QSizeF& size(){return p_size;}
238 const QSizeF& size(){return p_size;}
239 const QPointF& pos(){return p_pos;}
239 const QPointF& pos(){return p_pos;}
240 double drill(){return p_drill;}
240 double drill(){return p_drill;}
241 double angle(){return p_angle;}
241 padShape shape(){return p_shape;}
242 padShape shape(){return p_shape;}
243 int padNumber(){return p_padNumber;}
242 void setNode(QIlib::AbstractNode* node);
244 void setNode(QIlib::AbstractNode* node);
243 private:
245 private:
246 int p_padNumber;
244 padShape p_shape;
247 padShape p_shape;
245 double p_drill;
248 double p_drill;
249 double p_angle;
246 QSizeF p_size;
250 QSizeF p_size;
247 QPointF p_pos;
251 QPointF p_pos;
248 QStringList p_layers;
252 QStringList p_layers;
@@ -24,6 +24,7
24 #include "pcbmodule.h"
24 #include "pcbmodule.h"
25 #include "pcbline.h"
25 #include "pcbline.h"
26 #include "pcbvia.h"
26 #include "pcbvia.h"
27 #include <QFileDialog>
27
28
28
29
29 MainWindow::MainWindow(QWidget *parent) :
30 MainWindow::MainWindow(QWidget *parent) :
@@ -32,36 +33,11 MainWindow::MainWindow(QWidget *parent)
32 {
33 {
33 ui->setupUi(this);
34 ui->setupUi(this);
34 this->p_scene = new QGraphicsScene();
35 this->p_scene = new QGraphicsScene();
35 this->p_scene->setSceneRect(0, 0, 500, 200);
36
37 this->context = new PCBContext();
36 this->context = new PCBContext();
38 this->ui->graphicsView->setScene(this->p_scene);
37 this->ui->graphicsView->setScene(this->p_scene);
39 QIlib::QIcadPcb pcbDriver;
38 this->pcbDriver =NULL;
40 // pcbDriver.parsePcb("/opt/kicadTools/test/testFiles/pcb2.kicad_pcb");
41 // pcbDriver.parsePcb("/home/jeandet/Documents/PCB/ADC_STAMP/ADC_STAMP.kicad_pcb");
42 pcbDriver.parsePcb("/usr/share/kicad/demos/video/video.kicad_pcb");
43 // pcbDriver.parsePcb("/usr/share/kicad/demos/kit-dev-coldfire-xilinx_5213/kit-dev-coldfire-xilinx_5213.kicad_pcb");
44 for(int i=0;i<pcbDriver.pcbRoot->layers.layers.count();i++)
45 {
46 this->context->addlayer(pcbDriver.pcbRoot->layers.layers.at(i)->name(),pcbDriver.pcbRoot->layers.layers.at(i)->index());
47 }
48 for(int i=0;i<pcbDriver.pcbRoot->modules.count();i++)
49 {
50 this->p_scene->addItem(new PCBModule(pcbDriver.pcbRoot->modules.at(i),this->context));
51 }
52 for(int i=0;i<pcbDriver.pcbRoot->lines.count();i++)
53 {
54 this->p_scene->addItem(new PCBLine((QIlib::QIcadAbstractPcbLine*)pcbDriver.pcbRoot->lines.at(i),this->context));
55 }
56 for(int i=0;i<pcbDriver.pcbRoot->segments.count();i++)
57 {
58 this->p_scene->addItem(new PCBLine((QIlib::QIcadAbstractPcbLine*)pcbDriver.pcbRoot->segments.at(i),this->context));
59 }
60 for(int i=0;i<pcbDriver.pcbRoot->vias.count();i++)
61 {
62 this->p_scene->addItem(new PCBVia(pcbDriver.pcbRoot->vias.at(i),this->context));
63 }
64 connect(this->ui->actionRedraw,SIGNAL(triggered(bool)),this,SLOT(redraw()));
39 connect(this->ui->actionRedraw,SIGNAL(triggered(bool)),this,SLOT(redraw()));
40 connect(this->ui->actionOpen,SIGNAL(triggered(bool)),this,SLOT(openFile()));
65 }
41 }
66
42
67 MainWindow::~MainWindow()
43 MainWindow::~MainWindow()
@@ -74,6 +50,15 void MainWindow::redraw()
74 this->p_scene->update();
50 this->p_scene->update();
75 }
51 }
76
52
53 void MainWindow::openFile()
54 {
55 QString file = QFileDialog::getOpenFileName(this,tr("Open kicad PCB file"),
56 "",
57 tr("PCB file (*.kicad_pcb)"));
58 if(QFile::exists(file))
59 loadFile(file);
60 }
61
77 void MainWindow::changeEvent(QEvent *e)
62 void MainWindow::changeEvent(QEvent *e)
78 {
63 {
79 QMainWindow::changeEvent(e);
64 QMainWindow::changeEvent(e);
@@ -85,3 +70,36 void MainWindow::changeEvent(QEvent *e)
85 break;
70 break;
86 }
71 }
87 }
72 }
73
74 void MainWindow::loadFile(const QString &file)
75 {
76 this->p_scene->setSceneRect(0, 0, 500, 200);
77 if(pcbDriver!=NULL)delete pcbDriver;
78 pcbDriver = new QIlib::QIcadPcb();
79 this->context->clear();
80 this->p_scene->clear();
81 // pcbDriver.parsePcb("/opt/kicadTools/test/testFiles/pcb2.kicad_pcb");
82 // pcbDriver.parsePcb("/home/jeandet/Documents/PCB/ADC_STAMP/ADC_STAMP.kicad_pcb");
83 pcbDriver->parsePcb(file);
84 // pcbDriver.parsePcb("/usr/share/kicad/demos/kit-dev-coldfire-xilinx_5213/kit-dev-coldfire-xilinx_5213.kicad_pcb");
85 for(int i=0;i<pcbDriver->pcbRoot->layers.layers.count();i++)
86 {
87 this->context->addlayer(pcbDriver->pcbRoot->layers.layers.at(i)->name(),pcbDriver->pcbRoot->layers.layers.at(i)->index());
88 }
89 for(int i=0;i<pcbDriver->pcbRoot->modules.count();i++)
90 {
91 this->p_scene->addItem(new PCBModule(pcbDriver->pcbRoot->modules.at(i),this->context));
92 }
93 for(int i=0;i<pcbDriver->pcbRoot->lines.count();i++)
94 {
95 this->p_scene->addItem(new PCBLine((QIlib::QIcadAbstractPcbLine*)pcbDriver->pcbRoot->lines.at(i),this->context));
96 }
97 for(int i=0;i<pcbDriver->pcbRoot->segments.count();i++)
98 {
99 this->p_scene->addItem(new PCBLine((QIlib::QIcadAbstractPcbLine*)pcbDriver->pcbRoot->segments.at(i),this->context));
100 }
101 for(int i=0;i<pcbDriver->pcbRoot->vias.count();i++)
102 {
103 this->p_scene->addItem(new PCBVia(pcbDriver->pcbRoot->vias.at(i),this->context));
104 }
105 }
@@ -45,13 +45,16 public:
45
45
46 public slots:
46 public slots:
47 void redraw();
47 void redraw();
48 void openFile();
48 protected:
49 protected:
49 void changeEvent(QEvent *e);
50 void changeEvent(QEvent *e);
50
51
51 private:
52 private:
53 void loadFile(const QString& file);
52 Ui::MainWindow *ui;
54 Ui::MainWindow *ui;
53 QGraphicsScene* p_scene;
55 QGraphicsScene* p_scene;
54 PCBContext* context;
56 PCBContext* context;
57 QIlib::QIcadPcb* pcbDriver;
55 };
58 };
56
59
57 #endif // MAINWINDOW_H
60 #endif // MAINWINDOW_H
@@ -71,3 +71,9 const QString PCBContext::layer(int numb
71 return layers_map.key(number);
71 return layers_map.key(number);
72 }
72 }
73
73
74 void PCBContext::clear()
75 {
76 this->layers_colors.clear();
77 this->layers_map.clear();
78 }
79
@@ -36,6 +36,7 public:
36 const QColor& layerColor(const QString& name);
36 const QColor& layerColor(const QString& name);
37 const QColor& layerColor(int number);
37 const QColor& layerColor(int number);
38 const QString layer(int number);
38 const QString layer(int number);
39 void clear();
39 signals:
40 signals:
40
41
41 public slots:
42 public slots:
@@ -42,9 +42,11 void PCBRectPad::init( QPointF offset)
42 offset-=QPointF(this->padNode->size().width()/2,this->padNode->size().height()/2);
42 offset-=QPointF(this->padNode->size().width()/2,this->padNode->size().height()/2);
43 if(this->padNode->shape()==QIlib::QIcadPcbPad::rectangle)
43 if(this->padNode->shape()==QIlib::QIcadPcbPad::rectangle)
44 {
44 {
45 QRectF rec(this->padNode->pos()+offset,this->padNode->size());
45 for(int i=0;i<this->padNode->layers().count();i++)
46 for(int i=0;i<this->padNode->layers().count();i++)
46 {
47 {
47 QGraphicsRectItem* rect = new QGraphicsRectItem();
48 QGraphicsRectItem* rect = new QGraphicsRectItem();
49 rect->setTransformOriginPoint(rec.center());
48 QPen pen = rect->pen();
50 QPen pen = rect->pen();
49 pen.setWidthF(0.01);
51 pen.setWidthF(0.01);
50 rect->setPen(pen);
52 rect->setPen(pen);
@@ -52,11 +54,17 void PCBRectPad::init( QPointF offset)
52 brush.setStyle(Qt::SolidPattern);
54 brush.setStyle(Qt::SolidPattern);
53 brush.setColor(context->layerColor(this->padNode->layers().at(i)));
55 brush.setColor(context->layerColor(this->padNode->layers().at(i)));
54 rect->setBrush(brush);
56 rect->setBrush(brush);
55 QRectF rec(this->padNode->pos()+offset,this->padNode->size());
56 rect->setRect(rec);
57 rect->setRect(rec);
57 rect->setZValue(-context->layer(padNode->layers().at(i)));
58 rect->setZValue(-context->layer(padNode->layers().at(i)));
59 rect->setRotation(padNode->angle());
58 this->addToGroup(rect);
60 this->addToGroup(rect);
59 }
61 }
62 QGraphicsTextItem* text=new QGraphicsTextItem(QString::number(padNode->padNumber()));
63 text->setPos(rec.center());
64 text->setScale(0.01);
65 text->setZValue(1);
66 this->addToGroup(text);
67
60 }
68 }
61 if(this->padNode->shape()==QIlib::QIcadPcbPad::circle)
69 if(this->padNode->shape()==QIlib::QIcadPcbPad::circle)
62 {
70 {
@@ -37,26 +37,29 PCBVia::PCBVia(QIlib::QIcadPcbVia *viaNo
37
37
38 void PCBVia::init(QPointF offset)
38 void PCBVia::init(QPointF offset)
39 {
39 {
40 this->path.addEllipse(this->viaNode->pos(),this->viaNode->size().width()/2,this->viaNode->size().height()/2);
41 double thickness = (this->viaNode->size().width()-this->viaNode->drill())/2;
42 this->path.addEllipse(this->viaNode->pos(),(this->viaNode->size().width()/2)-thickness,(this->viaNode->size().height()/2)-thickness);
40 this->setCacheMode(QGraphicsItem::DeviceCoordinateCache);
43 this->setCacheMode(QGraphicsItem::DeviceCoordinateCache);
41 this->setFlags(ItemIsMovable|ItemIsSelectable|ItemIsFocusable);
44 this->setFlags(ItemIsMovable|ItemIsSelectable|ItemIsFocusable);
42 offset-=QPointF(this->viaNode->size().width()/2,this->viaNode->size().height()/2);
45 offset-=QPointF(this->viaNode->size().width()/2,this->viaNode->size().height()/2);
43
46
44 for(int i=0;i<this->viaNode->layers().count();i++)
47 for(int i=0;i<this->viaNode->layers().count();i++)
45 {
48 {
46 QGraphicsEllipseItem* ellipse = new QGraphicsEllipseItem();
49 QGraphicsPathItem* pathitem = new QGraphicsPathItem();
47 QPen pen = ellipse->pen();
50 QPen pen = pathitem->pen();
48 double thickness = (this->viaNode->size().width()-this->viaNode->drill())/2;
51 pen.setWidthF(0.01);
49 pen.setWidthF(thickness);
50
52
51 ellipse->setPen(pen);
53 pathitem->setPen(pen);
52 // QBrush brush = ellipse->brush();
54 QBrush brush = pathitem->brush();
53 // brush.setStyle(Qt::SolidPattern);
55 brush.setStyle(Qt::SolidPattern);
54 // brush.setColor(context->layerColor(this->viaNode->layers().at(i)));
56 brush.setColor(context->layerColor(this->viaNode->layers().at(i)));
55 // ellipse->setBrush(brush);
57 pathitem->setBrush(brush);
56 QRectF rec(this->viaNode->pos()+offset,QSizeF(this->viaNode->size().width()-thickness,this->viaNode->size().width()-thickness));
58 // QRectF rec(this->viaNode->pos()+offset,QSizeF(this->viaNode->size().width()-thickness,this->viaNode->size().width()-thickness));
57 ellipse->setRect(rec);
59 // pathitem->setRect(rec);
58 ellipse->setZValue(-context->layer(viaNode->layers().at(i)));
60 pathitem->setZValue(-context->layer(viaNode->layers().at(i)));
59 this->addToGroup(ellipse);
61 pathitem->setPath(path);
62 this->addToGroup(pathitem);
60 }
63 }
61
64
62 setOpacity(0.6);
65 setOpacity(0.6);
@@ -27,6 +27,7
27 #include <QGraphicsItemGroup>
27 #include <QGraphicsItemGroup>
28 #include <pcbcontext.h>
28 #include <pcbcontext.h>
29 #include <qicadpcb.h>
29 #include <qicadpcb.h>
30 #include <QPainterPath>
30
31
31 class PCBVia: public QGraphicsItemGroup
32 class PCBVia: public QGraphicsItemGroup
32 {
33 {
@@ -41,6 +42,7 private:
41 QRectF size;
42 QRectF size;
42 QList<int> layers;
43 QList<int> layers;
43 PCBContext* context;
44 PCBContext* context;
45 QPainterPath path;
44 };
46 };
45
47
46 #endif // PCBVIA_H
48 #endif // PCBVIA_H
General Comments 0
You need to be logged in to leave comments. Login now