Index: sansview/perspectives/fitting/basepage.py
===================================================================
--- sansview/perspectives/fitting/basepage.py	(revision 1b43306e628b9bad505e149e3b01b996b38f2202)
+++ sansview/perspectives/fitting/basepage.py	(revision 0b12abb5c0c3b5a6afac1385baf8c31c36e66602)
@@ -41,10 +41,7 @@
         """
         """
-        wx.ScrolledWindow.__init__(self, parent,
-                 style= wx.FULL_REPAINT_ON_RESIZE )
+        wx.ScrolledWindow.__init__(self, parent,style=wx.FULL_REPAINT_ON_RESIZE)
         #Set window's font size 
         self.SetWindowVariant(variant=FONT_VARIANT)
-        ##window_name
-       
         ## parent of the page
         self.parent = parent
@@ -58,5 +55,26 @@
         self.data = None
         self.mask = None
-        self.theory = None
+        ## Q range
+        self.qmax_x = None
+        self.qmin_x = None
+        self.num_points= _NPTS_DEFAULT
+        ## total number of point: float
+        self.npts = None
+        ## default fitengine type
+        self.engine_type = None
+        ## smear default
+        self.smearer = None
+        self.current_smearer = None
+        ## 2D smear accuracy default
+        self.smear2d_accuracy = 'Low'
+        ## slit smear: 
+        self.dxl = None
+        self.dxw = None
+        ## pinhole smear 
+        self.dx_min = None
+        self.dx_max = None
+       
+        self.disp_cb_dict = {}
+   
         self.state = PageState(parent=parent)
         ## dictionary containing list of models
@@ -96,8 +114,6 @@
         self.fitrange= True
 
-        ## Q range
-        self.qmin_x= _QMIN_DEFAULT
-        self.qmax_x= _QMAX_DEFAULT
-        self.num_points= _NPTS_DEFAULT
+        
+        
         
         ## Create memento to save the current state
@@ -193,5 +209,4 @@
             
             """
-            
             event.Skip()
             self.full_selection = True
@@ -296,5 +311,5 @@
         self.sizer4.SetMinSize((PANEL_WIDTH,-1))
         self.sizer5.SetMinSize((PANEL_WIDTH,-1))
-        #self.sizer6.SetMinSize((PANEL_WIDTH,-1))
+        self.sizer6.SetMinSize((PANEL_WIDTH,-1))
         
         self.vbox.Add(self.sizer0)
@@ -304,5 +319,5 @@
         self.vbox.Add(self.sizer4)
         self.vbox.Add(self.sizer5)
-        #self.vbox.Add(self.sizer6)
+        self.vbox.Add(self.sizer6)
         
     def set_layout(self):
@@ -578,6 +593,36 @@
         self.manager.save_fit_state(filepath=path, fitstate=new_state)
         return new_state  
-      
+    
     def on_bookmark(self, event):
+        """
+        save history of the data and model
+        """
+        if self.model==None:
+            msg="Can not bookmark; Please select Data and Model first..."
+            wx.MessageBox(msg, 'Info')
+            return 
+        self.save_current_state()
+        new_state = self.state.clone()
+        ##Add model state on context menu
+        self.number_saved_state += 1
+        #name= self.model.name+"[%g]"%self.number_saved_state 
+        name= self.model.__class__.__name__+"[%g]"%self.number_saved_state 
+        self.saved_states[name]= new_state
+        
+        ## Add item in the context menu
+        
+        year, month, day,hour,minute,second,tda,ty,tm_isdst= time.localtime()
+        my_time= str(hour)+" : "+str(minute)+" : "+str(second)+" "
+        date= str( month)+"|"+str(day)+"|"+str(year)
+        msg=  "Model saved at %s on %s"%(my_time, date)
+         ## post help message for the selected model 
+        msg +=" Saved! right click on this page to retrieve this model"
+        wx.PostEvent(self.parent.parent, StatusEvent(status = msg ))
+        
+        id = wx.NewId()
+        self.popUpMenu.Append(id,name,str(msg))
+        wx.EVT_MENU(self, id, self.onResetModel)
+        
+    def old_on_bookmark(self, event):
         """
         save history of the data and model
