예제 #1
0
static void HistoClickProc (PaneL pn, PoinT pt)
{
  VieweR    v;
  Uint2     segID, primID, primCt;
  SegmenT   s;
  PrimitivE p;
  GraphViewFormPtr gvp;
  SeqIntPtr sint;
  PntInfo   pnt;

  segID = 0;
  primID = 0;
  primCt = 0;

  v = (VieweR) pn;
  s = FindSegment (v, pt, &segID, &primID, &primCt);

  gvp = GetObjectExtra (v);
  if (primID < 1)
  {
    WatchCursor ();
    ExploreSegment (s, v, UnHLSeg);
    ObjMgrDeSelectAll ();
    ArrowCursor ();
  }
  else
  {
    WatchCursor ();
    ExploreSegment (s, v, UnHLSeg);
    ObjMgrDeSelectAll ();
    ArrowCursor ();
    p = GetPrimitive (s, primCt);
    HighlightPrimitive (v, s, p, FRAME_PRIMITIVE);
    gvp->slp = (SeqLocPtr) ValNodeNew (NULL);
    sint = SeqIntNew ();
    sint->id = SeqIdDup (gvp->bsp->id);
    if (primID == 1)
      sint->strand = Seq_strand_plus;
    else
      sint->strand = Seq_strand_minus;
    MapViewerToWorld (v, pt, &pnt);
    gvp->start = pnt.x * gvp->zoom;
    gvp->stop = gvp->start+gvp->window;
    sint->from = gvp->start;
    sint->to = gvp->stop;
    gvp->slp->choice = SEQLOC_INT;
    gvp->slp->data.ptrvalue = (Pointer) sint;
    ObjMgrSelect (gvp->entityID, gvp->itemID, OBJ_BIOSEQ, OM_REGION_SEQLOC,
                  gvp->slp);
  }
  return;
}
예제 #2
0
static Int2 LIBCALLBACK MatrixMsgFunc (OMMsgStructPtr ommsp)
{
  OMUserDataPtr         omudp;
  GraphViewFormPtr      gvp;
  SeqGraphPtr           sgp;
  VieweR                v;
  PoinT                 pt;
  PntInfo               pw;
  Uint2                 segID, primID, primCt;
  SegmenT               s;
  PrimitivE             p;
  Int4                  pos;
  FloatHi               maxVal;

  if ((omudp = (OMUserDataPtr) (ommsp->omuserdata)) == NULL)
    return OM_MSG_RET_ERROR;
  if ((gvp = (GraphViewFormPtr) (omudp->userdata.ptrvalue)) == NULL)
    return OM_MSG_RET_ERROR;

  switch (ommsp->message)
  {
   case OM_MSG_SELECT:
    if (ommsp->itemtype == OBJ_BIOSEQ)
    {
      if (ommsp->regiontype == OM_REGION_SEQLOC)
      {
        if ((sgp = gvp->sgp) == NULL)
          return OM_MSG_RET_ERROR;

        switch (sgp->flags[2])
        {
         default:
         case 1:
          maxVal = sgp->max.realvalue;
          break;
         case 2:
         case 3:
          maxVal = (FloatHi) sgp->max.intvalue;
          break;
        }

        if (gvp->slp != NULL)
        {
          v = gvp->viewer;
          pt.x = 0;
          pt.y = 0;
          s = FindSegment (v, pt, &segID, &primID, &primCt);
          ExploreSegment (s, v, UnHLSeg);
/*
          ObjMgrDeSelectAll ();
          gvp->slp = NULL;
*/
        }
        pos = SeqLocStart ((SeqLocPtr) ommsp->region);
        pos += SeqLocStop ((SeqLocPtr) ommsp->region);
        pos /= 2;
        pos /= gvp->zoom;
        pw.x = (Int2) pos;
        if (SeqLocStrand ((SeqLocPtr) ommsp->region) == Seq_strand_plus)
        {
          pw.y = (Int2) (gvp->margin + ((Int4) (1.0 +
                               (maxVal/2)) * sgp->a) +
                               (Int4) sgp->b);
        }
        else
        {
          pw.y = (Int2) (gvp->margin + ((Int4) (maxVal - 1.0 -
                               (maxVal/2)) * sgp->a) +
                               (Int4) sgp->b);
        }
        v = gvp->viewer;
        primID = 0;
        MapWorldToViewer (v, pw, &pt);
        s = FindSegment (v, pt, &segID, &primID, &primCt);
        if (primID < 1 || s == NULL)
          return OM_MSG_RET_ERROR;
        p = GetPrimitive (s, primCt);
        WatchCursor ();
        ExploreSegment (s, v, UnHLSeg);
        ArrowCursor ();
        HighlightPrimitive (v, s, p, FRAME_PRIMITIVE);
/* DUP/memcp and delta id
        gvp->slp = (Pointer) (ommsp->region);
*/
/*
        ObjMgrSelect (gvp->entityID, gvp->itemID, OBJ_BIOSEQ, OM_REGION_SEQLOC,
                      gvp->slp);
*/
      }
    }
    break;
   case OM_MSG_DESELECT:
    if (ommsp->itemtype == OBJ_BIOSEQ)
    {
      if (ommsp->regiontype == OM_REGION_SEQLOC)
      {
        if (gvp->slp != NULL)
        {
/*
          v = gvp->viewer;
          pt.x = 0;
          pt.y = 0;
          s = FindSegment (v, pt, &segID, &primID, &primCt);
          ExploreSegment (s, v, UnHLSeg);
          ObjMgrDeSelectAll ();
          gvp->slp = NULL;
*/
        }
      }
    }
    break;
   case OM_MSG_DEL:
   case OM_MSG_CREATE:
   case OM_MSG_UPDATE:
   case OM_MSG_CACHED:
   case OM_MSG_UNCACHED:
   case OM_MSG_TO_CLIPBOARD:
    break;
   default:
    break;
  }
  return OM_MSG_RET_OK;
}
예제 #3
0
static Int2 LIBCALLBACK FilterMsgFunc (OMMsgStructPtr ommsp)
{
  OMUserDataPtr         omudp;
  GraphViewFormPtr      gvp;
  SeqGraphPtr           sgp;
  VieweR                v;
  PoinT                 pt;
  PntInfo               pw;
  Uint2                 segID, primID, primCt, start, end, i;
  SegmenT               s;
  PrimitivE             p;
  FloatHi               fval;
  Int4                  pos;
  FloatHi               maxVal, minVal;

  if ((omudp = (OMUserDataPtr) (ommsp->omuserdata)) == NULL)
    return OM_MSG_RET_ERROR;
  if ((gvp = (GraphViewFormPtr) (omudp->userdata.ptrvalue)) == NULL)
    return OM_MSG_RET_ERROR;

  switch (ommsp->message)
  {
   case OM_MSG_SELECT:
    if (ommsp->itemtype == OBJ_BIOSEQ)
    {
      if (ommsp->regiontype == OM_REGION_SEQLOC)
      {
        if ((sgp = gvp->sgp) == NULL)
          return OM_MSG_RET_ERROR;

        switch (sgp->flags[2])
        {
         default:
         case 1:
          maxVal = sgp->max.realvalue;
          minVal = sgp->min.realvalue;
          break;
         case 2:
         case 3:
          maxVal = (FloatHi) sgp->max.intvalue;
          minVal = (FloatHi) sgp->min.intvalue;
          break;
        }

        if (gvp->slp != NULL)
        {
          v = gvp->viewer;
          pt.x = 0;
          pt.y = 0;
          s = FindSegment (v, pt, &segID, &primID, &primCt);
          ExploreSegment (s, v, UnHLSeg);
/*
          ObjMgrDeSelectAll ();
          gvp->slp = NULL;
*/
        }
        pos = SeqLocStart ((SeqLocPtr) ommsp->region);
        pos /= gvp->zoom;
        pw.x = (Int2) pos;
        v = gvp->viewer;
        primID = 0;
        fval = minVal - 1;
        while (primID < 1 && fval < maxVal)
        {
          fval++;
          pw.y = (Int2) (gvp->margin + ((Int4) (fval * sgp->a)) +
                         (Int4) sgp->b);
          MapWorldToViewer (v, pw, &pt);
          s = FindSegment (v, pt, &segID, &primID, &primCt);
        }
        if (primCt == 0 && fval == maxVal)
          return OM_MSG_RET_ERROR;
        if (s == NULL)
          return OM_MSG_RET_ERROR;
        start = primCt;

        pos = SeqLocStop ((SeqLocPtr) ommsp->region);
        pos /= gvp->zoom;
        pw.x = (Int2) pos;
        primID = 0;
        fval = minVal - 1;
        while (primID < 1 && fval < maxVal)
        {
          fval++;
          pw.y = (Int2) (gvp->margin + ((Int4) (fval * sgp->a)) +
                         (Int4) sgp->b);
          MapWorldToViewer (v, pw, &pt);
          s = FindSegment (v, pt, &segID, &primID, &primCt);
        }
        if (primCt == 0 || fval == maxVal)
          return OM_MSG_RET_ERROR;
        if (s == NULL)
          return OM_MSG_RET_ERROR;
        end = primCt;
        if (start > end)
          return OM_MSG_RET_ERROR;
        WatchCursor ();
        ExploreSegment (s, v, UnHLSeg);
        ArrowCursor ();
        for (i = start; i < end; i++)
        {
          p = GetPrimitive (s, i);
          HighlightPrimitive (v, s, p, FRAME_PRIMITIVE);
        }
/* DUP/memcp and delta id
        gvp->slp = (Pointer) (ommsp->region);
*/
/*
        ObjMgrSelect (gvp->entityID, gvp->itemID, OBJ_BIOSEQ, OM_REGION_SEQLOC,
                      gvp->slp);
*/
      }
    }
    break;
   case OM_MSG_DESELECT:
    if (ommsp->itemtype == OBJ_BIOSEQ)
    {
      if (ommsp->regiontype == OM_REGION_SEQLOC)
      {
        if (gvp->slp != NULL)
        {
/*
          v = gvp->viewer;
          pt.x = 0;
          pt.y = 0;
          s = FindSegment (v, pt, &segID, &primID, &primCt);
          ExploreSegment (s, v, UnHLSeg);
          ObjMgrDeSelectAll ();
          gvp->slp = NULL;
*/
        }
      }
    }
    break;
   case OM_MSG_DEL:
   case OM_MSG_CREATE:
   case OM_MSG_UPDATE:
   case OM_MSG_CACHED:
   case OM_MSG_UNCACHED:
   case OM_MSG_TO_CLIPBOARD:
    break;
   default:
    break;
  }
  return OM_MSG_RET_OK;
}
예제 #4
0
/**
 * Updates blocks in _globset buffer
 *
 * @param owner company whose signals we are updating
 * @return state of the first block from _globset
 * @pre Company::IsValidID(owner)
 */
