G4VisCommandsGeometry.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id$
00028 
00029 // /vis/geometry commands - John Allison  31st January 2006
00030 
00031 #include "G4VisCommandsGeometry.hh"
00032 
00033 #include "G4UIcmdWithAString.hh"
00034 #include "G4VisManager.hh"
00035 #include "G4LogicalVolumeStore.hh"
00036 #include "G4UImanager.hh"
00037 
00038 std::map<G4LogicalVolume*, const G4VisAttributes*>
00039 G4VVisCommandGeometry::fVisAttsMap;
00040 
00041 G4VVisCommandGeometry::~G4VVisCommandGeometry()
00042 {
00043   // Delete all vis atts that were "new".  Do something like "restore"
00044   // without the "rebuild".
00045 }
00046 
00048 
00049 G4VisCommandGeometryList::G4VisCommandGeometryList()
00050 {
00051   G4bool omitable;
00052   fpCommand = new G4UIcmdWithAString("/vis/geometry/list", this);
00053   fpCommand -> SetGuidance("Lists vis attributes of logical volume(s).");
00054   fpCommand -> SetGuidance("\"all\" lists all logical volumes.");
00055   fpCommand -> SetParameterName("logical-volume-name", omitable = true);
00056   fpCommand -> SetDefaultValue("all");
00057 }
00058 
00059 G4VisCommandGeometryList::~G4VisCommandGeometryList()
00060 {
00061   delete fpCommand;
00062 }
00063 
00064 G4String G4VisCommandGeometryList::GetCurrentValue(G4UIcommand*)
00065 {
00066   return "";
00067 }
00068 
00069 void G4VisCommandGeometryList::SetNewValue(G4UIcommand*, G4String newValue)
00070 {
00071   G4LogicalVolumeStore *pLVStore = G4LogicalVolumeStore::GetInstance();
00072   G4bool found = false;
00073   for (size_t iLV = 0; iLV < pLVStore->size(); iLV++ ) {
00074     G4LogicalVolume*pLV = (*pLVStore)[iLV];
00075     const G4String& logVolName = pLV->GetName();
00076     if (newValue == "all" || logVolName == newValue) {
00077       const G4VisAttributes* visAtts = pLV->GetVisAttributes();
00078       G4cout << "\nLogical Volume \"" << pLV->GetName()
00079              << "\": vis attributes:\n" << *visAtts
00080              << G4endl;
00081     }
00082     if (logVolName == newValue) found = true;
00083   }
00084   if (newValue != "all" && !found) {
00085     if (fpVisManager->GetVerbosity() >= G4VisManager::errors) {
00086       G4cout << "ERROR: Logical volume \"" << newValue
00087              << "\" not found in logical volume store." << G4endl;
00088     }
00089     return;
00090   }
00091 }
00092 
00094 
00095 G4VisCommandGeometryRestore::G4VisCommandGeometryRestore()
00096 {
00097   G4bool omitable;
00098   fpCommand = new G4UIcmdWithAString("/vis/geometry/restore", this);
00099   fpCommand -> SetGuidance("Restores vis attributes of logical volume(s).");
00100   fpCommand -> SetParameterName("logical-volume-name", omitable = true);
00101   fpCommand -> SetDefaultValue("all");
00102 }
00103 
00104 G4VisCommandGeometryRestore::~G4VisCommandGeometryRestore()
00105 {
00106   delete fpCommand;
00107 }
00108 
00109 G4String G4VisCommandGeometryRestore::GetCurrentValue(G4UIcommand*)
00110 {
00111   return "";
00112 }
00113 
00114 void G4VisCommandGeometryRestore::SetNewValue(G4UIcommand*, G4String newValue)
00115 {
00116   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
00117   G4LogicalVolumeStore *pLVStore = G4LogicalVolumeStore::GetInstance();
00118   size_t nLV = pLVStore->size();
00119   size_t iLV;
00120   G4LogicalVolume* pLV = 0;
00121   G4bool found = false;
00122   for (iLV = 0; iLV < nLV; iLV++ ) {
00123     pLV = (*pLVStore)[iLV];
00124     const G4String& logVolName = pLV->GetName();
00125     if (logVolName == newValue) found = true;
00126     if (newValue == "all" || logVolName == newValue) {
00127       VisAttsMapIterator i = fVisAttsMap.find(pLV);
00128       if (i != fVisAttsMap.end()) {
00129         const G4VisAttributes* newVisAtts = pLV->GetVisAttributes();
00130         const G4VisAttributes* oldVisAtts = i->second;
00131         pLV->SetVisAttributes(oldVisAtts);
00132         if (verbosity >= G4VisManager::confirmations) {
00133           G4cout << "\nLogical Volume \"" << pLV->GetName()
00134                  << "\": re-setting vis attributes:\nwas: " << *newVisAtts
00135                  << "\nnow: " << *oldVisAtts
00136                  << G4endl;
00137         }
00138       }
00139     }
00140   }
00141   if (newValue != "all" && !found) {
00142     if (verbosity >= G4VisManager::errors) {
00143       G4cout << "ERROR: Logical volume \"" << newValue
00144              << "\" not found in logical volume store." << G4endl;
00145     }
00146     return;
00147   }
00148   if (fpVisManager->GetCurrentViewer()) {
00149     G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/rebuild");
00150   }
00151 }

Generated on Mon May 27 17:50:15 2013 for Geant4 by  doxygen 1.4.7