@@ -676,4 +721,6 @@
         Store current state
         """
+        if hasattr(self, "engine_type"):
+            self.state.engine_type = copy.deepcopy(self.engine_type)
         ## save model option
         if self.model!= None:
@@ -681,5 +728,13 @@
             self.state.disp_list= copy.deepcopy(self.disp_list)
             self.state.model = self.model.clone()
-
+        #save radiobutton state for model selection
+        self.state.shape_rbutton = self.shape_rbutton.GetValue()
+        self.state.shape_indep_rbutton = self.shape_indep_rbutton.GetValue()
+        self.state.struct_rbutton = self.struct_rbutton.GetValue()
+        self.state.plugin_rbutton = self.plugin_rbutton.GetValue()
+        #model combobox
+        self.state.structurebox = self.structurebox.GetSelection()
+        self.state.formfactorbox = self.formfactorbox.GetSelection()
+        
         self.state.enable2D = copy.deepcopy(self.enable2D)
         self.state.values= copy.deepcopy(self.values)
@@ -687,4 +742,6 @@
         ## save data    
         self.state.data= copy.deepcopy(self.data)
+        self.state.qmax_x = self.qmax_x
+        self.state.qmin_x = self.qmin_x
         try:
             n = self.disp_box.GetCurrentSelection()
@@ -697,5 +754,5 @@
         except:
             pass
-        
+      
         if hasattr(self,"enable_disp"):
             self.state.enable_disp= self.enable_disp.GetValue()
@@ -711,5 +768,5 @@
                   
         if hasattr(self,"disp_box"):
-            self.state.disp_box = self.disp_box.GetCurrentSelection()
+            self.state.disp_box = self.disp_box.GetSelection()
 
             if len(self.disp_cb_dict)>0:
@@ -842,4 +899,5 @@
             return  True
         
+           
     def reset_page_helper(self, state):
         """
@@ -854,10 +912,6 @@
             #self._undo.Enable(False)
             return 
-       
-        self.model= state.model
-        self.data = state.data
-        if self.data !=None:
-            from DataLoader.qsmearing import smear_selection
-            self.smearer= smear_selection(self.data)
+    
+        self.set_data(state.data)
         self.enable2D= state.enable2D
         self.engine_type = state.engine_type
@@ -871,25 +925,21 @@
         self.struct_rbutton.SetValue(state.struct_rbutton )
         self.plugin_rbutton.SetValue(state.plugin_rbutton)
-        ##draw sizer containing model parameters value for the current model
-        self._set_model_sizer_selection( self.model )
-        self.set_model_param_sizer(self.model)
-
-        ## reset value of combox box
+        
+        ## fill model combobox
+        self._show_combox_helper()
+        #select the current model
         self.structurebox.SetSelection(state.structurecombobox )
         self.formfactorbox.SetSelection(state.formfactorcombobox)
-        
-        
-        ## enable the view 2d button if this is a modelpage type
-        if hasattr(self,"model_view"):
-            if self.enable2D:
-                self.model_view.Disable()
-            else:
-                self.model_view.Enable()
+        #reset the fitting engine type
+        self.engine_type = state.engine_type
+        #draw the pnael according to the new model parameter 
+        self._on_select_model(event=None)
+  
+        if self.manager !=None:
+            self.manager._on_change_engine(engine=self.engine_type)
         ## set the select all check box to the a given state
-        if hasattr(self, "cb1"):   
-            self.cb1.SetValue(state.cb1)
+        self.cb1.SetValue(state.cb1)
      
         ## reset state of checkbox,textcrtl  and  regular parameters value
-            
         self._reset_parameters_state(self.orientation_params_disp,
                                      state.orientation_params_disp)
@@ -944,4 +994,130 @@
         ##plotting range restore    
         self._reset_plotting_range(state)
