Warning, file /include/Geant4/G4VisFilterManager.hh was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032 #ifndef G4VISFILTERMANAGER_HH
0033 #define G4VISFILTERMANAGER_HH
0034
0035 #include "G4String.hh"
0036 #include "G4UImessenger.hh"
0037 #include "G4VFilter.hh"
0038 #include "G4VModelFactory.hh"
0039 #include <vector>
0040
0041 namespace FilterMode {
0042 enum Mode {Soft, Hard};
0043 }
0044
0045 template <typename T>
0046 class G4VisFilterManager {
0047
0048 public:
0049
0050
0051 G4VisFilterManager(const G4String&);
0052
0053 virtual ~G4VisFilterManager();
0054
0055
0056 typedef G4VFilter<T> Filter;
0057 typedef G4VModelFactory<Filter> Factory;
0058
0059
0060 void Register(Filter*);
0061 void Register(Factory*);
0062
0063
0064 bool Accept(const T&);
0065
0066
0067 G4String Placement() const;
0068
0069
0070 void SetMode(const FilterMode::Mode&);
0071 void SetMode(const G4String&);
0072 FilterMode::Mode GetMode() const;
0073
0074
0075 void Print(std::ostream& ostr, const G4String& name="") const;
0076
0077
0078 const std::vector<Filter*>& FilterList() const;
0079 const std::vector<Factory*>& FactoryList() const;
0080
0081 private:
0082
0083
0084 G4String fPlacement;
0085 FilterMode::Mode fMode;
0086 std::vector<Factory*> fFactoryList;
0087 std::vector<Filter*> fFilterList;
0088 std::vector<G4UImessenger*> fMessengerList;
0089
0090 };
0091
0092 template <typename T>
0093 G4VisFilterManager<T>::G4VisFilterManager(const G4String& placement)
0094 :fPlacement(placement)
0095 {
0096 fMode = FilterMode::Hard;
0097 }
0098
0099 template <typename T>
0100 G4VisFilterManager<T>::~G4VisFilterManager()
0101 {
0102
0103 std::vector<G4UImessenger*>::iterator iterMsgr = fMessengerList.begin();
0104
0105 while (iterMsgr != fMessengerList.end()) {
0106 delete *iterMsgr;
0107 iterMsgr++;
0108 }
0109
0110 typename std::vector<Factory*>::iterator iterFactory = fFactoryList.begin();
0111
0112 while (iterFactory != fFactoryList.end()) {
0113 delete *iterFactory;
0114 iterFactory++;
0115 }
0116
0117 typename std::vector<Filter*>::iterator iterFilter = fFilterList.begin();
0118
0119 while (iterFilter != fFilterList.end()) {
0120 delete *iterFilter;
0121 iterFilter++;
0122 }
0123 }
0124
0125 template <typename T>
0126 void
0127 G4VisFilterManager<T>::Register(Filter* filter)
0128 {
0129 fFilterList.push_back(filter);
0130 }
0131
0132 template <typename T>
0133 void
0134 G4VisFilterManager<T>::Register(Factory* factory)
0135 {
0136 fFactoryList.push_back(factory);
0137
0138 fMessengerList.push_back(new G4VisCommandModelCreate<Factory>(factory, fPlacement));
0139 }
0140
0141 template <typename T>
0142 bool
0143 G4VisFilterManager<T>::Accept(const T& obj)
0144 {
0145 typename std::vector<Filter*>::const_iterator iter = fFilterList.begin();
0146 bool passed(true);
0147
0148 while (passed && (iter != fFilterList.end())) {
0149 passed = (*iter)->Accept(obj);
0150 iter++;
0151 }
0152
0153 return passed;
0154 }
0155
0156 template <typename T>
0157 G4String
0158 G4VisFilterManager<T>::Placement() const
0159 {
0160 return fPlacement;
0161 }
0162
0163 template <typename T>
0164 void
0165 G4VisFilterManager<T>::SetMode(const G4String& mode)
0166 {
0167 bool result(false);
0168
0169 G4String myMode = G4StrUtil::to_lower_copy(mode);
0170
0171 if (myMode == "soft") {result = true; SetMode(FilterMode::Soft);}
0172 else if (myMode == "hard") {result = true; SetMode(FilterMode::Hard);}
0173
0174 if (!result) {
0175 G4ExceptionDescription ed;
0176 ed << "Invalid Filter mode: "<<mode;
0177 G4Exception
0178 ("G4VisFilterManager::SetMode(const G4String& mode)", "visman0101", JustWarning, ed);
0179 }
0180 }
0181
0182 template <typename T>
0183 void
0184 G4VisFilterManager<T>::SetMode(const FilterMode::Mode& mode)
0185 {
0186 fMode = mode;
0187 }
0188
0189 template <typename T>
0190 FilterMode::Mode
0191 G4VisFilterManager<T>::GetMode() const
0192 {
0193 return fMode;
0194 }
0195
0196 template <typename T>
0197 void
0198 G4VisFilterManager<T>::Print(std::ostream& ostr, const G4String& name) const
0199 {
0200 ostr<<"Registered filter factories:"<<std::endl;
0201 typename std::vector<Factory*>::const_iterator iterFactory = fFactoryList.begin();
0202
0203 while (iterFactory != fFactoryList.end()) {
0204 (*iterFactory)->Print(ostr);
0205 iterFactory++;
0206 }
0207
0208 if (0 == fFactoryList.size()) ostr<<" None"<<std::endl;
0209
0210 ostr<<std::endl;
0211 ostr<<"Registered filters:"<<std::endl;
0212
0213 typename std::vector<Filter*>::const_iterator iterFilter = fFilterList.begin();
0214
0215 while (iterFilter != fFilterList.end()) {
0216 if (!name.empty()) {
0217 if ((*iterFilter)->Name() == name) (*iterFilter)->PrintAll(ostr);
0218 }
0219 else {
0220 (*iterFilter)->PrintAll(ostr);
0221 }
0222 iterFilter++;
0223 }
0224
0225 if (0 == fFilterList.size()) ostr<<" None"<<std::endl;
0226 }
0227
0228 template <typename T>
0229 const std::vector< G4VFilter<T>* >&
0230 G4VisFilterManager<T>::FilterList() const
0231 {
0232 return fFilterList;
0233 }
0234
0235 template <typename T>
0236 const std::vector< G4VModelFactory< G4VFilter<T> >* >&
0237 G4VisFilterManager<T>::FactoryList() const
0238 {
0239 return fFactoryList;
0240 }
0241
0242 #endif