void DBGridIF::RenameLayer(DBObjRecord *layerRec, char *name) { DBObjRecord *dataRec; layerRec = LayerTable->Item(layerRec->RowID()); layerRec->Name(name); dataRec = LayerFLD->Record(layerRec); dataRec->Name(name); if (DataPTR->Type() == DBTypeGridContinuous) { DBObjRecord *itemRec = ItemTable->Item(layerRec->RowID()); itemRec->Name(name); } }
void Update () { ForegroundFLD->Int (OrigREC,Foreground ()); BackgroundFLD->Int (OrigREC,Background ()); StyleFLD->Int (OrigREC,Style ()); OrigREC->Name (Name ()); }
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 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); }
char *DBObjTableField::String(const DBObjRecord *record) const { static char retString[DBStringLength]; if (record == (DBObjRecord *) NULL) return ((char *) NULL); switch (Type()) { case DBTableFieldString: return ((char *) record->Data() + StartByte()); case DBTableFieldInt: { DBInt ret = Int(record); if (ret == IntNoData()) return ((char *) ""); sprintf(retString, Format(), ret); return (retString); } case DBTableFieldFloat: { DBFloat ret = Float(record); if (CMmathEqualValues(ret, FloatNoData())) return ((char *) ""); sprintf(retString, Format(), ret); return (retString); } case DBTableFieldDate: { DBDate date = Date(record); strncpy(retString, date.Get(), sizeof(retString)); } return (retString); case DBTableFieldTableRec: case DBTableFieldDataRec: { DBObjRecord *refRecord = Record(record); return (refRecord->Name()); } default: return (NULL); } }
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); }
char *CurrentLayer(DBInt layerID) { if (layerID == DBFault) LayerRec = GridIF->Layer(0); else LayerRec = layerID < GridIF->LayerNum() ? GridIF->Layer(layerID) : GridIF->Layer(layerID % GridIF->LayerNum()); return (LayerRec->Name()); }
DBInt DBGridIF::DeleteLayers(char *firstLayer, char *lastLayer) { DBInt layerID; DBObjRecord *layerRec; if ((layerRec = LayerTable->Item(firstLayer)) == (DBObjRecord *) NULL) { CMmsgPrint(CMmsgAppError, "Invalid layer name in: %s %d", __FILE__, __LINE__); return (DBFault); } layerID = layerRec->RowID(); while (strcmp(layerRec->Name(), lastLayer) != 0) { DeleteLayer(layerRec->Name()); if ((layerRec = LayerTable->Item(layerID)) == (DBObjRecord *) NULL) break; } return (DBSuccess); }
DBInt LayerIsDated(DBInt layerID) { DBObjRecord *layerRec; DBDate date; layerRec = GridIF->Layer(layerID); date.Set(layerRec->Name()); if (date.Year() != DBDefaultMissingIntVal) return (true); return (date.Month() != DBDefaultMissingIntVal ? true : false); }
Widget RGISGrdPanel::Load (DBObjData *data) { int itemPosition = 0; DBObjTable *layerTable = data->Table (DBrNLayers); DBObjRecord *record; XmString string; XmListDeleteAllItems (LayerListWGT); for (record = layerTable->First ();record != (DBObjRecord *) NULL;record = layerTable->Next ()) { string = XmStringCreate (record->Name (),UICharSetNormal); XmListAddItem (LayerListWGT, string, ++itemPosition); XmStringFree (string); } XmListDeselectAllItems (LayerListWGT); record = layerTable->Item (); string = XmStringCreate (record->Name (),UICharSetNormal); XmListSelectItem (LayerListWGT,string,False); XmStringFree (string); XtVaSetValues (LayerListWGT,XmNuserData, data, NULL); return (Form ()); }
DBInt FindLayer(char *layerName) { DBInt layerID, i = 0; DBObjRecord *layerRec; char *name; for (layerID = 0; layerID < GridIF->LayerNum(); ++layerID) { layerRec = GridIF->Layer(layerID); name = layerRec->Name(); if (strncmp(name, "XXXX-", 5) == 0) { i = 5; if ((strlen(name) - 5) == 0) return (layerID); } if (strncmp(name + i, layerName + i, strlen(name) - i) == 0) return (layerID); } return (CMfailed); }
int _RGISToolsGridExportARCInfo (DBObjData *data,char *selection) { DBInt layerID, i; FILE *file; char coverName [11], command [256]; char asciiGrid [FILENAME_MAX]; char attribDef [FILENAME_MAX]; char attribData [FILENAME_MAX]; char amlFile [FILENAME_MAX]; DBGridIF *gridIF = new DBGridIF (data); DBObjRecord *layerRec; for (layerID = 0;layerID < gridIF->LayerNum ();++layerID) { layerRec = gridIF->Layer (layerID); sprintf (asciiGrid,"%s/asciigrid%d.tmp",selection,layerID); if (DBExportARCGridLayer (data,layerRec,asciiGrid) == DBFault) return (DBFault); } if (data->Type () == DBTypeGridDiscrete) { sprintf (attribDef,"%s/attrib.def",selection); if (DBExportARCTableDef (data,DBrNItems,attribDef) == DBFault) { unlink (asciiGrid); return (DBFault); } sprintf (attribData,"%s/attrib.dat",selection); if (DBExportARCTableData (data,DBrNItems,attribData) == DBFault) { unlink (asciiGrid); unlink (attribDef); return (DBFault); } } sprintf (amlFile,"%s/grdcreate.aml",selection); if ((file = fopen (amlFile,"w")) == NULL) { for (layerID = 0;layerID < gridIF->LayerNum ();++layerID) { layerRec = gridIF->Layer (layerID); sprintf (asciiGrid,"%s/asciigrid%d.tmp",selection,layerID); unlink (asciiGrid); } if (data->Type () == DBTypeGridDiscrete) { unlink (attribDef); unlink (attribData); } CMmsgPrint (CMmsgAppError, "Aml File Creation Error in: %s %d",__FILE__,__LINE__); return (DBFault); } fprintf (file,"&workspace %s\n",selection); for (layerID = 0;layerID < gridIF->LayerNum ();++layerID) { layerRec = gridIF->Layer (layerID); strncpy (coverName,layerRec->Name (),sizeof (coverName) - 1); coverName [sizeof (coverName) - 1] = '\0'; for (i = 0;i < (DBInt) strlen (coverName);++i) if (coverName [i] == '.') coverName [i] = '\0'; for (i = 0;i < (DBInt) strlen (coverName);++i) coverName [i] = tolower (coverName [i]); sprintf (asciiGrid,"%s/asciigrid%d.tmp",selection,layerID); if (data->Type () == DBTypeGridContinuous) fprintf (file,"asciigrid %s g_%s float\n",asciiGrid,coverName); else fprintf (file,"asciigrid %s g_%s int\n",asciiGrid,coverName); if (data->Type () == DBTypeGridDiscrete) { fprintf (file,"tables\n"); fprintf (file,"define g_%s.vattr\n",coverName); fprintf (file,"&r %s\n",attribDef); fprintf (file,"~\n"); fprintf (file,"alter GridValue\n"); fprintf (file,"value,,,,\n"); fprintf (file,"add\n"); fprintf (file,"&r %s\n",attribData); fprintf (file,"~\n"); fprintf (file,"q stop\n"); fprintf (file,"joinitem g_%s.vat g_%s.vattr g_%s.vat value count\n",coverName,coverName,coverName); fprintf (file,"tables\n"); fprintf (file,"select g_%s.vattr\n",coverName); fprintf (file,"erase g_%s.vattr\ny\n",coverName); fprintf (file,"q stop\n"); } } fclose (file); if (getenv ("GHAAS_ARC") != NULL) { sprintf (command,getenv ("GHAAS_ARC"),amlFile); system (command); for (layerID = 0;layerID < gridIF->LayerNum ();++layerID) { layerRec = gridIF->Layer (layerID); sprintf (asciiGrid,"%s/asciigrid%d.tmp",selection,layerID); unlink (asciiGrid); } if (data->Type () == DBTypeGridDiscrete) { unlink (attribDef); unlink (attribData); } unlink (amlFile); } return (DBSuccess); }
int DBImportARCVector (DBObjData *vecData,const char *arcCov,const char *nameFieldStr,const char *symbolFieldStr) { char symbolName [DBStringLength + 1]; DBObjTable *items = vecData->Table (DBrNItems); DBObjTable *symbols = vecData->Table (DBrNSymbols); DBObjTableField *nameFLD = NULL, *symbolResFLD, *symbolFLD = NULL; DBObjTableField *symbolIDFLD = symbols->Field (DBrNSymbolID); DBObjTableField *foregroundFLD = symbols->Field (DBrNForeground); DBObjTableField *backgroundFLD = symbols->Field (DBrNBackground); DBObjTableField *styleFLD = symbols->Field (DBrNStyle); DBObjRecord *record; DBObjRecord *symbolRec; if (DBInfoGetFields (items,DBInfoFileName (arcCov,vecData->Type ())) == DBSuccess) if (DBInfoGetTable (items,DBInfoFileName (arcCov,vecData->Type ())) == DBFault) return (DBFault); switch (vecData->Type ()) { case DBTypeVectorPoint: if (DBImportARCPoint (vecData,arcCov) == DBFault) return (DBFault); else break; case DBTypeVectorLine: if (DBImportARCLine (vecData,arcCov) == DBFault) return (DBFault); else break; case DBTypeVectorPolygon: if (DBImportARCPoly (vecData,arcCov) == DBFault) return (DBFault); else break; default: return (DBFault); } nameFLD = nameFieldStr != NULL ? items->Field (nameFieldStr) : (DBObjTableField *) NULL; symbolFLD = symbolFieldStr != NULL ? items->Field (symbolFieldStr) : (DBObjTableField *) NULL; symbolResFLD = items->Field (DBrNSymbol); if (symbolFLD != NULL) { for (record = items->First ();record != (DBObjRecord *) NULL;record = items->Next ()) { switch (symbolFLD->Type ()) { case DBTableFieldString: if ((symbolRec = (DBObjRecord *) symbols->Item (symbolFLD->String (record))) == NULL) { if ((symbolRec = symbols->Add (symbolFLD->String (record))) == NULL) { CMmsgPrint (CMmsgAppError,"Symbol Object Creation Error in: %s %d",__FILE__,__LINE__); return (DBFault); } symbolIDFLD->Int (symbolRec,symbolRec->RowID ()); foregroundFLD->Int (symbolRec,1); backgroundFLD->Int (symbolRec,0); styleFLD->Int (symbolRec,0); } break; case DBTableFieldInt: sprintf (symbolName,"Symbol:%5d",symbolFLD->Int (record)); if ((symbolRec = (DBObjRecord *) symbols->Item (symbolName)) == NULL) { if ((symbolRec = symbols->Add (symbolName)) == NULL) { CMmsgPrint (CMmsgAppError, "Symbol Object Creation Error in: %s %d",__FILE__,__LINE__); return (DBFault); } symbolIDFLD->Int (symbolRec,symbolFLD->Int (record)); foregroundFLD->Int (symbolRec,1); backgroundFLD->Int (symbolRec,0); styleFLD->Int (symbolRec,0); } break; default: CMmsgPrint (CMmsgAppError, "Invalid Field Type in: %s %d",__FILE__,__LINE__); break; } symbolResFLD->Record (record,symbolRec); } } else { symbols->Add ("Default Symbol"); if ((symbolRec = (DBObjRecord *) symbols->Item ()) == (DBObjRecord *) NULL) { CMmsgPrint (CMmsgAppError, "Symbol Object Creation Error in: %s %d",__FILE__,__LINE__); return (DBFault); } symbolIDFLD->Int (symbolRec,0); foregroundFLD->Int (symbolRec,1); backgroundFLD->Int (symbolRec,0); styleFLD->Int (symbolRec,0); for (record = items->First ();record != (DBObjRecord *) NULL;record = items->Next ()) symbolResFLD->Record (record,symbolRec); } if (nameFLD != NULL) for (record = items->First ();record != (DBObjRecord *) NULL;record = items->Next ()) record->Name (nameFLD->String (record)); return (DBSuccess); }
DBInt Write (FILE *file,DBObjData *data) { char *dmRecord; DBInt layerID, docLen, dbType, intVal; DBFloat floatVal; DBPosition pos; DBObjRecord *layerRec; DBGridIF *gridIF = new DBGridIF (data); DMLayerHeader dmLayerHeader; dbType = gridIF->ValueType (); switch (dbType) { case DBTableFieldFloat: DataType (DMFloat); break; case DBTableFieldInt: DataType (gridIF->ValueSize () > 1 ? DMInt : DMByte); break; } CellWidth (gridIF->CellWidth ()); CellHeight (gridIF->CellHeight ()); Extent (data->Extent ()); LayerNum (gridIF->LayerNum ()); RowNum (gridIF->RowNum ()); ColNum (gridIF->ColNum ()); dmRecord = (char *) calloc (RowNum () * ColNum (),DataType () != DMByte ? sizeof (int) : sizeof (char)); if (dmRecord == (char *) NULL) { CMmsgPrint (CMmsgSysError, "Memory Allocation Error in: %s %d",__FILE__,__LINE__); return (DBFault); } DMFileHeader::Write (file); for (layerID = 0;layerID < gridIF->LayerNum ();++layerID) { layerRec = gridIF->Layer (layerID); dmLayerHeader.Description (layerRec->Name ()); dmLayerHeader.Write (file); } docLen = strlen (data->Document (DBDocComment)); if (fwrite (&docLen,sizeof (int),1,file) != 1) { CMmsgPrint (CMmsgSysError, "File Writing Error in: %s %d",__FILE__,__LINE__); return (DBFault); } if (docLen > 0) { if (fwrite (data->Document (DBDocComment),docLen,1,file) != 1) { CMmsgPrint (CMmsgSysError, "File Writing Error in: %s %d",__FILE__,__LINE__); return (DBFault); } } for (layerID = 0;layerID < gridIF->LayerNum ();++layerID) { layerRec = gridIF->Layer (layerID); switch (data->Type ()) { case DBTypeGridContinuous: layerRec = gridIF->Layer (layerID); if (dbType == DBTableFieldFloat) { for (pos.Row = 0;pos.Row < RowNum ();pos.Row++) for (pos.Col = 0;pos.Col < ColNum ();pos.Col++) if (gridIF->Value (layerRec,pos,&floatVal)) ((float *) dmRecord) [(RowNum () - pos.Row - 1) * ColNum () + pos.Col] = (float) floatVal; else ((float *) dmRecord) [(RowNum () - pos.Row - 1) * ColNum () + pos.Col] = MissingValue (); } else { for (pos.Row = 0;pos.Row < RowNum ();pos.Row++) for (pos.Col = 0;pos.Col < ColNum ();pos.Col++) if (gridIF->Value (layerRec,pos,&intVal)) { if (DataType () == DMInt) ((int *) dmRecord) [(RowNum () - pos.Row - 1) * ColNum () + pos.Col] = (int) intVal; else dmRecord [(RowNum () - pos.Row - 1) * ColNum () + pos.Col] = intVal; } else { if (DataType () == DMInt) ((int *) dmRecord) [(RowNum () - pos.Row - 1) * ColNum () + pos.Col] = (int) MissingValue (); else dmRecord [(RowNum () - pos.Row - 1) * ColNum () + pos.Col] = -99; } } break; case DBTypeGridDiscrete: for (pos.Row = 0;pos.Row < RowNum ();pos.Row++) for (pos.Col = 0;pos.Col < ColNum ();pos.Col++) { intVal = gridIF->GridValue (layerRec,pos); if (DataType () == DMInt) ((int *) dmRecord) [(RowNum () - pos.Row - 1) * ColNum () + pos.Col] = intVal; else dmRecord [(RowNum () - pos.Row - 1) * ColNum () + pos.Col] = -99; } break; default: CMmsgPrint (CMmsgAppError, "Invalid Data Type in: %s %d",__FILE__,__LINE__); free (dmRecord); delete gridIF; return (DBFault); } if ((DBInt) fwrite (dmRecord,DataType () == DMByte ? sizeof (char) : sizeof (int),DataPointNum (),file) != DataPointNum ()) { CMmsgPrint (CMmsgSysError, "File Writing Error in: %s %d",__FILE__,__LINE__); return (DBFault); } } free (dmRecord); delete gridIF; return (DBSuccess); }
void RGISAnGNUXYPlotCBK (Widget widget,RGISWorkspace *workspace,XmAnyCallbackStruct *callData) { FILE *file; char command [DBDataFileNameLen * 2 + DBStringLength]; const char *ghaasDir; char *f0Text, *f1Text, fileName [12]; int allowOk, fd; static int plot = false, logScale = false; DBDataset *dataset = UIDataset (); DBObjData *dbData = dataset->Data (); DBObjTable *itemTable = dbData->Table (DBrNItems); static Widget dShell = (Widget) NULL, mainForm; static Widget field0TextF, field1TextF; Widget toggle; XmString string; if (dShell == (Widget) NULL) { Widget button; dShell = UIDialogForm ((char *) "Compare Fields",false); mainForm = UIDialogFormGetMainForm (dShell); string = XmStringCreate ((char *) "Select",UICharSetBold); button = XtVaCreateManagedWidget ("RGISEdiCompFieldsButton",xmPushButtonWidgetClass,mainForm, XmNtopAttachment, XmATTACH_FORM, XmNtopOffset, 10, XmNrightAttachment, XmATTACH_FORM, XmNrightOffset, 10, XmNmarginHeight, 5, XmNtraversalOn, False, XmNlabelString, string, XmNuserData, DBTableFieldIsNumeric, NULL); XmStringFree (string); field0TextF = XtVaCreateManagedWidget ("RGISEditCompField0TextF",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) UIAuxObjectSelectCBK,field0TextF); string = XmStringCreate ((char *) "X Field:",UICharSetBold); XtVaCreateManagedWidget ("RGISEditCompFieldNameLabel",xmLabelWidgetClass,mainForm, XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET, XmNtopWidget, button, XmNleftAttachment, XmATTACH_FORM, XmNleftOffset, 10, XmNrightAttachment, XmATTACH_WIDGET, XmNrightWidget, field0TextF, XmNrightOffset, 10, XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET, XmNbottomWidget, button, XmNlabelString, string, NULL); XmStringFree (string); string = XmStringCreate ((char *) "Select",UICharSetBold); button = XtVaCreateManagedWidget ("RGISEditCompField0Button",xmPushButtonWidgetClass,mainForm, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget, button, XmNtopOffset, 10, XmNrightAttachment, XmATTACH_FORM, XmNrightOffset, 10, XmNmarginHeight, 5, XmNtraversalOn, False, XmNlabelString, string, XmNuserData, DBTableFieldIsNumeric, NULL); XmStringFree (string); field1TextF = XtVaCreateManagedWidget ("RGISEditCompField1TextF",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) UIAuxObjectSelectCBK,field1TextF); string = XmStringCreate ((char *) "Y Field:",UICharSetBold); XtVaCreateManagedWidget ("RGISEditCompField1Label",xmLabelWidgetClass,mainForm, XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET, XmNtopWidget, button, XmNleftAttachment, XmATTACH_FORM, XmNleftOffset, 10, XmNrightAttachment, XmATTACH_WIDGET, XmNrightWidget, field1TextF, XmNrightOffset, 10, XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET, XmNbottomWidget, button, XmNlabelString, string, NULL); XmStringFree (string); string = XmStringCreate ((char *) "Logarithmic Scale",UICharSetBold); toggle = XtVaCreateManagedWidget ("RGISEditCompLogScaleToggle",xmToggleButtonWidgetClass,mainForm, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget, button, XmNtopOffset, 10, XmNrightAttachment, XmATTACH_FORM, XmNrightOffset, 10, XmNbottomAttachment, XmATTACH_FORM, XmNbottomOffset, 10, XmNlabelString, string, XmNhighlightThickness, 0, XmNshadowThickness, 0, XmNmarginWidth, 5, XmNset, False, NULL); XmStringFree (string); XtAddCallback (toggle,XmNvalueChangedCallback,(XtCallbackProc) UIAuxSetToggleCBK, (XtPointer) &logScale); XtAddCallback (UIDialogFormGetOkButton (dShell),XmNactivateCallback,(XtCallbackProc) UIAuxSetBooleanTrueCBK,&plot); } plot = false; XtVaSetValues (field0TextF,XmNuserData, itemTable->Fields (), NULL); XtVaSetValues (field1TextF,XmNuserData, itemTable->Fields (), NULL); UIDialogFormPopup (dShell); while (UILoop ()) { f0Text = XmTextFieldGetString (field0TextF); f1Text = XmTextFieldGetString (field1TextF); allowOk = (strlen (f0Text) > 0) && (strlen (f1Text) > 0); XtFree (f0Text); XtFree (f1Text); XtSetSensitive (UIDialogFormGetOkButton (dShell),allowOk); } UIDialogFormPopdown (dShell); if (plot) { char buffer [256]; DBInt intVal, rowID; DBFloat val; DBObjTableField *field0 = itemTable->Field (f0Text = XmTextFieldGetString (field0TextF)); DBObjTableField *field1 = itemTable->Field (f1Text = XmTextFieldGetString (field1TextF)); DBObjRecord *record; XtFree (f0Text); XtFree (f1Text); if ((field0 == (DBObjTableField *) NULL) || (field1 == (DBObjTableField *) NULL)) { CMmsgPrint (CMmsgAppError, "Invalid Compare Fields in: %s %d",__FILE__,__LINE__); return; } strcpy (fileName,"ghaasXXXXXX"); if ((fd = mkstemp (fileName)) == DBFault) { CMmsgPrint (CMmsgSysError, "File Opening Error in: %s %d",__FILE__,__LINE__); return; } if ((file = fdopen (fd,"w")) == (FILE *) NULL) { CMmsgPrint (CMmsgSysError, "File Opening Error in: %s %d",__FILE__,__LINE__); return; } fprintf (file,"\"GHAASId\"\t\"RecordName\"\t\"Selected\"\t\"%s\"\t\"%s\"\n",field0->Name (),field1->Name ()); for (rowID = 0;rowID < itemTable->ItemNum ();++rowID) { record = itemTable->Item (rowID); if ((record->Flags () & DBObjectFlagIdle) == DBObjectFlagIdle) continue; sprintf (buffer,"%d\t\"%s\"\t%d",record->RowID () + 1,record->Name (), (record->Flags () & DBObjectFlagSelected) == DBObjectFlagSelected ? true : false); if (field0->Type () == DBTableFieldInt) { intVal = field0->Int (record); if (intVal == field0->IntNoData ()) continue; sprintf (buffer + strlen (buffer),"\t%d",intVal); } else { val = field0->Float (record); if (CMmathEqualValues (val,field0->FloatNoData ())) continue; sprintf (buffer + strlen (buffer),"\t%f",val); } if (field1->Type () == DBTableFieldInt) { intVal = field1->Int (record); if (intVal == field1->IntNoData ()) continue; sprintf (buffer + strlen (buffer),"\t%d",intVal); } else { val = field1->Float (record); if (CMmathEqualValues (val,field1->FloatNoData ())) continue; sprintf (buffer + strlen (buffer),"\t%f",val); } fprintf (file,"%s\n",buffer); } fclose (file); ghaasDir = getenv ("GHAAS_DIR"); sprintf (command,"%s/Scripts/xy-plot.sh %s %s",ghaasDir != (const char *) NULL ? ghaasDir : ".",fileName,logScale ? "log" : "normal"); system (command); unlink (fileName); } }
void _RGISUserFuncionQuery (DBObjData *dbData,UI2DView *view,XEvent *event) { DBInt sX, sY; DBCoordinate coord; DBObjData *data = dbData; UIAttribView *attribView; if (event->type != ButtonPress) return; sX = event->xbutton.x; sY = event->xbutton.y; view->Window2Map (sX,sY, &(coord.X), &(coord.Y)); for (data = dbData; (data != (DBObjData *) NULL) && ((data->Flags () & DBObjectFlagProcessed) != DBObjectFlagProcessed); data = data->LinkedData ()) { data->Flags (DBObjectFlagProcessed,DBSet); if ((data->Flags () & DBDataFlagUserModeFlags) == DBDataFlagUserModeQuery) { if ((attribView = (UIAttribView *) data->Display (UIAttribViewSTR)) == (UIAttribView *) NULL) data->DispAdd (attribView = new UIAttribView (data)); switch (data->Type ()) { case DBTypeVectorPoint: case DBTypeVectorLine: case DBTypeVectorPolygon: { DBVectorIF *vectorIF = new DBVectorIF (data); attribView->Draw (vectorIF->Item (coord)); } break; case DBTypeGridDiscrete: { DBGridIF *gridIF = new DBGridIF (data); attribView->Draw (gridIF->GridItem (coord)); delete gridIF; } break; case DBTypeGridContinuous: { DBPosition pos; DBGridIF *gridIF = new DBGridIF (data); char nameString [DBStringLength * 2]; DBObjRecord *record = new DBObjRecord ("Noname",sizeof (DBCoordinate)); gridIF->Coord2Pos (coord,pos); gridIF->Pos2Coord (pos,coord); sprintf (nameString,"CellCoordinate %10.2f%10.2f",coord.X,coord.Y); record->Name (nameString); memcpy (record->Data (),(void *) &coord,sizeof (coord)); attribView->Draw (record); delete record; delete gridIF; } break; case DBTypeNetwork: { DBNetworkIF *netIF = new DBNetworkIF (data); attribView->Draw (netIF->Cell (coord)); delete netIF; } break; default: CMmsgPrint (CMmsgAppError, "Invalid Data Type in: %s %d",__FILE__,__LINE__); break; } } } for (data = dbData; (data != (DBObjData *) NULL) && ((data->Flags () & DBObjectFlagProcessed) == DBObjectFlagProcessed); data = data->LinkedData ()) data->Flags (DBObjectFlagProcessed,DBClear); }
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 (); }