+        ## smearing info  restore
+        if hasattr(self, "enable_smearer"):
+            ## set smearing value whether or not the data contain the smearing info
+            self.enable_smearer.SetValue(state.enable_smearer)
+            self.disable_smearer.SetValue(state.disable_smearer)
+            self.onSmear(event=None)           
+        self.pinhole_smearer.SetValue(state.pinhole_smearer)
+        self.slit_smearer.SetValue(state.slit_smearer)
+        ## we have two more options for smearing
+        if self.pinhole_smearer.GetValue(): self.onPinholeSmear(event=None)
+        elif self.slit_smearer.GetValue(): self.onSlitSmear(event=None)
+       
+        ## reset state of checkbox,textcrtl  and dispersity parameters value
+        self._reset_parameters_state(self.fittable_param,state.fittable_param)
+        self._reset_parameters_state(self.fixed_param,state.fixed_param)
+        
+        ## draw the model with previous parameters value
+        self._onparamEnter_helper()
+        ## reset context menu items
+        self._reset_context_menu()
+        ## set the value of the current state to the state given as parameter
+        self.state = state.clone() 
+    
+        
+    def old_reset_page_helper(self, state):
+        """
+        Use page_state and change the state of existing page
+        
+        :precondition: the page is already drawn or created
+        
+        :postcondition: the state of the underlying data change as well as the
+            state of the graphic interface
+        """
+        if state ==None:
+            #self._undo.Enable(False)
+            return 
+       
+        self.model= state.model
+        self.data = state.data
+        if self.data !=None:
+            from DataLoader.qsmearing import smear_selection
+            self.smearer= smear_selection(self.data)
+        self.enable2D= state.enable2D
+        self.engine_type = state.engine_type
+
+        self.disp_cb_dict = state.disp_cb_dict
+        self.disp_list = state.disp_list
+
+        ## set the state of the radio box
+        self.shape_rbutton.SetValue(state.shape_rbutton )
+        self.shape_indep_rbutton.SetValue(state.shape_indep_rbutton)
+        self.struct_rbutton.SetValue(state.struct_rbutton )
+        self.plugin_rbutton.SetValue(state.plugin_rbutton)
+        ##draw sizer containing model parameters value for the current model
+        self._set_model_sizer_selection( self.model )
+        self.set_model_param_sizer(self.model)
+
+        ## reset value of combox box
+        self.structurebox.SetSelection(state.structurecombobox )
+        self.formfactorbox.SetSelection(state.formfactorcombobox)
+        
+        
+        ## enable the view 2d button if this is a modelpage type
+        if hasattr(self,"model_view"):
+            if self.enable2D:
+                self.model_view.Disable()
+            else:
+                self.model_view.Enable()
+        ## set the select all check box to the a given state
+        if hasattr(self, "cb1"):   
+            self.cb1.SetValue(state.cb1)
+     
+        ## reset state of checkbox,textcrtl  and  regular parameters value
+            
+        self._reset_parameters_state(self.orientation_params_disp,
+                                     state.orientation_params_disp)
+        self._reset_parameters_state(self.orientation_params,
+                                     state.orientation_params)
+        self._reset_parameters_state(self.parameters,state.parameters)    
+         ## display dispersion info layer        
+        self.enable_disp.SetValue(state.enable_disp)
+        self.disable_disp.SetValue(state.disable_disp)
+        
+        if hasattr(self, "disp_box"):
+            
+            self.disp_box.SetSelection(state.disp_box) 
+            n= self.disp_box.GetCurrentSelection()
+            dispersity= self.disp_box.GetClientData(n)
+            name= dispersity.__name__     
+
+            self._set_dipers_Param(event=None)
+       
+            if name=="ArrayDispersion":
+                
+                for item in self.disp_cb_dict.keys():
+                    
+                    if hasattr(self.disp_cb_dict[item],"SetValue") :
+                        self.disp_cb_dict[item].SetValue(state.disp_cb_dict[item])
+                        # Create the dispersion objects
+                        from sans.models.dispersion_models import ArrayDispersion
+                        disp_model = ArrayDispersion()
+                        if hasattr(state,"values")and self.disp_cb_dict[item].GetValue()==True:
+                            if len(state.values)>0:
+                                self.values=state.values
+                                self.weights=state.weights
+                                disp_model.set_weights(self.values, state.weights)
+                            else:
+                                self._reset_dispersity()
+                        
+                        self._disp_obj_dict[item] = disp_model
+                        # Set the new model as the dispersion object for the selected parameter
+                        self.model.set_dispersion(item, disp_model)
+                    
+                        self.model._persistency_dict[item] = [state.values, state.weights]
+                    
+            else:
+                keys = self.model.getParamList()
+                for item in keys:
+                    if item in self.disp_list and not self.model.details.has_key(item):
+                        self.model.details[item]=["",None,None]
+                for k,v in self.state.disp_cb_dict.iteritems():
+                    self.disp_cb_dict = copy.deepcopy(state.disp_cb_dict) 
+                    self.state.disp_cb_dict = copy.deepcopy(state.disp_cb_dict)
+
+        ##plotting range restore    
+        self._reset_plotting_range(state)
 
         ## smearing info  restore
@@ -1003,7 +1179,5 @@
         self.qmin.SetValue(str(state.qmin))
         self.qmax.SetValue(str(state.qmax)) 
