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