Esempio n. 1
0
int DBObjData::_Write (FILE *file)

	{
	DBInt id, userFlags;
	DBObjRecord *docRec;

	userFlags = Flags () & DBDataFlagUserModeFlags;
	Flags (DBDataFlagUserModeFlags,DBClear);
	if (DBObject::Write (file) == DBFault)		return (DBFault);
	Flags (userFlags,DBSet);
	if (DocsPTR->Write (file) == DBFault)		return (DBFault);
	for (id = 0;id < DocsPTR->ItemNum ();++id)
		{
		if (DocsPTR->WriteItem (file,id) == DBFault) return (DBFault);
		docRec = DocsPTR->Item (id);
		if (((DBVarString *) docRec->Data ())->Write (file) == DBFault) return (DBFault);
		}
	if (ArraysPTR->Write (file) == DBFault)		return (DBFault);
	for (id = 0;id < ArraysPTR->ItemNum ();++id)
		if (ArraysPTR->WriteItem (file,id) == DBFault) return (DBFault);
	TablesPTR->Write (file);
	for (id = 0;id < TablesPTR->ItemNum ();++id)
		if (TablesPTR->WriteItem (file,id) == DBFault) return (DBFault);
	return (BuildFields ());
	}
Esempio n. 2
0
void DBGridOperationAbs(DBObjData *grdData) {
    DBInt layerID;
    DBFloat value;
    DBPosition pos;
    DBObjRecord *layerRec;
    DBGridIF *gridIF = new DBGridIF(grdData);

    for (layerID = 0; layerID < gridIF->LayerNum(); ++layerID) {
        layerRec = gridIF->Layer(layerID);
        if ((layerRec->Flags() & DBObjectFlagIdle) != DBObjectFlagIdle) break;
    }
    if (layerID == gridIF->LayerNum()) {
        CMmsgPrint(CMmsgAppError, "No Layer to Process in %s %d", __FILE__, __LINE__);
        return;
    }

    for (layerID = 0; layerID < gridIF->LayerNum(); ++layerID) {
        layerRec = gridIF->Layer(layerID);
        if ((layerRec->Flags() & DBObjectFlagIdle) == DBObjectFlagIdle) continue;

        for (pos.Row = 0; pos.Row < gridIF->RowNum(); pos.Row++) {
            if (DBPause((layerID * gridIF->RowNum() + pos.Row) * 100 / (gridIF->LayerNum() * gridIF->RowNum())))
                goto Stop;
            for (pos.Col = 0; pos.Col < gridIF->ColNum(); pos.Col++)
                if (gridIF->Value(layerRec, pos, &value)) gridIF->Value(layerRec, pos, fabs(value));
        }
        gridIF->RecalcStats(layerRec);
    }
    Stop:
    return;
}
Esempio n. 3
0
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);
	}
Esempio n. 4
0
void DBObjTable::AddField(DBObjTableField *field) {
    DBInt recID;
    DBObjRecord *record;
    field->StartByte(RecordLengthVAR);
    FieldPTR->Add(field);
    RecordLengthVAR += field->Length();
    for (recID = 0; recID < ItemNum(); recID++) {
        record = Item(recID);
        record->Realloc(RecordLengthVAR);
        switch (field->Type()) {
            case DBTableFieldString:
                field->String(record, "");
                break;
            case DBTableFieldInt:
                field->Int(record, field->IntNoData());
                break;
            case DBTableFieldFloat:
                field->Float(record, field->FloatNoData());
                break;
            case DBTableFieldDate:
                field->Date(record, field->DateNoData());
                break;
        }
    }
}
Esempio n. 5
0
DBInt DBGridIF::Value (DBObjRecord *layerRec,DBPosition pos,DBFloat *value) const

	{
	DBInt j;
	DBObjRecord *dataRec = LayerFLD->Record (layerRec);
	DBFloat missingValue = MissingValueFLD->Float (ItemTable->Item (layerRec->RowID ()));

//	if (pos.Col < 0) return (false); No longer possible
//	if (pos.Row < 0) return (false);
	if (pos.Col >= DimensionVAR.Col) return (false);
	if (pos.Row >= DimensionVAR.Row) return (false);

	j = DimensionVAR.Col * (DimensionVAR.Row - pos.Row - 1) + pos.Col;
	switch (ValueTypeVAR)
		{
		case DBTableFieldFloat:
			switch (ValueSizeVAR)
				{
				case sizeof (DBFloat4): *value = (DBFloat) ((DBFloat4 *) (dataRec->Data ())) [j]; break;
				case sizeof (DBFloat):  *value = (DBFloat) ((DBFloat *)  (dataRec->Data ())) [j]; break;
				}
			break;
		case DBTableFieldInt:
			switch (ValueSizeVAR)
				{
				case sizeof (DBByte):  *value = (DBFloat) ((DBByte *)	 (dataRec->Data ())) [j];	break;
				case sizeof (DBShort): *value = (DBFloat) ((DBShort *) (dataRec->Data ())) [j];	break;
				case sizeof (DBInt):   *value = (DBFloat) ((DBInt *)	 (dataRec->Data ())) [j];	break;
				}
			break;
		}
	return (CMmathEqualValues (*value,missingValue) ? false : true);
	}
