Index: fittingview/src/sans/perspectives/fitting/fitpage.py
===================================================================
--- fittingview/src/sans/perspectives/fitting/fitpage.py	(revision bc0e08ddcc753eb40fe1784f2853586993187fe7)
+++ fittingview/src/sans/perspectives/fitting/fitpage.py	(revision 6ff97c5f09af745f7b13f49a990b8f1ad05b6680)
@@ -12,5 +12,7 @@
 from sans.guiframe.events import StatusEvent 
 from sans.guiframe.events import NewPlotEvent  
-from sans.guiframe.utils import format_number,check_float
+from sans.guiframe.dataFitting import check_data_validity
+from sans.guiframe.utils import format_number
+from sans.guiframe.utils import check_float
 
 (Chi2UpdateEvent, EVT_CHI2_UPDATE)   = wx.lib.newevent.NewEvent()
@@ -60,7 +62,14 @@
         self._set_paste_flag(False)
         self.btFit.SetFocus()
+        self.enable_fit_button()
         self.fill_data_combobox(data_list=self.data_list)
     
-    
+    def enable_fit_button(self):
+        """
+        Enable fit button if data is valid and model is valid
+        """
+        flag = check_data_validity(self.data) & (self.model is not None)
+        self.btFit.Enable(flag)
+        
     def _fill_data_sizer(self):
         """
@@ -98,4 +107,5 @@
         self.enable_datasource()
         if data_list:
+            #find the maximum range covering all data
             qmin, qmax, npts = self.compute_data_range(data_list[0])
             self.qmin_data_set, self.qmax_data_set = qmin, qmax
@@ -105,6 +115,4 @@
                 self.compute_data_set_range(data)
                 self.dataSource.Append(str(data.name), clientData=data)
-                
-        print "fill_data_combox", self.qmin_data_set, self.qmax_data_set
         self.dataSource.SetSelection(0)
         self.on_select_data(event=None)
@@ -1013,5 +1021,5 @@
         self.qmax_x = float(self.qmax.GetValue())
         self._manager._reset_schedule_problem(value=0, uid=self.uid)
-        self._manager.schedule_for_fit(uid=self.uid,value=1, fitproblem=None) 
+        self._manager.schedule_for_fit(uid=self.uid,value=1) 
         self._manager.set_fit_range(uid=self.uid,qmin=self.qmin_x, 
                                    qmax=self.qmax_x)
@@ -1060,4 +1068,11 @@
         self._on_fit_complete()
          
+    def rename_model(self):
+        """
+        find a short name for model
+        """
+        if self.model is not None:
+            self.model.name = "M" + str(self.index_model)
+    
     def _on_select_model(self, event=None): 
         """
@@ -1086,6 +1101,7 @@
         self.state.structurecombobox = self.structurebox.GetCurrentSelection()
         self.state.formfactorcombobox = self.formfactorbox.GetCurrentSelection()
-      
+        self.enable_fit_button()
         if self.model != None:
+            self.rename_model()
             self._set_copy_flag(True)
             self._set_paste_flag(True)
@@ -1100,5 +1116,5 @@
                 self.onSmear(None)
                 temp_smear = None
-                if self.enable_smearer.GetValue():
+                if not self.disable_smearer.GetValue():
                     # Set the smearer environments
                     temp_smear = self.smearer
@@ -1114,6 +1130,8 @@
             evt = ModelEventbox(model=self.model, 
                                         smearer=temp_smear, 
+                             enable_smearer=not self.disable_smearer.GetValue(),
                                         qmin=float(self.qmin_x),
                                         uid=self.uid,
+                                        caption=self.window_caption,
                                      qmax=float(self.qmax_x)) 
    
@@ -1185,8 +1203,9 @@
                         not self.enable2D:
                     self._manager.set_smearer(smearer=temp_smearer, 
-                                              enable2D=self.enable2D,
+                                              fid=self.data.id,
                                               uid=self.uid,
                                              qmin= float(self.qmin_x),
                                             qmax= float(self.qmax_x),
+                            enable_smearer=not self.disable_smearer.GetValue(),
                                             draw=True) 
                 if flag:   
