- Timestamp:
- Mar 26, 2010 12:41:45 PM (15 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 509af3d
- Parents:
- da87bce
- Location:
- sansview/perspectives/fitting
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
sansview/perspectives/fitting/basepage.py
re575db9 r2f189dc 319 319 self.state.event_owner = owner 320 320 321 def get_data(self): 322 """ 323 return the current data 324 """ 325 return self.data 321 326 def set_manager(self, manager): 322 327 """ -
sansview/perspectives/fitting/fitpanel.py
r3244cbe1 r2f189dc 49 49 self._current = int(value) 50 50 51 52 53 51 54 52 class ListOfState(list): 55 53 def __init__(self, *args, **kw): … … 89 87 def getCurrentPosition(self): 90 88 return self.iterator.currentPosition() 91 92 93 94 95 89 90 96 91 class PageInfo(object): 97 92 """ … … 109 104 ## Title to appear on top of the window 110 105 window_caption = "Page" 111 112 def __init__(self, model=None,data=None, manager=None, 113 event_owner=None,model_list_box=None , name=None): 106 #type of page can be real data , theory 1D or therory2D 107 type = "Data" 108 def __init__(self, model=None, data=None, manager=None, 109 event_owner=None, model_list_box=None, name=None): 114 110 """ 115 111 Initialize data members … … 123 119 self.window_name = "Page" 124 120 self.window_caption = "Page" 125 121 self.type = "Data" 122 126 123 class FitPanel(AuiNotebook): 127 124 … … 149 146 150 147 pageClosedEvent = wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSE 151 self.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSE, self.on ClosePage)148 self.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSE, self.on_close_page) 152 149 153 150 #dictionary of miodel {model class name, model class} 154 self.model_list_box={} 155 ##dictionary of page info 156 self.page_info_dict={} 151 self.model_list_box = {} 157 152 ## save the title of the last page tab added 158 self.fit_page_name ={}153 self.fit_page_name = {} 159 154 ## list of existing fit page 160 self.list_fitpage_name=[] 161 162 #model page info 163 self.model_page_number = None 164 ## fit page number for model plot 165 self.fit_page1D_number = None 166 self.fit_page2D_number = None 167 self.model_page = None 155 self.opened_pages = {} 156 #page of simultaneous fit 168 157 self.sim_page = None 169 self.default_page = None170 self.check_first_data = False171 158 ## get the state of a page 172 159 self.Bind(basepage.EVT_PAGE_INFO, self._onGetstate) … … 179 166 self.AddPage(page=self.hint_page, caption="Hint") 180 167 #Add the first fit page 181 self. default_page = self.add_fit_page(data=None)168 self.add_empty_page() 182 169 183 170 # increment number for model name … … 186 173 self.Update() 187 174 self.Center() 188 189 190 def onClosePage(self, event): 175 176 def on_close_page(self, event): 191 177 """ 192 178 close page and remove all references to the closed page … … 197 183 return 198 184 selected_page = self.GetPage(self.GetSelection()) 199 #remove default page 200 if selected_page == self.default_page: 201 self.default_page = None 202 return 203 #remove hint page 204 if selected_page == self.hint_page: 205 return 206 ## removing sim_page 207 if selected_page == self.sim_page : 208 self.manager.sim_page=None 209 return 210 211 ## closing other pages 212 state = selected_page.createMemento() 213 page_name = selected_page.window_name 214 page_finder = self.manager.get_page_finder() 215 fitproblem = None 216 ## removing model page 217 if selected_page == self.model_page: 218 #fitproblem = selected_page.model.clone() 219 self.model_page = None 220 self.count =0 221 ## page on menu 222 #self.manager._add_page_onmenu(page_name, fitproblem) 223 else: 224 if selected_page in page_finder: 225 226 #fitproblem= page_finder[selected_page].clone() 227 if self.GetPageIndex(selected_page)==self.fit_page1D_number: 228 self.fit_page1D_number=None 229 if self.GetPageIndex(selected_page)==self.fit_page2D_number: 230 self.fit_page2D_number=None 231 ## page on menu 232 #self.manager._add_page_onmenu(page_name, fitproblem) 233 del page_finder[selected_page] 234 ##remove the check box link to the model name of this page (selected_page) 235 try: 236 self.sim_page.draw_page() 237 except: 238 ## that page is already deleted no need to remove check box on 239 ##non existing page 240 pass 241 242 #Delete the name of the page into the list of open page 243 if selected_page.window_name in self.list_fitpage_name: 244 self.list_fitpage_name.remove(selected_page.window_name) 245 185 self._close_helper(selected_page=selected_page) 186 187 def close_page_with_data(self, deleted_data): 188 """ 189 close a fit page when its data is completely remove from the graph 190 """ 191 for index in range(self.GetPageCount()): 192 selected_page = self.GetPage(index) 193 if hasattr(selected_page,"get_data"): 194 data = selected_page.get_data() 195 if data.name == deleted_data.name: 196 self._close_helper(selected_page) 197 self.DeletePage(index) 198 break 246 199 247 200 def set_manager(self, manager): … … 287 240 return self.sim_page 288 241 289 290 def add_fit_page( self,data=None, reset=False ): 242 def get_page_info(self, data=None): 243 """ 244 fill information required to add a page in the fit panel 245 """ 246 name = "Fit Page" 247 type = 'empty' 248 if data is not None: 249 if data.is_data: 250 name = data.name 251 type = 'Data' 252 else: 253 if data.__class__.__name__ == "Data2D": 254 name = 'Model 2D Fit' 255 type = 'Theory2D' 256 else: 257 name = 'Model 1D Fit' 258 type = 'Theory1D' 259 page_info = PageInfo(data=data, name=name) 260 page_info.event_owner = self.event_owner 261 page_info.manager = self.manager 262 page_info.window_name = name 263 page_info.window_caption = name 264 page_info.type = type 265 return page_info 266 267 def add_empty_page(self): 268 """ 269 add an empty page 270 """ 271 page_info = self.get_page_info() 272 from fitpage import FitPage 273 panel = FitPage(parent=self, page_info=page_info) 274 self.AddPage(page=panel, caption=page_info.window_name, select=True) 275 self.opened_pages[page_info.type] = [page_info.window_name, panel] 276 return panel 277 278 def add_page(self, page_info): 279 """ 280 add a new page 281 """ 282 from fitpage import FitPage 283 panel = FitPage(parent=self, page_info=page_info) 284 self.AddPage(page=panel, caption=page_info.window_name, select=True) 285 index = self.GetPageIndex(panel) 286 self.change_page_content(data=page_info.data, index=index) 287 return panel 288 289 def change_page_content(self, data, index): 290 """ 291 replace the contains of an existing page 292 """ 293 page_info = self.get_page_info(data=data) 294 self.SetPageText(index, page_info.window_name) 295 panel = self.GetPage(index) 296 panel.set_data(data) 297 if panel.model_list_box is None or len(panel.model_list_box) == 0: 298 page_info.model_list_box = self.model_list_box.get_list() 299 panel.populate_box(dict=page_info.model_list_box) 300 panel.initialize_combox() 301 panel.set_page_info(page_info=page_info) 302 self.opened_pages[page_info.type] = [page_info.window_name, panel] 303 return panel 304 305 def replace_page(self, index, page_info, type): 306 """ 307 replace an existing page 308 """ 309 self.DeletePage(index) 310 del self.opened_pages[type] 311 return self.add_page(page_info=page_info) 312 313 def add_fit_page(self, data, reset=False): 291 314 """ 292 315 Add a fitting page on the notebook contained by fitpanel 293 316 @param data: data to fit 294 317 @return panel : page just added for further used. is used by fitting module 295 """ 296 if data is not None: 297 if data.is_data: 298 name = data.name 318 """ 319 if data is None: 320 return None 321 page_info = self.get_page_info(data=data) 322 type = page_info.type 323 npages = len(self.opened_pages.keys()) 324 #check if only and empty page is opened 325 if len(self.opened_pages.keys()) > 0: 326 first_page_type = self.opened_pages.keys()[0] 327 if npages == 1 and first_page_type in ['empty']: 328 #replace the first empty page 329 name, panel = self.opened_pages[first_page_type] 330 index = self.GetPageIndex(panel) 331 panel = self.change_page_content(data=data, index=index) 332 del self.opened_pages[first_page_type] 333 return panel 334 if type in self.opened_pages.keys(): 335 #this type of page is already created but it is a theory 336 # meaning the same page is just to fit different data 337 if not type.lower() in ['data']: 338 #delete the previous theory page and add a new one 339 name, panel = self.opened_pages[type] 340 self.manager.reset_plot_panel(panel.get_data()) 341 #delete the existing page and replace it 342 index = self.GetPageIndex(panel) 343 panel = self.replace_page(index=index, page_info=page_info, type=type) 344 return panel 299 345 else: 300 if data.__class__.__name__=="Data2D": 301 name = 'Model 2D Fit' 302 else: 303 name = 'Model 1D Fit' 304 myinfo = PageInfo( data=data, name=name ) 305 myinfo.model_list_box = self.model_list_box.get_list() 306 myinfo.event_owner = self.event_owner 307 myinfo.manager = self.manager 308 myinfo.window_name = name 309 myinfo.window_caption = name 310 311 else : 312 name = "Fit Page" 313 myinfo = PageInfo( data=data, name=name ) 314 315 if not name in self.list_fitpage_name: 316 # the first data loading 317 if not self.check_first_data and self.default_page is not None: 318 page_number = self.GetPageIndex(self.default_page) 319 self.SetPageText(page_number , name) 320 self.default_page.set_data(data) 321 self.default_page.set_page_info(page_info=myinfo) 322 self.default_page.initialize_combox() 323 if data is not None: 324 self.check_first_data = True 325 panel = self.default_page 326 else: 327 #if not name in self.fit_page_name : 328 from fitpage import FitPage 329 panel = FitPage(parent=self, page_info=myinfo) 330 331 self.AddPage(page=panel, caption=name, select=True) 332 if name == 'Model 1D Fit': 333 self.fit_page1D_number= self.GetPageIndex(panel) 334 if name =='Model 2D Fit': 335 self.fit_page2D_number= self.GetPageIndex(panel) 336 337 self.list_fitpage_name.append(name) 338 if data is not None: 339 if reset: 340 if name in self.fit_page_name.keys(): 341 memento= self.fit_page_name[name][0] 342 panel.reset_page(memento) 343 else: 344 self.fit_page_name[name]=ListOfState() 345 346 #self.fit_page_name[name].appendItem(panel.createMemento()) 347 #GetPage(self, page_idx) 348 return panel 349 elif name =='Model 1D Fit': 350 if self.fit_page1D_number!=None: 351 panel =self.GetPage(self.fit_page1D_number) 352 #self.fit_page_name[name]=[] 353 self.fit_page_name[name]= ListOfState() 354 #self.fit_page_name[name].insert(0,panel.createMemento()) 355 #self.fit_page_name[name].append(panel.createMemento()) 356 return panel 357 return None 358 elif name =='Model 2D Fit': 359 if self.fit_page2D_number!=None: 360 panel =self.GetPage(self.fit_page2D_number) 361 self.fit_page_name[name]=ListOfState() 362 #self.fit_page_name[name].append(panel.createMemento()) 363 return panel 364 return None 365 return None 366 367 368 def add_model_page(self,model,page_title="Model", qmin=0.0001, qmax=0.13, 369 npts=50, topmenu=False, reset=False): 370 """ 371 Add a model page only one to display any model selected from the menu or the page combo box. 372 when this page is closed than the user will be able to open a new one 373 374 @param model: the model for which paramters will be changed 375 @param page_title: the name of the page 376 @param page_info: contains info about the state of the page 377 @param qmin: mimimum Q 378 @param qmax: maximum Q 379 @param npts: number of Q points 380 """ 381 if topmenu==True: 382 ##first time to open model page 383 if self.count==0 : 384 #if not page_title in self.list_fitpage_name : 385 self._help_add_model_page(model=model, page_title=page_title, 386 qmin=qmin, qmax=qmax, npts=npts, reset=reset) 387 self.count +=1 388 else: 389 self.model_page.select_model(model) 390 self.fit_page_name[page_title]=ListOfState() 391 #self.fit_page_name[page_title].insert(0,self.model_page.createMemento()) 392 393 394 395 def _close_fitpage(self,data): 396 """ 397 close a fit page when its data is completely remove from the graph 398 """ 399 name = data.name 400 for index in range(self.GetPageCount()): 401 if self.GetPageText(index)== name: 402 selected_page = self.GetPage(index) 403 404 if index ==self.fit_page1D_number: 405 self.fit_page1D_number=None 406 if index ==self.fit_page2D_number: 407 self.fit_page2D_number=None 408 if selected_page in self.manager.page_finder: 409 del self.manager.page_finder[selected_page] 410 ##remove the check box link to the model name of this page (selected_page) 411 try: 412 self.sim_page.draw_page() 413 except: 414 ## that page is already deleted no need to remove check box on 415 ##non existing page 416 pass 417 418 #Delete the name of the page into the list of open page 419 if selected_page.window_name in self.list_fitpage_name: 420 self.list_fitpage_name.remove(selected_page.window_name) 421 self.DeletePage(index) 422 break 423 424 346 for name, panel in self.opened_pages.values(): 347 #Don't return any panel is the exact same page is created 348 if name == page_info.window_name: 349 return None 350 else: 351 panel = self.add_page(page_info=page_info) 352 return panel 353 else: 354 #a new type of page is created 355 panel = self.add_page(page_info=page_info) 356 return panel 357 425 358 def _onGetstate(self, event): 426 359 """ … … 444 377 page.reset_page(state) 445 378 446 def _onRedo(self, event 379 def _onRedo(self, event): 447 380 """ 448 381 return the next state available … … 458 391 state = self.fit_page_name[page.window_name].getNextItem() 459 392 page.reset_page(state) 393 394 def _close_helper(self, selected_page): 395 """ 396 Delete the given page from the notebook 397 """ 398 #remove hint page 399 if selected_page == self.hint_page: 400 return 401 ## removing sim_page 402 if selected_page == self.sim_page : 403 self.manager.sim_page=None 404 return 405 406 ## closing other pages 407 state = selected_page.createMemento() 408 page_name = selected_page.window_name 409 page_finder = self.manager.get_page_finder() 410 fitproblem = None 411 ## removing fit page 412 if selected_page in page_finder: 413 #Delete the name of the page into the list of open page 414 for type, list in self.opened_pages.iteritems(): 415 #Don't return any panel is the exact same page is created 416 name = str(list[0]) 417 if selected_page.window_name == name: 418 if type.lower() in ['theory1d', 'theory2d']: 419 self.manager.remove_plot(selected_page, theory=True) 420 else: 421 self.manager.remove_plot(selected_page, theory=False) 422 break 423 del page_finder[selected_page] 424 ##remove the check box link to the model name of this page (selected_page) 425 try: 426 self.sim_page.draw_page() 427 except: 428 ## that page is already deleted no need to remove check box on 429 ##non existing page 430 pass 460 431 461 def _help_add_model_page(self,model,page_title="Model", qmin=0.0001, 462 qmax=0.13, npts=50,reset= False): 463 """ 464 #TODO: fill in description 465 466 @param qmin: mimimum Q 467 @param qmax: maximum Q 468 @param npts: number of Q points 469 """ 470 ## creating object that contaning info about model 471 myinfo = PageInfo(model= model ,name= page_title) 472 myinfo.model_list_box = self.model_list_box.get_list() 473 myinfo.event_owner = self.event_owner 474 myinfo.manager = self.manager 475 myinfo.window_name = page_title 476 myinfo.window_caption = page_title 477 478 from modelpage import ModelPage 479 panel = ModelPage(self,myinfo) 480 481 self.AddPage(page=panel, caption=page_title, select=True) 482 483 self.model_page_number=self.GetSelection() 484 self.model_page=self.GetPage(self.GetSelection()) 432 #Delete the name of the page into the list of open page 433 for type, list in self.opened_pages.iteritems(): 434 #Don't return any panel is the exact same page is created 435 name = str(list[0]) 436 if selected_page.window_name == name: 437 del self.opened_pages[type] 438 break 485 439 486 ##resetting page487 if reset:488 if page_title in self.fit_page_name.keys():489 490 memento= self.fit_page_name[page_title][0]491 panel.reset_page(memento)492 else:493 self.fit_page_name[page_title]=ListOfState()494 #self.fit_page_name[page_title]=[]495 #self.fit_page_name[page_title].insert(0,panel.createMemento())496 497 440 -
sansview/perspectives/fitting/fitproblem.py
r7c845cb r2f189dc 16 16 ## the current model 17 17 self.model = None 18 self.model_index = None 18 19 ## if 1 this fit problem will be selected to fit , if 0 19 20 ## it will not be selected for fit … … 85 86 return self.model 86 87 87 88 def set_index(self, index): 89 """ 90 set index of the model name 91 """ 92 self.model_index = index 93 94 def get_index(self): 95 """ 96 get index of the model name 97 """ 98 return self.model_index 99 88 100 def add_plotted_data(self,data): 89 101 """ -
sansview/perspectives/fitting/fitting.py
r837a043 r2f189dc 510 510 else: 511 511 time.sleep(0.4) 512 513 512 513 def remove_plot(self, page, theory=False): 514 """ 515 remove model plot when a fit page is closed 516 """ 517 fitproblem = self.page_finder[page] 518 data = fitproblem.get_fit_data() 519 model = fitproblem.get_model() 520 if model is not None: 521 name = model.name 522 new_plot = Theory1D(x=[], y=[], dy=None) 523 new_plot.name = name 524 new_plot.xaxis(data._xaxis, data._xunit) 525 new_plot.yaxis(data._yaxis, data._yunit) 526 new_plot.group_id = data.group_id 527 new_plot.id = data.id + name 528 wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title=data.name)) 529 if theory: 530 new_plot_data = Data1D(x=[], y=[], dx=None, dy=None) 531 new_plot_data.name = data.name 532 new_plot_data.xaxis(data._xaxis, data._xunit) 533 new_plot_data.yaxis(data._yaxis, data._yunit) 534 new_plot_data.group_id = data.group_id 535 new_plot_data.id = data.id 536 wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot_data, 537 title=data.name)) 538 514 539 def _onEVT_SLICER_PANEL(self, event): 515 540 """ … … 531 556 from the plot 532 557 """ 533 self.fit_panel. _close_fitpage(event.data)558 self.fit_panel.close_page_with_data(event.data) 534 559 535 560 def _add_page_onmenu(self, name,fitproblem=None): … … 626 651 for plottable in self.panel.graph.plottables: 627 652 if plottable.name == self.panel.graph.selected_plottable: 628 #if not hasattr(plottable, "is_data"):629 630 653 if plottable.__class__.__name__=="Theory1D": 631 654 dy=numpy.zeros(len(plottable.y)) … … 633 656 dy= copy.deepcopy(plottable.dy) 634 657 635 item = self.copy_data(plottable, dy)658 item = self.copy_data(plottable, dy) 636 659 item.group_id += "data1D" 637 660 item.id +="data1D" 638 item.is_data = False661 item.is_data = False 639 662 title = item.name 640 wx.PostEvent(self.parent, NewPlotEvent(plot=item, title=str(title))) 663 title = 'Data created from Theory' 664 wx.PostEvent(self.parent, NewPlotEvent(plot=item, 665 title=str(title), 666 reset=True)) 641 667 else: 642 668 item= self.copy_data(plottable, plottable.dy) … … 698 724 wx.PostEvent(self.parent, StatusEvent(status="Page was already Created")) 699 725 except: 700 wx.PostEvent(self.parent, StatusEvent(status="Creating Fit page: %s"\ 701 %sys.exc_value)) 726 raise 727 #wx.PostEvent(self.parent, StatusEvent(status="Creating Fit page: %s"\ 728 #%sys.exc_value)) 702 729 return 703 730
Note: See TracChangeset
for help on using the changeset viewer.