af3cab9b22449e7db6b9367ee2416dc2b3d39a3e
tdreszer
  Fri Nov 5 12:26:52 2010 -0700
Fixed bug 32 in 1071. Repeated vis changes in track search had unpredictable consequences.
diff --git src/hg/hgTracks/hgTracks.c src/hg/hgTracks/hgTracks.c
index e53a98d..e7afbb5 100644
--- src/hg/hgTracks/hgTracks.c
+++ src/hg/hgTracks/hgTracks.c
@@ -1562,77 +1562,86 @@
 {
 #ifdef SUBTRACKS_HAVE_VIS
 if (tdbIsCompositeChild(subtrack->tdb))
     {
     if (fourStateVisible(subtrackFourStateChecked(subtrack->tdb,cart))) // Don't need all 4 states here.  Visible=checked&&enabled
         {
         char *var = cartOptionalString(cart, subtrack->track);
         if (var)
             {
             subtrack->visibility = hTvFromString(var);
 
             if (subtrack->limitedVisSet)
                 subtrack->limitedVis = tvMin(subtrack->visibility,subtrack->limitedVis);
             else
                 {
-                #ifdef OMIT
+                //#ifdef OMIT
                 // Not sure this is needed at all!  OMITting because of the recursive loop that wigMafs fell into on rightClick
                 if (subtrack->visibility != tvHide && slCount(subtrack->items) == 0)
                     {
                     // wigMaf legitimately has no items even after loadItems, as it triggers a loop to ->loadItems() !
                     // Really should protect against infinite loops better than this!
                     if (!startsWith("wigMaf", subtrack->tdb->type) && !startsWith("maf", subtrack->tdb->type))
                         {
                         subtrack->loadItems(subtrack);
                         }
                     }
-                #endif///def OMIT
+                //#endif///def OMIT
                 limitVisibility(subtrack);
                 }
             return hTvFromString(var);
             }
         }
     else
         return tvHide;
     }
 #endif///def SUBTRACKS_HAVE_VIS
 
 enum trackVisibility vis = subtrack->limitedVis == tvHide ?
                            subtrack->visibility :
                            tvMin(subtrack->visibility,subtrack->limitedVis);
 struct trackDb *tdb = subtrack->tdb;
 if(tdbIsCompositeChild(tdb))
     {
+    if (!subtrack->limitedVisSet)
+        {
+        subtrack->visibility = tdbVisLimitedByAncestors(cart, subtrack->tdb, TRUE, TRUE);
+        limitVisibility(subtrack);
+        return vis;
+        }
+    return subtrack->limitedVis;
+    /*
     struct trackDb *parentTdb = tdbGetComposite(tdb);
     assert(parentTdb != NULL);
 
     char *viewName = NULL;
     if (subgroupFind(tdb,"view",&viewName))
 	{
         int len = strlen(parentTdb->track) + strlen(viewName) + 10;
 
 	// Create the view dropdown var name.  This needs to have the view name surrounded by dots
 	// in the middle for the javascript to work.
 	char ddName[len];
         safef(ddName,len,"%s.%s.vis", parentTdb->track,viewName);
         char * fromParent = cartOptionalString(cart, ddName);
         if(fromParent)
             vis = tvMin(vis,hTvFromString(fromParent));
         else
             vis = tvMin(vis,visCompositeViewDefault(parentTdb,viewName));
         subgroupFree(&viewName);
 	}
+    */
     }
 return vis;
 }
 
 static int makeRulerZoomBoxes(struct hvGfx *hvg, struct cart *cart, int winStart,int winEnd,
 	int insideWidth,int seqBaseCount,int rulerClickY,int rulerClickHeight)
 /* Make hit boxes that will zoom program around ruler. */
 {
 int boxes = 30;
 int winWidth = winEnd - winStart;
 int newWinWidth = winWidth;
 int i, ws, we = 0, ps, pe = 0;
 int mid, ns, ne;
 double wScale = (double)winWidth/boxes;
 double pScale = (double)insideWidth/boxes;
@@ -4281,39 +4290,39 @@
 else
     warn("Unrecognized jsCommand %s", command);
 }
 
 #ifdef SUBTRACKS_HAVE_VIS
 void parentChildCartCleanup(struct track *trackList,struct cart *newCart,struct hash *oldVars)
 /* When composite/view settings changes, remove subtrack specific vis
    When superTrackChild is found and selected, shape superTrack to match. */
 {
 struct track *track = trackList;
 for (;track != NULL; track = track->next)
     {
     boolean shapedByubtrackOverride = FALSE;
     boolean cleanedByContainerSettings = FALSE;
 
+    cleanedByContainerSettings = cartTdbTreeCleanupOverrides(track->tdb,newCart,oldVars);
+
     if (tdbIsContainer(track->tdb))
         {
         shapedByubtrackOverride = cartTdbTreeMatchSubtrackVis(cart,track->tdb);
         if(shapedByubtrackOverride)
             track->visibility = tdbVisLimitedByAncestors(cart,track->tdb,TRUE,TRUE);
         }
 
-    cleanedByContainerSettings = cartTdbTreeCleanupOverrides(track->tdb,newCart,oldVars);
-
     if ((shapedByubtrackOverride || cleanedByContainerSettings) && tdbIsSuperTrackChild(track->tdb))  // Either cleanup may require supertrack intervention
         { // Need to update track visibility
         // Unfortunately, since supertracks are not in trackList, this occurs on superChildren,
         // So now we need to find the supertrack and take changed cart values of its children
         struct slRef *childRef;
         for(childRef = track->tdb->parent->children;childRef != NULL;childRef = childRef->next)
             {
             struct trackDb * childTdb = childRef->val;
             struct track *child = hashFindVal(trackHash, childTdb->track);
             char *cartVis = cartOptionalString(cart,child->track);
             if (cartVis)
                 child->visibility = hTvFromString(cartVis);
             }
         }
     }
@@ -4373,30 +4382,31 @@
 if (measureTiming)
     uglyTime("getTrackList");
 #endif /* SOON */
 
 // honor defaultImgOrder
 if(cgiVarExists("hgt.defaultImgOrder"))
     {
     char wildCard[32];
     safef(wildCard,sizeof(wildCard),"*_%s",IMG_ORDER_VAR);
     cartRemoveLike(cart, wildCard);
     }
 #ifdef SUBTRACKS_HAVE_VIS
 parentChildCartCleanup(trackList,cart,oldVars); // Subtrack settings must be removed when composite/view settings are updated
 #endif///def SUBTRACKS_HAVE_VIS
 
+
 /* Honor hideAll and visAll variables */
 if (hideAll || defaultTracks)
     {
     int vis = (hideAll ? tvHide : -1);
     changeTrackVis(groupList, NULL, vis);
     }
 
 /* Before loading items, deal with the next/prev item arrow buttons if pressed. */
 if (cgiVarExists("hgt.nextItem"))
     doNextPrevItem(TRUE, cgiUsualString("hgt.nextItem", NULL));
 else if (cgiVarExists("hgt.prevItem"))
     doNextPrevItem(FALSE, cgiUsualString("hgt.prevItem", NULL));
 
 if(advancedJavascriptFeaturesEnabled(cart) && !psOutput && !cgiVarExists("hgt.imageV1"))
     {