Esempio n. 6
0
DBInt DBGridIF::Value (DBObjRecord *layerRec,DBPosition pos,DBFloat value)

	{
	DBInt j = DimensionVAR.Col * (DimensionVAR.Row - pos.Row - 1) + pos.Col;
	DBObjRecord *dataRec = LayerFLD->Record (layerRec);

	if (pos.Col < 0) return (DBFault);
	if (pos.Row < 0) return (DBFault);
	if (pos.Col >= DimensionVAR.Col) return (DBFault);
	if (pos.Row >= DimensionVAR.Row) return (DBFault);

	switch (ValueTypeVAR)
		{
		case DBTableFieldFloat:
			switch (ValueSizeVAR)
				{
				case sizeof (DBFloat4): ((DBFloat4 *) (dataRec->Data ())) [j] = (DBFloat4) value; break;
				case sizeof (DBFloat):  ((DBFloat *)  (dataRec->Data ())) [j] = value; break;
				}
			break;
		case DBTableFieldInt:
			switch (ValueSizeVAR)
				{
				case sizeof (DBByte):  ((DBByte *)  (dataRec->Data ())) [j] = (DBByte)  value;	break;
				case sizeof (DBShort): ((DBShort *) (dataRec->Data ())) [j] = (DBShort) value;	break;
				case sizeof (DBInt):   ((DBInt *)   (dataRec->Data ())) [j] = (DBInt)   value;	break;
				}
			break;
		}
	return (DBSuccess);
	}
Esempio n. 7
0
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);
	}
Esempio n. 8
0
DBInt DBGridIF::Value (DBObjRecord *layerRec,DBPosition pos,DBInt *value) const

	{
	DBInt j;
	DBObjRecord *dataRec = LayerFLD->Record (layerRec);

	if (pos.Col < 0) return (false);
	if (pos.Row < 0) return (false);
	if (pos.Col >= DimensionVAR.Col) return (false);
	if (pos.Row >= DimensionVAR.Row) return (false);

	j = DimensionVAR.Col * (DimensionVAR.Row - pos.Row - 1) + pos.Col;
	switch (ValueTypeVAR)
		{
		case DBTableFieldFloat:
			switch (ValueSizeVAR)
				{
				case sizeof (DBFloat4): *value = (DBInt) ((DBFloat4 *) (dataRec->Data ())) [j]; break;
				case sizeof (DBFloat):  *value = (DBInt) ((DBFloat *)  (dataRec->Data ())) [j]; break;
				}
			break;
		case DBTableFieldInt:
			switch (ValueSizeVAR)
				{
				case sizeof (DBByte):  *value = (DBInt) ((DBByte *)  (dataRec->Data ())) [j];	break;
				case sizeof (DBShort): *value = (DBInt) ((DBShort *) (dataRec->Data ())) [j];	break;
				case sizeof (DBInt):   *value = (DBInt) ((DBInt *)   (dataRec->Data ())) [j];	break;
				}
			break;
		}
	if (MissingValueFLD != (DBObjTableField *) NULL)
		return (*value == MissingValueFLD->Int (ItemTable->Item (layerRec->RowID ())) ? false : true);
	return (*value == DBFault ? false: true);
	}
