Index: sansview/perspectives/fitting/fitpage.py
===================================================================
--- sansview/perspectives/fitting/fitpage.py	(revision 55fd10285df3ffb3ae109487fc585a83372ad4a0)
+++ sansview/perspectives/fitting/fitpage.py	(revision 442895f8f6b7b30ca7be518812051dcdd0204d83)
@@ -2,5 +2,5 @@
 import wx
 import wx.lib
-import numpy
+import numpy,math
 import copy
 
@@ -65,4 +65,8 @@
         self.vbox.Add(self.sizer1)
         
+        id = wx.NewId()
+        self.btClose =wx.Button(self,id,'Close')
+        self.btClose.Bind(wx.EVT_BUTTON, self.onClose,id=id)
+        self.btClose.SetToolTipString("Close page.")
         ix = 0
         iy = 1
@@ -123,5 +127,7 @@
         ix +=2
         self.sizer1.Add(self.btFit,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0)
-        
+        iy+= 1
+        ix = 3
+        self.sizer1.Add( self.btClose,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0)
         # contains link between  model ,all its parameters, and panel organization
         self.parameters=[]
@@ -193,5 +199,4 @@
              from the previous selected data
         """
-       
         try:
             if dataset !=None:
@@ -205,4 +210,31 @@
         
         
+    def onClose(self,event):
+        self.GrandParent.onClose()
+        
+        
+    def compute_chisqr(self):
+        """ @param fn: function that return model value
+            @return residuals
+        """
+        flag=self.checkFitRange()
+        if flag== True:
+            qmin = float(self.xmin.GetValue())
+            qmax = float(self.xmax.GetValue())
+            x,y,dy = [numpy.asarray(v) for v in (self.data.x,self.data.y,self.data.dy)]
+            if qmin==None and qmax==None: 
+                fx =numpy.asarray([self.model.run(v) for v in x])
+                res=(y - fx)/dy
+            else:
+                idx = (x>= qmin) & (x <=qmax)
+                fx = numpy.asarray([self.model.run(item)for item in x[idx ]])
+                res= (y[idx] - fx)/dy[idx]  
+            
+            sum=0
+            for item in res:
+                sum +=item
+        self.tcChi.SetValue(format_number(math.fabs(sum)))
+            
+            
     def onFit(self,event):
         """ signal for fitting"""
@@ -214,5 +246,4 @@
         qmax =float( self.xmax.GetValue())
         if len(self.param_toFit) >0 and flag==True:
-            #self.manager._on_single_fit(model=self.model,qmin=qmin,qmax=qmax)
             self.manager._on_single_fit(qmin=qmin,qmax=qmax)
         else:
@@ -264,4 +295,5 @@
             set a flag to determine if the fitting range entered by the user is valid
         """
+      
         try:
             flag=self.checkFitRange()
@@ -269,4 +301,5 @@
                  self.manager.redraw_model(float(self.xmin.GetValue())\
                                                ,float(self.xmax.GetValue()))
