display improvment

This commit is contained in:
Christophe Alexandre 2008-01-10 00:57:26 +00:00
parent d60da7f7ac
commit 7cc672bb96
2 changed files with 217 additions and 61 deletions

View File

@ -160,6 +160,7 @@ void CellWidget::redraw() {
painter->restore(); painter->restore();
for_each_basic_layer(basiclayer, getTechnology()->GetBasicLayers()) { for_each_basic_layer(basiclayer, getTechnology()->GetBasicLayers()) {
if (isDrawable(basiclayer)) {
painter->save(); painter->save();
map<BasicLayer*, QBrush>::const_iterator bmit = basicLayersBrush.find(basiclayer); map<BasicLayer*, QBrush>::const_iterator bmit = basicLayersBrush.find(basiclayer);
if (bmit != basicLayersBrush.end()) { if (bmit != basicLayersBrush.end()) {
@ -173,6 +174,7 @@ void CellWidget::redraw() {
painter->restore(); painter->restore();
end_for; end_for;
} }
}
invalidRegion = QRegion(); invalidRegion = QRegion();
} }
@ -221,11 +223,17 @@ void CellWidget::drawGo(const Go* go, const BasicLayer* basicLayer, const Box& u
const Contact* contact = dynamic_cast<const Contact*>(go); const Contact* contact = dynamic_cast<const Contact*>(go);
if (contact) { if (contact) {
drawContact(contact, basicLayer, updateArea, transformation); drawContact(contact, basicLayer, updateArea, transformation);
return;
} }
} }
void CellWidget::drawSegment(const Segment* segment, const BasicLayer* basicLayer, const Box& updateArea, const Transformation& transformation) const { void CellWidget::drawSegment(const Segment* segment, const BasicLayer* basicLayer, const Box& updateArea, const Transformation& transformation) const {
if (1 < getScreenSize(segment->GetWidth())) {
drawRectangle(transformation.getBox(segment->GetBoundingBox(basicLayer))); drawRectangle(transformation.getBox(segment->GetBoundingBox(basicLayer)));
} else {
drawLine(transformation.getPoint(segment->GetSourcePosition()),
transformation.getPoint(segment->GetTargetPosition()));
}
} }
void CellWidget::drawContact(const Contact* contact, const BasicLayer* basicLayer, const Box& updateArea, const Transformation& transformation) const { void CellWidget::drawContact(const Contact* contact, const BasicLayer* basicLayer, const Box& updateArea, const Transformation& transformation) const {
@ -277,6 +285,38 @@ void CellWidget::drawRectangle(const H::Box& box) const {
} }
} }
void CellWidget::drawLine(const Point& po, const Point& pe) const {
drawLine(po.getX(), po.getY(), pe.getX(), pe.getY());
}
void CellWidget::drawLine(const Unit& xo,
const Unit& yo,
const Unit& xe,
const Unit& ye) const {
if (painter) {
double dxo = GetValue(xo);
double dyo = GetValue(yo);
int co = getClipCode(dxo, dyo);
double dxe = GetValue(xe);
double dye = GetValue(ye);
int ce = getClipCode(dxe, dye);
if (clipLine(dxo, dyo, co, dxe, dye, ce)) {
int ixo = getScreenX(GetUnit(dxo));
int iyo = getScreenY(GetUnit(dyo));
int ixe = getScreenX(GetUnit(dxe));
int iye = getScreenY(GetUnit(dye));
painter->save();
if (painter->pen() == Qt::NoPen) {
painter->setPen(painter->brush().color());
}
//painter->moveTo(ixo, iyo);
//painter->lineTo(ixe, iye);
painter->drawLine(ixo, iyo, ixe, iye);
painter->restore();
}
}
}
Unit CellWidget::getX(int screenX) const { Unit CellWidget::getX(int screenX) const {
return GetUnit((screenX - screenDx) / scale); return GetUnit((screenX - screenDx) / scale);
} }
@ -308,6 +348,11 @@ int CellWidget::getScreenY(const Unit& y) const {
return height() - (int)rint(screenDy + (GetValue(y) * scale)); return height() - (int)rint(screenDy + (GetValue(y) * scale));
} }
int CellWidget::getScreenSize(const Unit& size) const {
return (int)rint(GetValue(size) * scale);
}
void CellWidget::setClipBox(const Box& area) { void CellWidget::setClipBox(const Box& area) {
clipBox = Box(area).inflate(getSize(2)); clipBox = Box(area).inflate(getSize(2));
@ -323,6 +368,112 @@ void CellWidget::setClipBox(const Box& area) {
} }
int CellWidget::getClipCode(double x, double y) const {
if (x < clipX[0]) {
if (y < clipY[0]) {
return 28;
}
if (clipY[3] < y) {
return 22;
}
return 4;
}
if (clipX[3] < x) {
if (y < clipY[0]) {
return 25;
}
if (clipY[3] < y) {
return 19;
}
return 1;
}
if (y < clipY[0]) {
return 8;
}
if (clipY[3] < y) {
return 2;
}
return 0;
}
bool CellWidget::clipLine(double& xo,
double& yo,
int co,
double& xe,
double& ye,
int ce,
int u) const {
if (co & ce & -17) {
return false;
}
if (!co & !ce) {
return true;
}
if (co & 1) {
yo += ((ye - yo) / (xe - xo)) * (clipX[3] - xo);
xo = clipX[3];
co = getClipCode(xo, yo);
return clipLine(xo, yo, co, xe, ye, ce, u + 1);
}
if (co & 2) {
xo += ((xe - xo) / (ye - yo)) * (clipY[3] - yo);
yo = clipY[3];
co = getClipCode(xo, yo);
return clipLine(xo, yo, co, xe, ye, ce, u + 1);
}
if (co & 4) {
yo += ((ye - yo) / (xe - xo)) * (clipX[0] - xo);
xo = clipX[0];
co = getClipCode(xo, yo);
return clipLine(xo, yo, co, xe, ye, ce, u + 1);
}
if (co & 8) {
xo += ((xe - xo) / (ye - yo)) * (clipY[0] - yo);
yo = clipY[0];
co = getClipCode(xo, yo);
return clipLine(xo, yo, co, xe, ye, ce, u + 1);
}
if (ce & 1) {
ye -= ((ye - yo) / (xe - xo)) * (xe - clipX[3]);
xe = clipX[3];
ce = getClipCode(xe, ye);
return clipLine(xo, yo, co, xe, ye, ce, u + 1);
}
if (ce & 2) {
xe -= ((xe - xo) / (ye - yo)) * (ye - clipY[3]);
ye = clipY[3];
ce = getClipCode(xe, ye);
return clipLine(xo, yo, co, xe, ye, ce, u + 1);
}
if (ce & 4) {
ye -= ((ye - yo) / (xe - xo)) * (xe - clipX[0]);
xe = clipX[0];
ce = getClipCode(xe, ye);
return clipLine(xo, yo, co, xe, ye, ce, u + 1);
}
if (ce & 8) {
xe -= ((xe - xo) / (ye - yo)) * (ye - clipY[0]);
ye = clipY[0];
ce = getClipCode(xe, ye);
return clipLine(xo, yo, co, xe, ye, ce, u + 1);
}
return true;
}
void CellWidget::setFont(const QFont& font) { void CellWidget::setFont(const QFont& font) {
if (painter) { if (painter) {
painter->setFont(font); painter->setFont(font);
@ -337,8 +488,7 @@ void CellWidget::setPen(const QPen& pen, double brightness) {
if (painter) { if (painter) {
if (pen == Qt::NoPen) { if (pen == Qt::NoPen) {
painter->setPen(pen); painter->setPen(pen);
} } else {
else {
QPen correctedPen = pen; QPen correctedPen = pen;
if (brightness < 1) { if (brightness < 1) {
@ -354,7 +504,6 @@ void CellWidget::setPen(const QPen& pen, double brightness) {
correctedPen = QPen(QColor(r, g, b)); correctedPen = QPen(QColor(r, g, b));
} }
painter->setPen(correctedPen); painter->setPen(correctedPen);
} }
} }
@ -368,8 +517,7 @@ void CellWidget::setBrush(const QBrush& brush, double brightness) {
if (painter) { if (painter) {
if (brush == Qt::NoBrush) { if (brush == Qt::NoBrush) {
painter->setBrush(brush); painter->setBrush(brush);
} } else {
else {
QBrush correctedBrush = brush; QBrush correctedBrush = brush;
if (brightness < 1) { if (brightness < 1) {
@ -385,7 +533,6 @@ void CellWidget::setBrush(const QBrush& brush, double brightness) {
correctedBrush = QBrush(QColor(r, g, b), brush.style()); correctedBrush = QBrush(QColor(r, g, b), brush.style());
} }
painter->setBrush(correctedBrush); painter->setBrush(correctedBrush);
} }
} }
@ -397,3 +544,7 @@ void CellWidget::setBrushOrigin(const QPoint& origin) {
} }
} }
bool CellWidget::isDrawable(BasicLayer* layer) const {
return (layer->GetDisplayThreshold() <= scale);
}

View File

@ -42,21 +42,26 @@ class CellWidget : public QWidget {
void drawSegment(const Segment* segment, const BasicLayer* basicLayer, const Box& updateArea, const Transformation& transformation) const; void drawSegment(const Segment* segment, const BasicLayer* basicLayer, const Box& updateArea, const Transformation& transformation) const;
void drawContact(const Contact* contact, const BasicLayer* basicLayer, const Box& updateArea, const Transformation& transformation) const; void drawContact(const Contact* contact, const BasicLayer* basicLayer, const Box& updateArea, const Transformation& transformation) const;
void drawRectangle(const Box& box) const; void drawRectangle(const Box& box) const;
void drawLine(const Point& po, const Point& pe) const;
void drawLine(const Unit& xo, const Unit& yo, const Unit& xe, const Unit& ye) const;
Unit getX(int screenX) const; Unit getX(int screenX) const;
Unit getY(int screenY) const; Unit getY(int screenY) const;
Unit getSize(int screenSize) const; Unit getSize(int screenSize) const;
H::Box getBox(const QRect& screenRect) 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;
int getScreenSize(const Unit& size) const;
void invalidate(); void invalidate();
void invalidate(const QRect& screenRect); void invalidate(const QRect& screenRect);
void setClipBox(const Box& area); void setClipBox(const Box& area);
int getClipCode(double x, double y) const;
bool clipLine(double& xo, double& yo, int co, double& xe, double& ye, int ce, int u=0) const;
void setFont(const QFont& font); void setFont(const QFont& font);
void setPen(const QPen& pen, double brightness = 1.0); void setPen(const QPen& pen, double brightness = 1.0);
void setBrush(const QBrush& brush, double brightness = 1.0); void setBrush(const QBrush& brush, double brightness = 1.0);
void setBrushOrigin(const QPoint& origin); void setBrushOrigin(const QPoint& origin);
const QColor& getBackgroundColor() const; const QColor& getBackgroundColor() const;
bool isDrawable(BasicLayer* layer) const;
}; };