From 984e7914370d53739d62b7abe5f578bb9e0ee41b Mon Sep 17 00:00:00 2001 From: Christophe Alexandre Date: Fri, 4 Jan 2008 16:13:29 +0000 Subject: [PATCH] save for the moment --- hurricane/src/figures/CMakeLists.txt | 5 +- hurricane/src/figures/CellFigure.cpp | 21 ++-- hurricane/src/figures/CellScene.cpp | 9 ++ hurricane/src/figures/CellScene.h | 15 +++ hurricane/src/figures/InstanceFigure.cpp | 120 +++++++++++++++++++---- hurricane/src/figures/InstanceFigure.h | 12 ++- hurricane/src/figures/SegmentFigure.cpp | 14 ++- hurricane/src/figures/SegmentFigure.h | 8 +- hurricane/src/figures/SliceFigure.cpp | 38 +++---- 9 files changed, 182 insertions(+), 60 deletions(-) create mode 100644 hurricane/src/figures/CellScene.cpp create mode 100644 hurricane/src/figures/CellScene.h diff --git a/hurricane/src/figures/CMakeLists.txt b/hurricane/src/figures/CMakeLists.txt index 55b39058..375c415c 100644 --- a/hurricane/src/figures/CMakeLists.txt +++ b/hurricane/src/figures/CMakeLists.txt @@ -2,11 +2,12 @@ include(${QT_USE_FILE}) include_directories(${HURRICANE_SOURCE_DIR}/hurricane) -set(includes CellFigure.h InstanceFigure.h SliceFigure.h GoFigure.h SegmentFigure.h) -set(cpps CellFigure.cpp InstanceFigure.cpp SliceFigure.cpp GoFigure.cpp SegmentFigure.cpp) +set(includes InstanceFigure.h Utils.h) +set(cpps InstanceFigure.cpp CellScene.cpp) add_library(hurricanefigs SHARED ${cpps}) target_link_libraries(hurricanefigs ${QT_LIBRARIES} hurricane) install(FILES ${includes} DESTINATION /include/hurricane) install(TARGETS hurricanefigs DESTINATION /lib) + diff --git a/hurricane/src/figures/CellFigure.cpp b/hurricane/src/figures/CellFigure.cpp index 932a89aa..44a33ec5 100644 --- a/hurricane/src/figures/CellFigure.cpp +++ b/hurricane/src/figures/CellFigure.cpp @@ -19,10 +19,10 @@ CellFigure::CellFigure(Cell* c): new InstanceFigure(this, instance); end_for; } - for_each_slice(slice, cell->GetSlices()) { - new SliceFigure(this, slice); - end_for; - } + //for_each_slice(slice, cell->GetSlices()) { + // new SliceFigure(this, slice); + // end_for; + //} } CellFigure::CellFigure(InstanceFigure* master, Cell* c) : QGraphicsItem(master), cell(c) { @@ -54,12 +54,12 @@ void CellFigure::paint(QPainter *painter, const QStyleOptionGraphicsItem* option // pen.setColor(Qt::red); // painter->setPen(pen); - painter->setClipRect(option->exposedRect); - if (option->levelOfDetail > 1.0) { - drawBoundary(painter); - } else { - drawPhantom(painter); - } + //painter->setClipRect(option->exposedRect); + //if (option->levelOfDetail > 1.0) { + // drawBoundary(painter); + //} else { + // drawPhantom(painter); + //} } void CellFigure::drawBoundary(QPainter* painter) { @@ -78,4 +78,3 @@ void CellFigure::drawPhantom(QPainter* painter) { BoxToRectangle(box, rect); painter->drawRect(rect); } - diff --git a/hurricane/src/figures/CellScene.cpp b/hurricane/src/figures/CellScene.cpp new file mode 100644 index 00000000..955e6c69 --- /dev/null +++ b/hurricane/src/figures/CellScene.cpp @@ -0,0 +1,9 @@ +#include "CellScene.h" + + +void CellScene::drawItems(QPainter *painter, + int numItems, + QGraphicsItem *items[], + const QStyleOptionGraphicsItem options[], + QWidget *widget) { +} diff --git a/hurricane/src/figures/CellScene.h b/hurricane/src/figures/CellScene.h new file mode 100644 index 00000000..3328bb51 --- /dev/null +++ b/hurricane/src/figures/CellScene.h @@ -0,0 +1,15 @@ +#ifndef __CELL_SCENE_H +#define __CELL_SCENE_H + +#include + +class CellScene : public QGraphicsScene { + protected : + void drawItems(QPainter *painter, + int numItems, + QGraphicsItem *items[], + const QStyleOptionGraphicsItem options[], + QWidget *widget); +}; + +#endif /* __CELL_SCENE_H */ diff --git a/hurricane/src/figures/InstanceFigure.cpp b/hurricane/src/figures/InstanceFigure.cpp index 2481d4b4..d42f2cb1 100644 --- a/hurricane/src/figures/InstanceFigure.cpp +++ b/hurricane/src/figures/InstanceFigure.cpp @@ -1,30 +1,112 @@ #include #include +#include + +#include "Cell.h" +#include "Slice.h" +#include "Segment.h" +#include "BasicLayer.h" +using namespace H; #include "Utils.h" #include "InstanceFigure.h" -InstanceFigure::InstanceFigure(CellFigure* parent, Instance* inst): - QGraphicsItem(parent), - instance(inst) { - Cell* masterCell = inst->GetMasterCell(); - - Transformation transformation = instance->GetTransformation(); - QTransform transform; - QPoint pos; - HurricanePositionToQtPosition(transformation, transform, pos); - setTransform(transform); - setPos(pos); - new CellFigure(this, masterCell); +//InstanceFigure::InstanceFigure(Instance* inst) +// : instance(inst), +// cell(instance->GetMasterCell()) +//{ +// Transformation transformation = instance->GetTransformation(); +// QTransform transform; +// QPoint pos; +// HurricanePositionToQtPosition(transformation, transform, pos); +// setTransform(transform); +// setPos(pos); +// constructSubInstances(); +//} + +InstanceFigure::InstanceFigure(Cell* c) + : instance(NULL), + cell(c) +{ + constructSubInstances(); +} + +InstanceFigure::InstanceFigure(InstanceFigure* parent, Instance* inst) + : QGraphicsItem(parent), + instance(inst), + cell(instance->GetMasterCell()) +{ + Transformation transformation = instance->GetTransformation(); + QTransform transform; + QPoint pos; + HurricanePositionToQtPosition(transformation, transform, pos); + setTransform(transform); + setPos(pos); + constructSubInstances(); +} + +void InstanceFigure::constructSubInstances() { + for_each_instance(instance, cell->GetInstances()) { + new InstanceFigure(this, instance); + end_for; + } } QRectF InstanceFigure::boundingRect() const { - Cell* masterCell = instance->GetMasterCell(); - Box box = masterCell->GetAbutmentBox(); - QRectF rect; - BoxToRectangle(box, rect); - return rect; + Box box = cell->GetAbutmentBox(); + QRectF rect; + BoxToRectangle(box, rect); + return rect; } -void InstanceFigure::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{} +void InstanceFigure::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { + painter->setClipRect(option->exposedRect.adjusted(-1.0, -1.0, 1.0, 1.0)); + if (option->levelOfDetail > 1.0) { + drawBoundary(painter); + drawElements(painter); + } else { + drawPhantom(painter); + } +} + +void InstanceFigure::drawElements(QPainter* painter) { + for_each_slice(slice, cell->GetSlices()) { + painter->save(); + BasicLayer* layer = dynamic_cast(slice->GetLayer()); + if (layer) { + painter->setBrush(QColor(layer->GetRedValue(), layer->GetGreenValue(), layer->GetBlueValue())); + } else { + painter->setBrush(Qt::blue); + } + for_each_go(go, slice->GetGos()) { + Segment* segment = dynamic_cast(go); + if (segment) { + Box box = segment->GetBoundingBox(); + QRectF rect; + BoxToRectangle(box, rect); + painter->drawRect(rect); + + } + end_for; + } + painter->restore(); + end_for; + } +} + +void InstanceFigure::drawBoundary(QPainter* painter) { + QPen pen(Qt::black); + painter->setPen(pen); + Box box = cell->GetAbutmentBox(); + QRectF rect; + BoxToRectangle(box, rect); + painter->drawRect(rect); +} + +void InstanceFigure::drawPhantom(QPainter* painter) { + painter->setBrush(Qt::red); + Box box = cell->GetAbutmentBox(); + QRectF rect; + BoxToRectangle(box, rect); + painter->drawRect(rect); +} diff --git a/hurricane/src/figures/InstanceFigure.h b/hurricane/src/figures/InstanceFigure.h index a922ca85..4d02d7fd 100644 --- a/hurricane/src/figures/InstanceFigure.h +++ b/hurricane/src/figures/InstanceFigure.h @@ -4,20 +4,26 @@ #include #include -#include "CellFigure.h" - #include "Instance.h" +#include "Cell.h" using namespace Hurricane; class InstanceFigure : public QGraphicsItem { public: - InstanceFigure(CellFigure* parent, Instance* instance); + InstanceFigure(InstanceFigure* parent, Instance* instance); + //InstanceFigure(Instance* instance); + InstanceFigure(Cell* cell); QRectF boundingRect() const; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); private: Instance* instance; + Cell* cell; + void drawPhantom(QPainter* painter); + void drawBoundary(QPainter* painter); + void drawElements(QPainter* painter); + void constructSubInstances(); }; diff --git a/hurricane/src/figures/SegmentFigure.cpp b/hurricane/src/figures/SegmentFigure.cpp index f8e4b168..8ab452f7 100644 --- a/hurricane/src/figures/SegmentFigure.cpp +++ b/hurricane/src/figures/SegmentFigure.cpp @@ -7,15 +7,25 @@ using namespace H; #include "Utils.h" +#include "SliceFigure.h" #include "SegmentFigure.h" SegmentFigure::SegmentFigure(SliceFigure* master, Segment* s): - GoFigure(master), + QGraphicsItem(master), segment(s) {} +QRectF SegmentFigure::boundingRect() const { + Box box = getGo()->GetBoundingBox(); + QRectF rect; + BoxToRectangle(box, rect); + return rect; +} + void SegmentFigure::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { - if (option->levelOfDetail < 1.0) { + Q_UNUSED(widget); + + if (option->levelOfDetail > 1.0) { painter->setClipRect(option->exposedRect); BasicLayer* layer = dynamic_cast(segment->GetLayer()); if (layer) { diff --git a/hurricane/src/figures/SegmentFigure.h b/hurricane/src/figures/SegmentFigure.h index d2ddab04..bf6d45b1 100644 --- a/hurricane/src/figures/SegmentFigure.h +++ b/hurricane/src/figures/SegmentFigure.h @@ -4,16 +4,16 @@ #include #include -#include "GoFigure.h" - #include "Segment.h" using namespace Hurricane; -class SegmentFigure : public GoFigure { +class SliceFigure; + +class SegmentFigure : public QGraphicsItem { public: SegmentFigure(SliceFigure* parent, Segment* segment); void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); - + QRectF boundingRect() const; private: Segment* segment; protected: diff --git a/hurricane/src/figures/SliceFigure.cpp b/hurricane/src/figures/SliceFigure.cpp index 4450a01e..1a68ec6b 100644 --- a/hurricane/src/figures/SliceFigure.cpp +++ b/hurricane/src/figures/SliceFigure.cpp @@ -21,25 +21,25 @@ QRectF SliceFigure::boundingRect() const { } void SliceFigure::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { - if (option->levelOfDetail > 1.0) { -// painter->setClipRect(option->exposedRect); - BasicLayer* layer = dynamic_cast(slice->GetLayer()); - if (layer) { - painter->setBrush(QColor(layer->GetRedValue(), layer->GetGreenValue(), layer->GetBlueValue())); - } else { - painter->setBrush(Qt::blue); - } - for_each_go(go, slice->GetGos()) { - Segment* segment = dynamic_cast(go); - if (segment) { - Box box = segment->GetBoundingBox(); - QRectF rect; - BoxToRectangle(box, rect); - painter->drawRect(rect); - } - end_for; - } - } +// if (option->levelOfDetail > 1.0) { +//// painter->setClipRect(option->exposedRect); +// BasicLayer* layer = dynamic_cast(slice->GetLayer()); +// if (layer) { +// painter->setBrush(QColor(layer->GetRedValue(), layer->GetGreenValue(), layer->GetBlueValue())); +// } else { +// painter->setBrush(Qt::blue); +// } +// for_each_go(go, slice->GetGos()) { +// Segment* segment = dynamic_cast(go); +// if (segment) { +// Box box = segment->GetBoundingBox(); +// QRectF rect; +// BoxToRectangle(box, rect); +// painter->drawRect(rect); +// } +// end_for; +// } +// } } void SliceFigure::constructGoFigures() {