void OnboardEscalatorInSim::CreateBackElementSpace() { int nPointCount = m_realpath.getCount(); if (nPointCount < 2) return; DeckPoint deckBackPt = m_pDevice->GetDeckPoint().back(); CPoint2008 backPt = m_realpath.getPoint(nPointCount - 1); CPoint2008 prePt = m_realpath.getPoint(nPointCount - 2); CPoint2008 backDir(backPt - prePt); backDir.setZ(0.0); backDir.Normalize(); CPoint2008 cellPt(GRID_WIDTH,GRID_HEIGHT,0.0); double dOffsetDist = cellPt.length();//offset make be able to next cell COnBoardEscalator* pEscalator = (COnBoardEscalator*)m_pDevice; double dDist = pEscalator->GetWidth()/2; //rotate 90 CPoint2008 leftDir = backDir; leftDir.rotate(90); leftDir.Normalize(); CPoint2008 leftTop = backPt + leftDir*dDist; CPoint2008 rightTop = leftTop + backDir*dOffsetDist; //rotate -90 CPoint2008 rightDir = backDir; rightDir.rotate(-90); rightDir.Normalize(); CPoint2008 leftBottom = backPt + rightDir*dDist; CPoint2008 rightBottom = leftBottom + backDir*dOffsetDist; CPollygon2008 pollygon; CPoint2008 ptList[4]; ptList[0] = leftTop; ptList[1] = rightTop; ptList[2] = rightBottom; ptList[3] = leftBottom; pollygon.init(4,ptList); if (m_pBackElementSpace) { delete m_pBackElementSpace; m_pBackElementSpace = NULL; } m_pBackElementSpace = new OnboardElementSpace(GetGround(deckBackPt.first)); m_pBackElementSpace->setPollygon(pollygon); m_pBackElementSpace->CalculateSpace(); }
void OnboardEscalatorInSim::CreateEntryPoint() { int nDeckCount = (int)m_pDevice->GetDeckPoint().size(); if (nDeckCount < 2) //less than two point can not calculate entry point return; int nPointCount = m_realpath.getCount(); if (nPointCount < 2) return; CPoint2008 cellPt(GRID_WIDTH,GRID_HEIGHT,0.0); double dDist = cellPt.length();//offset make be able to next cell //first entry point DeckPoint deckFirstPt = m_pDevice->GetDeckPoint().front(); CPoint2008 firstDir(m_realpath.getPoint(0) - m_realpath.getPoint(1)); firstDir.setZ(0.0); firstDir.Normalize(); OnboardCellInSim* pFirstCell = GetGround(deckFirstPt.first)->getCell(m_realpath.getPoint(0)); CPoint2008 firstLocate = pFirstCell->getLocation(); CPoint2008 firstEntryPoint = firstLocate + firstDir*dDist; OnboardCellInSim* pFirstEntryCell = GetGround(deckFirstPt.first)->getCell(firstEntryPoint); m_entryPointList.push_back(pFirstEntryCell); //back entry point DeckPoint deckBackPt = m_pDevice->GetDeckPoint().back(); CPoint2008 backPt = m_realpath.getPoint(nPointCount - 1); CPoint2008 prePt = m_realpath.getPoint(nPointCount - 2); CPoint2008 backDir(backPt - prePt); backDir.setZ(0.0); backDir.Normalize(); backPt += backDir*dDist; OnboardCellInSim* pBackCell = GetGround(deckBackPt.first)->getCell(backPt); CPoint2008 backLocate = pBackCell->getLocation(); CPoint2008 backEntryPoint = backLocate + backDir*(dDist/2); OnboardCellInSim* pBackEntryCell = GetGround(deckBackPt.first)->getCell(backEntryPoint); m_entryPointList.push_back(pBackEntryCell); }
void TestB() { char tty_name[] = "/dev_tty1"; int fd_stdin = open(tty_name, O_RDWR); assert(fd_stdin == 0); int fd_stdout = open(tty_name, O_RDWR); assert(fd_stdout == 1); char rdbuf[128]; char cmd[8]; char filename[120]; char buf[1024]; int m,n; initFSTree(); printf(" ==================================\n"); printf(" File Manager \n"); printf(" Kernel on Orange's \n\n"); printf(" ==================================\n"); while (1) { printPath(); printf("$ :"); int r = read(fd_stdin, rdbuf, 70); rdbuf[r] = 0; if (strcmp(rdbuf, "i") == 0) { char treeInfo[2048] = {0}; getTreeInfo(treeInfo); printf("%s\n", treeInfo); } else if(strcmp(rdbuf, "s") == 0) { showTree(); } else if(strcmp(rdbuf, "p") == 0) { printPath(); printf("\n"); } else if (strcmp(rdbuf, "help") == 0) { printf("=============================================================================\n"); printf("Command List :\n"); printf("1. create [filename] : Create a new file \n"); printf("2. read [filename] : Read the file\n"); printf("3. write [filename] : Write at the end of the file\n"); printf("4. delete [filename] : Delete the file\n"); printf("5. help : Display the help message\n"); printf("==============================================================================\n"); } else if (strcmp(rdbuf, "dir") == 0) { printCurrFile(); continue; } else { int fd; int i = 0; int j = 0; char temp = -1; while(rdbuf[i]!=' ' && rdbuf[i] != 0) { cmd[i] = rdbuf[i]; i++; } cmd[i++] = 0; while(rdbuf[i] != 0) { filename[j] = rdbuf[i]; i++; j++; } filename[j] = 0; if(strcmp(cmd, "mkdir") == 0) { createDir(filename); saveTreeToDsik(); // //write TreeRecord // char treeInfo[2048]={0}; // getTreeInfo(treeInfo); // printf("%s\n", treeInfo); // fd = open("TreeRecord", O_RDWR); // if (fd == -1) // { // printf("Failed to open 'TreeRecord'!\n"); // continue ; // } // strcpy(buf,treeInfo); // printf("buf :%s\n", buf); // n = write(fd, buf, 1024); // close(fd); } else if(strcmp(cmd, "cd") == 0) { //open dir if(strcmp(filename, "..") == 0) { backDir(); } else { openDir(filename); } } else if(strcmp(cmd,"rmdir") == 0) { //delete dir if(isThereFile(filename) == 0) { printf("fail to remove dir, not here!\n"); continue; } deleteDirRecord(filename); saveTreeToDsik(); // //write TreeRecord // char treeInfo[2048]={0}; // getTreeInfo(treeInfo); // printf("%s\n", treeInfo); // fd = open("TreeRecord", O_RDWR); // if (fd == -1) // { // printf("Failed to open 'TreeRecord'!\n"); // continue ; // } // strcpy(buf,treeInfo); // printf("buf :%s\n", buf); // n = write(fd, buf, 1024); // close(fd); } else if (strcmp(cmd, "create") == 0) { fd = open(filename, O_CREAT | O_RDWR); if (fd == -1) { printf("Failed to create file! Please check the fileaname!\n"); continue ; } buf[0] = 0; write(fd, buf, 1); printf("File created: %s (fd %d)\n", filename, fd); close(fd); //add to tree currFatherDir fTreeArray[treeCurrSize].currDir = treeCurrSize; fTreeArray[treeCurrSize].fatherDir = currFatherDir; fTreeArray[treeCurrSize].isDir = 0; //not a dir strcpy(fTreeArray[treeCurrSize].fileName, filename); treeCurrSize++; treeCount++; // showTree(); // char* treeInfo; // treeInfo = getTreeInfo(); // printf("%d\n", treeCurrSize); saveTreeToDsik(); // //write TreeRecord // char treeInfo[2048]={0}; // getTreeInfo(treeInfo); // printf("%s\n", treeInfo); // fd = open("TreeRecord", O_RDWR); // if (fd == -1) // { // printf("Failed to open 'TreeRecord'!\n"); // continue ; // } // strcpy(buf,treeInfo); // printf("buf :%s\n", buf); // n = write(fd, buf, 1024); // close(fd); } else if (strcmp(cmd, "read") == 0) { if(isThereFile(filename) == 0) { printf("fail to read file, not here!\n"); continue; } fd = open(filename, O_RDWR); if (fd == -1) { printf("Failed to open file! Please check the fileaname!\n"); continue ; } n = read(fd, buf, 1024); printf("%s\n", buf); close(fd); } else if (strcmp(cmd, "write") == 0) { // if(isThereFile(filename) == 0) // { // printf("fail to write file, not here!\n"); // continue; // } fd = open(filename, O_RDWR); if (fd == -1) { printf("Failed to open file! Please check the fileaname!\n"); continue ; } m = read(fd_stdin, rdbuf,80); rdbuf[m] = 0; n = write(fd, rdbuf, m+1); close(fd); } else if (strcmp(cmd, "delete") == 0) { if(isThereFile(filename) == 0) { printf("fail to delete file, not here!\n"); continue; } m=unlink(filename); if (m == 0) { printf("File deleted!\n"); //delete file from tree records, not a dir int i = 0; for (; i < treeCurrSize; ++i) { if(strcmp(fTreeArray[i].fileName,filename) == 0) { fTreeArray[i].currDir = -1; continue; } } treeCount--; // showTree(); saveTreeToDsik(); // //write TreeRecord // char treeInfo[2048]={0}; // getTreeInfo(treeInfo); // printf("%s\n", treeInfo); // fd = open("TreeRecord", O_RDWR); // if (fd == -1) // { // printf("Failed to open 'TreeRecord'!\n"); // continue ; // } // strcpy(buf,treeInfo); // printf("buf :%s\n", buf); // n = write(fd, buf, 1024); // close(fd); continue; } else { printf("Failed to delete file! Please check the fileaname!\n"); continue; } } else { printf("Command not found, Please check!\n"); continue; } } } assert(0); /* never arrive here */ }