📄 mapper.cpp
字号:
previousModule = currentModule; bool linkFound = false; // get the following 'valid' link for ( int i = 0; i < currentModule->numberOut; i++ ) { IOLink* link; // = ¤tModule->outputLinkVect.at(i); atp_( link, currentModule->outputLinkVect, i, 7 ); if ( !link ) { cout << "Link " << i << " is NULL at mapper.cpp:658" << endl; continue; } if ( link->toModule >= 0 ) { currentLink = link; currentModule = getModule( currentLink->toModule ); linkFound = true; break; } } // end for(i) if ( !linkFound ) { state = STATE_DRAW_REMAINING_LINKS; break; } } // end [else] : currentModule is not visible break; case STATE_DRAW_REMAINING_LINKS: /******************************************************************/ /* Part 2.2: Draw the remaining links. Interzone links will be */ /* Drawn in part 2.3, when all modules of the current */ /* column have been drawn. */ /******************************************************************/ if ( remainingLinkVect.size() < 1 ) { columnFinished = true; state = STATE_DRAW_INTERZONE_LINKS; break; } // get first link from vector currentLink = remainingLinkVect.begin(); fromModule = getModule( currentLink->fromModule ); toModule = getModule( currentLink->toModule ); if ( fromModule != NULL && toModule != NULL && fromModule->visible && toModule->visible ) { if ( fromModule->lowerNeighbor == toModule->getId() ) { // the two modules follow eachother startX = fromModule->getOutputXPosition( currentLink->fromPort ); startY = fromModule->getOutputYPosition(); endX = toModule->getInputXPosition( currentLink->toPort ); endY = toModule->getInputYPosition(); DRAW_LINE( startX, startY, endX, endY ); // remove link from vector remainingLinkVect.erase( remainingLinkVect.begin() ); break; } else { // the modules do not follow eachother // Vertical outwards line startX = fromModule->getOutputXPosition( currentLink->fromPort ); startY = fromModule->getOutputYPosition(); endX = startX; endY = startY + fromModule->outLinkSpace; fromModule->outLinkSpace -= LINK_Y_INTERVAL; DRAW_LINE( startX, startY, endX, endY ); // Horizontal outwards line startX = endX; startY = endY; endX = inputMaxXTab[ fromModule->zone ]; endY = startY; inputMaxXTab[ fromModule->zone ] += LINK_X_INTERVAL; DRAW_LINE( startX, startY, endX, endY ); // Side line startX = endX; startY = endY; endX = startX; endY = toModule->y - toModule->inLinkSpace; toModule->inLinkSpace -= LINK_Y_INTERVAL; DRAW_LINE( startX, startY, endX, endY ); // Horizontal inwards line startX = endX; startY = endY; endX = toModule->getInputXPosition( currentLink->toPort ); endY = startY; DRAW_LINE( startX, startY, endX, endY ); // Vertical inwards line startX = endX; startY = endY; endX = startX; endY = toModule->getInputYPosition(); DRAW_LINE( startX, startY, endX, endY ); // remove link from vector remainingLinkVect.erase( remainingLinkVect.begin() ); break; } // end else (not neighbor) } // end if(..visible..) else { // the module has not yet been drawn fromModule->outLinkSpace += LINK_Y_INTERVAL; state = STATE_DRAW_DIRECT_SUITE; break; } case STATE_DRAW_INTERZONE_LINKS: /******************************************************************/ /* Part 2.3: Draw the interzone links, which are stored in */ /* interzoneLinkVect. */ /******************************************************************/ if(interzoneLinkVect.size() < 1){ interzoneFinished = true; break; } else { int maxY = toModule->getInputYPosition() - toModule->inLinkSpace; // get the last link from the vector (LIFO queue) currentLink = &interzoneLinkVect.back(); fromModule = getModule(currentLink->fromModule); toModule = getModule(currentLink->toModule); // find the max y coord of 'highest' column between fromZone and toZone // note: toZone is always smaller than fromZone. int limit; if(fromModule == stfa) // stfa has '-1' as zone number, be careful when accessing // an array element at index [module->zone] limit = currentLink->fromPort; else limit = fromModule->zone + 1; // Ineiti: changed, don't know why... j <= limit for(int j = toModule->zone + 1; j < limit; j++){ maxY = MAXIMUM(maxY, outputMaxYTab[j]); } if(toModule->getInputYPosition() <= maxY) maxY += LINK_Y_INTERVAL; else maxY = toModule->getInputYPosition() - toModule->inLinkSpace; // for each zone between fromModule's zone and toModule's zone: // update the corresponding value in outputMinYTab for(int j = toModule->zone + 1; j < limit; j++){ outputMaxYTab[j] = maxY; } // draw the links // Vertical outwards line startX = fromModule->getOutputXPosition(currentLink->fromPort); startY = fromModule->getOutputYPosition(); endX = startX; endY = startY + fromModule->outLinkSpace; fromModule->outLinkSpace -= LINK_Y_INTERVAL; DRAW_LINE( startX, startY, endX, endY ); // Horizontal outwards line startX = endX; startY = endY; if(fromModule == stfa){ endX = MAXIMUM(stfa->getOutputXPosition(currentLink->fromPort), outputMaxXTab[currentLink->fromPort - 1]); outputMaxXTab[currentLink->fromPort] += LINK_X_INTERVAL; } else{ endX = outputMaxXTab[fromModule->zone]; outputMaxXTab[fromModule->zone] += LINK_X_INTERVAL; } endY = startY; DRAW_LINE( startX, startY, endX, endY ); // Side line startX = endX; startY = endY; endX = startX; endY = maxY; DRAW_LINE( startX, startY, endX, endY ); if((fromModule->lowerNeighbor >= 0) || (fromModule == stfa && maxY > toModule->y - toModule->inLinkSpace)) { // there is a lower neighbor to bypass // Inter-zone line startX = endX; startY = endY; endX = outputMaxXTab[toModule->zone]; endY = startY; outputMaxXTab[toModule->zone] += LINK_X_INTERVAL; DRAW_LINE( startX, startY, endX, endY ); // back to side line startX = endX; startY = endY; endX = startX; endY = toModule->y - toModule->inLinkSpace; toModule->inLinkSpace += LINK_Y_INTERVAL; DRAW_LINE( startX, startY, endX, endY ); } // Horizontal in line startX = endX; startY = endY; endX = toModule->getInputXPosition(currentLink->toPort); endY = startY; DRAW_LINE( startX, startY, endX, endY ); // Vertical in line startX = endX; startY = endY; endX = startX; endY = toModule->getInputYPosition(); DRAW_LINE( startX, startY, endX, endY ); // remove link from vect interzoneLinkVect.erase(&interzoneLinkVect.back()); break; } default: break; } // end switch(state) } // end while(!columnFinished) } // end for(all input ports of stfa)}/*******************************************************************************//* Function: addModule() *//* Description: Appends a module to the module list. *//* Inputs: module: pointer to the module to append. *//* Returns: void. *//*******************************************************************************/void Mapper::addModule( Module* module ) { moduleList.append( module );}/*******************************************************************************//* Function: getModule() *//* Description: returns a pointer to a module of moduleList given its number. *//* Inputs: moduleNumber: number of the searched module. *//* Returns: a pointer to the searched pointer or NULL if there is no such *//* module. *//*******************************************************************************/Module* Mapper::getModule( int moduleNumber ) { if ( moduleNumber < 0 ) return NULL; Module* module, *stfa = stfas[stfaChosen]; int size = moduleList.count(); if ( !stfa ){ cout << "Couldn't get current stfa in getModule\n"; } else { // check if it's the stfa if ( stfa->getId() == moduleNumber ) return stfa; } // check each module for ( int i = 0; i < size; i++ ) { module = moduleList.at( i ); if ( module->getId() == moduleNumber ) return module; } // if there is no module with this number return NULL;}/*******************************************************************************//* Function: getModule() *//* Description: returns a pointer to a module of moduleVect that contains the *//* specified x and y coordinates. This function is usually called *//* when the user clicks on a module displayed on the canvas. *//* Inputs: x: x coordinate on the canvas. *//* y: y coordinate on the canvas. *//* Returns: a pointer to the searched module or NULL if there is no such *//* module. *//*******************************************************************************/Module* Mapper::getModule( int x, int y ) { Module * module, *stfa = stfas[stfaChosen]; QRect* rectangle; int size = moduleList.count(); if ( !stfa ){ cout << "Couldn't get stfa in getModule\n"; } else { // check if click on stfa rectangle = new QRect( stfa->x, stfa->y, stfa->width, stfa->height ); if ( rectangle->contains( x, y ) ) return stfa; } // check each module for ( int i = 0; i < size; i++ ) { module = moduleList.at( i ); if ( module->visible ){ rectangle = new QRect( module->x, module->y, module->width, module->height ); if ( rectangle->contains( x, y ) ) { module = moduleList.at( i ); return module; } } } // end for return NULL;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -