Index: sansview/perspectives/fitting/fitpage.py
===================================================================
--- sansview/perspectives/fitting/fitpage.py	(revision 3b9e0231871991c172eecf17561c194a02ec66db)
+++ sansview/perspectives/fitting/fitpage.py	(revision 077809cc34f294ac6bdd73e60f59f5494154c970)
@@ -552,5 +552,5 @@
         self.state.structurecombobox = self.structurebox.GetCurrentSelection()
         self.state.formfactorcombobox = self.formfactorbox.GetCurrentSelection()
-        #print "_on_select_model",self.state.structurecombobox,self.state.formfactorcombobox 
+      
        
         if event !=None:
@@ -586,4 +586,5 @@
             temp_smearer= self.smearer   
          ##Calculate chi2
+       
         self.compute_chisqr(smearer= temp_smearer)  
         ## new state posted
@@ -606,4 +607,5 @@
             if self.enable_smearer.GetValue():
                 temp_smearer= self.smearer
+            
             self.compute_chisqr(smearer= temp_smearer)
             ## new state posted
@@ -793,4 +795,6 @@
         """
         try:
+            if output ==None:
+                output= "-"
             self.tcChi.SetLabel(str(output))
            
@@ -825,7 +829,5 @@
                 self.calc_Chisqr.stop()
                 
-            self.calc_Chisqr= CalcChisqr1D( x= self.data.x,
-                                            y= self.data.y,
-                                            dy= self.data.dy,
+            self.calc_Chisqr= CalcChisqr1D( data1d= self.data,
                                             model= self.model,
                                             smearer=smearer,
@@ -864,8 +866,5 @@
                 self.calc_Chisqr.stop()
            
-            self.calc_Chisqr= CalcChisqr2D( x_bins= self.data.x_bins,
-                                            y_bins= self.data.y_bins,
-                                            data= self.data.data,
-                                            err_data = self.data.err_data,
+            self.calc_Chisqr= CalcChisqr2D( data2d= self.data,
                                             model= self.model,
                                             qmin= self.qmin_x,
@@ -877,6 +876,5 @@
           
         except:
-            raise ValueError," Could not compute Chisqr for %s Model 2D: "%self.model.name
-           
+           raise
 
         
@@ -897,5 +895,5 @@
                     return
             except:
-                wx.PostEvent(self.parent.GrandParent, StatusEvent(status=\
+                wx.PostEvent(self.parent.parent, StatusEvent(status=\
                             "Chisqr Error: %s"% sys.exc_value))
                 return 
Index: sansview/perspectives/fitting/gui_thread.py
===================================================================
--- sansview/perspectives/fitting/gui_thread.py	(revision e733619fb1f7796ab0bfac7eb996599f5f3a7a0e)
+++ sansview/perspectives/fitting/gui_thread.py	(revision 077809cc34f294ac6bdd73e60f59f5494154c970)
@@ -9,4 +9,6 @@
 
 from data_util.calcthread import CalcThread
+from sans.fit.AbstractFitEngine import FitData2D, FitData1D, SansAssembly
+
 
 class CalcChisqr1D(CalcThread):
@@ -14,5 +16,5 @@
        Compute chisqr
     """
