File indexing completed on 2025-01-18 09:59:22
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
0033
0034 #ifndef G4VISCOMMANDSMODELCREATE_HH
0035 #define G4VISCOMMANDSMODELCREATE_HH
0036
0037 #include "G4VVisCommand.hh"
0038 #include "G4String.hh"
0039 #include "G4UIcmdWithAString.hh"
0040 #include "G4UIcommand.hh"
0041 #include "G4UIdirectory.hh"
0042 #include <vector>
0043
0044 template <typename Factory>
0045 class G4VisCommandModelCreate : public G4VVisCommand {
0046
0047 public:
0048
0049 G4VisCommandModelCreate(Factory*, const G4String& placement);
0050
0051
0052 virtual ~G4VisCommandModelCreate();
0053
0054 G4String GetCurrentValue(G4UIcommand*);
0055 void SetNewValue (G4UIcommand* command, G4String newValue);
0056
0057 G4String Placement() const;
0058
0059 private:
0060
0061 G4String NextName();
0062
0063
0064 Factory* fpFactory;
0065 G4String fPlacement;
0066 G4int fId;
0067 G4UIcmdWithAString* fpCommand;
0068 std::vector<G4UIcommand*> fDirectoryList;
0069
0070 };
0071
0072 template <typename Factory>
0073 G4VisCommandModelCreate<Factory>::G4VisCommandModelCreate(Factory* factory, const G4String& placement)
0074 :fpFactory(factory)
0075 ,fPlacement(placement)
0076 ,fId(0)
0077 {
0078 G4String factoryName = factory->Name();
0079
0080 G4String command = Placement()+"/create/"+factoryName;
0081 G4String guidance = "Create a "+factoryName+" model and associated messengers.";
0082
0083 fpCommand = new G4UIcmdWithAString(command, this);
0084 fpCommand->SetGuidance(guidance);
0085 fpCommand->SetGuidance("Generated model becomes current.");
0086 fpCommand->SetParameterName("model-name", true);
0087 }
0088
0089 template <typename Factory>
0090 G4VisCommandModelCreate<Factory>::~G4VisCommandModelCreate()
0091 {
0092 delete fpCommand;
0093
0094 unsigned i(0);
0095 for (i=0; i<fDirectoryList.size(); ++i) {
0096 delete fDirectoryList[i];
0097 }
0098 }
0099
0100 template <typename Factory>
0101 G4String
0102 G4VisCommandModelCreate<Factory>::Placement() const
0103 {
0104 return fPlacement;
0105 }
0106
0107 template <typename Factory>
0108 G4String
0109 G4VisCommandModelCreate<Factory>::NextName()
0110 {
0111 std::ostringstream oss;
0112 oss <<fpFactory->Name()<<"-" << fId++;
0113 return oss.str();
0114 }
0115
0116 template <typename Factory>
0117 G4String
0118 G4VisCommandModelCreate<Factory>::GetCurrentValue(G4UIcommand*)
0119 {
0120 return "";
0121 }
0122
0123 template <typename Factory>
0124 void G4VisCommandModelCreate<Factory>::SetNewValue(G4UIcommand*, G4String newName)
0125 {
0126 if (newName.empty()) newName = NextName();
0127
0128 assert (0 != fpFactory);
0129
0130
0131 G4String title = Placement()+"/"+newName+"/";
0132 G4String guidance = "Commands for "+newName+" model.";
0133
0134 G4UIcommand* directory = new G4UIdirectory(title);
0135 directory->SetGuidance(guidance);
0136 fDirectoryList.push_back(directory);
0137
0138
0139 typename Factory::ModelAndMessengers creation = fpFactory->Create(Placement(), newName);
0140
0141
0142 fpVisManager->RegisterModel(creation.first);
0143
0144
0145 typename Factory::Messengers::iterator iter = creation.second.begin();
0146
0147 while (iter != creation.second.end()) {
0148 fpVisManager->RegisterMessenger(*iter);
0149 iter++;
0150 }
0151 }
0152
0153 #endif