source: trunk/source/intercoms/src/G4UIcmdWith3VectorAndUnit.cc@ 1157

Last change on this file since 1157 was 1016, checked in by garnier, 17 years ago

update

File size: 5.2 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// $Id: G4UIcmdWith3VectorAndUnit.cc,v 1.9 2006/06/29 19:08:41 gunter Exp $
28// GEANT4 tag $Name: geant4-09-02 $
29//
30//
31
32#include "G4UIcmdWith3VectorAndUnit.hh"
33#include "G4Tokenizer.hh"
34#include "G4UnitsTable.hh"
35#include <sstream>
36
37G4UIcmdWith3VectorAndUnit::G4UIcmdWith3VectorAndUnit
38(const char * theCommandPath,G4UImessenger * theMessenger)
39:G4UIcommand(theCommandPath,theMessenger)
40{
41 G4UIparameter * dblParamX = new G4UIparameter('d');
42 SetParameter(dblParamX);
43 G4UIparameter * dblParamY = new G4UIparameter('d');
44 SetParameter(dblParamY);
45 G4UIparameter * dblParamZ = new G4UIparameter('d');
46 SetParameter(dblParamZ);
47 G4UIparameter * untParam = new G4UIparameter('s');
48 SetParameter(untParam);
49 untParam->SetParameterName("Unit");
50}
51
52G4ThreeVector G4UIcmdWith3VectorAndUnit::GetNew3VectorValue(const char* paramString)
53{
54 return ConvertToDimensioned3Vector(paramString);
55}
56
57G4ThreeVector G4UIcmdWith3VectorAndUnit::GetNew3VectorRawValue(const char* paramString)
58{
59 G4double vx;
60 G4double vy;
61 G4double vz;
62 char unts[30];
63 std::istringstream is(paramString);
64 is >> vx >> vy >> vz >> unts;
65 return G4ThreeVector(vx,vy,vz);
66}
67
68G4double G4UIcmdWith3VectorAndUnit::GetNewUnitValue(const char* paramString)
69{
70 G4double vx;
71 G4double vy;
72 G4double vz;
73 char unts[30];
74 std::istringstream is(paramString);
75 is >> vx >> vy >> vz >> unts;
76 G4String unt = unts;
77 return ValueOf(unt);
78}
79
80G4String G4UIcmdWith3VectorAndUnit::ConvertToStringWithBestUnit(G4ThreeVector vec)
81{
82 G4UIparameter* unitParam = GetParameter(3);
83 G4String canList = unitParam->GetParameterCandidates();
84 G4Tokenizer candidateTokenizer(canList);
85 G4String aToken = candidateTokenizer();
86
87 std::ostringstream os;
88 os << G4BestUnit(vec,CategoryOf(aToken));
89 G4String st = os.str();
90
91 return st;
92}
93
94G4String G4UIcmdWith3VectorAndUnit::ConvertToStringWithDefaultUnit(G4ThreeVector vec)
95{
96 G4UIparameter* unitParam = GetParameter(3);
97 G4String st;
98 if(unitParam->IsOmittable())
99 { st = ConvertToString(vec,unitParam->GetDefaultValue()); }
100 else
101 { st = ConvertToStringWithBestUnit(vec); }
102 return st;
103}
104
105void G4UIcmdWith3VectorAndUnit::SetParameterName
106(const char * theNameX,const char * theNameY,const char * theNameZ,
107G4bool omittable,G4bool currentAsDefault)
108{
109 G4UIparameter * theParamX = GetParameter(0);
110 theParamX->SetParameterName(theNameX);
111 theParamX->SetOmittable(omittable);
112 theParamX->SetCurrentAsDefault(currentAsDefault);
113 G4UIparameter * theParamY = GetParameter(1);
114 theParamY->SetParameterName(theNameY);
115 theParamY->SetOmittable(omittable);
116 theParamY->SetCurrentAsDefault(currentAsDefault);
117 G4UIparameter * theParamZ = GetParameter(2);
118 theParamZ->SetParameterName(theNameZ);
119 theParamZ->SetOmittable(omittable);
120 theParamZ->SetCurrentAsDefault(currentAsDefault);
121}
122
123void G4UIcmdWith3VectorAndUnit::SetDefaultValue(G4ThreeVector vec)
124{
125 G4UIparameter * theParamX = GetParameter(0);
126 theParamX->SetDefaultValue(vec.x());
127 G4UIparameter * theParamY = GetParameter(1);
128 theParamY->SetDefaultValue(vec.y());
129 G4UIparameter * theParamZ = GetParameter(2);
130 theParamZ->SetDefaultValue(vec.z());
131}
132
133void G4UIcmdWith3VectorAndUnit::SetUnitCategory(const char * unitCategory)
134{
135 SetUnitCandidates(UnitsList(unitCategory));
136}
137
138void G4UIcmdWith3VectorAndUnit::SetUnitCandidates(const char * candidateList)
139{
140 G4UIparameter * untParam = GetParameter(3);
141 G4String canList = candidateList;
142 untParam->SetParameterCandidates(canList);
143}
144
145void G4UIcmdWith3VectorAndUnit::SetDefaultUnit(const char * defUnit)
146{
147 G4UIparameter * untParam = GetParameter(3);
148 untParam->SetOmittable(true);
149 untParam->SetDefaultValue(defUnit);
150 SetUnitCategory(CategoryOf(defUnit));
151}
152
Note: See TracBrowser for help on using the repository browser.