From 562f0aa230716a042b675bc7aea682abdc98efb5 Mon Sep 17 00:00:00 2001
From: jsiegle <joshs@alleninstitute.org>
Date: Mon, 15 Sep 2014 15:32:35 -0700
Subject: [PATCH] Fix bug when removing processors with active DataViewport
 tabs

---
 Source/Processors/ProcessorGraph.cpp          |  1 +
 .../Visualization/LfpDisplayCanvas.cpp        | 24 ++++++++++---------
 Source/UI/DataViewport.cpp                    |  8 +++----
 Source/UI/EditorViewport.cpp                  |  3 +--
 4 files changed, 19 insertions(+), 17 deletions(-)

diff --git a/Source/Processors/ProcessorGraph.cpp b/Source/Processors/ProcessorGraph.cpp
index a805f9ae9..41243fe9b 100644
--- a/Source/Processors/ProcessorGraph.cpp
+++ b/Source/Processors/ProcessorGraph.cpp
@@ -668,6 +668,7 @@ void ProcessorGraph::removeProcessor(GenericProcessor* processor)
 
     std::cout << "Removing processor with ID " << processor->getNodeId() << std::endl;
 
+    disconnectNode(processor->getNodeId());
     removeNode(processor->getNodeId());
 
 }
diff --git a/Source/Processors/Visualization/LfpDisplayCanvas.cpp b/Source/Processors/Visualization/LfpDisplayCanvas.cpp
index 1e72d87d1..71aa143a4 100755
--- a/Source/Processors/Visualization/LfpDisplayCanvas.cpp
+++ b/Source/Processors/Visualization/LfpDisplayCanvas.cpp
@@ -90,6 +90,7 @@ LfpDisplayCanvas::LfpDisplayCanvas(LfpDisplayNode* processor_) :
 	spreads.add("40");
 	spreads.add("50");
 	spreads.add("60");
+	spreads.add("100");
 
 	colorGroupings.add("1");
 	colorGroupings.add("2");
@@ -345,22 +346,22 @@ void LfpDisplayCanvas::setParameter(int param, float val)
 
 void LfpDisplayCanvas:: setRangeSelection(float range)
 {
-			//rangeSelection->setItemEnabled(0,true); //keep custom range unavailable for direct selection
-			rangeSelection->setSelectedId(1,true);  // but show it for display
-			rangeSelection->changeItemText(1,String(int(range))); // and set to correct number
+	//rangeSelection->setItemEnabled(0,true); //keep custom range unavailable for direct selection
+	rangeSelection->setSelectedItemIndex(0, sendNotificationAsync);  // but show it for display
+	rangeSelection->changeItemText(1, String(int(range))); // and set to correct number
 
-			repaint();
-			refresh();
+	repaint();
+	refresh();
 			
 }
 
 void LfpDisplayCanvas:: setSpreadSelection(int spread)
 {
-			spreadSelection->setSelectedId(1,true);
-			spreadSelection->changeItemText(1,String(int(spread))); // and set to correct number
+	spreadSelection->setSelectedItemIndex(0, sendNotificationAsync);
+	spreadSelection->changeItemText(1, String(int(spread))); // and set to correct number
 
-			repaint();
-			refresh();
+	repaint();
+	refresh();
 			
 }
 
@@ -1151,12 +1152,13 @@ void LfpDisplay::mouseWheelMove(const MouseEvent&  e, const MouseWheelDetails&
 void LfpDisplay::toggleSingleChannel(int chan)
 {
 	std::cout << "Toggle channel " << chan << std::endl;
+
 	if (chan != singleChan)
 	{
 		singleChan = chan;
 		int newHeight = viewport->getHeight();
-		setChannelHeight(newHeight,false);
-		setSize(getWidth(),numChans*getChannelHeight());
+		setChannelHeight(newHeight-100, false);
+		setSize(getWidth(), numChans*getChannelHeight());
 		viewport->setScrollBarsShown(false,false);
 		//viewport->setViewPosition(Point<int>(0,chan*newHeight));
 		for (int n = 0; n < numChans; n++)
diff --git a/Source/UI/DataViewport.cpp b/Source/UI/DataViewport.cpp
index d0b0331af..63f6b2b1a 100755
--- a/Source/UI/DataViewport.cpp
+++ b/Source/UI/DataViewport.cpp
@@ -74,7 +74,7 @@ int DataViewport::addTabToDataViewport(String name, Component* component, Generi
 
     editorArray.add(editor);
 
-    //  std::cout << "Adding tab with index " << tabIndex << std::endl;
+    std::cout << "Adding tab with index " << tabIndex << std::endl;
 
     setCurrentTabIndex(tabArray.size()-1);
 
@@ -97,8 +97,8 @@ void DataViewport::destroyTab(int index)
     int newIndex = tabArray.indexOf(index);
 
     tabArray.remove(newIndex);
-    editorArray.remove(newIndex);
-
+    editorArray.remove(newIndex); // do this after the editor has been refreshed
+    
     removeTab(newIndex);
 
     if (tabArray.size() == 0)
@@ -127,7 +127,7 @@ void DataViewport::currentTabChanged(int newIndex, const String& newTabName)
 
     if (!shutdown)
     {
-        getEditorViewport()->makeEditorVisible(editorArray[newIndex]);
+        //getEditorViewport()->makeEditorVisible(editorArray[newIndex]);
         getTopLevelComponent()->repaint();
     }
 }
diff --git a/Source/UI/EditorViewport.cpp b/Source/UI/EditorViewport.cpp
index e7d0ecfba..1d8558345 100755
--- a/Source/UI/EditorViewport.cpp
+++ b/Source/UI/EditorViewport.cpp
@@ -349,6 +349,7 @@ void EditorViewport::deleteNode(GenericEditor* editor)
         editor->setVisible(false);
 
         signalChainManager->updateVisibleEditors(editor, indexOfMovingComponent, insertionPoint, REMOVE);
+        
         getGraphViewer()->removeNode(editor);
 
         refreshEditors();
@@ -360,8 +361,6 @@ void EditorViewport::deleteNode(GenericEditor* editor)
 
         somethingIsBeingDraggedOver = false;
 
-
-
         repaint();
 
     }
-- 
GitLab