void Update () { ForegroundFLD->Int (OrigREC,Foreground ()); BackgroundFLD->Int (OrigREC,Background ()); StyleFLD->Int (OrigREC,Style ()); OrigREC->Name (Name ()); }
DBInt IsChanged() { if (Foreground() != ForegroundFLD->Int(OrigREC)) return (true); if (Background() != BackgroundFLD->Int(OrigREC)) return (true); if (Style() != StyleFLD->Int(OrigREC)) return (true); if (strcmp(Name(), OrigREC->Name()) != 0) return (true); return (false); }
static void _RGISGrpPanelNewCBK (Widget widget,RGISGrpPanel *grpPanel,XmAnyCallbackStruct *callData) { char *groupName; DBDataset *dataset = UIDataset (); DBObjData *dbData = dataset->Data (); DBObjTable *groupTable = dbData->Table (DBrNGroups); DBObjTableField *group; DBObjRecord *record; if ((groupName = UIGetString ((char *) "Group Name",16)) == (char *) NULL) return; if (groupTable == (DBObjTable *) NULL) { DBObjTable *items = dbData->Table (DBrNItems); DBObjectLIST<DBObjTable> *tables = dbData->Tables (); DBTableFieldDefinition fieldDefs [] = { DBTableFieldDefinition (groupName, DBTableFieldInt,(char *) "%1d",sizeof (DBByte)), DBTableFieldDefinition () }; tables->Add (groupTable = new DBObjTable (DBrNGroups,fieldDefs)); grpPanel->Groups (groupTable->Fields ()); group = groupTable->Field (groupName); for (record = items->First ();record != (DBObjRecord *) NULL;record = items->Next ()) group->Int (groupTable->Add (record->Name ()),true); } else { groupTable->AddField (group = new DBObjTableField (groupName,DBTableFieldInt,"%1d",sizeof (DBByte))); for (record = groupTable->First ();record != (DBObjRecord *) NULL;record = groupTable->Next ()) group->Int (record,true); } grpPanel->Add (group); }
DBObjRecord *DBVectorIF::Item (DBCoordinate coord) const { DBObjRecord *record, *retRecord = (DBObjRecord *) NULL; switch (DataPTR->Type ()) { case DBTypeVectorPoint: { DBFloat dist, minDist = DBHugeVal; DBObjTableField *coordFLD = ItemTable->Field (DBrNCoord); DBMathDistanceFunction distFunc = DBMathGetDistanceFunction (DataPTR); for (record = FirstItem ();record != (DBObjRecord *) NULL;record = NextItem ()) { dist = DBMathCoordinateDistance (distFunc,coord,coordFLD->Coordinate (record)); if (dist < minDist) { minDist = dist; retRecord = record; } } } break; case DBTypeVectorLine: break; case DBTypeVectorPolygon: break; default: CMmsgPrint (CMmsgAppError, "Unknown Vector Data Type in: %s %d",__FILE__,__LINE__); break; } return (retRecord); }
int DBObjTable::Write(FILE *file) { DBInt id; DBObjRecord *obj; DBObjRecord *record; DBObjTableField *field; if (DBObjectLIST<DBObjRecord>::Write(file) != DBSuccess) return (DBFault); if (FieldPTR->Write(file) != DBSuccess) return (DBFault); for (id = 0; id < FieldPTR->ItemNum(); ++id) if (FieldPTR->WriteItem(file, id) == DBFault) return (DBFault); for (id = 0; id < ItemNum(); ++id) { record = Item(id); for (field = FieldPTR->First(); field != (DBObjTableField *) NULL; field = FieldPTR->Next()) switch (field->Type()) { case DBTableFieldTableRec: case DBTableFieldDataRec: if ((obj = field->Record(record)) != (DBObjRecord *) NULL) field->Record(record, (DBObjRecord *) ((char *) NULL + obj->RowID())); else field->Record(record, (DBObjRecord *) DBFault); break; } if (WriteItem(file, id) == DBFault) return (DBFault); } if (MethodPTR->Write(file) != DBSuccess) return (DBFault); for (id = 0; id < MethodPTR->ItemNum(); ++id) if (MethodPTR->WriteItem(file, id) == DBFault) return (DBFault); return (DBSuccess); }
DBObjData::DBObjData(DBObjData &data) : DBObject(data), DBDataHeader(data._Header()) { DBObjTable *table; DBObjRecord *record, *obj; DBObjTableField *field; DBObjectLIST<DBObjTableField> *fields; strcpy(FileNameSTR, ""); TablesPTR = new DBObjectLIST<DBObjTable>(*data.TablesPTR); DocsPTR = new DBObjectLIST<DBObjRecord>(*data.DocsPTR); ArraysPTR = new DBObjectLIST<DBObjRecord>(*data.ArraysPTR); DispPTR = new DBObjectLIST<DBObject>("Data Display"); LinkedDataPTR = (DBObjData *) NULL; for (table = TablesPTR->First(); table != (DBObjTable *) NULL; table = TablesPTR->Next()) { fields = table->Fields(); for (record = table->First(); record != (DBObjRecord *) NULL; record = table->Next()) { for (field = fields->First(); field != (DBObjTableField *) NULL; field = fields->Next()) switch (field->Type()) { case DBTableFieldTableRec: case DBTableFieldDataRec: if ((obj = field->Record(record)) != NULL) field->Record(record, (DBObjRecord *) ((char *) NULL + obj->RowID())); else field->Record(record, (DBObjRecord *) DBFault); break; } } } BuildFields(); }
void DBObjTable::RedefineField(DBObjTableField *field, DBObjTableField *newField) { DBInt recID, fieldID; DBObjRecord *record, *oldRecord; DBObjTableField *tmpField; newField->StartByte(field->StartByte()); if (field->Length() != newField->Length()) { RecordLengthVAR += (newField->Length() - field->Length()); for (fieldID = field->RowID() + 1; fieldID < FieldNum(); ++fieldID) { tmpField = Field(fieldID); tmpField->StartByte(tmpField->StartByte() + newField->Length() - field->Length()); } } for (recID = 0; recID < ItemNum(); recID++) { record = Item(recID); oldRecord = new DBObjRecord(*record); if (field->Length() != newField->Length()) { record->Realloc(RecordLengthVAR); if (newField->StartByte() + newField->Length() < RecordLengthVAR) memcpy(((char *) record->Data()) + newField->StartByte() + newField->Length(), ((char *) oldRecord->Data()) + field->StartByte() + field->Length(), RecordLengthVAR - (newField->StartByte() + newField->Length())); } switch (newField->Type()) { case DBTableFieldString: newField->String(record, field->String(oldRecord)); break; case DBTableFieldInt: newField->Int(record, field->Int(oldRecord)); break; case DBTableFieldFloat: newField->Float(record, field->Float(oldRecord)); break; case DBTableFieldDate: newField->Date(record, field->Date(oldRecord)); break; case DBTableFieldCoord: newField->Coordinate(record, field->Coordinate(oldRecord)); break; case DBTableFieldRegion: newField->Region(record, field->Region(oldRecord)); break; case DBTableFieldPosition: newField->Position(record, field->Position(oldRecord)); break; case DBTableFieldTableRec: case DBTableFieldDataRec: newField->Record(record, field->Record(oldRecord)); break; } delete oldRecord; } if (strcmp(field->Name(), newField->Name()) != 0) field->Name(newField->Name()); if (field->Type() != newField->Type()) field->Type(newField->Type()); if (field->FormatWidth() != newField->FormatWidth()) field->FormatWidth(newField->FormatWidth()); if ((field->Type() == DBTableFieldFloat) && (field->FormatDecimals() != field->FormatDecimals())) field->FormatDecimals(newField->FormatDecimals()); if (field->Length() != newField->Length()) field->Length(newField->Length()); }
void RGISAnNetworkToGridCBK (Widget widget,RGISWorkspace *workspace,XmAnyCallbackStruct *callData) { char *selection; DBInt dataType; DBDataset *dataset = UIDataset (); DBObjData *netData = dataset->Data (); DBObjTable *cellTable = netData->Table (DBrNCells); DBObjTableField *field; DBObjData *grdData; static Widget select = NULL; if (select == NULL) select = UISelectionCreate ((char *) "Field Selection"); selection = UISelectObject (select,(DBObjectLIST<DBObject> *) (cellTable->Fields ()),DBTableFieldIsSimple); if (selection == (char *) NULL) return; if ((field = cellTable->Field (selection)) == (DBObjTableField *) NULL) { CMmsgPrint (CMmsgAppError,"Corrupt Network Dataset in: %s %d",__FILE__,__LINE__); return; } if (DBTableFieldIsCategory (field) && DBTableFieldIsNumeric (field)) { DBObjData *tmpData; tmpData = new DBObjData ("",DBTypeGrid); tmpData->Document (DBDocGeoDomain,netData->Document (DBDocGeoDomain)); tmpData->Document (DBDocSubject,field->Name ()); if (UIDataHeaderForm (tmpData)) { grdData = DBNetworkToGrid (netData,tmpData->Type ()); grdData->Name (tmpData->Name ()); grdData->Document (DBDocGeoDomain,tmpData->Document (DBDocGeoDomain)); grdData->Document (DBDocSubject,tmpData->Document (DBDocSubject)); grdData->Document (DBDocVersion,tmpData->Document (DBDocVersion)); grdData->Document (DBDocCitationRef,tmpData->Document (DBDocCitationRef)); grdData->Document (DBDocCitationInst,tmpData->Document (DBDocCitationInst)); grdData->Document (DBDocSourceInst,tmpData->Document (DBDocSourceInst)); grdData->Document (DBDocSourcePerson,tmpData->Document (DBDocSourcePerson)); grdData->Document (DBDocOwnerPerson,tmpData->Document (DBDocOwnerPerson)); grdData->Document (DBDocComment,tmpData->Document (DBDocComment)); delete tmpData; } else { return; } } else { if (DBTableFieldIsCategory (field)) dataType = DBTypeGridDiscrete; else if (DBTableFieldIsNumeric (field)) dataType = DBTypeGridContinuous; else { CMmsgPrint (CMmsgAppError,"Invalid field type in: %s %d",__FILE__,__LINE__); return; } grdData = DBNetworkToGrid (netData,dataType); if (UIDataHeaderForm (grdData) == false) { delete grdData; return; } } UIPauseDialogOpen ((char *) "Converting Network to Grid"); if (RGlibNetworkToGrid (netData,field,grdData) == DBSuccess) workspace->CurrentData (grdData); else delete grdData; UIPauseDialogClose (); }
void UIAttribView::Draw (DBObjRecord *record) { DBObjTableField *field; DBObjectLIST<DBObjTableField> *fields; UIXYGraphShell *graphCLS; if (record == (DBObjRecord *) NULL) { Cardinal i, numChildren; WidgetList rowCols; UIAuxSetLabelString (ItemNameWGT,(char *) ""); XtVaGetValues (FieldsRowCol,XmNchildren, &rowCols, XmNnumChildren, &numChildren,NULL); for (i = 0;i < numChildren; ++i) XmTextFieldSetString (XtNameToWidget (rowCols [i],"UIAttribViewTextField"),(char *) ""); return; } UIAuxSetLabelString (ItemNameWGT,record->Name ()); switch (DataPTR->Type ()) { case DBTypeVectorPoint: case DBTypeVectorLine: case DBTypeVectorPolygon: case DBTypeGridDiscrete: fields = ItemTable->Fields (); for (field = fields->First ();field != (DBObjTableField *) NULL;field = fields->Next ()) if (DBTableFieldIsVisible (field) == true) DrawField (field->Name (),field->String (record)); break; case DBTypeGridContinuous: { DBCoordinate coord = *((DBCoordinate *) (record->Data ())); DBGridIF *gridIF = new DBGridIF (DataPTR); for (record = ItemTable->First ();record != (DBObjRecord *) NULL;record = ItemTable->Next ()) DrawField (record->Name (),gridIF->ValueString (record,coord)); delete gridIF; } break; case DBTypeNetwork: { DBObjTable *cellTable = DataPTR->Table (DBrNCells); DBObjTableField *basinFLD = cellTable->Field (DBrNBasin); DBObjRecord *basinRec; if ((basinRec = ItemTable->Item (basinFLD->Int (record) - 1)) == (DBObjRecord *) NULL) { CMmsgPrint (CMmsgAppError, "BasinID Error in:%s %d",__FILE__,__LINE__); return; } DrawField ((char *) "Basin Name",basinRec->Name ()); fields = ItemTable->Fields (); for (field = fields->First ();field != (DBObjTableField *) NULL;field = fields->Next ()) if (DBTableFieldIsVisible (field) == true) DrawField (field->Name (),field->String (basinRec)); fields = cellTable->Fields (); for (field = fields->First ();field != (DBObjTableField *) NULL;field = fields->Next ()) if (DBTableFieldIsVisible (field) == true) DrawField (field->Name (),field->String (record)); } break; default: break; } if ((graphCLS = (UIXYGraphShell *) DataPTR->Display (UIXYGraphShellStr)) != (UIXYGraphShell *) NULL) graphCLS->Configure (record); }
DBInt DBTableFieldIsOptional(const DBObject *obj) { DBObjTableField *tableField = (DBObjTableField *) obj; switch (tableField->Type()) { case DBTableFieldString: case DBTableFieldInt: case DBTableFieldFloat: case DBTableFieldDate: return (tableField->Required() ? false : true); default: return (false); } }
DBInt Configure(DBObjTable *table, bool flat) { DBInt i; char *dataName; char *fieldName = (char *) NULL; DBObjData *data; dataName = TargetFLD->Name(); if ((dataName = (char *) malloc(strlen(dataName) + 1)) == (char *) NULL) { CMmsgPrint(CMmsgSysError, "Memory allocation error in: %s %d", __FILE__, __LINE__); return (CMfailed); } strcpy(dataName, TargetFLD->Name()); for (i = 0; i < (DBInt) strlen(dataName); ++i) if (dataName[i] == ':') { fieldName = dataName + i + 1; dataName[i] = '\0'; i = 0; break; } data = new DBObjData(); if ((strcmp(dataName, "stdin") == 0 ? data->Read(stdin) : data->Read(dataName)) == DBFault) { CMmsgPrint(CMmsgUsrError, "%s", dataName); return (CMfailed); } if (data->Type() == DBTypeGridDiscrete) { DBObjTable *table = data->Table(DBrNItems); if (fieldName == (char *) NULL) fieldName = DBrNGridValue; if ((SourceFLD = table->Field(fieldName)) == (DBObjTableField *) NULL) { CMmsgPrint(CMmsgUsrError, "Invalid field [%s]!", fieldName); return (CMfailed); } strcpy(dataName, TargetFLD->Name()); delete TargetFLD; TargetFLD = new DBObjTableField(*SourceFLD); TargetFLD->Name(dataName); } else { if (fieldName != (char *) NULL) { CMmsgPrint(CMmsgUsrError, "Continuous grid field is referenced!"); free(dataName); return (CMfailed); } } table->AddField(TargetFLD); GridIF = new DBGridIF(data, flat); free(dataName); return (DBSuccess); }
DBInt DBTableFieldIsVisible(const DBObject *obj) { DBObjTableField *tableField = (DBObjTableField *) obj; switch (tableField->Type()) { case DBTableFieldString: case DBTableFieldInt: case DBTableFieldFloat: case DBTableFieldDate: return (strlen(tableField->Format()) > 0 ? true : false); default: return (false); } }
void DBGridIF::DiscreteStats() { DBInt recordID, layerID; DBFloat area, sumArea = 0.0; DBPosition pos; DBObjTableField *areaFLD = ItemTable->Field(DBrNGridArea); DBObjTableField *percentFLD = ItemTable->Field(DBrNGridPercent); DBObjRecord *layerRec, *record; for (recordID = 0; recordID < ItemTable->ItemNum(); ++recordID) { record = ItemTable->Item(recordID); areaFLD->Float(record, 0.0); percentFLD->Float(record, 0.0); } for (layerID = 0; layerID < LayerNum(); ++layerID) { layerRec = Layer(layerID); for (pos.Row = 0; pos.Row < RowNum(); ++pos.Row) for (pos.Col = 0; pos.Col < ColNum(); ++pos.Col) if ((record = GridItem(layerRec, pos)) != (DBObjRecord *) NULL) { area = CellArea(pos); sumArea += area; areaFLD->Float(record, areaFLD->Float(record) + area); } } for (recordID = 0; recordID < ItemTable->ItemNum(); ++recordID) { record = ItemTable->Item(recordID); percentFLD->Float(record, areaFLD->Float(record) * 100.0 / sumArea); } }
DBRegion DBObjData::Extent(DBObjRecord *record) { DBRegion extent; DBCoordinate coord; DBFloat delta; DBObjTable *items; DBObjTableField *field; if (record == (DBObjRecord *) NULL) return (Extent()); switch (Type()) { case DBTypeVectorPoint: delta = pow((double) 10.0, (double) Precision()); items = TablesPTR->Item(DBrNItems); field = items->Field(DBrNCoord); coord = field->Coordinate(record); extent.Expand(coord + delta); extent.Expand(coord - delta); return (extent); case DBTypeVectorLine: case DBTypeVectorPolygon: items = TablesPTR->Item(DBrNItems); field = items->Field(DBrNRegion); return (field->Region(record)); case DBTypeGridDiscrete: case DBTypeGridContinuous: return (Extent()); case DBTypeNetwork: { DBInt cellID, cellNum; DBObjRecord *cellRec; DBNetworkIF *netIF = new DBNetworkIF(this); cellRec = netIF->MouthCell(record); cellNum = netIF->CellBasinCells(cellRec) + cellRec->RowID(); for (cellID = cellRec->RowID(); cellID < cellNum; ++cellID) { cellRec = netIF->Cell(cellID); extent.Expand(netIF->Center(cellRec) + (netIF->CellSize() / 2.0)); extent.Expand(netIF->Center(cellRec) - (netIF->CellSize() / 2.0)); } delete netIF; } return (extent); case DBTypeTable: default: return (extent); } }
DBInt RGlibGenFuncFieldCompare(DBObjTable *table, char *f0Text, char *f1Text, char *rText, DBInt diffMethod) { DBInt intVal, ret, i, rowID; DBFloat val[2]; DBObjTableField *field[2]; DBObjTableField *result; DBObjRecord *record; field[0] = table->Field(f0Text); field[1] = table->Field(f1Text); result = table->Field(rText); if ((field[0] == (DBObjTableField *) NULL) || (field[1] == (DBObjTableField *) NULL)) { CMmsgPrint(CMmsgAppError, "Invalid Compare Fields in: %s %d", __FILE__, __LINE__); return (DBFault); } if (result == (DBObjTableField *) NULL) table->AddField(result = new DBObjTableField(rText, DBTableFieldFloat, "%10.3f", sizeof(DBFloat4))); if (diffMethod > 0) result->Format("%6.2f"); for (rowID = 0; rowID < table->ItemNum(); ++rowID) { record = table->Item(rowID); if ((record->Flags() & DBObjectFlagIdle) == DBObjectFlagIdle) result->Float(record, result->FloatNoData()); else { for (i = 0; i < 2; ++i) if (field[i]->Type() == DBTableFieldInt) { intVal = field[i]->Int(record); ret = intVal == field[i]->IntNoData(); val[i] = (DBFloat) intVal; } else { val[i] = field[i]->Float(record); ret = CMmathEqualValues(val[i], field[i]->FloatNoData()); } if (ret) result->Float(record, result->FloatNoData()); else switch (diffMethod) { default: result->Float(record, val[0] - val[1]); break; case 1: result->Float(record, (val[0] - val[1]) * 100.0 / val[0]); break; case 2: result->Float(record, (val[0] - val[1]) * 100.0 / (val[0] > val[1] ? val[0] : val[1])); break; } } } return (DBSuccess); }
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 (); }
void RGISEditPointAddXYCBK (Widget widget, RGISWorkspace *workspace,XmAnyCallbackStruct *callData) { DBDataset *dataset = UIDataset (); DBObjData *dbData =dataset->Data (); DBVPointIF *pntIF = new DBVPointIF (dbData); DBObjTable *pointTable = dbData->Table (DBrNItems); DBObjTableField *xCoordFLD = pointTable->Field (RGISEditPointXCoord); DBObjTableField *yCoordFLD = pointTable->Field (RGISEditPointYCoord); DBCoordinate coord; DBObjRecord *pointRec; UITable *tableCLS = (UITable *) dbData->Display (UITableName (dbData,pointTable)); widget = widget; workspace = workspace; callData = callData; UIPauseDialogOpen ((char *) "Adding XY Coordinates"); if (xCoordFLD == NULL) { xCoordFLD = new DBObjTableField (RGISEditPointXCoord,DBTableFieldFloat,"%10.3f",sizeof (DBFloat4)); pointTable->AddField (xCoordFLD); if (tableCLS != (UITable *) NULL) tableCLS->AddField (xCoordFLD); UIPause (40); } if (yCoordFLD == NULL) { yCoordFLD = new DBObjTableField (RGISEditPointYCoord,DBTableFieldFloat,"%10.3f",sizeof (DBFloat4)); pointTable->AddField (yCoordFLD); if (tableCLS != (UITable *) NULL) tableCLS->AddField (yCoordFLD); UIPause (80); } for (pointRec = pntIF->FirstItem (); pointRec != (DBObjRecord *) NULL; pointRec = pntIF->NextItem ()) { if (UIPause (80 + pointRec->RowID () * 20 / pntIF->ItemNum ())) goto Stop; coord = pntIF->Coordinate (pointRec); xCoordFLD->Float (pointRec,coord.X); yCoordFLD->Float (pointRec,coord.Y); } Stop: UIPauseDialogClose (); if (tableCLS != (UITable *) NULL) tableCLS->Draw (); }
void DBObjTable::DeleteField(DBObjTableField *delField) { DBInt i, recID, fieldID; DBObjRecord *record; DBObjTableField *field; unsigned char *data; for (fieldID = 0; fieldID < FieldPTR->ItemNum(); ++fieldID) { field = FieldPTR->Item(fieldID); if (field->StartByte() > delField->StartByte()) field->StartByte(field->StartByte() - delField->Length()); } for (recID = 0; recID < ItemNum(); ++recID) { record = Item(recID); data = (unsigned char *) record->Data() + delField->StartByte(); for (i = 0; i < RecordLengthVAR - delField->StartByte() - delField->Length(); ++i) data[i] = data[i + delField->Length()]; record->Realloc(RecordLengthVAR - delField->Length()); } FieldPTR->Remove(delField); RecordLengthVAR -= delField->Length(); delete delField; }
DBInt RGlibPointSubbasinCenter(DBObjData *pntData, DBObjData *netData) { DBCoordinate massCoord; DBVPointIF *pntIF = new DBVPointIF(pntData); DBObjTable *pointTable = pntData->Table(DBrNItems); DBObjTableField *massCoordXFLD = pointTable->Field(RGlibMassCoordX); DBObjTableField *massCoordYFLD = pointTable->Field(RGlibMassCoordY); DBNetworkIF *netIF = new DBNetworkIF(netData); DBObjRecord *pointRec, *cellRec; if (massCoordXFLD == NULL) { massCoordXFLD = new DBObjTableField(RGlibMassCoordX, DBTableFieldFloat, "%10.3f", sizeof(DBFloat4)); pointTable->AddField(massCoordXFLD); } if (massCoordYFLD == NULL) { massCoordYFLD = new DBObjTableField(RGlibMassCoordY, DBTableFieldFloat, "%10.3f", sizeof(DBFloat4)); pointTable->AddField(massCoordYFLD); } for (pointRec = pntIF->FirstItem(); pointRec != (DBObjRecord *) NULL; pointRec = pntIF->NextItem()) { if ((pointRec->Flags() & DBObjectFlagIdle) == DBObjectFlagIdle) { massCoordXFLD->Float(pointRec, massCoordXFLD->FloatNoData()); massCoordYFLD->Float(pointRec, massCoordYFLD->FloatNoData()); continue; } if (DBPause(pointRec->RowID() * 100 / pntIF->ItemNum())) goto Stop; if ((cellRec = netIF->Cell(pntIF->Coordinate(pointRec))) == (DBObjRecord *) NULL) massCoord = pntIF->Coordinate(pointRec); else { if (netIF->CellBasinCells(cellRec) > 1) { massCoord.X = 0.0; massCoord.Y = 0.0; netIF->UpStreamSearch(cellRec, (DBNetworkACTION) _RGlibSubbasinCenterAction, &massCoord); massCoord.X = massCoord.X / (DBFloat) netIF->CellBasinCells(cellRec); massCoord.Y = massCoord.Y / (DBFloat) netIF->CellBasinCells(cellRec); } else massCoord = netIF->Center(cellRec); } massCoordXFLD->Float(pointRec, massCoord.X); massCoordYFLD->Float(pointRec, massCoord.Y); } Stop: if (pointRec != (DBObjRecord *) NULL) { pointTable->DeleteField(massCoordXFLD); pointTable->DeleteField(massCoordYFLD); return (DBFault); } return (DBSuccess); }
static void _RGISGrpPanelSaveCBK (Widget widget,RGISGrpPanel *grpPanel,XmAnyCallbackStruct *callData) { DBInt rowID; DBDataset *dataset= UIDataset (); DBObjData *dbData = dataset->Data (); DBObjTable *itemTable = dbData->Table (DBrNItems); DBObjTable *groupTable = dbData->Table (DBrNGroups); DBObjTableField *group; DBObjRecord *itemRec, *groupRec; UITable *tableCLS; if (groupTable == (DBObjTable *) NULL) return; group = grpPanel->Current (); for (rowID = 0;rowID < groupTable->ItemNum ();++rowID) { groupRec = groupTable->Item (rowID); itemRec = itemTable->Item (rowID); group->Int (groupRec,(itemRec->Flags () & DBObjectFlagSelected) == DBObjectFlagSelected ? true : false); } if ((tableCLS = (UITable *) dbData->Display (UITableName (dbData,groupTable))) != (UITable *) NULL) tableCLS->Draw (); }
DBInt LoadPoints (FILE *file,DBObjTable *points,DBRegion *extent) { DBInt swap = DBByteOrder (DBByteOrderLITTLE), pointNum = 0;; DBObjTableField *coordField = points->Field (DBrNCoord); DBObjRecord *record; DBCoordinate coord; if (coordField == (DBObjTableField *) NULL) { CMmsgPrint (CMmsgAppError, "Corrupt Point Data Block in: %s %d",__FILE__,__LINE__); return (DBFault); } for (record = points->First ();record != (DBObjRecord *) NULL;record = (DBObjRecord *) points->Next ()) { if (Read (file,swap) == DBFault) return (DBFault); DBPause ((++pointNum * 100)/ points->ItemNum ()); coord.X = CoordX; coord.Y = CoordY; extent->Expand (coord); coordField->Coordinate (record,coord); } return (DBSuccess); }
DBObjTableField::DBObjTableField(DBObjTableField &field) : DBObject(field) { TypeVAR = field.TypeVAR; UnitTypeVAR = field.UnitTypeVAR; UnitVAR = field.UnitVAR; RequiredVAR = field.RequiredVAR; StartByteVAR = field.StartByteVAR; LengthVAR = field.LengthVAR; strcpy(FormatSTR, field.FormatSTR); Flags(field.Flags()); switch (TypeVAR) { case DBTableFieldInt: switch (LengthVAR) { case sizeof(DBByte): BytePROP = field.BytePROP; break; case sizeof(DBShort): ShortPROP = field.ShortPROP; break; default: IntPROP = field.IntPROP; break; } break; case DBTableFieldFloat: switch (LengthVAR) { case sizeof(DBFloat4): Float4PROP = field.Float4PROP; break; default: FloatPROP = field.FloatPROP; break; } break; case DBTableFieldDate: DatePROP = field.DatePROP; break; case DBTableFieldTableRec: case DBTableFieldDataRec: RecordPROP = field.RecordPROP; break; } }
void RGISAnalysePointInterStationTSCBK (Widget widget, RGISWorkspace *workspace,XmAnyCallbackStruct *callData) { char *selection; DBDataset *dataset = UIDataset (); DBObjMetaEntry *metaEntry; DBObjData *pntData = dataset->Data (), *tsData; DBObjTable *relateTBL = pntData->Table (DBrNRelations); DBObjRecord *relateRec; DBObjTableField *relDataFLD; DBObjTableField *relateFLD; DBObjTableField *joinFLD; static Widget selectWidget = (Widget) NULL; if (selectWidget == (Widget) NULL) selectWidget = UISelectionCreate ((char *) "Select Time Series"); if ((selection = UISelectObject (selectWidget,(DBObjectLIST<DBObject> *) relateTBL)) == (char *) NULL) return; if ((relateRec = relateTBL->Item (selection)) == (DBObjRecord *) NULL) { CMmsgPrint (CMmsgAppError, "Relate Record Error in: %s %d",__FILE__,__LINE__); return; } relDataFLD = relateTBL->Field (DBrNRelateData); relateFLD = relateTBL->Field (DBrNRelateField); joinFLD = relateTBL->Field (DBrNRelateJoinField); if ((tsData = dataset->Data (relDataFLD->String (relateRec))) == (DBObjData *) NULL) { if ((metaEntry = dataset->Meta (relDataFLD->String (relateRec))) == (DBObjMetaEntry *) NULL) { CMmsgPrint (CMmsgAppError, "Meta Enrty Finding Error in: %s %d",__FILE__,__LINE__); return; } tsData = new DBObjData (); if (tsData->Read (metaEntry->FileName ()) != DBSuccess) return; } workspace->CurrentData (tsData); UIPauseDialogOpen ((char *) "Calculating"); RGlibPointInterStationTS (pntData,tsData,relateFLD->String (relateRec),joinFLD->String (relateRec)); UIPauseDialogClose (); }
int DBObjData::BuildFields() { DBInt ret = DBSuccess; DBObjTable *table, *refTable; DBObjRecord *tableRec; DBObjTableField *field; DBObjectLIST<DBObjTableField> *tableFLDs; for (table = TablesPTR->First(); table != (DBObjTable *) NULL; table = TablesPTR->Next()) { tableFLDs = table->Fields(); for (field = tableFLDs->First(); field != (DBObjTableField *) NULL; field = tableFLDs->Next()) switch (field->Type()) { case DBTableFieldTableRec: if ((refTable = TablesPTR->Item(field->RecordProp())) == (DBObjTable *) NULL) { CMmsgPrint(CMmsgAppError, "Corrupt Dataset in: %s %d", __FILE__, __LINE__); ret = DBFault; continue; } for (tableRec = table->First(); tableRec != (DBObjRecord *) NULL; tableRec = table->Next()) if ((DBInt) (field->Record(tableRec) - (DBObjRecord *) NULL) != DBFault) field->Record(tableRec, refTable->Item((DBInt) ((char *) (field->Record(tableRec)) - (char *) NULL))); else field->Record(tableRec, (DBObjRecord *) NULL); break; case DBTableFieldDataRec: for (tableRec = table->First(); tableRec != (DBObjRecord *) NULL; tableRec = table->Next()) if ((DBInt) (field->Record(tableRec) - (DBObjRecord *) NULL) != DBFault) field->Record(tableRec, ArraysPTR->Item( (DBInt) ((char *) (field->Record(tableRec)) - (char *) NULL))); else field->Record(tableRec, (DBObjRecord *) NULL); break; } } return (ret); }
int DBObjTable::Read(FILE *file, int swap) { DBInt id; DBDate date; DBCoordinate coord; DBRegion region; DBPosition pos; DBUShort row, col; DBObjRecord *record; DBObjTableField *field; if (DBObjectLIST<DBObjRecord>::Read(file, swap) != DBSuccess) return (DBFault); if (FieldPTR->Read(file, swap) != DBSuccess) return (DBFault); for (id = 0; id < FieldPTR->ItemNum(); ++id) if (FieldPTR->ReadItem(file, id, swap) == DBFault) return (DBFault); RecordLengthVAR = 0; for (field = FieldPTR->First(); field != (DBObjTableField *) NULL; field = FieldPTR->Next()) RecordLengthVAR = RecordLengthVAR > field->StartByte() + field->Length() ? RecordLengthVAR : field->StartByte() + field->Length(); for (id = 0; id < ItemNum(); ++id) { if (ReadItem(file, id, swap) == DBFault) return (DBFault); record = Item(id); if (swap == false) continue; for (field = FieldPTR->First(); field != (DBObjTableField *) NULL; field = FieldPTR->Next()) switch (field->Type()) { case DBTableFieldInt: case DBTableFieldFloat: case DBTableFieldTableRec: case DBTableFieldDataRec: switch (field->Length()) { case 2: DBByteOrderSwapHalfWord((char *) record->Data() + field->StartByte()); break; case 4: DBByteOrderSwapWord((char *) record->Data() + field->StartByte()); break; case 8: DBByteOrderSwapLongWord((char *) record->Data() + field->StartByte()); break; } break; case DBTableFieldDate: date = field->Date(record); date.Swap(); field->Date(record, date); break; case DBTableFieldCoord: coord = field->Coordinate(record); coord.Swap(); field->Coordinate(record, coord); break; case DBTableFieldRegion: region = field->Region(record); region.Swap(); field->Region(record, region); break; case DBTableFieldPosition: pos = field->Position(record); switch (field->Length()) { case sizeof(DBPosition): pos.Swap(); break; default: row = pos.Row; col = pos.Col; DBByteOrderSwapHalfWord(&row); DBByteOrderSwapHalfWord(&col); pos.Row = row; pos.Col = col; break; } field->Position(record, pos); break; default: break; } } if (MethodPTR->Read(file, swap) != DBSuccess) return (DBFault); for (id = 0; id < MethodPTR->ItemNum(); ++id) if (MethodPTR->ReadItem(file, id, swap) == DBFault) return (DBFault); return (DBSuccess); }
void RGISAnalyseLineSSampleGridCBK (Widget widget, RGISWorkspace *workspace,XmAnyCallbackStruct *callData) { char *fText; int allowOk; static int sample; DBDataset *dataset = UIDataset (); DBObjData *dbData = dataset->Data (), *grdData = dbData->LinkedData (); DBObjTable *itemTable = dbData->Table (DBrNItems); static Widget dShell = (Widget) NULL, mainForm; static Widget fromNameTextF, toNameTextF; XmString string; widget = widget; workspace = workspace; callData = callData; _RGISAnLineSampleGridFields = itemTable->Fields (); if (dShell == (Widget) NULL) { Widget button; dShell = UIDialogForm ((char *) "Single Layer Grid Sampling",false); mainForm = UIDialogFormGetMainForm (dShell); string = XmStringCreate ((char *) "Select",UICharSetBold); button = XtVaCreateManagedWidget ("RGISAnalyseLineSSampleNameButton",xmPushButtonWidgetClass,mainForm, XmNtopAttachment, XmATTACH_FORM, XmNtopOffset, 10, XmNrightAttachment, XmATTACH_FORM, XmNrightOffset, 10, XmNmarginHeight, 5, XmNtraversalOn, False, XmNlabelString, string, XmNuserData, grdData->Type () == DBTypeGridContinuous ? DBTableFieldIsNumeric : DBTableFieldIsCategory, NULL); XmStringFree (string); fromNameTextF = XtVaCreateManagedWidget ("RGISAnalyseLineSSampleNameTextF",xmTextFieldWidgetClass,mainForm, XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET, XmNtopWidget, button, XmNrightAttachment, XmATTACH_WIDGET, XmNrightWidget, button, XmNrightOffset, 10, XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET, XmNbottomWidget, button, XmNmaxLength, DBStringLength, XmNcolumns, DBStringLength / 2, NULL); XtAddCallback (button,XmNactivateCallback,(XtCallbackProc) _RGIAnalyseLineSSampleGridSSelectCBK,fromNameTextF); string = XmStringCreate ((char *) "From Field:",UICharSetBold); XtVaCreateManagedWidget ("RGISAnalyseLineSSampleNameLabel",xmLabelWidgetClass,mainForm, XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET, XmNtopWidget, button, XmNleftAttachment, XmATTACH_FORM, XmNleftOffset, 10, XmNrightAttachment, XmATTACH_WIDGET, XmNrightWidget, fromNameTextF, XmNrightOffset, 10, XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET, XmNbottomWidget, button, XmNlabelString, string, NULL); XmStringFree (string); string = XmStringCreate ((char *) "Select",UICharSetBold); button = XtVaCreateManagedWidget ("RGISAnalyseLineSSampleNameButton",xmPushButtonWidgetClass,mainForm, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget, button, XmNtopOffset, 10, XmNrightAttachment, XmATTACH_FORM, XmNrightOffset, 10, XmNbottomAttachment, XmATTACH_FORM, XmNbottomOffset, 10, XmNmarginHeight, 5, XmNtraversalOn, False, XmNlabelString, string, XmNuserData, grdData->Type () == DBTypeGridContinuous ? DBTableFieldIsNumeric : DBTableFieldIsCategory, NULL); XmStringFree (string); toNameTextF = XtVaCreateManagedWidget ("RGISAnalyseLineSSampleNameTextF",xmTextFieldWidgetClass,mainForm, XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET, XmNtopWidget, button, XmNrightAttachment, XmATTACH_WIDGET, XmNrightWidget, button, XmNrightOffset, 10, XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET, XmNbottomWidget, button, XmNmaxLength, DBStringLength, XmNcolumns, DBStringLength / 2, NULL); XtAddCallback (button,XmNactivateCallback,(XtCallbackProc) _RGIAnalyseLineSSampleGridSSelectCBK,toNameTextF); string = XmStringCreate ((char *) "To Field:",UICharSetBold); XtVaCreateManagedWidget ("RGISAnalyseLineSSampleNameLabel",xmLabelWidgetClass,mainForm, XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET, XmNtopWidget, button, XmNleftAttachment, XmATTACH_FORM, XmNleftOffset, 10, XmNrightAttachment, XmATTACH_WIDGET, XmNrightWidget, toNameTextF, XmNrightOffset, 10, XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET, XmNbottomWidget, button, XmNlabelString, string, NULL); XmStringFree (string); XtAddCallback (UIDialogFormGetOkButton (dShell),XmNactivateCallback,(XtCallbackProc) UIAuxSetBooleanTrueCBK,&sample); } sample = false; UIDialogFormPopup (dShell); while (UILoop ()) { allowOk = false; fText = XmTextFieldGetString (fromNameTextF); if (strlen (fText) > 0) allowOk = true; XtFree (fText); fText = XmTextFieldGetString (toNameTextF); if (strlen (fText) > 0) allowOk = true; XtFree (fText); XtSetSensitive (UIDialogFormGetOkButton (dShell),allowOk); } UIDialogFormPopdown (dShell); if (sample) { DBInt ret; DBFloat value; DBCoordinate coord; DBGridIF *gridIF = new DBGridIF (grdData); DBVLineIF *lineIF = new DBVLineIF (dbData); DBObjTableField *fromField; DBObjTableField *toField; DBObjRecord *record; fText = XmTextFieldGetString (fromNameTextF); if (strlen (fText) > 0) { if ((fromField = itemTable->Field (fText)) == (DBObjTableField *) NULL) itemTable->AddField (fromField = new DBObjTableField (fText,DBTableFieldFloat,"%10.3f",sizeof (DBFloat4))); } else fromField = (DBObjTableField *) NULL; XtFree (fText); fText = XmTextFieldGetString (toNameTextF); if (strlen (fText) > 0) { if ((toField = itemTable->Field (fText)) == (DBObjTableField *) NULL) itemTable->AddField (toField = new DBObjTableField (fText,DBTableFieldFloat,"%10.3f",sizeof (DBFloat4))); } else toField = (DBObjTableField *) NULL; XtFree (fText); UIPauseDialogOpen ((char *) "Sampling Grid"); for (record = itemTable->First ();record != (DBObjRecord *) NULL;record = itemTable->Next ()) { if (UIPause (record->RowID () * 100 / itemTable->ItemNum ())) goto Stop; if (fromField != (DBObjTableField *) NULL) { coord = lineIF->FromCoord (record); ret = gridIF->Value (coord,&value); if (fromField->Type () == DBTableFieldFloat) { if (ret) fromField->Float (record,value); else fromField->Float (record,fromField->FloatNoData ()); } else { if (ret) fromField->Int (record,(DBInt) value); else fromField->Int (record,fromField->IntNoData ()); } } if (toField != (DBObjTableField *) NULL) { coord = lineIF->ToCoord (record); ret = gridIF->Value (coord,&value); if (toField->Type () == DBTableFieldFloat) { if (ret) toField->Float (record,value); else toField->Float (record,toField->FloatNoData ()); } else { if (ret) toField->Int (record,(DBInt) value); else toField->Int (record,toField->IntNoData ()); } } } Stop: UIPauseDialogClose (); delete lineIF; delete gridIF; } }
void RGISAnalyseLineMSampleGridCBK (Widget widget, RGISWorkspace *workspace,XmAnyCallbackStruct *callData) { DBInt layerID, layerNum; DBCoordinate coord; DBFloat realValue; DBDataset *dataset = UIDataset (); DBObjData *dbData = dataset->Data (); DBObjData *grdData = dbData->LinkedData (); DBObjData *tblData; DBObjTable *table, *itemTable = dbData->Table (DBrNItems); DBObjTableField *lineIDFLD; DBObjTableField *layerIDFLD; DBObjTableField *layerNameFLD; DBObjTableField *fromValueFLD = (DBObjTableField *) NULL; DBObjTableField *toValueFLD = (DBObjTableField *) NULL; DBVLineIF *lineIF = (DBVLineIF *) NULL; DBGridIF *gridIF; DBObjRecord *record, *layerRec, *tblRec; DBObjectLIST<DBObjTableField> *fields; widget = widget; callData = callData; gridIF = new DBGridIF (grdData); for (layerID = 0;layerID < gridIF->LayerNum ();++layerID) { layerRec = gridIF->Layer (layerID); if ((layerRec->Flags () & DBObjectFlagIdle) != DBObjectFlagIdle) ++layerNum; } if (layerNum < 1) { CMmsgPrint (CMmsgAppError, "No Layer to Process in: %s %d",__FILE__,__LINE__); delete gridIF; return; } tblData = new DBObjData ("",DBTypeTable); tblData->Document (DBDocGeoDomain,dbData->Document (DBDocGeoDomain)); tblData->Document (DBDocSubject,grdData->Document (DBDocSubject)); if (UIDataHeaderForm (tblData) == false) { delete gridIF; delete tblData; return; } table = tblData->Table (DBrNItems); lineIF = new DBVLineIF (dbData); table->AddField (lineIDFLD = new DBObjTableField ("GHAASPointID",DBTableFieldInt, "%8d",sizeof (DBInt))); table->AddField (layerIDFLD = new DBObjTableField ("LayerID", DBTableFieldInt, "%4d",sizeof (DBShort))); table->AddField (layerNameFLD = new DBObjTableField ("LayerName", DBTableFieldString,"%s",DBStringLength)); table->AddField (fromValueFLD = new DBObjTableField (RGISLineFromNodeValue,DBTableFieldFloat,gridIF->ValueFormat (),sizeof (DBFloat4))); table->AddField (toValueFLD = new DBObjTableField (RGISLineToNodeValue,DBTableFieldFloat,gridIF->ValueFormat (),sizeof (DBFloat4))); grdData->Flags (DBObjectFlagProcessed,DBSet); UIPauseDialogOpen ((char *) "Sampling Grid(s)"); for (layerID = 0;layerID < gridIF->LayerNum ();++layerID) { layerRec = gridIF->Layer (layerID); if ((layerRec->Flags () & DBObjectFlagIdle) == DBObjectFlagIdle) continue; for (record = itemTable->First ();record != (DBObjRecord *) NULL;record = itemTable->Next ()) { if (UIPause ((layerRec->RowID () * itemTable->ItemNum () + record->RowID ()) * 100 / (itemTable->ItemNum () * gridIF->LayerNum ()))) goto Stop; if ((record->Flags () & DBObjectFlagIdle) == DBObjectFlagIdle) continue; tblRec = table->Add (record->Name ()); lineIDFLD->Int (tblRec,record->RowID () + 1); layerIDFLD->Int (tblRec,layerRec->RowID ()); layerNameFLD->String (tblRec,layerRec->Name ()); coord = lineIF->FromCoord (record); if (gridIF->Value (layerRec,coord,&realValue)) fromValueFLD->Float (tblRec,realValue); coord = lineIF->ToCoord (record); if (gridIF->Value (layerRec,coord,&realValue)) toValueFLD->Float (tblRec,realValue); } } Stop: UIPauseDialogClose (); delete gridIF; delete lineIF; fields = new DBObjectLIST<DBObjTableField> ("Field List"); fields->Add (new DBObjTableField (*lineIDFLD)); fields->Add (new DBObjTableField (*layerIDFLD)); table->ListSort (fields); workspace->CurrentData (tblData); delete fields; }
int main (int argc,char *argv []) { int argPos, argNum = argc, ret, verbose = false; DBInt recID; bool padding = false; char *tableName = (char *) NULL; char *fieldName = (char *) NULL; char *yearFieldName = (char *) NULL; char *monthFieldName = (char *) NULL; char *dayFieldName = (char *) NULL; char *hourFieldName = (char *) NULL; char *minFieldName = (char *) NULL; char *tmp = (char *) NULL; DBObjData *data; DBObjTable *table; DBObjTableField *srcField; DBObjTableField *yearField = (DBObjTableField *) NULL; DBObjTableField *monthField= (DBObjTableField *) NULL; DBObjTableField *dayField = (DBObjTableField *) NULL; DBObjTableField *hourField = (DBObjTableField *) NULL; DBObjTableField *minField = (DBObjTableField *) NULL; DBInt dbInputType = DBTableFieldInt; DBInt dbInputSize = sizeof(DBShort); DBDate date; DBObjRecord *record; 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","--field")) { if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) { CMmsgPrint (CMmsgUsrError,"Missing field name!"); return (CMfailed); } fieldName = argv [argPos]; if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break; continue; } if (CMargTest (argv [argPos],"-y","--year")) { if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) { CMmsgPrint (CMmsgUsrError,"Missing year field name!"); return (CMfailed); } yearFieldName = argv [argPos]; if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break; continue; } if (CMargTest (argv [argPos],"-m","--month")) { if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) { CMmsgPrint (CMmsgUsrError,"Missing month field name!"); return (CMfailed); } monthFieldName = argv [argPos]; if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break; continue; } if (CMargTest (argv [argPos],"-d","--day")) { if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) { CMmsgPrint (CMmsgUsrError,"Missing day field name!"); return (CMfailed); } dayFieldName = argv [argPos]; if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break; continue; } if (CMargTest (argv [argPos],"-o","--hour")) { if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) { CMmsgPrint (CMmsgUsrError,"Missing hour field name!"); return (CMfailed); } hourFieldName = argv [argPos]; if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break; continue; } if (CMargTest (argv [argPos],"-i","--minute")) { if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) { CMmsgPrint (CMmsgUsrError,"Missing minute field name!"); return (CMfailed); } minFieldName = argv [argPos]; if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break; continue; } if (CMargTest (argv [argPos],"-p","--padding")) { padding = true; dbInputType = DBTableFieldString; dbInputSize = sizeof(DBByte) * 3; 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 [table name]"); CMmsgPrint (CMmsgInfo," -f,--field [field name]"); CMmsgPrint (CMmsgInfo," -y,--year [year field]"); CMmsgPrint (CMmsgInfo," -m,--month [month field]"); CMmsgPrint (CMmsgInfo," -d,--day [day field]"); CMmsgPrint (CMmsgInfo," -o,--hour [hour field]"); CMmsgPrint (CMmsgInfo," -i,--minute [minute field]"); CMmsgPrint (CMmsgInfo," -p,--padding"); CMmsgPrint (CMmsgInfo," -V,--verbose"); CMmsgPrint (CMmsgInfo," -h,--help"); return (DBSuccess); } if ((argv [argPos][0] == '-') && ((int) 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]); data = new DBObjData (); if (((argNum > 1) && (strcmp (argv [1],"-") != 0) ? data->Read (argv [1]) : data->Read (stdin)) == DBFault) { delete data; return (CMfailed); } if (tableName == (char *) NULL) tableName = DBrNItems; if ((table = data->Table (tableName)) == (DBObjTable *) NULL) { CMmsgPrint (CMmsgUsrError,"Invalid table!"); delete data; return (CMfailed); } if (fieldName == (char *) NULL) fieldName = (char *) "Date"; if ((srcField = table->Field (fieldName)) == (DBObjTableField *) NULL) { CMmsgPrint (CMmsgUsrError,"Missing date field!"); delete data; return (CMfailed); } if ((srcField->Type () != DBTableFieldString) && (srcField->Type () != DBTableFieldDate)) { CMmsgPrint (CMmsgUsrError,"Invalid date field!"); delete data; return (CMfailed); } if (yearFieldName != (char *) NULL) { if ((yearField = table->Field (yearFieldName)) == (DBObjTableField *) NULL) { yearField = new DBObjTableField (yearFieldName,DBTableFieldInt,"%4d",sizeof(DBShort),false); table->AddField (yearField); } } if (monthFieldName != (char *) NULL) { if ((monthField = table->Field (monthFieldName)) == (DBObjTableField *) NULL) { monthField = new DBObjTableField (monthFieldName,dbInputType,"%2d",dbInputSize,false); table->AddField (monthField); } } if (dayFieldName != (char *) NULL) { if (monthField == (DBObjTableField *) NULL) { CMmsgPrint (CMmsgUsrError,"Month field is not set!"); delete data; return (CMfailed); } if ((dayField = table->Field (dayFieldName)) == (DBObjTableField *) NULL) { dayField = new DBObjTableField (dayFieldName,dbInputType,"%2d",dbInputSize,false); table->AddField (dayField); } } if (hourFieldName != (char *) NULL) { if (dayField == (DBObjTableField *) NULL) { CMmsgPrint (CMmsgUsrError,"Day field is not set!"); delete data; return (CMfailed); } if ((hourField = table->Field (hourFieldName)) == (DBObjTableField *) NULL) { hourField = new DBObjTableField (hourFieldName,dbInputType,"%2d",dbInputSize,false); table->AddField (hourField); } } if (minFieldName != (char *) NULL) { if (hourField == (DBObjTableField *) NULL) { CMmsgPrint (CMmsgUsrError,"Hour field is not set!"); delete data; return (CMfailed); } if ((minField = table->Field (minFieldName)) == (DBObjTableField *) NULL) { minField = new DBObjTableField (minFieldName,dbInputType,"%2d",dbInputSize,false); table->AddField (minField); } } for (recID = 0;recID < table->ItemNum ();++recID) { record = table->Item (recID); if (srcField->Type () == DBTableFieldString) date.Set (srcField->String (record)); else date = srcField->Date (record); if (yearField != (DBObjTableField *) NULL) yearField->Int(record,date.Year ()); if(padding) { if (monthField != (DBObjTableField *) NULL) { if (date.Month() != DBDefaultMissingIntVal) monthField->String (record,tmp = _CMDpadit(date.Month() + 1,false)); else monthField->String (record,tmp = _CMDpadit(date.Month(),false)); free(tmp); } if (dayField != (DBObjTableField *) NULL) { dayField->String (record,tmp = _CMDpadit(date.Day(),false)); free(tmp); } if (hourField != (DBObjTableField *) NULL) { hourField->String (record,tmp = _CMDpadit(date.Hour(),false)); free(tmp); } if (minField != (DBObjTableField *) NULL) { minField->String (record,tmp = _CMDpadit(date.Minute(),false)); free(tmp); } } else { if (monthField != (DBObjTableField *) NULL) { if (date.Month() != DBDefaultMissingIntVal) monthField->Int(record,date.Month () + 1); else monthField->Int (record,DBDefaultMissingIntVal); } if (dayField != (DBObjTableField *) NULL) dayField->Int (record,date.Day ()); if (hourField != (DBObjTableField *) NULL) hourField->Int(record,date.Hour ()); if (minField != (DBObjTableField *) NULL) minField->Int (record,date.Minute ()); } } ret = (argNum > 2) && (strcmp (argv [2],"-") != 0) ? data->Write (argv [2]) : data->Write (stdout); delete data; if (verbose) RGlibPauseClose (); return (ret); }
void RGISAnNetworkStreamLinesCBK (Widget widget,RGISWorkspace *workspace,XmAnyCallbackStruct *callData) { char *selection; DBDataset *dataset = UIDataset (); DBObjData *netData = dataset->Data (); DBObjTable *cellTable = netData->Table (DBrNCells); DBObjData *arcData = new DBObjData ("",DBTypeVectorLine); DBNetworkIF *netIF = new DBNetworkIF (netData); static Widget fieldSelect = (Widget) NULL; widget = widget; callData = callData; if (fieldSelect == (Widget) NULL) fieldSelect = UISelectionCreate ((char *) "Select Field"); if ((selection = UISelectObject (fieldSelect,(DBObjectLIST<DBObject> *) cellTable->Fields (),DBTableFieldIsInteger)) == (char *) NULL) return; if ((_RGISAnNetOrderField = cellTable->Field (selection)) == (DBObjTableField *) NULL) { CMmsgPrint (CMmsgAppError, "Field Selection Error in: %s %d",__FILE__,__LINE__); return; } arcData->Document (DBDocGeoDomain,netData->Document (DBDocGeoDomain)); arcData->Document (DBDocSubject,"Stream Lines"); if (UIDataHeaderForm (arcData)) { DBInt cellID; char objName [DBStringLength]; DBVLineIF *lineIF = new DBVLineIF (arcData); DBObjTable *cellTable = netData->Table (DBrNCells); DBObjTable *lineTable = arcData->Table (DBrNItems); DBObjTableField *basinFLD = new DBObjTableField (DBrNBasin,DBTableFieldInt,"%8d",sizeof (DBInt)); DBObjTableField *fieldFLD = new DBObjTableField (_RGISAnNetOrderField->Name (), _RGISAnNetOrderField->Type (), _RGISAnNetOrderField->Format (), _RGISAnNetOrderField->Length ()); DBObjTableField *lengthFLD = new DBObjTableField (RGISNetStreamLength,DBTableFieldFloat,"%10.1f",sizeof (DBFloat4)); DBObjTableField *areaFLD = new DBObjTableField (RGISNetStreamArea,DBTableFieldFloat,"%10.1f",sizeof (DBFloat4)); DBObjTableField *basinAreaFLD = new DBObjTableField (RGISNetBasinArea,DBTableFieldFloat,"%10.1f",sizeof (DBFloat4)); DBObjTableField *nextFLD = new DBObjTableField (RGISNetStreamNext,DBTableFieldInt,"%6d",sizeof (DBInt)); DBObjRecord *cellRec, *toCellRec, *lineRec; arcData->Projection (netData->Projection ()); arcData->Precision (netData->Precision ()); arcData->MaxScale (netData->MaxScale ()); arcData->MinScale (netData->MinScale ()); lineTable->AddField (basinFLD); lineTable->AddField (fieldFLD); lineTable->AddField (lengthFLD); lineTable->AddField (areaFLD); lineTable->AddField (basinAreaFLD); lineTable->AddField (nextFLD); cellTable->AddField (_RGISAnNetStreamIDFLD = new DBObjTableField ("StreamID",DBTableFieldInt,"%8d",sizeof (DBInt))); _RGISAnNetStreamID = 0; UIPauseDialogOpen ((char *) "Creating Stream Lines"); cellID = netIF->CellNum () - 1; cellRec = netIF->Cell (cellID); if (lineIF->NewSymbol ("Default Symbol") == (DBObjRecord *) NULL) { CMmsgPrint (CMmsgAppError, "Symbol Creation Error in: %s %d",__FILE__,__LINE__); return; } for (;cellID >= 0;--cellID) { cellRec = netIF->Cell (cellID); if (((toCellRec = netIF->ToCell (cellRec)) == (DBObjRecord *) NULL) || (_RGISAnNetOrderField->Int (cellRec) != _RGISAnNetOrderField->Int (toCellRec)) || (netIF->CellOrder (cellRec) != netIF->CellOrder (toCellRec))) { if (UIPause ((netIF->CellNum () - cellRec->RowID ()) * 100 / netIF->CellNum ())) goto Stop; sprintf (objName,"Line: %5d",_RGISAnNetStreamID + 1); if ((lineRec = lineIF->NewItem (objName)) == (DBObjRecord *) NULL) { CMmsgPrint (CMmsgAppError, "Line Insertion Error in: %s %d",__FILE__,__LINE__); return; } nextFLD->Int (lineRec,toCellRec == (DBObjRecord *) NULL ? 0 : _RGISAnNetStreamIDFLD->Int (toCellRec) + 1); basinFLD->Int (lineRec,netIF->CellBasinID (cellRec)); fieldFLD->Int (lineRec,_RGISAnNetOrderField->Int (cellRec)); _RGISAnNetVertex = 0; netIF->UpStreamSearch (_RGISAnNetworkCellRec = cellRec,(DBNetworkACTION) _RGISAnNetworkUpStreamAction); lineIF->FromNode (lineRec,lineIF->Node (netIF->Center (_RGISAnNetworkCellRec),true)); lineIF->ToNode (lineRec,lineIF->Node (netIF->Center (cellRec) + netIF->Delta (cellRec),true)); _RGISAnNetArea = netIF->CellArea (_RGISAnNetworkCellRec); if (_RGISAnNetVertex > 1) { if (_RGISAnNetVertexNum < _RGISAnNetVertex - 1) { _RGISAnNetCoord = (DBCoordinate *) realloc (_RGISAnNetCoord,(_RGISAnNetVertex - 1) * sizeof (DBCoordinate)); if (_RGISAnNetCoord == (DBCoordinate *) NULL) { CMmsgPrint (CMmsgSysError, "Memory Allocation Error in: %s %d",__FILE__,__LINE__); return; } } _RGISAnNetVertex = 0; netIF->DownStreamSearch (netIF->ToCell (_RGISAnNetworkCellRec),(DBNetworkACTION) _RGISAnNetworkDownStreamAction); } else _RGISAnNetVertex = 0; lineIF->Vertexes (lineRec,_RGISAnNetCoord,_RGISAnNetVertex); lineIF->ItemSymbol (lineRec,lineIF->Symbol (0)); lengthFLD->Float (lineRec,netIF->CellBasinLength (cellRec)); areaFLD->Float (lineRec,_RGISAnNetArea); basinAreaFLD->Float (lineRec,netIF->CellBasinArea (cellRec)); _RGISAnNetStreamID += 1; } } Stop: UIPauseDialogClose (); if (_RGISAnNetCoord != (DBCoordinate *) NULL) free (_RGISAnNetCoord); delete lineIF; if (cellID >= 0) delete arcData; else workspace->CurrentData (arcData); } else delete arcData; delete netIF; }
DBInt DBPointToGrid(DBObjData *pntData, DBObjData *netData, DBObjData *grdData) { DBInt i; DBPosition pos; DBObjTable *pntTable = pntData->Table(DBrNItems); DBObjTable *grdTable = grdData->Table(DBrNItems); DBObjTable *symTable = grdData->Table(DBrNSymbols); DBObjectLIST<DBObjTableField> *pntFields = pntTable->Fields(); DBObjTableField *pntFLD; DBObjTableField *grdAttribFLD; DBObjTableField *grdFLD = grdTable->Field(DBrNGridValue); DBObjTableField *symFLD = grdTable->Field(DBrNSymbol); DBObjRecord *cellRec, *toCell, *pntRec, *itemRec; DBObjRecord *symRec = symTable->First(); DBVPointIF *pntIF; DBNetworkIF *netIF; DBGridIF *grdIF; pntIF = new DBVPointIF(pntData); netIF = new DBNetworkIF(netData); grdIF = new DBGridIF(grdData); grdIF->RenameLayer(grdIF->Layer((DBInt) 0), (char *) "Subbasins"); for (pos.Row = 0; pos.Row < grdIF->RowNum(); ++pos.Row) for (pos.Col = 0; pos.Col < grdIF->ColNum(); ++pos.Col) grdIF->Value(pos, DBFault); for (pntFLD = pntFields->First(); pntFLD != (DBObjTableField *) NULL; pntFLD = pntFields->Next()) if (DBTableFieldIsVisible(pntFLD)) grdTable->AddField(new DBObjTableField(*pntFLD)); for (i = 0; i < pntIF->ItemNum(); ++i) { DBPause(i * 100 / pntIF->ItemNum()); pntRec = pntIF->Item(i); if ((pntRec->Flags() & DBObjectFlagIdle) == DBObjectFlagIdle) continue; if ((cellRec = netIF->Cell(pntIF->Coordinate(pntRec))) == (DBObjRecord *) NULL) continue; itemRec = grdTable->Add(pntRec->Name()); grdFLD->Int(itemRec, pntRec->RowID() + 1); symFLD->Record(itemRec, symRec); for (pntFLD = pntFields->First(); pntFLD != (DBObjTableField *) NULL; pntFLD = pntFields->Next()) if ((grdAttribFLD = grdTable->Field(pntFLD->Name())) != (DBObjTableField *) NULL) switch (pntFLD->Type()) { case DBTableFieldString: grdAttribFLD->String(itemRec, pntFLD->String(pntRec)); break; case DBTableFieldInt: grdAttribFLD->Int(itemRec, pntFLD->Int(pntRec)); break; case DBTableFieldFloat: grdAttribFLD->Float(itemRec, pntFLD->Float(pntRec)); break; case DBTableFieldDate: grdAttribFLD->Date(itemRec, pntFLD->Date(pntRec)); break; } grdIF->Value(netIF->CellPosition(cellRec), itemRec->RowID()); } for (i = 0; i < netIF->CellNum(); ++i) { if ((cellRec = netIF->Cell(i)) == (DBObjRecord *) NULL) continue; if ((itemRec = grdIF->GridItem(netIF->CellPosition(cellRec))) != (DBObjRecord *) NULL) continue; if ((toCell = netIF->ToCell(cellRec)) == (DBObjRecord *) NULL) continue; if ((itemRec = grdIF->GridItem(netIF->CellPosition(toCell))) != (DBObjRecord *) NULL) grdIF->Value(netIF->CellPosition(cellRec), itemRec->RowID()); } grdIF->DiscreteStats(); delete pntIF; delete netIF; delete grdIF; return (DBSuccess); }