source: trunk/examples/advanced/radiation_monitor/generalPurpose/src/RadmonLayoutEntityWithAttributes.cc @ 1319

Last change on this file since 1319 was 807, checked in by garnier, 16 years ago

update

File size: 9.0 KB
Line 
1//
2// ********************************************************************
3// * License and Disclaimer                                           *
4// *                                                                  *
5// * The  Geant4 software  is  copyright of the Copyright Holders  of *
6// * the Geant4 Collaboration.  It is provided  under  the terms  and *
7// * conditions of the Geant4 Software License,  included in the file *
8// * LICENSE and available at  http://cern.ch/geant4/license .  These *
9// * include a list of copyright holders.                             *
10// *                                                                  *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work  make  any representation or  warranty, express or implied, *
14// * regarding  this  software system or assume any liability for its *
15// * use.  Please see the license in the file  LICENSE  and URL above *
16// * for the full disclaimer and the limitation of liability.         *
17// *                                                                  *
18// * This  code  implementation is the result of  the  scientific and *
19// * technical work of the GEANT4 collaboration.                      *
20// * By using,  copying,  modifying or  distributing the software (or *
21// * any work based  on the software)  you  agree  to acknowledge its *
22// * use  in  resulting  scientific  publications,  and indicate your *
23// * acceptance of all terms of the Geant4 Software license.          *
24// ********************************************************************
25//
26//
27// File name:     RadmonLayoutEntityWithAttributes.cc
28// Creation date: Sep 2005
29// Main author:   Riccardo Capra <capra@ge.infn.it>
30//
31// Id:            $Id: RadmonLayoutEntityWithAttributes.cc,v 1.5 2006/06/29 16:14:45 gunter Exp $
32// Tag:           $Name:  $
33//
34
35// Include files
36#include "RadmonLayoutEntityWithAttributes.hh"
37#include "RadmonDumpStyle.hh"
38#include "RadmonMessenger.hh"
39#include "G4UIcommand.hh"
40#include <iomanip>
41
42
43
44G4int                                           RadmonLayoutEntityWithAttributes :: GetNAttributes(void) const
45{
46 return attributesVector.size();
47}
48
49
50
51const G4String &                                RadmonLayoutEntityWithAttributes :: GetAttributeName(G4int index) const
52{
53 return attributesVector[index].first;
54}
55
56
57 
58G4String                                        RadmonLayoutEntityWithAttributes :: GetAttribute(const G4String & attributeName, const G4String & defaultValue) const
59{
60 AttributesVector::const_iterator i(attributesVector.begin());
61 AttributesVector::const_iterator end(attributesVector.end());
62 
63 while (i!=end)
64 {
65  if (i->first==attributeName)
66   return i->second;
67 
68  i++;
69 }
70 
71 return defaultValue;
72}
73
74
75
76G4bool                                          RadmonLayoutEntityWithAttributes :: ExistsAttribute(const G4String & attributeName) const
77{
78 AttributesVector::const_iterator i(attributesVector.begin());
79 AttributesVector::const_iterator end(attributesVector.end());
80 
81 while (i!=end)
82 {
83  if (i->first==attributeName)
84   return true;
85 
86  i++;
87 }
88 
89 return false;
90}
91
92
93
94void                                            RadmonLayoutEntityWithAttributes :: SetAttribute(const G4String & attributeName, const G4String & value)
95{
96 AttributesVector::iterator i(attributesVector.begin());
97 AttributesVector::iterator end(attributesVector.end());
98 
99 while (i!=end)
100 {
101  if (i->first==attributeName)
102  {
103   i->second=value;
104   return;
105  }
106 
107  i++;
108 }
109
110 size_t n(attributesVector.size());
111 attributesVector.resize(n+1);
112 attributesVector[n].first=attributeName;
113 attributesVector[n].second=value;
114}
115
116
117
118void                                            RadmonLayoutEntityWithAttributes :: ClearAttribute(const G4String & attributeName)
119{
120 AttributesVector::iterator i(attributesVector.begin());
121 AttributesVector::iterator end(attributesVector.end());
122 
123 while (i!=end)
124 {
125  if (i->first==attributeName)
126  {
127   attributesVector.erase(i);
128   return;
129  }
130 
131  i++;
132 }
133}
134
135
136
137void                                            RadmonLayoutEntityWithAttributes :: ClearAllAttributes(void)
138{
139 attributesVector.clear();
140}
141
142
143
144
145
146G4double                                        RadmonLayoutEntityWithAttributes :: GetAttributeAsDouble(const G4String & attributeName, double defaultValue) const
147{
148 G4String str;
149 
150 str=GetAttribute(attributeName, "#");
151 if (str=="#")
152  return defaultValue;
153 
154 G4String args[1];
155 if (!RadmonMessenger::ProcessArguments(str, 1, args))
156  return defaultValue;
157 
158 return G4UIcommand::ConvertToDouble(args[0]);
159}
160
161
162
163G4double                                        RadmonLayoutEntityWithAttributes :: GetAttributeAsMeasure(const G4String & attributeName, const char * category, double defaultValue) const
164{
165 G4String str;
166 
167 str=GetAttribute(attributeName, "#");
168 if (str=="#")
169  return defaultValue;
170 
171 G4String args[2];
172 if (!RadmonMessenger::ProcessArguments(str, 2, args))
173  return defaultValue;
174
175 G4double unit(RadmonMessenger::GetUnit(args[1], category));
176 if (unit<=0.)
177  return defaultValue;
178 
179 return G4UIcommand::ConvertToDouble(args[0])*unit;
180}
181
182
183
184G4int                                           RadmonLayoutEntityWithAttributes :: GetAttributeAsInteger(const G4String & attributeName, G4int defaultValue) const
185{
186 G4String str;
187 
188 str=GetAttribute(attributeName, "#");
189 if (str=="#")
190  return defaultValue;
191 
192 G4String args[1];
193 if (!RadmonMessenger::ProcessArguments(str, 1, args))
194  return defaultValue;
195 
196 return G4UIcommand::ConvertToInt(args[0]);
197}
198
199
200
201
202
203G4ThreeVector                                   RadmonLayoutEntityWithAttributes :: GetAttributeAsThreeVector(const G4String & attributeName, const G4ThreeVector & defaultValue) const
204{
205 G4String str;
206 
207 str=GetAttribute(attributeName, "#");
208 if (str=="#")
209  return defaultValue;
210 
211 G4String args[3];
212 if (!RadmonMessenger::ProcessArguments(str, 3, args))
213  return defaultValue;
214
215 return G4ThreeVector(G4UIcommand::ConvertToDouble(args[0]), G4UIcommand::ConvertToDouble(args[1]), G4UIcommand::ConvertToDouble(args[2])); 
216}
217
218
219
220
221
222G4ThreeVector                                   RadmonLayoutEntityWithAttributes :: GetAttributeAsThreeVectorWithMeasure(const G4String & attributeName, const char * category, const G4ThreeVector & defaultValue) const
223{
224 G4String str;
225 
226 str=GetAttribute(attributeName, "#");
227 if (str=="#")
228  return defaultValue;
229 
230 G4String args[4];
231 if (!RadmonMessenger::ProcessArguments(str, 4, args))
232  return defaultValue;
233
234 G4double unit(RadmonMessenger::GetUnit(args[3], category));
235 if (unit<=0.)
236  return defaultValue;
237 
238 return G4ThreeVector(G4UIcommand::ConvertToDouble(args[0])*unit, G4UIcommand::ConvertToDouble(args[1])*unit, G4UIcommand::ConvertToDouble(args[2])*unit);
239}
240
241
242
243
244
245G4ThreeVector                                   RadmonLayoutEntityWithAttributes :: GetAttributeAsDirection(const G4String & attributeName, const G4ThreeVector & defaultValue) const
246{
247 G4String str;
248 
249 str=GetAttribute(attributeName, "#");
250 if (str=="#")
251  return defaultValue;
252 
253 G4String args[3];
254 if (!RadmonMessenger::ProcessArguments(str, 3, args))
255  return defaultValue;
256
257 G4double theta(RadmonMessenger::GetUnit(args[2], "Angle"));
258 if (theta<=0.)
259  return defaultValue;
260
261 G4double phi(theta*G4UIcommand::ConvertToDouble(args[1]));
262 theta*=G4UIcommand::ConvertToDouble(args[0]);
263 
264 G4ThreeVector axis;
265 axis.setRThetaPhi(1., theta/rad, phi/rad);
266 
267 return axis;
268}
269
270
271
272G4RotationMatrix                                RadmonLayoutEntityWithAttributes :: GetAttributeAsRotationMatrix(const G4String & attributeName, const G4RotationMatrix & defaultValue) const
273{
274 G4String str;
275 
276 str=GetAttribute(attributeName, "#");
277 if (str=="#")
278  return defaultValue;
279 
280 G4String args[4];
281 if (!RadmonMessenger::ProcessArguments(str, 4, args))
282  return defaultValue;
283
284 G4double theta(RadmonMessenger::GetUnit(args[3], "Angle"));
285 if (theta<=0.)
286  return defaultValue;
287
288 G4double phi(theta*G4UIcommand::ConvertToDouble(args[1]));
289 G4double delta(theta*G4UIcommand::ConvertToDouble(args[2]));
290 theta*=G4UIcommand::ConvertToDouble(args[0]);
291 
292 G4ThreeVector axis;
293 axis.setRThetaPhi(1., theta/rad, phi/rad);
294 
295 return G4RotationMatrix(axis, delta/rad);
296}
297
298
299
300
301
302void                                            RadmonLayoutEntityWithAttributes :: DumpAttributesLayout(std::ostream & out, const G4String & indent) const
303{
304 AttributesVector::const_iterator i(attributesVector.begin());
305 AttributesVector::const_iterator end(attributesVector.end());
306 
307 if (i==end)
308 {
309  out << indent << "No attributes defined.\n";
310  return;
311 }
312
313 G4int width(RADMONDUMP_INDENT_WIDTH-1-indent.length());
314 if (width<0)
315  width=0;
316 
317 G4int width2;
318 
319 while (i!=end)
320 {
321  width2=width-i->first.length();
322  if (width2<0)
323   width2=0;
324   
325  out << indent << '\"' << i->first << std::setw(width2); 
326  out.setf(std::ostream::left, std::ostream::adjustfield); 
327  out << "\""; 
328  out.setf(std::ostream::right, std::ostream::adjustfield); 
329  out << " = \"" << i->second << "\"\n";
330 
331  i++;
332 }
333}
334
335
336
337
338
339void                                            RadmonLayoutEntityWithAttributes :: CopyFrom(const RadmonLayoutEntityWithAttributes & copy)
340{
341 attributesVector=copy.attributesVector;
342}
343
Note: See TracBrowser for help on using the repository browser.