-        if self.state.npts!=None:
-            self.npts.SetValue(str(state.npts)) 
-            
+
     def _save_typeOfmodel(self):
         """
@@ -1182,10 +1356,8 @@
             item_page_info = statelist[j]
             ##change the state of the check box for simple parameters
-            if item_page[0]!=None:               
+            if item_page[0]!=None:   
                 item_page[0].SetValue(item_page_info[0])
-                
             if item_page[2]!=None:
                 item_page[2].SetValue(item_page_info[2])
-                
             if item_page[3]!=None:
                 ## show or hide text +/-
@@ -1477,15 +1649,9 @@
         self.SetScrollbars(20,20,25,65)
         
-    def _show_combox(self, event):
-        """
-        Show combox box associate with type of model selected
-        """
-        if self.check_invalid_panel():
-            self.shape_rbutton.SetValue(True)
-            return
-
-        ## Don't want to populate combo box again if the event comes from check box
-        if self.shape_rbutton.GetValue()and\
-             event.GetEventObject()==self.shape_rbutton:
+    def _show_combox_helper(self):
+        """
+        Fill panel's combo box according to the type of model selected
+        """
+        if self.shape_rbutton.GetValue():
             ##fill the combobox with form factor list
             self.structurebox.SetSelection(0)
@@ -1493,7 +1659,5 @@
             self.formfactorbox.Clear()
             self._populate_box( self.formfactorbox,self.model_list_box["Shapes"])
-            
-        if self.shape_indep_rbutton.GetValue()and\
-             event.GetEventObject()==self.shape_indep_rbutton:
+        if self.shape_indep_rbutton.GetValue():
             ##fill the combobox with shape independent  factor list
             self.structurebox.SetSelection(0)
@@ -1502,7 +1666,5 @@
             self._populate_box( self.formfactorbox,
                                 self.model_list_box["Shape-Independent"])
-            
-        if self.struct_rbutton.GetValue() and\
-             event.GetEventObject()==self.struct_rbutton:
+        if self.struct_rbutton.GetValue():
             ##fill the combobox with structure factor list
             self.structurebox.SetSelection(0)
@@ -1511,8 +1673,5 @@
             self._populate_box( self.formfactorbox,
                                 self.model_list_box["Structure Factors"])
-           
-        if self.plugin_rbutton.GetValue()and\
-             event.GetEventObject()==self.plugin_rbutton:
-           
+        if self.plugin_rbutton.GetValue():
             ##fill the combobox with form factor list
             self.structurebox.Disable()
@@ -1521,4 +1680,13 @@
                                 self.model_list_box["Customized Models"])
         
+    def _show_combox(self, event=None):
+        """
+        Show combox box associate with type of model selected
+        """
+        if self.check_invalid_panel():
+            self.shape_rbutton.SetValue(True)
+            return
+
+        self._show_combox_helper()
         self._on_select_model(event=None)
         self._save_typeOfmodel()
@@ -1574,6 +1742,5 @@
                     msg= "Model Error:wrong value entered : %s"% sys.exc_value
                     wx.PostEvent(self.parent.parent, StatusEvent(status = msg ))
-                    return 
-                
+                    return  
             except:
                 tcrtl.SetBackgroundColour("pink")
@@ -1591,10 +1758,8 @@
                     msg= "Cannot Plot :No npts in that Qrange!!!  "
                     wx.PostEvent(self.parent.parent, StatusEvent(status = msg ))
-           
         else:
            tcrtl.SetBackgroundColour("pink")
            msg= "Model Error:wrong value entered!!!"
-           wx.PostEvent(self.parent.parent, StatusEvent(status = msg ))
-           
+           wx.PostEvent(self.parent.parent, StatusEvent(status=msg))
         #self._undo.Enable(True)
         self.save_current_state()
@@ -1617,5 +1782,5 @@
         form_factor = None
         if f_id >= 0:
-            form_factor = self.formfactorbox.GetClientData( f_id )
+            form_factor = self.formfactorbox.GetClientData(f_id)
 
         if not form_factor in  self.model_list_box["multiplication"]:
@@ -2119,10 +2284,8 @@
         self.sizer5.Layout()
 
-    
     def _fill_save_sizer(self):
         """
         Draw the layout for saving option
         """
-        return
         self.sizer6.Clear(True)
         box_description= wx.StaticBox(self, -1,"Save Model")
Index: sansview/perspectives/fitting/fitpage.py
===================================================================
--- sansview/perspectives/fitting/fitpage.py	(revision 5062bbf9abf800e4b5ffab0375da1c4a03967672)
+++ sansview/perspectives/fitting/fitpage.py	(revision 0b12abb5c0c3b5a6afac1385baf8c31c36e66602)
@@ -12,8 +12,6 @@
 from sans.guicomm.events import StatusEvent   
 from sans.guiframe.utils import format_number,check_float
-#from sans.guiframe.local_perspectives.plotting.Masking import ModelPanel2D as panel2D
-
-## event to post model to fit to fitting plugins
-(ModelEventbox, EVT_MODEL_BOX) = wx.lib.newevent.NewEvent()
+
+
 
 ## event to know the selected fit engine
@@ -45,35 +43,11 @@
         """
         BasicPage.__init__(self, parent, page_info)
