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[ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /visualization/modeling/src/G4TrajectoryDrawByAttribute.cc (Version 11.3.0) and /visualization/modeling/src/G4TrajectoryDrawByAttribute.cc (Version 10.7)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
 26 //                                                 26 //
 27 // Jane Tinslay August 2006                        27 // Jane Tinslay August 2006
 28 //                                                 28 //
 29 #include "G4TrajectoryDrawByAttribute.hh"          29 #include "G4TrajectoryDrawByAttribute.hh"
 30 #include "G4AttDef.hh"                             30 #include "G4AttDef.hh"
 31 #include "G4AttFilterUtils.hh"                     31 #include "G4AttFilterUtils.hh"
 32 #include "G4AttUtils.hh"                           32 #include "G4AttUtils.hh"
 33 #include "G4AttValue.hh"                           33 #include "G4AttValue.hh"
 34 #include "G4TrajectoryDrawerUtils.hh"              34 #include "G4TrajectoryDrawerUtils.hh"
 35 #include "G4VAttValueFilter.hh"                    35 #include "G4VAttValueFilter.hh"
 36 #include "G4VisTrajContext.hh"                     36 #include "G4VisTrajContext.hh"
 37 #include "G4VTrajectory.hh"                        37 #include "G4VTrajectory.hh"
 38 #include <assert.h>                                38 #include <assert.h>
 39                                                    39 
 40 G4TrajectoryDrawByAttribute::G4TrajectoryDrawB     40 G4TrajectoryDrawByAttribute::G4TrajectoryDrawByAttribute(const G4String& name, G4VisTrajContext* context)
 41   :G4VTrajectoryModel(name, context)               41   :G4VTrajectoryModel(name, context)
 42   ,fAttName("")                                    42   ,fAttName("")
 43   ,fFirst(true)                                    43   ,fFirst(true)
 44   ,fWarnedMissingAttribute(false)                  44   ,fWarnedMissingAttribute(false)
 45   ,filter(0)                                       45   ,filter(0)
 46 {}                                                 46 {}
 47                                                    47 
 48 G4TrajectoryDrawByAttribute::~G4TrajectoryDraw     48 G4TrajectoryDrawByAttribute::~G4TrajectoryDrawByAttribute() 
 49 {                                                  49 {
 50   ContextMap::iterator iter = fContextMap.begi     50   ContextMap::iterator iter = fContextMap.begin();
 51                                                    51   
 52   while (iter != fContextMap.end()) {              52   while (iter != fContextMap.end()) {
 53     delete iter->second;                           53     delete iter->second;
 54     iter++;                                        54     iter++;
 55   }                                                55   }
 56                                                    56   
 57   delete filter;                                   57   delete filter;
 58 }                                                  58 }
 59                                                    59 
 60 void                                               60 void
 61 G4TrajectoryDrawByAttribute::Draw(const G4VTra     61 G4TrajectoryDrawByAttribute::Draw(const G4VTrajectory& object, 
 62           const G4bool& /*visible*/) const         62           const G4bool& /*visible*/) const
 63 {                                                  63 {
 64   // Return if attribute name has not been set     64   // Return if attribute name has not been set. Just print one warning
 65   if (fAttName.empty()) {                      <<  65   if (fAttName.isNull()) {
 66                                                    66 
 67     if (!fWarnedMissingAttribute) {                67     if (!fWarnedMissingAttribute) {
 68       G4ExceptionDescription ed;                   68       G4ExceptionDescription ed;
 69       ed<<"Null attribute name";                   69       ed<<"Null attribute name";
 70       G4Exception("G4TrajectoryDrawByAttribute     70       G4Exception("G4TrajectoryDrawByAttribute::Draw",
 71       "modeling0116",                              71       "modeling0116",
 72       JustWarning, ed);                            72       JustWarning, ed);
 73       fWarnedMissingAttribute = true;              73       fWarnedMissingAttribute = true;
 74     }                                              74     }
 75                                                    75     
 76     return;                                        76     return;
 77   }                                                77   }
 78                                                    78   
 79   // Basically cache data loaded filter for ef     79   // Basically cache data loaded filter for efficiency
 80   if (fFirst) {                                    80   if (fFirst) {
 81                                                    81     
 82     fFirst = false;                                82     fFirst = false;
 83                                                    83     
 84     // Get attribute definition                    84     // Get attribute definition
 85     G4AttDef attDef;                               85     G4AttDef attDef;
 86                                                    86     
 87     // Expect definition to exist                  87     // Expect definition to exist    
 88     if (!G4AttUtils::ExtractAttDef(object, fAt     88     if (!G4AttUtils::ExtractAttDef(object, fAttName, attDef)) {
 89       static G4bool warnedUnableToExtract = fa     89       static G4bool warnedUnableToExtract = false;
 90       if (!warnedUnableToExtract) {                90       if (!warnedUnableToExtract) {
 91   G4ExceptionDescription ed;                       91   G4ExceptionDescription ed;
 92   ed <<"Unable to extract attribute definition <<  92   ed <<"Unable to extract attribute definition named "<<fAttName;
 93         << "Available attributes:\n"           << 
 94         << *object.GetAttDefs();               << 
 95   G4Exception                                      93   G4Exception
 96     ("G4TrajectoryDrawByAttribute::Draw",          94     ("G4TrajectoryDrawByAttribute::Draw",
 97      "modeling0117", JustWarning, ed, ". Inval     95      "modeling0117", JustWarning, ed, ". Invalid attribute name");
                                                   >>  96   G4cout << "Available attributes:\n"
                                                   >>  97          << *object.GetAttDefs();
 98   warnedUnableToExtract = true;                    98   warnedUnableToExtract = true;
 99       }                                            99       }
100       return;                                     100       return;
101     }                                             101     }
102                                                   102     
103     // Get new G4AttValue filter                  103     // Get new G4AttValue filter
104     filter = G4AttFilterUtils::GetNewFilter(at    104     filter = G4AttFilterUtils::GetNewFilter(attDef);
105     assert (0 != filter);                         105     assert (0 != filter);
106                                                   106     
107     // Load both interval and single valued da    107     // Load both interval and single valued data. Single valued data should
108     // override interval data.                    108     // override interval data.
109     ContextMap::const_iterator iter = fContext    109     ContextMap::const_iterator iter = fContextMap.begin();
110                                                   110     
111     while (iter != fContextMap.end()) {           111     while (iter != fContextMap.end()) {
112       if (iter->first.second == G4TrajectoryDr    112       if (iter->first.second == G4TrajectoryDrawByAttribute::Interval) {
113   filter->LoadIntervalElement(iter->first.firs    113   filter->LoadIntervalElement(iter->first.first);
114       }                                           114       }
115       else if (iter->first.second == G4Traject    115       else if (iter->first.second == G4TrajectoryDrawByAttribute::SingleValue) {
116   filter->LoadSingleValueElement(iter->first.f    116   filter->LoadSingleValueElement(iter->first.first);
117       }                                           117       }
118       iter++;                                     118       iter++;
119     }                                             119     }
120   }                                               120   }
121                                                   121  
122   // Get attribute value                          122   // Get attribute value
123   G4AttValue attVal;                              123   G4AttValue attVal;
124                                                   124 
125   // Expect value to exist                        125   // Expect value to exist
126   if (!G4AttUtils::ExtractAttValue(object, fAt    126   if (!G4AttUtils::ExtractAttValue(object, fAttName, attVal)) {
127     static G4bool warnedUnableToExtract = fals    127     static G4bool warnedUnableToExtract = false;
128     if (!warnedUnableToExtract) {                 128     if (!warnedUnableToExtract) {
129       G4ExceptionDescription ed;                  129       G4ExceptionDescription ed;
130       ed <<"Unable to extract attribute defini << 130       ed <<"Unable to extract attribute value named "<<fAttName;
131       << "Available attributes:\n"             << 
132       << *object.GetAttDefs();                 << 
133       G4Exception                                 131       G4Exception
134   ("G4TrajectoryDrawByAttribute::Draw",           132   ("G4TrajectoryDrawByAttribute::Draw",
135    "modeling0118", JustWarning, ed, ". Invalid    133    "modeling0118", JustWarning, ed, ". Invalid attribute name");
                                                   >> 134   G4cout << "Available attributes:\n"
                                                   >> 135          << *object.GetAttDefs();
136       warnedUnableToExtract = true;               136       warnedUnableToExtract = true;
137     }                                             137     }
138       return;                                     138       return;
139   }                                               139   }
140                                                   140   
141   G4VisTrajContext myContext(GetContext());       141   G4VisTrajContext myContext(GetContext());
142   G4String key;                                   142   G4String key;
143                                                   143 
144   // If attribute value passes filter, get cor    144   // If attribute value passes filter, get corresponding interval/single value 
145   // key loaded into G4AttValue filter.           145   // key loaded into G4AttValue filter.
146   if (filter->GetValidElement(attVal, key)) {     146   if (filter->GetValidElement(attVal, key)) {
147                                                   147 
148     // Extract context corresponding to valid     148     // Extract context corresponding to valid key.
149     // Single value match should have override    149     // Single value match should have overriden interval match.
150     ContextMap::const_iterator iter = fContext    150     ContextMap::const_iterator iter = fContextMap.begin();
151                                                   151 
152     G4bool gotContext(false);                     152     G4bool gotContext(false);
153                                                   153 
154     while (!gotContext && (iter != fContextMap    154     while (!gotContext && (iter != fContextMap.end())) {
155       if (iter->first.first == key) {             155       if (iter->first.first == key) {
156   myContext = *(iter->second);                    156   myContext = *(iter->second);
157   gotContext = true;                              157   gotContext = true;
158       }                                           158       }
159       iter++;                                     159       iter++;
160     }                                             160     }
161                                                   161 
162     assert (gotContext);                          162     assert (gotContext);
163   }                                               163   }
164                                                   164   
165   if (GetVerbose()) {                             165   if (GetVerbose()) {
166     G4cout<<"G4TrajectoryDrawByAttribute drawe    166     G4cout<<"G4TrajectoryDrawByAttribute drawer named "<<Name();
167     G4cout<<", drawing style selected accordin    167     G4cout<<", drawing style selected according to value of attribute "<<fAttName;
168     G4cout<<" : "<<attVal.GetValue()<<".  Sele    168     G4cout<<" : "<<attVal.GetValue()<<".  Selected context:"<<G4endl;
169     myContext.Print(G4cout);                      169     myContext.Print(G4cout);
170   }                                               170   }
171                                                   171 
172   // Draw the trajectory                          172   // Draw the trajectory
173   G4TrajectoryDrawerUtils::DrawLineAndPoints(o    173   G4TrajectoryDrawerUtils::DrawLineAndPoints(object, myContext);
174 }                                                 174 }
175                                                   175 
176 void                                              176 void
177 G4TrajectoryDrawByAttribute::Print(std::ostrea    177 G4TrajectoryDrawByAttribute::Print(std::ostream& ostr) const
178 {                                                 178 {
179   ostr<<"G4TrajectoryDrawByAttribute, dumping     179   ostr<<"G4TrajectoryDrawByAttribute, dumping configuration for model named "<< Name() <<":"<<std::endl;;
180                                                   180 
181   ostr<<"Default configuration:"<<G4endl;         181   ostr<<"Default configuration:"<<G4endl;
182   GetContext().Print(ostr);                       182   GetContext().Print(ostr);
183                                                   183 
184   ostr<<"\nAttribute name "<<fAttName<<std::en    184   ostr<<"\nAttribute name "<<fAttName<<std::endl;
185   ostr<<"\nKey<->Context map dump:"<<std::endl    185   ostr<<"\nKey<->Context map dump:"<<std::endl;
186                                                   186 
187   ContextMap::const_iterator iter = fContextMa    187   ContextMap::const_iterator iter = fContextMap.begin();
188                                                   188 
189   while (iter != fContextMap.end()) {             189   while (iter != fContextMap.end()) {
190     ostr<<"Context for key "<<iter->first.firs    190     ostr<<"Context for key "<<iter->first.first<<":"<<std::endl;
191     iter->second->Print(ostr);                    191     iter->second->Print(ostr);
192                                                   192     
193     iter++;                                       193     iter++;
194   }                                               194   }
195 }                                                 195 }
196                                                   196 
197 void                                              197 void
198 G4TrajectoryDrawByAttribute::Set(const G4Strin    198 G4TrajectoryDrawByAttribute::Set(const G4String& name)
199 {                                                 199 {
200   fAttName = name;                                200   fAttName = name;
201 }                                                 201 }
202                                                   202 
203 void                                              203 void
204 G4TrajectoryDrawByAttribute::AddIntervalContex    204 G4TrajectoryDrawByAttribute::AddIntervalContext(const G4String& name, G4VisTrajContext* context)
205 {                                                 205 {
206   // Takes ownership of context                   206   // Takes ownership of context
207   std::pair<G4String, Config> myPair(name, G4T    207   std::pair<G4String, Config> myPair(name, G4TrajectoryDrawByAttribute::Interval);
208                                                   208 
209   ContextMap::iterator iter = fContextMap.find    209   ContextMap::iterator iter = fContextMap.find(myPair);
210                                                   210   
211   if (iter != fContextMap.end()) {                211   if (iter != fContextMap.end()) {
212     G4ExceptionDescription ed;                    212     G4ExceptionDescription ed;
213     ed <<"Interval "<< name <<" already exists    213     ed <<"Interval "<< name <<" already exists";
214     G4Exception                                   214     G4Exception
215       ("G4TrajectoryDrawByAttribute::AddInterv    215       ("G4TrajectoryDrawByAttribute::AddIntervalContext",
216        "modeling0119", FatalErrorInArgument, e    216        "modeling0119", FatalErrorInArgument, ed, ". Invalid interval");
217   }                                               217   }
218                                                   218 
219   fContextMap[myPair] = context;                  219   fContextMap[myPair] = context;
220 }                                                 220 }
221                                                   221 
222 void                                              222 void
223 G4TrajectoryDrawByAttribute::AddValueContext(c    223 G4TrajectoryDrawByAttribute::AddValueContext(const G4String& name, G4VisTrajContext* context)
224 {                                                 224 {
225   // Takes ownership of context                   225   // Takes ownership of context
226   std::pair<G4String, Config> myPair(name, G4T    226   std::pair<G4String, Config> myPair(name, G4TrajectoryDrawByAttribute::SingleValue);
227                                                   227 
228   ContextMap::iterator iter = fContextMap.find    228   ContextMap::iterator iter = fContextMap.find(myPair);
229                                                   229   
230   if (iter != fContextMap.end()) {                230   if (iter != fContextMap.end()) {
231     G4ExceptionDescription ed;                    231     G4ExceptionDescription ed;
232     ed <<"Single value "<< name <<" already ex    232     ed <<"Single value "<< name <<" already exists";
233     G4Exception                                   233     G4Exception
234       ("G4TrajectoryDrawByAttribute::AddSingle    234       ("G4TrajectoryDrawByAttribute::AddSingleValueContext",
235        "modeling0120", FatalErrorInArgument, e    235        "modeling0120", FatalErrorInArgument, ed, ". Invalid value");
236   }                                               236   }
237                                                   237 
238   fContextMap[myPair] = context;                  238   fContextMap[myPair] = context;
239 }                                                 239 }
240                                                   240