// This method gets a set of unique widget group names in a subsystem void Project::getWidgetGroupNames(HTREEITEM hItem, set<INXString> &sWidgetGroupSet) { INXString csProjectDir, csBlockFile, csWidgetGroupName; BlockOperations bo; INXObjList* encapsulated; INXPOSITION pos; ConData* blob; HTREEITEM hUserDefItem; CMainFrame* pFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd; pProjMData->getProjectDir(csProjectDir); csBlockFile = csProjectDir + DEPDIR + pFrame->m_wndProjectBar.m_cProjTree.GetDEPPath(hItem) + (INXString)pFrame->m_wndProjectBar.m_cProjTree.GetItemText(hItem) + ".prg"; encapsulated = bo.LoadBlock(csBlockFile); pos = encapsulated->GetHeadPosition(); while(pos) { blob = (ConData *) (encapsulated->GetNext(pos)); if (blob->m_iUserDefined) { hUserDefItem = pFrame->m_wndProjectBar.m_cProjTree.GetUserDefChildItem(blob, hItem); getWidgetGroupNames(hUserDefItem, sWidgetGroupSet); } else if (blob->isGuiWidget()) { blob->getScreenTag(csWidgetGroupName); sWidgetGroupSet.insert(csWidgetGroupName); } } bo.DeleteBlock(encapsulated); }
// Loads an encapsulated block into a temporary list INXObjList* BlockOperations::LoadBlock(INXString Info) { ifstream datafile(Info); INXObjList* encapsulated = new INXObjList; char type[256]; long int id; // store the id value id = ConData::uniqueidgenerator; if(datafile.is_open()) { int i = 0; while ((!datafile.eof()) && (!datafile.bad())) { i++; datafile >> type; // TRACE(type); if (strcmp(type,"END_OF_BLOCKS")==0) break; else if (strcmp(type,"BEGIN_BLOCK")==0) { ConData *blob = new ConData; blob->Load(&datafile); encapsulated->AddTail((CObject*) blob); } if(i>500) { // TRACE("hang\n"); } } }
void Project::closeUserDefDoc(HTREEITEM hItem) { INXString csProjectDir, csBlockFile; BlockOperations bo; INXObjList* encapsulated; INXPOSITION pos; ConData* blob; HTREEITEM hUserDefItem; CMainFrame* pFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd; pProjMData->getProjectDir(csProjectDir); csBlockFile = csProjectDir + DEPDIR + pFrame->m_wndProjectBar.m_cProjTree.GetDEPPath(hItem) + (INXString)pFrame->m_wndProjectBar.m_cProjTree.GetItemText(hItem) + ".prg"; encapsulated = bo.LoadBlock(csBlockFile); // Find all the user defined blocks within an encapsualted block pos = encapsulated->GetHeadPosition(); while(pos) { blob = (ConData *) (encapsulated->GetNext(pos)); if (blob->m_iUserDefined) { hUserDefItem = pFrame->m_wndProjectBar.m_cProjTree.GetUserDefChildItem(blob, hItem); closeUserDefDoc(hUserDefItem); } } bo.DeleteBlock(encapsulated); // if the user defined blocks are loaded then close the document/window if (depIsLoaded(hItem)) { // decrement dep counter, as this is used to save the project //DEPNum--; ((CDrawProgApp*)AfxGetApp())->CloseUserDefDoc(hItem); } }
INXObjList* EditList::LoadTemp() { ConData* blob; long int id = 0; INXObjList* temp = new INXObjList; // Copy the condata list to the flattened list // save the condata list and then load it back in to flattened // Alternatively could use a copy constructor temp->RemoveAll(); //SaveProg(workDir + TEMPDIR + "temp"); ifstream datafile(workDir + TEMPDIR + "temp"); char type[256]; while ((!datafile.eof()) && (!datafile.fail())) { datafile >> type; if (strcmp(type,"END_OF_BLOCKS")==0) break; else if (strcmp(type,"BEGIN_BLOCK")==0) { blob = new ConData; if(blob) { blob->Load(&datafile); temp->AddTail((CObject*) blob); id = blob->identnum; } else { //delete blob; break; } } } // set the uniqueidgenerator to the identnum of the last icon // This is necessary as it is possible that this value may be greater than // the number of icons loaded, due to icons being deleted previously. This // prevents icon IDs being duplicated // Need to add 1, since uniqueidgenerator is incremented after a new icon is // instantiated. //id++; //ConData::uniqueidgenerator = id; return temp; }
void Project::removeWidgetsInUserDefBlock(HTREEITEM hItem) { INXString csProjectDir, csBlockFile; BlockOperations bo; INXObjList* encapsulated; INXPOSITION pos; ConData* blob; HTREEITEM hUserDefItem; DEP* pLoadedDEP; CMainFrame* pFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd; // If DEP is in memory then need to remove widgets from this because the user may have added widgets // that have not been saved. pLoadedDEP = depIsLoaded(hItem); if (pLoadedDEP) { encapsulated = pLoadedDEP->condata; } else { pProjMData->getProjectDir(csProjectDir); csBlockFile = csProjectDir + DEPDIR + pFrame->m_wndProjectBar.m_cProjTree.GetDEPPath(hItem) + (INXString)pFrame->m_wndProjectBar.m_cProjTree.GetItemText(hItem) + ".prg"; encapsulated = bo.LoadBlock(csBlockFile); } pos = encapsulated->GetHeadPosition(); while(pos) { blob = (ConData *) (encapsulated->GetNext(pos)); if (blob->m_iUserDefined) { hUserDefItem = pFrame->m_wndProjectBar.m_cProjTree.GetUserDefChildItem(blob, hItem); removeWidgetsInUserDefBlock(hUserDefItem); } else if (blob->isGuiWidget()) { removeGuiWidget(blob); } } // if the DEP is in memory don't do memory cleanup here if (!pLoadedDEP) { bo.DeleteBlock(encapsulated); } }
// Loads the saved copySelList into the pasteList INXObjList* EditList::LoadPaste(INXString Info) { ifstream datafile(Info); char type[256] = {'\0'}; long int id; INXObjList* pasteList = NULL; datafile >> type; // if a file is empty don't load it if ((INXString)type == "") { return NULL; } datafile.close(); datafile.open(Info); // store the id value id = ConData::uniqueidgenerator; while ((!datafile.eof()) && (!datafile.bad())) { datafile >> type; if (strcmp(type,"END_OF_BLOCKS")==0) break; else if (strcmp(type,"BEGIN_BLOCK")==0) { ConData *blob = new ConData; blob->Load(&datafile); if (!pasteList) { pasteList = new INXObjList; } pasteList->AddTail((CObject*) blob); } } // restore the id value, since it will have been increased when creating flattened ConData::uniqueidgenerator = id; return pasteList; }
// Function that flattens all encapsulated icons. void SODL::Flatten() { ConData *blob, *blockIcon, *blockOtherIcon, *blobOtherIcon; INXObjList* encapsulated; INXPOSITION pos, rmpos, otherPos, blockPos; int otherportno; INXString blockFile, csProjectDir; bool allFlattened = FALSE; bool flattenFlag = FALSE; BlockOperations bo; UINT i; pProject->pProjMData->getProjectDir(csProjectDir); // This first loop is used to catch the case when an encapsulated icon that contains other // encapsulated blocks is the last element in the list. // If it didn't exist then the icon would be flattened but the encapsulated icons within would not be // because GetNext(pos) would return null. while (!allFlattened) { flattenFlag = FALSE; // Find encapsulated blocks and flatten pos = flattened->GetHeadPosition(); while(pos) { rmpos = pos; blob = (ConData *) (flattened->GetNext(pos)); //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! if (blob->m_iUserDefined == 1) { //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! flattenFlag = TRUE; blockFile = csProjectDir + DEPDIR + blob->hierarchyName + blob->description + ".prg"; encapsulated = bo.LoadBlock(blockFile); // Give the block icons unique IDs //AfxMessageBox("About to call ReassignIconIDs ( from within 'Flatten' )"); ReassignIconIDs(encapsulated); bo.SaveBlock(blockFile, encapsulated); // Hook up the encapsulated block // This is done in 2 passes for the case when a subsystem input is connected to an output on the same // subsystem. The 2 pass process takes care of the case when the output xport is in the list before // the FB connected to the input xport. // The first pass basically hooks up all the FBs. // The second pass hooks up all the output xports. blockPos = encapsulated->GetHeadPosition(); while(blockPos) { blockIcon = (ConData *) (encapsulated->GetNext(blockPos)); // find the ports connected to a XINPUT if (blockIcon->m_csIconType.Find("XINPUT") == -1 && blockIcon->m_csIconType != "XSTART" && blockIcon->m_csIconType.Find("XOUTPUT") == -1 && blockIcon->m_csIconType != "XFINISH") { for (i=0; i<blockIcon->inputport_num; i++) { // check the input is connected if (blockIcon->inputport[i]->line.exist) { blockOtherIcon = bo.GetBlockIconFromID(blockIcon->inputport[i]->line.othericonid, encapsulated); // if an encapsulated icon is connected to an XINPUT then connect it to the icon // the XINPUT is connected to in the level above if (blockOtherIcon->m_csIconType.Find("XINPUT") != -1) { for (UINT j=0; j<blob->inputport_num; j++) { if (blockOtherIcon->description == blob->inputport[j]->description) { if (blob->inputport[j]->line.exist) { blockIcon->inputport[i]->line.othericonid = blob->inputport[j]->line.othericonid; blockIcon->inputport[i]->line.otherportno = blob->inputport[j]->line.otherportno; } // if XINPUT on the encapsulated block is unconnected then the corresponding // port on the block should be unconnected else { blockIcon->inputport[i]->line.exist = 0; } } } } } } // for (i=0; i<blockIcon->inputport_num; i++) // find the ports connected to a XSTART for (i=0; i<blockIcon->startport_num; i++) { // check the input is connected if (blockIcon->startport[i]->line.exist) { blockOtherIcon = bo.GetBlockIconFromID(blockIcon->startport[i]->line.othericonid, encapsulated); // if an encapsulated icon is connected to a XSTART then connect it to the icon // the XSTART is connected to in the level above if (blockOtherIcon->m_csIconType == "XSTART") { for (UINT j=0; j<blob->startport_num; j++) { if (blockOtherIcon->description == blob->startport[j]->description) { if (blob->startport[j]->line.exist) { blockIcon->startport[i]->line.othericonid = blob->startport[j]->line.othericonid; blockIcon->startport[i]->line.otherportno = blob->startport[j]->line.otherportno; } // case when start port is initialised else if (blob->startport[j]->initialise) { blockIcon->startport[i]->initialise = 1; blockIcon->startport[i]->line.exist = 0; //blockIcon->startport[i]->line.othericonid = -1; } // if XSTART on the encapsulated block is unconnected then the corresponding // port on the block should be unconnected else { blockIcon->startport[i]->line.exist = 0; } } } } } } flattened->AddTail(blockIcon); } // if (blockIcon->m_csIconType.Find("XINPUT") == -1 && blockIcon->m_csIconType != "XSTART") } // while(blockPos) blockPos = encapsulated->GetHeadPosition(); while(blockPos) { blockIcon = (ConData *) (encapsulated->GetNext(blockPos)); // find the ports connected to a XOUTPUT if (blockIcon->m_csIconType.Find("XOUTPUT") != -1) { blockOtherIcon = bo.GetBlockIconFromID(blockIcon->inputport[0]->line.othericonid, encapsulated); // find the input port in flattened connected to this XOUTPUT otherPos = flattened->GetHeadPosition(); while(otherPos) { blobOtherIcon = (ConData *) (flattened->GetNext(otherPos)); if (blobOtherIcon != blob) { for (i=0; i<blobOtherIcon->inputport_num; i++) { if (blobOtherIcon->inputport[i]->line.exist) { otherportno = blobOtherIcon->inputport[i]->line.otherportno; // if XOUTPUT is not connected then remove line from blobOtherIcon if (blobOtherIcon->inputport[i]->line.othericonid == blob->identnum && blockIcon->description == blob->outputport[otherportno]->description && !blockIcon->inputport[0]->line.exist) { blobOtherIcon->inputport[i]->line.exist = 0; } // if the input port in the flattened list is connected and // the icon it is connected to is the encapsulated block and // the port it is connected to is this XOUTPUT then connect it // to the icon in the encapsulated block else if ((blobOtherIcon->inputport[i]->line.othericonid == blob->identnum) && (blockIcon->description == blob->outputport[otherportno]->description)) { blobOtherIcon->inputport[i]->line.othericonid = blockIcon->inputport[0]->line.othericonid; blobOtherIcon->inputport[i]->line.otherportno = blockIcon->inputport[0]->line.otherportno; } } } } } } // find the ports connected to a XFINISH if (blockIcon->m_csIconType == "XFINISH") { blockOtherIcon = bo.GetBlockIconFromID(blockIcon->startport[0]->line.othericonid, encapsulated); // find the start port in flattened connected to this XFINISH otherPos = flattened->GetHeadPosition(); while(otherPos) { blobOtherIcon = (ConData *) (flattened->GetNext(otherPos)); if (blobOtherIcon != blob) { for (i=0; i<blobOtherIcon->startport_num; i++) { if (blobOtherIcon->startport[i]->line.exist) { otherportno = blobOtherIcon->startport[i]->line.otherportno; // if XFINISH is not connected then remove line from blobOtherIcon if (blobOtherIcon->startport[i]->line.othericonid == blob->identnum && blockIcon->description == blob->finishport[otherportno]->description && !blockIcon->startport[0]->line.exist && !blockIcon->startport[0]->initialise) { blobOtherIcon->startport[i]->line.exist = 0; } // if the input port in the flattened list is connected and // the icon it is connected to is the encapsulated block and // the port it is connected to is this XOUTPUT then connect it // to the icon in the encapsulated block if ((blobOtherIcon->startport[i]->line.othericonid == blob->identnum) && (blockIcon->description == blob->finishport[otherportno]->description)) { if (blockIcon->startport[0]->initialise) { blobOtherIcon->startport[i]->initialise = 1; blobOtherIcon->startport[i]->line.exist = 0; blobOtherIcon->startport[i]->line.othericonid = -1; } else { blobOtherIcon->startport[i]->line.othericonid = blockIcon->startport[0]->line.othericonid; blobOtherIcon->startport[i]->line.otherportno = blockIcon->startport[0]->line.otherportno; } } } } } } } // if (blockIcon->m_csIconType == "XFINISH") } // while(blockPos) // destroy xports blockPos = encapsulated->GetHeadPosition(); while(blockPos) { blockIcon = (ConData *) (encapsulated->GetNext(blockPos)); if (blockIcon->m_csIconType.Find("XINPUT") != -1 || blockIcon->m_csIconType.Find("XOUTPUT") != -1 || blockIcon->m_csIconType == "XSTART" || blockIcon->m_csIconType == "XFINISH") { delete blockIcon; } } // remove encapsulated block from flattened delete blob; flattened->RemoveAt(rmpos); // destroy encapsulated icon // causes a crash //delete blob; // destroy list of encapsulated icons delete encapsulated; //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! } // if (blob->m_iUserDefined == 1) //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! } if (!flattenFlag) { allFlattened = TRUE; } } // while (!allFlattened) }
// This function stores a copy of the selected icons when a copy or cut is performed void EditList::BufferSelectedIcons(INXRect selectRect, Project* pProject, DEP* pDEP) { ConData *icondata; ConData *otherIcon; INXPOSITION pos, otherPos; bool isConnected = FALSE; INXObjList* temp; CFileOperation fo; CMainFrame* pFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd; BlockOperations bo; UINT i; INXString csProjectDir; pProject->pProjMData->getProjectDir(csProjectDir); copySelList->RemoveAll(); // the following algorithm is used because there isn't a copy constructor // copy the condata list to the flattened list // copy the selected icons from the flattened list to the copySelList temp = LoadTemp(); bo.AssignIconLineEndPoints(temp); // if the icon is in the selection box add it to copySelList pos = temp->GetHeadPosition(); while (pos) { icondata = (ConData *) (temp->GetNext(pos)); //if (selectRect.PtInRect(icondata->GetIconCentre())) { if (icondata->selected) { // Copy user defined blocks to the temp directory if (icondata->m_iUserDefined) { fo.SetOverwriteMode(true); // set OverwriteMode flag fo.Copy(csProjectDir + DEPDIR + pFrame->m_wndProjectBar.m_cProjTree.GetDEPPath(pDEP->hItem) + pDEP->depFilename + "\\" + icondata->description + ".prg", workDir + TEMPDIR); fo.Copy(csProjectDir + DEPDIR + pFrame->m_wndProjectBar.m_cProjTree.GetDEPPath(pDEP->hItem) + pDEP->depFilename + "\\" + icondata->description, workDir + TEMPDIR); //CopyInstance(icondata, pProject, pDEP); } copySelList->AddTail(icondata); } // if icon isn't in selection box then delete else { //delete icondata; } } //delete temp; // if an input on an icon in copySelList is not connected to another // icon in the list then disconnect it // remove all tags from ports in the copy list. Don't want same tags as this is confusing. pos = copySelList->GetHeadPosition(); while (pos) { icondata = (ConData *) (copySelList->GetNext(pos)); for (i=0; i<icondata->inputport_num; i++) { icondata->inputport[i]->tag = ""; otherPos = copySelList->GetHeadPosition(); isConnected = FALSE; while (otherPos) { otherIcon = (ConData *)(copySelList->GetNext(otherPos)); if (icondata->inputport[i]->line.exist && icondata->inputport[i]->line.othericonid == otherIcon->identnum) { isConnected = TRUE; } } if (!isConnected) { icondata->inputport[i]->line.exist = 0; } } for (i=0; i<icondata->startport_num; i++) { icondata->startport[i]->tag = ""; otherPos = copySelList->GetHeadPosition(); isConnected = FALSE; while (otherPos) { otherIcon = (ConData *)(copySelList->GetNext(otherPos)); if (icondata->startport[i]->line.exist && icondata->startport[i]->line.othericonid == otherIcon->identnum) { isConnected = TRUE; } } if (!isConnected) { icondata->startport[i]->line.exist = 0; } } for (i=0; i<icondata->outputport_num; i++) { icondata->outputport[i]->tag = ""; } for (i=0; i<icondata->finishport_num; i++) { icondata->finishport[i]->tag = ""; } } // save copySelList. This is used for test purposes SaveCopy((INXString)workDir + "\\tmpcopy.prg"); //pView->pasteFlag = TRUE; // delete the temp list now the selected blocks have been saved bo.DeleteBlock(temp); }
// Works together with AssignHierLineID and AssignSubBlockHierId to propagate the hierIds into lower level // subsystems. If an XINPUT port is connected to a subsystem then the hierId is propagated into the subsystem block. void Project::PropagateHierLineId(ConData* blob, HTREEITEM hItem, long hierID, int portType, int iPortNum) { CMainFrame* pFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd; INXString filename, csProjectDir; INXObjList* tmpList; INXPOSITION subpos; ConData *subblob, *othersubblob; HTREEITEM hChild; BlockOperations bo; CanvasSupport cs; cs.SetDebugTrace(false); pProjMData->getProjectDir(csProjectDir); filename = csProjectDir + DEPDIR + pFrame->m_wndProjectBar.m_cProjTree.GetDEPPath(hItem) + blob->description + ".prg"; cs.DebugTrace("sdg: subblock Filename: %s\n", filename); tmpList = bo.LoadBlock(filename); cs.DebugTrace("sdg: subblock LoadBlock\n"); if (portType == INPUTPORT) { subpos = tmpList->GetHeadPosition(); while (subpos) { subblob = (ConData*) tmpList->GetNext(subpos); // find icon port connected to XINPUT that has same description as user defined input for (UINT j=0; j<subblob->inputport_num; j++) { if (subblob->inputport[j]->line.exist) { othersubblob = bo.GetBlockIconFromID(subblob->inputport[j]->line.othericonid, tmpList); if (othersubblob->m_csIconType.Find("XINPUT") != -1 && othersubblob->description == blob->inputport[iPortNum]->description) { subblob->inputport[j]->line.hierID = hierID; // This if block used to be outside the one its nested in // Need to check it still works with the debugger if (subblob->m_iUserDefined) { hChild = pFrame->m_wndProjectBar.m_cProjTree.GetUserDefChildItem(subblob, hItem); PropagateHierLineId(subblob, hChild, hierID, INPUTPORT, j); } } } } } } else if (portType == STARTPORT) { cs.DebugTrace("sdg: subblock start ports\n"); subpos = tmpList->GetHeadPosition(); while (subpos) { subblob = (ConData*) tmpList->GetNext(subpos); //cs.DebugTrace("sdg: subblock start subblob type is: %s\n", subblob->type); // find icon port connected to XINPUT that has same description as user defined input for (UINT j=0; j<subblob->startport_num; j++) { if (subblob->startport[j]->line.exist) { othersubblob = bo.GetBlockIconFromID(subblob->startport[j]->line.othericonid, tmpList); if (othersubblob->m_csIconType.Find("XSTART") != -1 && othersubblob->description == blob->startport[iPortNum]->description) { subblob->startport[j]->line.hierID = hierID; cs.DebugTrace("sdg: subblock port label is: %s\n", subblob->startport[j]->description); // This if block used to be outside the one its nested in // Need to check it still works with the debugger if (subblob->m_iUserDefined) { cs.DebugTrace("sdg: subblock subblob block: %s\n", subblob->m_csBlockName); cs.DebugTrace("sdg: subblock subblob GetUserDefChildItem\n"); hChild = pFrame->m_wndProjectBar.m_cProjTree.GetUserDefChildItem(subblob, hItem); cs.DebugTrace("sdg: subblock PropagateHierLineId\n"); PropagateHierLineId(subblob, hChild, hierID, STARTPORT, j); cs.DebugTrace("sdg: subblock end PropagateHierLineId\n"); } } } } } } cs.DebugTrace("sdg: end subblock start ports\n"); bo.SaveBlock(filename, tmpList); bo.DeleteBlock(tmpList); }
// Same as the AssignHierLineId method except it recursively goes through all subsystem blocks void Project::AssignSubBlockHierLineId(HTREEITEM hItem) { CMainFrame* pFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd; INXString csFileName, csProjectDir; INXObjList* pTmpList; BlockOperations bo; INXPOSITION pos; ConData *pBlob, *pOtherBlob; HTREEITEM hChildItem; long iHierId; pProjMData->getProjectDir(csProjectDir); csFileName = csProjectDir + DEPDIR + pFrame->m_wndProjectBar.m_cProjTree.GetDEPPath(hItem) + (INXString)pFrame->m_wndProjectBar.m_cProjTree.GetItemText(hItem) + ".prg"; pTmpList = bo.LoadBlock(csFileName); pos = pTmpList->GetHeadPosition(); while (pos) { pBlob = (ConData*) pTmpList->GetNext(pos); if (pBlob->m_iUserDefined) { hChildItem = pFrame->m_wndProjectBar.m_cProjTree.GetUserDefChildItem(pBlob, hItem); for (UINT i=0; i<pBlob->inputport_num; i++) { if (pBlob->inputport[i]->line.exist) { iHierId = m_iHierIdCount; } else { iHierId = -1; } pOtherBlob = bo.GetBlockIconFromID(pBlob->inputport[i]->line.othericonid, pTmpList); // if port is connected to XSTART assume the hierID has already been assigned if (pOtherBlob && pOtherBlob->m_csIconType.Find("XINPUT") == -1) { pBlob->inputport[i]->line.hierID = iHierId; PropagateHierLineId(pBlob, hChildItem, iHierId, INPUTPORT, i); if (pBlob->inputport[i]->line.exist) { m_iHierIdCount++; } } } for (UINT i=0; i<pBlob->startport_num; i++) { if (pBlob->startport[i]->line.exist) { iHierId = m_iHierIdCount; } else { iHierId = -1; } pOtherBlob = bo.GetBlockIconFromID(pBlob->startport[i]->line.othericonid, pTmpList); // if port is connected to XSTART assume the hierID has already been assigned if (pOtherBlob && pOtherBlob->m_csIconType.Find("XSTART") == -1) { pBlob->startport[i]->line.hierID = iHierId; PropagateHierLineId(pBlob, hChildItem, iHierId, STARTPORT, i); if (pBlob->startport[i]->line.exist) { m_iHierIdCount++; } } } AssignSubBlockHierLineId(hChildItem); } } bo.SaveBlock(csFileName, pTmpList); bo.DeleteBlock(pTmpList); }
// Assigns a hierarchical line ID to lines connected to userdefined blocks and lines connected to XINPUT ports to simplify mapping // in debug mode void Project::AssignHierLineID() { CMainFrame* pFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd; INXPOSITION pos, subpos; ConData *blob, *subblob, *othersubblob; long hierID = 0; INXObjList* tmpList; INXString filename, csProjectDir; HTREEITEM hChild, hItem; BlockOperations bo; UINT i; CanvasSupport cs; cs.SetDebugTrace(false); m_iHierIdCount = 0; cs.DebugTrace("sdg: assignhierlineid\n"); pProjMData->getProjectDir(csProjectDir); pos = pDEP[0]->condata->GetHeadPosition(); while (pos) { // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // For Each function-block in the top level dep // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! blob = (ConData*) pDEP[0]->condata->GetNext(pos); cs.DebugTrace("sdg: blob m_csIconType is: %s\n", blob->m_csIconType); // assign hierID to userdefined block and icon in sub block the input is connected to if (blob->m_iUserDefined) { // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // If the function-block is a sub-block (ie user-defined) // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // If the function-block is a sub-block (ie user-defined) // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! hItem = pFrame->m_wndProjectBar.m_cProjTree.GetUserDefChildItem(blob, pDEP[0]->hItem); cs.DebugTrace("sdg: GetUserDefChildItem\n"); filename = csProjectDir + DEPDIR + pFrame->m_wndProjectBar.m_cProjTree.GetDEPPath(hItem) + blob->description + ".prg"; cs.DebugTrace("sdg: Filename: %s\n", filename); tmpList = bo.LoadBlock(filename); cs.DebugTrace("sdg: LoadBlock\n"); for (i=0; i<blob->inputport_num; i++) { // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // For each input-port of the (top-level, user-defined) sub-block // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! if (blob->inputport[i]->line.exist) { hierID = m_iHierIdCount; } // Need to set unconnected ports to -1, because could have case where it is connected in sub-block // and has a value that was set in a previous call to this function else { hierID = -1; } blob->inputport[i]->line.hierID = hierID; subpos = tmpList->GetHeadPosition(); while (subpos) { // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // For each function-block in the sub-block // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! subblob = (ConData*) tmpList->GetNext(subpos); cs.DebugTrace("sdg: input subblob m_csIconType is: %s\n", subblob->m_csIconType); // find icon port connected to XINPUT that has same description as user defined input for (UINT j=0; j<subblob->inputport_num; j++) { if (subblob->inputport[j]->line.exist) { othersubblob = bo.GetBlockIconFromID(subblob->inputport[j]->line.othericonid, tmpList); if (othersubblob->m_csIconType.Find("XINPUT") != -1 && othersubblob->description == blob->inputport[i]->description) { subblob->inputport[j]->line.hierID = hierID; // This if block used to be outside the one its nested in // Need to check it still works with the debugger if (subblob->m_iUserDefined) { hChild = pFrame->m_wndProjectBar.m_cProjTree.GetUserDefChildItem(subblob, hItem); PropagateHierLineId(subblob, hChild, hierID, INPUTPORT, j); } } } } } // while (subpos) if (blob->inputport[i]->line.exist) { m_iHierIdCount++; } } // for (i=0; i<blob->inputport_num; i++) cs.DebugTrace("sdg: end input ports\n"); for (i=0; i<blob->startport_num; i++) { if (blob->startport[i]->line.exist) { hierID = m_iHierIdCount; } // Need to set unconnected ports to -1, because could have case where it is connected in sub-block // and has a value that was set in a previous call to this function else { hierID = -1; } blob->startport[i]->line.hierID = hierID; subpos = tmpList->GetHeadPosition(); while (subpos) { subblob = (ConData*) tmpList->GetNext(subpos); cs.DebugTrace("sdg: start subblob m_csIconType is: %s\n", subblob->m_csIconType); // find icon port connected to XINPUT that has same description as user defined input for (UINT j=0; j<subblob->startport_num; j++) { if (subblob->startport[j]->line.exist) { othersubblob = bo.GetBlockIconFromID(subblob->startport[j]->line.othericonid, tmpList); if (othersubblob->m_csIconType.Find("XSTART") != -1 && othersubblob->description == blob->startport[i]->description) { subblob->startport[j]->line.hierID = hierID; // This if block used to be outside the one its nested in // Need to check it still works with the debugger if (subblob->m_iUserDefined) { cs.DebugTrace("sdg: subblob block: %s\n", subblob->m_csBlockName); cs.DebugTrace("sdg: subblob GetUserDefChildItem\n"); hChild = pFrame->m_wndProjectBar.m_cProjTree.GetUserDefChildItem(subblob, hItem); cs.DebugTrace("sdg: PropagateHierLineId\n"); PropagateHierLineId(subblob, hChild, hierID, STARTPORT, j); cs.DebugTrace("sdg: end PropagateHierLineId\n"); } } } } } if (blob->startport[i]->line.exist) { m_iHierIdCount++; } } // iterate through all sub-blocks and assign sub-blocks cs.DebugTrace("sdg: end start ports\n"); bo.SaveBlock(filename, tmpList); bo.DeleteBlock(tmpList); AssignSubBlockHierLineId(hItem); } // if (blob->userDefined) } }