[c77d859] | 1 | |
---|
| 2 | |
---|
[6f023e8] | 3 | import copy |
---|
[c77d859] | 4 | |
---|
[cfc0913] | 5 | class PageState(object): |
---|
[c77d859] | 6 | """ |
---|
| 7 | Contains info to reconstruct a page |
---|
| 8 | """ |
---|
| 9 | def __init__(self, parent,model=None, data=None): |
---|
| 10 | |
---|
| 11 | """ |
---|
| 12 | Initialization of the Panel |
---|
| 13 | """ |
---|
| 14 | #TODO: remove this once the inheritence is cleaned up |
---|
| 15 | ## Data member to store the dispersion object created |
---|
| 16 | self._disp_obj_dict = {} |
---|
[cfc0913] | 17 | ## reset True change the state of exsiting button |
---|
| 18 | self.reset = False |
---|
[c77d859] | 19 | #Data used for fitting |
---|
| 20 | self.data = data |
---|
| 21 | # flag to allow data2D plot |
---|
[cfc0913] | 22 | self.enable2D = False |
---|
[c77d859] | 23 | # model on which the fit would be performed |
---|
| 24 | self.model = model |
---|
| 25 | #fit page manager |
---|
| 26 | self.manager = None |
---|
| 27 | #Store the parent of this panel parent |
---|
| 28 | # For this application fitpanel is the parent |
---|
| 29 | self.parent = parent |
---|
| 30 | # Event_owner is the owner of model event |
---|
| 31 | self.event_owner = None |
---|
[c9a4377] | 32 | ##page name |
---|
[cfc0913] | 33 | self.page_name = "" |
---|
[c77d859] | 34 | # Contains link between model ,all its parameters, and panel organization |
---|
[cfc0913] | 35 | self.parameters =[] |
---|
[c77d859] | 36 | # Contains list of parameters that cannot be fitted and reference to |
---|
| 37 | #panel objects |
---|
[cfc0913] | 38 | self.fixed_param =[] |
---|
[c77d859] | 39 | # Contains list of parameters with dispersity and reference to |
---|
| 40 | #panel objects |
---|
[cfc0913] | 41 | self.fittable_param =[] |
---|
[c77d859] | 42 | #list of dispersion paramaters |
---|
[cfc0913] | 43 | self.disp_list =[] |
---|
[c77d859] | 44 | #contains link between a model and selected parameters to fit |
---|
[cfc0913] | 45 | self.param_toFit =[] |
---|
[a074145] | 46 | ##dictionary of model type and model class |
---|
[cfc0913] | 47 | self.model_list_box = None |
---|
[a074145] | 48 | ## save the state of the context menu |
---|
| 49 | self.saved_states={} |
---|
[c77d859] | 50 | ## save current value of combobox |
---|
| 51 | self.formfactorcombobox = "" |
---|
| 52 | self.structurecombobox = "" |
---|
[b787e68c] | 53 | ## the indice of the current selection |
---|
| 54 | self.disp_box = 0 |
---|
[c77d859] | 55 | ## Qrange |
---|
[cfc0913] | 56 | ## Q range |
---|
| 57 | self.qmin= 0.001 |
---|
| 58 | self.qmax= 0.1 |
---|
| 59 | self.npts = None |
---|
| 60 | ## enable smearering state |
---|
| 61 | self.enable_smearer = False |
---|
| 62 | ## disperity selection |
---|
| 63 | self.enable_disp= False |
---|
| 64 | ## state of selected all check button |
---|
| 65 | self.cb1 = False |
---|
[c9a4377] | 66 | |
---|
[cfc0913] | 67 | |
---|
| 68 | def save_data(self, data): |
---|
[c77d859] | 69 | """ |
---|
[cfc0913] | 70 | Save data |
---|
[c77d859] | 71 | """ |
---|
[cfc0913] | 72 | self.data = copy.deepcopy(data) |
---|
[b787e68c] | 73 | |
---|
[cfc0913] | 74 | |
---|
[6f023e8] | 75 | def clone(self): |
---|
| 76 | model=None |
---|
| 77 | if self.model !=None: |
---|
| 78 | model = self.model.clone() |
---|
| 79 | |
---|
[cfc0913] | 80 | obj = PageState( self.parent,model= model ) |
---|
[6f023e8] | 81 | obj.data = copy.deepcopy(self.data) |
---|
[dcf29d7] | 82 | obj.model_list_box = copy.deepcopy(self.model_list_box) |
---|
| 83 | obj.manager = self.manager |
---|
| 84 | obj.event_owner = self.event_owner |
---|
[cfc0913] | 85 | obj.parameters = copy.deepcopy(self.parameters) |
---|
| 86 | obj.fixed_param = copy.deepcopy(self.fixed_param) |
---|
| 87 | obj.fittable_param = copy.deepcopy(self.fittable_param) |
---|
[b787e68c] | 88 | obj.enable_disp = copy.deepcopy(self.enable_disp) |
---|
| 89 | obj.enable_smearer = copy.deepcopy(self.enable_smearer) |
---|
| 90 | obj.disp_box = copy.deepcopy(self.disp_box) |
---|
| 91 | obj.qmin = copy.deepcopy(self.qmin) |
---|
| 92 | obj.qmax = copy.deepcopy(self.qmax) |
---|
| 93 | obj.npts = copy.deepcopy(self.npts ) |
---|
| 94 | obj.cb1 = copy.deepcopy(self.cb1) |
---|
[a074145] | 95 | for name, state in self.saved_states.iteritems(): |
---|
| 96 | copy_name = copy.deepcopy(name) |
---|
| 97 | copy_state = state.clone() |
---|
| 98 | obj.saved_states[copy_name]= copy_state |
---|
| 99 | |
---|
| 100 | |
---|
[b787e68c] | 101 | |
---|
[6f023e8] | 102 | return obj |
---|
[c77d859] | 103 | |
---|
[cfc0913] | 104 | class PageMemento(object): |
---|
| 105 | """ |
---|
| 106 | Store the state of a fitpage or model page of fitpanel |
---|
| 107 | """ |
---|
| 108 | def __init__(self, state): |
---|
| 109 | """ Initialization""" |
---|
| 110 | self.state = state |
---|
| 111 | |
---|
| 112 | def setState(self,state): |
---|
| 113 | """ |
---|
| 114 | set current state |
---|
| 115 | @param state: new state |
---|
| 116 | """ |
---|
| 117 | self.state = state |
---|
| 118 | |
---|
| 119 | def getState(self): |
---|
| 120 | """ |
---|
| 121 | @return state |
---|
| 122 | """ |
---|
| 123 | return self.state |
---|
| 124 | |
---|
| 125 | |
---|
| 126 | |
---|
[c77d859] | 127 | |
---|