@@ -1248,7 +1267,5 @@
         Check validity of value enter in the Q range field
         """
-        #if self.check_invalid_panel():
-        #    return
-        tcrtl= event.GetEventObject()
+        tcrtl = event.GetEventObject()
         #Clear msg if previously shown.
         msg= ""
@@ -1282,32 +1299,31 @@
             #Check if # of points for theory model are valid(>0).
             # check for 2d
-            if self.data is not None:
-                if self.data.__class__.__name__ == "Data2D" or \
-                        self.enable2D:
-                    # set mask   
-                    radius= numpy.sqrt( self.data.qx_data*self.data.qx_data + 
-                                        self.data.qy_data*self.data.qy_data )
-                    index_data = ((self.qmin_x <= radius)& \
-                                    (radius<= self.qmax_x))
-                    index_data = (index_data)&(self.data.mask)
-                    index_data = (index_data)&(numpy.isfinite(self.data.data))
-                    if len(index_data[index_data]) < 10:
-                        msg = "Cannot Plot :No or too little npts in"
-                        msg += " that data range!!!  "
-                        wx.PostEvent(self.parent.parent, 
-                                     StatusEvent(status=msg))
-                        return
-                    else:
-                        self.data.mask = index_data
-                        #self.Npts_fit.SetValue(str(len(self.data.mask)))
-                        self.set_npts2fit() 
+            if self.data.__class__.__name__ == "Data2D" or \
+                    self.enable2D:
+                # set mask   
+                radius= numpy.sqrt(self.data.qx_data*self.data.qx_data + 
+                                    self.data.qy_data*self.data.qy_data )
+                index_data = ((self.qmin_x <= radius)& \
+                                (radius<= self.qmax_x))
+                index_data = (index_data)&(self.data.mask)
+                index_data = (index_data)&(numpy.isfinite(self.data.data))
+                if len(index_data[index_data]) < 10:
+                    msg = "Cannot Plot :No or too little npts in"
+                    msg += " that data range!!!  "
+                    wx.PostEvent(self.parent.parent, 
+                                 StatusEvent(status=msg))
+                    return
                 else:
-                    index_data = ((self.qmin_x <= self.data.x)& \
-                                  (self.data.x <= self.qmax_x))
-                    self.Npts_fit.SetValue(str(len(self.data.x[index_data])))
+                    self.data.mask = index_data
+                    #self.Npts_fit.SetValue(str(len(self.data.mask)))
+                    self.set_npts2fit() 
             else:
-                self.npts_x = self.Npts_total.GetValue()
-                self._save_plotting_range()
-
+                index_data = ((self.qmin_x <= self.data.x)& \
+                              (self.data.x <= self.qmax_x))
+                self.Npts_fit.SetValue(str(len(self.data.x[index_data])))
+            
+            self.npts_x = self.Npts_total.GetValue()
+            self.create_default_data()
+            self._save_plotting_range()
         else:
            tcrtl.SetBackgroundColour("pink")
@@ -1316,7 +1332,4 @@
         
         self._draw_model()
-        ##update chi2
-        #self.compute_chisqr(smearer= temp_smearer)
-        #self._undo.Enable(True)
         self.save_current_state()
         event = PageInfoEvent(page = self)
@@ -1673,5 +1686,4 @@
                 qmax = math.sqrt(x*x + y*y)
                 npts = len(data.data)
-        print "compute single data range", qmin, qmax
         return qmin, qmax, npts
             
@@ -1684,12 +1696,15 @@
         group_id = None
         flag = False
+        if self.data is not None:
+            group_id = self.data.group_id
+           
         if self.data is None and data is not None:
-            flag = True
+                flag = True
         if data is not None:
             id = data.id
-            group_id = data.group_id
             if self.data is not None:
                 flag = (data.id != self.data.id)
         self.data = data
+        self.data.group_id = group_id
         if self.data is None:
             data_min = ""
@@ -1703,4 +1718,5 @@
                 self._set_bookmark_flag(True)
                 self._keep.Enable(True)
+                
             self._set_save_flag(True)
             self._set_preview_flag(True)
@@ -1756,5 +1772,5 @@
         self.state.qmin = self.qmin_x
         self.state.qmax = self.qmax_x
-        
+        self.enable_fit_button()
         #update model plot with new data information
         if flag:
@@ -1766,7 +1782,5 @@
                 self.enable2D = False
                 self.model_view.SetLabel("1D Mode")
-                
             self.model_view.Disable()
-            
             #replace data plot on combo box selection
             #by removing the previous selected data
@@ -1776,6 +1790,5 @@
             wx.PostEvent(self._manager.parent, NewPlotEvent(plot=self.data, 
                                                 title=str(self.data.title)))
-            self._manager.store_data(uid=self.uid, data=data,
-                                     data_list=self.data_list,
+            self._manager.store_data(uid=self.uid, data_list=self.data_list,
                                       caption=self.window_name)
             self._draw_model()
@@ -2151,8 +2164,10 @@
             get_pin_max.SetBackgroundColour("white")
         ## set smearing value whether or not the data contain the smearing info
+        
         self._manager.set_smearer(smearer=self.current_smearer,
-                                 enable2D=self.enable2D,
+                                fid=self.data.id,
                                  qmin=float(self.qmin_x),
                                  qmax= float(self.qmax_x),
+                                 enable_smearer=not self.disable_smearer.GetValue(),
                                  uid=self.uid)
         return msg
@@ -2326,7 +2341,8 @@
         ## set smearing value whether or not the data contain the smearing info
         self._manager.set_smearer(smearer=self.current_smearer, 
-                                 enable2D=self.enable2D,
+                                 fid=self.data.id,
                                  qmin=float(self.qmin_x), 
                                  qmax= float(self.qmax_x),
+                        enable_smearer=not self.disable_smearer.GetValue(),
                                  uid=self.uid) 
         return msg
@@ -2415,7 +2431,9 @@
         ## set smearing value whether or not the data contain the smearing info
         self._manager.set_smearer(uid=self.uid, smearer=temp_smearer,
-                        enable2D=self.enable2D,
-                        qmin= float(self.qmin_x),
-                        qmax= float(self.qmax_x), draw=True) 
+                                  fid=self.data.id,
+                        qmin=float(self.qmin_x),
+                        qmax=float(self.qmax_x),
+                        enable_smearer=not self.disable_smearer.GetValue(),
+                         draw=True) 
         
         self.state.enable_smearer=  self.enable_smearer.GetValue()
@@ -2426,8 +2444,6 @@
     def on_complete_chisqr(self, event):  
         """
-        print result chisqr 
-        
+        Display result chisqr on the panel
         :event: activated by fitting/ complete after draw
-        
         """
         try:
@@ -2439,5 +2455,4 @@
                 output = event.output
             self.tcChi.SetValue(str(format_number(output, True)))
-
             self.state.tcChi = self.tcChi.GetValue()
         except:
@@ -2958,5 +2973,5 @@
             self.model_view.SetLabel("1D Mode")
             self.enable2D = False
-
+        self.create_default_data()
         self.set_model_param_sizer(self.model)
         self._set_sizer_dispersion()  
