From 3bbc311e444c1ef9ac66dd6861fb0acb13ddb72a Mon Sep 17 00:00:00 2001 From: stephane Domas Date: Wed, 10 May 2017 22:30:19 +0200 Subject: [PATCH 1/1] changed connection process --- AbstractInterface.cpp | 3 +++ BoxItem.cpp | 2 +- ConnectedInterface.cpp | 29 +++++++++++++++++----- ConnectedInterface.h | 5 ++-- Dispatcher.cpp | 54 +++++++++++++---------------------------- Dispatcher.h | 2 +- FunctionalInterface.cpp | 5 +--- GroupInterface.cpp | 6 ++--- GroupItem.cpp | 2 +- Parameters.cpp | 2 +- SourceItem.cpp | 2 +- blast.creator.user | 12 ++++----- 12 files changed, 60 insertions(+), 64 deletions(-) diff --git a/AbstractInterface.cpp b/AbstractInterface.cpp index dde5930..f57f780 100644 --- a/AbstractInterface.cpp +++ b/AbstractInterface.cpp @@ -172,6 +172,9 @@ int AbstractInterface::typeFromString(const QString &_type) { else if (_type == "natural") { ret = Natural; } + else if (_type == "inherited") { + ret = Inherited; + } return ret; } diff --git a/BoxItem.cpp b/BoxItem.cpp index 1902003..43cceec 100644 --- a/BoxItem.cpp +++ b/BoxItem.cpp @@ -394,7 +394,7 @@ void BoxItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { else if (params->editState == Parameters::EditCloseConnection) { InterfaceItem* iface1 = getScene()->getSelectedInterface(1); InterfaceItem* iface2 = getScene()->getSelectedInterface(2); - bool ok = dispatcher->createConnectionItem(iface1,iface2); + bool ok = dispatcher->createConnection(iface1,iface2); if (ok) { iface1->selected = false; update(iface1->boundingRect()); diff --git a/ConnectedInterface.cpp b/ConnectedInterface.cpp index 69a484b..c053aad 100644 --- a/ConnectedInterface.cpp +++ b/ConnectedInterface.cpp @@ -25,16 +25,32 @@ void ConnectedInterface::clearConnectedTo() { connectedTo.clear(); } -bool ConnectedInterface::connectTo(ConnectedInterface *iface) { - - if (canConnectTo(iface)) { - connectedTo.append(iface); - return true; +void ConnectedInterface::connectTo(ConnectedInterface *iface) { + + connectedTo.append(iface); + iface->connectedFrom = this; + ConnectedInterface* asso1 = (ConnectedInterface*)associatedIface; + ConnectedInterface* asso2 = (ConnectedInterface*)(iface->associatedIface); + if ((asso1 != NULL) && (asso2 != NULL)) { + asso1->connectedTo.append(asso2); + asso2->connectedFrom = asso1; } +} - return false; +void ConnectedInterface::disconnectTo(ConnectedInterface *iface) { + + connectedTo.removeAll(iface); + iface->connectedFrom = NULL; + ConnectedInterface* asso1 = (ConnectedInterface*)associatedIface; + ConnectedInterface* asso2 = (ConnectedInterface*)(iface->associatedIface); + if ((asso1 != NULL) && (asso2 != NULL)) { + asso1->connectedTo.removeAll(asso2); + asso2->connectedFrom = NULL; + } } + +/* bool ConnectedInterface::connectFrom(ConnectedInterface *iface) { if (canConnectFrom(iface)) { connectedFrom = iface; @@ -42,6 +58,7 @@ bool ConnectedInterface::connectFrom(ConnectedInterface *iface) { } return false; } +*/ /* getConnectionToParentGroup() : if an interface among connectedTo is an interface of the parent group diff --git a/ConnectedInterface.h b/ConnectedInterface.h index fc89e22..cfea68c 100644 --- a/ConnectedInterface.h +++ b/ConnectedInterface.h @@ -37,8 +37,9 @@ public : virtual bool canConnectFrom(AbstractInterface* iface) = 0; // others - bool connectTo(ConnectedInterface* iface); - bool connectFrom(ConnectedInterface* iface); + void connectTo(ConnectedInterface* iface); + void disconnectTo(ConnectedInterface* iface); + //bool connectFrom(ConnectedInterface* iface); ConnectedInterface* getConnectionToParentGroup(); ConnectedInterface* getConnectionFromParentGroup(); diff --git a/Dispatcher.cpp b/Dispatcher.cpp index e7846b4..238c7e5 100644 --- a/Dispatcher.cpp +++ b/Dispatcher.cpp @@ -81,12 +81,12 @@ void Dispatcher::closeCurrentProject() { sceneCounter = 0; } -bool Dispatcher::createConnectionItem(InterfaceItem *iface1, InterfaceItem *iface2) { +bool Dispatcher::createConnection(InterfaceItem *iface1, InterfaceItem *iface2) { ConnectedInterface* ref1 = iface1->refInter; ConnectedInterface* ref2 = iface2->refInter; - ConnectedInterface* asso1 = iface1->refInter->getAssociatedIface(); - ConnectedInterface* asso2 = iface2->refInter->getAssociatedIface(); + ConnectedInterface* asso1 = (ConnectedInterface*)(iface1->refInter->getAssociatedIface()); + ConnectedInterface* asso2 = (ConnectedInterface*)(iface2->refInter->getAssociatedIface()); // connect both interface bool ok1 = false; @@ -95,21 +95,25 @@ bool Dispatcher::createConnectionItem(InterfaceItem *iface1, InterfaceItem *ifac // test the ref1->ref2 connection if ((ref1->canConnectTo(ref2)) && (ref2->canConnectFrom(ref1))) { ref1->connectTo(ref2); + /* ref2->connectFrom(ref1); if ((asso1 != NULL) && (asso2 != NULL)) { asso1->connectTo(asso2); asso2->connectFrom(asso1); } + */ ok1 = true; } // if the frist one did not work, test ref2->ref1 if ((ok1 == false) && (ref2->canConnectTo(ref1)) && (ref1->canConnectFrom(ref2))) { ref2->connectTo(ref1); + /* ref1->connectFrom(ref2); if ((asso1 != NULL) && (asso2 != NULL)) { asso1->connectFrom(asso2); asso2->connectTo(asso1); } + */ ok2 = true; } if ((ok1 == true) || (ok2 == true)) { @@ -905,8 +909,7 @@ void Dispatcher::removeConnection(ConnectionItem *conn) { // process the special case source->group apart if (fromIfaceItem->getOwner()->isSourceItem()) { // remove from graph - fromInter->removeConnectedTo(toInter); - toInter->clearConnectedFrom(); + fromInter->disconnectTo(toInter); // remove from scene fromIfaceItem->removeConnectionItem(conn); toIfaceItem->removeConnectionItem(conn); @@ -931,16 +934,8 @@ void Dispatcher::removeConnection(ConnectionItem *conn) { #ifdef DEBUG cout << "removing connections from graph ..." ; #endif - if (fromInter->getDirection() == AbstractInterface::InOut) { - fromInter->clearConnectedTo(); - fromInter->clearConnectedFrom(); - toInter->clearConnectedTo(); - toInter->clearConnectedFrom(); - } - else { - fromInter->removeConnectedTo(toInter); - toInter->clearConnectedFrom(); - } + fromInter->disconnectTo(toInter); + #ifdef DEBUG cout << "done." << endl ; #endif @@ -958,6 +953,10 @@ void Dispatcher::removeConnection(ConnectionItem *conn) { #endif if (groupIfaceItem != NULL) { + + bool groupInterRemove = false; + if ((groupIfaceItem->nter->isConnectedTo() == false) && (groupInter->isConnectedFrom() == false)) groupInterRemove = true; + ConnectedInterface* groupInter = groupIfaceItem->refInter; groupItem->removeInterface(groupIfaceItem); @@ -1002,32 +1001,13 @@ void Dispatcher::connectInterToGroup(InterfaceItem *item){ // creating/adding the group control interface in the graph model GroupInterface *groupCtlInter = new GroupInterface(parentBlock,refInter->getName()+"_group_enb",refInter->getDirection(),AbstractInterface::Control); groupCtlInter->setAssociatedIface(groupInter); - parentItem->getRefBlock()->addInterface(groupCtlInter); - - // connect both interface - bool ok = true; - if (refInter->getDirection() == AbstractInterface::Output) { - ok = refInter->connectTo(groupInter); - ok = ok & groupInter->connectFrom(refInter); - } - else if (refInter->getDirection() == AbstractInterface::Input) { - ok = groupInter->connectTo(refInter); - ok = ok & refInter->connectFrom(groupInter); - } - else if (refInter->getDirection() == AbstractInterface::InOut) { - ok = refInter->connectTo(groupInter); - ok = ok & groupInter->connectFrom(refInter); - ok = ok & groupInter->connectTo(refInter); - ok = ok & refInter->connectFrom(groupInter); - } - if (!ok) { - cerr << "abnormal case while connecting a block iface to its parent group" << endl; - } + parentItem->getRefBlock()->addInterface(groupCtlInter); // creating/adding the group interface in the current scene model, and connection item InterfaceItem *groupIfaceItem = new InterfaceItem(0,item->getOrientation(),groupInter,parentItem,params); parentItem->addInterface(groupIfaceItem,true); - parentItem->getScene()->createConnectionItem(item, groupIfaceItem); + // creating the connection, in graph and with an item + createConnection(item, groupIfaceItem); // if groupItem is not topGroup, must also add a new interface to the parent BlockItem BoxItem* parent2Item = parentItem->getParentItem(); diff --git a/Dispatcher.h b/Dispatcher.h index 0ddba40..95e0183 100644 --- a/Dispatcher.h +++ b/Dispatcher.h @@ -124,7 +124,7 @@ public slots: void renameInterface(InterfaceItem* item); // connection ops - bool createConnectionItem(InterfaceItem *iface1, InterfaceItem *iface2); + bool createConnection(InterfaceItem *iface1, InterfaceItem *iface2); void removeAllBlockConnections(AbstractBoxItem *item); void removeConnection(ConnectionItem *conn); diff --git a/FunctionalInterface.cpp b/FunctionalInterface.cpp index 7224b3f..495d60e 100644 --- a/FunctionalInterface.cpp +++ b/FunctionalInterface.cpp @@ -76,10 +76,7 @@ AbstractInterface *FunctionalInterface::clone() { int id = getInterfaceMultiplicity(); if (id < 0) return NULL; FunctionalInterface *inter = new FunctionalInterface(owner, reference); - inter->setWidth(width); - inter->setDirection(direction); - inter->setPurpose(purpose); - inter->connectFrom(NULL); + inter->setWidth(width); inter->setName(reference->getName()+"_"+QString::number(id+1)); return inter; } diff --git a/GroupInterface.cpp b/GroupInterface.cpp index 6757790..934ad08 100644 --- a/GroupInterface.cpp +++ b/GroupInterface.cpp @@ -2,7 +2,7 @@ #include "FunctionalInterface.h" #include "GroupBlock.h" -GroupInterface::GroupInterface(AbstractBlock* _owner, const QString& _name, int _direction, int _purpose) throw(Exception) : ConnectedInterface(_owner,_name,AbstractInterface::Inherited,"",_direction,_purpose) { +GroupInterface::GroupInterface(AbstractBlock* _owner, const QString& _name, int _direction, int _purpose) throw(Exception) : ConnectedInterface(_owner,_name,"inherited","",_direction,_purpose) { if (! _owner->isGroupBlock()) throw(Exception(BLOCK_INVALID_TYPE)); connectedFrom = NULL; @@ -14,9 +14,7 @@ bool GroupInterface::isGroupInterface() { AbstractInterface *GroupInterface::clone() { GroupInterface *inter = new GroupInterface(owner,name,direction, purpose); - inter->setWidth(width); - inter->connectFrom(NULL); - + inter->setWidth(width); return inter; } diff --git a/GroupItem.cpp b/GroupItem.cpp index 90c5574..27f539c 100644 --- a/GroupItem.cpp +++ b/GroupItem.cpp @@ -448,7 +448,7 @@ void GroupItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { else if (params->editState == Parameters::EditCloseConnection) { InterfaceItem* iface1 = getScene()->getSelectedInterface(1); InterfaceItem* iface2 = getScene()->getSelectedInterface(2); - bool ok = dispatcher->createConnectionItem(iface1,iface2); + bool ok = dispatcher->createConnection(iface1,iface2); if (ok) { iface1->selected = false; update(iface1->boundingRect()); diff --git a/Parameters.cpp b/Parameters.cpp index 12f5b2b..848ef7f 100644 --- a/Parameters.cpp +++ b/Parameters.cpp @@ -367,7 +367,7 @@ GroupWidget *Parameters::loadProject(QDomElement root) throw(Exception) { InterfaceItem *iface2 = searchInterfaceItemById(to,topScene); if(iface1 != NULL && iface2 != NULL){ - dispatcher->createConnectionItem(iface1,iface2); + dispatcher->createConnection(iface1,iface2); } else { cout << "interfaces not found, connect canceled!" << endl; } diff --git a/SourceItem.cpp b/SourceItem.cpp index 4f29761..62f601a 100644 --- a/SourceItem.cpp +++ b/SourceItem.cpp @@ -389,7 +389,7 @@ void SourceItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { else if (params->editState == Parameters::EditCloseConnection) { InterfaceItem* iface1 = getScene()->getSelectedInterface(1); InterfaceItem* iface2 = getScene()->getSelectedInterface(2); - bool ok = dispatcher->createConnectionItem(iface1,iface2); + bool ok = dispatcher->createConnection(iface1,iface2); if (ok) { iface1->selected = false; update(iface1->boundingRect()); diff --git a/blast.creator.user b/blast.creator.user index 8878024..5d3c6f4 100755 --- a/blast.creator.user +++ b/blast.creator.user @@ -1,10 +1,10 @@ - + EnvironmentId - {1d077e47-e3a1-47fd-8b12-4de650e39df5} + {c8006d66-d34f-42be-ad10-d0207752286d} ProjectExplorer.Project.ActiveTarget @@ -60,12 +60,12 @@ Desktop Desktop - {451ee8a3-56ff-4aba-8a8e-3da882cc142e} + {2c9bf876-3476-44eb-8065-1f0844704dda} 0 0 0 - /localhome/sdomas/Projet/Blast/code/blast + /home/sdomas/Projet/Blast/code/blast @@ -162,10 +162,10 @@ 2 - blast + false %{buildDir} - Exécuter blast + Exécutable personnalisé ProjectExplorer.CustomExecutableRunConfiguration 3768 -- 2.39.5