Example #1
0
void DBObjData::RecalcExtent() {
    DBRegion extent;

    switch (Type()) {
        case DBTypeVectorPoint:
        case DBTypeVectorLine:
        case DBTypeVectorPolygon: {
            DBVectorIF *vectorIF = new DBVectorIF(this);
            DBInt recordID;
            for (recordID = 0; recordID < vectorIF->ItemNum(); ++recordID)
                extent.Expand(Extent(vectorIF->Item(recordID)));
            delete vectorIF;
        }
            break;
        case DBTypeGridDiscrete:
        case DBTypeGridContinuous: {
            DBGridIF *gridIF = new DBGridIF(this);
            extent.LowerLeft = Extent().LowerLeft;
            extent.UpperRight.X = extent.LowerLeft.X + gridIF->ColNum() * gridIF->CellWidth();
            extent.UpperRight.Y = extent.LowerLeft.Y + gridIF->RowNum() * gridIF->CellHeight();
            delete gridIF;
        }
            break;
        case DBTypeNetwork: {
            DBNetworkIF *netIF = new DBNetworkIF(this);
            extent.LowerLeft = Extent().LowerLeft;
            extent.UpperRight.X = extent.LowerLeft.X + netIF->ColNum() * netIF->CellWidth();
            extent.UpperRight.Y = extent.LowerLeft.Y + netIF->RowNum() * netIF->CellHeight();
            delete netIF;
        }
            break;
        case DBTypeTable:
        default:
            return;
    }
    Extent(extent);
}
Example #2
0
void _RGISUserFuncionNetwork (DBObjData *data,UI2DView *view,XEvent *event)

	{
	DBInt sX, sY, redraw = false;
	DBNetworkIF *netIF;
	DBCoordinate coord;
	DBObjRecord *cellRec, *basinRec;
	void _RGISUserFuncionQuery (DBObjData *,UI2DView *,XEvent *);

	if ((data->Flags () & DBDataFlagUserModeFlags) == DBDataFlagUserModeQuery)
		{ _RGISUserFuncionQuery (data,view,event);	return; }

	if (event->type != ButtonPress) return;
	if (DBTypeNetwork != data->Type ())
		{ CMmsgPrint (CMmsgAppError, "Invalid data Type in: %s %d",__FILE__,__LINE__); }

	sX = event->xbutton.x;
	sY = event->xbutton.y;
	view->Window2Map  (sX,sY, &coord.X, &coord.Y);

	netIF = new DBNetworkIF (data);
	switch (data->Flags () & DBDataFlagUserModeFlags)
		{
		case DBDataFlagUserModeSelect:
			{
			DBInt basinID, cellID;
			DBRegion extent;
			UITable *tableView;

			if ((cellRec = netIF->Cell (coord)) == (DBObjRecord *) NULL)
				{ UIMessage ((char *) "Cell Does not Exists!"); return; }
			for (basinID = 0;basinID < netIF->BasinNum ();++basinID)
				{
				basinRec = netIF->Basin (basinID);
				if ((basinRec->Flags () & DBObjectFlagSelected) == DBObjectFlagSelected)
					{
					data->SelectObject (basinRec,DBClear);
					extent.Expand (data->Extent (basinRec));
					}
				}
			for (cellID = 0;cellID < netIF->CellNum ();++cellID)
				{
				cellRec = netIF->Cell (cellID);
				if ((cellRec->Flags () & DBObjectFlagSelected) == DBObjectFlagSelected)
					{
					extent.Expand (netIF->Center (cellRec) + (netIF->CellSize () / 2.0));
					extent.Expand (netIF->Center (cellRec) - (netIF->CellSize () / 2.0));
					cellRec->Flags (DBObjectFlagSelected,DBClear);
					}
				}
			if ((tableView = (UITable *) data->Display (UITableName (data,data->Table (DBrNItems)))) != (UITable *) NULL)
				tableView->Draw ();
			if ((tableView = (UITable *) data->Display (UITableName (data,data->Table (DBrNCells)))) != (UITable *) NULL)
				tableView->Draw ();
			UI2DViewRedrawAll (extent);
			cellRec = netIF->Cell (coord);
			switch (data->Flags () & DBDataFlagSelectMode)
				{
				case DBDataFlagSelectMode:	netIF->DownStreamSearch	(cellRec, DBNetworkSelect);	break;
				default:							netIF->UpStreamSearch	(cellRec, DBNetworkSelect);	break;
				}
			extent.Initialize ();
			for (cellID = 0;cellID < netIF->CellNum ();++cellID)
				{
				cellRec = netIF->Cell (cellID);
				if ((cellRec->Flags () & DBObjectFlagSelected) == DBObjectFlagSelected)
					{
					extent.Expand (netIF->Center (cellRec) + (netIF->CellSize () / 2.0));
					extent.Expand (netIF->Center (cellRec) - (netIF->CellSize () / 2.0));
					}
				}
			UI2DViewRedrawAll (extent);
			if ((tableView = (UITable *) data->Display (UITableName (data,data->Table (DBrNCells)))) != (UITable *) NULL)
				tableView->Draw ();
			} break;
		case DBDataFlagUserModeAdd:
			if (netIF->CellAdd (coord) == (DBObjRecord *) NULL) UIMessage ((char *) "Cell Creation Error");
			else redraw = true;
			break;
		case DBDataFlagUserModeDelete:
			if (netIF->CellDelete (coord) == DBFault) UIMessage ((char *) "Cell Does not Exists!");
			else redraw = true;
			break;
		case DBDataFlagUserModeRotate:
			{
			DBObjRecord *cellRec = netIF->Cell (coord);

			if (cellRec != (DBObjRecord *) NULL)
				{
				switch (netIF->CellDirection (cellRec))
					{
					case DBNull:     netIF->CellDirection (cellRec,DBNetDirN); break;
					case DBNetDirNW: netIF->CellDirection (cellRec,DBNull);    break;
					default:         netIF->CellRotate    (cellRec,DBForward); break;
					}
				redraw = true;
				}
			} break;
		default: printf ("Unknown Mode %lX",data->Flags () & DBDataFlagUserModeFlags); break;
		}
	if (redraw)
		{
		DBPosition pos;

		if (netIF->Coord2Pos (coord,pos) == DBSuccess)
			{
			DBRegion extent;
			DBCoordinate delta (netIF->CellWidth () * 1.25, netIF->CellHeight () * 1.25);

			netIF->Pos2Coord (pos,coord); coord = coord + delta; extent.Expand (coord);
			netIF->Pos2Coord (pos,coord); coord = coord - delta; extent.Expand (coord);
			UI2DViewRedrawAll (extent);
			}
		}
	delete netIF;
	}
