#include <G4TrajectoryDrawByAttribute.hh>
Inheritance diagram for G4TrajectoryDrawByAttribute:
Public Member Functions | |
G4TrajectoryDrawByAttribute (const G4String &name="Unspecified", G4VisTrajContext *context=0) | |
virtual | ~G4TrajectoryDrawByAttribute () |
virtual void | Draw (const G4VTrajectory &trajectory, const G4int &i_mode=0, const G4bool &visible=true) const |
virtual void | Draw (const G4VTrajectory &trajectory, const G4bool &visible=true) const |
virtual void | Print (std::ostream &ostr) const |
void | Set (const G4String &attribute) |
void | AddIntervalContext (const G4String &name, G4VisTrajContext *context) |
void | AddValueContext (const G4String &name, G4VisTrajContext *context) |
Definition at line 42 of file G4TrajectoryDrawByAttribute.hh.
G4TrajectoryDrawByAttribute::G4TrajectoryDrawByAttribute | ( | const G4String & | name = "Unspecified" , |
|
G4VisTrajContext * | context = 0 | |||
) |
Definition at line 41 of file G4TrajectoryDrawByAttribute.cc.
00042 :G4VTrajectoryModel(name, context) 00043 ,fAttName("") 00044 ,fFirst(true) 00045 ,fWarnedMissingAttribute(false) 00046 ,filter(0) 00047 {}
G4TrajectoryDrawByAttribute::~G4TrajectoryDrawByAttribute | ( | ) | [virtual] |
Definition at line 49 of file G4TrajectoryDrawByAttribute.cc.
00050 { 00051 ContextMap::iterator iter = fContextMap.begin(); 00052 00053 while (iter != fContextMap.end()) { 00054 delete iter->second; 00055 iter++; 00056 } 00057 00058 delete filter; 00059 }
void G4TrajectoryDrawByAttribute::AddIntervalContext | ( | const G4String & | name, | |
G4VisTrajContext * | context | |||
) |
Definition at line 215 of file G4TrajectoryDrawByAttribute.cc.
References FatalErrorInArgument, and G4Exception().
00216 { 00217 // Takes ownership of context 00218 std::pair<G4String, Config> myPair(name, G4TrajectoryDrawByAttribute::Interval); 00219 00220 ContextMap::iterator iter = fContextMap.find(myPair); 00221 00222 if (iter != fContextMap.end()) { 00223 G4ExceptionDescription ed; 00224 ed <<"Interval "<< name <<" already exists"; 00225 G4Exception 00226 ("G4TrajectoryDrawByAttribute::AddIntervalContext", 00227 "modeling0119", FatalErrorInArgument, ed, "Invalid interval"); 00228 } 00229 00230 fContextMap[myPair] = context; 00231 }
void G4TrajectoryDrawByAttribute::AddValueContext | ( | const G4String & | name, | |
G4VisTrajContext * | context | |||
) |
Definition at line 234 of file G4TrajectoryDrawByAttribute.cc.
References FatalErrorInArgument, and G4Exception().
00235 { 00236 // Takes ownership of context 00237 std::pair<G4String, Config> myPair(name, G4TrajectoryDrawByAttribute::SingleValue); 00238 00239 ContextMap::iterator iter = fContextMap.find(myPair); 00240 00241 if (iter != fContextMap.end()) { 00242 G4ExceptionDescription ed; 00243 ed <<"Single value "<< name <<" already exists"; 00244 G4Exception 00245 ("G4TrajectoryDrawByAttribute::AddSingleValueContext", 00246 "modeling0120", FatalErrorInArgument, ed, "Invalid value"); 00247 } 00248 00249 fContextMap[myPair] = context; 00250 }
void G4TrajectoryDrawByAttribute::Draw | ( | const G4VTrajectory & | trajectory, | |
const G4bool & | visible = true | |||
) | const [virtual] |
Implements G4VTrajectoryModel.
Definition at line 70 of file G4TrajectoryDrawByAttribute.cc.
References G4TrajectoryDrawerUtils::DrawLineAndPoints(), G4AttUtils::ExtractAttDef(), G4AttUtils::ExtractAttValue(), G4cout, G4endl, G4Exception(), G4VTrajectoryModel::GetContext(), G4AttFilterUtils::GetNewFilter(), G4VAttValueFilter::GetValidElement(), G4AttValue::GetValue(), G4VTrajectoryModel::GetVerbose(), G4String::isNull(), JustWarning, G4VAttValueFilter::LoadIntervalElement(), G4VAttValueFilter::LoadSingleValueElement(), G4VTrajectoryModel::Name(), G4VisTrajContext::Print(), and G4VisTrajContext::SetVisible().
00072 { 00073 // Return if attribute name has not been set. Just print one warning 00074 if (fAttName.isNull()) { 00075 00076 if (!fWarnedMissingAttribute) { 00077 G4ExceptionDescription ed; 00078 ed<<"Null attribute name"; 00079 G4Exception("G4TrajectoryDrawByAttribute::Draw", 00080 "modeling0116", 00081 JustWarning, ed); 00082 fWarnedMissingAttribute = true; 00083 } 00084 00085 return; 00086 } 00087 00088 // Basically cache data loaded filter for efficiency 00089 if (fFirst) { 00090 00091 fFirst = false; 00092 00093 // Get attribute definition 00094 G4AttDef attDef; 00095 00096 // Expect definition to exist 00097 if (!G4AttUtils::ExtractAttDef(object, fAttName, attDef)) { 00098 static G4bool warnedUnableToExtract = false; 00099 if (!warnedUnableToExtract) { 00100 G4ExceptionDescription ed; 00101 ed <<"Unable to extract attribute definition named "<<fAttName; 00102 G4Exception 00103 ("G4TrajectoryDrawByAttribute::Draw", 00104 "modeling0117", JustWarning, ed, "Invalid attribute name"); 00105 G4cout << "Available attributes:\n" 00106 << object.GetAttDefs(); 00107 warnedUnableToExtract = true; 00108 } 00109 return; 00110 } 00111 00112 // Get new G4AttValue filter 00113 filter = G4AttFilterUtils::GetNewFilter(attDef); 00114 assert (0 != filter); 00115 00116 // Load both interval and single valued data. Single valued data should 00117 // override interval data. 00118 ContextMap::const_iterator iter = fContextMap.begin(); 00119 00120 while (iter != fContextMap.end()) { 00121 if (iter->first.second == G4TrajectoryDrawByAttribute::Interval) { 00122 filter->LoadIntervalElement(iter->first.first); 00123 } 00124 else if (iter->first.second == G4TrajectoryDrawByAttribute::SingleValue) { 00125 filter->LoadSingleValueElement(iter->first.first); 00126 } 00127 iter++; 00128 } 00129 } 00130 00131 // Get attribute value 00132 G4AttValue attVal; 00133 00134 // Expect value to exist 00135 if (!G4AttUtils::ExtractAttValue(object, fAttName, attVal)) { 00136 static G4bool warnedUnableToExtract = false; 00137 if (!warnedUnableToExtract) { 00138 G4ExceptionDescription ed; 00139 ed <<"Unable to extract attribute value named "<<fAttName; 00140 G4Exception 00141 ("G4TrajectoryDrawByAttribute::Draw", 00142 "modeling0118", JustWarning, ed, "Invalid attribute name"); 00143 G4cout << "Available attributes:\n" 00144 << object.GetAttDefs(); 00145 warnedUnableToExtract = true; 00146 } 00147 return; 00148 } 00149 00150 G4VisTrajContext myContext(GetContext()); 00151 G4String key; 00152 00153 // If attribute value passes filter, get corresponding interval/single value 00154 // key loaded into G4AttValue filter. 00155 if (filter->GetValidElement(attVal, key)) { 00156 00157 // Extract context corresponding to valid key. 00158 // Single value match should have overriden interval match. 00159 ContextMap::const_iterator iter = fContextMap.begin(); 00160 00161 G4bool gotContext(false); 00162 00163 while (!gotContext && (iter != fContextMap.end())) { 00164 if (iter->first.first == key) { 00165 myContext = *(iter->second); 00166 gotContext = true; 00167 } 00168 iter++; 00169 } 00170 00171 assert (gotContext); 00172 } 00173 00174 myContext.SetVisible(visible); 00175 00176 if (GetVerbose()) { 00177 G4cout<<"G4TrajectoryDrawByAttribute drawer named "<<Name(); 00178 G4cout<<", drawing style selected according to value of attribute "<<fAttName; 00179 G4cout<<" : "<<attVal.GetValue()<<". Selected context:"<<G4endl; 00180 myContext.Print(G4cout); 00181 } 00182 00183 // Draw the trajectory 00184 G4TrajectoryDrawerUtils::DrawLineAndPoints(object, myContext); 00185 }
void G4TrajectoryDrawByAttribute::Draw | ( | const G4VTrajectory & | trajectory, | |
const G4int & | i_mode = 0 , |
|||
const G4bool & | visible = true | |||
) | const [virtual] |
Implements G4VTrajectoryModel.
Definition at line 62 of file G4TrajectoryDrawByAttribute.cc.
00065 { 00066 Draw(object, visible); 00067 }
void G4TrajectoryDrawByAttribute::Print | ( | std::ostream & | ostr | ) | const [virtual] |
Implements G4VTrajectoryModel.
Definition at line 188 of file G4TrajectoryDrawByAttribute.cc.
References G4endl, G4VTrajectoryModel::GetContext(), G4VTrajectoryModel::Name(), and G4VisTrajContext::Print().
00189 { 00190 ostr<<"G4TrajectoryDrawByAttribute, dumping configuration for model named "<< Name() <<":"<<std::endl;; 00191 00192 ostr<<"Default configuration:"<<G4endl; 00193 GetContext().Print(ostr); 00194 00195 ostr<<"\nAttribute name "<<fAttName<<std::endl; 00196 ostr<<"\nKey<->Context map dump:"<<std::endl; 00197 00198 ContextMap::const_iterator iter = fContextMap.begin(); 00199 00200 while (iter != fContextMap.end()) { 00201 ostr<<"Context for key "<<iter->first.first<<":"<<std::endl; 00202 iter->second->Print(ostr); 00203 00204 iter++; 00205 } 00206 }
void G4TrajectoryDrawByAttribute::Set | ( | const G4String & | attribute | ) |