void DBNetworkIF::DownStreamSearch (DBObjRecord *cellRec,DBNetworkACTION forAction,DBNetworkACTION backAction,void *data) { DBObjRecord *toCell; if ((forAction != (DBNetworkACTION) NULL) && ((*forAction) (this,cellRec,data) == true)) if ((toCell = ToCell (cellRec)) != (DBObjRecord *) NULL) DownStreamSearch (toCell,forAction,backAction,data); if (backAction != (DBNetworkACTION) NULL) (*backAction) (this,cellRec,data); }
TCell TCanvas::GetCell() const { int x = GetCursorX(); int y = GetCursorY(); if (x<0 || x>=width_ || y<0 || y>=height_) { static TCell defaultCell = { ' ', TLightGrey, TBlack, }; return defaultCell; } return ToCell(cells_[x+y*width_]); }
void TCanvas::SetCell(int x, int y, TCell cell) { if (x<0 || x>=width_ || y<0 || y>=height_) { return; } TCell targetCell = ToCell(cells_[x+y*width_]); if (cell.foreground!=TUndefined) { targetCell.foreground = cell.foreground; } if (cell.background!=TUndefined) { targetCell.background = cell.background; } if (cell.ascii!=0) { targetCell.ascii = cell.ascii; } cells_[x+y*width_] = ToUShort(targetCell); }
void DBNetworkIF::SetMagnitude () { DBInt cellID; DBObjRecord *cellRec, *toCellRec; if (MagnitudeFLD == (DBObjTableField *) NULL) { MagnitudeFLD = new DBObjTableField (DBrNMagnitude,DBTableFieldInt,"%4d",sizeof (DBShort)); CellTable->AddField (MagnitudeFLD); } for (cellID = 0;cellID < CellNum ();++cellID) { cellRec = Cell (cellID); MagnitudeFLD->Int (cellRec,(FromCellDirs (cellRec) == 0x0) ? 1 : 0); } for (cellID = 0;cellID < CellNum ();++cellID) { cellRec = Cell (cellID); DBPause ((CellNum () - cellRec->RowID ()) * 100 / CellNum ()); if ((toCellRec = ToCell (cellRec)) != (DBObjRecord *) NULL) MagnitudeFLD->Int (toCellRec,MagnitudeFLD->Int (toCellRec) + MagnitudeFLD->Int (cellRec)); } }
DBInt DBNetworkIF::Build () { DBInt i, j, row, col, basin, dir, projection = DataPTR->Projection (); DBCoordinate coord0, coord1; char nameStr [DBStringLength]; DBPosition pos; DBObjRecord *cellRec, *toCell, *fromCell, *basinRec, *symbolRec; _DBnetIF = this; for (j = 0;j < BasinTable->ItemNum ();++j) { basinRec = BasinTable->Item (j); if (((cellRec = Cell (MouthPosFLD->Position (basinRec))) == (DBObjRecord *) NULL) || (ToCell (cellRec) != (DBObjRecord *) NULL)) { BasinTable->Delete (basinRec); j--; } } for (i = 0;i < CellNum ();++i) { cellRec = CellTable->Item (i); DBPause (i * 10 / CellNum ()); if (Cell (CellPosition (cellRec)) == (DBObjRecord *) NULL) continue; else if (ToCell (ToCell (cellRec)) == cellRec) ToCellFLD->Int (cellRec,DBNull); } DBPause (10); for (i = 0;i < CellNum ();++i) { cellRec = CellTable->Item (i); DBPause (10 + i * 10 / CellNum ()); pos = CellPosition (cellRec); if (((DBInt *) DataRec->Data ()) [pos.Row * ColNum () + pos.Col] == DBFault) { CellTable->Delete (cellRec); --i; } else { cellRec->Flags (DBObjectFlagLocked,DBClear); FromCellFLD->Int (cellRec,DBNull); OrderFLD->Int (cellRec,1); BasinFLD->Int (cellRec,DBFault); BasinCellsFLD->Int (cellRec,1); TravelFLD->Int (cellRec,0); UpCellPosFLD->Position (cellRec,pos); CellAreaFLD->Float (cellRec,DBMathRectangleArea (projection,Center (cellRec) - CellSize () / 2,Center (cellRec) + CellSize () / 2)); coord0 = Center (cellRec); coord1 = Center (cellRec) + Delta (cellRec); CellLengthFLD->Float (cellRec,DBMathCoordinateDistance (DataPTR->Projection (),coord0,coord1)); SubbasinLengthFLD->Float (cellRec,CellLength (cellRec)); SubbasinAreaFLD->Float (cellRec,CellAreaFLD->Float (cellRec)); } } for (j = 0;j < BasinTable->ItemNum ();++j) { basinRec = BasinTable->Item (j); cellRec = Cell (MouthPosFLD->Position (basinRec)); if ((cellRec == (DBObjRecord *) NULL) || ((cellRec->Flags () & DBObjectFlagLocked) == DBObjectFlagLocked)) { BasinTable->Delete (basinRec); j--; } else cellRec->Flags (DBObjectFlagLocked,DBSet); } DBPause (20); for (row = 0;row < RowNum ();row++) for (col = 0;col < ColNum ();col++) ((DBInt *) DataRec->Data ()) [row * ColNum () + col] = DBFault; for (i = 0;i < CellNum ();++i) { cellRec = CellTable->Item (i); cellRec->Flags (DBObjectFlagLocked,DBClear); DBPause (20 + i * 10 / CellNum ()); pos = CellPosition (cellRec); if (((DBInt *) DataRec->Data ()) [pos.Row * ColNum () + pos.Col] != DBFault) { CellTable->Delete (cellRec); --i; } else ((DBInt *) DataRec->Data ()) [pos.Row * ColNum () + pos.Col] = cellRec->RowID (); } DBPause (30); for (i = 0;i < CellNum ();++i) { cellRec = CellTable->Item (i); if ((toCell = ToCell (cellRec)) != (DBObjRecord *) NULL) FromCellFLD->Int (toCell,FromCellFLD->Int (toCell) | _DBNetworkOppositeDirection (ToCellFLD->Int (cellRec))); } for (i = 0;i < CellNum ();++i) { DBPause (30 + i * 10 / CellNum ()); cellRec = CellTable->Item (i); if (ToCell (cellRec) == (DBObjRecord *) NULL) Climb (cellRec,0); } DBPause (40); CellTable->ItemSort (_DBGNetworkCellCompare); for (i = 0;i < CellNum ();++i) { cellRec = CellTable->Item (i); DBPause (35 + i * 10/ CellNum ()); pos = CellPosition (cellRec); ((DBInt *) DataRec->Data ()) [pos.Row * ColNum () + pos.Col] = cellRec->RowID (); } DBPause (50); basin = 0; for (i = 0;i < CellNum ();++i) { cellRec = CellTable->Item (i); DBPause (50 + i * 20 / CellNum ()); if (ToCell (cellRec) == (DBObjRecord *) NULL) { SetBasin (cellRec,basin + 1); basinRec = (DBObjRecord *) NULL; for (j = 0;j < BasinTable->ItemNum ();++j) { if (((basin - j) >= 0) && ((basin - j) < BasinTable->ItemNum ()) && (cellRec == MouthCell (basinRec = BasinTable->Item (basin - j)))) break; if (((basin + j) < BasinTable->ItemNum ()) && (cellRec == MouthCell (basinRec = BasinTable->Item (basin + j)))) break; basinRec = (DBObjRecord *) NULL; } if (basinRec == (DBObjRecord *) NULL) { basinRec = BasinTable->Add ("GHAASBasin"); MouthPosFLD->Position (basinRec,CellPosition (cellRec)); } basinRec->ListPos (basin++); } } DBPause (70); CellTable->ItemSort (_DBGNetworkCellCompare); BasinTable->ItemSort (); for (i = 0;i < CellNum ();++i) { cellRec = CellTable->Item (i); DBPause (70 + i * 10 / CellNum ()); pos = CellPosition (cellRec); ((DBInt *) DataRec->Data ()) [pos.Row * ColNum () + pos.Col] = cellRec->RowID (); sprintf (nameStr,"GHAASCell:%d",cellRec->RowID () + 1); cellRec->Name (nameStr); } DBPause (80); SymbolTable->DeleteAll (); symbolRec = SymbolTable->Add ("Network Symbol"); SymbolIDFLD->Int (symbolRec,1); ForegroundFLD->Int (symbolRec,1); BackgroundFLD->Int (symbolRec,0); for (j = 0;j < BasinTable->ItemNum ();++j) { basinRec = BasinTable->Item (j); if ((strncmp (basinRec->Name (),"GHAASBasin",strlen ("GHAASBasin")) == 0) || (strlen (basinRec->Name ()) < 1)) { sprintf (nameStr,"GHAASBasin%d",basinRec->RowID () + 1); basinRec->Name (nameStr); } ColorFLD->Int (basinRec,DBFault); BasinOrderFLD->Int (basinRec,CellOrder (MouthCell (basinRec))); BasinAreaFLD->Float (basinRec,CellBasinArea (MouthCell (basinRec))); BasinLengthFLD->Float (basinRec,CellBasinLength (MouthCell (basinRec))); SymbolFLD->Record (basinRec,symbolRec); } basin = DBFault; for (i = 0;i < CellNum ();++i) { cellRec = CellTable->Item (i); if ((basinRec = Basin (cellRec)) == (DBObjRecord *) NULL) { CMmsgPrint (CMmsgAppError,"BasinID: %d CellID:%d",BasinFLD->Int (cellRec),cellRec->RowID ()); continue; } if (basin != basinRec->RowID ()) { basin = basinRec->RowID (); DBPause (80 + basin * 20 / BasinNum ()); ColorFLD->Int (basinRec,7); toCell = cellRec; } for (dir = 0;dir < 8;dir += 2) { if ((fromCell = FromCell (cellRec,0x01 << dir,false)) == (DBObjRecord *) NULL) continue; if (basinRec == Basin (fromCell)) continue; if (ColorFLD->Int (basinRec) == ColorFLD->Int (Basin (fromCell))) { ColorFLD->Int (basinRec,ColorFLD->Int (basinRec) + 1); cellRec = MouthCell (basinRec); i = cellRec->RowID () - 1; } } } DBPause (100); if (DistToMouth ()) SetDistToMouth (); if (DistToOcean ()) SetDistToOcean (); if (Magnitude ()) SetMagnitude (); return (DBSuccess); }