Example #3
0
DBObjData *DBNetworkToGrid(DBObjData *netData, DBInt type) {
    DBPosition pos;
    DBObjData *grdData = new DBObjData("", type);
    DBObjRecord *layerRec, *dataRec;
    DBObjTable *layerTable = grdData->Table(DBrNLayers);
    DBObjTable *itemTable = grdData->Table(DBrNItems);
    DBObjTableField *rowNumFLD = layerTable->Field(DBrNRowNum);
    DBObjTableField *colNumFLD = layerTable->Field(DBrNColNum);
    DBObjTableField *cellWidthFLD = layerTable->Field(DBrNCellWidth);
    DBObjTableField *cellHeightFLD = layerTable->Field(DBrNCellHeight);
    DBObjTableField *valueTypeFLD = layerTable->Field(DBrNValueType);
    DBObjTableField *valueSizeFLD = layerTable->Field(DBrNValueSize);
    DBObjTableField *layerFLD = layerTable->Field(DBrNLayer);
    DBNetworkIF *netIF;
    DBGridIF *gridIF;

    grdData->Projection(netData->Projection());
    grdData->Precision(netData->Precision());
    grdData->MaxScale(netData->MaxScale());
    grdData->MinScale(netData->MinScale());
    grdData->Extent(netData->Extent());
    grdData->Document(DBDocGeoDomain, netData->Document(DBDocGeoDomain));

    netIF = new DBNetworkIF(netData);

    layerTable->Add("FirstLayer");
    if ((layerRec = layerTable->Item()) == (DBObjRecord *) NULL) {
        delete netIF;
        return ((DBObjData *) NULL);
    }
    rowNumFLD->Int(layerRec, netIF->RowNum());
    colNumFLD->Int(layerRec, netIF->ColNum());
    cellWidthFLD->Float(layerRec, netIF->CellWidth());
    cellHeightFLD->Float(layerRec, netIF->CellHeight());
    switch (type) {
        case DBTypeGridContinuous:
            valueTypeFLD->Int(layerRec, DBTableFieldFloat);
            valueSizeFLD->Int(layerRec, sizeof(DBFloat));
            break;
        case DBTypeGridDiscrete:
            valueTypeFLD->Int(layerRec, DBTableFieldInt);
            valueSizeFLD->Int(layerRec, sizeof(DBInt));
            break;
        default:
            CMmsgPrint(CMmsgAppError, "Invalid Data Type in: %s %d", __FILE__, __LINE__);
            delete grdData;
            delete netIF;
            return ((DBObjData *) NULL);
    }
    if ((dataRec = new DBObjRecord(layerRec->Name(),
                                   ((size_t) netIF->ColNum()) * netIF->RowNum() * valueSizeFLD->Int(layerRec),
                                   valueSizeFLD->Int(layerRec))) == (DBObjRecord *) NULL) {
        delete netIF;
        return ((DBObjData *) NULL);
    }
    (grdData->Arrays())->Add(dataRec);
    layerFLD->Record(layerRec, dataRec);

    gridIF = new DBGridIF(grdData);
    if (type == DBTypeGridContinuous) {
        itemTable->Add(layerRec->Name());
        DBObjTableField *missingValueFLD = itemTable->Field(DBrNMissingValue);
        missingValueFLD->Float(itemTable->Item(layerRec->Name()), DBDefaultMissingFloatVal);
        for (pos.Row = 0; pos.Row < netIF->RowNum(); pos.Row++)
            for (pos.Col = 0; pos.Col < netIF->ColNum(); pos.Col++)
                gridIF->Value(layerRec, pos, DBDefaultMissingFloatVal);
    }
    else {
        DBObjTable *symbolTable = grdData->Table(DBrNSymbols);
        DBObjTableField *foregroundFLD = symbolTable->Field(DBrNForeground);
        DBObjTableField *backgroundFLD = symbolTable->Field(DBrNBackground);
        DBObjTableField *styleFLD = symbolTable->Field(DBrNStyle);
        DBObjRecord *symbolRec = symbolTable->Add("Default Symbol");

        foregroundFLD->Int(symbolRec, 1);
        backgroundFLD->Int(symbolRec, 0);
        styleFLD->Int(symbolRec, 0);
        for (pos.Row = 0; pos.Row < netIF->RowNum(); pos.Row++)
            for (pos.Col = 0; pos.Col < netIF->ColNum(); pos.Col++)
                gridIF->Value(layerRec, pos, 0);
    }
    delete netIF;
    delete gridIF;
    return (grdData);
}