Esempio n. 9
0
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);
}
Esempio n. 10
0
int DBNetworkIF::Trim ()

	{
	DBInt i, row, col;
	DBPosition pos, min, max;
	DBRegion extent = DataPTR->Extent ();
	DBObjRecord *cellRec;
	DBCoordinate coord;

	min.Row = RowNum ();
	min.Col = ColNum ();
	max.Row = max.Col = 0;

	for (i = 0;i < CellNum ();++i)
		{
		DBPause (33 * i / CellNum ());
		cellRec = CellTable->Item (i);
		pos = CellPosition (cellRec);
		min.Row = min.Row < pos.Row ? min.Row : pos.Row;
		min.Col = min.Col < pos.Col ? min.Col : pos.Col;
		max.Row = max.Row > pos.Row ? max.Row : pos.Row;
		max.Col = max.Col > pos.Col ? max.Col : pos.Col;
		}

	for (i = 0;i < CellNum ();++i)
		{
		DBPause (33 + 33 * i / CellNum ());
		cellRec = CellTable->Item (i);
		pos = CellPosition (cellRec);
		pos.Row = pos.Row - min.Row;
		pos.Col = pos.Col - min.Col;
		PositionFLD->Position (cellRec,pos);
		}
	coord.X = min.Col * CellWidth ();
	coord.Y = min.Row * CellHeight ();
	extent.LowerLeft = extent.LowerLeft + coord;
	coord.X = (ColNum () - max.Col - 1) * CellWidth ();
	coord.Y = (RowNum () - max.Row - 1) * CellHeight ();
	extent.UpperRight = extent.UpperRight - coord;
	DataPTR->Extent (extent);

	row = max.Row - min.Row + 1;
	col = max.Col - min.Col + 1;
	RowNumFLD->Int (LayerRecord,row);
	ColNumFLD->Int (LayerRecord,col);

	DataRec->Realloc (row * col * sizeof (int));

	for (row = 0;row < RowNum ();row++)	for (col = 0;col < ColNum ();col++)
			((DBInt *) DataRec->Data ()) [row * ColNum () + col] = DBFault;

	for (i = 0;i < CellNum ();++i)
		{
		DBPause (67 + 33 * i / CellNum ());
		pos = CellPosition (CellTable->Item (i));
		((DBInt *) DataRec->Data ()) [pos.Row * ColNum () + pos.Col] = cellRec->RowID ();
		}

	return (DBSuccess);
	}
Esempio n. 11
0
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);
    }
}
Esempio n. 12
0
void DBObjTable::DeleteAllFields() {
    DBObjRecord *record;

    FieldPTR->DeleteAll();
    RecordLengthVAR = 0;
    for (record = First(); record != (DBObjRecord *) NULL; record = Next())
        record->Realloc(RecordLengthVAR);
}
Esempio n. 13
0
 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);
 }