-        ## total number of point: float
-        self.npts=None
-        ## thread for compute Chisqr
-        self.calc_Chisqr=None
-        ## default fitengine type
-        self.engine_type = None
-        ## smear default
-        self.smearer = None
-        self.current_smearer = None
-        ## 2D smear accuracy default
-        self.smear2d_accuracy = 'Low'
-        ## slit smear: 
-        self.dxl = None
-        self.dxw = None
-        ## pinhole smear 
-        self.dx_min = None
-        self.dx_max = None
-        
-        ## model data (theory) calculated on drawing.
-        self.theory_data = None
-      
+ 
         ## draw sizer
         self._fill_datainfo_sizer()
-        
         # get smear info from data
         self._get_smear_info()
-        
         self._fill_model_sizer( self.sizer1)
-        
         self._get_defult_custom_smear()
-        
         self._fill_range_sizer() 
         
@@ -82,12 +56,7 @@
             self.structurebox.Disable()
         else:
-            self.smearer = smear_selection( self.data )
+            self.smearer = smear_selection(self.data)
             if self.smearer ==None:
                 self.enable_smearer.Disable()
-            #if self.data.__class__.__name__ =="Data2D":
-                #if self.model != None:
-                    #self.smear_description_2d.Show(True)
-                    
-        self.disp_cb_dict = {}
         ## to update the panel according to the fit engine type selected
         self.Bind(EVT_FITTER_TYPE,self._on_engine_change)
@@ -124,4 +93,5 @@
         """
         self.engine_type = event.type
+        self.state.engine_type = self.engine_type
         if len(self.parameters)==0:
             self.Layout()
@@ -828,5 +798,5 @@
         
             
-    def _on_select_model(self, event): 
+    def _on_select_model(self, event=None): 
         """
         call back for model selection
@@ -859,4 +829,6 @@
                 ## error occured on chisqr computation
                 pass
+            ## event to post model to fit to fitting plugins
+            (ModelEventbox, EVT_MODEL_BOX) = wx.lib.newevent.NewEvent()
             if self.data is not None and self.data.__class__.__name__ !="Data2D":
                 ## set smearing value whether or not the data contain the smearing info
@@ -867,6 +839,10 @@
             else:   
                  evt = ModelEventbox(model=self.model)
-            wx.PostEvent(self.event_owner, evt)  
-            
+          
+            self.manager._on_model_panel(evt=evt)
+            self.state.model = self.model.clone()
+            self.state.model.name = self.model.name
+            if event is not None:
+                self._draw_model()
         if event !=None:
             #self._undo.Enable(True)
@@ -874,4 +850,5 @@
             event = PageInfoEvent(page = self)
             wx.PostEvent(self.parent, event) 
+      
       
     def _onparamEnter(self,event):
@@ -1335,7 +1312,7 @@
         """
         self.reset_page_helper(state)
-        import sans.guiframe.gui_manager
-        evt = ModelEventbox(model=state.model)
-        wx.PostEvent(self.event_owner, evt)  
+        #import sans.guiframe.gui_manager
+        #evt = ModelEventbox(model=state.model)
+        #wx.PostEvent(self.event_owner, evt)  
    
         if self.engine_type != None:
@@ -1813,4 +1790,6 @@
             of the values entered for slit smear
         """
+        if self.data.__class__.__name__ == "Data2D":
+            return
         temp_smearer = None
         # make sure once more if it is smearer
