[531] | 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: G4VisFilterManager.hh,v 1.4 2006/06/29 21:29:02 gunter Exp $ |
---|
[593] | 27 | // GEANT4 tag $Name: geant4-09-00-ref-01 $ |
---|
[531] | 28 | // |
---|
| 29 | // Filter manager. Manages filter models, factories, messengers, |
---|
| 30 | // command placement, filter mode etc |
---|
| 31 | // |
---|
| 32 | // Jane Tinslay, March 2006 |
---|
| 33 | // |
---|
| 34 | #ifndef G4VISFILTERMANAGER_HH |
---|
| 35 | #define G4VISFILTERMANAGER_HH |
---|
| 36 | |
---|
| 37 | #include "G4String.hh" |
---|
| 38 | #include "G4UImessenger.hh" |
---|
| 39 | #include "G4VFilter.hh" |
---|
| 40 | #include "G4VModelFactory.hh" |
---|
| 41 | #include <sstream> |
---|
| 42 | #include <vector> |
---|
| 43 | |
---|
| 44 | namespace FilterMode { |
---|
| 45 | enum Mode {Soft, Hard}; |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | template <typename T> |
---|
| 49 | class G4VisFilterManager { |
---|
| 50 | |
---|
| 51 | public: |
---|
| 52 | |
---|
| 53 | // Construct with command placement |
---|
| 54 | G4VisFilterManager(const G4String&); |
---|
| 55 | |
---|
| 56 | virtual ~G4VisFilterManager(); |
---|
| 57 | |
---|
| 58 | // Useful typedef's |
---|
| 59 | typedef G4VFilter<T> Filter; |
---|
| 60 | typedef G4VModelFactory<Filter> Factory; |
---|
| 61 | |
---|
| 62 | // Registration methods |
---|
| 63 | void Register(Filter*); |
---|
| 64 | void Register(Factory*); |
---|
| 65 | |
---|
| 66 | // Do filtering |
---|
| 67 | bool Accept(const T&); |
---|
| 68 | |
---|
| 69 | // Command placement |
---|
| 70 | G4String Placement() const; |
---|
| 71 | |
---|
| 72 | // Filter mode operations |
---|
| 73 | void SetMode(const FilterMode::Mode&); |
---|
| 74 | void SetMode(const G4String&); |
---|
| 75 | FilterMode::Mode GetMode() const; |
---|
| 76 | |
---|
| 77 | // Print configuration |
---|
| 78 | void Print(std::ostream& ostr, const G4String& name="") const; |
---|
| 79 | |
---|
| 80 | // Accessors |
---|
| 81 | const std::vector<Filter*>& FilterList() const; |
---|
| 82 | const std::vector<Factory*>& FactoryList() const; |
---|
| 83 | |
---|
| 84 | private: |
---|
| 85 | |
---|
| 86 | // Data members |
---|
| 87 | G4String fPlacement; // Placement |
---|
| 88 | FilterMode::Mode fMode; |
---|
| 89 | std::vector<Factory*> fFactoryList; |
---|
| 90 | std::vector<Filter*> fFilterList; |
---|
| 91 | std::vector<G4UImessenger*> fMessengerList; |
---|
| 92 | |
---|
| 93 | }; |
---|
| 94 | |
---|
| 95 | template <typename T> |
---|
| 96 | G4VisFilterManager<T>::G4VisFilterManager(const G4String& placement) |
---|
| 97 | :fPlacement(placement) |
---|
| 98 | { |
---|
| 99 | fMode = FilterMode::Hard; |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | template <typename T> |
---|
| 103 | G4VisFilterManager<T>::~G4VisFilterManager() |
---|
| 104 | { |
---|
| 105 | // Cleanup |
---|
| 106 | std::vector<G4UImessenger*>::iterator iterMsgr = fMessengerList.begin(); |
---|
| 107 | |
---|
| 108 | while (iterMsgr != fMessengerList.end()) { |
---|
| 109 | delete *iterMsgr; |
---|
| 110 | iterMsgr++; |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | typename std::vector<Factory*>::iterator iterFactory = fFactoryList.begin(); |
---|
| 114 | |
---|
| 115 | while (iterFactory != fFactoryList.end()) { |
---|
| 116 | delete *iterFactory; |
---|
| 117 | iterFactory++; |
---|
| 118 | } |
---|
| 119 | |
---|
| 120 | typename std::vector<Filter*>::iterator iterFilter = fFilterList.begin(); |
---|
| 121 | |
---|
| 122 | while (iterFilter != fFilterList.end()) { |
---|
| 123 | delete *iterFilter; |
---|
| 124 | iterFilter++; |
---|
| 125 | } |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | template <typename T> |
---|
| 129 | void |
---|
| 130 | G4VisFilterManager<T>::Register(Filter* filter) |
---|
| 131 | { |
---|
| 132 | fFilterList.push_back(filter); |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | template <typename T> |
---|
| 136 | void |
---|
| 137 | G4VisFilterManager<T>::Register(Factory* factory) |
---|
| 138 | { |
---|
| 139 | fFactoryList.push_back(factory); |
---|
| 140 | |
---|
| 141 | fMessengerList.push_back(new G4VisCommandModelCreate<Factory>(factory, fPlacement)); |
---|
| 142 | } |
---|
| 143 | |
---|
| 144 | template <typename T> |
---|
| 145 | bool |
---|
| 146 | G4VisFilterManager<T>::Accept(const T& obj) |
---|
| 147 | { |
---|
| 148 | typename std::vector<Filter*>::const_iterator iter = fFilterList.begin(); |
---|
| 149 | bool passed(true); |
---|
| 150 | |
---|
| 151 | while (passed && (iter != fFilterList.end())) { |
---|
| 152 | passed = (*iter)->Accept(obj); |
---|
| 153 | iter++; |
---|
| 154 | } |
---|
| 155 | |
---|
| 156 | return passed; |
---|
| 157 | } |
---|
| 158 | |
---|
| 159 | template <typename T> |
---|
| 160 | G4String |
---|
| 161 | G4VisFilterManager<T>::Placement() const |
---|
| 162 | { |
---|
| 163 | return fPlacement; |
---|
| 164 | } |
---|
| 165 | |
---|
| 166 | template <typename T> |
---|
| 167 | void |
---|
| 168 | G4VisFilterManager<T>::SetMode(const G4String& mode) |
---|
| 169 | { |
---|
| 170 | bool result(false); |
---|
| 171 | |
---|
| 172 | G4String myMode(mode); |
---|
| 173 | myMode.toLower(); |
---|
| 174 | |
---|
| 175 | if (myMode == "soft") {result = true; SetMode(FilterMode::Soft);} |
---|
| 176 | else if (myMode == "hard") {result = true; SetMode(FilterMode::Hard);} |
---|
| 177 | |
---|
| 178 | if (!result) { |
---|
| 179 | std::ostringstream o; |
---|
| 180 | o << "Invalid Filter mode."<<mode; |
---|
| 181 | G4Exception |
---|
| 182 | ("G4VisFilterManager::SetMode(const G4String& mode)", "InvalidMode", JustWarning, o.str().c_str()); |
---|
| 183 | } |
---|
| 184 | } |
---|
| 185 | |
---|
| 186 | template <typename T> |
---|
| 187 | void |
---|
| 188 | G4VisFilterManager<T>::SetMode(const FilterMode::Mode& mode) |
---|
| 189 | { |
---|
| 190 | fMode = mode; |
---|
| 191 | } |
---|
| 192 | |
---|
| 193 | template <typename T> |
---|
| 194 | FilterMode::Mode |
---|
| 195 | G4VisFilterManager<T>::GetMode() const |
---|
| 196 | { |
---|
| 197 | return fMode; |
---|
| 198 | } |
---|
| 199 | |
---|
| 200 | template <typename T> |
---|
| 201 | void |
---|
| 202 | G4VisFilterManager<T>::Print(std::ostream& ostr, const G4String& name) const |
---|
| 203 | { |
---|
| 204 | ostr<<"Registered filter factories:"<<std::endl; |
---|
| 205 | typename std::vector<Factory*>::const_iterator iterFactory = fFactoryList.begin(); |
---|
| 206 | |
---|
| 207 | while (iterFactory != fFactoryList.end()) { |
---|
| 208 | (*iterFactory)->Print(ostr); |
---|
| 209 | iterFactory++; |
---|
| 210 | } |
---|
| 211 | |
---|
| 212 | if (0 == fFactoryList.size()) ostr<<" None"<<std::endl; |
---|
| 213 | |
---|
| 214 | ostr<<std::endl; |
---|
| 215 | ostr<<"Registered filters:"<<std::endl; |
---|
| 216 | |
---|
| 217 | typename std::vector<Filter*>::const_iterator iterFilter = fFilterList.begin(); |
---|
| 218 | |
---|
| 219 | while (iterFilter != fFilterList.end()) { |
---|
| 220 | if (!name.isNull()) { |
---|
| 221 | if ((*iterFilter)->Name() == name) (*iterFilter)->PrintAll(ostr); |
---|
| 222 | } |
---|
| 223 | else { |
---|
| 224 | (*iterFilter)->PrintAll(ostr); |
---|
| 225 | } |
---|
| 226 | iterFilter++; |
---|
| 227 | } |
---|
| 228 | |
---|
| 229 | if (0 == fFilterList.size()) ostr<<" None"<<std::endl; |
---|
| 230 | } |
---|
| 231 | |
---|
| 232 | template <typename T> |
---|
| 233 | const std::vector< G4VFilter<T>* >& |
---|
| 234 | G4VisFilterManager<T>::FilterList() const |
---|
| 235 | { |
---|
| 236 | return fFilterList; |
---|
| 237 | } |
---|
| 238 | |
---|
| 239 | template <typename T> |
---|
| 240 | const std::vector< G4VModelFactory< G4VFilter<T> >* >& |
---|
| 241 | G4VisFilterManager<T>::FactoryList() const |
---|
| 242 | { |
---|
| 243 | return fFactoryList; |
---|
| 244 | } |
---|
| 245 | |
---|
| 246 | #endif |
---|