Beispiel #1
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;
	}
Beispiel #2
0
void RGISEditAdjustNetworkCBK (Widget widget, RGISWorkspace *workspace,XmAnyCallbackStruct *callData)

	{
	DBInt vertex, vertexNum, dir, cell, cellNum, maxCellNum = 0;
	DBPosition pos0, pos1;
	DBCoordinate *vertexes;
	DBObjRecord *lineRec, **cellList = (DBObjRecord **) NULL;
	DBDataset *dataset = UIDataset ();
	DBObjData *netData = dataset->Data ();
	DBObjData *lineData = netData->LinkedData ();
	DBNetworkIF *netIF = new DBNetworkIF (netData);
	DBVLineIF *lineIF = new DBVLineIF (lineData);

	UIPauseDialogOpen ((char *) "Adjusting Networks");
	cellNum = 0;
	for (lineRec = lineIF->FirstItem ();lineRec != (DBObjRecord *) NULL; lineRec = lineIF->NextItem ())
		{
		UIPause (lineRec->RowID () * 100 / lineIF->ItemNum ());
		if (lineIF->ToNode (lineRec) == lineIF->FromNode (lineRec)) continue;
		if ((cellList = _RGISReallocCellList (cellList,maxCellNum,cellNum + 1)) == (DBObjRecord **) NULL) return;
		if ((cellList [cellNum] = netIF->Cell (lineIF->FromCoord (lineRec))) == (DBObjRecord *) NULL)
			if((cellList [cellNum] = netIF->CellAdd (lineIF->FromCoord (lineRec))) != (DBObjRecord *) NULL) cellNum++;
		if ((vertexNum = lineIF->VertexNum (lineRec)) > 0)
			{
			vertexes = lineIF->Vertexes (lineRec);
			for (vertex = 0; vertex < vertexNum; ++vertex)
				{
				if ((cellList = _RGISReallocCellList (cellList,maxCellNum,cellNum + 1)) == (DBObjRecord **) NULL) return;
				if ((cellList [cellNum] = netIF->Cell (vertexes [vertex])) == (DBObjRecord *) NULL)
					if((cellList [cellNum] = netIF->CellAdd (vertexes [vertex])) == (DBObjRecord *) NULL) continue;
				for (cell = 0;cell < cellNum;++cell) if (cellList [cell] == cellList [cellNum]) break;
				if (cell != cellNum) continue;
				cellNum++;
/*				if (cellNum > 1)
					{
					pos0 = netIF->CellPosition (cellList [cellNum - 2]);
					pos1 = netIF->CellPosition (cellList [cellNum - 1]);
					printf ("%5d   %3d %3d  %3d %3d\n",lineRec->RowID (),pos0.Col, pos0.Row, pos1.Col, pos1.Row);
					if ((abs (pos0.Row - pos1.Row) <= 1) && (abs (pos0.Col - pos1.Col) <= 1)) continue;
					if (abs (pos0.Row - pos1.Row) > abs (pos0.Col - pos1.Col))
						for (pos.Row = pos0.Row; pos.Row  != pos1.Row;
							  pos.Row = (pos0.Row < pos1.Row) ? pos.Row + 1 : pos.Row - 1)
							{
							pos.Col = pos0.Col + (DBUShort) ((((DBInt) pos.Row - (DBInt) pos0.Row) * ((DBInt) pos1.Col - (DBInt) pos0.Col)) / ((DBInt) pos1.Row - (DBInt) pos0.Row));
							if ((cellList = _RGISReallocCellList (cellList,maxCellNum,cellNum + 1)) == (DBObjRecord **) NULL) return;
							if ((cellRec = netIF->Cell (pos)) != (DBObjRecord *) NULL)
								{
								cellList [cellNum] = cellList [cellNum - 1];
								cellList [cellNum - 1] = cellRec;
								cellNum++;
								}
							}
					else
						for (pos.Col = pos0.Col; pos.Col != pos1.Col;
							  pos.Col = (pos0.Col < pos1.Col) ? pos.Col + 1 : pos.Col - 1)
							{
							pos.Row = pos0.Row + (DBUShort) ((((DBInt) pos.Col - (DBInt) pos0.Col) * ((DBInt) pos1.Row - (DBInt) pos0.Row)) / ((DBInt) pos1.Col - (DBInt) pos0.Col));
							if ((cellList = _RGISReallocCellList (cellList,maxCellNum,cellNum + 1)) == (DBObjRecord **) NULL) return;
							if ((cellRec = netIF->Cell (pos)) != (DBObjRecord *) NULL)
								{
								cellList [cellNum] = cellList [cellNum - 1];
								cellList [cellNum - 1] = cellRec;
								cellNum++;
								}
							}
					}
*/				}
			}
 		for (cell = 0;cell < cellNum - 1;++cell)
 			{
			pos0 = netIF->CellPosition (cellList [cell]);
			pos1 = netIF->CellPosition (cellList [cell + 1]);
			if ((pos0.Col <  pos1.Col) && (pos0.Row == pos1.Row))	dir = DBNetDirE;
			else if ((pos0.Col <  pos1.Col) && (pos0.Row >  pos1.Row))	dir = DBNetDirSE;
			else if ((pos0.Col == pos1.Col) && (pos0.Row >  pos1.Row))	dir = DBNetDirS;
			else if ((pos0.Col >  pos1.Col) && (pos0.Row >  pos1.Row))	dir = DBNetDirSW;
			else if ((pos0.Col >  pos1.Col) && (pos0.Row == pos1.Row))	dir = DBNetDirW;
			else if ((pos0.Col >  pos1.Col) && (pos0.Row <  pos1.Row))	dir = DBNetDirNW;
			else if ((pos0.Col == pos1.Col) && (pos0.Row <  pos1.Row))	dir = DBNetDirN;
			else if ((pos0.Col <  pos1.Col) && (pos0.Row <  pos1.Row))	dir = DBNetDirNE;
//			printf ("%5d   %3d %3d  %3d %3d  %2x\n",lineRec->RowID (),pos0.Col, pos0.Row, pos1.Col, pos1.Row,dir);
			netIF->CellDirection (cellList [cell],dir);
			}
		}
	if (maxCellNum > 0) free (cellList);
	UIPauseDialogClose ();
	UIPauseDialogOpen ((char *) "Building Networks");
//	netIF->Build ();
	UIPauseDialogClose ();
	}