Index: sansview/perspectives/fitting/fitpanel.py
===================================================================
--- sansview/perspectives/fitting/fitpanel.py	(revision 5062bbf9abf800e4b5ffab0375da1c4a03967672)
+++ sansview/perspectives/fitting/fitpanel.py	(revision 0b12abb5c0c3b5a6afac1385baf8c31c36e66602)
@@ -211,6 +211,17 @@
                 if name == page_info.window_name:
                     # the page is still opened
+                    panel.set_manager(self.manager)
+                    panel.set_owner(self.event_owner)
+                    if panel.model_list_box is None or len(panel.model_list_box) == 0: 
+                        page_info.model_list_box = self.model_list_box.get_list()
+                        panel.populate_box(dict=page_info.model_list_box)
+                        panel.initialize_combox()
+                        panel.set_page_info(page_info=page_info)
+                        self.opened_pages[page_info.type] = [page_info.window_name, panel]
+                    if panel is not None:  
+                        self.manager.store_page(page=panel, data=state.data)
                     panel.reset_page(state=state)
                     page_is_opened = True
+                    
             if not page_is_opened:
                 panel = self.add_fit_page(data=state.data)
@@ -303,5 +314,5 @@
         name = "Fit Page"
         type = 'empty'
-        if data is not None:
+        if data is not None and hasattr(data, "is_data"):
             if data.is_data:
                 name = data.name 
Index: sansview/perspectives/fitting/fitting.py
===================================================================
--- sansview/perspectives/fitting/fitting.py	(revision 1759c8e7679328bd0f82f5a99577536407a0ee32)
+++ sansview/perspectives/fitting/fitting.py	(revision 0b12abb5c0c3b5a6afac1385baf8c31c36e66602)
@@ -161,6 +161,5 @@
         self.fit_panel.set_owner(owner)
         self.fit_panel.set_model_list(self.menu_mng.get_model_list())
-        owner.Bind(fitpage.EVT_MODEL_BOX,self._on_model_panel)
-
+   
         #create  menubar items
         return [(id, self.menu1, "Fitting")]
@@ -299,6 +298,7 @@
         
         """
+        #print "state", state
+        #return
         #working on reading state
-        return 
         try: 
             # Load fitting state
@@ -1003,5 +1003,5 @@
         ## example trying to call set_panel on self.sim_page
         if self.current_pg != self.sim_page :
-            if self.page_finder[self.current_pg].get_model()== None :
+            if self.page_finder[self.current_pg].get_model()== None:
                 
                 model.name = "M"+str(self.index_model)
@@ -1016,8 +1016,5 @@
             qmin, qmax= self.current_pg.get_range()
             self.page_finder[self.current_pg].set_range(qmin=qmin, qmax=qmax)
-            smearer=  self.page_finder[self.current_pg].get_smearer()
-            # save model name
-            self.set_smearer(smearer=smearer, qmin=qmin, qmax=qmax)
-            
+           
             if self.sim_page!=None:
                 self.sim_page.draw_page()
Index: sansview/perspectives/fitting/pagestate.py
===================================================================
--- sansview/perspectives/fitting/pagestate.py	(revision df7ed14719dc1b84a41a963784f6debd5457ff5c)
+++ sansview/perspectives/fitting/pagestate.py	(revision 0b12abb5c0c3b5a6afac1385baf8c31c36e66602)
@@ -44,7 +44,7 @@
                       ["plugin_rbutton", "plugin_rbutton","bool"],
                       ["struct_rbutton", "struct_rbutton", "bool"],
-                      ["formfactorcombobox", "formfactorcombobox", "bool"],
-                      ["structurecombobox", "structurecombobox", "bool"],
-                      ["disp_box", "disp_box"],
+                      ["formfactorcombobox", "formfactorcombobox", "float"],
+                      ["structurecombobox", "structurecombobox", "float"],
+                      ["disp_box", "disp_box", "float"],
                       ["enable_smearer","enable_smearer","bool"],
                       ["disable_smearer","disable_smearer","bool"],
@@ -89,4 +89,31 @@
                          ["mask","mask","bool"]]
 
+def parse_entry_helper( node, item):
+    """
+    Create a numpy list from value extrated from the node
+    
+    :param node: node from each the value is stored
+    :param item: list name of three strings.the two first are name of data
+        attribute and the third one is the type of the value of that 
+        attribute. type can be string, float, bool, etc.
+    
+    : return: numpy array
+    """
+    if node is not None:
+        if item[2] == "string":
+            return str(node.get(item[0]).strip())
+        elif item[2] == "bool":
+            try:
+                exec "value = bool(node.get(item[0]).strip())"
+                return value
+            except:
+                return None
+        else:
+            try:
+                return float(node.get(item[0]))
+            except:
+                return None
+            
+            
 class PageState(object):
     """