+           
         except:
             wx.PostEvent(self.parent.GrandParent, StatusEvent(status=\
@@ -489,5 +522,5 @@
             self.xmin.Disable()
             self.xmax.Disable()
-      
+        self.compute_chisqr()
         self.vbox.Layout()
         self.GrandParent.GetSizer().Layout()
@@ -500,6 +533,11 @@
         """
         self.set_model_parameter()
-        
+        self.compute_chisqr()
+     
     def set_model_parameter(self):
+        """
+            this method redraws the model according to parameters values changes
+            and the reset model according to paramaters changes
+        """
         if len(self.parameters) !=0 and self.model !=None:
             for item in self.parameters:
@@ -514,4 +552,6 @@
                      wx.PostEvent(self.parent.GrandParent, StatusEvent(status=\
                             "Drawing  Error:wrong value entered : %s"% sys.exc_value))
+                     
+                     
     def select_all_param(self,event): 
         """
@@ -603,5 +643,6 @@
             for item in self.param_toFit:
                 if( out != None ) and len(out)<=len(self.param_toFit)and i < len(out):
-                    item[1].SetValue(format_number(out[i]))
+                    #item[1].SetValue(format_number(out[i]))
+                    item[1].SetValue(format_number(self.model.getParam(item[0].GetLabelText())))
                     item[1].Refresh() 
                 if (cov !=None)and len(cov)<=len(self.param_toFit)and i < len(cov):
Index: sansview/perspectives/fitting/fitpanel.py
===================================================================
--- sansview/perspectives/fitting/fitpanel.py	(revision 4fc6dbff4c1dda63a0963b2e4c0caff3fdd63636)
+++ sansview/perspectives/fitting/fitpanel.py	(revision 442895f8f6b7b30ca7be518812051dcdd0204d83)
@@ -37,13 +37,4 @@
         self.nb.AddPage(self.sim_page,"Simultaneous Fit")
         
-        id = wx.NewId()
-        self.btClose =wx.Button(self,id,'Close')
-        self.btClose.Bind(wx.EVT_BUTTON, self.onClose,id=id)
-        self.btClose.SetToolTipString("Close page.")
-    
-        sizer_button = wx.BoxSizer(wx.HORIZONTAL)
-        sizer_button.Add((20, 20), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
-        sizer_button.Add(self.btClose, 0, wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10)
-        self.sizer.Add(sizer_button,1, wx.EXPAND)
         #dictionary of miodel {model class name, model class}
         self.model_list_box={}
@@ -145,9 +136,10 @@
         return self.nb.GetPage(self.nb.GetSelection())
     
-    def onClose(self,event):
+    def onClose(self):
         """
              close the current page except the simpage. remove each check box link to the model
              selected on that page. remove its reference into page_finder (fitting module)
         """
+       
         sim_page = self.nb.GetPage(0)
         selected_page = self.nb.GetPage(self.nb.GetSelection())
Index: sansview/perspectives/fitting/fitting.py
===================================================================
--- sansview/perspectives/fitting/fitting.py	(revision 55fd10285df3ffb3ae109487fc585a83372ad4a0)
+++ sansview/perspectives/fitting/fitting.py	(revision 442895f8f6b7b30ca7be518812051dcdd0204d83)
@@ -14,13 +14,35 @@
 import fitpage
 import park
+class PlottableDatas(Data,Data1D):
+    """ class plottable data: class allowing to plot Data type on panel"""
+    
+    def __init__(self,data=None,data1d=None):
+        Data.__init__(self,sans_data=data1d)
+        Data1D.__init__(self,x=data1d.x,y = data1d.y,dx = data1d.dx,dy = data1d.dy)
+        #self.x = data1d.x
+        #self.y = data1d.y
+        #self.dx = data1d.dx
+        #self.dy = data1d.dy
+        #self.data=data
+        self.group_id = data1d.group_id
+        #x_name, x_units = data1d.get_xaxis() 
+        #y_name, y_units = data1d.get_yaxis() 
+        #self.xaxis( x_name, x_units)
+        #self.yaxis( y_name, y_units )
+        #self.qmin = data.qmin
+        #self.qmax = data.qmax
+       
 
 class PlottableData(Data,Data1D):
     """ class plottable data: class allowing to plot Data type on panel"""
-    def __init__(self,data,data1d):
+    
+    def __init__(self,data=None,data1d=None):
+        #Data.__init__(self,*args)
+        #Data1D.__init__(self,**kw)
         self.x = data1d.x
         self.y = data1d.y
         self.dx = data1d.dx
         self.dy = data1d.dy
-       
+        self.data=data
         self.group_id = data1d.group_id
         x_name, x_units = data1d.get_xaxis() 
@@ -30,4 +52,6 @@
         self.qmin = data.qmin
         self.qmax = data.qmax
+        def residuals(self, fn):
+            return self.data.residuals(fn)
 
 class Plugin:
@@ -68,5 +92,5 @@
         wx.EVT_MENU(owner, id1, self.on_perspective)
         id3 = wx.NewId()
-        self.menu1.Append(id3,'&scipy \ park','toggle engine to park or scipy')
+        self.menu1.AppendCheckItem(id3, "park") 
         wx.EVT_MENU(owner, id3, self._onset_engine)
         
@@ -166,8 +190,10 @@
                     #create a fitproblem storing all link to data,model,page creation
                     self.page_finder[page]= FitProblem()
-                    data_for_park= Data(sans_data=item)
-                    datap=PlottableData(data=data_for_park,data1d=item)
-                    self.page_finder[page].add_data(datap)
+                    #data_for_park= Data(sans_data=item)
+                    #datap = PlottableData(data=data_for_park,data1d=item)
+                    #self.page_finder[page].add_data(datap)
+                    self.page_finder[page].add_data(item)
                 except:
+                    #raise
                     wx.PostEvent(self.parent, StatusEvent(status="Fitting error: \
                     data already Selected "))
@@ -230,4 +256,5 @@
                     break
             i = 0
+#            print "fitting: single fit pars ", pars
             for name in pars:
                 if result.pvec.__class__==numpy.float64:
@@ -235,8 +262,14 @@
                 else:
                     model.setParam(name,result.pvec[i])
+#                    print "fitting: single fit", name, result.pvec[i]
                     i += 1
+#            print "fitting result : chisqr",result.fitness
+#            print "fitting result : pvec",result.pvec
+#            print "fitting result : stderr",result.stderr
+            
             current_pg.onsetValues(result.fitness, result.pvec,result.stderr)
             self.plot_helper(currpage=current_pg,qmin=qmin,qmax=qmax)
         except:
+            raise
             wx.PostEvent(self.parent, StatusEvent(status="Fitting error: %s" % sys.exc_value))
             
@@ -319,5 +352,8 @@
                 try:
                     self.fitter.set_model(Model(model), self.id, pars) 
-                    self.fitter.set_data(data,self.id,qmin,qmax)
+                    #print "fitting: data .x",data.x
+                    #print "fitting: data .y",data.y
+                    #print "fitting: data .dy",data.dy
+                    self.fitter.set_data(Data(sans_data=data),self.id,qmin,qmax)
                 
                     result=self.fitter.fit()
@@ -325,4 +361,5 @@
                    
                 except:
+                    raise
                     wx.PostEvent(self.parent, StatusEvent(status="Single Fit error: %s" % sys.exc_value))
                     return
@@ -364,5 +401,5 @@
                             return
                     self.fitter.set_model(Model(model), self.id, pars) 
-                    self.fitter.set_data(data,self.id,qmin,qmax)
+                    self.fitter.set_data(Data(sans_data=data),self.id,qmin,qmax)
                 
                     self.id += 1 
@@ -415,5 +452,5 @@
             model.name="M"+str(self.index_model)
             self.index_model += 1  
-            #self.page_finder[current_pg].set_theory("Fitness")
+            
             self.page_finder[current_pg].set_model(model,M_name)
             self.plot_helper(currpage= current_pg,qmin= None,qmax= None)
@@ -448,5 +485,5 @@
             if data!=None:
                 theory = Theory1D(x=[], y=[])
-                theory.name = model.name
+                theory.name = "Model"
                 theory.group_id = data.group_id
               
@@ -455,5 +492,7 @@
                 theory.xaxis(x_name, x_units)
                 theory.yaxis(y_name, y_units)
-              
+                #print"fitting : redraw data.x",data.x
+                #print"fitting : redraw data.y",data.y
+                #print"fitting : redraw data.dy",data.dy
                 if qmin == None :
                    qmin = min(data.x)
@@ -489,7 +528,11 @@
                         skipping point x %g %s" %(qmax, sys.exc_value)))
                 try:
-                    from sans.guicomm.events import NewPlotEvent
+                    #print "fitting redraw for plot thoery .x",theory.x
+                    #print "fitting redraw for plot thoery .y",theory.y
+                    #print "fitting redraw for plot thoery .dy",theory.dy
+                    #rom sans.guicomm.events import NewPlotEvent
                     wx.PostEvent(self.parent, NewPlotEvent(plot=theory, title="Analytical model"))
                 except:
+                    raise
                     print "SimView.complete1D: could not import sans.guicomm.events"
             
@@ -520,5 +563,5 @@
            
             new_plot = Theory1D(x, y)
-            new_plot.name = model.name
+            new_plot.name = "Model"
             new_plot.xaxis("\\rm{Q}", 'A^{-1}')
             new_plot.yaxis("\\rm{Intensity} ","cm^{-1}")
Index: sansview/perspectives/fitting/modelpage.py
===================================================================
--- sansview/perspectives/fitting/modelpage.py	(revision 55fd10285df3ffb3ae109487fc585a83372ad4a0)
+++ sansview/perspectives/fitting/modelpage.py	(revision 442895f8f6b7b30ca7be518812051dcdd0204d83)
@@ -268,6 +268,7 @@
                      self.manager.draw_model(self.model)
                 except:
+                    
                      wx.PostEvent(self.parent.GrandParent, StatusEvent(status=\
-                            "Drawing  Error:wrong value entered : %s"% sys.exc_value))
+                            "Model Drawing  Error:wrong value entered : %s"% sys.exc_value))
    
   
Index: sansview/perspectives/fitting/models.py
===================================================================
--- sansview/perspectives/fitting/models.py	(revision 3b19ac900df88b5cbef968f2497d314a8a59c333)
+++ sansview/perspectives/fitting/models.py	(revision 442895f8f6b7b30ca7be518812051dcdd0204d83)
@@ -1,5 +1,5 @@
 import wx
 import imp
-import os,sys
+import os,sys,math
 import os.path
 
@@ -76,16 +76,71 @@
         self.model_list = {}
         self.model_list_box = {}
+        
         model_info="shape-based models"
+        
+        from sans.models.SphereModel import SphereModel
+        self.model_list[str(wx.NewId())] =  ModelInfo(SphereModel , model_info)
+        
         from sans.models.CylinderModel import CylinderModel
         self.model_list[str(wx.NewId())] = ModelInfo(CylinderModel , model_info)
       
-        from sans.models.SphereModel import SphereModel
-        self.model_list[str(wx.NewId())] =  ModelInfo(SphereModel , model_info)
-   
+        from sans.models.CoreShellModel import CoreShellModel
+        self.model_list[str(wx.NewId())] = ModelInfo(CoreShellModel , model_info)
+        
+        from sans.models.CoreShellCylinderModel import CoreShellCylinderModel
+        self.model_list[str(wx.NewId())] = ModelInfo(CoreShellCylinderModel , model_info)
+        
+        from sans.models.EllipticalCylinderModel import EllipticalCylinderModel
+        self.model_list[str(wx.NewId())] = ModelInfo(EllipticalCylinderModel , model_info)
+        
+        from sans.models.EllipsoidModel import EllipsoidModel
+        self.model_list[str(wx.NewId())] = ModelInfo(EllipsoidModel , model_info)
+        
         from sans.guitools.LineModel import LineModel
         self.model_list[str(wx.NewId())]  = ModelInfo(LineModel , model_info)
+        
+        
         model_info="shape-independent models"
-        from sans.models.Lorentzian import Lorentzian
-        self.indep_model.append( ModelInfo(Lorentzian , model_info) )
+        
+        from sans.models.BEPolyelectrolyte import BEPolyelectrolyte
+        self.indep_model.append( ModelInfo( BEPolyelectrolyte , model_info) )
+        
+        from sans.models.DABModel import DABModel
+        self.indep_model.append( ModelInfo(DABModel , model_info+
+        "\n Evaluates F(x) = scale/( 1 + (x*L)^2 )^(2) +bkd") )
+        
+        from sans.models.DebyeModel import DebyeModel
+        self.indep_model.append( ModelInfo(DebyeModel , model_info+
+        "\n Evaluates F(x) = 2( exp(-x)+x -1 )/x**2") )
+        
+        from sans.models.FractalModel import FractalModel
+        class FractalAbsModel(FractalModel):
+            def _Fractal(self, x):
+                return FractalModel._Fractal(self, math.fabs(x))
+        self.indep_model.append( ModelInfo(FractalAbsModel , model_info) )
+        
+        from sans.models.LorentzModel import LorentzModel
+        self.indep_model.append( ModelInfo(LorentzModel , model_info+
+                "\n Evaluates F(x)= scale/( 1 + (x*L)^2 ) + bkd ") ) 
+            
+        from sans.models.PowerLawModel import PowerLawModel
+        class PowerLawAbsModel(PowerLawModel):
+            def _PowerLaw(self, x):
+                try:
+                    return PowerLawModel._PowerLaw(self, math.fabs(x))
+                except:
+                    print sys.exc_value  
+        self.indep_model.append( ModelInfo(PowerLawAbsModel , model_info+
+        "\n Evaluates abs(F(x)) \n with F(x) = scale* (x)^(m) + bkd ") )
+                    
+       
+        from sans.models.TeubnerStreyModel import TeubnerStreyModel
+        self.indep_model.append( ModelInfo(TeubnerStreyModel , model_info) )
+        
+        
+          
+        
+        
+      
         
         #Looking for plugins
Index: sansview/perspectives/fitting/simfitpage.py
===================================================================
--- sansview/perspectives/fitting/simfitpage.py	(revision 55fd10285df3ffb3ae109487fc585a83372ad4a0)
+++ sansview/perspectives/fitting/simfitpage.py	(revision 442895f8f6b7b30ca7be518812051dcdd0204d83)
@@ -39,16 +39,13 @@
                         wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
         wx.EVT_CHECKBOX(self, self.cb1.GetId(), self.select_all_model_name)
-       
-        ix  = 0
-        iy  = 1
+      
         text=wx.StaticText(self, -1, 'Constraint')
         self.sizer2.Add(text,0, wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10)
-        ix  = 0
-        iy  += 1
+
         self.ctl2 = wx.TextCtrl(self, -1, style=wx.TE_MULTILINE)
         self.ctl2.Bind(wx.EVT_KILL_FOCUS, self._onTextEnter)
         self.ctl2.Bind(wx.EVT_TEXT_ENTER, self._onTextEnter)
         self.sizer2.Add(self.ctl2, 0, wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10)
-        ix +=2
+       
         self.sizer2.Add(self.btFit, 0, wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10)
         self.params=[]
@@ -56,7 +53,8 @@
         self.model_toFit=[]
         self.page_finder={}
-        iy +=1
+       
+
         #self.sizer2.Add((20,20),(iy, ix))
-        self.sizer2.Add((20,20), 0, wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10)
+        #self.sizer2.Add((20,20), 0, wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10)
         self.vbox.Layout()
         self.vbox.Fit(self) 
@@ -117,7 +115,7 @@
         for page, value in page_finder.iteritems():
             try:
-                list=value.get_model()
-                model=list[0]
-                modelname=list[1]
+                list = value.get_model()
+                model = list[0]
+                modelname = list[1]
                 cb = wx.CheckBox(self, -1, modelname, (10, 10))
                 cb.SetValue(False)
@@ -131,4 +129,6 @@
                 #(value.get_data().group_id,sys.exc_value)))
                 pass
+        iy +=1
+        self.sizer1.Add((20,20),( iy,ix),(1,1),  wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
         self.sizer1.Layout()        
         self.vbox.Layout()
