From a0e381b6322d7efba70394fd9f7fbecccb18aa64 Mon Sep 17 00:00:00 2001 From: Christophe Alexandre Date: Tue, 22 Jan 2008 18:26:07 +0000 Subject: [PATCH] viewer improvment --- hurricane/src/hurricane/Box.cpp | 4 + hurricane/src/hurricane/Box.h | 1 + hurricane/src/hurricane/Point.cpp | 4 + hurricane/src/hurricane/Point.h | 1 + hurricane/src/viewer/CellViewer.cpp | 20 +- hurricane/src/viewer/CellViewer.h | 2 + hurricane/src/viewer/CellWidget.cpp | 2841 ++++++++++++++++++++++++--- hurricane/src/viewer/CellWidget.h | 1691 +++++++++++++++- 8 files changed, 4169 insertions(+), 395 deletions(-) diff --git a/hurricane/src/hurricane/Box.cpp b/hurricane/src/hurricane/Box.cpp index 7b759ebc..34de8ed4 100644 --- a/hurricane/src/hurricane/Box.cpp +++ b/hurricane/src/hurricane/Box.cpp @@ -247,6 +247,10 @@ Box& Box::inflate(const Unit& dxMin, const Unit& dyMin, const Unit& dxMax, const return *this; } +Box Box::getInflated(const Unit& d) const { + return Box(*this).inflate(d); +} + Box& Box::shrinkByFactor(double factor) // ************************************** { diff --git a/hurricane/src/hurricane/Box.h b/hurricane/src/hurricane/Box.h index abc7d272..fbdea3ca 100644 --- a/hurricane/src/hurricane/Box.h +++ b/hurricane/src/hurricane/Box.h @@ -96,6 +96,7 @@ class Box { public: Box& inflate(const Unit& d); public: Box& inflate(const Unit& dx, const Unit& dy); public: Box& inflate(const Unit& dxMin, const Unit& dyMin, const Unit& dxMax, const Unit& dyMax); + public: Box getInflated(const Unit& d) const; public: Box& shrinkByFactor(double factor); // 0 <= factor <= 1 public: Box& merge(const Unit& x, const Unit& y); diff --git a/hurricane/src/hurricane/Point.cpp b/hurricane/src/hurricane/Point.cpp index d5aec09c..9b21c3d4 100644 --- a/hurricane/src/hurricane/Point.cpp +++ b/hurricane/src/hurricane/Point.cpp @@ -92,6 +92,10 @@ Point& Point::translate(const Unit& dx, const Unit& dy) return *this; } +Point Point::getTranslated(const Unit& dx, const Unit& dy) const { + return Point(*this).translate(dx, dy); +} + string Point::_GetString() const // ***************************** { diff --git a/hurricane/src/hurricane/Point.h b/hurricane/src/hurricane/Point.h index 83619324..028acabe 100644 --- a/hurricane/src/hurricane/Point.h +++ b/hurricane/src/hurricane/Point.h @@ -63,6 +63,7 @@ class Point { public: void setX(const Unit& x) {_x = x;}; public: void setY(const Unit& y) {_y = y;}; public: Point& translate(const Unit& dx, const Unit& dy); + public: Point getTranslated(const Unit& dx, const Unit& dy) const; // Others // ****** diff --git a/hurricane/src/viewer/CellViewer.cpp b/hurricane/src/viewer/CellViewer.cpp index 09b8183e..3061436f 100644 --- a/hurricane/src/viewer/CellViewer.cpp +++ b/hurricane/src/viewer/CellViewer.cpp @@ -15,7 +15,7 @@ CellViewer::CellViewer(Cell* cell) createMenus(); setWindowTitle(tr("Cell Viewer")); - resize(500, 400); + resize(1000, 500); } CellViewer::~CellViewer() { @@ -56,13 +56,17 @@ CellViewer::~CellViewer() { void CellViewer::zoomIn() { cellWidget->reframe(cellWidget->getScale() * 1.2); - cellWidget->redraw(); + cellWidget->update(); } void CellViewer::zoomOut() { + cellWidget->reframe(cellWidget->getScale() / 1.2); + cellWidget->update(); } void CellViewer::fitToWindow() { + cellWidget->fitToContent(); + cellWidget->update(); } void CellViewer::createActions() { @@ -70,11 +74,23 @@ void CellViewer::createActions() { zoomInAct->setShortcut(tr("Ctrl++")); zoomInAct->setEnabled(true); connect(zoomInAct, SIGNAL(triggered()), this, SLOT(zoomIn())); + + zoomOutAct = new QAction(tr("Zoom &Out (25%)"), this); + zoomOutAct->setShortcut(tr("Ctrl+-")); + zoomOutAct->setEnabled(true); + connect(zoomOutAct, SIGNAL(triggered()), this, SLOT(zoomOut())); + + fitToWindowAct = new QAction(tr("Fit &To &Window"), this); + fitToWindowAct->setShortcut(tr("f")); + fitToWindowAct->setEnabled(true); + connect(fitToWindowAct, SIGNAL(triggered()), this, SLOT(fitToWindow())); } void CellViewer::createMenus() { viewMenu = new QMenu(tr("&View"), this); viewMenu->addAction(zoomInAct); + viewMenu->addAction(zoomOutAct); + viewMenu->addAction(fitToWindowAct); menuBar()->addMenu(viewMenu); } diff --git a/hurricane/src/viewer/CellViewer.h b/hurricane/src/viewer/CellViewer.h index 4ee9614d..e74a88ba 100644 --- a/hurricane/src/viewer/CellViewer.h +++ b/hurricane/src/viewer/CellViewer.h @@ -20,6 +20,8 @@ class CellViewer : public QMainWindow { LayersWidget* layersWidget; QAction *zoomInAct; + QAction *zoomOutAct; + QAction *fitToWindowAct; QMenu *viewMenu; void createActions(); diff --git a/hurricane/src/viewer/CellWidget.cpp b/hurricane/src/viewer/CellWidget.cpp index 4cd1102e..6b59a1d8 100644 --- a/hurricane/src/viewer/CellWidget.cpp +++ b/hurricane/src/viewer/CellWidget.cpp @@ -1,18 +1,32 @@ -#include +// ************************************************************************************************* +// ************************************************************************************************* +// File: CellWidget.cpp +// ************************************************************************************************* +// ************************************************************************************************* + +#include "CellWidget.h" + +#include "Cell.h" +#include "Boxes.h" +//#include "Command.h" +#include "DataBase.h" +#include "Exception.h" +#include "Layer.h" +#include "Record.h" +//#include "Selector.h" +#include "Slice.h" +#include "Slot.h" +#include "Technology.h" +#include "Transformation.h" +using namespace H; #include #include -#include -#include "DataBase.h" -#include "Technology.h" -#include "BasicLayer.h" -#include "Slice.h" -#include "Box.h" -#include "Segment.h" -using namespace H; +#include +#include -#include "CellWidget.h" +//OPEN_MY_NAMESPACE namespace { @@ -56,14 +70,6 @@ QBrush getBrush(const string &pattern, int redValue, int greenValue, int blueVal QPixmap(bits)); } } - -Technology* getTechnology() { - DataBase* database = GetDataBase(); - if (database) { - return database->GetTechnology(); - } - return NULL; -} static QColor backgroundColor = QColor( 50, 50, 50 ); static QColor foregroundColor = QColor( 255, 255, 255 ); @@ -81,124 +87,1691 @@ static QPen boundariesPen = QPen(boundaryColor); static QBrush boundariesBrush = QBrush(boundaryColor); static QPen phantomsPen = QPen(phantomColor); static QBrush phantomsBrush = QBrush(phantomColor); +static QBrush defaultBrush = QBrush(); +static QPen defaultPen = QPen(); } -CellWidget::CellWidget(Cell* c, QWidget* parent) - : QWidget(parent), - cell(c), - invalidRegion(), - clipBox(), - clipX(), - clipY(), - painter(NULL), - backgroundColor(20, 20, 20), - foregroundColor(255, 255, 255), - scale(1), - screenDx(0), - screenDy(0), - brushDx(0), - brushDy(0), - basicLayersBrush(), - basicLayersPen() { - for_each_basic_layer(basiclayer, getTechnology()->GetBasicLayers()) { - basicLayersBrush[basiclayer] = - getBrush(basiclayer->GetFillPattern(), - basiclayer->GetRedValue(), - basiclayer->GetGreenValue(), - basiclayer->GetBlueValue()); - basicLayersPen[basiclayer] = - QPen(QColor(basiclayer->GetRedValue(), basiclayer->GetGreenValue(), basiclayer->GetBlueValue())); - end_for; - } - +Cell* +CellWidget::getCell() const { + return _cell; } -void CellWidget::paintEvent(QPaintEvent* event) { - invalidate(event->rect()); - redraw(); -} +// ************************************************************************************************* +// getLabel() +// ************************************************************************************************* -void CellWidget::reframe(double sc) { - reframe(center, sc); -} - -void CellWidget::reframe(const Point& c, double sc) { - if (0 < sc) { - center = c; - scale = sc; - screenDx = -(int)rint((GetValue(center.getX()) - (width() / (scale*2))) * scale); - screenDy = -(int)rint((GetValue(center.getY()) - (height() / (scale*2))) * scale); - brushDx = 0; - brushDy = 0; - invalidate(); - } -} +///static +///Label +///getLabel(const QColor& color) +///{ +/// return getLabel(color.red()) + ":" + getLabel(color.green()) + ":" + getLabel(color.blue()); +///} +/// -void CellWidget::invalidate() { - invalidRegion = QRegion(rect()); -} +// ************************************************************************************************* +// CellWidget::_sPoints +// ************************************************************************************************* + +//QPointArray CellWidget::_sPoints; -void CellWidget::invalidate(const QRect& screenRect) { - QRect visibleScreenRect = screenRect.intersect(rect()); - if (!visibleScreenRect.isEmpty()) { - invalidRegion = invalidRegion.unite(QRegion(visibleScreenRect)); - } -} +// ************************************************************************************************* +// CellWidget::CellWidget() +// ************************************************************************************************* -void CellWidget::redraw() { - if (!invalidRegion.isEmpty()) { - QRect invalidRect = invalidRegion.boundingRect(); +CellWidget::CellWidget(Cell* cell, + QWidget* parent, + const char* name) +: Inherit(parent), + _cell(cell), + _center(0, 0), + _scale(1), + _screenDx(0), + _screenDy(0), + _brushDx(0), + _brushDy(0), + _alreadyExposed(false), + _invalidRegion(), + _clipBox(), + _clipX(), + _clipY(), + _painter(NULL), + _backgroundColor(20, 20, 20), + _foregroundColor(255, 255, 255), + _doubleBuffering(false), + _automaticScrolling(false), + _visibleLayerMask(~0), + //_commandMap(), + //_startedCommand(NULL), + _gridOrigin(), + _gridXStep(GetUnit(1)), + _gridYStep(GetUnit(1)), + _gridIsVisible(true), + _gridAxesAreVisible(false), + _gridDisplayThreshold(8), + _gridColor(QColor(155, 155, 155)), + _snapGrid(true), + _drawSnapPoint(false), + _snapPoint(), + _displayDepth(1), + _displaySize(2), + //_selectorSet(), + _selectionLimit(100000), + _selectionColor(255, 255, 255), + _selectionIsVisible(true), + //_highlightorSet(), + _highlightionLimit(10000), + _highlightionIsVisible(true), + //_trackBox(NULL), + _peekList(), + _basicLayersBrush(), + _basicLayersPen() +{ + setFocusPolicy(Qt::StrongFocus); // to accepts focus by tabbing and clicking + setMouseTracking(true); // to have move events even a mouse button isn't pressed - H::Box area = getBox(invalidRect).inflate(getSize(1)); - - setClipBox(area); - - QPaintDevice* device = this; - - QPainter newPainter(device); - QPainter* oldPainter = painter; - painter = &newPainter; - - double brightness = 1.0; - - painter->setClipRegion(invalidRegion); - - painter->fillRect(invalidRect, QBrush(getBackgroundColor())); - - painter->save(); - setPen(boundariesPen, brightness); - setBrush(boundariesBrush, brightness); - drawBoundaries(cell, area, Transformation()); - painter->restore(); - - for_each_basic_layer(basiclayer, getTechnology()->GetBasicLayers()) { - if (isDrawable(basiclayer)) { - //painter->save(); - map::const_iterator bmit = basicLayersBrush.find(basiclayer); - if (bmit != basicLayersBrush.end()) { - setBrush(bmit->second, brightness); - } - map::const_iterator pmit = basicLayersPen.find(basiclayer); - if (pmit != basicLayersPen.end()) { - setPen(pmit->second, brightness); - } - drawContent(cell, basiclayer, area, Transformation()); - //painter->restore(); + DataBase* database = GetDataBase(); + if (database) { + Technology* technology = database->GetTechnology(); + if (technology) { + for_each_basic_layer(basiclayer, technology->GetBasicLayers()) { + _basicLayersBrush[basiclayer] = + ::getBrush(basiclayer->GetFillPattern(), + basiclayer->GetRedValue(), + basiclayer->GetGreenValue(), + basiclayer->GetBlueValue()); + _basicLayersPen[basiclayer] = + QPen(QColor(basiclayer->GetRedValue(), basiclayer->GetGreenValue(), basiclayer->GetBlueValue())); end_for; } } - - painter = oldPainter; - - invalidRegion = QRegion(); } } + + +// ************************************************************************************************* +// CellWidget::~CellWidget() +// ************************************************************************************************* + +CellWidget::~CellWidget() +{ + clearPeeks(); + //clearHighlightion(); + //clearSelection(); + + //forEachCommand(command, getCommands()) { + // command->uninstallFrom(this); + // endFor; + //} + + //if (_trackBox) { + // _trackBox->_setCellWidget(NULL); + //} +} + + + +// ************************************************************************************************* +// CellWidget::getLabel() +// CellWidget::getRecord() +// CellWidget::getSlot() +// ************************************************************************************************* + +//Label +//CellWidget::getLabel() const +//{ +// Label label = Label::create(getTypeName(*this)); +// +// View* view = getView(); +// if (view) { +// label.add(" ", view); +// } +// +// return label; +//} +// +//Record* +//CellWidget::getRecord() const +//{ +// Record* record = new Record(this); +// +// if (record) { +// record->addHeader("Widget"); +// +// record->addHeader("CellWidget"); +// +// record->addSlot("View", getView()); +// record->addSlot("Center", getCenter()); +// record->addSlot("Scale", getScale()); +// record->addSlot("BackgroundColor", My::getLabel(getBackgroundColor())); +// record->addSlot("ForegroundColor", My::getLabel(getForegroundColor())); +// record->addSlot("DoubleBuffering", doubleBuffering()); +// record->addSlot("AutomaticScrolling", automaticScrolling()); +// record->addSlot("VisibleLayers", getVisibleLayers()); +// record->addSlot("Commands", getCommands()); +// record->addSlot("GridOrigin", getGridOrigin()); +// record->addSlot("GridXStep", GetValueString(getGridXStep())); +// record->addSlot("GridYStep", GetValueString(getGridYStep())); +// record->addSlot("GridDisplayThreshold", getGridDisplayThreshold()); +// record->addSlot("GridIsVisible", gridIsVisible()); +// record->addSlot("GridAxesAreVisible", gridAxesAreVisible()); +// record->addSlot("GridIsDrawable", gridIsDrawable()); +// record->addSlot("GridColor", My::getLabel(getGridColor())); +// record->addSlot("SnapGrid", snapGrid()); +// record->addSlot("DisplayDepth", getDisplayDepth()); +// record->addSlot("DisplaySize", getDisplaySize()); +// record->addSlot("SelectionIsVisible", selectionIsVisible()); +// record->addSlot("Selection", getSelection()); +// record->addSlot("SelectionBox", getSelectionBox()); +// unsigned limit = getSelectionLimit(); +// if (limit) { +// record->addSlot("SelectionLimit", limit); +// } +// else { +// record->addSlot("SelectionLimit", "NONE"); +// } +// record->addSlot("SelectionColor", My::getLabel(getSelectionColor())); +// record->addSlot("HighlightionIsVisible", highlightionIsVisible()); +// record->addSlot("Highlightion", getHighlightion()); +// record->addSlot("HighlightionBox", getHighlightionBox()); +// record->addSlot("TrackBox", getTrackBox()); +// } +// +// return record; +//} +// +//Slot* +//CellWidget::getSlot(const string& name) const +//{ +// return new StandardSlot(name, this); +//} +// + + +// ************************************************************************************************* +// CellWidget::getCenter() +// CellWidget::getScale() +// ************************************************************************************************* + +const Point& +CellWidget::getCenter() const +{ + return _center; +} + +double +CellWidget::getScale() const +{ + return _scale; +} + + + +// ************************************************************************************************* +// CellWidget::getX() +// CellWidget::getY() +// CellWidget::getSize() +// CellWidget::getPoint() +// CellWidget::getBox() +// ************************************************************************************************* + +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); +} + +Point +CellWidget::getPoint(const QPoint& screenPoint) const +{ + return Point(getX(screenPoint.x()), getY(screenPoint.y())); +} + +Box +CellWidget::getBox(const QRect& screenRect) const +{ + if (screenRect.isEmpty()) { + return Box(); + } + + return Box(getX(screenRect.left()), + getY(screenRect.bottom()), + getX(screenRect.right()), + getY(screenRect.top())); +} + + + +// ************************************************************************************************* +// CellWidget::getScreenX() +// CellWidget::getScreenY() +// CellWidget::getScreenSize() +// CellWidget::getScreenPoint() +// CellWidget::getScreenBox() +// ************************************************************************************************* + +int +CellWidget::getScreenX(const Unit& x) const +{ + return _screenDx + (int)rint(GetValue(x) * _scale); +} + +int +CellWidget::getScreenY(const Unit& y) const +{ + return height() - (int)rint(_screenDy + (GetValue(y) * _scale)); +} + +int +CellWidget::getScreenSize(const Unit& size) const +{ + return (int)rint(GetValue(size) * _scale); +} + +QPoint +CellWidget::getScreenPoint(const Point& point) const +{ + return QPoint(getScreenX(point.getX()), getScreenY(point.getY())); +} + +QRect +CellWidget::getScreenRect(const Box& box) const +{ + if (box.isEmpty()) { + return QRect(); + } + + int screenX1 = getScreenX(box.getXMin()); + int screenY1 = getScreenY(box.getYMin()); + int screenX2 = getScreenX(box.getXMax()); + int screenY2 = getScreenY(box.getYMax()); + + return QRect(QPoint(min(screenX1, screenX2), min(screenY1, screenY2)), + QPoint(max(screenX1, screenX2), max(screenY1, screenY2))); +} + + + +// ************************************************************************************************* +// CellWidget::getSnapPoint() +// ************************************************************************************************* + +Point +CellWidget::getSnapPoint(const Point& point) const +{ + return (_snapGrid) ? getGridPoint(point) : point; +} + +Point +CellWidget::getSnapPoint(int screenX, + int screenY) const +{ + return getSnapPoint(Point(getX(screenX), getY(screenY))); +} + + + +// ************************************************************************************************* +// CellWidget::getVisibleLayers() +// ************************************************************************************************* + +BasicLayers +CellWidget::getVisibleLayers() const +{ + DataBase* database = GetDataBase(); + if (database) { + Technology* technology = database->GetTechnology(); + if (technology) { + return technology->GetBasicLayers(_visibleLayerMask); + } + } + return NULL; +} + + + +// ************************************************************************************************* +// CellWidget::getCommand() +// CellWidget::getCommands() +// ************************************************************************************************* + +//Command* +//CellWidget::getCommand(int button) const +//{ +// CommandMap::const_iterator i = _commandMap.find(button); +// +// return (i != _commandMap.end()) ? (*i).second : NULL; +//} +// +//Commands +//CellWidget::getCommands() const +//{ +// return _commandMap; +//} +// + + +// ************************************************************************************************* +// CellWidget::getGridX() +// CellWidget::getGridY() +// CellWidget::getGridPoint() +// ************************************************************************************************* + +Unit +CellWidget::getGridX(const Unit& x, + int sign) const +{ + if (!((-1 <= sign) && (sign <= 1))) { + //throw Error(INVALID_REQUEST, __FILE__, __LINE__); + } + + Unit cx = x; + Unit xo = _gridOrigin.getX(); + + if (cx != xo) { + cx -= xo; + switch (sign) { + case -1 : { + if (0 < cx) { + return ((cx / _gridXStep) * _gridXStep) + xo; + } + else { + if (cx < 0) { + return (((cx / _gridXStep) - 1) * _gridXStep) + xo; + } + } + return cx + xo; + } + case 0 : { + Unit x1 = (cx / _gridXStep) * _gridXStep; + Unit x2 = ((x1 < cx) ? (x1 + _gridXStep) : (x1 - _gridXStep)); + return ((labs(x1 - cx) <= labs(x2 - cx)) ? x1 : x2) + xo; + } + case 1 : { + if (0 < cx) { + return (((cx / _gridXStep) + 1) * _gridXStep) + xo; + } + else { + if (cx < 0) { + return ((cx / _gridXStep) * _gridXStep) + xo; + } + } + return cx + xo; + } + } + } + + return cx; +} + +Unit +CellWidget::getGridY(const Unit& y, + int sign) const +{ + if (!((-1 <= sign) && (sign <= 1))) { + //throw Error(INVALID_REQUEST, __FILE__, __LINE__); + } + + Unit cy = y; + Unit yo = _gridOrigin.getY(); + + if (cy != yo) { + cy -= yo; + switch (sign) { + case -1 : { + if (0 < cy) { + return ((cy / _gridYStep) * _gridYStep) + yo; + } + else { + if (cy < 0) { + return (((cy / _gridYStep) - 1) * _gridYStep) + yo; + } + } + return cy + yo; + } + case 0 : { + Unit y1 = (cy / _gridYStep) * _gridYStep; + Unit y2 = ((y1 < cy) ? (y1 + _gridYStep) : (y1 - _gridYStep)); + return ((labs(y1 - cy) <= labs(y2 - cy)) ? y1 : y2) + yo; + } + case 1 : { + if (0 < cy) { + return (((cy / _gridYStep) + 1) * _gridYStep) + yo; + } + else { + if (cy < 0) { + return ((cy / _gridYStep) * _gridYStep) + yo; + } + } + return cy + yo; + } + } + } + + return cy; +} + +Point +CellWidget::getGridPoint(const Point& point, + int xSign, + int ySign) const +{ + return Point(getGridX(point.getX(), xSign), getGridY(point.getY(), ySign)); +} + + + +// ************************************************************************************************* +// CellWidget::getWorld() +// ************************************************************************************************* + +//Box +//CellWidget::getWorld() const +//{ +// Box world = Box(getX(0), getY(0), getX(width()), getY(height())); +// +// View* view = getView(); +// +// if (view) { +// world.merge(view->getBoundingBox()); +// } +// +// return world; +//} + + + +// ************************************************************************************************* +// CellWidget::getSelectors() +// CellWidget::getSelection() +// CellWidget::getSelectionBox() +// CellWidget::getHighlightors() +// CellWidget::getHighlightion() +// CellWidget::getHighlightionBox() +// ************************************************************************************************* + +//Selectors +//CellWidget::getSelectors() const +//{ +// return _selectorSet; +//} + +//Occurrences +//CellWidget::getSelection() const +//{ +// return getSelectors().getAssociates(GetOccurrence()); +//} + +//Box +//CellWidget::getSelectionBox() const +//{ +// Box selectionBox; +// +// forEachOccurrence(occurrence, getSelection()) { +// selectionBox.merge(occurrence.getBoundingBox()); +// endFor; +// } +// +// return selectionBox; +//} +// +//Highlightors +//CellWidget::getHighlightors() const +//{ +// return _highlightorSet; +//} +// +//Occurrences +//CellWidget::getHighlightion() const +//{ +// return getHighlightors().getAssociates(GetOccurrence()); +//} +// +//Box +//CellWidget::getHighlightionBox() const +//{ +// Box highlightionBox; +// +// forEachOccurrence(occurrence, getHighlightion()) { +// highlightionBox.merge(occurrence.getBoundingBox()); +// endFor; +// } +// +// return highlightionBox; +//} +// + + +// ************************************************************************************************* +// CellWidget::getFont() +// CellWidget::getPen() +// CellWidget::getBrush() +// CellWidget::getBrushOrigin() +// ************************************************************************************************* + +const QFont& +CellWidget::getFont() +{ + return (_painter) ? _painter->font() : QPainter(this).font(); +} + +const QPen& +CellWidget::getPen() +{ + return (_painter) ? _painter->pen() : QPainter(this).pen(); +} + + +const QPen& +CellWidget::getPen(const BasicLayer* basiclayer) { + map::const_iterator pmit = _basicLayersPen.find(basiclayer); + if (pmit != _basicLayersPen.end()) { + return pmit->second; + } + return defaultPen; +} + +const QBrush& +CellWidget::getBrush() +{ + return (_painter) ? _painter->brush() : QPainter(this).brush(); +} + +const QBrush& +CellWidget::getBrush(BasicLayer* basiclayer) { + map::const_iterator bmit = _basicLayersBrush.find(basiclayer); + if (bmit != _basicLayersBrush.end()) { + return bmit->second; + } + return defaultBrush; +} + +const QPoint +CellWidget::getBrushOrigin() +{ + return (_painter) ? _painter->brushOrigin() : QPainter(this).brushOrigin(); +} + + + +// ************************************************************************************************* +// CellWidget::hasRecord() +// ************************************************************************************************* + +bool +CellWidget::hasRecord() const +{ + return true; +} + + + +// ************************************************************************************************* +// CellWidget::setTrackBox() +// ************************************************************************************************* + +//void +//CellWidget::setTrackBox(TrackBox* trackBox) +//{ +// if (trackBox != _trackBox) { +// if (_trackBox) { +// _trackBox->_setCellWidget(NULL); +// } +// _trackBox = trackBox; +// if (_trackBox) { +// _trackBox->_setCellWidget(this); +// } +// } +//} +// + + +// ************************************************************************************************* +// CellWidget::allowAutomaticScrolling() +// ************************************************************************************************* + +bool +CellWidget::allowAutomaticScrolling() const +{ + return true; +} + + + +// ************************************************************************************************* +// CellWidget::isVisible() +// CellWidget::isDrawable() +// ************************************************************************************************* + +bool +CellWidget::isVisible(BasicLayer* layer) const +{ + if (!layer) { + //throw Error(NULL_LAYER, __FILE__, __LINE__); + } + + return (_visibleLayerMask & layer->GetMask()); +} + +bool +CellWidget::isDrawable(BasicLayer* layer) const +{ + if (!layer) { + //throw Error(NULL_LAYER, __FILE__, __LINE__); + } + + return (layer->GetDisplayThreshold() <= _scale); +} + + + +// ************************************************************************************************* +// CellWidget::isOnGridX() +// CellWidget::isOnGridY() +// CellWidget::isOnGridPoint() +// ************************************************************************************************* + +bool +CellWidget::isOnGridX(const Unit& x, + unsigned n) const +{ + if (!n) { + //throw Error(INVALID_REQUEST, __FILE__, __LINE__); + } + + Unit delta = labs(x - _gridOrigin.getX()); + + if (delta < 0) { + delta = -delta; + } + + Unit step = _gridXStep * n; + + return (delta == ((delta / step) * step)); +} + +bool +CellWidget::isOnGridY(const Unit& y, + unsigned n) const +{ + if (!n) { + //throw Error(INVALID_REQUEST, __FILE__, __LINE__); + } + + Unit delta = labs(y - _gridOrigin.getY()); + + if (delta < 0) { + delta = -delta; + } + + Unit step = _gridYStep * n; + + return (delta == ((delta / step) * step)); +} + +bool +CellWidget::isOnGridPoint(const Point& point, + unsigned xN, + unsigned yN) const +{ + return isOnGridX(point.getX(), xN) && isOnGridY(point.getX(), yN); +} + + + +// ************************************************************************************************* +// CellWidget::isSelected() +// CellWidget::isSelectable() +// CellWidget::isHighlighted() +// CellWidget::isHighlightable() +// ************************************************************************************************* + +//bool +//CellWidget::isSelected(const Occurrence& occurrence) const +//{ +// Selector* selector = +// dynamic_cast(occurrence.getProperty(Selector::getPropertyName())); +// +// return (selector) ? selector->_contains((CellWidget*)this) : false; +//} +// +//bool +//CellWidget::isSelectable(const Occurrence& occurrence) const +//{ +// return occurrence.isSelectable() && (occurrence.getView() == getView()); +//} +// +//bool +//CellWidget::isHighlighted(const Occurrence& occurrence) const +//{ +// Highlightor* highlightor = +// dynamic_cast(occurrence.getProperty(Highlightor::getPropertyName())); +// +// return (highlightor) ? highlightor->_contains((CellWidget*)this) : false; +//} +// +//bool +//CellWidget::isHighlightable(const Occurrence& occurrence) const +//{ +// return occurrence.isHighlightable() && (occurrence.getView() == getView()); +//} + + + +// ************************************************************************************************* +// CellWidget::setBackgroundColor() +// CellWidget::setForegroundColor() +// ************************************************************************************************* + +void +CellWidget::setBackgroundColor(const QColor& color) +{ + if (color != _backgroundColor) { + _backgroundColor = color; + invalidate(); + } +} + +void +CellWidget::setForegroundColor(const QColor& color) +{ + if (color != _foregroundColor) { + _foregroundColor = color; + invalidate(); + } +} + + + +// ************************************************************************************************* +// CellWidget::setVisible() +// ************************************************************************************************* + +void +CellWidget::setVisible(BasicLayer* layer, + bool visible) +{ + if (isVisible(layer) != visible) { + if (visible) { + _visibleLayerMask |= layer->GetMask(); + } + else { + _visibleLayerMask &= ~layer->GetMask(); + } + + onSetVisible(layer, visible); + + Cell* cell = getCell(); + + //if (view && !view->getSlices(layer).isEmpty() && isDrawable(layer)) { + // invalidate(); + //} + + if (cell && !cell->GetSlices(layer->GetMask()).IsEmpty() && isDrawable(layer)) { + invalidate(); + } + } +} + + + +// ************************************************************************************************* +// CellWidget::setGridOrigin() +// CellWidget::setGridXStep() +// CellWidget::setGridYStep() +// CellWidget::setGridStep() +// CellWidget::setGridSteps() +// CellWidget::setGridDisplayThreshold() +// CellWidget::setGridColor() +// ************************************************************************************************* + +void +CellWidget::setGridOrigin(const Point& origin) +{ + if (origin != _gridOrigin) { + bool gridIsDrawn = gridIsVisible() && gridIsDrawable(); + + _gridOrigin = origin; + + if (gridIsDrawn || (gridIsVisible() && gridIsDrawable())) { + invalidate(); + } + } +} + +void +CellWidget::setGridXStep(const Unit& step) +{ + if (!step) { + //throw Error(INVALID_REQUEST, __FILE__, __LINE__); + } + + if (step != _gridXStep) { + bool gridIsDrawn = gridIsVisible() && gridIsDrawable(); + + _gridXStep = step; + + if (gridIsDrawn || (gridIsVisible() && gridIsDrawable())) { + invalidate(); + } + } +} + +void +CellWidget::setGridYStep(const Unit& step) +{ + if (!step) { + //throw Error(INVALID_REQUEST, __FILE__, __LINE__); + } + + if (step != _gridYStep) { + bool gridIsDrawn = gridIsVisible() && gridIsDrawable(); + + _gridYStep = step; + + if (gridIsDrawn || (gridIsVisible() && gridIsDrawable())) { + invalidate(); + } + } +} + +void +CellWidget::setGridStep(const Unit& step) +{ + if (!step) { + //throw Error(INVALID_REQUEST, __FILE__, __LINE__); + } + + if ((step != _gridXStep) || (step != _gridYStep)) { + bool gridIsDrawn = gridIsVisible() && gridIsDrawable(); + + _gridXStep = step; + _gridYStep = step; + + if (gridIsDrawn || (gridIsVisible() && gridIsDrawable())) { + invalidate(); + } + } +} + +void +CellWidget::setGridSteps(const Unit& xStep, + const Unit& yStep) +{ + if (!xStep || !yStep) { + //throw Error(INVALID_REQUEST, __FILE__, __LINE__); + } + + if ((xStep != _gridXStep) || (yStep != _gridYStep)) { + bool gridIsDrawn = gridIsVisible() && gridIsDrawable(); + + _gridXStep = xStep; + _gridYStep = yStep; + + if (gridIsDrawn || (gridIsVisible() && gridIsDrawable())) { + invalidate(); + } + } +} + +void +CellWidget::setGridDisplayThreshold(unsigned threshold) +{ + if (threshold < 3) { + //throw Error(INVALID_REQUEST, __FILE__, __LINE__); + } + + _gridDisplayThreshold = threshold; + + invalidate(); +} + +void +CellWidget::setGridColor(const QColor& color) +{ + if (_gridColor != color) { + _gridColor = color; + if (gridIsVisible() && gridIsDrawable()) { + invalidate(); + } + } +} + + + +// ************************************************************************************************* +// CellWidget::setGridVisible() +// CellWidget::setGridAxesVisible() +// CellWidget::setSnapGrid() +// ************************************************************************************************* + +void +CellWidget::setGridVisible(bool visible) +{ + if (_gridIsVisible != visible) { + _gridIsVisible = visible; + if (gridIsDrawable()) { + invalidate(); + } + } +} + +void +CellWidget::setGridAxesVisible(bool visible) +{ + if (_gridAxesAreVisible != visible) { + _gridAxesAreVisible = visible; + if (gridIsDrawable()) { + invalidate(); + } + } +} + +void +CellWidget::setSnapGrid(bool enable) +{ + if (_snapGrid != enable) { + if (_snapGrid && _drawSnapPoint) { + drawSnapPoint(); + _drawSnapPoint = false; + } + _snapGrid = enable; + if (_snapGrid && !_drawSnapPoint) { + _drawSnapPoint = true; + drawSnapPoint(); + } + } +} + + + +// ************************************************************************************************* +// CellWidget::setDisplayDepth() +// CellWidget::setDisplayDepth() +// ************************************************************************************************* + +void +CellWidget::setDisplayDepth(unsigned displayDepth) +{ + if (displayDepth != _displayDepth) { + _displayDepth = displayDepth; + invalidate(); + } +} + +void +CellWidget::setDisplaySize(unsigned displaySize) +{ + if (displaySize != _displaySize) { + _displaySize = displaySize; + } +} + + + +// ************************************************************************************************* +// CellWidget::setFont() +// CellWidget::setPen() +// CellWidget::setBrush() +// CellWidget::setBrushOrigin() +// ************************************************************************************************* + +void +CellWidget::setFont(const QFont& font) +{ + if (_painter) { + _painter->setFont(font); + } +} + +void +CellWidget::setPen(const QPen& pen, + double brightness) +{ + if (!((0.1 <= brightness) && (brightness <= 1.0))) { + //throw Error(INVALID_REQUEST, __FILE__, __LINE__); + } + + if (_painter) { + if (pen == Qt::NoPen) { + _painter->setPen(pen); + } + else { + QPen correctedPen = pen; + + if (brightness < 1) { + QColor bgColor = getBackgroundColor(); + int r = bgColor.red(); + int g = bgColor.green(); + int b = bgColor.blue(); + + QColor color = pen.color(); + r = r + (int)((color.red() - r) * brightness); + g = g + (int)((color.green() - g) * brightness); + b = b + (int)((color.blue() - b) * brightness); + + correctedPen = QPen(QColor(r, g, b)); + } + + _painter->setPen(correctedPen); + } + } +} + +void +CellWidget::setBrush(const QBrush& brush, + double brightness) +{ + if (!((0.1 <= brightness) && (brightness <= 1.0))) { + //throw Error(INVALID_REQUEST, __FILE__, __LINE__); + } + + if (_painter) { + if (brush == Qt::NoBrush) { + _painter->setBrush(brush); + } + else { + QBrush correctedBrush = brush; + + if (brightness < 1) { + QColor bgColor = getBackgroundColor(); + int r = bgColor.red(); + int g = bgColor.green(); + int b = bgColor.blue(); + + QColor color = brush.color(); + r = r + (int)((color.red() - r) * brightness); + g = g + (int)((color.green() - g) * brightness); + b = b + (int)((color.blue() - b) * brightness); + + correctedBrush = QBrush(QColor(r, g, b), brush.style()); + } + + _painter->setBrush(correctedBrush); + } + } +} + +void +CellWidget::setBrushOrigin(const QPoint& origin) +{ + if (_painter) { + _painter->setBrushOrigin(_brushDx + origin.x(), _brushDy + origin.y()); + } +} + + + +// ************************************************************************************************* +// CellWidget::setSelectionColor() +// CellWidget::setSelectionVisible() +// CellWidget::setHighlightionVisible() +// ************************************************************************************************* + +//void +//CellWidget::setSelectionColor(const QColor& color) +//{ +// if (color != _selectionColor) { +// _selectionColor = color; +// if (selectionIsVisible()) { +// invalidate(getSelectionBox()); +// } +// } +//} +// +//void +//CellWidget::setSelectionVisible(bool visible) +//{ +// if (_selectionIsVisible != visible) { +// _selectionIsVisible = visible; +// invalidate(getSelectionBox()); +// } +//} +// +//void +//CellWidget::setHighlightionVisible(bool visible) +//{ +// if (_highlightionIsVisible != visible) { +// _highlightionIsVisible = visible; +// invalidate(getHighlightionBox()); +// } +//} +// + + +// ************************************************************************************************* +// CellWidget::setAutomaticScrolling() +// ************************************************************************************************* + +void +CellWidget::setAutomaticScrolling(bool enable) +{ + if (!allowAutomaticScrolling()) { + //throw Error(INVALID_REQUEST, __FILE__, __LINE__); + } + + _automaticScrolling = enable; +} + + + +// ************************************************************************************************* +// CellWidget::showAllLayers() +// CellWidget::hideAllLayers() +// ************************************************************************************************* + +void +CellWidget::showAllLayers() +{ + DataBase* database = GetDataBase(); + if (database) { + Technology* technology = database->GetTechnology(); + if (technology) { + for_each_basic_layer(layer, technology->GetBasicLayers()) { + setVisible(layer, true); + end_for; + } + } + } +} + +void +CellWidget::hideAllLayers() +{ + DataBase* database = GetDataBase(); + if (database) { + Technology* technology = database->GetTechnology(); + if (technology) { + for_each_basic_layer(layer, technology->GetBasicLayers()) { + setVisible(layer, false); + end_for; + } + } + } +} + + + +// ************************************************************************************************* +// CellWidget::select() +// CellWidget::unselect() +// CellWidget::clearSelection() +// ************************************************************************************************* + +//bool +//CellWidget::select(const Occurrence& occurrence) +//{ +// if (!isSelectable(occurrence)) { +// throw Error(INVALID_REQUEST, __FILE__, __LINE__); +// } +// +// if (_selectionLimit && (_selectionLimit <= getSelectors().getCount())) { +// return false; +// } +// +// Property* property = occurrence.getProperty(Selector::getPropertyName()); +// +// Selector* selector = NULL; +// +// if (!property) { +// selector = new Selector(occurrence); +// } +// else { +// if (!dynamic_cast(property)) { +// throw Error(BAD_PROPERTY_TYPE, __FILE__, __LINE__); +// } +// selector = (Selector*)property; +// } +// +// selector->_attachTo(this); +// +// invalidate(occurrence.getBoundingBox()); +// +// return true; +//} + +//void +//CellWidget::unselect(const Occurrence& occurrence) +//{ +// if (!isSelectable(occurrence)) { +// throw Error(INVALID_REQUEST, __FILE__, __LINE__); +// } +// +// Property* property = occurrence.getProperty(Selector::getPropertyName()); +// +// if (property) { +// if (!dynamic_cast(property)) { +// throw Error(BAD_PROPERTY_TYPE, __FILE__, __LINE__); +// } +// +// ((Selector*)property)->_detachFrom(this); +// +// invalidate(occurrence.getBoundingBox()); +// } +//} +// +//void +//CellWidget::clearSelection() +//{ +// Occurrences selection = getSelection(); +// +// bool _cumulativeMode = false; // HOOPS !!! +// if (_cumulativeMode) { +// invalidate(getSelectionBox()); +// } +// +// while (!selection.isEmpty()) { +// unselect(selection.getFirst()); +// } +//} +// +// +// +//// ************************************************************************************************* +//// CellWidget::highlight() +//// CellWidget::unhighlight() +//// CellWidget::clearHighlightion() +//// ************************************************************************************************* +// +//bool +//CellWidget::highlight(const Occurrence& occurrence) +//{ +// if (!isHighlightable(occurrence)) { +// throw Error(INVALID_REQUEST, __FILE__, __LINE__); +// } +// +// unsigned count = getHighlightors().getCount(); +// +// if (_highlightionLimit && (_highlightionLimit <= count)) { +// return false; +// } +// +// Property* property = occurrence.getProperty(Highlightor::getPropertyName()); +// +// Highlightor* highlightor = NULL; +// +// if (!property) { +// highlightor = new Highlightor(occurrence); +// } +// else { +// if (!dynamic_cast(property)) { +// throw Error(BAD_PROPERTY_TYPE, __FILE__, __LINE__); +// } +// highlightor = (Highlightor*)property; +// } +// +// highlightor->_attachTo(this); +// +// if (!count) { +// invalidate(); +// } +// else { +// invalidate(occurrence.getBoundingBox()); +// } +// +// return true; +//} +// +//void +//CellWidget::unhighlight(const Occurrence& occurrence) +//{ +// if (!isHighlightable(occurrence)) { +// throw Error(INVALID_REQUEST, __FILE__, __LINE__); +// } +// +// Property* property = occurrence.getProperty(Highlightor::getPropertyName()); +// +// if (property) { +// if (!dynamic_cast(property)) { +// throw Error(BAD_PROPERTY_TYPE, __FILE__, __LINE__); +// } +// +// ((Highlightor*)property)->_detachFrom(this); +// +// if (getHighlightors().isEmpty()) { +// invalidate(); +// } +// else { +// invalidate(occurrence.getBoundingBox()); +// } +// } +//} +// +//void +//CellWidget::clearHighlightion() +//{ +// Occurrences highlightion = getHighlightion(); +// +// bool _cumulativeMode = false; // HOOPS !!! +// if (_cumulativeMode) { +// invalidate(getHighlightionBox()); +// } +// +// while (!highlightion.isEmpty()) { +// unhighlight(highlightion.getFirst()); +// } +//} +// +// + +// ************************************************************************************************* +// CellWidget::clearPeeks() +// CellWidget::addPeek() +// ************************************************************************************************* + +void +CellWidget::clearPeeks() +{ + for (list::iterator plit = _peekList.begin(); + plit != _peekList.end(); + ++plit) { + invalidate(*plit); + } +// for_each_box(peek, GetCollection(_peekList)) { +// invalidate(peek); +// end_for; +// } +// + _peekList.clear(); +} + +void +CellWidget::addPeek(const Box& peek) +{ + if (!peek.isEmpty()) { + invalidate(peek); + _peekList.push_back(peek); + } +} + + + +// ************************************************************************************************* +// CellWidget::invalidate() +// ************************************************************************************************* + +void +CellWidget::invalidate() +{ + _invalidRegion = QRegion(rect()); +} + +void +CellWidget::invalidate(const QRect& screenRect) +{ + QRect visibleScreenRect = screenRect.intersect(rect()); + + if (!visibleScreenRect.isEmpty()) { + bool _cumulativeMode = false; // HOOPS !!! + if (!_cumulativeMode) { + _invalidRegion = _invalidRegion.unite(QRegion(visibleScreenRect)); + } + else { + _invalidRegion = QRegion(_invalidRegion.boundingRect().unite(visibleScreenRect)); + } + } +} + +void +CellWidget::invalidate(const Box& box) +{ + if (!box.isEmpty()) { + int safetyMargin = 2; // 2 pixel + invalidate(getScreenRect(box.getInflated(getSize(safetyMargin)))); + } +} + +void +CellWidget::fitToContent(unsigned screenMargin) { + Box area(getX(0), getY(0), getX(width()), getY(height())); + if (_cell) { + area = _cell->GetBoundingBox(); + } + + reframe(area); + area.inflate(screenMargin); + reframe(area); +} + + + + +// ************************************************************************************************* +// CellWidget::reframe() +// ************************************************************************************************* + +void +CellWidget::reframe() +{ + reframe(_center, _scale); +} + +void +CellWidget::reframe(double scale) +{ + reframe(_center, scale); +} + +void +CellWidget::reframe(const Point& center) +{ + reframe(center, _scale); +} + +void +CellWidget::reframe(const Point& center, + double scale) +{ + if (0 < scale) { + _center = center; + _scale = scale; + _screenDx = -(int)rint((GetValue(_center.getX()) - (width() / (_scale*2))) * _scale); + _screenDy = -(int)rint((GetValue(_center.getY()) - (height() / (_scale*2))) * _scale); + _brushDx = 0; + _brushDy = 0; + invalidate(); + } +} + +void +CellWidget::reframe(const Box& box) +{ + if (!box.isEmpty()) { + Point center = box.getCenter(); + + double scale = min((double)width() / GetValue(box.getWidth()), + (double)height() / GetValue(box.getHeight())); + + reframe(center, scale); + } +} + + + +// ************************************************************************************************* +// CellWidget::scroll() +// ************************************************************************************************* + +void +CellWidget::scroll(const Unit& dx, + const Unit& dy) +{ + if ((getSize(width()) < labs(dx)) || (getSize(height()) < labs(dy))) { + reframe(getCenter().getTranslated(-dx, -dy)); + redraw(); + } + else { + int sdx = getScreenSize(dx); + int sdy = getScreenSize(dy); + + if (sdx || sdy) { + QCursor oldCursor = cursor(); + setCursor(Qt::WaitCursor); + + if (_snapGrid) { + drawSnapPoint(); + } + + //forEachCommand(command, getCommands()) { + // _callDrawOf(command); + // endFor; + //} + + _screenDx += sdx; + _screenDy += sdy; + + _brushDx += sdx; + _brushDy -= sdy; + + _center = getPoint(QPoint(width() / 2, height() / 2)); + + int w = width(); + int h = height(); + + if (0 < sdx) { + if (0 < sdy) { + //bitBlt(this, sdx, 0, this, 0, sdy, w - sdx, h - sdy); + invalidate(QRect(-1, -1, sdx + 1, h + 1)); + _redraw(); + invalidate(QRect(sdx - 1, h - sdy - 1, w + 1, h + 1)); + _redraw(); + } + else { + //bitBlt(this, sdx, -sdy, this, 0, 0, w - sdx, h + sdy, CopyROP); + invalidate(QRect(-1, -1, sdx + 1, h + 1)); + _redraw(); + invalidate(QRect(sdx - 1, -1, w + 1, -sdy + 1)); + _redraw(); + } + } + else { + if (0 < sdy) { + //bitBlt(this, 0, 0, this, -sdx, sdy, w + sdx, h - sdy, CopyROP); + invalidate(QRect(w + sdx - 1, -1, w + 1, h + 1)); + _redraw(); + invalidate(QRect(-1, h - sdy - 1, w + sdx + 1, h + 1)); + _redraw(); + } + else { + //bitBlt(this, 0, -sdy, this, -sdx, 0, w + sdx, h + sdy); + invalidate(QRect(w + sdx - 1, -1, w + 1, h + 1)); + _redraw(); + invalidate(QRect(-1, -1, w + sdx + 1, -sdy + 1)); + _redraw(); + } + } + + //forEachCommand(command, reverse(getCommands())) { + // _callDrawOf(command); + // endFor; + //} + + if (_snapGrid) { + drawSnapPoint(); + } + + setCursor(oldCursor); + } + } +} + + + +// ************************************************************************************************* +// CellWidget::redraw() +// ************************************************************************************************* + +void +CellWidget::redraw() +{ + if (!_invalidRegion.isEmpty()) { + QCursor oldCursor = cursor(); + setCursor(Qt::WaitCursor); + + if (_snapGrid) { + drawSnapPoint(); + } + + //forEachCommand(command, getCommands()) { + // _callDrawOf(command); + // endFor; + //} + + if (!_alreadyExposed) { + fitToContent(); + _alreadyExposed = true; + } + + _redraw(); + + //forEachCommand(command, reverse(getCommands())) { + // _callDrawOf(command); + // endFor; + //} + + if (_snapGrid) { + drawSnapPoint(); + } + + setCursor(oldCursor); + + _invalidRegion = QRegion(); + } +} + + + +// ************************************************************************************************* +// CellWidget::abortStartedCommand() +// ************************************************************************************************* + +//void +//CellWidget::abortStartedCommand() +//{ +// if (_startedCommand) { +// _startedCommand->abortOn(this); +// } +// +// if (_trackBox) { +// _trackBox->stop(_snapPoint); +// } +//} + + + +// ************************************************************************************************* +// CellWidget::preRedraw() +// CellWidget::postRedraw() +// ************************************************************************************************* + +void +CellWidget::preRedraw(const Box& area) +{ +} + +void +CellWidget::postRedraw(const Box& area) +{ +} + + void CellWidget::drawContent(const Cell* cell, const BasicLayer* basicLayer, const H::Box& updateArea, const Transformation& transformation) const { for_each_instance(instance, cell->GetInstancesUnder(updateArea)) { drawContent(instance, basicLayer, updateArea, transformation); @@ -290,284 +1863,900 @@ void CellWidget::drawBoundaries(const Instance* instance, const H::Box& updateAr drawBoundaries(instance->GetMasterCell(), masterArea, masterTransformation); } -void CellWidget::drawRectangle(const H::Box& box) const { - if (painter) { - H::Box ibox = box.getIntersection(clipBox); - if (!ibox.isEmpty()) { - int x = getScreenX(ibox.getXMin()); - int y = getScreenY(ibox.getYMax()); - int w = getScreenX(ibox.getXMax()) - x + 1; - int h = getScreenY(ibox.getYMin()) - y + 1; - painter->drawRect(x, y, w, h); - } + +// ************************************************************************************************* +// CellWidget::drawLine() +// CellWidget::drawPolyline() +// CellWidget::drawRectangle() +// CellWidget::drawPolygon() +// CellWidget::drawText() +// ************************************************************************************************* + +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->drawLine(ixo, iyo, ixe, iye); + //_painter->moveTo(ixo, iyo); + //_painter->lineTo(ixe, iye); + _painter->restore(); + } } } -void CellWidget::drawLine(const Point& po, const Point& pe) const { - drawLine(po.getX(), po.getY(), pe.getX(), pe.getY()); -} +//void +//CellWidget::drawPolyline(const Points& points) +//{ +// if (_painter) { +// unsigned sCount; +// +// if (clipLines(points, _sPoints, sCount, false)) { +// _painter->save(); +// if (_painter->pen() == NoPen) { +// _painter->setPen(_painter->brush().color()); +// } +// _painter->drawPolyline(_sPoints, 0, sCount); +// _painter->restore(); +// } +// } +//} -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(); - } +void +CellWidget::drawRectangle(const Box& box) const +{ + if (_painter) { + Box ibox = box.getIntersection(_clipBox); + + if (!ibox.isEmpty()) { + int x = getScreenX(ibox.getXMin()); + int y = getScreenY(ibox.getYMax()); + int w = getScreenX(ibox.getXMax()) - x + 1; + int h = getScreenY(ibox.getYMin()) - y + 1; + _painter->drawRect(x, y, w, h); + } } } -Unit CellWidget::getX(int screenX) const { - return GetUnit((screenX - screenDx) / scale); +//void +//CellWidget::drawPolygon(const Points& points) +//{ +// if (_painter) { +// unsigned sCount; +// +// if (clipLines(points, _sPoints, sCount, true)) { +// _painter->drawPolygon(_sPoints, true, 0, sCount); +// } +// } +//} + +//void +//CellWidget::drawText(const Box& frame, +// const string& text, +// const Direction& direction) +//{ +// if (_painter && !frame.isEmpty()) { +// int x = getScreenX(frame.getXMin()); +// int y = getScreenY(frame.getYMax()); +// int w = getScreenX(frame.getXMax()) - x + 1; +// int h = getScreenY(frame.getYMin()) - y + 1; +// switch (direction) { +// case NORTH: { +// int ow = w; +// w = h; +// h = ow; +// int ox = x; +// x = - (y + w); +// y = ox; +// break; +// } +// /* +// case WEST: { +// x = - (x + w); +// y = - (y + h); +// break; +// } +// */ +// case SOUTH: { +// int ow = w; +// w = h; +// h = ow; +// int ox = x; +// x = y; +// y = - (ox + h); +// break; +// } +// } +// QFontMetrics metrics(_painter->font()); +// if ((metrics.width(text) <= w) && (metrics.height() <= h)) { +// _painter->save(); +// switch (direction) { +// case NORTH: _painter->rotate(-90); break; +// /* +// case WEST: _painter->rotate(180); break; +// */ +// case SOUTH: _painter->rotate(90); break; +// } +// if (_painter->pen() == NoPen) { +// _painter->setPen(_painter->brush().color()); +// } +// _painter->drawText(x, y, w, h, Qt::AlignCenter, text); +// _painter->restore(); +// } +// } +//} +// + + +// ************************************************************************************************* +// CellWidget::drawSnapPoint() +// ************************************************************************************************* + +void +CellWidget::drawSnapPoint() +{ + if (_drawSnapPoint) { + int sx = getScreenX(_snapPoint.getX()); + int sy = getScreenY(_snapPoint.getY()); + + if (((-3 <= sx) && (sx <= (width() + 3))) && + ((-3 <= sy) && (sy <= (height() + 3)))) { + QPainter painter(this); + painter.setPen(getForegroundColor()); + painter.setBrush(Qt::NoBrush); + //painter.setRasterOp(Qt::XorROP); + painter.drawRect(sx - 3, sy - 3, 7, 7); + } + } } -Unit CellWidget::getY(int screenY) const { - return GetUnit(((height() - screenY) - screenDy) / scale); + + +// ************************************************************************************************* +// CellWidget::resizeEvent() +// CellWidget::enterEvent() +// CellWidget::leaveEvent() +// CellWidget::mousePressEvent() +// CellWidget::mouseMoveEvent() +// CellWidget::mouseReleaseEvent() +// CellWidget::focusInEvent() +// CellWidget::focusOutEvent() +// CellWidget::paintEvent() +// ************************************************************************************************* + +void +CellWidget::resizeEvent(QResizeEvent* event) +{ + reframe(); } -Unit CellWidget::getSize(int screenSize) const { - return GetUnit(screenSize / scale); +//void +//CellWidget::enterEvent(QEvent* event) +//{ +// if (getView()) { +// forEachCommand(command, getCommands()) { +// command->onArm(this); +// endFor; +// } +// } +// +// if (_snapGrid) { +// _drawSnapPoint = true; +// drawSnapPoint(); +// } +//} +// +//void +//CellWidget::leaveEvent(QEvent* event) +//{ +// if (_snapGrid) { +// drawSnapPoint(); +// _drawSnapPoint = false; +// } +// +// if (getView()) { +// forEachCommand(command, getCommands()) { +// command->onDisarm(this); +// endFor; +// } +// } +//} + +//void +//CellWidget::mousePressEvent(QMouseEvent* event) +//{ +// if (!_startedCommand) { +// Point position = getSnapPoint(event->x(), event->y()); +// if (getView()) { +// _startedCommand = getCommand(event->button()); +// +// if (_startedCommand) { +// _startedCommand->onStart(this, position, event->state()); +// } +// } +// if (_trackBox) { +// _trackBox->start(position); +// } +// } +//} +// +//void +//CellWidget::mouseMoveEvent(QMouseEvent* event) +//{ +// if (_startedCommand && automaticScrolling() && _startedCommand->automaticScrolling()) { +// int sx = event->x(); +// int sy = event->y(); +// Unit dx = 0; +// if (sx < 0) { +// dx = GetUnit(width() / 40); +// } +// else { +// if (width() < sx) { +// dx = - GetUnit(width() / 40); +// } +// } +// Unit dy = 0; +// if (sy < 0) { +// dy = - GetUnit(height() / 40); +// } +// else { +// if (height() < sy) { +// dy = GetUnit(height() / 40); +// } +// } +// if (dx || dy) { +// scroll(dx, dy); +// } +// } +// +// Point position = getSnapPoint(event->x(), event->y()); +// +// if (position != _snapPoint) { +// if (_snapGrid) { +// drawSnapPoint(); +// } +// _snapPoint = position; +// if (_snapGrid) { +// drawSnapPoint(); +// } +// if (getView()) { +// forEachCommand(command, getCommands()) { +// command->onTrack(this, position); +// endFor; +// } +// +// if (_startedCommand) { +// _startedCommand->onUpdate(this, position, event->state()); +// } +// } +// if (_trackBox) { +// _trackBox->update(position); +// } +// } +//} +// +//void +//CellWidget::mouseReleaseEvent(QMouseEvent* event) +//{ +// if (_startedCommand && (_startedCommand->getButton() == event->button())) { +// Point position = getSnapPoint(event->x(), event->y()); +// if (getView()) { +// _startedCommand->onStop(this, position); +// _startedCommand = NULL; +// } +// if (_trackBox) { +// _trackBox->stop(position); +// } +// } +//} +// +//void +//CellWidget::focusInEvent(QFocusEvent* event) +//{ +// // overriden to avoid repaint when the widget gains the focus +//} +// +//void +//CellWidget::focusOutEvent(QFocusEvent* event) +//{ +// // overriden to avoid repaint when the widget loose the focus +//} + +void +CellWidget::paintEvent(QPaintEvent* event) +{ + invalidate(event->rect()); + + redraw(); } -H::Box CellWidget::getBox(const QRect& screenRect) const { - if (screenRect.isEmpty()) { - return H::Box(); + + +// ************************************************************************************************* +// CellWidget::onSetVisible() +// ************************************************************************************************* + +void +CellWidget::onSetVisible(Layer* layer, + bool visible) +{ +} + + + +// ************************************************************************************************* +// CellWidget:getClipCode() +// ************************************************************************************************* + +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; } - return H::Box(getX(screenRect.left()), - getY(screenRect.bottom()), - getX(screenRect.right()), - getY(screenRect.top())); -} - -int CellWidget::getScreenX(const Unit& x) const { - return screenDx + (int)rint(GetValue(x) * scale); -} - -int CellWidget::getScreenY(const Unit& y) const { - 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) { - clipBox = Box(area).inflate(getSize(2)); - - clipX[0] = GetValue(clipBox.getXMin()); - clipX[1] = GetValue(clipBox.getXMax()); - clipX[2] = GetValue(clipBox.getXMin()); - clipX[3] = GetValue(clipBox.getXMax()); - clipY[0] = GetValue(clipBox.getYMin()); - clipY[1] = GetValue(clipBox.getYMin()); - clipY[2] = GetValue(clipBox.getYMax()); - clipY[3] = GetValue(clipBox.getYMax()); -} - - -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 (clipX[3] < x) { - if (y < clipY[0]) { - return 25; - } - if (clipY[3] < y) { - return 19; - } - return 1; + if (y < _clipY[0]) { + return 8; } - if (y < clipY[0]) { - return 8; + if (_clipY[3] < y) { + return 2; } - 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 { + +// ************************************************************************************************* +// CellWidget::clipLine() +// CellWidget::clipLines() +// ************************************************************************************************* + +bool +CellWidget::clipLine(double& xo, + double& yo, + int co, + double& xe, + double& ye, + int ce, + int u) const +{ if (co & ce & -17) { - return false; + return false; } if (!co & !ce) { - return true; + 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); + 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); + 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); + 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); + 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); + 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); + 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); + 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); + 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; } +//bool +//CellWidget::clipLines(const Points& points, +// QPointArray& sPoints, +// unsigned& sCount, +// bool closed) const +//{ +// sCount = 0; +// +// if (points.isEmpty()) { +// return false; +// } +// +// int co, ce; +// double xo, yo, xe, ye; +// bool firstPoint = true; +// +// forEachPoint(point, points) { +// xe = GetValue(point.getX()); +// ye = GetValue(point.getY()); +// ce = getClipCode(xe, ye); +// if (firstPoint) { +// if (!ce) { +// int sx = getScreenX(GetUnit(xe)); +// int sy = getScreenY(GetUnit(ye)); +// sPoints.putPoints(sCount++, 1, sx, sy); +// } +// firstPoint = false; +// } +// else { +// static int tcc[] = {0,-3,-6,1,3,0,1,0,6,1,0,0,1,0,0,0}; +// static int cra[] = {-1,-1,-1,3,-1,-1,2,-1,-1,1,-1,-1,0,-1,-1,-1}; +// +// double xco = xo; +// double yco = yo; +// double xce = xe; +// double yce = ye; +// if (clipLine(xco, yco, co, xce, yce, ce)) { +// if (co) { +// int sx = getScreenX(GetUnit(xco)); +// int sy = getScreenY(GetUnit(yco)); +// sPoints.putPoints(sCount++, 1, sx, sy); +// } +// int sx = getScreenX(GetUnit(xce)); +// int sy = getScreenY(GetUnit(yce)); +// sPoints.putPoints(sCount++, 1, sx, sy); +// } +// else { +// if (ce & 16) { +// if (!(co & ce & ~16)) { +// int c; +// if (!(co & 16)) { +// c = ce + tcc[co]; +// } +// else { +// bool done = false; +// double xto = xo; +// double yto = yo; +// double xte = xe; +// double yte = ye; +// while (!done) { +// double x = (xto + xte) / 2; +// double y = (yto + yte) / 2; +// c = getClipCode(x, y); +// if (!(c & 16)) { +// if (c & ce) { +// c = ce + tcc[co & ~16]; +// } +// else { +// c = co + tcc[ce & ~16]; +// } +// done = true; +// } +// else { +// if (c == ce) { +// xte = x; +// yte = y; +// } +// else { +// if (c != co) { +// done = true; +// } +// else { +// xto = x; +// yto = y; +// } +// } +// } +// } +// } +// int sx = getScreenX(GetUnit(_clipX[cra[c&~16]])); +// int sy = getScreenY(GetUnit(_clipY[cra[c&~16]])); +// sPoints.putPoints(sCount++, 1, sx, sy); +// } +// } +// else { +// if (co & 16) { +// if (!(co & ce)) ce = co + tcc[ce]; +// } +// else { +// ce |= co; +// if (tcc[ce] == 1) ce |= 16; +// } +// } +// } +// if (ce & 16) { +// int sx = getScreenX(GetUnit(_clipX[cra[ce&~16]])); +// int sy = getScreenY(GetUnit(_clipY[cra[ce&~16]])); +// sPoints.putPoints(sCount++, 1, sx, sy); +// } +// } +// xo = xe; +// yo = ye; +// co = ce; +// endFor; +// } +// +// if (closed && sCount) { +// sPoints.putPoints(sCount++, 1, sPoints[0].x(), sPoints[0].y()); +// } +// +// return sCount; +//} +// -void CellWidget::setFont(const QFont& font) { - if (painter) { - painter->setFont(font); - } + +// ************************************************************************************************* +// CellWidget::_setStartedCommand() +// CellWidget::_setClipBox() +// ************************************************************************************************* + +//void +//CellWidget::_setStartedCommand(Command* command) +//{ +// _startedCommand = command; +//} + +void +CellWidget::_setClipBox(const Box& area) +{ + _clipBox = Box(area).inflate(getSize(2)); + + _clipX[0] = GetValue(_clipBox.getXMin()); + _clipX[1] = GetValue(_clipBox.getXMax()); + _clipX[2] = GetValue(_clipBox.getXMin()); + _clipX[3] = GetValue(_clipBox.getXMax()); + _clipY[0] = GetValue(_clipBox.getYMin()); + _clipY[1] = GetValue(_clipBox.getYMin()); + _clipY[2] = GetValue(_clipBox.getYMax()); + _clipY[3] = GetValue(_clipBox.getYMax()); } -void CellWidget::setPen(const QPen& pen, double brightness) { - if (!((0.1 <= brightness) && (brightness <= 1.0))) { - throw Error(__FILE__, __LINE__); - } - if (painter) { - if (pen == Qt::NoPen) { - painter->setPen(pen); - } else { - QPen correctedPen = pen; - if (brightness < 1) { - QColor bgColor = getBackgroundColor(); - int r = bgColor.red(); - int g = bgColor.green(); - int b = bgColor.blue(); +// ************************************************************************************************* +// CellWidget::_redraw() +// ************************************************************************************************* - QColor color = pen.color(); - r = r + (int)((color.red() - r) * brightness); - g = g + (int)((color.green() - g) * brightness); - b = b + (int)((color.blue() - b) * brightness); +void +CellWidget::_redraw() +{ + if (!_invalidRegion.isEmpty()) { + QRect invalidRect = _invalidRegion.boundingRect(); - correctedPen = QPen(QColor(r, g, b)); - } - painter->setPen(correctedPen); + if (_doubleBuffering) { + _invalidRegion = invalidRect; + } + + Box area = getBox(invalidRect).inflate(getSize(1)); + + _setClipBox(area); + + QPaintDevice* device = this; + + if (_doubleBuffering) { + //device = _getPixmap(); + } + + QPainter painter(device); + QPainter* oldPainter = _painter; + _painter = &painter; + + QRegion deepRegion; + for (list::iterator plit = _peekList.begin(); + plit != _peekList.end(); + ++plit) { + deepRegion = deepRegion.unite(QRegion(getScreenRect(*plit))); } +// forEachBox(peek, _peekList) { +// deepRegion = deepRegion.unite(QRegion(getScreenRect(peek))); +// endFor; +// } + deepRegion = deepRegion.intersect(_invalidRegion); + Box deepArea = getBox(deepRegion.boundingRect()); + + _painter->setClipRegion(_invalidRegion); + + _painter->fillRect(invalidRect, QBrush(getBackgroundColor())); + + preRedraw(area); + + QRegion region = _invalidRegion.subtract(deepRegion); + + Cell* cell = getCell(); + if (cell) { + + + _painter->save(); + + + double brightness = 1.0; + //if (highlightionIsVisible() && !getHighlightion().isEmpty()) { + // brightness = 0.4; + //} + + setPen(boundariesPen, brightness); + setBrush(boundariesBrush, brightness); + //drawBoundaries(cell, area, Transformation()); + + + for_each_basic_layer(layer, getVisibleLayers()) { + if (isDrawable(layer)) { + //setFont(getFont(layer)); + //setPen(layer->getPen(), brightness); + setPen(getPen(layer), brightness); + //setBrush(layer->getBrush(), brightness); + setBrush(getBrush(layer), brightness); + //setBrushOrigin(layer->getBrushOrigin()); + if (deepRegion.isEmpty()) { + drawContent(cell, layer, area, Transformation()); + // view->_draw(this, layer, area, Transformation()); + } else { + _painter->setClipRegion(region); + drawContent(cell, layer, area, Transformation()); + //view->_draw(this, layer, area, Transformation()); + _painter->setClipRegion(deepRegion); + unsigned displayDepth = _displayDepth; + _displayDepth = (unsigned)-1; + //view->_draw(this, layer, deepArea, Transformation()); + drawContent(cell, layer, deepArea, Transformation()); + _displayDepth = displayDepth; + _painter->setClipRegion(_invalidRegion); + } + //_painter->flush(); + } + end_for; + } +// if (highlightionIsVisible() && !getHighlightion().isEmpty()) { +// Technology* technology = getDatabase()->getTechnology(); +// if (technology) { +// forEachLayer(layer, technology->getLayers()) { +// if (isDrawable(layer)) { +// setFont(layer->getFont()); +// setPen(layer->getPen()); +// setBrush(layer->getBrush()); +// setBrushOrigin(layer->getBrushOrigin()); +// forEachOccurrence(occurrence, getHighlightion()) { +// Figure* figure = dynamic_cast(occurrence.getEntity()); +// if (figure && +// figure->isMaterialized() && +// (figure->getLayerMask() & layer->getMask())) { +// Box boundingBox = occurrence.getBoundingBox(); +// if (boundingBox.overlaps(area)) { +// Transformation transformation = +// occurrence.getPath().getTransformation(); +// Box correctedArea = +// transformation.getInverted().getBox(area); +// figure->_draw(this, layer, correctedArea, transformation); +// } +// } +// endFor; +// } +// _painter->flush(); +// } +// endFor; +// } +// } +// } +// if (selectionIsVisible()) { +// QColor selectionColor = getSelectionColor(); +// setPen(selectionColor); +// setBrush(QBrush(selectionColor, Dense4Pattern)); +// setBrushOrigin(QPoint(0, 0)); +// forEachOccurrence(occurrence, getSelection()) { +// Figure* figure = dynamic_cast(occurrence.getEntity()); +// if (figure) { +// Box boundingBox = occurrence.getBoundingBox(); +// if (boundingBox.overlaps(area)) { +// figure->_highlight(this, occurrence.getPath().getTransformation()); +// } +// } +// endFor; +// } +// } + _painter->restore(); + if (gridIsVisible() && gridIsDrawable()) { + Unit xMin = getGridX(getX(0)); + Unit yMin = getGridY(getY(height())); + Unit xMax = getGridX(getX(width())); + Unit yMax = getGridY(getY(0)); + setPen(getGridColor()); + for (Unit x = xMin; x <= xMax; x += _gridXStep) { + int sx = getScreenX(x); + if (_gridAxesAreVisible && (x == getGridOrigin().getX())) { + //_painter->moveTo(sx, 0); + //_painter->lineTo(sx, height()); + _painter->drawLine(sx, 0, sx, height()); + } + for (Unit y = yMin; y <= yMax; y += _gridYStep) { + int sy = getScreenY(y); + if (_gridAxesAreVisible && (y == getGridOrigin().getY())) { + //_painter->moveTo(0, sy); + //_painter->lineTo(width(), sy); + _painter->drawLine(0, sy, width(), sy); + } + if (!(isOnGridX(x, 10) && isOnGridY(y, 10))) { + _painter->drawPoint(sx, sy); + } + else { + //_painter->moveTo(sx - 2, sy); + //_painter->lineTo(sx + 2, sy); + _painter->drawLine(sx - 2, sy, sx + 2, sy); + //_painter->moveTo(sx, sy - 2); + //_painter->lineTo(sx, sy + 2); + _painter->drawLine(sx, sy - 2, sx, sy + 2); + } + } + } + } + } + + postRedraw(area); + + if (device != this) { + int x = invalidRect.x(); + int y = invalidRect.y(); + int w = invalidRect.width(); + int h = invalidRect.height(); + //bitBlt(this, x, y, device, x, y, w, h, CopyROP, true); + } + + _setClipBox(getBox(rect())); + + _painter = oldPainter; + + _invalidRegion = QRegion(); } } -void CellWidget::setBrush(const QBrush& brush, double brightness) { - if (!((0.1 <= brightness) && (brightness <= 1.0))) { - throw Error(__FILE__, __LINE__); - } - - if (painter) { - if (brush == Qt::NoBrush) { - painter->setBrush(brush); - } else { - QBrush correctedBrush = brush; - - if (brightness < 1) { - QColor bgColor = getBackgroundColor(); - int r = bgColor.red(); - int g = bgColor.green(); - int b = bgColor.blue(); - - QColor color = brush.color(); - r = r + (int)((color.red() - r) * brightness); - g = g + (int)((color.green() - g) * brightness); - b = b + (int)((color.blue() - b) * brightness); - - correctedBrush = QBrush(QColor(r, g, b), brush.style()); - } - painter->setBrush(correctedBrush); - } - } -} - -void CellWidget::setBrushOrigin(const QPoint& origin) { - if (painter) { - painter->setBrushOrigin(brushDx + origin.x(), brushDy + origin.y()); - } -} - -bool CellWidget::isDrawable(BasicLayer* layer) const { - return (layer->GetDisplayThreshold() <= scale); -} -double CellWidget::getScale() const { - return scale; -} +// ************************************************************************************************* +// CellWidget::_callDrawOf() +// ************************************************************************************************* + +//void +//CellWidget::_callDrawOf(Command* command) +//{ +// assert(command); +// assert(command->isInstalledOn(this)); +// +// if (getView()) { +// QPainter painter(this); +// +// _painter = &painter; +// +// _painter->setRasterOp(XorROP); +// _painter->setPen(getForegroundColor()); +// _painter->setBrush(NoBrush); +// +// command->onDraw(this); +// } +//} +// + + +// ************************************************************************************************* +// CellWidget::_insertCommand() +// CellWidget::_removeCommand() +// ************************************************************************************************* + +//void +//CellWidget::_insertCommand(Command* command) +//{ +// _commandMap[command->getButton()] = command; +//} +// +//void +//CellWidget::_removeCommand(Command* command) +//{ +// _commandMap.erase(command->getButton()); +//} +// +// +// +//// ************************************************************************************************* +//// CellWidget::_insertSelector() +//// CellWidget::_removeSelector() +//// ************************************************************************************************* +// +//void +//CellWidget::_insertSelector(Selector* selector) +//{ +// _selectorSet.insert(selector); +//} +// +//void +//CellWidget::_removeSelector(Selector* selector) +//{ +// _selectorSet.erase(selector); +//} +// +// +// +//// ************************************************************************************************* +//// CellWidget::_insertHighlightor() +//// CellWidget::_removeHighlightor() +//// ************************************************************************************************* +// +//void +//CellWidget::_insertHighlightor(Highlightor* highlightor) +//{ +// _highlightorSet.insert(highlightor); +//} +// +//void +//CellWidget::_removeHighlightor(Highlightor* highlightor) +//{ +// _highlightorSet.erase(highlightor); +//} +// + + +//CLOSE_MY_NAMESPACE + +// ************************************************************************************************* +// ************************************************************************************************* diff --git a/hurricane/src/viewer/CellWidget.h b/hurricane/src/viewer/CellWidget.h index 3db5ece7..e6a9b4da 100644 --- a/hurricane/src/viewer/CellWidget.h +++ b/hurricane/src/viewer/CellWidget.h @@ -1,84 +1,1641 @@ -#ifndef __CELL_WIDGET_H -#define __CELL_WIDGET_H +// ************************************************************************************************* +// ************************************************************************************************* +// File: CellWidget.h +// ************************************************************************************************* +// ************************************************************************************************* + +#ifndef H_CellWidget +#define H_CellWidget #include -#include #include "Box.h" -#include "Cell.h" +//#include "Commands.h" +#include "Slice.h" +#include "Segment.h" +#include "Contact.h" +#include "Layers.h" +#include "BasicLayer.h" +#include "Occurrences.h" +#include "Points.h" using namespace H; +//#include "Selectors.h" + +//OPEN_MY_NAMESPACE + +//class View; +//class TrackBox; -class CellWidget : public QWidget { - Q_OBJECT +// ************************************************************************************************* +// CellWidget +// ************************************************************************************************* - public: - CellWidget(Cell* cell, QWidget* parent=0); - double getScale() const; - void redraw(); - void reframe(double scale); - void reframe(const Point& c, double sc); - protected: - void paintEvent(QPaintEvent* event); - private: - Cell* cell; - QRegion invalidRegion; - Box clipBox; - double clipX[4]; - double clipY[4]; - QPainter* painter; - QColor backgroundColor; - QColor foregroundColor; - Point center; - double scale; - int screenDx; - int screenDy; - int brushDx; - int brushDy; - map basicLayersBrush; - map basicLayersPen; +class /* Q_EXPORT */ CellWidget : public QWidget { - void fitToContent(unsigned screenMargin = 5); - void scroll(const Unit& dx, const Unit& dy); + Q_OBJECT + + public: + ~CellWidget(); + + Cell* getCell() const; + //View* getView() const ; + const Point& getCenter() const; + double getScale() const; + Unit getX(int screenX) const; + Unit getY(int screenY) const; + Unit getSize(int screenSize) const; + Point getPoint(const QPoint& screenPoint) const; + Box getBox(const QRect& screenRect) const; + int getScreenX(const Unit& x) const; + int getScreenY(const Unit& y) const; + int getScreenSize(const Unit& size) const; + QPoint getScreenPoint(const Point& point) const; + QRect getScreenRect(const Box& box) const; + Point getSnapPoint(const Point& point) const; + Point getSnapPoint(int screenX, int screenY) const; + const QColor& getBackgroundColor() const; + const QColor& getForegroundColor() const; + const Layer::Mask& getVisibleLayerMask() const; + BasicLayers getVisibleLayers() const; + //Command* getCommand(int button) const; + //Command* getStartedCommand() const; + //Commands getCommands() const; + const Point& getGridOrigin() const; + const Unit& getGridXStep() const; + const Unit& getGridYStep() const; + unsigned getGridDisplayThreshold() const; + const QColor& getGridColor() const; + Unit getGridX(const Unit& x, + int sign = 0) const; + Unit getGridY(const Unit& y, + int sign = 0) const; + Point getGridPoint(const Point& point, + int xSign = 0, + int ySign = 0) const; + unsigned getDisplayDepth() const; + unsigned getDisplaySize() const; + Occurrences getSelection() const; + Box getSelectionBox() const; + unsigned getSelectionLimit() const; + const QColor& getSelectionColor() const; + Occurrences getHighlightion() const; + Box getHighlightionBox() const; + unsigned getHighlightionLimit() const; + const QFont& getFont(); + const QPen& getPen(); + const QPen& getPen(const BasicLayer* layer); + const QBrush& getBrush(); + const QBrush& getBrush(BasicLayer* layer); + const QPoint getBrushOrigin(); + //TrackBox* getTrackBox() const; + + bool doubleBuffering() const; + bool automaticScrolling() const; + bool isVisible(BasicLayer* layer) const; + bool isDrawable(BasicLayer* layer) const; + bool gridIsVisible() const; + bool gridAxesAreVisible() const; + bool gridIsDrawable() const; + bool isOnGridX(const Unit& x, + unsigned n = 1) const; + bool isOnGridY(const Unit& y, + unsigned n = 1) const; + bool isOnGridPoint(const Point& point, + unsigned xN = 1, + unsigned yN = 1) const; + bool snapGrid() const; + bool selectionIsVisible() const; + bool isSelected(const Occurrence& occurrence) const; + bool isSelectable(const Occurrence& occurrence) const; + bool highlightionIsVisible() const; + bool isHighlighted(const Occurrence& occurrence) const; + bool isHighlightable(const Occurrence& occurrence) const; + + void setBackgroundColor(const QColor& color); + void setForegroundColor(const QColor& color); + void setDoubleBuffering(bool enable); + void setAutomaticScrolling(bool enable); + void setVisible(BasicLayer* layer, + bool visible); + void setGridOrigin(const Point& origin); + void setGridXStep(const Unit& step); + void setGridYStep(const Unit& step); + void setGridStep(const Unit& step); + void setGridSteps(const Unit& xStep, + const Unit& yStep); + void setGridDisplayThreshold(unsigned threshold); + void setGridColor(const QColor& color); + void setGridVisible(bool visible); + void setGridAxesVisible(bool visible); + void setSnapGrid(bool enable); + void setDisplayDepth(unsigned displayDepth); + void setDisplaySize(unsigned displaySize); + void setSelectionLimit(unsigned limit); + void setSelectionColor(const QColor& color); + void setSelectionVisible(bool visible); + void setHighlightionLimit(unsigned limit); + void setHighlightionVisible(bool visible); + void setFont(const QFont& font); + void setPen(const QPen& pen, + double brightness = 1.0); + void setBrush(const QBrush& brush, + double brightness = 1.0); + void setBrushOrigin(const QPoint& origin); + //void setTrackBox(TrackBox* trackBox); + + void showAllLayers(); + void hideAllLayers(); + bool select(const Occurrence& occurrence); + void unselect(const Occurrence& occurrence); + //void clearSelection(); + //bool highlight(const Occurrence& occurrence); + //void unhighlight(const Occurrence& occurrence); + //void clearHighlightion(); + void clearPeeks(); + void addPeek(const Box& box); + + void invalidate(); + void invalidate(const QRect& screenRect); + void invalidate(const Box& box); + void fitToContent(unsigned screenMargin = 5) ; + void reframe(double scale); + void reframe(const Point& center); + void reframe(const Point& center, + double scale); + void reframe(const Box& box); + void scroll(const Unit& dx, + const Unit& dy); + void redraw(); + void abortStartedCommand(); + + + void drawContent(const Cell* cell, const BasicLayer* basicLayer, const H::Box& updateArea, const Transformation& transformation) const; + void drawContent(const Instance* instance, const BasicLayer* basicLayer, const H::Box& updateArea, const Transformation& transformation) const; + void drawSlice(const Slice* slice, const BasicLayer* basicLayer, const H::Box& updateArea, const Transformation& transformation) const; + void drawPhantoms(const Cell* cell, const Box& updateArea, const Transformation& transformation) const; + void drawPhantoms(const Instance* instance, const Box& updateArea, const Transformation& transformation) const; + void drawBoundaries(const Cell* cell, const Box& updateArea, const Transformation& transformation) const; + void drawBoundaries(const Instance* instance, const Box& updateArea, const Transformation& transformation) const; + void drawGo(const Go* go, 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 drawLine(const Unit& xo, + const Unit& yo, + const Unit& xe, + const Unit& ye) const; + void drawLine(const Point& origin, + const Point& extremity) const; + void drawPolyline(const Points& points); + + void drawRectangle(const Unit& xMin, + const Unit& yMin, + const Unit& xMax, + const Unit& yMax) const; + void drawRectangle(const Box& box) const; + void drawPolygon(const Points& points); + //void drawText(const Box& frame, + // const string& text, + // const Direction& direction); + //void drawText(const Box& frame, +// const Name& name, +// const Direction& direction); +#ifndef DOXYGEN + public: + typedef QWidget Inherit; + + //Label getLabel() const; + Record* getRecord() const; + Slot* getSlot(const string& name) const; + Box getWorld() const; + //Selectors getSelectors() const; + //Highlightors getHighlightors() const; + + bool hasRecord() const; + bool allowAutomaticScrolling() const; + + void reframe(); + + void preRedraw(const Box& area); + void postRedraw(const Box& area); + + void drawSnapPoint(); + + CellWidget(Cell* cell, + QWidget* parent = NULL, + const char* name = NULL); + + protected: + + void resizeEvent(QResizeEvent* event); + //void enterEvent(QEvent* event); + //void leaveEvent(QEvent* event); + //void mousePressEvent(QMouseEvent* event); + //void mouseMoveEvent(QMouseEvent* event); + //void mouseReleaseEvent(QMouseEvent* event); + //void focusInEvent(QFocusEvent* event); + //void focusOutEvent(QFocusEvent* event); + void paintEvent(QPaintEvent* event); + + void onSetVisible(Layer* layer, + bool visible); + + private: + CellWidget(const CellWidget& porthole); + // not implemented to forbid copy + + CellWidget& operator=(const CellWidget& porthole); + // not implemented to forbid assignment + + 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; +// bool clipLines(const Points& points, +// QPointArray& sPoints, +// unsigned& sCount, +// bool closed = false) const; +// +// typedef map CommandMap; +// typedef set SelectorSet; +// typedef set HighlightorSet; + typedef list PeekList; + + Cell* _cell; + Point _center; + double _scale; + int _screenDx; + int _screenDy; + int _brushDx; + int _brushDy; + bool _alreadyExposed; + QRegion _invalidRegion; + Box _clipBox; + double _clipX[4]; + double _clipY[4]; + QPainter* _painter; + QColor _backgroundColor; + QColor _foregroundColor; + bool _doubleBuffering; + bool _automaticScrolling; + Layer::Mask _visibleLayerMask; + //CommandMap _commandMap; + //Command* _startedCommand; + Point _gridOrigin; + Unit _gridXStep; + Unit _gridYStep; + bool _gridIsVisible; + bool _gridAxesAreVisible; + unsigned _gridDisplayThreshold; + QColor _gridColor; + bool _snapGrid; + bool _drawSnapPoint; + Point _snapPoint; + unsigned _displayDepth; + unsigned _displaySize; + //SelectorSet _selectorSet; + unsigned _selectionLimit; + QColor _selectionColor; + bool _selectionIsVisible; + //HighlightorSet _highlightorSet; + unsigned _highlightionLimit; + bool _highlightionIsVisible; + //static QPointArray _sPoints; + //TrackBox* _trackBox; + PeekList _peekList; + map _basicLayersBrush; + map _basicLayersPen; + + protected: + //restricted: + //QPixmap* _getPixmap() const ; + + //void _setStartedCommand(Command* command); + //void _setTrackBox(TrackBox* trackBox); + void _setClipBox(const Box& area); + + void _redraw(); + //void _callDrawOf(Command* command); + + // void _insertCommand(Command* command); + // void _removeCommand(Command* command); + // void _insertSelector(Selector* selector); + // void _removeSelector(Selector* selector); + // void _insertHighlightor(Highlightor* highlightor); + // void _removeHighlightor(Highlightor* highlightor); +#endif // DOXYGEN - void drawContent(const Cell* cell, const BasicLayer* basicLayer, const H::Box& updateArea, const Transformation& transformation) const; - void drawContent(const Instance* instance, const BasicLayer* basicLayer, const H::Box& updateArea, const Transformation& transformation) const; - void drawSlice(const Slice* slice, const BasicLayer* basicLayer, const H::Box& updateArea, const Transformation& transformation) const; - void drawPhantoms(const Cell* cell, const Box& updateArea, const Transformation& transformation) const; - void drawPhantoms(const Instance* instance, const Box& updateArea, const Transformation& transformation) const; - void drawBoundaries(const Cell* cell, const Box& updateArea, const Transformation& transformation) const; - void drawBoundaries(const Instance* instance, const Box& updateArea, const Transformation& transformation) const; - void drawGo(const Go* go, 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 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 getY(int screenY) const; - Unit getSize(int screenSize) const; - H::Box getBox(const QRect& screenRect) const; - int getScreenX(const Unit& x) const; - int getScreenY(const Unit& y) const; - int getScreenSize(const Unit& size) const; - void invalidate(); - void invalidate(const QRect& screenRect); - 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 setPen(const QPen& pen, double brightness = 1.0); - void setBrush(const QBrush& brush, double brightness = 1.0); - void setBrushOrigin(const QPoint& origin); - const QColor& getBackgroundColor() const; - bool isDrawable(BasicLayer* layer) const; }; -inline const QColor& CellWidget::getBackgroundColor() const { - return backgroundColor; +// ************************************************************************************************* +// getLabel() +// getRecord() +// getSlot() +// ************************************************************************************************* + +#ifndef DOXYGEN +//inline +//Label +//getLabel(const CellWidget& porthole) +//{ +// return porthole.getLabel(); +//} +// +//inline +//Label +//getLabel(const CellWidget* porthole) +//{ +// return (!porthole) ? Label("nil") : porthole->getLabel(); +//} +// +//inline +//Record* +//getRecord(const CellWidget& porthole) +//{ +// return porthole.getRecord(); +//} +// +//inline +//Record* +//getRecord(const CellWidget* porthole) +//{ +// return (!porthole) ? NULL : porthole->getRecord(); +//} +// +//inline +//Slot* +//getSlot(const string& name, +// const CellWidget& porthole) +//{ +// return porthole.getSlot(name); +//} +// +//inline +//Slot* +//getSlot(const string& name, +// const CellWidget* porthole) +//{ +// return (!porthole) ? getSlot(name, getLabel("nil")) : porthole->getSlot(name); +//} +#endif // DOXYGEN + + + +// ************************************************************************************************* +// hasRecord() +// ************************************************************************************************* + +#ifndef DOXYGEN +//inline +//bool +//hasRecord(const CellWidget& porthole) +//{ +// return porthole.hasRecord(); +//} +// +//inline +//bool +//hasRecord(const CellWidget* porthole) +//{ +// return (!porthole) ? false : porthole->hasRecord(); +//} +#endif // DOXYGEN + + + +// ************************************************************************************************* +// operator<<() +// ************************************************************************************************* + +#ifndef DOXYGEN +//inline +//ostream& +//operator<<(ostream& stream, +// const CellWidget& porthole) +//{ +// return stream << porthole.getLabel(); +//} +// +//inline +//ostream& +//operator<<(ostream& stream, +// const CellWidget* porthole) +//{ +// return (!porthole) ? (stream << "nil") : (stream << "&" << porthole->getLabel()); +//} +#endif // DOXYGEN + + + +// ************************************************************************************************* +// CellWidget::getBackgroundColor() +// CellWidget::getForegroundColor() +// CellWidget::getStartedCommand() +// CellWidget::getGridOrigin() +// CellWidget::getGridXStep() +// CellWidget::getGridYStep() +// CellWidget::getGridDisplayThreshold() +// CellWidget::getGridColor() +// CellWidget::getDisplayDepth() +// CellWidget::getDisplaySize() +// CellWidget::getSelectionColor() +// CellWidget::getSelectionLimit() +// CellWidget::getHighlightionLimit() +// CellWidget::getTrackBox() +// ************************************************************************************************* + +inline +const QColor& +CellWidget::getBackgroundColor() const +{ + return _backgroundColor; +} + +inline +const QColor& +CellWidget::getForegroundColor() const +{ + return _foregroundColor; +} + +inline +const Layer::Mask& +CellWidget::getVisibleLayerMask() const +{ + return _visibleLayerMask; +} + +// +//inline +//Command* +//CellWidget::getStartedCommand() const +//{ +// return _startedCommand; +//} + +inline +const Point& +CellWidget::getGridOrigin() const +{ + return _gridOrigin; +} + +inline +const Unit& +CellWidget::getGridXStep() const +{ + return _gridXStep; +} + +inline +const Unit& +CellWidget::getGridYStep() const +{ + return _gridYStep; +} + +inline +unsigned +CellWidget::getGridDisplayThreshold() const +{ + return _gridDisplayThreshold; +} + +inline +const QColor& +CellWidget::getGridColor() const +{ + return _gridColor; +} + +inline +unsigned +CellWidget::getDisplayDepth() const +{ + return _displayDepth; +} + +inline +unsigned +CellWidget::getDisplaySize() const +{ + return _displaySize; +} + +inline +const QColor& +CellWidget::getSelectionColor() const +{ + return _selectionColor; +} + +inline +unsigned +CellWidget::getSelectionLimit() const +{ + return _selectionLimit; +} + +inline +unsigned +CellWidget::getHighlightionLimit() const +{ + return _highlightionLimit; +} + +//inline +//TrackBox* +//CellWidget::getTrackBox() const +//{ +// return _trackBox; +//} + + + +// ************************************************************************************************* +// CellWidget::doubleBuffering() +// CellWidget::automaticScrolling() +// CellWidget::gridIsVisible() +// CellWidget::gridAxesAreVisible() +// CellWidget::gridIsDrawable() +// CellWidget::snapGrid() +// CellWidget::selectionIsVisible() +// CellWidget::highlightionIsVisible() +// ************************************************************************************************* + +inline +bool +CellWidget::doubleBuffering() const +{ + return _doubleBuffering; +} + +inline +bool +CellWidget::automaticScrolling() const +{ + return _automaticScrolling; +} + +inline +bool +CellWidget::gridIsVisible() const +{ + return _gridIsVisible; +} + +inline +bool +CellWidget::gridAxesAreVisible() const +{ + return _gridAxesAreVisible; +} + +inline +bool +CellWidget::gridIsDrawable() const +{ + return ((int)_gridDisplayThreshold < getScreenSize(min(_gridXStep, _gridYStep))); +} + +inline +bool +CellWidget::snapGrid() const +{ + return _snapGrid; +} + +inline +bool +CellWidget::selectionIsVisible() const +{ + return _selectionIsVisible; +} + +inline +bool +CellWidget::highlightionIsVisible() const +{ + return _highlightionIsVisible; } -#endif /* __CELL_WIDGET_H */ + +// ************************************************************************************************* +// CellWidget::setDoubleBuffering() +// CellWidget::setSelectionLimit() +// CellWidget::setHighlightionLimit() +// ************************************************************************************************* + +inline +void +CellWidget::setDoubleBuffering(bool enable) +{ + _doubleBuffering = enable; +} + +inline +void +CellWidget::setSelectionLimit(unsigned limit) +{ + _selectionLimit = limit; +} + +inline +void +CellWidget::setHighlightionLimit(unsigned limit) +{ + _highlightionLimit = limit; +} + + + +// ************************************************************************************************* +// CellWidget::drawLine() +// CellWidget::drawRectangle() +// CellWidget::drawText() +// ************************************************************************************************* + +inline +void +CellWidget::drawLine(const Point& origin, + const Point& extremity) const +{ + drawLine(origin.getX(), origin.getY(), extremity.getX(), extremity.getY()); +} + +inline +void +CellWidget::drawRectangle(const Unit& xMin, + const Unit& yMin, + const Unit& xMax, + const Unit& yMax) const +{ + drawRectangle(Box(xMin, yMin, xMax, yMax)); +} + +//inline +//void +//CellWidget::drawText(const Box& frame, +// const Name& name, +// const Direction& direction) +//{ +// drawText(frame, name.getString(), direction); +//} + + + +// ************************************************************************************************* +// CellWidget::_setTrackBox() +// ************************************************************************************************* + +//#ifndef DOXYGEN +//inline +//void +//CellWidget::_setTrackBox(TrackBox* trackBox) +//{ +// _trackBox = trackBox; +//} +//#endif // DOXYGEN +// + + +// ************************************************************************************************* +// File documentation +// ************************************************************************************************* + +/*!\file + \brief This file contains the definition of the CellWidget class. + \paragraph Concept of CellWidget: + \nn A porthole is a Qt widget used to display a cell view. + \nn When a porthole is bound to a given cell view the content of this cell view is + displayed according to some porthole characteristics (zoom factor, grid, visible + layers, selection, highlightion, ...). + \nn The display reflects exactly the current state of the cell view (there isn't a + parallel display list). + \nn A porthole can display one and only one cell view, but a cell view can be displayed + simultaneously in multiple portholes. The fact that each porthole has its own + characteristics provides the capability to show different aspects of the same cell + view within separated portholes. + \paragraph Concept of MainCellWidget: + \nn The MainCellWidget class implements the concept of main porthole. + \nn The porthole class being an abstract class, to display a cell view you should create + a main porthole (or a specialization) and insert this widget in your graphic + interface (as all other widgets). + \nn Furthermore, you can attach to each main porthole a map porthole used to visualize + which part of the cell view is currently drawn in the main porthole and, can attach + a palette used to control the visibility of each layer and you can also two main + scroll bars. + \paragraph Concept of MapCellWidget: + \nn The MapCellWidget class implements the concept of map porthole. + \nn A map porthole is used to visualize which part of the cell view is currently + displayed by a main porthole. + \see View, MainCellWidget, MapCellWidget, Palette or Command. + \author \remye + */ + + + +// ************************************************************************************************* +// CellWidget documentation +// ************************************************************************************************* + +/*!\class CellWidget + \brief This abstract class introduces the concept of porthole + \concept A porthole is a Qt widget used to display a cell view. + \nn When a porthole is bound to a given cell view the content of this cell view is + displayed according to some porthole characteristics (zoom factor, grid, visible + layers, selection, highlightion, ...) as we will discover in the following. + \nn The display reflects exactly the current state of the cell view (there isn't a + parallel display list). + \nn A porthole can display one and only one cell view, but a cell view can be displayed + simultaneously in multiple portholes. The fact that each porthole has its own + characteristics provides the capability to show different aspects of the same cell + view within separated portholes. + \paragraph Specialization: + \nn The database provides two kind of portholes: the MainCellWidget which is used to + display the totality or some part of a cell view; and the MapCellWidget which is + associated to a main porthole to show which part of the cell view is currently + displayed in this main porthole. + \nn Note that, if you need to create a new kind of porthole you should inherit of one + of those types and not directly of the base class. + \paragraph Selection: + \nn Each porthole manages a collection of selected occurrences. The selection being + managed by portholes and not by cell views it's possible to have differents + selections for differents portholes bound to the same cell view. + \nn The selection is managed with the help of occurrence properties which is a very + secure mechanism. So, when an occurrence is no longer valid, this occurrence is + automaticaly unselected from each porthole it was selected in. + \paragraph Highlightion: + \nn Each porthole manages a collection of highlighted occurrences. The highlightion + being managed by portholes and not by cell views it's possible to have differents + highlightions for differents portholes bound to the same cell view. + \nn The highlightion is managed with the help of occurrence properties which is a very + secure mechanism. So, when an occurrence is no longer valid, this occurrence is + automaticaly unhighlighted from each porthole it was highlighted in. + \paragraph Commands: + \nn The database provides some command facilities. A command is an object which models + the behaviour to be obtained in reaction to mouse events within a porthole. + \nn Furthermore, coordinates which are manipulated by commands are cell view + coordinates and not screen coordinates (the translation being done by the porthole). + \nn %Commands are very powerfull objects which make the task more easier by managing + automaticaly important features of portholes like double buffering, automatic + scrolling, synchronization of the xor more when drawing ghost shapes... + \paragraph Palette: + \nn A palette can be used to control the visibility of the layers in a given main + porthole. + \paragraph Main scroll bars: + \nn You can also attach to each main porthole an horizontal and/or a vertical scroll + bar. + \paragraph Updates: + \nn A lot of functions provided by this class change the characteristics of the display. + \nn So, to avoid useless intermediate drawings or screen flickerings those functions + don't update the display immediately but post some invalidation regions which are + cumulated until a real request of redraw is asked. + \nn Furthermore, when a redraw is asked, something is done only when the invalidated + region isn't empty. + \paragraph Drawing: + \nn The CellWidget class provides some convenience functions to draw shapes which are + defined in cell view coordinates (and not in screen ones) according to the center, + scale and clipping region. + \nn So, no need to manage screen transformations, clipping or something like that. No + need to manage colors, pens, brushes or something else because all is controled by + the porthole which know when it is drawing a given layer or when it is drawing a + command ghost (in xor mode). + \paragraph Usage: + \nn The following piece of code illustrate the manner to build a very simple graphical + interface using a main porthole, a map porthole, two main scroll bars and a palette. + Furthermore, some commands are installed in the different portholes. The returned + editor being a widget it can be embedded in another parent widget which can add, for + example, a menu bar, a status bar or some additionnal decorations... + \code + * QWidget* getEditor(View* view) + * { + * QHBox* editor = new QHBox(); + * + * QFrame* mainFrame = new QFrame(editor); + * mainFrame->setFrameStyle(QFrame::Panel | QFrame::Sunken); + * mainFrame->setLineWidth(2); + * mainFrame->setMinimumSize(120, 120); + * editor->setStretchFactor(mainFrame, 1); + * + * QGridLayout* mainLayout = new QGridLayout(mainFrame, 2, 2); + * mainLayout->setMargin(2); + * + * MainCellWidget* mainCellWidget = new MainCellWidget(mainFrame); + * mainLayout->addWidget(mainCellWidget, 0, 0); + * + * MainScrollBar* hScrollBar = new MainScrollBar(mainFrame); + * hScrollBar->setOrientation(Qt::Horizontal); + * mainLayout->addWidget(hScrollBar, 1, 0); + * + * MainScrollBar* vScrollBar = new MainScrollBar(mainFrame); + * vScrollBar->setOrientation(Qt::Vertical); + * mainLayout->addWidget(vScrollBar, 0, 1); + * + * QVBox* vBox = new QVBox(editor); + * editor->setStretchFactor(vBox, 0); + * vBox->setMinimumWidth(120); + * vBox->setMaximumWidth(120); + * vBox->setSpacing(5); + * + * QFrame* mapFrame = new QFrame(vBox); + * mapFrame->setFrameStyle(QFrame::Panel | QFrame::Sunken); + * mapFrame->setLineWidth(2); + * mapFrame->setMinimumSize(120, 120); + * mapFrame->setMaximumSize(120, 120); + * + * QGridLayout* mapLayout = new QGridLayout(mapFrame, 1, 1); + * mapLayout->setMargin(2); + * + * MapCellWidget* mapCellWidget = new MapCellWidget(mapFrame); + * mapLayout->addWidget(mapCellWidget, 0, 0); + * + * Palette* palette = new Palette(vBox); + * + * mainCellWidget->setView(view); + * mainCellWidget->setMapCellWidget(mapCellWidget); + * mainCellWidget->setPalette(palette); + * mainCellWidget->setHScrollBar(hScrollBar); + * mainCellWidget->setVScrollBar(vScrollBar); + * + * mapCellWidget->hideAllLayers(); + * Layer* phantom = getDatabase()->getTechnology()->getLayer("PHANTOM"); + * if (phantom) { + * mapCellWidget->setVisible(phantom, true); + * } + * + * getZoomCommand().installOn(mainCellWidget); + * getSelectCommand().installOn(mainCellWidget); + * getPanCommand().installOn(mainCellWidget); + * + * getZoomCommand().installOn(mapCellWidget); + * getPanCommand().installOn(mapCellWidget); + * + * editor->resize(700, 500); + * editor->setMargin(5); + * editor->setSpacing(5); + * editor->show(); + * + * return editor; + * } + \endcode + \nn + \see View, MainCellWidget, MapCellWidget, MainScrollBar, Palette or Command. + \author \remye + */ + +/*!\function CellWidget::~CellWidget() + \behaviour This is the destructor. + */ + +//@{ +/*!\function View* CellWidget::getView() const + \behaviour This function returns the view displayed in this porthole. + */ + +/*!\function const Point& CellWidget::getCenter() const + \behaviour This function returns the center of this porthole. + \nn This center is in fact the point of the cell view which is located on the center of + this porthole. + \note Returns the point \c [0,0] if the porthole isn't bound to a cell view. + */ + +/*!\function double CellWidget::getScale() const + \behaviour This function returns the scale used by this porthole to display its contents. + \note Returns \c 1.0 if the porthole isn't bound to a cell view. + */ + +/*!\function Unit CellWidget::getX(int screenX) const + \behaviour This function returns the cell view abscissa corresponding to a screen abscissa. + \parameter screenX The screen abscissa for which the request is asked. + */ + +/*!\function Unit CellWidget::getY(int screenY) const + \behaviour This function returns the cell view ordinate corresponding to a screen ordinate. + \parameter screenY The screen ordinate for which the request is asked. + */ + +/*!\function Unit CellWidget::getSize(int screenSize) const + \behaviour This function returns the cell view dimension corresponding to a screen dimension. + \parameter screenSize The screen dimension for which the request is asked. + */ + +/*!\function Point CellWidget::getPoint(const QPoint& screenPoint) const + \behaviour This function returns the cell view location corresponding to a screen location. + \parameter screenPoint The screen location for which the request is asked. + */ + +/*!\function Box CellWidget::getBox(const QRect& screenRect) const + \behaviour This function returns the cell view box corresponding to a screen rectangle. + \parameter screenRect The screen rectangle for which the request is asked. + */ + +/*!\function int CellWidget::getScreenX(const Unit& x) const + \behaviour This function returns the screeen abscissa corresponding to a cell view abscissa. + \parameter x The cell view abscissa for which the request is asked. + */ + +/*!\function int CellWidget::getScreenY(const Unit& y) const + \behaviour This function returns the screeen ordinate corresponding to a cell view ordinate. + \parameter y The cell view ordinate for which the request is asked. + */ + +/*!\function int CellWidget::getScreenSize(const Unit& size) const + \behaviour This function returns the screeen dimension corresponding to a cell view dimension. + \parameter size The cell view dimension for which the request is asked. + */ + +/*!\function QPoint CellWidget::getScreenPoint(const Point& point) const + \behaviour This function returns the screeen location corresponding to a cell view location. + \parameter point The cell view location for which the request is asked. + */ + +/*!\function QRect CellWidget::getScreenRect(const Box& box) const + \behaviour This function returns the screeen rectangle corresponding to a cell view box. + \parameter box The cell view box for which the request is asked. + */ + +/*!\function Point CellWidget::getSnapPoint(const Point& point) const + \behaviour This convenience function returns the cell view location associated to a given cell + view location in respect to the snap grid status. + \nn So when snap grid is enabled the returned location correspond to the nearest grid + point of the given location else the returned location is the given location itself. + \parameter point The cell view location for which the request is asked. + */ + +/*!\function Point CellWidget::getSnapPoint(int screenX, int screenY) const + \behaviour This convenience function returns the cell view location associated to the specified + screen coordinates in respect to the snap grid status. + \nn So when snap grid is enabled the returned location correspond to the nearest grid + point of the location obtained from the specified screen coordinates else the + returned location is directly the location obtained from the specified screen + coordinates. + \parameter screenX The screen abscissa for which the request is asked. + \parameter screenY The screen ordinate for which the request is asked. + */ + +/*!\function const QColor& CellWidget::getBackgroundColor() const + \behaviour This function returns the background color of this porthole. + */ + +/*!\function const QColor& CellWidget::getForegroundColor() const + \behaviour This function returns the foreground color of this porthole. + */ + +/*!\function const LayerMask& CellWidget::getVisibleLayerMask() const + \behaviour This function returns the mask representing the visible layers of this porthole. + */ + +/*!\function Layers CellWidget::getVisibleLayers() const + \behaviour This function returns the collection of visible layers (can be empty). + \note The layers are sorted from the deepest one to the higher one. + */ + +/*!\function Command* CellWidget::getCommand(int button) const + \behaviour This function returns the command which is installed on a given button. + \parameter button The button for which we want to get the associated command. + */ + +/*!\function Command* CellWidget::getStartedCommand() const + \behaviour This function returns the command of this porthole which has started. + \note Returns \NULL when no command has started. + */ + +/*!\function Commands CellWidget::getCommands() const + \behaviour This function returns the collection of commands installed on this porthole. + */ + +/*!\function const Point& CellWidget::getGridOrigin() const + \behaviour This function returns the origin of the grid. + */ + +/*!\function const Unit& CellWidget::getGridXStep() const + \behaviour This function returns the horizontal grid step. + */ + +/*!\function const Unit& CellWidget::getGridYStep() const + \behaviour This function returns the vertical grid step. + */ + +/*!\function unsigned CellWidget::getGridDisplayThreshold() const + \behaviour This function returns the display threshold used to control the drawability of the + grid. + \nn The threshold is a minimal number of pixels allowed between two consecutives grid + points on screen. When the number of pixels is less than the threshold the grid + isn't drawn (even it is visible). + */ + +/*!\function const QColor& CellWidget::getGridColor() const + \behaviour This function returns the grid color of this porthole. + */ + +/*!\function Unit CellWidget::getGridX(const Unit& x, int sign) const + \behaviour This function returns the grid abscissa corresponding to a given cell view abscissa. + \parameter x The cell view abscissa for which the request is asked. + \parameter sign Indicates which grid position should be used. When the sign is -1 we + consider the lower grid position, when the sign is 0 we consider the + nearest position and when the sign is 1 we consider the upper grid + position (all other values are forbidden). + \exception INVALID_REQUEST This exception is thrown when the \c sign doesn't correspond to a + legal value. + */ + +/*!\function Unit CellWidget::getGridY(const Unit& y, int sign) const + \behaviour This function returns the grid ordinate corresponding to a given cell view ordinate. + \parameter y The cell view ordinate for which the request is asked. + \parameter sign Indicates which grid position should be used. When the sign is -1 we + consider the lower grid position, when the sign is 0 we consider the + nearest position and when the sign is 1 we consider the upper grid + position (all other values are forbidden). + \exception INVALID_REQUEST This exception is thrown when the \c sign doesn't correspond to a + legal value. + */ + +/*!\function Point CellWidget::getGridPoint(const Point& point, int xSign, int ySign) const + \behaviour This function returns the grid location corresponding to a given cell view location. + \parameter point The cell view location for which the request is asked. + \parameter xSign and + \parameter ySign Indicate which grid position should be used in the associated + direction. When the sign is -1 we consider the lower grid position, + when the sign is 0 we consider the nearest position and when the + sign is 1 we consider the upper grid position (all other values are + forbidden). + \exception INVALID_REQUEST This exception is thrown when the \c xSign or \c ySign doesn't + correspond to a legal value. + */ + +/*!\function unsigned CellWidget::getDisplayDepth() const + \behaviour This function returns the display depth of this porthole. + \note The display depth represent the maximal number of hierarchy levels that should be + drawn in this porthole. + */ + +/*!\function unsigned CellWidget::getDisplaySize() const + \behaviour This function returns the display size of this porthole. + \note To be drawn in a given porthole the maximal size of the bounding box of a figure + (on the screen) should be greather than the display size (defined in pixels). + */ + +/*!\function Occurrences CellWidget::getSelection() const + \behaviour This function returns the collection of occurrences selected in this porthole. + */ + +/*!\function Box CellWidget::getSelectionBox() const + \behaviour This function returns the box enclosing the selection of this porthole. + */ + +/*!\function unsigned CellWidget::getSelectionLimit() const + \behaviour This function returns the maximal number of occurrences that could be selected in + this porthole. + */ + +/*!\function const QColor& CellWidget::getSelectionColor() const + \behaviour This function returns the selection color of this porthole. + */ + +/*!\function Occurrences CellWidget::getHighlightion() const + \behaviour This function returns the collection of occurrences highlighted in this porthole. + */ + +/*!\function Box CellWidget::getHighlightionBox() const + \behaviour This function returns the box enclosing the highlightion of this porthole. + */ + +/*!\function unsigned CellWidget::getHighlightionLimit() const + \behaviour This function returns the maximal number of occurrences that could be highlighted in + this porthole. + */ + +/*!\function const QFont& CellWidget::getFont() const + \behaviour This function returns the current font of this porthole. + \note This is this font which is used by the drawing and filling functions. + */ + +/*!\function const QPen& CellWidget::getPen() const + \behaviour This function returns the current pen of this porthole. + \note This is this pen which is used by the drawing and filling functions. + */ + +/*!\function const QBrush& CellWidget::getBrush() const + \behaviour This function returns the current brush of this porthole. + \note This is this brush which is used by the drawing and filling functions. + */ + +/*!\function const QPoint& CellWidget::getBrushOrigin() const + \behaviour This function returns the current brush origin of this porthole. + \note This is this brush origin which is used by the drawing and filling functions. + */ + +/*!\function TrackBox* CellWidget::getTrackBox() const + \behaviour This function returns the track box associated to this porthole. + */ +//@} + +//@{ +/*!\function bool CellWidget::doubleBuffering() const + \behaviour This function returns \TRUE when the double buffering is enabled. + */ + +/*!\function bool CellWidget::automaticScrolling() const + \behaviour This function returns \TRUE when the automatic scrolling is enabled. + */ + +/*!\function bool CellWidget::isVisible(Layer* layer) const + \behaviour This function returns \TRUE when the specified layer is visible. + \parameter layer The layer for which the request is asked. + \note A visible layer is not systematicaly drawn. The display depends also of the layer + display threshold and the current scale. + */ + +/*!\function bool CellWidget::isDrawable(Layer* layer) const + \behaviour This function returns \TRUE when the layer can be drawn according to the layer + display threshold and the current scale. + \note A non visible layer can be drawable and a visible layer can be not drawable. So to + known if the layer should really be drawn you need to check its visibility and its + drawability. + */ + +/*!\function bool CellWidget::gridIsVisible() const + \behaviour This function returns \TRUE when the grid is visible. + \note A visible grid is not systematicaly drawn. The display depends also of the grid + display threshold and the current scale. + */ + +/*!\function bool CellWidget::gridAxesAreVisible() const + \behaviour This function returns \TRUE when the grid axes are visible. + \note Those grid axes are drawn only when this function returns \TRUE and the grid is + drawn. + */ + +/*!\function bool CellWidget::gridIsDrawable() const + \behaviour This function returns \TRUE when the grid can be drawn according to the grid + display threshold and the current scale. + \note A non visible grid can be drawable and a visible grid can be not drawable. So to + known if the grid should really be drawn you need to check its visibility and its + drawability. + */ + +/*!\function bool CellWidget::isOnGridX(const Unit& x, unsigned n) const + \behaviour This function returns \TRUE when the specified cell view abscissa is on a grid + position. + \parameter x The cell view abscissa for which the request is asked. + \parameter n This argument allows to do not take into account each grid position + but only those which are multiples of n (a null value is forbidden). + \exception INVALID_REQUEST This exception is thrown when \c n is null. + */ + +/*!\function bool CellWidget::isOnGridY(const Unit& y, unsigned n) const + \behaviour This function returns \TRUE when the specified cell view ordinate is on a grid + position. + \parameter y The cell view ordinate for which the request is asked. + \parameter n This argument allows to do not take into account each grid position + but only those which are multiples of n (a null value is forbidden). + \exception INVALID_REQUEST This exception is thrown when \c n is null. + */ + +/*!\function bool CellWidget::isOnGridPoint(const Point& point, unsigned xN, unsigned yN) const + \behaviour This function returns \TRUE when the specified cell view location is on a grid + location. + \parameter point The cell view location for which the request is asked. + \parameter xN and + \parameter yN Allow to do not take into account each grid position but only those + which are multiples of xN horizontaly and yN verticaly (null values + are forbidden). + \exception INVALID_REQUEST This exception is thrown when \c xN or \c yN is null. + */ + +/*!\function bool CellWidget::snapGrid() const + \behaviour This function returns \TRUE when the snap grid is enabled. + */ + +/*!\function bool CellWidget::selectionIsVisible() const + \behaviour This function returns \TRUE when the selection is visible. + */ + +/*!\function bool CellWidget::isSelected(const Occurrence& occurrence) const + \behaviour This function returns \TRUE when the specified occurrence is selected in this + porthole. + */ + +/*!\function bool CellWidget::isSelectable(const Occurrence& occurrence) const + \behaviour This function returns \TRUE when the specified occurrence can be selected in this + porthole (meaning that the occurrence is selectable and the view owning the + occurrence is the view bound to this porthole). + */ + +/*!\function bool CellWidget::highlightionIsVisible() const + \behaviour This function returns \TRUE when the highlightion is visible. + */ + +/*!\function bool CellWidget::isHighlighted(const Occurrence& occurrence) const + \behaviour This function returns \TRUE when the specified occurrence is highlighted in this + porthole. + */ + +/*!\function bool CellWidget::isHighlightable(const Occurrence& occurrence) const + \behaviour This function returns \TRUE when the specified occurrence can be highlighted in this + porthole (meaning that the occurrence is highlightable and the view owning the + occurrence is the view bound to this porthole). + */ +//@} + +//@{ +/*!\function void CellWidget::setBackgroundColor(const QColor& color) + \behaviour This function sets the background color of this porthole to the specified value. + \parameter color The new background color. + */ + +/*!\function void CellWidget::setForegroundColor(const QColor& color) + \behaviour This function sets the foreground color of this porthole to the specified value. + \parameter color The new foreground color. + */ + +/*!\function void CellWidget::setDoubleBuffering(bool enable) + \behaviour This function enables or disables the double buffering. + \parameter enable The new status. + */ + +/*!\function void CellWidget::setAutomaticScrolling(bool enable) + \behaviour This function enables or disables the automatic scrolling. + \parameter enable The new status. + \exception INVALID_REQUEST This exception is thrown when this porthole is a map + porthole. + */ + +/*!\function void CellWidget::setVisible(Layer* layer, bool visible) + \behaviour This function sets the visibility status of the specified layer in this porthole to + the specified value. + \parameter layer The layer for which the request is asked. + \parameter visible The new status. + */ + +/*!\function void CellWidget::setGridOrigin(const Point& origin) + \behaviour This function sets the origin of the grid of this porthole to the specified value. + \parameter origin The new grid origin. + */ + +/*!\function void CellWidget::setGridXStep(const Unit& step) + \behaviour This function sets the horizontal grid step of this porthole to the specified value. + \parameter step The new horizontal grid step. + \exception INVALID_REQUEST This exception is thrown when the \c step is null. + */ + +/*!\function void CellWidget::setGridYStep(const Unit& step) + \behaviour This function sets the vertical grid step of this porthole to the specified value. + \parameter step The new vertical grid step. + \exception INVALID_REQUEST This exception is thrown when the \c step is null. + */ + +/*!\function void CellWidget::setGridStep(const Unit& step) + \behaviour This function sets the horizontal and vertical grid steps of this porthole to the + specified value. + \parameter step The new horizontal and vertical grid step. + \exception INVALID_REQUEST This exception is thrown when the \c step is null. + */ + +/*!\function void CellWidget::setGridSteps(const Unit& xStep, const Unit& yStep) + \behaviour This function sets the horizontal and vertical grid step of this porthole to the + specified values. + \parameter xStep The new horizontal grid step. + \parameter yStep The new vertical grid step. + \exception INVALID_REQUEST This exception is thrown when \c xStep or \c yStep is null. + is null. + */ + +/*!\function void CellWidget::setGridDisplayThreshold(unsigned threshold) + \behaviour This function sets the grid display threshold of this porthole to the specified + value. + \parameter threshold The new display threshold. + \exception INVALID_REQUEST This exception is thrown when the new display threshold is too + small (less than 3 pixels). + */ + +/*!\function void CellWidget::setGridColor(const QColor& color) + \behaviour This function sets the grid color of this porthole to the specified value. + \parameter color The new grid color. + */ + +/*!\function void CellWidget::setGridVisible(bool visible) + \behaviour This function sets the visibility status of the grid in this porthole to the + specified value. + \parameter visible The new status. + */ + +/*!\function void CellWidget::setGridAxesVisible(bool visible) + \behaviour This function sets the visibility status of the grid axes in this porthole to the + specified value. + \parameter visible The new status. + */ + +/*!\function void CellWidget::setSnapGrid(bool enable) + \behaviour This function enables or disables the snap grid. + \parameter enable The new status. + */ + +/*!\function void CellWidget::setDisplayDepth(unsigned displayDepth) + \behaviour This function sets the display depth of this porthole to the specified value. + \parameter displayDepth The new display depth. + */ + +/*!\function void CellWidget::setDisplaySize(unsigned displaySize) + \behaviour This function sets the display size of this porthole to the specified value. + \parameter displaySize The new display size. + */ + +/*!\function void CellWidget::setSelectionLimit(unsigned limit) + \behaviour This function sets the selection limit of this porthole to the specified value. + \parameter limit The new selection limit (a null value indicating no limit). + */ + +/*!\function void CellWidget::setSelectionColor(const QColor& color) + \behaviour This function sets the selection color of this porthole to the specified value. + \parameter color The new selection color. + */ + +/*!\function void CellWidget::setSelectionVisible(bool visible) + \behaviour This function sets the visibility status of the selection in this porthole to the + specified value. + \parameter visible The new status. + */ + +/*!\function void CellWidget::setHighlightionLimit(unsigned limit) + \behaviour This function sets the highlightion limit of this porthole to the specified value. + \parameter limit The new highlightion limit (a null value indicating no limit). + */ + +/*!\function void CellWidget::setHighlightionVisible(bool visible) + \behaviour This function sets the visibility status of the highlightion in this porthole to the + specified value. + \parameter visible The new status. + */ + +/*!\function void CellWidget::setFont(const QFont& font) + \behaviour This function sets the font of this porthole to the specified value. + \parameter font The new font. + \note When a layer (or a ghost) is displayed, the graphical characteristics of this layer + (or this ghost) have been positionned. So, in principle, unless very specific needs, + there is no need to call this function. If you do so, dont forget to restore the + previous font after use. + */ + +/*!\function void CellWidget::setPen(const QPen& pen, double brightness) + \behaviour This function sets the pen of this porthole to the specified value. + \parameter pen The new pen. + \parameter brightness The brightness of the new pen. + \exception INVALID_REQUEST This exception is thrown if the brightness isn't in the range + [0.1 1.0]. + \notes When a layer (or a ghost) is displayed, the graphical characteristics of this layer + (or this ghost) have been positionned. So, in principle, unless very specific needs, + there is no need to call this function. If you do so, dont forget to restore the + previous pen after use. + */ + +/*!\function void CellWidget::setBrush(const QBrush& brush, double brightness) + \behaviour This function sets the brush of this porthole to the specified value. + \parameter brush The new brush. + \parameter brightness The brightness of the new brush. + \exception INVALID_REQUEST This exception is thrown if the brightness isn't in the range + [0.1 1.0]. + \notes When a layer (or a ghost) is displayed, the graphical characteristics of this layer + (or this ghost) have been positionned. So, in principle, unless very specific needs, + there is no need to call this function. If you do so, dont forget to restore the + previous brush after use. + */ + +/*!\function void CellWidget::setBrushOrigin(const QPoint& origin) + \behaviour This function sets the brush origin of this porthole to the specified value. + \parameter origin The new brush origin. + \note When a layer (or a ghost) is displayed, the graphical characteristics of this layer + (or this ghost) have been positionned. So, in principle, unless very specific needs, + there is no need to call this function. If you do so, dont forget to restore the + previous brush origin after use. + */ + +/*!\function void CellWidget::setTrackBox(TrackBox* track) + \behaviour This function bounds this porthole with the specified track box. + \parameter track The track box to bound with this porthole (can be \NULL). + */ +//@} + +//@{ +/*!\function void CellWidget::showAllLayers() + \behaviour This function sets the visibility status of all layers to \TRUE for this porthole. + */ + +/*!\function void CellWidget::hideAllLayers() + \behaviour This function sets the visibility status of all layers to \FALSE for this porthole. + */ + +/*!\function bool CellWidget::select(const Occurrence& occurrence) + \behaviour This function selects the specified occurrence in this porthole. + \parameter occurrence The occurrence to select. + */ + +/*!\function void CellWidget::unselect(const Occurrence& occurrence) + \behaviour This function unselects the specified occurrence from this porthole. + \parameter occurrence The occurrence to unselect. + */ + +/*!\function void CellWidget::clearSelection() + \behaviour This function clears the selection. + */ + +/*!\function bool CellWidget::highlight(const Occurrence& occurrence) + \behaviour This function highlights the specified occurrence in this porthole. + \parameter occurrence The occurrence to highlight. + */ + +/*!\function void CellWidget::unhighlight(const Occurrence& occurrence) + \behaviour This function unhighlights the specified occurrence from this porthole. + \parameter occurrence The occurrence to unhighlight. + */ + +/*!\function void CellWidget::clearHighlightion() + \behaviour This function clears the highlightion. + */ + +/*!\function void CellWidget::clearPeeks() + */ + +/*!\function void CellWidget::addPeek(const Box& box) + */ + +/*!\function void CellWidget::invalidate() + \behaviour This function post an invalidation region representing the visible part of the cell + view bound to this porthole. + \example + \code + * void MyCellWidget::refresh() + * { + * invalidate(); + * redraw(); + * } + \endcode + */ + +/*!\function void CellWidget::invalidate(const QRect& screenRect) + \behaviour This convenience function post an invalidation region representing the cell view + box corresponding to a given screen rect. + \parameter screenRect The screen rectangle to invalidate. + */ + +/*!\function void CellWidget::invalidate(const Box& box) + \behaviour This function post an invalidation region representing a given cell view box. + \parameter box The cell view box to invalidate. + */ + +/*!\function void CellWidget::fitToContent(unsigned screenMargin) + \behaviour This function makes the entire cell view visible in this porthole. + \parameter screenMargin Represent the minimal number of pixel we want around the bounding + box of the cell view. + */ + +/*!\function void CellWidget::reframe(double scale) + \behaviour This function sets the scale used to display the content of this porthole to the + specified value. + \parameter scale The new scale. + \examples + \code + * void MyCellWidget::zoomIn() + * { + * reframe(getScale() * 1.2)); + * redraw(); + * } + \endcode + \code + * void MyCellWidget::zoomOut() + * { + * reframe(getScale() / 1.2)); + * redraw(); + * } + \endcode + \note This function does nothing if the new scale is null. + */ + +/*!\function void CellWidget::reframe(const Point& center) + \behaviour This function sets the center of this porthole to the specified value. + \parameter center The new center. + \example + \code + * void MyCellWidget::pan(const Point& point) + * { + * reframe(point); + * redraw(); + * } + \endcode + */ + +/*!\function void CellWidget::reframe(const Point& center, double scale) + \behaviour This function sets the center and the scale of this porthole to the specified + values. + \parameter center The new center. + \parameter scale The new scale. + \note This function does nothing if the new scale is null. + */ + +/*!\function void CellWidget::reframe(const Box& box) + \behaviour This function allows you to map a cell view region into this porthole. + \remark The aspect ratios of the cell view region and the porthole can be differents + but the function ensures that the entire region will becomes visible. + \parameter box The region for which the request is asked. + \note This function does nothing if the region is inverted. + */ + +/*!\function void CellWidget::scroll(const Unit& dx, const Unit& dy) + \behaviour This function scrolls the content of this porthole of the specified quantities. + \parameter dx The horizontal quantity. + \parameter dy The verticaly quantity. + \note The display is updated immediately (it is not differed as it will be with the + reframe or fitToContent functions). So, it is not needed to call the redraw + function to see the effects. + */ + +/*!\function void CellWidget::redraw() + \behaviour This function is called or should be called to redraw the invalidated region. + \important Nothing is done if the invalidated region is empty. + */ + +/*!\function void CellWidget::abortStartedCommand() + \behaviour This function aborts the started command. + \important Nothing is done if no command has started. + */ + +/*!\function void CellWidget::drawLine(const Unit& xo, const Unit& yo, const Unit& xe, const Unit& ye) + \behaviour This function draws the line joining the points defined by the specified + coordinates with the current pen. + \parameter xo The abscissa of the line origin. + \parameter yo The ordinate of the line origin. + \parameter xe The abscissa of the line extremity. + \parameter ye The ordinate of the line extremity. + */ + +/*!\function void CellWidget::drawLine(const Point& origin, const Point& extremity) + \behaviour This function draws the line joining the specified points with the current pen. + \parameter origin The origin of the line. + \parameter extremity The extremity of the line. + */ + +/*!\function void CellWidget::drawPolyline(const Points& points) + \behaviour This function draws the polyline joining the specified points with the current pen. + \parameter points The collection of points defining the polyline. + */ + +/*!\function void CellWidget::drawRectangle(const Unit& xMin, const Unit& yMin, const Unit& xMax, const Unit& yMax) + \behaviour This function draws the rectangle defined by the specified values with the current + pen and brush. + \parameter xMin The left bound of the rectangle. + \parameter yMin The bottom bound of the rectangle. + \parameter xMax The right bound of the rectangle. + \parameter yMax The top bound of the rectangle. + */ + +/*!\function void CellWidget::drawRectangle(const Box& box) + \behaviour This convenience function behaves essentially like the above function. + \parameter box The box which defines the limits of the rectangle. + */ + +/*!\function void CellWidget::drawPolygon(const Points& points) + \behaviour This function draws the polygon defined by the specified points with the current + pen and brush. + \parameter points The collection of points which defining the polygon. + */ + +/*!\function void CellWidget::drawText(const Box& frame, const string& text, const Direction& direction) + \behaviour This function draws the string defined by the specified text, in the specified + direction, inside the specified frame, with the specified area style and using the + current font and pen. + \nn Texts are displayed using a fixed size font. The appearence of each text depend to + the scale factor of this porthole. The frame is used to control the display of a + text. So, to be really drawn, the screen dimensions of a text should be smaller than + the dimensions of the frame. + \parameter frame Defines the maximal dimensions of the text. + \parameter text Defines the string that should be drawn. + \parameter direction Defines the direction of the text. + */ + +/*!\function void CellWidget::drawText(const Box& frame, const Name& name, const Direction& direction) + \behaviour This convenience function behaves essentially like the above function. + \parameter frame Defines the maximal dimensions of the name. + \parameter name Defines the string that should be drawn. + \parameter direction Defines the direction of the text. + */ +//@} + + + +//CLOSE_MY_NAMESPACE +// +//USING_MY_NAMESPACE + +#endif // H_CellWidget + +// *************************************************************************************************