1 | |
---|
2 | |
---|
3 | import copy |
---|
4 | |
---|
5 | class PageState(object): |
---|
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 = {} |
---|
17 | ## reset True change the state of exsiting button |
---|
18 | self.reset = False |
---|
19 | #Data used for fitting |
---|
20 | self.data = data |
---|
21 | # flag to allow data2D plot |
---|
22 | self.enable2D = False |
---|
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 |
---|
32 | ##page name |
---|
33 | self.page_name = "" |
---|
34 | # Contains link between model ,all its parameters, and panel organization |
---|
35 | self.parameters =[] |
---|
36 | # Contains list of parameters that cannot be fitted and reference to |
---|
37 | #panel objects |
---|
38 | self.fixed_param =[] |
---|
39 | # Contains list of parameters with dispersity and reference to |
---|
40 | #panel objects |
---|
41 | self.fittable_param =[] |
---|
42 | #list of dispersion paramaters |
---|
43 | self.disp_list =[] |
---|
44 | #contains link between a model and selected parameters to fit |
---|
45 | self.param_toFit =[] |
---|
46 | ##dictionary of model type and model class |
---|
47 | self.model_list_box = None |
---|
48 | ## save the state of the context menu |
---|
49 | self.saved_states={} |
---|
50 | ## save current value of combobox |
---|
51 | self.formfactorcombobox = "" |
---|
52 | self.structurecombobox = "" |
---|
53 | ## the indice of the current selection |
---|
54 | self.disp_box = 0 |
---|
55 | ## Qrange |
---|
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 |
---|
66 | |
---|
67 | |
---|
68 | def save_data(self, data): |
---|
69 | """ |
---|
70 | Save data |
---|
71 | """ |
---|
72 | self.data = copy.deepcopy(data) |
---|
73 | |
---|
74 | |
---|
75 | def clone(self): |
---|
76 | model=None |
---|
77 | if self.model !=None: |
---|
78 | model = self.model.clone() |
---|
79 | |
---|
80 | obj = PageState( self.parent,model= model ) |
---|
81 | obj.data = copy.deepcopy(self.data) |
---|
82 | obj.model_list_box = copy.deepcopy(self.model_list_box) |
---|
83 | obj.manager = self.manager |
---|
84 | obj.event_owner = self.event_owner |
---|
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) |
---|
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) |
---|
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 | |
---|
101 | |
---|
102 | return obj |
---|
103 | |
---|
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 | |
---|
127 | |
---|