This commit is contained in:
Christophe Alexandre 2008-01-07 10:07:46 +00:00
parent 9322a046f0
commit 7134556b5e
2 changed files with 142 additions and 18 deletions

View File

@ -2,6 +2,7 @@
#include <QPaintEvent> #include <QPaintEvent>
#include <QPainter> #include <QPainter>
#include <QPen>
#include "DataBase.h" #include "DataBase.h"
#include "Technology.h" #include "Technology.h"
@ -20,35 +21,128 @@ Technology* getTechnology() {
return NULL; return NULL;
} }
}
CellWidget::CellWidget(Cell* c, QWidget* parent) CellWidget::CellWidget(Cell* c, QWidget* parent)
: QAbstractScrollArea(parent), : QAbstractScrollArea(parent),
cell(c) { cell(c),
invalidRegion(),
clipBox(),
painter(NULL),
scale(1),
screenDx(0),
screenDy(0) {
painter = new QPainter();
} }
void CellWidget::paintEvent(QPaintEvent* event) { void CellWidget::paintEvent(QPaintEvent* event) {
//invalidate(event->rect()); invalidate(event->rect());
redraw();
if (!invalidRegion.isEmpty()) {
QRect invalidRect = invalidRegion.boundingRect();
H::Box area = getBox(invalidRect).inflate(getSize(1));
cerr << "akecoucou3" << endl;
//QPaintDevice* device = this;
//QPainter newPainter(device);
//QPainter* oldPainter = painter;
//painter = &newPainter;
painter->setPen(QPen(QColor(255, 255, 255)));
painter->fillRect(QRectF(0, 0, 100, 100), QBrush(QColor(255, 255, 255)));
drawPhantoms(cell, area, Transformation());
drawBoundaries(cell, area, Transformation());
for_each_layer(layer, getTechnology()->GetLayers()) {
drawCell(cell, layer, area, Transformation());
end_for;
}
invalidRegion = QRegion();
}
} }
void CellWidget::invalidate() {
invalidRegion = QRegion(rect());
}
void CellWidget::invalidate(const QRect& screenRect) {
QRect visibleScreenRect = screenRect.intersect(rect());
if (!visibleScreenRect.isEmpty()) {
invalidRegion = invalidRegion.unite(QRegion(visibleScreenRect));
}
}
void CellWidget::redraw() { void CellWidget::redraw() {
drawPhantoms(cell); if (!invalidRegion.isEmpty()) {
drawBoundaries(cell); QRect invalidRect = invalidRegion.boundingRect();
for_each_layer(layer, getTechnology()->GetLayers()) {
drawCell(cell, layer); H::Box area = getBox(invalidRect).inflate(getSize(1));
cerr << "akecoucou2" << endl;
QPaintDevice* device = this;
QPainter newPainter(device);
QPainter* oldPainter = painter;
painter = &newPainter;
//painter->fillRect(QRectF(0, 0, 100, 100), QBrush(QColor(255, 255, 255)));
//painter->setPen(QPen(QColor(255, 255, 255)));
//drawPhantoms(cell, area, Transformation());
//drawBoundaries(cell, area, Transformation());
//for_each_layer(layer, getTechnology()->GetLayers()) {
// drawCell(cell, layer, area, Transformation());
// end_for;
//}
invalidRegion = QRegion();
}
}
void CellWidget::drawCell(const Cell* cell, const Layer* layer, const H::Box& updateArea, const Transformation& transformation) const {
}
void CellWidget::drawPhantoms(const Cell* cell, const H::Box& updateArea, const Transformation& transformation) const {
for_each_instance(instance, cell->GetInstancesUnder(updateArea)) {
drawPhantoms(instance, updateArea, transformation);
end_for; end_for;
} }
} }
void CellWidget::drawCell(const Cell* cell, const Layer* layer) const { void CellWidget::drawPhantoms(const Instance* instance, const H::Box& updateArea, const Transformation& transformation) const {
H::Box masterArea = updateArea;
Transformation masterTransformation = instance->GetTransformation();
instance->GetTransformation().GetInvert().ApplyOn(masterArea);
transformation.ApplyOn(masterTransformation);
drawPhantoms(instance->GetMasterCell(), masterArea, masterTransformation);
} }
void CellWidget::drawPhantoms(const Cell* cell) const { void CellWidget::drawBoundaries(const Cell* cell, const H::Box& updateArea, const Transformation& transformation) const {
drawRectangle(cell->GetAbutmentBox());
for_each_instance(instance, cell->GetInstances()) {
drawBoundaries(instance, updateArea, transformation);
end_for;
}
} }
void CellWidget::drawBoundaries(const Cell* cell) const { void CellWidget::drawBoundaries(const Instance* instance, const H::Box& updateArea, const Transformation& transformation) const {
H::Box masterArea = updateArea;
Transformation masterTransformation = instance->GetTransformation();
instance->GetTransformation().GetInvert().ApplyOn(masterArea);
transformation.ApplyOn(masterTransformation);
drawBoundaries(instance->GetMasterCell(), masterArea, masterTransformation);
} }
void CellWidget::drawRectangle(const H::Box& box) { void CellWidget::drawRectangle(const H::Box& box) const {
if (painter) { if (painter) {
H::Box ibox = box.getIntersection(clipBox); H::Box ibox = box.getIntersection(clipBox);
if (!ibox.isEmpty()) { if (!ibox.isEmpty()) {
@ -62,6 +156,29 @@ void CellWidget::drawRectangle(const H::Box& box) {
} }
} }
Unit CellWidget::getX(int screenX) const {
return GetUnit((screenX - screenDx) / scale);
}
Unit CellWidget::getY(int screenY) const {
return GetUnit(((height() - screenY) - screenDy) / scale);
}
Unit CellWidget::getSize(int screenSize) const {
return GetUnit(screenSize / scale);
}
H::Box CellWidget::getBox(const QRect& screenRect) const {
if (screenRect.isEmpty()) {
return H::Box();
}
return H::Box(getX(screenRect.left()),
getY(screenRect.bottom()),
getX(screenRect.right()),
getY(screenRect.top()));
}
int CellWidget::getScreenX(const Unit& x) const { int CellWidget::getScreenX(const Unit& x) const {
return screenDx + (int)rint(GetValue(x) * scale); return screenDx + (int)rint(GetValue(x) * scale);
} }
@ -69,5 +186,3 @@ int CellWidget::getScreenX(const Unit& x) const {
int CellWidget::getScreenY(const Unit& y) const { int CellWidget::getScreenY(const Unit& y) const {
return height() - (int)rint(screenDy + (GetValue(y) * scale)); return height() - (int)rint(screenDy + (GetValue(y) * scale));
} }
}

View File

@ -16,18 +16,27 @@ class CellWidget : public QAbstractScrollArea {
void paintEvent(QPaintEvent* event); void paintEvent(QPaintEvent* event);
private: private:
Cell* cell; Cell* cell;
QPainter* painter; QRegion invalidRegion;
H::Box clipBox; H::Box clipBox;
QPainter* painter;
double scale; double scale;
int screenDx; int screenDx;
int screenDy; int screenDy;
void drawCell(const Cell* cell, const Layer* layer) const; void drawCell(const Cell* cell, const Layer* layer, const H::Box& updateArea, const Transformation& transformation) const;
void drawPhantoms(const Cell* cell) const; void drawPhantoms(const Cell* cell, const H::Box& updateArea, const Transformation& transformation) const;
void drawBoundaries(const Cell* cell) const; void drawPhantoms(const Instance* instance, const H::Box& updateArea, const Transformation& transformation) const;
void drawRectangle(const H::Box& box); void drawBoundaries(const Cell* cell, const H::Box& updateArea, const Transformation& transformation) const;
void drawBoundaries(const Instance* instance, const H::Box& updateArea, const Transformation& transformation) const;
void drawRectangle(const H::Box& box) const;
Unit getX(int screenX) const;
Unit getY(int screenY) const;
Unit getSize(int screenSize) const;
H::Box getBox(const QRect& screenRect) const;
int getScreenX(const Unit& x) const; int getScreenX(const Unit& x) const;
int getScreenY(const Unit& y) const; int getScreenY(const Unit& y) const;
void invalidate();
void invalidate(const QRect& screenRect);
}; };