1 // $Id: traitmodel_interface.cpp,v 1.7 2011/03/07 06:08:53 bobgian Exp $
2 
3 /*
4  *  Copyright 2002  Peter Beerli, Mary Kuhner, Jon Yamato and Joseph Felsenstein
5  *
6  *  This software is distributed free of charge for non-commercial use
7  *  and is copyrighted.  Of course, we do not guarantee that the software
8  *  works, and are not responsible for any damage you may cause or have.
9  *
10  */
11 
12 #include <cassert>
13 
14 #include "traitmodel_interface.h"
15 #include "registry.h"
16 #include "ui_strings.h"
17 #include "ui_regid.h"
18 #include "ui_vars.h"
19 
20 //------------------------------------------------------------------------------------
21 
uiTraitModelName()22 uiTraitModelName::uiTraitModelName()
23     : GetString(uistr::traitModelName)
24 {
25 }
26 
27 //------------------------------------------------------------------------------------
28 
~uiTraitModelName()29 uiTraitModelName::~uiTraitModelName()
30 {
31 }
32 
33 //------------------------------------------------------------------------------------
34 
Get(UIVars & vars,UIId id)35 string uiTraitModelName::Get(UIVars& vars, UIId id)
36 {
37     UIRegId regID(id, vars);
38     return vars.traitmodels.GetName(regID);
39 }
40 
41 //------------------------------------------------------------------------------------
42 
SetRangepair(const string & key)43 SetRangepair::SetRangepair(const string& key)
44     : SetGetTemplate<rangepair>(key)
45 {
46 }
47 
48 //------------------------------------------------------------------------------------
49 
~SetRangepair()50 SetRangepair::~SetRangepair()
51 {
52 }
53 
54 //------------------------------------------------------------------------------------
55 
Get(UIVars & vars,UIId id)56 rangepair SetRangepair::Get(UIVars& vars, UIId id)
57 {
58     assert(false);
59     throw implementation_error("Shouldn't be able to 'Get' anything from this interface");
60 };
61 
62 //------------------------------------------------------------------------------------
63 
GetValFromString(UIVars & vars,string val)64 rangepair SetRangepair::GetValFromString(UIVars& vars, string val)
65 {
66     string::size_type colonpos = val.rfind(":");
67     string firstnum = val;
68     if (colonpos != string::npos)
69     {
70         firstnum.erase(colonpos, firstnum.size()-colonpos);
71     }
72     long int first = ProduceLongOrBarf(firstnum);
73     long int second = first;
74     if (colonpos != string::npos)
75     {
76         string secondnum = val;
77         secondnum.erase(0,colonpos+1);
78         second = ProduceLongOrBarf(secondnum);
79     }
80     if (first > second)
81     {
82         throw data_error("The second value in the range must be larger than the first.");
83     }
84     if (registry.GetConvertOutputToEliminateZeroes() && ((first == 0) || (second == 0)))
85     {
86         throw data_error("We assume that because you had no '0's for any map positions, your data follows the"
87                          " traditional biologist convention of not having a site 0, and placing site -1 next"
88                          " to site 1.  If this is incorrect, you must edit your LAMARC input file to set the"
89                          " '<convert_output_to_eliminate_zeroes>' tag to 'false'.");
90     }
91     //Now make it open-ended.
92     second++;
93     return ToSequentialIfNeeded(std::make_pair(first, second));
94 }
95 
96 //------------------------------------------------------------------------------------
97 
uiAddRangeForTraitModel()98 uiAddRangeForTraitModel::uiAddRangeForTraitModel()
99     : SetRangepair(uistr::addRangeForTraitModel)
100 {
101 }
102 
103 //------------------------------------------------------------------------------------
104 
~uiAddRangeForTraitModel()105 uiAddRangeForTraitModel::~uiAddRangeForTraitModel()
106 {
107 }
108 
109 //------------------------------------------------------------------------------------
110 
Set(UIVars & vars,UIId id,rangepair val)111 void uiAddRangeForTraitModel::Set(UIVars& vars, UIId id, rangepair val)
112 {
113     UIRegId regID(id, vars);
114     vars.traitmodels.AddRange(regID, val);
115 }
116 
117 //------------------------------------------------------------------------------------
118 
uiRemoveRangeForTraitModel()119 uiRemoveRangeForTraitModel::uiRemoveRangeForTraitModel()
120     : SetRangepair(uistr::removeRangeForTraitModel)
121 {
122 }
123 
124 //------------------------------------------------------------------------------------
125 
~uiRemoveRangeForTraitModel()126 uiRemoveRangeForTraitModel::~uiRemoveRangeForTraitModel()
127 {
128 }
129 
130 //------------------------------------------------------------------------------------
131 
Set(UIVars & vars,UIId id,rangepair val)132 void uiRemoveRangeForTraitModel::Set(UIVars& vars, UIId id, rangepair val)
133 {
134     UIRegId regID(id, vars);
135     vars.traitmodels.RemoveRange(regID, val);
136 }
137 
138 //------------------------------------------------------------------------------------
139 
uiSetTraitModelRangeToPoint()140 uiSetTraitModelRangeToPoint::uiSetTraitModelRangeToPoint()
141     : SetGetLong(uistr::traitModelRangeToPoint)
142 {
143 }
144 
145 //------------------------------------------------------------------------------------
146 
~uiSetTraitModelRangeToPoint()147 uiSetTraitModelRangeToPoint::~uiSetTraitModelRangeToPoint()
148 {
149 }
150 
151 //------------------------------------------------------------------------------------
152 
Set(UIVars & vars,UIId id,long int val)153 void uiSetTraitModelRangeToPoint::Set(UIVars& vars, UIId id, long int val)
154 {
155     UIRegId regID(id, vars);
156     if (registry.GetConvertOutputToEliminateZeroes() && val == 0)
157     {
158         throw data_error("We assume that because you had no '0's for any map positions, your data follows"
159                          " the traditional biologist convention of not having a site 0, and placing site"
160                          " -1 next to site 1.  If this is incorrect, you must edit your LAMARC input file"
161                          " to set the 'convert_output_to_eliminate_zeroes' tag to 'false'.");
162     }
163     val = ToSequentialIfNeeded(val);
164     vars.traitmodels.SetRangeToPoint(regID, val);
165 }
166 
167 //------------------------------------------------------------------------------------
168 
Get(UIVars & vars,UIId id)169 long int uiSetTraitModelRangeToPoint::Get(UIVars& vars, UIId id)
170 {
171     assert(false);
172     throw implementation_error("Shouldn't be able to 'Get' anything from this interface");
173 }
174 
175 //------------------------------------------------------------------------------------
176 
uiValidMovingLoci()177 uiValidMovingLoci::uiValidMovingLoci()
178     : GetUIIdVec1d(uistr::validMovingLoci)
179 {
180 }
181 
182 //------------------------------------------------------------------------------------
183 
~uiValidMovingLoci()184 uiValidMovingLoci::~uiValidMovingLoci()
185 {
186 }
187 
188 //------------------------------------------------------------------------------------
189 
Get(UIVars & vars,UIId id)190 UIIdVec1d uiValidMovingLoci::Get(UIVars& vars, UIId id)
191 {
192     vector<UIRegId> regIDs = vars.traitmodels.GetRegIDs();
193     UIIdVec1d uiIDs;
194     for (vector<UIRegId>::iterator regID = regIDs.begin(); regID != regIDs.end(); regID++)
195     {
196         UIId id(regID->GetRegion(), regID->GetLocus());
197         uiIDs.push_back(id);
198     }
199     return uiIDs;
200 }
201 
202 //------------------------------------------------------------------------------------
203 
uiTraitModelFloat()204 uiTraitModelFloat::uiTraitModelFloat()
205     : SetGetNoval(uistr::traitAnalysisFloat)
206 {
207 }
208 
209 //------------------------------------------------------------------------------------
210 
~uiTraitModelFloat()211 uiTraitModelFloat::~uiTraitModelFloat()
212 {
213 }
214 
215 //------------------------------------------------------------------------------------
216 
Set(UIVars & vars,UIId id,noval val)217 void uiTraitModelFloat::Set(UIVars& vars, UIId id,noval val)
218 {
219     UIRegId regID(id, vars);
220     vars.traitmodels.SetAnalysisType(regID, mloc_mapfloat);
221 }
222 
223 //------------------------------------------------------------------------------------
224 
uiTraitModelJump()225 uiTraitModelJump::uiTraitModelJump()
226     : SetGetNoval(uistr::traitAnalysisJump)
227 {
228 }
229 
230 //------------------------------------------------------------------------------------
231 
~uiTraitModelJump()232 uiTraitModelJump::~uiTraitModelJump()
233 {
234 }
235 
236 //------------------------------------------------------------------------------------
237 
Set(UIVars & vars,UIId id,noval val)238 void uiTraitModelJump::Set(UIVars& vars, UIId id,noval val)
239 {
240     UIRegId regID(id, vars);
241     vars.traitmodels.SetAnalysisType(regID, mloc_mapjump);
242 }
243 
244 //------------------------------------------------------------------------------------
245 
uiTraitModelData()246 uiTraitModelData::uiTraitModelData()
247     : SetGetNoval(uistr::traitAnalysisData)
248 {
249 }
250 
251 //------------------------------------------------------------------------------------
252 
~uiTraitModelData()253 uiTraitModelData::~uiTraitModelData()
254 {
255 }
256 
257 //------------------------------------------------------------------------------------
258 
Set(UIVars & vars,UIId id,noval val)259 void uiTraitModelData::Set(UIVars& vars, UIId id,noval val)
260 {
261     UIRegId regID(id, vars);
262     vars.traitmodels.SetAnalysisType(regID, mloc_data);
263 }
264 
265 //------------------------------------------------------------------------------------
266 
uiTraitModelPartition()267 uiTraitModelPartition::uiTraitModelPartition()
268     : SetGetNoval(uistr::traitAnalysisPartition)
269 {
270 }
271 
272 //------------------------------------------------------------------------------------
273 
~uiTraitModelPartition()274 uiTraitModelPartition::~uiTraitModelPartition()
275 {
276 }
277 
278 //------------------------------------------------------------------------------------
279 
Set(UIVars & vars,UIId id,noval val)280 void uiTraitModelPartition::Set(UIVars& vars, UIId id,noval val)
281 {
282     UIRegId regID(id, vars);
283     vars.traitmodels.SetAnalysisType(regID, mloc_partition);
284 }
285 
286 //____________________________________________________________________________________
287