-    def __init__(self, x, y,dy, model,
+    def __init__(self, data1d, model,
                  smearer=None,
                  qmin=None,
@@ -27,12 +29,16 @@
                  yieldtime,
                  worktime)
-        self.smearer =smearer
-        self.y = numpy.array(y)
-        self.x = numpy.array(x)
-        self.dy= copy.deepcopy(dy)
+        
+        if model ==None or data1d ==None:
+            raise ValueError, "Need data and model to compute chisqr"
+        
+        if data1d.__class__.__name__ !="Data1D":
+            msg= str(data1d.__class__.__name__)
+            raise ValueError, "need Data1D to compute chisqr. Current class %s"%msg
+        
+        self.fitdata= FitData1D(data1d, smearer=smearer)
+        self.fitdata.setFitRange(qmin=qmin,qmax=qmax)
         self.model = model
-        self.qmin = qmin
-        self.qmax = qmax
-        self.smearer = smearer
+       
         self.starttime = 0  
         
@@ -53,40 +59,8 @@
         self.starttime = time.time()
        
-        x,y = [numpy.asarray(v) for v in (self.x,self.y)]
-        if self.dy==None or self.dy==[]:
-            self.dy= numpy.zeros(len(self.y))
-        self.dy[self.dy==0]=1
-        
-        if self.qmin==0.0 and not numpy.isfinite(self.y[self.qmin]):
-            self.qmin = min(self.x[sel.x!=0])      
-        elif self.qmin==None:
-            self.qmin= min(self.x)
-        
-        if self.qmax==None:
-            self.qmax= max(self.x)
-            
-        fx = numpy.zeros(len(self.x)) 
-        
         output= None
         res=[]
-        try: 
-            
-            for i_x in range(len(self.x)):
-               
-                # Check whether we need to bail out
-                self.isquit()  
-               
-                fx[i_x]=self.model.run(self.x[i_x])
-                
-            if self.smearer!=None:
-                fx= self.smearer(fx)
-                
-            for i_y in range(len(fx)):
-                # Check whether we need to bail out
-                self.isquit()   
-               
-                temp=(self.y[i_y] - fx[i_y])/self.dy[i_y]
-                res.append(temp*temp)
-            #sum of residuals
+        try:
+            res = self.fitdata.residuals(self.model.run)
             sum=0
             for item in res:
@@ -94,6 +68,8 @@
                 self.isquit()  
                 if numpy.isfinite(item):
-                    sum +=item
-            output = sum/ len(res)
+                    sum +=item*item
+            if len(res)>0:
+                output = sum/ len(res)
+            
             elapsed = time.time()-self.starttime
             self.complete(output= output,  elapsed=elapsed)
@@ -103,5 +79,5 @@
             # Real code should not print, but this is an example...
             raise
-        except:
+        except: 
             raise
         
@@ -111,5 +87,5 @@
     """
     
-    def __init__(self, x_bins, y_bins,data,err_data, model,
+    def __init__(self,data2d, model,
                  qmin,
                  qmax,
@@ -123,12 +99,16 @@
                  yieldtime,
                  worktime)
-      
-        self.y_bins = y_bins
-        self.x_bins = x_bins
-        self.data= data
-        self.err_data= copy.deepcopy(err_data)
+        
+        if model ==None or data2d ==None:
+            raise ValueError, "Need data and model to compute chisqr"
+        
+        if data2d.__class__.__name__ !="Data2D":
+            msg= str(data2d.__class__.__name__)
+            raise ValueError, "need Data2D to compute chisqr. Current class %s"%msg
+        
+        self.fitdata = FitData2D(data2d)
+        self.fitdata.setFitRange(qmin=qmin,qmax=qmax)
+     
         self.model = model
-        self.qmin = qmin
-        self.qmax = qmax
       
         self.starttime = 0  
@@ -149,31 +129,9 @@
         """
         self.starttime = time.time()
-        if self.model ==None:
-            return
-        if self.data==None:
-            return
-        if self.err_data==None or self.err_data==[]:
-            self.err_data= numpy.zeros(len(self.x_bins),len(self.y_bins))
-            
-        self.err_data[self.err_data==0]=1
-            
+       
         output= None
         res=[]
         try:
-          
-            for i in range(len(self.x_bins)):
-                # Check whether we need to bail out
-                self.isquit()   
-                for j in range(len(self.y_bins)):
-                    #Check the range containing data between self.qmin_x and self.qmax_x
-                    value =  math.pow(self.x_bins[i],2)+ math.pow(self.y_bins[j],2)
-                    if value >= math.pow(self.qmin,2) and value <= math.pow(self.qmax,2):
-                        
-                        temp = [self.x_bins[i],self.y_bins[j]]
-                        error= self.err_data[j][i]
-                        chisqrji = (self.data[j][i]- self.model.runXY(temp ))/error
-                        #Vector containing residuals
-                        res.append( math.pow(chisqrji,2) )
- 
+            res = self.fitdata.residuals(self.model.run)
             sum=0
             for item in res:
@@ -181,6 +139,8 @@
                 self.isquit()  
                 if numpy.isfinite(item):
-                    sum +=item
-            output = sum/ len(res)
+                    sum +=item*item
+            if len(res)>0:
+                output = sum/ len(res)
+            
             elapsed = time.time()-self.starttime
             self.complete(output= output,  elapsed=elapsed)
@@ -190,2 +150,4 @@
             # Real code should not print, but this is an example...
             raise
+        except: 
+            raise
