Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
G4TrajectoryDrawByAttribute.cc
이 파일의 문서화 페이지로 가기
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 // $Id: G4TrajectoryDrawByAttribute.cc 78838 2014-01-28 08:46:17Z gcosmo $
27 //
28 // Jane Tinslay August 2006
29 //
31 #include "G4AttDef.hh"
32 #include "G4AttFilterUtils.hh"
33 #include "G4AttUtils.hh"
34 #include "G4AttValue.hh"
36 #include "G4VAttValueFilter.hh"
37 #include "G4VisTrajContext.hh"
38 #include "G4VTrajectory.hh"
39 #include <assert.h>
40 
42  :G4VTrajectoryModel(name, context)
43  ,fAttName("")
44  ,fFirst(true)
45  ,fWarnedMissingAttribute(false)
46  ,filter(0)
47 {}
48 
50 {
51  ContextMap::iterator iter = fContextMap.begin();
52 
53  while (iter != fContextMap.end()) {
54  delete iter->second;
55  iter++;
56  }
57 
58  delete filter;
59 }
60 
61 void
63  const G4bool& visible) const
64 {
65  // Return if attribute name has not been set. Just print one warning
66  if (fAttName.isNull()) {
67 
70  ed<<"Null attribute name";
71  G4Exception("G4TrajectoryDrawByAttribute::Draw",
72  "modeling0116",
73  JustWarning, ed);
75  }
76 
77  return;
78  }
79 
80  // Basically cache data loaded filter for efficiency
81  if (fFirst) {
82 
83  fFirst = false;
84 
85  // Get attribute definition
86  G4AttDef attDef;
87 
88  // Expect definition to exist
89  if (!G4AttUtils::ExtractAttDef(object, fAttName, attDef)) {
90  static G4bool warnedUnableToExtract = false;
91  if (!warnedUnableToExtract) {
93  ed <<"Unable to extract attribute definition named "<<fAttName;
95  ("G4TrajectoryDrawByAttribute::Draw",
96  "modeling0117", JustWarning, ed, ". Invalid attribute name");
97  G4cout << "Available attributes:\n"
98  << *object.GetAttDefs();
99  warnedUnableToExtract = true;
100  }
101  return;
102  }
103 
104  // Get new G4AttValue filter
106  assert (0 != filter);
107 
108  // Load both interval and single valued data. Single valued data should
109  // override interval data.
110  ContextMap::const_iterator iter = fContextMap.begin();
111 
112  while (iter != fContextMap.end()) {
113  if (iter->first.second == G4TrajectoryDrawByAttribute::Interval) {
114  filter->LoadIntervalElement(iter->first.first);
115  }
116  else if (iter->first.second == G4TrajectoryDrawByAttribute::SingleValue) {
117  filter->LoadSingleValueElement(iter->first.first);
118  }
119  iter++;
120  }
121  }
122 
123  // Get attribute value
124  G4AttValue attVal;
125 
126  // Expect value to exist
127  if (!G4AttUtils::ExtractAttValue(object, fAttName, attVal)) {
128  static G4bool warnedUnableToExtract = false;
129  if (!warnedUnableToExtract) {
131  ed <<"Unable to extract attribute value named "<<fAttName;
133  ("G4TrajectoryDrawByAttribute::Draw",
134  "modeling0118", JustWarning, ed, ". Invalid attribute name");
135  G4cout << "Available attributes:\n"
136  << *object.GetAttDefs();
137  warnedUnableToExtract = true;
138  }
139  return;
140  }
141 
142  G4VisTrajContext myContext(GetContext());
143  G4String key;
144 
145  // If attribute value passes filter, get corresponding interval/single value
146  // key loaded into G4AttValue filter.
147  if (filter->GetValidElement(attVal, key)) {
148 
149  // Extract context corresponding to valid key.
150  // Single value match should have overriden interval match.
151  ContextMap::const_iterator iter = fContextMap.begin();
152 
153  G4bool gotContext(false);
154 
155  while (!gotContext && (iter != fContextMap.end())) {
156  if (iter->first.first == key) {
157  myContext = *(iter->second);
158  gotContext = true;
159  }
160  iter++;
161  }
162 
163  assert (gotContext);
164  }
165 
166  myContext.SetVisible(visible);
167 
168  if (GetVerbose()) {
169  G4cout<<"G4TrajectoryDrawByAttribute drawer named "<<Name();
170  G4cout<<", drawing style selected according to value of attribute "<<fAttName;
171  G4cout<<" : "<<attVal.GetValue()<<". Selected context:"<<G4endl;
172  myContext.Print(G4cout);
173  }
174 
175  // Draw the trajectory
177 }
178 
179 void
180 G4TrajectoryDrawByAttribute::Print(std::ostream& ostr) const
181 {
182  ostr<<"G4TrajectoryDrawByAttribute, dumping configuration for model named "<< Name() <<":"<<std::endl;;
183 
184  ostr<<"Default configuration:"<<G4endl;
185  GetContext().Print(ostr);
186 
187  ostr<<"\nAttribute name "<<fAttName<<std::endl;
188  ostr<<"\nKey<->Context map dump:"<<std::endl;
189 
190  ContextMap::const_iterator iter = fContextMap.begin();
191 
192  while (iter != fContextMap.end()) {
193  ostr<<"Context for key "<<iter->first.first<<":"<<std::endl;
194  iter->second->Print(ostr);
195 
196  iter++;
197  }
198 }
199 
200 void
202 {
203  fAttName = name;
204 }
205 
206 void
208 {
209  // Takes ownership of context
210  std::pair<G4String, Config> myPair(name, G4TrajectoryDrawByAttribute::Interval);
211 
212  ContextMap::iterator iter = fContextMap.find(myPair);
213 
214  if (iter != fContextMap.end()) {
216  ed <<"Interval "<< name <<" already exists";
218  ("G4TrajectoryDrawByAttribute::AddIntervalContext",
219  "modeling0119", FatalErrorInArgument, ed, ". Invalid interval");
220  }
221 
222  fContextMap[myPair] = context;
223 }
224 
225 void
227 {
228  // Takes ownership of context
229  std::pair<G4String, Config> myPair(name, G4TrajectoryDrawByAttribute::SingleValue);
230 
231  ContextMap::iterator iter = fContextMap.find(myPair);
232 
233  if (iter != fContextMap.end()) {
235  ed <<"Single value "<< name <<" already exists";
237  ("G4TrajectoryDrawByAttribute::AddSingleValueContext",
238  "modeling0120", FatalErrorInArgument, ed, ". Invalid value");
239  }
240 
241  fContextMap[myPair] = context;
242 }
void DrawLineAndPoints(const G4VTrajectory &traj, const G4VisTrajContext &)
const XML_Char * name
Definition: expat.h:151
const G4VisTrajContext & GetContext() const
G4bool isNull() const
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:45
virtual void Print(std::ostream &ostr) const
G4TrajectoryDrawByAttribute(const G4String &name="Unspecified", G4VisTrajContext *context=0)
#define G4endl
Definition: G4ios.hh:61
G4VAttValueFilter * GetNewFilter(const G4AttDef &def)
void SetVisible(const G4bool &visible)
virtual void LoadIntervalElement(const G4String &)=0
bool G4bool
Definition: G4Types.hh:79
void AddValueContext(const G4String &name, G4VisTrajContext *context)
void AddIntervalContext(const G4String &name, G4VisTrajContext *context)
virtual void Draw(const G4VTrajectory &trajectory, const G4bool &visible=true) const
G4String Name() const
void Set(const G4String &attribute)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.hh:65
const XML_Char * context
Definition: expat.h:434
G4GLOB_DLL std::ostream G4cout
G4bool GetVerbose() const
G4bool ExtractAttValue(const T &object, const G4String &name, G4AttValue &attVal)
Definition: G4AttUtils.hh:76
G4bool ExtractAttDef(const T &object, const G4String &name, G4AttDef &def)
Definition: G4AttUtils.hh:62
virtual G4bool GetValidElement(const G4AttValue &, G4String &) const =0
void Print(std::ostream &ostr) const
virtual void LoadSingleValueElement(const G4String &)=0
const G4String & GetValue() const
Definition: G4AttValue.hh:64