#include "GroupWidget.h"
#include "GroupItem.h"
#include "BoxItem.h"
+#include "StimuliItem.h"
#include "ConnectionItem.h"
#include "InterfaceItem.h"
#include "AbstractBlock.h"
+#include "Graph.h"
GroupScene::GroupScene(GroupScene *_parentScene, GroupWidget *_window, Dispatcher* _dispatcher, Parameters* _params, bool _topScene, QObject *parent) : QGraphicsScene(parent) {
dispatcher = _dispatcher;
}
GroupScene::~GroupScene() {
- blockItems.clear();
+ static QString fctName = "GroupScene::~GroupScene()";
+#ifdef DEBUG_FCTNAME
+ cout << "call to " << qPrintable(fctName) << endl;
+#endif
+
+ boxItems.clear();
connectionItems.clear();
groupItem = NULL;
}
+/*
+void GroupScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
+
+ //QGraphicsScene::mouseMoveEvent(event);
+
+ QPointF p = event->scenePos();
+ cout << p.x() << "," << p.y() << endl;
+
+}
+*/
+
void GroupScene::setSelectedInterface(int id, InterfaceItem* iface) {
if ((id < 1)|| (id > 2)) return;
selectedInterfaces[id-1] = iface;
QList<BoxItem *> GroupScene::getSelectedBlocks() {
QList<BoxItem*> lst;
- foreach(BoxItem *item, blockItems){
+ foreach(BoxItem *item, boxItems){
if (item->isSelected()){
lst.append(item);
}
int GroupScene::setItemsId(int countInit) {
int counter = countInit;
groupItem->setId(counter++);
- foreach(BoxItem *item, blockItems){
+ if (isTopScene()) {
+ foreach(StimuliItem *item, stimuliItems){
+ item->setId(counter++);
+ }
+ }
+ foreach(BoxItem *item, boxItems){
item->setId(counter++);
}
return counter;
foreach(InterfaceItem* inter, groupItem->getInterfaces()){
inter->setId(counter++);
}
- foreach(BoxItem *item, blockItems){
+ if (isTopScene()) {
+ foreach(StimuliItem *item, stimuliItems){
+ foreach(InterfaceItem* inter, item->getInterfaces()){
+ inter->setId(counter++);
+ }
+ }
+ }
+ foreach(BoxItem *item, boxItems){
foreach(InterfaceItem* inter, item->getInterfaces()){
inter->setId(counter++);
}
return counter;
}
-QList<AbstractBoxItem*> GroupScene::getGroupAndBlocks() {
+BoxItem *GroupScene::createBoxItem(AbstractBlock *block, BoxItem::Position position, int lock, BoxItem::SpanType span) {
- QList<AbstractBoxItem*> lst;
- lst.append(groupItem);
- foreach(BoxItem *item, blockItems){
- lst.append(item);
+ BoxItem* item = new BoxItem(block,dispatcher,params,groupItem, lock, span, position);
+ item->setZValue(1);
+ // add item from the QList
+ boxItems.append(item);
+ // repainting the group
+ groupItem->updateShape();
+
+/*
+ // position the new block
+ double x,y;
+ if (hPos == BoxItem::Left) {
+ x = 0;
}
- return lst;
+ else if (hPos == BoxItem::Center) {
+ x = (groupItem->getWidth()-item->getTotalWidth())/2.0;
+ }
+ else if (hPos == BoxItem::Right) {
+ x = groupItem->getWidth()-item->getTotalWidth();
+ }
+ if (vPos == BoxItem::Top) {
+ y = 0;
+ }
+ else if (vPos == BoxItem::Center) {
+ y = (groupItem->getHeight()-item->getTotalHeight())/2.0;
+ }
+ else if (vPos == BoxItem::Bottom) {
+ y = groupItem->getHeight()-item->getTotalHeight();
+ }
+ QPointF newPos(x,y);
+ newPos = newPos-item->getOriginPoint();
+ item->moveTo(newPos);
+*/
+ return item;
}
-BoxItem *GroupScene::createBlockItem(AbstractBlock *block) {
-
- BoxItem* blockItem = new BoxItem(block,dispatcher,params,groupItem);
- blockItem->setZValue(1);
- addBlockItem(blockItem);
- return blockItem;
+void GroupScene::addBoxItem(BoxItem* item) {
+ // add item from the QList
+ boxItems.append(item);
+ // repainting the group
+ groupItem->updateShape();
}
-void GroupScene::addBlockItem(BoxItem* item) {
- // add item from the viewport
- //addItem(item);
- // add item from the QList
- blockItems.append(item);
+void GroupScene::removeBoxItem(BoxItem* item) {
+ // remove item from the viewport
+ removeItem(item);
+ // remove item from the QList
+ boxItems.removeAll(item);
// repainting the group
groupItem->updateShape();
+}
+
+BoxItem* GroupScene::searchBoxItemByName(QString name) {
+ foreach(BoxItem* item, boxItems) {
+ if (item->getRefBlock()->getName() == name) {
+ return item;
+ }
+ }
+ return NULL;
+}
+
+StimuliItem *GroupScene::createStimuliItem(AbstractBlock *block) {
+
+ StimuliItem* item = new StimuliItem(block,dispatcher,params);
+ // adding item to the scene
+ addItem(item);
+ item->setZValue(1);
+ // add item from the QList
+ stimuliItems.append(item);
// center the new block
- QPointF newPos((groupItem->getWidth()-item->getTotalWidth())/2.0, (groupItem->getHeight()-item->getTotalHeight())/2.0);
+ QPointF groupPos = groupItem->pos();
+ QPointF newPos(groupPos.x()-item->getTotalWidth()-100, groupPos.y());
newPos = newPos-item->getOriginPoint();
- item->moveTo(newPos);
+ item->moveTo(newPos);
+ return item;
+}
+
+void GroupScene::addStimuliItem(StimuliItem* item) {
+ // adding item to the scene
+ addItem(item);
+ item->setZValue(1);
+ // add item from the QList
+ stimuliItems.append(item);
}
-void GroupScene::removeBlockItem(BoxItem* item) {
+void GroupScene::removeStimuliItem(StimuliItem* item) {
// remove item from the viewport
removeItem(item);
// remove item from the QList
- blockItems.removeAll(item);
- // repainting the group
- groupItem->updateShape();
+ stimuliItems.removeAll(item);
}
-void GroupScene::createConnectionItem(InterfaceItem *iface1, InterfaceItem *iface2) {
- ConnectionItem* conn = new ConnectionItem(iface1,iface2, dispatcher, params, groupItem);
+void GroupScene::createConnectionItem(InterfaceItem *iface1, InterfaceItem *iface2, bool visible) {
+ ConnectionItem* conn = NULL;
+
+ conn = new ConnectionItem(iface1,iface2, dispatcher, params);
+ conn->setVisible(visible);
+ addItem(conn);
addConnectionItem(conn);
}
return conn;
}
}
+ return NULL;
}
void GroupScene::addConnectionItem(ConnectionItem* item) {
}
void GroupScene::removeConnectionItem(ConnectionItem* item) {
+
+ // remove connection from/to InterfaceItem
+ InterfaceItem* fromIfaceItem = item->getFromInterfaceItem();
+ InterfaceItem* toIfaceItem = item->getToInterfaceItem();
+ fromIfaceItem->removeConnectionItem(item);
+ toIfaceItem->removeConnectionItem(item);
+
// remove item from the viewport
removeItem(item);
// remove item from the QList
groupItem = NULL;
}
-QList<ConnectionItem *> GroupScene::getInterfaceConnections(InterfaceItem *item) {
- QList<ConnectionItem*> list;
- foreach(ConnectionItem *conn, connectionItems){
- if(conn->getFromInterfaceItem() == item || conn->getToInterfaceItem() == item){
- list.append(conn);
- }
- }
- return list;
-}
-
void GroupScene::unselecteInterfaces() {
if (selectedInterfaces[0] != NULL) {
selectedInterfaces[0]->selected = false;
- selectedInterfaces[0] == NULL;
+ selectedInterfaces[0] = NULL;
}
if (selectedInterfaces[1] != NULL) {
selectedInterfaces[1]->selected = false;
- selectedInterfaces[1] == NULL;
+ selectedInterfaces[1] = NULL;
}
}
void GroupScene::save(QXmlStreamWriter &writer) {
writer.writeStartElement("scene");
writer.writeAttribute("id",QString::number(id));
+ if (parentScene == NULL) {
+ writer.writeAttribute("upper_scene",QString::number(-1));
+ }
+ else {
+ writer.writeAttribute("upper_scene",QString::number(parentScene->getId()));
+ }
+ if (isTopScene()) {
+ QString clkList = "";
+ QList<double> lst = params->getGraph()->getClocks();
+ foreach(double d, lst) {
+ clkList += QString::number(d)+",";
+ }
+ clkList.chop(1);
+ writer.writeAttribute("clkList",clkList);
+
+ }
groupItem->save(writer);
+ if (isTopScene()) {
+ writer.writeStartElement("source_items");
+ writer.writeAttribute("count",QString::number(stimuliItems.length()));
+ foreach(StimuliItem* item, stimuliItems) {
+ item->save(writer);
+ }
+ writer.writeEndElement(); // source_items
+ }
writer.writeStartElement("block_items");
QList<BoxItem *> functionalBlocks;
QList<BoxItem *> groupBlocks;
- foreach(BoxItem *item, blockItems){
+ foreach(BoxItem *item, boxItems){
if(item->getRefBlock()->isFunctionalBlock()){
functionalBlocks.append(item);
} else if(item->getRefBlock()->isGroupBlock()){