parentItem->setChildGroupItem(this);
}
- /*
- minimumBoxWidth = nameWidth+2*nameMargin;
- minimumBoxHeight = 100;
- boxHeight = minimumBoxHeight;
- boxWidth = minimumBoxWidth;
- */
+ boxHeight = 1;
+ boxWidth = 1;
rectTitle = QRectF(0,-(nameHeight+2*nameMargin),nameWidth+2*nameMargin,nameHeight+2*nameMargin);
+
+ /* NB: boxPoint represent the position in scene of the top-left corner of the box, thus
+ * without taking into account the interfaces. It is also the reference position to draw the item.
+ * Nevertheless, in order to place sources in the scene, the real bouding box of the group is determined
+ * from originPoint and totalWidth/totalheight.
+ * */
+ boxPoint = QPointF(0,0);
/*
totalHeight = boxHeight + rectTitle.height();
totalWidth = boxWidth;
*/
selected = false;
-
setZValue(100);
setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemSendsGeometryChanges);
- updateGeometry(InterfaceMove);
- QPointF initPos = QPointF(0.0,0.0) - originPoint;
- setPos(initPos);
+ updateGeometry(Creation);
+ setPos(boxPoint);
cout << "total size of group: " << totalWidth << "," << totalHeight << endl;
cout << "pos in scene: " << x() << "," << y() << endl;
}
minimumBoxHeight = 2*marginConn;
if (getScene() == NULL) return;
-
QList<BoxItem *> blocks = getScene()->getBoxItems();
- if(blocks.length() > 0) {
- // first, search for blocks that are at (0,0)
- int xMaxZero = 0;
- int yMaxZero = 0;
- int xMax = 0;
- int yMax = 0;
- bool isZeroBlocks = false;
- bool isOtherBlocks = false;
- foreach(BoxItem* item, blocks) {
- QPointF p = item->pos() + item->getOriginPoint();
- if ((p.x()==0.0) && (p.y()==0.0)) {
- isZeroBlocks = true;
- if (item->getTotalWidth() > xMaxZero) {
- xMaxZero = item->getTotalWidth();
+ if(blocks.length() == 0) return; // no blocks within, keep the miniumum computed before.
+
+ QRectF boxFree; // the bounding box of free blocks.
+ foreach(BoxItem* item, blocks) {
+ QRectF boxItem = item->boundingRect();
+ if (item->getPosition() == BoxItem::Free) {
+ boxItem.translate(item->pos());
+ if (item->getSpan() == BoxItem::NoSpan) {
+ boxFree = boxFree.united(boxItem);
+ }
+ else if (item->getSpan() == BoxItem::HSpan) {
+ QRectF r(boxFree.left()+boxFree.width()/2.0,boxItem.top(),1,boxItem.height());
+ boxFree = boxFree.united(r);
+ }
+ else if (item->getSpan() == BoxItem::VSpan) {
+ QRectF r(boxItem.left(),boxFree.top()+boxFree.height()/2.0,boxItem.width(),1);
+ boxFree = boxFree.united(r);
+ }
+ }
+ }
+ // find the move to apply to freely located items
+ double gapXLeft = 0.0;
+ double gapYTop = 0.0;
+ if (boxFree.left() < marginConn) {
+ gapXLeft = boxFree.left() - marginConn;
+ }
+ if (boxFree.top() < marginConn) {
+ gapYTop = boxFree.top() - marginConn;
+ }
+ // translate the box
+ boxFree.translate(-gapXLeft,-gapYTop);
+ minimumBoxWidth = boxFree.right() + marginConn;
+ minimumBoxHeight = boxFree.bottom() + marginConn;
+
+ // find the highest/largest item stick on top/bottom/left/right
+
+ qreal topHighest = 0.0;
+ qreal bottomHighest = 0.0;
+ qreal leftLargest = 0.0;
+ qreal rightLargest = 0.0;
+
+ foreach(BoxItem* item, blocks) {
+ QRectF boxItem = item->boundingRect();
+
+ if (item->getPosition() == BoxItem::Top) {
+
+ if (item->getSpan() == BoxItem::VSpan) {
+ if (item->getMinimumBoxHeight() > topHighest) {
+ topHighest = item->getMinimumBoxHeight();
}
- if (item->getTotalHeight() > yMaxZero) {
- yMaxZero = item->getTotalHeight();
+ }
+ else {
+ if (boxItem.height()+marginConn > topHighest) {
+ topHighest = boxItem.height()+marginConn;
+ }
+ }
+ if (item->getSpan() == BoxItem::HSpan) {
+ if (item->getMinimumBoxWidth() > leftLargest) {
+ leftLargest = item->getMinimumBoxWidth();
+ }
+ }
+ }
+
+ if (item->getPosition() == BoxItem::Bottom) {
+
+ if (item->getSpan() == BoxItem::VSpan) {
+ if (item->getMinimumBoxHeight() > bottomHighest) {
+ bottomHighest = item->getMinimumBoxHeight();
}
}
else {
- isOtherBlocks = true;
- if(p.x()+item->getTotalWidth() > xMax) {
- xMax = p.x()+item->getTotalWidth();
+ if (boxItem.height()+marginConn > bottomHighest) {
+ bottomHighest = boxItem.height()+marginConn;
}
- if(p.y()+item->getTotalHeight() > yMax) {
- yMax = p.y()+item->getTotalHeight();
+ }
+ if (item->getSpan() == BoxItem::HSpan) {
+ if (item->getMinimumBoxWidth() > leftLargest) {
+ leftLargest = item->getMinimumBoxWidth();
}
}
}
- if (isZeroBlocks) {
- if (!isOtherBlocks) {
- minimumBoxWidth = xMaxZero+2*marginConn;
- minimumBoxHeight = yMaxZero+2*marginConn;
+
+ if (item->getPosition() == BoxItem::Left) {
+
+ if (item->getSpan() == BoxItem::HSpan) {
+ if (item->getMinimumBoxWidth() > leftLargest) {
+ leftLargest = item->getMinimumBoxWidth();
+ }
}
else {
- if (xMaxZero+marginConn > xMax) {
- minimumBoxWidth = xMaxZero+2*marginConn;
+ if (boxItem.width()+marginConn > leftLargest) {
+ leftLargest = boxItem.width()+marginConn;
}
- else {
- minimumBoxWidth = xMax+marginConn;
+ }
+ if (item->getSpan() == BoxItem::VSpan) {
+ if (item->getMinimumBoxHeight() > topHighest) {
+ topHighest = item->getMinimumBoxHeight();
+ }
+ }
+ }
+
+ if (item->getPosition() == BoxItem::Right) {
+
+ if (item->getSpan() == BoxItem::HSpan) {
+ if (item->getMinimumBoxWidth() > rightLargest) {
+ rightLargest = item->getMinimumBoxWidth();
}
- if (yMaxZero+marginConn > yMax) {
- minimumBoxHeight = yMaxZero+2*marginConn;
+ }
+ else {
+ if (boxItem.width()+marginConn > rightLargest) {
+ rightLargest = boxItem.width()+marginConn;
}
- else {
- minimumBoxHeight = yMax+marginConn;
+ }
+ if (item->getSpan() == BoxItem::VSpan) {
+ if (item->getMinimumBoxHeight() > topHighest) {
+ topHighest = item->getMinimumBoxHeight();
}
}
}
- else {
- minimumBoxWidth = xMax+marginConn;
- minimumBoxHeight = yMax+marginConn;
+ }
+
+ if (leftLargest > minimumBoxWidth) {
+ minimumBoxWidth = leftLargest;
+ }
+ if (rightLargest > minimumBoxWidth) {
+ minimumBoxWidth = rightLargest;
+ }
+ if (topHighest > minimumBoxHeight) {
+ minimumBoxHeight = topHighest;
+ }
+ if (bottomHighest > minimumBoxHeight) {
+ minimumBoxHeight = bottomHighest;
+ }
+ // must move all free boxitem within of -gapXLeft,-gapYTop
+ foreach(BoxItem* item, blocks) {
+ if (item->getPosition() == BoxItem::Free) {
+ if (item->getSpan() == BoxItem::HSpan) {
+ item->moveBy(0,-gapYTop);
+ }
+ if (item->getSpan() == BoxItem::VSpan) {
+ item->moveBy(-gapXLeft,0);
+ }
+ else {
+ item->moveBy(-gapXLeft,-gapYTop);
+ }
}
}
+
//cout << "min group size: " << minimumBoxWidth << "," << minimumBoxHeight << endl;
}
updateGeometry(InterfaceMove);
}
+void GroupItem::updateBorderSpanItems() {
+ QList<BoxItem *> blocks = getScene()->getBoxItems();
+ bool changed = false;
+ foreach(BoxItem* item, blocks) {
+ changed = false;
+ if (item->getPosition() == BoxItem::Bottom) {
+ changed = true;
+ QPointF pos = item->pos();
+ item->moveTo(QPointF(pos.x(),boxHeight-item->getTotalHeight()));
+ }
+ else if (item->getPosition() == BoxItem::Right) {
+ changed = true;
+ QPointF pos = item->pos();
+ item->moveTo(QPointF(boxWidth-item->getTotalWidth(),pos.y()));
+ }
+ if (item->getSpan() == BoxItem::HSpan) {
+ changed = true;
+ item->setWidth(boxWidth);
+ }
+ else if (item->getSpan() == BoxItem::VSpan) {
+ changed = true;
+ item->setHeight(boxHeight);
+ }
+ if (changed) {
+ item->updateGeometry(Resize);
+ }
+ }
+}
+
bool GroupItem::updateGeometry(ChangeType type) {
QPointF oldOrigin = originPoint;
// whatever the change, the minimum size may have changed
updateMinimumSize();
- if (type == Resize) {
+ if (type == Creation) {
boxSizeChanged = true;
- }
- // if an internal block has moved, the actual box size may be inadequate
- if (boxWidth < minimumBoxWidth) {
boxWidth = minimumBoxWidth;
- boxSizeChanged = true;
- }
- if (boxHeight < minimumBoxHeight) {
boxHeight = minimumBoxHeight;
- boxSizeChanged = true;
+ /* reset and update interfaces positions
+ * in case of spanning, the interface are positionned
+ * only on free borders.
+ */
+ resetInterfaceItemsPosition();
}
-
- if (boxSizeChanged) {
+ else if (type == Resize) {
+ boxSizeChanged = true;
updateInterfaceAndConnectionItems();
+ updateBorderSpanItems();
+ }
+ else if (type == InterfaceMove) {
+ // if an internal block has moved, the actual box size may be inadequate
+ if (boxWidth < minimumBoxWidth) {
+ boxWidth = minimumBoxWidth;
+ boxSizeChanged = true;
+ updateInterfaceAndConnectionItems();
+ updateBorderSpanItems();
+ }
+ if (boxHeight < minimumBoxHeight) {
+ boxHeight = minimumBoxHeight;
+ boxSizeChanged = true;
+ updateInterfaceAndConnectionItems();
+ updateBorderSpanItems();
+ }
}
if ((y>boxHeight-2*marginS)&&(y<boxHeight)) {
currentBorder = CornerSouthEast;
- setCursor(Qt::SizeFDiagCursor);
+ setCursor(Qt::SizeFDiagCursor);
}
else {
currentBorder = BorderEast;
- setCursor(Qt::SizeHorCursor);
+ setCursor(Qt::SizeHorCursor);
}
}
else if ((y>boxHeight-marginS)&&(y<boxHeight)) {
if ((x>boxWidth-2*marginE)&&(x<boxWidth)) {
currentBorder = CornerSouthEast;
- setCursor(Qt::SizeFDiagCursor);
+ setCursor(Qt::SizeFDiagCursor);
}
else {
currentBorder = BorderSouth;
- setCursor(Qt::SizeVerCursor);
+ setCursor(Qt::SizeVerCursor);
}
}
else {
setCursor(Qt::ArrowCursor);
}
}
- }
- //QGraphicsItem::hoverMoveEvent(event);
- event->ignore();
+ }
}
void GroupItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
QAction* removeAction = NULL;
QAction* renameAction = NULL;
QAction* showParameters = NULL;
+ QAction* addExtClkAction = NULL;
InterfaceItem* ifaceItem = getInterfaceItemFromCursor(event->pos().x(), event->pos().y());
showParameters = menu.addAction("Show parameters");
}
renameAction = menu.addAction("Rename");
+ if (refBlock->isTopGroupBlock()) {
+ addExtClkAction = menu.addAction("Add new external clock/reset");
+ }
+
}
QAction* selectedAction = menu.exec(event->screenPos());
}
else if(selectedAction == showParameters) {
new ParametersWindow(refBlock, params, NULL);
- }
+ }
+ else if (selectedAction == addExtClkAction) {
+ bool ok = false;
+ double freq = QInputDialog::getDouble(NULL,"Adding a clkrstgen","External clock frequency (in MHz)",100,0,100000,1,&ok);
+ if (!ok) return;
+ dispatcher->addClkRstGenBlock(Dispatcher::Design, freq);
+ }
}
InterfaceItem* GroupItem::isHoverInterface(QPointF point) {
if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
GroupInterface *groupIface = new GroupInterface(groupBlock,name,direction,purpose);
- GroupInterface *groupCtlIface = new GroupInterface(groupBlock,name+"_enb",direction,AbstractInterface::Control);
- groupCtlIface->setAssociatedIface(groupIface);
-
+ groupBlock->addInterface(groupIface);
InterfaceItem *interfaceItem = new InterfaceItem(position,orientation,groupIface,this,params);
interfaceItem->setId(id);
-
- groupBlock->addInterface(groupIface);
- groupBlock->addInterface(groupCtlIface);
addInterfaceItem(interfaceItem, false);
+
+ if (purpose == AbstractInterface::Data) {
+ GroupInterface *groupCtlIface = new GroupInterface(groupBlock,name+"_enb",direction,AbstractInterface::Control);
+ groupCtlIface->setAssociatedIface(groupIface);
+ groupBlock->addInterface(groupCtlIface);
+ }
cout << "interface add to " << groupBlock->getName().toStdString() << endl;
}