Esempio n. 14
0
void DBObjData::Document(const char *docName, const char *string) {
    DBObjRecord *obj = DocsPTR->Item(docName);

    if (obj == (DBObjRecord *) NULL) {
        DocsPTR->Add(obj = new DBObjRecord(docName, sizeof(DBVarString)));
        memset(obj->Data(), 0, sizeof(DBVarString));
        ((DBVarString *) obj->Data())->VString(string);
    }
    else ((DBVarString *) obj->Data())->VString(string);
}
Esempio n. 15
0
static DBInt _RGlibSubbasinCategories(void *io, DBObjRecord *cellRec) {
    DBObjRecord *grdRec;
    DBNetworkIF *netIF = (DBNetworkIF *) io;
    if (cellRec == (DBObjRecord *) NULL) return (false);
    grdRec = _RGlibPointGrdIF->GridItem(_RGlibPointGrdLayerRec, netIF->Center(cellRec));
    if (grdRec == (DBObjRecord *) NULL) return (true);
    _RGlibHistogram[grdRec->RowID()].cellNum++;
    _RGlibHistogram[grdRec->RowID()].area += netIF->CellArea(cellRec);
    return (true);
}
Esempio n. 16
0
char *DBObjData::Document(const char *docName) {
    DBObjRecord *obj = DocsPTR->Item(docName);
    if (obj == (DBObjRecord *) NULL) {
        if ((strcmp(docName, DBDocSubject) == 0) || (strcmp(docName, DBDocGeoDomain) == 0)) {
            Document(docName, (char *) "unspecified");
            return ((char *) "unspecified");
        }
        else return ((char *) "");
    }
    return (((DBVarString *) obj->Data())->VString());
}
Esempio n. 17
0
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);
    }
}
Esempio n. 18
0
static void _RGISGridLayerListCBK (Widget widget,void *dummy, XmListCallbackStruct *callData)

	{
	int item = 0;
	DBObjData *data;
	DBObjTable *layerTable;
	DBObjRecord *record;

	XtVaGetValues (widget,XmNuserData, &data, NULL);
	layerTable = data->Table (DBrNLayers);
	for (record = layerTable->First ();record != (DBObjRecord *) NULL;record = layerTable->Next ())
		if (++item == callData->item_position)	layerTable->Item (record->RowID (),true);
	}
Esempio n. 19
0
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);
}
Esempio n. 20
0
		void Update ()
			{
			ForegroundFLD->Int (OrigREC,Foreground ());
			BackgroundFLD->Int (OrigREC,Background ());
			StyleFLD->Int (OrigREC,Style ());
			OrigREC->Name (Name ());
			}
Esempio n. 21
0
 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);
 }
Esempio n. 22
0
 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());
 }
Esempio n. 23
0
    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);
    }
