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[ 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 ]

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