@@ -122,5 +149,5 @@
         if self.data is not None and hasattr(self.data, "group_id"):
             self.data_group_id = self.data.group_id
-        #-------------------------
+        
         ## reset True change the state of exsiting button
         self.reset = False
@@ -189,4 +216,8 @@
         self.qmin = 0.001
         self.qmax = 0.1
+        #reset data range
+        self.qmax_x = None
+        self.qmin_x = None
+        
         self.npts = None
         self.name = ""
@@ -312,5 +343,20 @@
         rep += "Plotting Range: min: %s, max: %s, steps: %s\n"%(str(self.qmin),
                                                 str(self.qmax),str(self.npts))
-        """
+        rep += "Dispersion selection : %s\n"%str(self.disp_box)
+        rep += "Smearing enable : %s\n"%str(self.enable_smearer)
+        rep += "Smearing disable : %s\n"%str(self.disable_smearer)
+        rep += "Pinhole smearer enable : %s\n"%str(self.pinhole_smearer)
+        rep += "Slit smearer enable : %s\n"%str(self.slit_smearer)
+        rep += "Dispersity enable : %s\n"%str(self.enable_disp)
+        rep += "Dispersity disable : %s\n"%str(self.disable_disp)
+        rep += "Slit smearer enable: %s\n"%str(self.slit_smearer)
+        rep += "2D enable : %s\n"%str(self.enable2D)
+        rep += "All parameters checkbox selected: %s\n"%(self.cb1)
+        rep += "Value of Chisqr : %s\n"%str(self.tcChi)
+        rep += "Smear object : %s\n"%str(self.smearer)
+        rep += "Smear type : %s\n"%(self.smear_type)
+        rep += "dq_l  : %s\n"%self.dq_l
+        rep += "dq_r  : %s\n"%self.dq_r
+        
         rep += "model  : %s\n\n"% str(self.model)
         rep += "number parameters(self.parameters): %s\n"%len(self.parameters)
@@ -322,5 +368,5 @@
         rep += "(self.orientation_params_disp): %s\n"%len(self.orientation_params_disp)
         rep += self._repr_helper( list=self.orientation_params_disp, rep=rep)
-        """
+        
         return rep
    
@@ -395,5 +441,5 @@
         top_element.appendChild(inputs)
        
-        element = newdoc.createElement('data_attributes')
+
         if self.data is not None and hasattr(self.data, "group_id"):
             self.data_group_id = self.data.group_id
@@ -406,6 +452,7 @@
        
         for item in list_of_data_attributes:
+            element = newdoc.createElement(item[0])
             exec "element.setAttribute(item[0], str(self.%s))"%(item[1])
-        inputs.appendChild(element)   
+            inputs.appendChild(element)   
         
         for item in list_of_state_attributes:
@@ -418,5 +465,5 @@
             exec "list = self.%s"%item[1]
             for value in list:
-                exec "element.appendChild(newdoc.createTextNode(str(%s)))" % value
+                exec "element.appendChild(newdoc.createTextNode(str(%s)))"%value
             inputs.appendChild(element)
             
@@ -440,14 +487,44 @@
         """
         for item in node:
-            name = item.get('name')
-            value = item.get('value')
-            selected_to_fit = item.get('selected_to_fit')
-            error_displayed = item.get('error_displayed')
-            error_value = item.get('error_value')
-            minimum_displayed = item.get('minimum_displayed')
-            minimum_value = item.get('minimum_value')
-            maximum_displayed = item.get('maximum_displayed')
-            maximum_value = item.get('maximum_value')
-            unit = item.get('unit')
+            try:
+                name = item.get('name')
+            except:
+                name = None
+            try:
+                value = item.get('value')
+            except:
+                value = None
+            try:
+                selected_to_fit = bool(item.get('selected_to_fit'))
+            except:
+                selected_to_fit = None
+            try:
+                error_displayed = item.get('error_displayed')
+            except:
+                error_displayed = None
+            try:  
+                error_value = item.get('error_value')
+            except:
+                error_value = None
+            try:
+                minimum_displayed = bool(item.get('minimum_displayed'))
+            except:
+                minimum_displayed = None
+            try:
+                minimum_value = item.get('minimum_value')
+            except:
+                minimum_value = None
+            try:
+                maximum_displayed = bool(item.get('maximum_displayed'))
+            except:
+                maximum_displayed = None
+            try:
+                maximum_value = item.get('maximum_value')
+            except:
+                maximum_value = None
+            try:
+                unit = item.get('unit')
+            except:
+                unit = None
             list.append([selected_to_fit, name, value, "+/-",[error_displayed, error_value],
                          [minimum_displayed,minimum_value],[maximum_displayed,maximum_value], unit])
@@ -461,5 +538,4 @@
         
         """
