source: trunk/source/visualization/management/include/G4VisModelManager.hh@ 1137

Last change on this file since 1137 was 954, checked in by garnier, 17 years ago

remise a jour

  • Property svn:mime-type set to text/cpp
File size: 5.0 KB
Line 
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: G4VisModelManager.hh,v 1.4 2006/06/29 21:29:10 gunter Exp $
27// GEANT4 tag $Name: $
28//
29// Generic model manager. Manages models, associated
30// factories, messengers, command placement etc
31//
32// Jane Tinslay, March 2006
33//
34#ifndef G4VISMODELMANAGER_HH
35#define G4VISMODELMANAGER_HH
36
37#include "G4UImessenger.hh"
38#include "G4VisCommandModelCreate.hh"
39#include "G4VisListManager.hh"
40#include "G4VModelFactory.hh"
41#include <vector>
42
43template <typename Model>
44class G4VisModelManager {
45
46public: // With description
47
48 // Useful typedef's
49 typedef G4VisListManager<Model> List;
50 typedef G4VModelFactory<Model> Factory;
51
52 G4VisModelManager(const G4String&);
53 virtual ~G4VisModelManager();
54
55 // Registration methods
56 void Register(Model*);
57 void Register(Factory*);
58
59 // Change/Retrieve "Current" object
60 void SetCurrent(const G4String&);
61 const Model* Current() const;
62
63 // Command placement
64 G4String Placement() const;
65
66 // Print factory and model data
67 void Print(std::ostream& ostr, const G4String& name="") const;
68
69 // Accessors
70 const List* ListManager() const;
71 const std::vector<Factory*>& FactoryList() const;
72
73private:
74
75 // Data members
76 G4String fPlacement;
77 List* fpModelList;
78 std::vector<Factory*> fFactoryList;
79 std::vector<G4UImessenger*> fMessengerList;
80
81};
82
83template <typename Model>
84G4VisModelManager<Model>::G4VisModelManager(const G4String& placement)
85 :fPlacement(placement)
86 ,fpModelList(new List)
87{}
88
89template <typename Model>
90G4VisModelManager<Model>::~G4VisModelManager()
91{
92 // Cleanup
93 std::vector<G4UImessenger*>::iterator iterMsgr = fMessengerList.begin();
94
95 while (iterMsgr != fMessengerList.end()) {
96 delete *iterMsgr;
97 iterMsgr++;
98 }
99
100 typename std::vector<Factory*>::iterator iterFactory = fFactoryList.begin();
101
102 while (iterFactory != fFactoryList.end()) {
103 delete *iterFactory;
104 iterFactory++;
105 }
106
107 delete fpModelList;
108}
109
110template <typename Model>
111void
112G4VisModelManager<Model>::Register(Model* model)
113{
114 fpModelList->Register(model);
115}
116
117template <typename Model>
118void
119G4VisModelManager<Model>::Register(Factory* factory)
120{
121 // Assume ownership
122 fFactoryList.push_back(factory);
123
124 // Generate "create" command for this factory
125 fMessengerList.push_back(new G4VisCommandModelCreate<Factory>(factory, fPlacement));
126}
127
128template <typename Model>
129void
130G4VisModelManager<Model>::SetCurrent(const G4String& model)
131{
132 fpModelList->SetCurrent(model);
133}
134
135template <typename Model>
136const Model*
137G4VisModelManager<Model>::Current() const
138{
139 return fpModelList->Current();
140}
141
142template <typename Model>
143G4String
144G4VisModelManager<Model>::Placement() const
145{
146 return fPlacement;
147}
148
149template <typename Model>
150void
151G4VisModelManager<Model>::Print(std::ostream& ostr, const G4String& name) const
152{
153 ostr<<"Registered model factories:"<<std::endl;
154
155 typename std::vector<Factory*>::const_iterator iter = fFactoryList.begin();
156
157 while (iter != fFactoryList.end()) {
158 (*iter)->Print(ostr);
159 iter++;
160 }
161
162 if (0 == fFactoryList.size()) ostr<<" None"<<std::endl;
163
164 ostr<<std::endl;
165 ostr<<"Registered models: "<<std::endl;
166
167 fpModelList->Print(ostr, name);
168}
169
170template <typename Model>
171const G4VisListManager<Model>*
172G4VisModelManager<Model>::ListManager() const
173{
174 return fpModelList;
175}
176
177template <typename Model>
178const std::vector<G4VModelFactory<Model>*>&
179G4VisModelManager<Model>::FactoryList() const
180{
181 return fFactoryList;
182}
183
184#endif
Note: See TracBrowser for help on using the repository browser.