void RGISEditNetAddBasinXYCBK (Widget widget, RGISWorkspace *workspace,XmAnyCallbackStruct *callData) { DBInt basinID; DBDataset *dataset = UIDataset (); DBObjData *dbData =dataset->Data (); DBNetworkIF *netIF = new DBNetworkIF (dbData); DBObjTable *itemTable = dbData->Table (DBrNItems); DBObjTableField *xCoordFLD = itemTable->Field (RGISNetMouthXCoord); DBObjTableField *yCoordFLD = itemTable->Field (RGISNetMouthYCoord); DBCoordinate coord; DBObjRecord *basinRec; UITable *tableCLS = (UITable *) dbData->Display (UITableName (dbData,itemTable)); UIPauseDialogOpen ((char *) "Adding XY Coordinates"); if (xCoordFLD == NULL) { xCoordFLD = new DBObjTableField (RGISNetMouthXCoord,DBTableFieldFloat,(char *) "%10.3f",sizeof (DBFloat4)); itemTable->AddField (xCoordFLD); if (tableCLS != (UITable *) NULL) tableCLS->AddField (xCoordFLD); UIPause (40); } if (yCoordFLD == NULL) { yCoordFLD = new DBObjTableField (RGISNetMouthYCoord,DBTableFieldFloat,(char *) "%10.3f",sizeof (DBFloat4)); itemTable->AddField (yCoordFLD); if (tableCLS != (UITable *) NULL) tableCLS->AddField (yCoordFLD); UIPause (80); } for (basinID = 0;basinID < netIF->BasinNum ();++basinID) { basinRec = netIF->Basin (basinID); if (UIPause (80 + basinID * 20 / netIF->BasinNum ())) goto Stop; coord = netIF->Center (netIF->MouthCell (basinRec)); xCoordFLD->Float (basinRec,coord.X); yCoordFLD->Float (basinRec,coord.Y); } Stop: UIPauseDialogClose (); if (tableCLS != (UITable *) NULL) tableCLS->Draw (); }
int main(int argc, char *argv[]) { int argPos, argNum = argc, ret, verbose = false; DBInt recID; DBObjData *data; char *tableName = (char *) NULL; char *fieldIDName = (char *) NULL; char *fieldXName = (char *) NULL; char *fieldYName = (char *) NULL; DBObjTable *table; DBObjTableField *fieldID, *fieldX, *fieldY; DBObjRecord *record; DBNetworkIF *netIF; DBCoordinate coord; for (argPos = 1; argPos < argNum;) { if (CMargTest (argv[argPos], "-a", "--table")) { if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) { CMmsgPrint(CMmsgUsrError, "Missing table name!"); return (CMfailed); } tableName = argv[argPos]; if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break; continue; } if (CMargTest (argv[argPos], "-f", "--IDfield")) { if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) { CMmsgPrint(CMmsgUsrError, "Missing field name!"); return (CMfailed); } fieldIDName = argv[argPos]; if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break; continue; } if (CMargTest (argv[argPos], "-x", "--Xfield")) { if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) { CMmsgPrint(CMmsgUsrError, "Missing field name!"); return (CMfailed); } fieldXName = argv[argPos]; if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break; continue; } if (CMargTest (argv[argPos], "-y", "--Yfield")) { if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) { CMmsgPrint(CMmsgUsrError, "Missing field name!"); return (CMfailed); } fieldYName = argv[argPos]; if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break; continue; } if (CMargTest (argv[argPos], "-V", "--verbose")) { verbose = true; if ((argNum = CMargShiftLeft(argPos, argv, argNum)) <= argPos) break; continue; } if (CMargTest (argv[argPos], "-h", "--help")) { CMmsgPrint(CMmsgInfo, "%s [options] <input file> <output file>", CMfileName(argv[0])); CMmsgPrint(CMmsgInfo, " -a, --table [ [DBCells] | DBItems ]"); CMmsgPrint(CMmsgInfo, " -f, --IDfield [ [CellID] | BasinID ]"); CMmsgPrint(CMmsgInfo, " -x, --Xfield [ [CellXCoord] | MouthXCoord ]"); CMmsgPrint(CMmsgInfo, " -y, --Yfield [ [CellYCoord] | MouthYCoord ]"); CMmsgPrint(CMmsgInfo, " -V, --verbose"); CMmsgPrint(CMmsgInfo, " -h, --help"); return (DBSuccess); } if ((argv[argPos][0] == '-') && (strlen(argv[argPos]) > 1)) { CMmsgPrint(CMmsgUsrError, "Unknown option: %s!", argv[argPos]); return (CMfailed); } argPos++; } if (argNum > 3) { CMmsgPrint(CMmsgUsrError, "Extra arguments!"); return (CMfailed); } if (verbose) RGlibPauseOpen(argv[0]); if (tableName == (char *) NULL) tableName = (char *) "DBCells"; if (fieldIDName == (char *) NULL) fieldIDName = (char *) "CellID"; if (fieldXName == (char *) NULL) fieldXName = (char *) "CellXCoord"; if (fieldYName == (char *) NULL) fieldYName = (char *) "CellYCoord"; data = new DBObjData(); if (((argNum > 1) && (strcmp(argv[1], "-") != 0) ? data->Read(argv[1]) : data->Read(stdin)) == DBFault) { delete data; return (CMfailed); } if ((table = data->Table(tableName)) == (DBObjTable *) NULL) { CMmsgPrint(CMmsgUsrError, "Invalid table: %s!", tableName); delete data; return (CMfailed); } netIF = new DBNetworkIF(data); fieldID = new DBObjTableField(fieldIDName, DBTableFieldInt, (char *) "%8d", sizeof (DBInt)); fieldX = new DBObjTableField (fieldXName, DBTableFieldFloat, (char *) "%10.3f", sizeof (DBFloat4)); fieldY = new DBObjTableField (fieldYName, DBTableFieldFloat, (char *) "%10.3f", sizeof (DBFloat4)); table->AddField(fieldID); table->AddField(fieldX); table->AddField(fieldY); if (strcmp(fieldIDName, "CellID") == 0) { for (recID = 0; recID < table->ItemNum(); ++recID) { record = netIF->Cell(recID); coord = netIF->Center(record); fieldID->Int(record, recID+1); fieldX->Float(record, coord.X); fieldY->Float(record, coord.Y); } } else if (strcmp(fieldIDName, "BasinID") == 0) { for (recID = 0; recID < netIF->BasinNum(); ++recID) { record = netIF->Basin(recID); coord = netIF->Center(netIF->MouthCell(record)); fieldID->Int(record, recID+1); fieldX->Float(record,coord.X); fieldY->Float(record,coord.Y); } } else { CMmsgPrint(CMmsgUsrError, "Invalid field name: %s!", fieldIDName); delete data; return (CMfailed); } ret = (argNum > 2) && (strcmp(argv[2], "-") != 0) ? data->Write(argv[2]) : data->Write(stdout); delete data; if (verbose) RGlibPauseClose(); return (ret); }
void _RGISUserFuncionNetwork (DBObjData *data,UI2DView *view,XEvent *event) { DBInt sX, sY, redraw = false; DBNetworkIF *netIF; DBCoordinate coord; DBObjRecord *cellRec, *basinRec; void _RGISUserFuncionQuery (DBObjData *,UI2DView *,XEvent *); if ((data->Flags () & DBDataFlagUserModeFlags) == DBDataFlagUserModeQuery) { _RGISUserFuncionQuery (data,view,event); return; } if (event->type != ButtonPress) return; if (DBTypeNetwork != data->Type ()) { CMmsgPrint (CMmsgAppError, "Invalid data Type in: %s %d",__FILE__,__LINE__); } sX = event->xbutton.x; sY = event->xbutton.y; view->Window2Map (sX,sY, &coord.X, &coord.Y); netIF = new DBNetworkIF (data); switch (data->Flags () & DBDataFlagUserModeFlags) { case DBDataFlagUserModeSelect: { DBInt basinID, cellID; DBRegion extent; UITable *tableView; if ((cellRec = netIF->Cell (coord)) == (DBObjRecord *) NULL) { UIMessage ((char *) "Cell Does not Exists!"); return; } for (basinID = 0;basinID < netIF->BasinNum ();++basinID) { basinRec = netIF->Basin (basinID); if ((basinRec->Flags () & DBObjectFlagSelected) == DBObjectFlagSelected) { data->SelectObject (basinRec,DBClear); extent.Expand (data->Extent (basinRec)); } } for (cellID = 0;cellID < netIF->CellNum ();++cellID) { cellRec = netIF->Cell (cellID); if ((cellRec->Flags () & DBObjectFlagSelected) == DBObjectFlagSelected) { extent.Expand (netIF->Center (cellRec) + (netIF->CellSize () / 2.0)); extent.Expand (netIF->Center (cellRec) - (netIF->CellSize () / 2.0)); cellRec->Flags (DBObjectFlagSelected,DBClear); } } if ((tableView = (UITable *) data->Display (UITableName (data,data->Table (DBrNItems)))) != (UITable *) NULL) tableView->Draw (); if ((tableView = (UITable *) data->Display (UITableName (data,data->Table (DBrNCells)))) != (UITable *) NULL) tableView->Draw (); UI2DViewRedrawAll (extent); cellRec = netIF->Cell (coord); switch (data->Flags () & DBDataFlagSelectMode) { case DBDataFlagSelectMode: netIF->DownStreamSearch (cellRec, DBNetworkSelect); break; default: netIF->UpStreamSearch (cellRec, DBNetworkSelect); break; } extent.Initialize (); for (cellID = 0;cellID < netIF->CellNum ();++cellID) { cellRec = netIF->Cell (cellID); if ((cellRec->Flags () & DBObjectFlagSelected) == DBObjectFlagSelected) { extent.Expand (netIF->Center (cellRec) + (netIF->CellSize () / 2.0)); extent.Expand (netIF->Center (cellRec) - (netIF->CellSize () / 2.0)); } } UI2DViewRedrawAll (extent); if ((tableView = (UITable *) data->Display (UITableName (data,data->Table (DBrNCells)))) != (UITable *) NULL) tableView->Draw (); } break; case DBDataFlagUserModeAdd: if (netIF->CellAdd (coord) == (DBObjRecord *) NULL) UIMessage ((char *) "Cell Creation Error"); else redraw = true; break; case DBDataFlagUserModeDelete: if (netIF->CellDelete (coord) == DBFault) UIMessage ((char *) "Cell Does not Exists!"); else redraw = true; break; case DBDataFlagUserModeRotate: { DBObjRecord *cellRec = netIF->Cell (coord); if (cellRec != (DBObjRecord *) NULL) { switch (netIF->CellDirection (cellRec)) { case DBNull: netIF->CellDirection (cellRec,DBNetDirN); break; case DBNetDirNW: netIF->CellDirection (cellRec,DBNull); break; default: netIF->CellRotate (cellRec,DBForward); break; } redraw = true; } } break; default: printf ("Unknown Mode %lX",data->Flags () & DBDataFlagUserModeFlags); break; } if (redraw) { DBPosition pos; if (netIF->Coord2Pos (coord,pos) == DBSuccess) { DBRegion extent; DBCoordinate delta (netIF->CellWidth () * 1.25, netIF->CellHeight () * 1.25); netIF->Pos2Coord (pos,coord); coord = coord + delta; extent.Expand (coord); netIF->Pos2Coord (pos,coord); coord = coord - delta; extent.Expand (coord); UI2DViewRedrawAll (extent); } } delete netIF; }
static void _RGISToolsNetBasinMouthCBK (Widget widget,RGISWorkspace *workspace,XmAnyCallbackStruct *callData) { DBDataset *dataset = UIDataset (); DBObjData *netData = dataset->Data (), *pntData; DBNetworkIF *netIF; widget = widget; callData = callData; if (netData == (DBObjData *) NULL) { CMmsgPrint (CMmsgAppError, "Null Data in: %s %d",__FILE__,__LINE__); return; } netIF = new DBNetworkIF (netData); if (UIDataHeaderForm (pntData = new DBObjData ("",DBTypeVectorPoint))) { char symName [DBStringLength]; DBInt basinID, order; DBCoordinate coord; DBObjTable *items = pntData->Table (DBrNItems); DBObjTable *symbols = pntData->Table (DBrNSymbols); DBObjTableField *coordField = items->Field (DBrNCoord); DBObjTableField *symbolFLD = items->Field (DBrNSymbol); DBObjTableField *orderFLD = new DBObjTableField (DBrNOrder,DBTableFieldInt,"%3d",sizeof (DBByte)); DBObjTableField *subbasinLengthFLD = new DBObjTableField (DBrNSubbasinLength,DBTableFieldFloat,"%10.1f",sizeof (float)); DBObjTableField *subbasinAreaFLD = new DBObjTableField (DBrNSubbasinArea,DBTableFieldFloat,"%10.1f",sizeof (float)); DBObjTableField *foregroundFLD = symbols->Field (DBrNForeground); DBObjTableField *backgroundFLD = symbols->Field (DBrNBackground); DBObjTableField *styleFLD = symbols->Field (DBrNStyle); DBObjRecord *pntRec, *symRec, *cellRec, *basinRec; DBRegion dataExtent; items->AddField (orderFLD); items->AddField (subbasinLengthFLD); items->AddField (subbasinAreaFLD); cellRec = netIF->Cell ((DBInt) 0); for (order = 0;order <= netIF->CellOrder (cellRec);++order) { sprintf (symName,"Strahler Order:%2d",order); symRec = symbols->Add (symName); styleFLD->Int (symRec,0); foregroundFLD->Int (symRec,1); backgroundFLD->Int (symRec,0); } UIPauseDialogOpen ((char *) "Creating Basin Mouth"); for (basinID = 0;basinID < netIF->BasinNum ();++basinID) { basinRec = netIF->Basin (basinID); if (UIPause (basinID * 100 / netIF->BasinNum ())) goto Stop; symRec = symbols->Item (netIF->CellOrder (cellRec)); cellRec = netIF->MouthCell (basinRec); pntRec = items->Add (basinRec->Name ()); coord = netIF->Center (cellRec); coordField->Coordinate (pntRec,coord); symbolFLD->Record (pntRec,symRec); orderFLD->Int (pntRec,netIF->CellOrder (cellRec)); subbasinLengthFLD->Float (pntRec,netIF->CellBasinLength (cellRec)); subbasinAreaFLD->Float (pntRec,netIF->CellBasinArea (cellRec)); dataExtent.Expand (coord); } Stop: UIPauseDialogClose (); pntData->Extent (dataExtent); workspace->CurrentData (pntData); } else delete pntData; delete netIF; }