[1337] | 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: pyG4UImanager.cc,v 1.1 2006/08/08 05:20:57 kmura Exp $ |
---|
| 27 | // $Name: geant4-09-04-beta-01 $ |
---|
| 28 | // ==================================================================== |
---|
| 29 | // pyG4UImanager.cc |
---|
| 30 | // |
---|
| 31 | // G4UImanager class is pure singleton, so it cannnot be exposed |
---|
| 32 | // from BPL. Functionality of G4UImanager is exposed in global |
---|
| 33 | // name space via wrappers. |
---|
| 34 | // 2006 Q |
---|
| 35 | // ==================================================================== |
---|
| 36 | #include <boost/python.hpp> |
---|
| 37 | #include "G4UImanager.hh" |
---|
| 38 | #include "G4UIcommandTree.hh" |
---|
| 39 | |
---|
| 40 | using namespace boost::python; |
---|
| 41 | |
---|
| 42 | // ==================================================================== |
---|
| 43 | // wrappers |
---|
| 44 | // ==================================================================== |
---|
| 45 | namespace pyG4UImanager { |
---|
| 46 | |
---|
| 47 | // ApplyCommand |
---|
| 48 | G4int(G4UImanager::*f1_ApplyCommand)(const char*)= &G4UImanager::ApplyCommand; |
---|
| 49 | G4int(G4UImanager::*f2_ApplyCommand)(G4String)= &G4UImanager::ApplyCommand; |
---|
| 50 | |
---|
| 51 | // CreateHTML |
---|
| 52 | BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(f_CreateHTML, CreateHTML, 0, 1); |
---|
| 53 | |
---|
| 54 | |
---|
| 55 | |
---|
| 56 | ////////////////////////////////////////////// |
---|
| 57 | G4int ApplyUICommand_1(const G4String& cmdstr) |
---|
| 58 | ////////////////////////////////////////////// |
---|
| 59 | { |
---|
| 60 | G4UImanager* UImgr= G4UImanager::GetUIpointer(); |
---|
| 61 | G4int returnVal= UImgr-> ApplyCommand(cmdstr); |
---|
| 62 | if( returnVal == fCommandSucceeded ) return returnVal; |
---|
| 63 | |
---|
| 64 | G4int paramIndex= returnVal % 100; |
---|
| 65 | G4int commandStatus= returnVal - paramIndex; |
---|
| 66 | |
---|
| 67 | switch(commandStatus) { |
---|
| 68 | case fCommandSucceeded: |
---|
| 69 | break; |
---|
| 70 | |
---|
| 71 | case fCommandNotFound: |
---|
| 72 | G4cout << "command <" << UImgr-> SolveAlias(cmdstr) |
---|
| 73 | << "> not found" << G4endl; |
---|
| 74 | break; |
---|
| 75 | |
---|
| 76 | case fIllegalApplicationState: |
---|
| 77 | G4cout << "illegal application state -- command refused" |
---|
| 78 | << G4endl; |
---|
| 79 | break; |
---|
| 80 | |
---|
| 81 | case fParameterOutOfRange: |
---|
| 82 | break; |
---|
| 83 | |
---|
| 84 | case fParameterOutOfCandidates: |
---|
| 85 | G4cout << "Parameter is out of candidate list (index " |
---|
| 86 | << paramIndex << ")" |
---|
| 87 | << G4endl; |
---|
| 88 | break; |
---|
| 89 | |
---|
| 90 | case fParameterUnreadable: |
---|
| 91 | G4cout << "Parameter is wrong type and/or is not omittable (index " |
---|
| 92 | << paramIndex << ")" << G4endl; |
---|
| 93 | break; |
---|
| 94 | |
---|
| 95 | case fAliasNotFound: |
---|
| 96 | break; |
---|
| 97 | |
---|
| 98 | default: |
---|
| 99 | G4cout << "command refused (" << commandStatus << ")" << G4endl; |
---|
| 100 | break; |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | return returnVal; |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | ///////////////////////////////////////////////// |
---|
| 107 | G4int ApplyUICommand_2(const std::string& cmdstr) |
---|
| 108 | ///////////////////////////////////////////////// |
---|
| 109 | { |
---|
| 110 | return ApplyUICommand_1(cmdstr); |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | }; |
---|
| 114 | |
---|
| 115 | using namespace pyG4UImanager; |
---|
| 116 | |
---|
| 117 | // ==================================================================== |
---|
| 118 | // module definition |
---|
| 119 | // ==================================================================== |
---|
| 120 | void export_G4UImanager() |
---|
| 121 | { |
---|
| 122 | class_<G4UImanager, boost::noncopyable> |
---|
| 123 | ("G4UImanager", "UI manager class", no_init) |
---|
| 124 | .def("GetUIpointer", &G4UImanager::GetUIpointer, |
---|
| 125 | return_value_policy<reference_existing_object>()) |
---|
| 126 | .staticmethod("GetUIpointer") |
---|
| 127 | // --- |
---|
| 128 | .def("GetCurrentValues", &G4UImanager::GetCurrentValues) |
---|
| 129 | .def("ExecuteMacroFile", &G4UImanager::ExecuteMacroFile) |
---|
| 130 | .def("ApplyCommand", f1_ApplyCommand) |
---|
| 131 | .def("ApplyCommand", f2_ApplyCommand) |
---|
| 132 | .def("CreateHTML", &G4UImanager::CreateHTML, f_CreateHTML()) |
---|
| 133 | // --- |
---|
| 134 | .def("SetPauseAtBeginOfEvent", &G4UImanager::SetPauseAtBeginOfEvent) |
---|
| 135 | .def("GetPauseAtBeginOfEvent", &G4UImanager::GetPauseAtBeginOfEvent) |
---|
| 136 | .def("SetPauseAtEndOfEvent", &G4UImanager::SetPauseAtEndOfEvent) |
---|
| 137 | .def("GetPauseAtEndOfEvent", &G4UImanager::GetPauseAtEndOfEvent) |
---|
| 138 | .def("SetVerboseLevel", &G4UImanager::SetVerboseLevel) |
---|
| 139 | .def("GetVerboseLevel", &G4UImanager::GetVerboseLevel) |
---|
| 140 | // --- |
---|
| 141 | .def("GetTree", &G4UImanager::GetTree, |
---|
| 142 | return_value_policy<reference_existing_object>()) |
---|
| 143 | ; |
---|
| 144 | |
---|
| 145 | // --- |
---|
| 146 | def("ApplyUICommand", ApplyUICommand_1); |
---|
| 147 | def("ApplyUICommand", ApplyUICommand_2); |
---|
| 148 | |
---|
| 149 | } |
---|