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 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); }
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 (); }
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); }
UIAttribView::UIAttribView (DBObjData *data) : DBObject (data->Name (),sizeof (UIAttribView)) { DBObjTableField *field; DBObjectLIST<DBObjTableField> *fields; Widget mainForm, scrolledW, rowCol, label; XmString string; Atom deleteWindowAtom = XmInternAtom(XtDisplay(UITopLevel ()),(char *) "WM_DELETE_WINDOW",FALSE); DataPTR = data; ItemTable = DataPTR->Table (DBrNItems); Name (UIAttribViewSTR); DShellWGT = XtVaCreatePopupShell ("UIAttribView",xmDialogShellWidgetClass,UITopLevel (), XmNkeyboardFocusPolicy, XmPOINTER, XmNtitle, data->Name (), XmNtransient, False, XmNminWidth, 400, XmNminHeight, 300, NULL); XmAddWMProtocolCallback (DShellWGT,deleteWindowAtom,(XtCallbackProc) _UIAttribViewDeleteCBK,(XtPointer) this); mainForm = XtVaCreateWidget ("UIAttribViewForm",xmFormWidgetClass,DShellWGT, XmNshadowThickness, 0, NULL); string = XmStringCreate ((char *) "Item:",UICharSetBold); label = XtVaCreateManagedWidget ("UIAttribViewNameLabel",xmLabelWidgetClass,mainForm, XmNtopAttachment, XmATTACH_FORM, XmNtopOffset, 5, XmNleftAttachment, XmATTACH_FORM, XmNleftOffset, 10, XmNlabelString, string, XmNrecomputeSize, False, NULL); XmStringFree (string); string = XmStringCreate ((char *) "",UICharSetNormal); ItemNameWGT = XtVaCreateManagedWidget ("UIAttribViewNameText",xmLabelWidgetClass,mainForm, XmNtopAttachment, XmATTACH_FORM, XmNtopOffset, 5, XmNleftAttachment, XmATTACH_WIDGET, XmNleftWidget, label, XmNleftOffset, 5, XmNlabelString, string, NULL); XmStringFree (string); scrolledW = XtVaCreateManagedWidget ("UIAttribViewScrolledW",xmScrolledWindowWidgetClass,mainForm, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget, label, XmNtopOffset, 5, XmNleftAttachment, XmATTACH_FORM, XmNleftOffset, 5, XmNrightAttachment, XmATTACH_FORM, XmNrightOffset, 5, XmNbottomAttachment, XmATTACH_FORM, XmNbottomOffset, 5, XmNheight, 150, XmNvisualPolicy, XmCONSTANT, XmNscrollingPolicy, XmAUTOMATIC, NULL); rowCol = XtVaCreateManagedWidget ("UIAttribViewRowColumn",xmRowColumnWidgetClass,scrolledW, XmNnumColumns, 2, XmNorientation, XmHORIZONTAL, XmNrowColumnType, XmWORK_AREA, NULL); NamesRowCol = XtVaCreateManagedWidget ("UIAttribViewNamesRowColumn",xmRowColumnWidgetClass,rowCol, XmNorientation, XmVERTICAL, XmNrowColumnType, XmWORK_AREA, XmNpacking, XmPACK_COLUMN, XmNspacing, 0, NULL); FieldsRowCol = XtVaCreateManagedWidget ("UIAttribViewNamesRowColumn",xmRowColumnWidgetClass,rowCol, XmNorientation, XmVERTICAL, XmNrowColumnType, XmWORK_AREA, XmNspacing, 0, NULL); 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) NewField (field->Name (),field->Format ()); break; case DBTypeGridContinuous: { DBObjRecord *record; DBGridIF *gridIF = new DBGridIF (DataPTR); ItemTable = DataPTR->Table (DBrNLayers); for (record = ItemTable->First ();record != (DBObjRecord *) NULL;record = ItemTable->Next ()) NewField (record->Name (),gridIF->ValueFormat ()); delete gridIF; } break; case DBTypeNetwork: { DBObjTable *cellTable = DataPTR->Table (DBrNCells); NewField ((char *) "Basin Name",(char *) "%s"); fields = ItemTable->Fields (); for (field = fields->First ();field != (DBObjTableField *) NULL;field = fields->Next ()) if (DBTableFieldIsVisible (field) == true) NewField (field->Name (),field->Format ()); fields = cellTable->Fields (); for (field = fields->First ();field != (DBObjTableField *) NULL;field = fields->Next ()) if (DBTableFieldIsVisible (field) == true) NewField (field->Name (),field->Format ()); } break; default: break; } XtManageChild (mainForm); UILoop (); }