#include "AbstractInterface.h"
#include "ConnectedInterface.h"
+int AbstractBoxItem::NoLock = 0;
+int AbstractBoxItem::Position = 1;
+int AbstractBoxItem::Dimension = 2;
+int AbstractBoxItem::Interfaces = 4;
+int AbstractBoxItem::Names = 8;
-AbstractBoxItem:: AbstractBoxItem(AbstractBlock *_refBlock, Dispatcher *_dispatcher, Parameters *_params, QGraphicsItem *parent) : QGraphicsItem(parent) {
+AbstractBoxItem::AbstractBoxItem(AbstractBlock *_refBlock, Dispatcher *_dispatcher, Parameters *_params, int _lock, QGraphicsItem *parent) : QGraphicsItem(parent) {
dispatcher = _dispatcher;
params = _params;
refBlock = _refBlock;
+ lock = _lock;
QFontMetrics fmId(params->defaultBlockFont);
nameWidth = fmId.width(refBlock->getName());
nameHeight = fmId.height();
- nameMargin = 10;
+ nameMargin = 5;
ifaceMargin = 10;
// the six following values will be override in subclass constructors
// NOTE : initInterfaces() is only called in subclasses
}
-AbstractBoxItem::AbstractBoxItem(Dispatcher *_dispatcher, Parameters *_params, QGraphicsItem* parent) : QGraphicsItem(parent) {
+AbstractBoxItem::AbstractBoxItem(Dispatcher *_dispatcher, Parameters *_params, int _lock, QGraphicsItem* parent) : QGraphicsItem(parent) {
dispatcher = _dispatcher;
- params = _params;
+ params = _params;
refBlock = NULL;
+ lock = _lock;
nameWidth = 0;
nameHeight = 0;
nameMargin = 10;
bool AbstractBoxItem::isGroupItem() {
return false;
}
+
+bool AbstractBoxItem::isSourceItem() {
+ return false;
+}
+
void AbstractBoxItem::setRstClkVisible(bool b) {
rstClkVisible = b;
foreach(InterfaceItem* ifaceItem, interfaces) {
ifaceItem->visible = b;
}
}
- resetInterfacesPosition();
+ resetInterfaceItemsPosition();
updateGeometry(InterfaceMove);
update();
getScene()->updateConnectionItemsShape();
ifaceItem->visible = b;
}
}
- resetInterfacesPosition();
+ resetInterfaceItemsPosition();
updateGeometry(InterfaceMove);
update();
getScene()->updateConnectionItemsShape();
nameHeight = fmId.height();
}
-void AbstractBoxItem::initInterfaces() {
+void AbstractBoxItem::createInterfaceItems(Parameters::Direction posInputs, Parameters::Direction posOutputs, Parameters::Direction posBidirs) {
/* TO DO : creating all needed InterfaceItem, with by default, input at west and output at east */
int orientation = Parameters::West;
foreach(AbstractInterface *inter, refBlock->getInterfaces()){
- /* NB: create InterfaceItem for every interfaces, even if they do not have a graphical representation
- It will allow to save them in the XML project file and thus to create their equivalent
- in the graph while the file is loaded.
+ /* NB: does not create InterfaceItem for control interfaces.
*/
- InterfaceItem *item;
- if(inter->getDirection() == AbstractInterface::Input){
- orientation = Parameters::West;
- } else if(inter->getDirection() == AbstractInterface::Output){
- orientation = Parameters::East;
- } else if(inter->getDirection() == AbstractInterface::InOut){
- orientation = Parameters::North;
+ if (inter->getPurpose() != AbstractInterface::Control) {
+ InterfaceItem *item;
+ if(inter->getDirection() == AbstractInterface::Input){
+ orientation = posInputs;
+ } else if(inter->getDirection() == AbstractInterface::Output){
+ orientation = posOutputs;
+ } else if(inter->getDirection() == AbstractInterface::InOut){
+ orientation = posBidirs;
+ }
+ item = new InterfaceItem(0.0 , orientation, (ConnectedInterface *)inter, this, params);
+ interfaces.append(item);
}
- item = new InterfaceItem(0.0 , orientation, (ConnectedInterface *)inter, this, params);
- interfaces.append(item);
}
}
-InterfaceItem* AbstractBoxItem::searchInterfaceByName(QString name) {
+InterfaceItem* AbstractBoxItem::searchInterfaceItemByName(QString name) {
foreach(InterfaceItem *inter, interfaces){
if(inter->getName() == name)
return inter;
return NULL;
}
-InterfaceItem* AbstractBoxItem::searchInterfaceByRef(ConnectedInterface *ref) {
+InterfaceItem* AbstractBoxItem::searchInterfaceItemByRef(ConnectedInterface *ref) {
foreach(InterfaceItem *inter, interfaces){
if(inter->refInter == ref) {
return inter;
return NULL;
}
-void AbstractBoxItem::addInterface(InterfaceItem *i, bool resetPosition) {
+void AbstractBoxItem::addInterfaceItem(InterfaceItem *i, bool resetPosition) {
interfaces.append(i);
- if (resetPosition) resetInterfacesPosition();
+ if (resetPosition) resetInterfaceItemsPosition();
updateGeometry(InterfaceMove);
update();
}
-void AbstractBoxItem::removeInterface(InterfaceItem *i) {
+void AbstractBoxItem::removeInterfaceItem(InterfaceItem *i) {
// NB : removing from model is done in dispatcher
- interfaces.removeOne(i);
+ interfaces.removeAll(i);
delete i;
//resetInterfacesPosition();
}
-void AbstractBoxItem::resetInterfacesPosition() {
+void AbstractBoxItem::resetInterfaceItemsPosition() {
int nbNorth=0, nbSouth=0, nbEast=0, nbWest=0;
double cntNorth=1.0,cntSouth=1.0,cntEast=1.0,cntWest=1.0;
}
}
-void AbstractBoxItem::moveInterfaceTo(QPointF pos) {
+void AbstractBoxItem::moveInterfaceItemTo(QPointF pos) {
double positionRatio;
if(currentInterface->getOrientation() == Parameters::North || currentInterface->getOrientation() == Parameters::South){
if(pos.x() < 0){
QRectF AbstractBoxItem::boundingRect() const {
// returns a QRectF that contains the block (i.e the main rectangle, interfaces, title, ...)
- QPointF p = originPoint - QPointF(nameHeight,nameHeight);
- QSizeF s(totalWidth+2*nameHeight,totalHeight+2*nameHeight);
+ QPointF p = originPoint;
+ QSizeF s(totalWidth,totalHeight);
return QRectF(p,s);
}
+QRectF AbstractBoxItem::boundingRectInScene() {
+ /* returns a QRectF in scene coordinates, that contains the block plus
+ a margin of size arrowWidth+arrowLineLength
+ */
+ int marginConn = params->arrowLineLength+params->arrowWidth;
+
+ QPointF posBox = scenePos();
+ posBox.setX(posBox.x()+originPoint.x()-marginConn);
+ posBox.setY(posBox.y()+originPoint.y()-marginConn);
+
+ QSizeF sizeBox(totalWidth+2*marginConn,totalHeight+2*marginConn);
+
+ return QRectF(posBox,sizeBox);
+}
+
/* isInterface() : return true if there are some interfaces
with the given orientation (N,S,E,O)
*/
bool AbstractBoxItem::isInterfaces(int orientation) const {
foreach(InterfaceItem* inter, interfaces) {
- if (inter->getOrientation() == orientation) return true;
+ if ((inter->visible) && (inter->getOrientation() == orientation)) return true;
}
return false;
}
return nb;
}
-void AbstractBoxItem::updateInterfacesAndConnections() {
+void AbstractBoxItem::updateInterfaceAndConnectionItems() {
// update all interfaces positions
foreach(InterfaceItem *item, interfaces){
boxHeight = y;
}
-InterfaceItem* AbstractBoxItem::getInterfaceFromCursor(qreal x, qreal y) {
+InterfaceItem* AbstractBoxItem::getInterfaceItemFromCursor(qreal x, qreal y) {
foreach(InterfaceItem* inter, interfaces) {
if(x > inter->boundingRect().x() && x < (inter->boundingRect().x() + inter->boundingRect().width())){