src/hg/hgTracks/imageV2.c 1.10

1.10 2009/09/14 15:22:35 tdreszer
Added imgTrackAddMapItem to let the imgTrack divide map items between slices.
Index: src/hg/hgTracks/imageV2.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/hgTracks/imageV2.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -b -B -U 4 -r1.9 -r1.10
--- src/hg/hgTracks/imageV2.c	4 Sep 2009 18:25:50 -0000	1.9
+++ src/hg/hgTracks/imageV2.c	14 Sep 2009 15:22:35 -0000	1.10
@@ -10,9 +10,9 @@
 static char const rcsid[] = "$Id$";
 
 struct imgBox   *theImgBox   = NULL; // Make this global for now to avoid huge rewrite
 //struct image    *theOneImg   = NULL; // Make this global for now to avoid huge rewrite
-//struct imgTrack *curImgTrack = NULL; // Make this global for now to avoid huge rewrite
+struct imgTrack *curImgTrack = NULL; // Make this global for now to avoid huge rewrite
 //struct imgSlice *curSlice    = NULL; // Make this global for now to avoid huge rewrite
 struct mapSet   *curMap      = NULL; // Make this global for now to avoid huge rewrite
 //struct mapItem  *curMapItem  = NULL; // Make this global for now to avoid huge rewrite
 
@@ -286,9 +286,9 @@
 return slice->map;
 }
 
 struct mapSet *sliceGetMap(struct imgSlice *slice,boolean sliceSpecific)
-/* Gets the map associate with a slice which male be sliceSpecific or it map belong to the slices' image.
+/* Gets the map associate with a slice which may be sliceSpecific or it map belong to the slices' image.
    Map items can then be added to the map returned with mapSetItemAdd() */
 {
 if(!sliceSpecific && slice->map == NULL && slice->parentImg != NULL)
         return slice->parentImg->map;
@@ -512,8 +512,47 @@
     return NULL;
 return sliceGetMap(slice,FALSE); // Map could belong to image or could be slice specific
 }
 
+int imgTrackAddMapItem(struct imgTrack *imgTrack,char *link,char *title,int topLeftX,int topLeftY,int bottomRightX,int bottomRightY)
+/* Will add a map item it an imgTrack's appropriate slice's map
+   Since a map item may span slices, the imgTrack is in the best position to determine where to put the map item
+   returns count of map items added, which could be 0, 1 or more than one if item spans slices */
+{
+struct imgSlice *slice;
+char *imgFile = NULL;               // name of file that hold the image
+
+int count = 0;
+for(slice = imgTrack->slices;slice != NULL;slice=slice->next)
+    {
+    if(imgFile == NULL)
+        imgFile = slice->parentImg->file;
+    else if(differentString(imgFile,slice->parentImg->file))
+        {
+        char * name = (imgTrack->name != NULL ? imgTrack->name : imgTrack->tdb != NULL ? imgTrack->tdb->tableName : imgFile);
+        warn("imgTrackAddMapItem(%s) called, but not all slice images are the same for this track.",name);
+        }
+    if(topLeftX     < (slice->offsetX + slice->width)
+    && bottomRightX >= slice->offsetX
+    && topLeftY     < (slice->offsetY + slice->height)
+    && bottomRightY >= slice->offsetY ) // some overlap
+        {
+        struct mapSet *map = sliceGetMap(slice,FALSE);
+        if(map!=NULL)
+            {
+            mapSetItemAdd(map,link,title,max(topLeftX,slice->offsetX),max(topLeftY,slice->offsetY),min(bottomRightX,slice->offsetX + slice->width),min(bottomRightY,slice->offsetY + slice->height));
+            count++;
+            }
+        }
+    }
+//if(count>=2)
+//    {
+//    char * name = (imgTrack->name != NULL ? imgTrack->name : imgTrack->tdb != NULL ? imgTrack->tdb->tableName : imgFile);
+//    warn("imgTrackAddMapItem(%s) called for map items stretching across %d slice(s).",name,count);
+//    }
+return count;
+}
+
 boolean imgTrackIsComplete(struct imgTrack *imgTrack,boolean verbose)
 /* Tests the completeness and consistency of this imgTrack (including slices) */
 {
 if (imgTrack == NULL)