static SigSegState UpdateSignalsInBuffer(Owner owner)
{
	assert(Company::IsValidID(owner));

	bool first = true;  // first block?
	SigSegState state = SIGSEG_FREE; // value to return

	TileIndex tile;
	DiagDirection dir;

	while (_globset.Get(&tile, &dir)) {
		assert(_tbuset.IsEmpty());
		assert(_tbdset.IsEmpty());

		/* After updating signal, data stored are always MP_RAILWAY with signals.
		 * Other situations happen when data are from outside functions -
		 * modification of railbits (including both rail building and removal),
		 * train entering/leaving block, train leaving depot...
		 */
		switch (GetTileType(tile)) {
			case MP_TUNNELBRIDGE:
				/* 'optimization assert' - do not try to update signals when it is not needed */
				assert(GetTunnelBridgeTransportType(tile) == TRANSPORT_RAIL);
				assert(dir == INVALID_DIAGDIR || dir == ReverseDiagDir(GetTunnelBridgeDirection(tile)));
				_tbdset.Add(tile, INVALID_DIAGDIR);  // we can safely start from wormhole centre
				_tbdset.Add(GetOtherTunnelBridgeEnd(tile), INVALID_DIAGDIR);
				break;

			case MP_RAILWAY:
				if (IsRailDepot(tile)) {
					/* 'optimization assert' do not try to update signals in other cases */
					assert(dir == INVALID_DIAGDIR || dir == GetRailDepotDirection(tile));
					_tbdset.Add(tile, INVALID_DIAGDIR); // start from depot inside
					break;
				}
				/* FALL THROUGH */
			case MP_STATION:
			case MP_ROAD:
				if ((TrackStatusToTrackBits(GetTileTrackStatus(tile, TRANSPORT_RAIL, 0)) & _enterdir_to_trackbits[dir]) != TRACK_BIT_NONE) {
					/* only add to set when there is some 'interesting' track */
					_tbdset.Add(tile, dir);
					_tbdset.Add(tile + TileOffsByDiagDir(dir), ReverseDiagDir(dir));
					break;
				}
				/* FALL THROUGH */
			default:
				/* jump to next tile */
				tile = tile + TileOffsByDiagDir(dir);
				dir = ReverseDiagDir(dir);
				if ((TrackStatusToTrackBits(GetTileTrackStatus(tile, TRANSPORT_RAIL, 0)) & _enterdir_to_trackbits[dir]) != TRACK_BIT_NONE) {
					_tbdset.Add(tile, dir);
					break;
				}
				/* happens when removing a rail that wasn't connected at one or both sides */
				continue; // continue the while() loop
		}

		assert(!_tbdset.Overflowed()); // it really shouldn't overflow by these one or two items
		assert(!_tbdset.IsEmpty()); // it wouldn't hurt anyone, but shouldn't happen too

		SigFlags flags = ExploreSegment(owner);

		if (first) {
			first = false;
			/* SIGSEG_FREE is set by default */
			if (flags & SF_PBS) {
				state = SIGSEG_PBS;
			} else if ((flags & SF_TRAIN) || ((flags & SF_EXIT) && !(flags & SF_GREEN)) || (flags & SF_FULL)) {
				state = SIGSEG_FULL;
			}
		}

		/* do not do anything when some buffer was full */
		if (flags & SF_FULL) {
			ResetSets(); // free all sets
			break;
		}

		UpdateSignalsAroundSegment(flags);
	}

	return state;
}
예제 #5
0
static void GraphClickProc (PaneL pn, PoinT pt)
{
  VieweR    v;
  Uint2     segID, primID, primCt, start, end, i;
  SegmenT   s;
  PrimitivE p;
  GraphViewFormPtr gvp;
  SeqIntPtr sint;
  PntInfo   pnt;

  segID = 0;
  primID = 0;
  primCt = 0;

  v = (VieweR) pn;
  s = FindSegment (v, pt, &segID, &primID, &primCt);
  p = GetPrimitive (s, primCt);
  if (primID == 0)
    return;

  gvp = GetObjectExtra (v);
  if (gvp->flagNewClick)
  {
    WatchCursor ();
    ExploreSegment (s, v, UnHLSeg);
    ArrowCursor ();
    HighlightPrimitive (v, s, p, FRAME_PRIMITIVE);
    gvp->flagNewClick = FALSE;
    gvp->HLRange = primCt;
    MapViewerToWorld (v, pt, &pnt);
    gvp->start = pnt.x * gvp->zoom;
  }
  else
  {
    start = gvp->HLRange;
    if (start < primCt)
      end = (Uint2) (primCt + 1);
    else
    {
      start = primCt;
      end = (Uint2) (gvp->HLRange + 1);
    }
    for (i = start; i < end; i++)
    {
      p = GetPrimitive (s, i);
      HighlightPrimitive (v, s, p, FRAME_PRIMITIVE);
    }
    if (gvp->slp != NULL)
    {
      ObjMgrDeSelect (gvp->entityID, gvp->itemID, OBJ_BIOSEQ, OM_REGION_SEQLOC,
                      gvp->slp);
/*      gvp->slp = SeqLocFree (gvp->slp); */
      gvp->slp = NULL;
    }
    gvp->slp = (SeqLocPtr) ValNodeNew (NULL);
    sint = SeqIntNew ();
    sint->id = SeqIdDup (gvp->bsp->id);
    sint->strand = Seq_strand_plus;
    MapViewerToWorld (v, pt, &pnt);
    gvp->stop = pnt.x * gvp->zoom;
    if (gvp->start < gvp->stop)
    {
      sint->from = gvp->start;
      sint->to = gvp->stop;
    }
    else
    {
      sint->from = gvp->stop;
      sint->to = gvp->start;
    }
    gvp->slp->choice = SEQLOC_INT;
    gvp->slp->data.ptrvalue = (Pointer) sint;
    ObjMgrSelect (gvp->entityID, gvp->itemID, OBJ_BIOSEQ, OM_REGION_SEQLOC,
                  gvp->slp);
/* ObjMgrAlsoSelect for loop thru slp's */
/* have to clone each slp added to chain and pass clone to OM */
    gvp->flagNewClick = TRUE;
  }
  return;
}