Esempio n. 24
0
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);
    }
}
Esempio n. 25
0
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);
}
Esempio n. 26
0
void DBGridOperation(DBObjData *grdData, DBFloat constant, DBInt oper) {
    DBInt layerID;
    DBFloat value;
    DBPosition pos;
    DBObjRecord *layerRec;
    DBGridIF *gridIF = new DBGridIF(grdData);

    for (layerID = 0; layerID < gridIF->LayerNum(); ++layerID) {
        layerRec = gridIF->Layer(layerID);
        if ((layerRec->Flags() & DBObjectFlagIdle) != DBObjectFlagIdle) break;
    }
    if (layerID == gridIF->LayerNum()) {
        CMmsgPrint(CMmsgAppError, "No Layer to Process in %s %d", __FILE__, __LINE__);
        return;
    }

    for (layerID = 0; layerID < gridIF->LayerNum(); ++layerID) {
        layerRec = gridIF->Layer(layerID);
        if ((layerRec->Flags() & DBObjectFlagIdle) == DBObjectFlagIdle) continue;

        for (pos.Row = 0; pos.Row < gridIF->RowNum(); pos.Row++) {
            if (DBPause((layerID * gridIF->RowNum() + pos.Row) * 100 / (gridIF->LayerNum() * gridIF->RowNum())))
                goto Stop;
            for (pos.Col = 0; pos.Col < gridIF->ColNum(); pos.Col++) {
                if (gridIF->Value(layerRec, pos, &value))
                    switch (oper) {
                        case DBMathOperatorAdd:
                            gridIF->Value(layerRec, pos, value + constant);
                            break;
                        case DBMathOperatorSub:
                            gridIF->Value(layerRec, pos, value - constant);
                            break;
                        case DBMathOperatorMul:
                            gridIF->Value(layerRec, pos, value * constant);
                            break;
                        case DBMathOperatorDiv:
                            gridIF->Value(layerRec, pos, value / constant);
                            break;
                    }
            }
        }
        gridIF->RecalcStats(layerRec);
    }
    Stop:
    return;
}
Esempio n. 27
0
int DBObjData::_Read(FILE *file, int swap) {
    DBInt id;
    DBObjRecord *docRec;

    if (DBObject::Read(file, swap) == DBFault) return (DBFault);
    if (DocsPTR->Read(file, swap) == DBFault) return (DBFault);
    for (id = 0; id < DocsPTR->ItemNum(); ++id) {
        if (DocsPTR->ReadItem(file, id, swap) == DBFault) return (DBFault);
        docRec = DocsPTR->Item(id);
        if (((DBVarString *) docRec->Data())->Read(file, swap) == DBFault) return (DBFault);
    }
    if (ArraysPTR->Read(file, swap) == DBFault) return (DBFault);
    for (id = 0; id < ArraysPTR->ItemNum(); ++id)
        if (ArraysPTR->ReadItem(file, id, swap) == DBFault) return (DBFault);
    TablesPTR->Read(file, swap);
    for (id = 0; id < TablesPTR->ItemNum(); ++id)
        if (TablesPTR->ReadItem(file, id, swap) == DBFault) return (DBFault);
    return (BuildFields());
}
Esempio n. 28
0
DBObjRecord *DBNetworkIF::CellAdd (DBPosition pos)

	{
	char nameSTR [DBStringLength];
	DBInt dir, fromDir;
	DBPosition fromPos;
	DBObjRecord *cellRec;

	if (pos.Col < 0) return ((DBObjRecord *) NULL);
	if (pos.Row < 0) return ((DBObjRecord *) NULL);
	if (pos.Col >= ColNum ()) return ((DBObjRecord *) NULL);
	if (pos.Row >= RowNum ()) return ((DBObjRecord *) NULL);

	if (((DBInt *) DataRec->Data ()) [pos.Row * ColNum () + pos.Col] != DBFault) return ((DBObjRecord *) NULL);

	sprintf (nameSTR,"Cell:%6d",CellNum ());
	cellRec = CellTable->Add (nameSTR);
	((DBInt *) DataRec->Data ()) [pos.Row * ColNum () + pos.Col] = cellRec->RowID ();
	PositionFLD->Position (cellRec,pos);
	ToCellFLD->Int (cellRec,DBNetDirN);
	fromDir = DBNull;
	for (dir = 0;dir < 8;++dir)
		{
		fromPos = pos;
		if ((dir == DBNetDirNW) || (dir == DBNetDirN) || (dir == DBNetDirNE)) fromPos.Row++;
		if ((dir == DBNetDirSE) || (dir == DBNetDirS) || (dir == DBNetDirSW)) fromPos.Row--;
		if ((dir == DBNetDirNE) || (dir == DBNetDirE) || (dir == DBNetDirSE)) fromPos.Col++;
		if ((dir == DBNetDirNW) || (dir == DBNetDirW) || (dir == DBNetDirSW)) fromPos.Col--;
		if (((DBInt *) DataRec->Data ()) [fromPos.Row * ColNum () + fromPos.Col ] != DBFault) fromDir |= dir;
		}
	FromCellFLD->Int (cellRec,fromDir);
	OrderFLD->Int (cellRec,1);
	BasinFLD->Int (cellRec,1);
	BasinCellsFLD->Int (cellRec,1);
	TravelFLD->Int (cellRec,1);
	UpCellPosFLD->Position (cellRec,pos);
	CellAreaFLD->Float (cellRec,0.0);
	SubbasinLengthFLD->Float (cellRec,0.0);
	SubbasinAreaFLD->Float (cellRec,0.0);
	return (cellRec);
	}
Esempio n. 29
0
DBInt DBObjData::SelectObject(DBObjRecord *record, DBInt select) {
    DBObjTable *items = TablesPTR->Item(DBrNItems);

    if (record == (DBObjRecord *) NULL) return (false);
    if (items->Item(record->RowID()) != record) return (false);

    record->Flags(DBObjectFlagSelected, select);
    if (Type() == DBTypeNetwork) {
        DBInt cellID;
        DBObjRecord *cellRec;
        DBNetworkIF *netIF = new DBNetworkIF(this);

        for (cellID = 0; cellID < netIF->CellNum(); ++cellID) {
            cellRec = netIF->Cell(cellID);
            if (netIF->CellBasinID(cellRec) == record->RowID() + 1)
                cellRec->Flags(DBObjectFlagSelected, select);
        }
        delete netIF;
    }
    return (DBSuccess);
}
Esempio n. 30
0
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 ();
	}