Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4VisCommandModelCreate.hh
Go to the documentation of this file.
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: G4VisCommandModelCreate.hh 66373 2012-12-18 09:41:34Z gcosmo $
27 //
28 // Jane Tinslay, John Allison, Joseph Perl October 2005
29 //
30 // Class Description:
31 // Templated create command for model factories. Factory generates new models
32 // and associated messengers.
33 // Class Description - End:
34 
35 #ifndef G4VISCOMMANDSMODELCREATE_HH
36 #define G4VISCOMMANDSMODELCREATE_HH
37 
38 #include "G4VVisCommand.hh"
39 #include "G4String.hh"
40 #include "G4UIcmdWithAString.hh"
41 #include "G4UIcommand.hh"
42 #include "G4UIdirectory.hh"
43 #include <vector>
44 
45 template <typename Factory>
47 
48 public: // With description
49 
50  G4VisCommandModelCreate(Factory*, const G4String& placement);
51  // Input factory and command placement
52 
53  virtual ~G4VisCommandModelCreate();
54 
56  void SetNewValue (G4UIcommand* command, G4String newValue);
57 
58  G4String Placement() const;
59 
60 private:
61 
62  G4String NextName();
63 
64  // Data members
65  Factory* fpFactory;
66  G4String fPlacement;
67  G4int fId;
68  G4UIcmdWithAString* fpCommand;
69  std::vector<G4UIcommand*> fDirectoryList;
70 
71 };
72 
73 template <typename Factory>
75  :fpFactory(factory)
76  ,fPlacement(placement)
77  ,fId(0)
78 {
79  G4String factoryName = factory->Name();
80 
81  G4String command = Placement()+"/create/"+factoryName;
82  G4String guidance = "Create a "+factoryName+" model and associated messengers.";
83 
84  fpCommand = new G4UIcmdWithAString(command, this);
85  fpCommand->SetGuidance(guidance);
86  fpCommand->SetGuidance("Generated model becomes current.");
87  fpCommand->SetParameterName("model-name", true);
88 }
89 
90 template <typename Factory>
92 {
93  delete fpCommand;
94 
95  unsigned i(0);
96  for (i=0; i<fDirectoryList.size(); ++i) {
97  delete fDirectoryList[i];
98  }
99 }
100 
101 template <typename Factory>
102 G4String
104 {
105  return fPlacement;
106 }
107 
108 template <typename Factory>
109 G4String
111 {
112  std::ostringstream oss;
113  oss <<fpFactory->Name()<<"-" << fId++;
114  return oss.str();
115 }
116 
117 template <typename Factory>
118 G4String
120 {
121  return "";
122 }
123 
124 template <typename Factory>
126 {
127  if (newName.isNull()) newName = NextName();
128 
129  assert (0 != fpFactory);
130 
131  // Create directory for new model commands
132  G4String title = Placement()+"/"+newName+"/";
133  G4String guidance = "Commands for "+newName+" model.";
134 
135  G4UIcommand* directory = new G4UIdirectory(title);
136  directory->SetGuidance(guidance);
137  fDirectoryList.push_back(directory);
138 
139  // Create the model.
140  typename Factory::ModelAndMessengers creation = fpFactory->Create(Placement(), newName);
141 
142  // Register model with vis manager
143  fpVisManager->RegisterModel(creation.first);
144 
145  // Register associated messengers with vis manager
146  typename Factory::Messengers::iterator iter = creation.second.begin();
147 
148  while (iter != creation.second.end()) {
149  fpVisManager->RegisterMessenger(*iter);
150  iter++;
151  }
152 }
153 
154 #endif
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
G4String GetCurrentValue(G4UIcommand *)
void SetNewValue(G4UIcommand *command, G4String newValue)
G4VisCommandModelCreate(Factory *, const G4String &placement)
int G4int
Definition: G4Types.hh:78
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:161
G4bool isNull() const