-      
         if file is not None:
             msg = "PageState no longer supports non-CanSAS"
@@ -486,20 +562,21 @@
             # Parse fitting attributes
             entry = get_content('ns:Attributes', node)
+            for item in list_of_data_attributes:
+                node = get_content('ns:%s'%item[0], entry)
+                try:
+                    exec "self.%s = parse_entry_helper(node, item)"%item[0]
+                    
+                except:
+                    raise
+            
             if entry is not None:
+                
                 for item in list_of_state_attributes:
-                    field = get_content('ns:%s'%item[0], entry)
-                    if field is not None:
-                        if item[2] == "string":
-                            exec "self.%s= str(field.text)"%item[1]
-                        elif item[2] == "bool":
-                            try:
-                                exec "self.%s= field.get(%s)"%(item[1], item[0])
-                            except:
-                                exec "self.%s = None"%item[1]
-                        else:
-                            try:
-                                exec "self.%s = float(field.get(%s))"%(item[1], item[0])
-                            except:
-                                exec "self.%s = None"%item[1]
+                    node = get_content('ns:%s'%item[0], entry)
+                    try:
+                        exec "self.%s = parse_entry_helper(node, item)"%str(item[0])
+                    except:
+                        raise
+                    
                 for item in list_of_model_attributes:
                     node = get_content("ns:%s"%item[0], entry)
@@ -510,11 +587,10 @@
                         except:
                             list.append(None)
-                        
                     exec "self.%s = list"%item[1]
-                    
+                
                 for item in list_of_state_parameters:
                     node = get_content("ns:%s"%item[0], entry)
-                    self._fromXML_helper(node=node, list=self.parameters)
-                
+                    exec "self._fromXML_helper(node=node, list=self.%s)"%item[1]
+                   
 
 class Reader(CansasReader):
@@ -761,6 +837,4 @@
         try:
             nodes = entry.xpath('ns:%s' % FITTING_NODE_NAME, namespaces={'ns': CANSAS_NS})
-            #if entry is not None:
-            #    self.file = entry.text.strip()
             state.fromXML(node=nodes[0])
         except:
@@ -769,28 +843,5 @@
         return state
     
-    def _parse_entry_2d_helper(self, node, item):
-        """
-        Create a numpy list from value extrated from the node
-        
-        :param node: node from each the value is stored
-        :param item: list name of three strings.the two first are name of data
-            attribute and the third one is the type of the value of that 
-            attribute. type can be string, float, bool, etc.
-        
-        : return: numpy array
-        """
-        if node is not None:
-            if item[2] == "string":
-                return node.get(item[0]).strip()
-            elif item[2] == "bool":
-                try:
-                    return node.get(item[0]).strip()
-                except:
-                    return None
-            else:
-                try:
-                    return float(node.get(item[0]))
-                except:
-                    return None
+   
                     
     def _parse_entry(self, dom):
@@ -1014,5 +1065,5 @@
                 #get node
                 node = get_content('ns:%s'%item[0], entry)
-                exec "data_info.%s = self._parse_entry_2d_helper(node, item)"%(item[1])
+                exec "data_info.%s = parse_entry_helper(node, item)"%(item[1])
                     
             for item in list_of_data2d_values:
@@ -1020,5 +1071,5 @@
                 list = []
                 if field is not None:
-                    list = [self._parse_entry_2d_helper(node, item) for node in field]
+                    list = [parse_entry_helper(node, item) for node in field]
                 exec "data_info.%s = numpy.array(list)"%item[0]
         
@@ -1085,5 +1136,4 @@
                  
                 output[0].filename = state.file
-                #output[0].filename = state.data_name
                 state.data = output[0]
                 state.data.name = state.data_name
@@ -1092,5 +1142,4 @@
                 if state.is_data is not None:
                     state.data.is_data = state.is_data
-                #state.data.group_id = state.data_group_id
                 state.data.group_id = output[0].filename
               
