\r
// getters\r
inline QString getName() { return name; }\r
+ inline int nbParameters() { return params.size(); }\r
inline QList<BlockParameter *> getParameters() { return params; }\r
inline QList<AbstractInterface*> getInputs() { return inputs; }\r
inline QList<AbstractInterface*> getOutputs() { return outputs; }\r
int mode = getScene()->getEditionMode();
- dispatcher->setCurrentGroupWidget(getScene()->getGroupWindow());
+ dispatcher->setCurrentGroupWidget(getScene()->getGroupWidget());
if ((mode == GroupScene::AddConnection) && (params->cursorState == Parameters::CursorOnInterface)) {
InterfaceItem *inter = getInterfaceFromCursor(x,y);
params->setEditState(Parameters::EditNoOperation);
}
else {
+ //QMessageBox::warning(NULL,"Error","Cannot connect selected interfaces", QMessageBox::Ok);
getScene()->setSelectedInterface(2,NULL);
params->setEditState(Parameters::EditStartConnection);
}
void BoxItem::contextMenuEvent(QGraphicsSceneContextMenuEvent * event) {
QMenu menu;
- QAction* removeAction = menu.addAction("Remove");
- QAction* duplicateAction = menu.addAction("Duplicate");
- QAction* renameAction = menu.addAction("Rename");
+ QAction* titleAction = NULL;
+ QAction* removeAction = NULL;
+ QAction* duplicateAction = NULL;
+ QAction* renameAction = NULL;
QAction* connectToGroup = NULL;
QAction* disconnectFromGroup = NULL;
QAction* showProperties = NULL;
QAction* showParameters = NULL;
InterfaceItem* ifaceItem = getInterfaceFromCursor(event->pos().x(), event->pos().y());
+ // menu for interface
if( ifaceItem != NULL){
+
+ titleAction = menu.addAction("Interface operations");
+ titleAction->setEnabled(false);
+ menu.addSeparator();
+
+
showProperties = menu.addAction("Show properties");
+ renameAction = menu.addAction("Rename");
ConnectedInterface* iface = ifaceItem->refInter;
ConnectedInterface* ifaceGroup = NULL;
+ bool canRemove = true;
if ((iface->getDirection() == AbstractInterface::Input) && (iface->getConnectedFrom() == NULL)) {
connectToGroup = menu.addAction("Connect to group input");
}
- else if ((iface->getDirection() == AbstractInterface::Output) && (!iface->isConnectedTo())) {
+ else if ((iface->getDirection() == AbstractInterface::Output) && (iface->getConnectionToParentGroup() == NULL)) {
connectToGroup = menu.addAction("Connect to group output");
}
else if (iface->getConnectionFromParentGroup() != NULL) {
ifaceGroup = iface->getConnectionFromParentGroup();
- if ((!ifaceGroup->isConnectedFrom()) || (!ifaceGroup->isConnectedTo())) {
+ //if ((!ifaceGroup->isConnectedFrom()) || (!ifaceGroup->isConnectedTo())) {
+ if (!ifaceGroup->isConnectedFrom()) {
disconnectFromGroup = menu.addAction("Disconnect from group");
}
+ else {
+ canRemove = false;
+ }
}
else if (iface->getConnectionToParentGroup() != NULL) {
ifaceGroup = iface->getConnectionToParentGroup();
- if ((!ifaceGroup->isConnectedFrom()) || (!ifaceGroup->isConnectedTo())) {
+ //if ((!ifaceGroup->isConnectedFrom()) || (!ifaceGroup->isConnectedTo())) {
+ if (!ifaceGroup->isConnectedTo()) {
disconnectFromGroup = menu.addAction("Disconnect from group");
}
+ else {
+ canRemove = false;
+ }
}
if (iface->isFunctionalInterface()) {
FunctionalInterface* fi = AI_TO_FUN(ifaceItem->refInter);
ReferenceInterface* ri = (ReferenceInterface*)(fi->getReference());
if(ri->getMultiplicity() == -1 || ri->getMultiplicity() > 1){
- cloneInterface = menu.addAction("Clone interface");
- }
+ cloneInterface = menu.addAction("Duplicate");
+ if ((canRemove) && (fi->getInterfaceMultiplicity() > 1)) {
+ removeAction = menu.addAction("Remove");
+ }
+ }
}
}
- if(refBlock->isGroupBlock()){
- openWindow = menu.addAction("Open/show group window");
- } else {
- showRstClkInter = menu.addAction("Show reset/clock interfaces");
- showRstClkInter->setCheckable(true);
- showRstClkInter->setChecked(rstClkVisible);
+ // menu for blocks (group or func)
+ else {
+ titleAction = menu.addAction("Block operations");
+ titleAction->setEnabled(false);
+ menu.addSeparator();
+
+ if (refBlock->nbParameters() > 0) {
+ showParameters = menu.addAction("Show parameters");
+ }
+ renameAction = menu.addAction("Rename");
- showParameters = menu.addAction("Show parameters");
+ if(refBlock->isGroupBlock()){
+ openWindow = menu.addAction("Open/show group window");
+ }
+ else {
+ duplicateAction = menu.addAction("Duplicate");
+ showRstClkInter = menu.addAction("Show reset/clock interfaces");
+ showRstClkInter->setCheckable(true);
+ showRstClkInter->setChecked(rstClkVisible);
+ }
+ removeAction = menu.addAction("Remove");
}
QAction* selectedAction = NULL;
if(selectedAction == NULL) return ;
if (selectedAction == removeAction) {
- dispatcher->removeBlock(this);
+ if(ifaceItem != NULL) {
+ dispatcher->removeBlockInterface(ifaceItem);
+ }
+ else {
+ dispatcher->removeBlock(this);
+ }
}
else if (selectedAction == duplicateAction) {
dispatcher->duplicateBlock(this);
}
else if(selectedAction == renameAction){
if(ifaceItem != NULL)
- dispatcher->rename(ifaceItem);
+ dispatcher->renameInterface(ifaceItem);
else
- dispatcher->rename(this);
+ dispatcher->renameBlockOrGroup(this);
}
else if(selectedAction == showProperties){
dispatcher->showProperties(ifaceItem);
}
void ConnectionItem::contextMenuEvent(QGraphicsSceneContextMenuEvent * event) {
- QMenu menu;
- QAction* removeAction = menu.addAction("Remove");
- QAction * selectedAction= menu.exec(event->screenPos());
+ /* have to check if the connection can be removed.
+ If the from or to InterfaceItem is owned by a group item, and this item
+ is both connected to and from, thus it is impossible to remove this connection
+ */
+ bool canRemove = true;
+ InterfaceItem* groupIfaceItem = NULL;
+ if (fromInterfaceItem->getOwner()->isGroupItem()) {
+ groupIfaceItem = fromInterfaceItem;
+ }
+ else if (toInterfaceItem->getOwner()->isGroupItem()) {
+ groupIfaceItem = toInterfaceItem;
+ }
+
+ if (groupIfaceItem != NULL) {
+ ConnectedInterface* ref = groupIfaceItem->refInter;
+ if ((ref->isConnectedFrom()) && (ref->isConnectedTo())) {
+ canRemove = false;
+ }
+ }
- if(selectedAction == removeAction){
- dispatcher->removeConnection(this);
- dispatcher->removeUselessGroupInterfaces();
+ if (canRemove) {
+ QMenu menu;
+ QAction* titleAction = menu.addAction("Connection operations");
+ titleAction->setEnabled(false);
+ menu.addSeparator();
+ QAction* removeAction = menu.addAction("Remove");
+ QAction * selectedAction= menu.exec(event->screenPos());
+
+ if(selectedAction == removeAction){
+ dispatcher->removeConnection(this);
+ }
}
}
class Dispatcher;
class Parameters;
class InterfaceItem;
+class GroupScene;
using namespace std;
using namespace Qt;
void prepareChange();
+ inline GroupScene* getScene() { return (GroupScene*)(scene()); }
inline InterfaceItem* getToInterfaceItem(){ return toInterfaceItem; }
inline void setToInterfaceItem(InterfaceItem *iface){ toInterfaceItem = iface; }
inline InterfaceItem* getFromInterfaceItem(){ return fromInterfaceItem; }
*/
}
-void Dispatcher::rename(AbstractBoxItem *item){
+void Dispatcher::renameBlockOrGroup(AbstractBoxItem *item){
+ static QString fctName = "Dispatcher::renameBlockOrGroup()";
+#ifdef DEBUG_FCTNAME
+ cout << "call to " << qPrintable(fctName) << endl;
+#endif
bool ok;
- QString text = QInputDialog::getText(NULL, "Rename an element",
+ QString text = QInputDialog::getText(NULL, "Rename an block/group",
"New name:", QLineEdit::Normal,
item->getRefBlock()->getName(), &ok);
QMessageBox::warning(NULL,"Error in given name",
"the element name must be shorter than 30 characters and can't be empty!",
QMessageBox::Ok);
- rename(item);
+ renameBlockOrGroup(item);
}
}
}
-void Dispatcher::rename(InterfaceItem *item){
+void Dispatcher::renameInterface(InterfaceItem *item) {
+ static QString fctName = "Dispatcher::renameInterface()";
+#ifdef DEBUG_FCTNAME
+ cout << "call to " << qPrintable(fctName) << endl;
+#endif
+
bool ok;
QString text = QInputDialog::getText(NULL, "Rename an interface",
"New name:", QLineEdit::Normal,
QMessageBox::warning(NULL,"Error in given name",
"the interface name must be shorter than 30 characters and can't be empty!",
QMessageBox::Ok);
- rename(item);
+ renameInterface(item);
}
}
void Dispatcher::duplicateBlock(BoxItem *item){
+ static QString fctName = "Dispatcher::duplicateBlock()";
+#ifdef DEBUG_FCTNAME
+ cout << "call to " << qPrintable(fctName) << endl;
+#endif
- GroupScene *scene = params->getCurrentScene();
+ GroupScene *scene = item->getScene();
AbstractBlock* block = item->getRefBlock();
AbstractBlock *newBlock;
}
}
-void Dispatcher::duplicateInterface(InterfaceItem *item){
+void Dispatcher::duplicateInterface(InterfaceItem *item) {
+ static QString fctName = "Dispatcher::duplicateInterface()";
+#ifdef DEBUG_FCTNAME
+ cout << "call to " << qPrintable(fctName) << endl;
+#endif
+
AbstractInterface *refI = item->refInter;
if (! refI->isFunctionalInterface()) return;
void Dispatcher::addBlock(int idCategory, int idBlock, int idScene) {
+ static QString fctName = "Dispatcher::addBlock()";
+#ifdef DEBUG_FCTNAME
+ cout << "call to " << qPrintable(fctName) << endl;
+#endif
GroupScene *scene = searchSceneById(idScene);
- FunctionalBlock* newOne = params->addFunctionalBlock(idCategory, idBlock);
+ ReferenceBlock* ref = params->getReferenceBlock(idCategory,idBlock);
+ GroupBlock* group = AB_TO_GRP(scene->getGroupItem()->getRefBlock());
+ FunctionalBlock* newOne = params->getGraph()->addFunctionalBlock(group, ref);
scene->createBlockItem(newOne);
+ params->unsaveModif = true;
}
GroupWidget *Dispatcher::createTopScene(){
+ static QString fctName = "Dispatcher::createTopScene()";
+#ifdef DEBUG_FCTNAME
+ cout << "call to " << qPrintable(fctName) << endl;
+#endif
// creating the model part of the group
Graph* graph = params->createGraph();
return topGroup;
}
+void Dispatcher::addNewEmptyGroup(GroupScene* scene) {
+ static QString fctName = "Dispatcher::addNewEmptyGroup();";
+#ifdef DEBUG_FCTNAME
+ cout << "call to " << qPrintable(fctName) << endl;
+#endif
+
+ // getting the parent block in the graph
+ GroupBlock* parent = AB_TO_GRP(scene->getGroupItem()->getRefBlock());
+ cout << "new group : parent = "<< qPrintable(parent->getName()) << endl;
+ GroupBlock* groupBlock = params->getGraph()->createChildBlock(parent);
+ cout << "new group : child = "<< qPrintable(groupBlock->getName()) << ", child of " << qPrintable(groupBlock->getParent()->getName()) << endl;
+ // creating the BlockItem in the scene
+ BoxItem* newItem = scene->createBlockItem(groupBlock);
+
+ params->unsaveModif = true;
+
+ GroupWidget* child = createChildScene(scene->getGroupWidget(),newItem);
+ child->show();
+
+}
+
GroupWidget *Dispatcher::createChildScene(GroupWidget* parentWidget, BoxItem *upperItemOfGroupItem) {
+ static QString fctName = "Dispatcher::createChildScene()";
+#ifdef DEBUG_FCTNAME
+ cout << "call to " << qPrintable(fctName) << endl;
+#endif
// getting back the goup block already created
GroupBlock* groupBlock = NULL;
return group;
}
-void Dispatcher::showRaiseWindow(AbstractBoxItem *item) {
- GroupWidget* win = item->getScene()->getGroupWindow();
- if (win->isTopGroup()) {
- mainWindow->show();
- mainWindow->raise();
+void Dispatcher::destroyScene(GroupScene *scene) {
+ foreach(GroupScene* s, scene->getChildrenScene()) {
+ destroyScene(s);
+ }
+
+ if (scene->getNbChildScene() == 0) {
+ // remove scene from the parent list
+ scene->getParentScene()->removeChildScene(scene);
+ // destroy the GroupWidget
+ groupList.removeAll(scene->getGroupWidget());
+ scene->getGroupWidget()->deleteLater();
}
else {
- win->show();
- win->raise();
+ cerr << "Abnormal case when destroying a scene" << endl;
+ }
+}
+
+void Dispatcher::showRaiseWindow(BoxItem *item) {
+ static QString fctName = "Dispatcher::showRaiseWindow()";
+#ifdef DEBUG_FCTNAME
+ cout << "call to " << qPrintable(fctName) << endl;
+#endif
+
+ cout << "raising child scene of " << qPrintable(item->getRefBlock()->getName()) << endl;
+ GroupItem* child = item->getChildGroupItem();
+ if (child == NULL) {
+ cerr << "abnormal case: child group item is null " << endl;
+ return;
}
+
+ GroupWidget* win = child->getScene()->getGroupWidget();
+
+ win->showNormal();
+ win->raise();
+ win->activateWindow();
+
currentGroup = win;
params->setCurrentScene(currentGroup->getScene());
}
void Dispatcher::showRstClkInter(AbstractBoxItem *item) {
+ static QString fctName = "Dispatcher::showRstClkInter()";
+#ifdef DEBUG_FCTNAME
+ cout << "call to " << qPrintable(fctName) << endl;
+#endif
item->setRstClkVisible(!item->isRstClkVisible());
item->resetInterfacesPosition();
}
void Dispatcher::addNewFullGroup() {
+ static QString fctName = "Dispatcher::addNewFullGroup()";
+#ifdef DEBUG_FCTNAME
+ cout << "call to " << qPrintable(fctName) << endl;
+#endif
+
#ifdef DEBUG_INCLFUN
#endif
}
-void Dispatcher::removeBlock(AbstractBoxItem *item) {
-
-#ifdef DEBUG_INCLFUN
-
- GroupScene *scene = params->getCurrentScene();
- AbstractBlock* block = item->getRefBlock();
- if (block->isReferenceBlock()) return;
-
- GroupBlock* group = (GroupBlock*)item->getParentItem()->getRefBlock();
+void Dispatcher::removeBlock(BoxItem *item) {
+ static QString fctName = "Dispatcher::removeBlock()";
+#ifdef DEBUG_FCTNAME
+ cout << "call to " << qPrintable(fctName) << endl;
+#endif
- removeConnections(item);
+ /* a BoxItem (group of func) can be removed only if none of its
+ interfaces is connected to a group interface that is itself
+ connected to another one.
+ */
+ bool canRemove = true;
- //récupérer l'objet
- group->removeBlock(block);
+ foreach(InterfaceItem* ifaceItem, item->getInterfaces()) {
+ foreach(ConnectionItem* conn, ifaceItem->connections) {
+ InterfaceItem* other = NULL;
+ if (conn->getFromInterfaceItem() == ifaceItem) {
+ other = conn->getToInterfaceItem();
+ }
+ else {
+ other = conn->getFromInterfaceItem();
+ }
- //remove the associated window
- if(block->isGroupBlock()){
- foreach(QWidget *window, params->windows){
- if(!window->inherits("MainWindow")){
- if(((GroupWidget*)window)->getScene()->getGroupItem()->getRefBlock() == block){
- params->removeWindow(window);
- delete window;
+ if (other->getOwner()->isGroupItem()) {
+ ConnectedInterface* ref = other->refInter;
+ if ((ref->isConnectedFrom()) && (ref->isConnectedTo())) {
+ canRemove = false;
}
}
}
}
+ if (!canRemove) {
+ QMessageBox::warning(NULL,"Forbidden operation",
+ "The block has at least one connection to a group interface that is totally connected.",
+ QMessageBox::Ok);
+ return;
+ }
- delete block;
+ QString msg = "";
+ if (item->getRefBlock()->isFunctionalBlock()) {
+ msg = "Removing block ";
+ }
+ else {
+ msg = "Removing group ";
+ }
+ msg += item->getRefBlock()->getName();
+ msg += " and all its connections.\n\nAre you sure ?";
- //supprimer l'item de la scène
- cout << "dispatcher : remove item of scene " << params->currentWindow << endl;
- ((GroupItem *)scene->getGroupItem())->removeBlockItem(item);
- scene->removeItem(item);
- scene->removeBlockItem(item);
- delete item;
+ int ret = QMessageBox::question(NULL,"Removing functional block",msg, QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Ok);
+ if (ret == QMessageBox::Cancel) {
+ return;
+ }
+ removeAllBlockConnections(item);
- ((GroupItem *)scene->getGroupItem())->updateShape();
+ if (item->getRefBlock()->isFunctionalBlock()) {
+ FunctionalBlock* block = AB_TO_FUN(item->getRefBlock());
+ GroupBlock* group = AB_TO_GRP(block->getParent());
+ item->getScene()->removeBlockItem(item);
+ params->getGraph()->removeFunctionalBlock(block,group);
+ }
+ else if (item->getRefBlock()->isGroupBlock()) {
- params->updateToolbar();
- params->unsaveModif = true;
+ GroupBlock* group = AB_TO_GRP(item->getRefBlock());
-#endif
+ // remove all child scenes recursively
+ GroupItem* subgroup = item->getChildGroupItem();
+ destroyScene(subgroup->getScene());
+ // remove the BoxItem
+ item->getScene()->removeBlockItem(item);
+ // remove the group from the graph
+ params->getGraph()->removeGroupBlock(group);
+ }
}
-void Dispatcher::removeAllBlockConnections(AbstractBoxItem *block) {
+void Dispatcher::removeAllBlockConnections(BoxItem *item) {
+ static QString fctName = "Dispatcher::removeAllBlockConnection()";
+#ifdef DEBUG_FCTNAME
+ cout << "call to " << qPrintable(fctName) << endl;
+#endif
- GroupScene* scene = block->getScene();
- // supprimer les connections associées au bloc
- foreach (ConnectionItem *conn, scene->getConnectionItems()) {
- if(conn->getToInterfaceItem()->owner == block || conn->getFromInterfaceItem()->owner == block){
+ foreach(InterfaceItem* ifaceItem, item->getInterfaces()) {
+ foreach(ConnectionItem* conn, ifaceItem->connections) {
removeConnection(conn);
}
}
- scene->getGroupItem()->updateInterfacesAndConnections();
}
void Dispatcher::removeConnection(ConnectionItem *conn) {
+ static QString fctName = "Dispatcher::removeConnection()";
+#ifdef DEBUG_FCTNAME
+ cout << "call to " << qPrintable(fctName) << endl;
+#endif
+ InterfaceItem* fromIfaceItem = conn->getFromInterfaceItem();
+ InterfaceItem* toIfaceItem = conn->getToInterfaceItem();
- GroupScene *scene = params->getCurrentScene();
- GroupItem* currentGroup = scene->getGroupItem();
+#ifdef DEBUG
+ cout << "remove connection from " << qPrintable(fromIfaceItem->refInter->getName()) << " to " << qPrintable(toIfaceItem->refInter->getName()) << endl;
+#endif
+
+ InterfaceItem* groupIfaceItem = NULL; // in case of one of the two interface belongs to the GroupItem
+ GroupItem* groupItem = NULL;
- conn->getFromInterfaceItem()->unconnectTo(conn->getToInterfaceItem());
+ if (fromIfaceItem->getOwner()->isGroupItem()) {
+ groupIfaceItem = fromIfaceItem;
+ groupItem = toIfaceItem->getOwner()->getScene()->getGroupItem();
+ }
+ else if (toIfaceItem->getOwner()->isGroupItem()) {
+ groupIfaceItem = toIfaceItem;
+ groupItem = fromIfaceItem->getOwner()->getScene()->getGroupItem();
+ }
+ else {
+ groupItem = fromIfaceItem->getOwner()->getScene()->getGroupItem();
+ }
- scene->removeConnectionItem(conn);
- delete conn;
+ // removing the connection from graph
+#ifdef DEBUG
+ cout << "removing connections from graph ..." ;
+#endif
+ ConnectedInterface *fromInter = fromIfaceItem->refInter;
+ ConnectedInterface *toInter = toIfaceItem->refInter;
+ if (fromInter->getDirection() == AbstractInterface::InOut) {
+ fromInter->clearConnectedTo();
+ fromInter->clearConnectedFrom();
+ toInter->clearConnectedTo();
+ toInter->clearConnectedFrom();
+ }
+ else {
+ fromInter->removeConnectedTo(toInter);
+ toInter->clearConnectedFrom();
+ }
+#ifdef DEBUG
+ cout << "done." << endl ;
+#endif
- currentGroup->updateInterfacesAndConnections();
- params->unsaveModif = true;
-}
+ // removing the connection from scene
+#ifdef DEBUG
+ cout << "removing connections from scene ..." ;
+#endif
+ fromIfaceItem->removeConnectionItem(conn);
+ toIfaceItem->removeConnectionItem(conn);
+ groupItem->getScene()->removeConnectionItem(conn);
-void Dispatcher::removeUselessGroupInterfaces() {
+#ifdef DEBUG
+ cout << "done." << endl ;
+#endif
- GroupScene *scene = params->getCurrentScene();
- GroupItem* currentGroup = scene->getGroupItem();
+ if (groupIfaceItem != NULL) {
+ ConnectedInterface* groupInter = groupIfaceItem->refInter;
+ groupItem->removeInterface(groupIfaceItem);
- foreach(InterfaceItem *inter, currentGroup->getInterfaces()) {
- if(inter->refInter->getConnectedTo().length() == 0) {
- // NB : remove from view also remove from model
- currentGroup->removeInterface(inter);
+ BoxItem* parent2Item = groupItem->getParentItem();
+ if (parent2Item != NULL) {
+ InterfaceItem* group2IfaceItem = parent2Item->searchInterfaceByRef(groupInter);
+ parent2Item->removeInterface(group2IfaceItem);
}
+ groupInter->getOwner()->removeInterface(groupInter);
}
- scene->updateConnectionItemsShape();
}
void Dispatcher::showBlocksLibrary(){
if (refInter->getDirection() == AbstractInterface::Output) {
groupInter = refInter->getConnectionToParentGroup(); // must be a single connection to
- refInter->clearConnectedTo();
+ refInter->removeConnectedTo(groupInter);
groupInter->clearConnectedFrom();
}
else if (refInter->getDirection() == AbstractInterface::Input) {
#endif
}
+void Dispatcher::removeBlockInterface(InterfaceItem *item) {
+ static QString fctName = "Dispatcher::removeBlockInterface()";
+#ifdef DEBUG_FCTNAME
+ cout << "call to " << qPrintable(fctName) << endl;
+#endif
+
+ /* first, remove all connections from item
+ NB: if there is a connection to a group interface, then this
+ method should not be called if the group interface is also
+ connected to another interface. Normally, this is not possible
+ because such a check is done when creating the contextual menu
+ that allows to remove an interface.
+ */
+ foreach(ConnectionItem* conn, item->connections) {
+ removeConnection(conn);
+ }
+
+ ConnectedInterface* ref = item->refInter;
+ item->getOwner()->removeInterface(item);
+ FunctionalBlock* fun = AB_TO_FUN(ref->getOwner());
+ fun->removeInterface(ref);
+}
void Dispatcher::removeGroupInterface(InterfaceItem *item) {
static QString fctName = "Dispatcher::removeGroupInterface()";
void unselectAllItems(int direction=0);
void setCurrentGroupWidget(GroupWidget *win);
void changeConnectionMode(int mode = -1);
- void rename(AbstractBoxItem* item);
- void rename(InterfaceItem* item);
+
+
GroupWidget* createTopScene();
GroupWidget* createChildScene(GroupWidget* parentWidget, BoxItem* upperItemOfGroupItem = NULL);
- void showRaiseWindow(AbstractBoxItem *item);
+ void destroyScene(GroupScene* scene);
+ void showRaiseWindow(BoxItem *item);
void showRstClkInter(AbstractBoxItem *item);
- void addNewEmptyGroup();
+ void addNewEmptyGroup(GroupScene *scene);
void addNewFullGroup();
inline GroupWidget* getCurrentGroup() { return currentGroup; }
GroupItem* searchGroupItemById(int id);
InterfaceItem* searchInterfaceItemById(int id);
- void removeBlock(AbstractBoxItem* item);
+ // block ops
+ void addBlock(int idCategory, int idBlock, int idScene);
+ void removeBlock(BoxItem* item);
void duplicateBlock(BoxItem* item);
+ void renameBlockOrGroup(AbstractBoxItem* item);
+
+ // interface ops
+ /*!
+ * \brief connectInterToGroup
+ * \param item item is always owned by a BoxItem
+ *
+ * This method is called only when the user right clicks on an InterfaceItem (that belongs
+ * to a BoxItem and if it is NOT connected to an InterfaceItem of the GroupItem) and chooses
+ * connect to group in the contextual menu.
+ * Thus, parameter item is always owned by a BoxItem
+ */
+ void connectInterToGroup(InterfaceItem* item);
+ /*!
+ * \brief disconnectInterFromGroup
+ * \param item item is always owned by a BoxItem
+ *
+ * This method is called only when the user right clicks on an InterfaceItem (that belongs
+ * to a BoxItem and if it IS connected to an InterfaceItem of the GroupItem) and chooses
+ * disconnect from group in the contextual menu.
+ * Thus, parameter item is always owned by a BoxItem
+ */
+ void disconnectInterFromGroup(InterfaceItem* item);
+ /*!
+ * \brief removeBlockInterface
+ * \param item item is always owned by a BoxItem
+ *
+ * This method is called only when the user right clicks on an InterfaceItem (that belongs
+ * to a BoxItem and has a multiplicity > 1) and chooses remove in the contextual menu.
+ * Thus, parameter item is always owned by a BoxItem
+ */
+ void removeBlockInterface(InterfaceItem* item);
+ /*!
+ * \brief removeGroupInterface
+ * \param item item is always owned by a GroupItem
+ *
+ * This method is called only when the user right clicks on an InterfaceItem (that belongs
+ * to a GroupItem and if it is connected only to an inner interface) and chooses remove in the contextual menu.
+ * Thus, parameter item is always owned by a GroupItem
+ */
+ void removeGroupInterface(InterfaceItem* item);
void duplicateInterface(InterfaceItem* item);
- void addBlock(int idCategory, int idBlock, int idScene);
+ void showProperties(InterfaceItem *inter);
+ void renameInterface(InterfaceItem* item);
+
+ // connection ops
ConnectionItem *addConnection(InterfaceItem *input, InterfaceItem *output);
- void removeAllBlockConnections(AbstractBoxItem *block);
+ void removeAllBlockConnections(BoxItem *item);
void removeConnection(ConnectionItem *conn);
- void removeUselessGroupInterfaces();
+
+
+ // others
void showBlocksLibrary();
- void showProperties(InterfaceItem *inter);
- void connectInterToGroup(InterfaceItem* item);
- void disconnectInterFromGroup(InterfaceItem* item);
- void removeGroupInterface(InterfaceItem* item);
- void addConnection();
void closeCurrentProject();
return -1;\r
}\r
else if ( reference->getMultiplicity() == -1) {\r
- return ifaceCount+1;\r
+ return ifaceCount;\r
}\r
- else if ( reference->getMultiplicity() > ifaceCount) {\r
- return ifaceCount+1;\r
+ else if ( ifaceCount < reference->getMultiplicity()) {\r
+ return ifaceCount;\r
}\r
return -1;\r
}\r
inter->setPurpose(purpose);\r
inter->setLevel(level); \r
inter->connectFrom(NULL);\r
- inter->setName(reference->getName()+"_"+QString::number(id));\r
+ inter->setName(reference->getName()+"_"+QString::number(id+1));\r
return inter;\r
}\r
\r
return newBlock;
}
+
+bool Graph::removeFunctionalBlock(FunctionalBlock* block, GroupBlock *group) {
+ group->removeBlock(block);
+}
+
+bool Graph::removeGroupBlock(GroupBlock *group) {
+ group->removeAllBlocks();
+ GroupBlock* parent = AB_TO_GRP(group->getParent());
+ parent->removeBlock(group);
+}
GroupBlock* createChildBlock(GroupBlock* parent);
FunctionalBlock* addFunctionalBlock(GroupBlock *group, ReferenceBlock *ref);
+ bool removeFunctionalBlock(FunctionalBlock* block, GroupBlock *group);
+ bool removeGroupBlock(GroupBlock *group);
private:
GroupBlock* topGroup;
topGroup = false;
}
}
+void GroupBlock::removeAllBlocks() {
+ foreach(AbstractBlock* block, blocks) {
+ if (block->isGroupBlock()) {
+ GroupBlock* group = AB_TO_GRP(block);
+ group->removeAllBlocks();
+ }
+ removeBlock(block);
+ }
+}
void GroupBlock::removeBlock(AbstractBlock* block) {
- blocks.removeAll(block);
+ /* CAUTION: no check is done if the block has connected interface
+ or not. Thus, they must be deleted elsewhere.
+ */
+ blocks.removeAll(block);
+ delete block;
}
void GroupBlock::parametersValidation(QList<AbstractBlock *> *checkedBlocks, QList<AbstractBlock *> *blocksToConfigure) {
virtual ~GroupBlock();
// getters
-
+ inline QList<AbstractBlock*> getBlocks() { return blocks; }
// setters
void setParent(AbstractBlock *_parent);
// others
inline void addBlock(AbstractBlock* block) { blocks.append(block); }
void removeBlock(AbstractBlock* block);
+ void removeAllBlocks();
void parametersValidation(QList<AbstractBlock *> *checkedBlocks, QList<AbstractBlock*>* blocksToConfigure);
void addGenericParameter(QString name, QString type, QString value);
void removeGenericParameter(QString name);
private:
bool topGroup;
- QList<AbstractBlock*> blocks; // contains instances of FunctionalBlock or GroupBlock
+ QList<AbstractBlock*> blocks; // contains instances of FunctionalBlock or GroupBlock that are children of this group
};
#include "AbstractInterface.h"
#include "ConnectedInterface.h"
#include "GroupScene.h"
+#include "ParametersWindow.h"
GroupItem::GroupItem(BoxItem *_parentItem,
Parameters *_params) throw(Exception) :AbstractBoxItem( _refBlock, _dispatcher, _params) {
parentItem = _parentItem;
+ if (parentItem != NULL) {
+ parentItem->setChildGroupItem(this);
+ }
/*
minimumBoxWidth = nameWidth+2*nameMargin;
int mode = getScene()->getEditionMode();
- dispatcher->setCurrentGroupWidget(getScene()->getGroupWindow());
+ dispatcher->setCurrentGroupWidget(getScene()->getGroupWidget());
/* NOTE : commneted because group interface are normally
created and the connected directly to a block within
void GroupItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
QMenu menu;
+ QAction* titleAction = NULL;
QAction* showProperties = NULL;
QAction* removeAction = NULL;
QAction* renameAction = NULL;
+ QAction* showParameters = NULL;
InterfaceItem* ifaceItem = getInterfaceFromCursor(event->pos().x(), event->pos().y());
- if( ifaceItem != NULL){
+
+ // menu for interface
+ if( ifaceItem != NULL) {
+ titleAction = menu.addAction("Interface operations");
+ titleAction->setEnabled(false);
+ menu.addSeparator();
showProperties = menu.addAction("Show properties");
renameAction = menu.addAction("Rename");
menu.addSeparator();
}
}
else {
+ titleAction = menu.addAction("Block operations");
+ titleAction->setEnabled(false);
+ menu.addSeparator();
+
+ if (refBlock->nbParameters() > 0) {
+ showParameters = menu.addAction("Show parameters");
+ }
renameAction = menu.addAction("Rename");
}
QAction* selectedAction = menu.exec(event->screenPos());
if(selectedAction == renameAction){
if(ifaceItem != NULL)
- dispatcher->rename(ifaceItem);
+ dispatcher->renameInterface(ifaceItem);
else
- dispatcher->rename(this);
+ dispatcher->renameBlockOrGroup(this);
}
else if(selectedAction == showProperties){
dispatcher->showProperties(ifaceItem);
- }
+ }
else if (selectedAction == removeAction) {
dispatcher->removeGroupInterface(ifaceItem);
}
+ else if(selectedAction == showParameters) {
+ new ParametersWindow(refBlock, params, NULL);
+ }
}
InterfaceItem* GroupItem::isHoverInterface(QPointF point) {
inline QList<BoxItem*> getBlockItems() { return blockItems; }
inline QList<ConnectionItem*> getConnectionItems() { return connectionItems; }
inline QList<GroupScene*> getChildrenScene() { return childrenScene; }
- inline GroupWidget* getGroupWindow() { return window; }
+ inline GroupScene* getParentScene() { return parentScene; }
+ inline GroupWidget* getGroupWidget() { return window; }
inline int getId() { return id; }
inline EditMode getEditionMode() { return editMode; }
InterfaceItem* getSelectedInterface(int id);
void removeConnectionItem(ConnectionItem* item);
void removeGroupItem();
inline void addChildScene(GroupScene* child) { childrenScene.append(child); }
+ inline void removeChildScene(GroupScene* child) { childrenScene.removeAll(child); }
+ inline int getNbChildScene() { return childrenScene.size(); }
void unselecteInterfaces();
QList<AbstractBoxItem*> getGroupAndBlocks();
private:
Dispatcher *dispatcher;
Parameters *params;
- GroupScene* parentScene; // the parnet scene, =NULL for top scene
+ GroupScene* parentScene; // the parent scene, =NULL for top scene
GroupWidget* window; // the GroupWindow that contains that scene
int id;
GroupItem *groupItem; // mandatory to be an instance of GroupItem.
void GroupWidget::closeEvent(QCloseEvent *e) {
clearFocus();
focusNextChild();
+
}
void GroupWidget::slotNewEmptyGroup() {
- // creating the GroupBlock in graph model
- GroupBlock* parent = AB_TO_GRP(scene->getGroupItem()->getRefBlock());
- cout << "new group : parent = "<< qPrintable(parent->getName()) << endl;
- GroupBlock* groupBlock = params->getGraph()->createChildBlock(parent);
- cout << "new group : child = "<< qPrintable(groupBlock->getName()) << ", child of " << qPrintable(groupBlock->getParent()->getName()) << endl;
- // creating the BlockItem in the scene
- BoxItem* newItem = scene->createBlockItem(groupBlock);
+ dispatcher->addNewEmptyGroup(scene);
- GroupWidget* child = dispatcher->createChildScene(this,newItem);
- child->show();
}
void GroupWidget::slotNewGroup()
GroupWidget* topGroup = dispatcher->createTopScene();
addTopGroup(topGroup);
library->updateComboScene();
+ params->isCurrentProject = true;
}
void MainWindow::slotCloseProject(){
delete graph;\r
}\r
\r
-GroupBlock* Parameters::addGroupBlock() {\r
- GroupBlock* parent = AB_TO_GRP(currentScene->getGroupItem()->getRefBlock());\r
- GroupBlock* newOne = graph->createChildBlock(parent);\r
- return newOne;\r
-}\r
-\r
-FunctionalBlock* Parameters::addFunctionalBlock(int idCategory, int idBlock) {\r
+ReferenceBlock* Parameters::getReferenceBlock(int idCategory, int idBlock) {\r
\r
BlockCategory* blockCat = categoryTree->searchCategory(idCategory);\r
\r
if (blockCat == NULL) return NULL;\r
- GroupBlock* group = AB_TO_GRP(currentScene->getGroupItem()->getRefBlock());\r
ReferenceBlock* ref = blockCat->getBlock(idBlock);\r
- if (ref == NULL) return NULL;\r
-\r
- FunctionalBlock* newOne = graph->addFunctionalBlock(group, ref);\r
- unsaveModif = true;\r
-\r
- return newOne;\r
+ return ref;\r
}\r
\r
+\r
FunctionalBlock* Parameters::duplicateFunctionalBlock(FunctionalBlock *block) {\r
\r
ReferenceBlock* ref = block->getReference();\r
GroupBlock* group = AB_TO_GRP(block->getParent());\r
\r
- // adding to the group\r
- FunctionalBlock* newBlock = new FunctionalBlock(group,ref);\r
- newBlock->populate();\r
- group->addBlock(newBlock);\r
-\r
+ // adding to the graph\r
+ FunctionalBlock* newBlock = graph->addFunctionalBlock(group,ref);\r
return newBlock;\r
}\r
\r
int nb = currentScene->getBlockItems().length();\r
for(int i = 0; i<nb; i++){\r
if(currentScene->getBlockItems().at(i)->isSelected()){\r
- currentScene->getGroupWindow()->enableGroupButton(true);\r
+ currentScene->getGroupWidget()->enableGroupButton(true);\r
return;\r
}\r
}\r
- currentScene->getGroupWindow()->enableGroupButton(false);\r
+ currentScene->getGroupWidget()->enableGroupButton(false);\r
}\r
\r
\r
// cross the scene level by level using a FIFO\r
QList<GroupScene*> fifoScene;\r
fifoScene.append(topScene);\r
- foreach(ConnectionItem* item, topScene->getConnectionItems()) {\r
- allConnections.append(item);\r
- }\r
\r
GroupScene *scene;\r
while (!fifoScene.isEmpty()) {\r
foreach(GroupScene* s, scene->getChildrenScene()) {\r
fifoScene.append(s);\r
}\r
- foreach(ConnectionItem* item, topScene->getConnectionItems()) {\r
+\r
+ foreach(ConnectionItem* item, scene->getConnectionItems()) {\r
allConnections.append(item);\r
}\r
}\r
-\r
+ writer.writeEndElement(); //</scenes>\r
\r
writer.writeStartElement("connections");\r
foreach(ConnectionItem* item, allConnections) {\r
using namespace std;\r
using namespace Qt;\r
\r
+/*!\r
+ * \brief The Parameters class\r
+ *\r
+ * Parameters class represents the Model part of blast in MVC paradigm.\r
+ * It contains all data necessary to create a design: the graph of blocks,\r
+ * the scenes, ...\r
+ */\r
class Parameters {\r
\r
public :\r
\r
Graph* createGraph();\r
void destroyGraph();\r
- inline Graph* getGraph() { return graph; }\r
- GroupBlock* addGroupBlock(); // adding an empty GroupBlock to the current group\r
- FunctionalBlock* addFunctionalBlock(int idCategory, int idBlock); // adding a functional block to current group\r
+ inline Graph* getGraph() { return graph; } \r
+ ReferenceBlock* getReferenceBlock(int idCategory, int idBlock); // get the reference block from its category and index\r
FunctionalBlock* duplicateFunctionalBlock(FunctionalBlock* block); // adding a copy of a functional block to current group\r
\r
\r
comboBox = new QComboBox;
+ cout << "block has " <<block->getParameters().size() << " params" << endl;
foreach(BlockParameter *param, block->getParameters()){
comboBox->addItem(param->getName());
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
-<!-- Written by QtCreator 3.2.1, 2017-04-26T18:51:42. -->
+<!-- Written by QtCreator 3.2.1, 2017-04-27T20:11:44. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
- <value type="QByteArray">{3701e197-5b6c-48ea-9e98-a6cf6de18672}</value>
+ <value type="QByteArray">{c8006d66-d34f-42be-ad10-d0207752286d}</value>
</data>
<data>
<variable>ProjectExplorer.Project.ActiveTarget</variable>
<valuemap type="QVariantMap">
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop</value>
- <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">{ed04208c-8774-456b-99b9-4a02094ca7a4}</value>
+ <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">{2c9bf876-3476-44eb-8065-1f0844704dda}</value>
<value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
<value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
<value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
</xs:group>
<xs:group name="block_itemsElmtGroup">
- <xs:sequence>
- <xs:element ref="bi_functional" minOccurs="0" maxOccurs="unbounded"/>
- <xs:element ref="bi_group" minOccurs="0"/>
+ <xs:sequence>
+ <xs:element ref="bi_group" minOccurs="0" maxOccurs="unbounded"/>
+ <xs:element ref="bi_functional" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:group>