File indexing completed on 2025-01-18 09:59:24
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 G4VISMODELMANAGER_HH
0033 #define G4VISMODELMANAGER_HH
0034
0035 #include "G4UImessenger.hh"
0036 #include "G4VisCommandModelCreate.hh"
0037 #include "G4VisListManager.hh"
0038 #include "G4VModelFactory.hh"
0039 #include <vector>
0040
0041 template <typename Model>
0042 class G4VisModelManager {
0043
0044 public:
0045
0046
0047 typedef G4VisListManager<Model> List;
0048 typedef G4VModelFactory<Model> Factory;
0049
0050 G4VisModelManager(const G4String&);
0051 virtual ~G4VisModelManager();
0052
0053
0054 void Register(Model*);
0055 void Register(Factory*);
0056
0057
0058 void SetCurrent(const G4String&);
0059 const Model* Current() const;
0060
0061
0062 G4String Placement() const;
0063
0064
0065 void Print(std::ostream& ostr, const G4String& name="") const;
0066
0067
0068 const List* ListManager() const;
0069 const std::vector<Factory*>& FactoryList() const;
0070
0071 private:
0072
0073
0074
0075 G4VisModelManager (const G4VisModelManager&);
0076 G4VisModelManager& operator = (const G4VisModelManager&);
0077
0078
0079 G4String fPlacement;
0080 List* fpModelList;
0081 std::vector<Factory*> fFactoryList;
0082 std::vector<G4UImessenger*> fMessengerList;
0083
0084 };
0085
0086 template <typename Model>
0087 G4VisModelManager<Model>::G4VisModelManager(const G4String& placement)
0088 :fPlacement(placement)
0089 ,fpModelList(new List)
0090 {}
0091
0092 template <typename Model>
0093 G4VisModelManager<Model>::~G4VisModelManager()
0094 {
0095
0096 std::vector<G4UImessenger*>::iterator iterMsgr = fMessengerList.begin();
0097
0098 while (iterMsgr != fMessengerList.end()) {
0099 delete *iterMsgr;
0100 iterMsgr++;
0101 }
0102
0103 typename std::vector<Factory*>::iterator iterFactory = fFactoryList.begin();
0104
0105 while (iterFactory != fFactoryList.end()) {
0106 delete *iterFactory;
0107 iterFactory++;
0108 }
0109
0110 delete fpModelList;
0111 }
0112
0113 template <typename Model>
0114 void
0115 G4VisModelManager<Model>::Register(Model* model)
0116 {
0117 fpModelList->Register(model);
0118 }
0119
0120 template <typename Model>
0121 void
0122 G4VisModelManager<Model>::Register(Factory* factory)
0123 {
0124
0125 fFactoryList.push_back(factory);
0126
0127
0128 fMessengerList.push_back(new G4VisCommandModelCreate<Factory>(factory, fPlacement));
0129 }
0130
0131 template <typename Model>
0132 void
0133 G4VisModelManager<Model>::SetCurrent(const G4String& model)
0134 {
0135 fpModelList->SetCurrent(model);
0136 }
0137
0138 template <typename Model>
0139 const Model*
0140 G4VisModelManager<Model>::Current() const
0141 {
0142 return fpModelList->Current();
0143 }
0144
0145 template <typename Model>
0146 G4String
0147 G4VisModelManager<Model>::Placement() const
0148 {
0149 return fPlacement;
0150 }
0151
0152 template <typename Model>
0153 void
0154 G4VisModelManager<Model>::Print(std::ostream& ostr, const G4String& name) const
0155 {
0156 ostr<<"Registered model factories:"<<std::endl;
0157
0158 typename std::vector<Factory*>::const_iterator iter = fFactoryList.begin();
0159
0160 while (iter != fFactoryList.end()) {
0161 (*iter)->Print(ostr);
0162 iter++;
0163 }
0164
0165 if (0 == fFactoryList.size()) ostr<<" None"<<std::endl;
0166
0167 ostr<<std::endl;
0168 ostr<<"Registered models: "<<std::endl;
0169
0170 fpModelList->Print(ostr, name);
0171 }
0172
0173 template <typename Model>
0174 const G4VisListManager<Model>*
0175 G4VisModelManager<Model>::ListManager() const
0176 {
0177 return fpModelList;
0178 }
0179
0180 template <typename Model>
0181 const std::vector<G4VModelFactory<Model>*>&
0182 G4VisModelManager<Model>::FactoryList() const
0183 {
0184 return fFactoryList;
0185 }
0186
0187 #endif