// CAUTION : the owner must add explicitely this item to its interface, calling addInterface()
owner = _owner;
params = _params;
- selected = false;
- name = refInter->getName();
+ selected = false;
QFontMetrics fmName(params->defaultIfaceFont);
- nameWidth = fmName.width(name);
+ nameWidth = fmName.width(refInter->getName());
nameHeight = fmName.height();
// by default, only data interface are visible
if (refInter->getPurpose() == AbstractInterface::Data) {
this->id = counter++;
}
+QString InterfaceItem::getName() {
+ return refInter->getName();
+}
+
+void InterfaceItem::updateName(QString name) {
+ QFontMetrics fmName(params->defaultIfaceFont);
+ nameWidth = fmName.width(refInter->getName());
+ nameHeight = fmName.height();
+ updatePosition();
+}
+
+
/* boundingRect() : give the bounding rect in the blockitem coord. system */
QRectF InterfaceItem::boundingRect() const {
if(selected) {
painter->setPen(QPen(Qt::red,2));
- }
- else if(refInter->getLevel() == AbstractInterface::Basic) {
- painter->setPen(QPen(Qt::darkCyan,1));
- }
- else if(refInter->getLevel() == AbstractInterface::Top) {
- painter->setPen(QPen(Qt::black,1));
+ }
+ else {
+ if(owner->isBoxItem()) {
+ painter->setPen(QPen(Qt::black,1));
+ }
+ else if(owner->isSourceItem()) {
+ painter->setPen(QPen(Qt::darkCyan,1));
+ }
}
painter->translate(originPoint);
if(owner->isGroupItem()){
painter->drawText(-(w+params->arrowWidth+params->arrowLineLength),-h/2,w,h,Qt::AlignLeft | Qt::TextWordWrap, refInter->getName());
}
- else if(owner->isBoxItem()){
+ else if((owner->isBoxItem()) || (owner->isSourceItem())){
painter->drawText(0,-h/2,w,h,Qt::AlignRight | Qt::TextWordWrap, refInter->getName());
}
}
if(owner->isGroupItem()) {
painter->drawText(params->arrowWidth+params->arrowLineLength,-h/2,w,h,Qt::AlignRight | Qt::TextWordWrap, refInter->getName());
}
- else if(owner->isBoxItem()) {
+ else if((owner->isBoxItem()) || (owner->isSourceItem())){
painter->drawText(-w,-h/2,w,h,Qt::AlignLeft | Qt::TextWordWrap, refInter->getName());
}
}
}
-/* connectWith() :
- - modify all necessary attributes in the model to create a connection
- between current InterfaceItem and iface. Note that the source and destination
- are deduced from the direction (In, Out) and the type of the owner (funcitonal, group)
-
- CAUTION: No security checks are done. This method must be called only if canConnectWith has been called and returned true.
-
- NOTE : conditions so that this InterfaceItem can be connected with inter.
- (i.e. current one can connect to inter OR inter can connect to current)
-
- Here are all the possible combinations, depending on the type of the
- block/item and direction of the interface, which are :
- GI/GB : a GroupItem referencing a GroupBlock (single solution for GI)
- BI/FB : a BlockItem referencing a FunctionalBlock
- BI/GB : a BlockItem referencing a GroupBlock
-
- For GI/GB:
- - Input can connect with BI/FB or BI/GB Input
- - Output can connect with BI/FB or BI/GB Output
-
- For BI/FB:
- - Input can connect with:
- GI/GB Input
- BI/FB Output
- BI/GB Output
- - Output can connect with:
- GI/GB Output
- BI/FB Input
- BI/GB Input
-
- For BI/GB:
- - Input can connect with:
- GI/GB Input
- BI/FB Output
- BI/GB Output
- - Output can connect with:
- GI/GB Output
- BI/FB Input
- BI/GB Input
-
- And whatever the case an InOut can only connect with an InOut
- We note that:
- - the IG does not allow the connect a GI/GB interface to an
- interface of another GI/GB, thus the case is not considered above.
- - BI/FB and BI/GB are the same.
- - the cases where direction are the same only occur when
- the 2 items are of different type (GI and BI)
- - the cases where directions are different only occur when
- the 2 are of both BlockItem
-
-*/
-bool InterfaceItem::connectWith(InterfaceItem *iface) {
- ConnectedInterface* interThis = refInter; // the reference of this
- ConnectedInterface* interOther = iface->refInter; // the reference of the other
- ConnectedInterface* src = NULL, *dest = NULL;
-
- if(interThis->getDirection() == AbstractInterface::InOut && interOther->getDirection() == AbstractInterface::InOut){
- /* NOTE: InOut interfaces have both directions and thus are
- connected from inter1 to inter2 AND inter2 to inter1
- Another effect is that a InOut can be connected to/from a single
- InOut.
- */
- if((interThis->getConnectedFrom() == NULL) && (interOther->getConnectedFrom() == NULL)) {
-
- interOther->connectFrom(interThis);
- interOther->getConnectedTo().append(interThis);
- interThis->connectFrom(interOther);
- interThis->getConnectedTo().append(interOther);
-
- cout << "connecting 2 InOut"<< endl;
- return true;
- }
- return false;
- }
- else if (interThis->getDirection() == interOther->getDirection()) {
-
- // cannot connect GI to GI or 2 BI of the same direction.
- if ((getOwner()->isGroupItem()) && (iface->getOwner()->isGroupItem())) return false;
- if ((getOwner()->isBoxItem()) && (iface->getOwner()->isBoxItem())) return false;
-
- if (interThis->getDirection() == AbstractInterface::Input) { // both are inputs
- cout << "connecting GI to BI" << endl;
- if(getOwner()->isGroupItem()) {
- src = interThis;
- dest = interOther;
- }
- else {
- src = interOther;
- dest = interThis;
- }
- }
- else { // both are outputs
- cout << "connecting BO to GO" << endl;
- if(getOwner()->isGroupItem()){
- src = interOther;
- dest = interThis;
- }
- else {
- src = interThis;
- dest = interOther;
- }
- }
- }
- else {
- if ((getOwner()->isGroupItem()) || (iface->getOwner()->isGroupItem())) return false;
-
- cout << "connecting BO to BI" << endl;
- if(interOther->getDirection() == AbstractInterface::Output) {
- src = interOther;
- dest = interThis;
- }
- else {
- src = interThis;
- dest = interOther;
- }
- }
-
- if(dest != NULL && src != NULL){
- // cannot overrive existing connectionFrom
- if(dest->getConnectedFrom() == NULL) {
- dest->connectFrom(src);
- src->connectTo(dest);
- return true;
- }
- else {
- return false;
- }
- }
- return false;
-}
-
-void InterfaceItem::unconnectTo(InterfaceItem *iface)
-{
- if(iface->refInter->getConnectedFrom() == refInter){
- iface->refInter->connectFrom(NULL);
- }
- if(iface->refInter->getConnectedTo().contains(refInter)){
- cout << "abnormal case while removing iface conn from " << qPrintable(name) << " to " << qPrintable(iface->name) << endl;
- iface->refInter->removeConnectedTo(refInter);
- }
- if(refInter->getConnectedFrom() == iface->refInter) {
- cout << "abnormal case while removing iface conn from " << qPrintable(name) << " to " << qPrintable(iface->name) << endl;
- refInter->connectFrom(NULL);
- }
- if(refInter->getConnectedTo().contains(iface->refInter)){
- refInter->removeConnectedTo(iface->refInter);
- }
-}
-
-void InterfaceItem::updatePosition()
-{
+void InterfaceItem::updatePosition() {
if(orientation == Parameters::North || orientation == Parameters::South){
position = positionRatio * owner->getWidth();
} else {