Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // >> 26 // $Id: G4TrajectoryDrawByCharge.cc,v 1.10 2010-05-28 02:00:59 allison Exp $ >> 27 // GEANT4 tag $Name: not supported by cvs2svn $ 26 // 28 // 27 // Jane Tinslay, John Allison, Joseph Perl Nov 29 // Jane Tinslay, John Allison, Joseph Perl November 2005 28 #include "G4TrajectoryDrawByCharge.hh" 30 #include "G4TrajectoryDrawByCharge.hh" 29 #include "G4TrajectoryDrawerUtils.hh" 31 #include "G4TrajectoryDrawerUtils.hh" 30 #include "G4VisTrajContext.hh" 32 #include "G4VisTrajContext.hh" 31 #include "G4VTrajectory.hh" 33 #include "G4VTrajectory.hh" 32 #include <sstream> 34 #include <sstream> 33 35 34 G4TrajectoryDrawByCharge::G4TrajectoryDrawByCh 36 G4TrajectoryDrawByCharge::G4TrajectoryDrawByCharge(const G4String& name, G4VisTrajContext* context) 35 :G4VTrajectoryModel(name, context) 37 :G4VTrajectoryModel(name, context) 36 { 38 { 37 // Default configuration 39 // Default configuration 38 fMap[Positive] = G4Colour::Blue(); 40 fMap[Positive] = G4Colour::Blue(); 39 fMap[Negative] = G4Colour::Red(); 41 fMap[Negative] = G4Colour::Red(); 40 fMap[Neutral] = G4Colour::Green(); 42 fMap[Neutral] = G4Colour::Green(); 41 } 43 } 42 44 43 G4TrajectoryDrawByCharge::G4TrajectoryDrawByCh 45 G4TrajectoryDrawByCharge::G4TrajectoryDrawByCharge(const G4String& name, 44 const G4Colour& positive, 46 const G4Colour& positive, 45 const G4Colour& negative, 47 const G4Colour& negative, 46 const G4Colour& neutral) 48 const G4Colour& neutral) 47 :G4VTrajectoryModel(name) 49 :G4VTrajectoryModel(name) 48 { 50 { 49 fMap[Positive] = positive; 51 fMap[Positive] = positive; 50 fMap[Negative] = negative; 52 fMap[Negative] = negative; 51 fMap[Neutral] = neutral; 53 fMap[Neutral] = neutral; 52 } 54 } 53 55 54 G4TrajectoryDrawByCharge::~G4TrajectoryDrawByC 56 G4TrajectoryDrawByCharge::~G4TrajectoryDrawByCharge() {} 55 57 56 void 58 void 57 G4TrajectoryDrawByCharge::Draw(const G4VTrajec << 59 G4TrajectoryDrawByCharge::Draw(const G4VTrajectory& object, >> 60 const G4int&, >> 61 const G4bool& visible) const >> 62 { >> 63 Draw(object, visible); >> 64 } >> 65 >> 66 void >> 67 G4TrajectoryDrawByCharge::Draw(const G4VTrajectory& traj, const G4bool& visible) const 58 { 68 { 59 G4Colour colour; 69 G4Colour colour; 60 70 61 const G4double charge = traj.GetCharge(); 71 const G4double charge = traj.GetCharge(); 62 72 63 if(charge>0.) fMap.GetColour(Positive, 73 if(charge>0.) fMap.GetColour(Positive, colour); 64 else if(charge<0.) fMap.GetColour(Negative, 74 else if(charge<0.) fMap.GetColour(Negative, colour); 65 else fMap.GetColour(Neutral, c 75 else fMap.GetColour(Neutral, colour); 66 76 67 G4VisTrajContext myContext(GetContext()); 77 G4VisTrajContext myContext(GetContext()); 68 << 78 69 myContext.SetLineColour(colour); 79 myContext.SetLineColour(colour); 70 << 80 myContext.SetVisible(visible); >> 81 71 if (GetVerbose()) { 82 if (GetVerbose()) { 72 G4cout<<"G4TrajectoryDrawByCharge drawer n 83 G4cout<<"G4TrajectoryDrawByCharge drawer named "<<Name(); 73 G4cout<<", drawing trajectory with charge, 84 G4cout<<", drawing trajectory with charge, "<<charge<<G4endl; 74 G4cout<<", with configuration:"<<G4endl; 85 G4cout<<", with configuration:"<<G4endl; 75 myContext.Print(G4cout); 86 myContext.Print(G4cout); 76 } 87 } 77 88 78 G4TrajectoryDrawerUtils::DrawLineAndPoints(t 89 G4TrajectoryDrawerUtils::DrawLineAndPoints(traj, myContext); 79 } 90 } 80 91 81 void 92 void 82 G4TrajectoryDrawByCharge::Print(std::ostream& 93 G4TrajectoryDrawByCharge::Print(std::ostream& ostr) const 83 { 94 { 84 ostr<<"G4TrajectoryDrawByCharge model "<< Na 95 ostr<<"G4TrajectoryDrawByCharge model "<< Name() <<" colour scheme: "<<std::endl; 85 fMap.Print(ostr); 96 fMap.Print(ostr); 86 ostr<<"Default configuration:"<<G4endl; 97 ostr<<"Default configuration:"<<G4endl; 87 GetContext().Print(G4cout); 98 GetContext().Print(G4cout); 88 } 99 } 89 100 90 void 101 void 91 G4TrajectoryDrawByCharge::Set(const Charge& ch 102 G4TrajectoryDrawByCharge::Set(const Charge& charge, const G4String& colour) 92 { 103 { 93 fMap.Set(charge, colour); 104 fMap.Set(charge, colour); 94 } 105 } 95 106 96 void 107 void 97 G4TrajectoryDrawByCharge::Set(const Charge& ch 108 G4TrajectoryDrawByCharge::Set(const Charge& charge, const G4Colour& colour) 98 { 109 { 99 fMap[charge] = colour; 110 fMap[charge] = colour; 100 } 111 } 101 112 102 void 113 void 103 G4TrajectoryDrawByCharge::Set(const G4String& 114 G4TrajectoryDrawByCharge::Set(const G4String& charge, const G4String& colour) 104 { 115 { 105 Charge myCharge; 116 Charge myCharge; 106 117 107 if (!ConvertToCharge(charge, myCharge)) { 118 if (!ConvertToCharge(charge, myCharge)) { 108 G4ExceptionDescription ed; 119 G4ExceptionDescription ed; 109 ed << "Invalid charge "<<charge; 120 ed << "Invalid charge "<<charge; 110 G4Exception 121 G4Exception 111 ("G4TrajectoryDrawByCharge::Set(const G4 122 ("G4TrajectoryDrawByCharge::Set(const G4int& charge, const G4String& colour)", "modeling0121", JustWarning, ed); 112 return; 123 return; 113 } 124 } 114 125 115 return Set(myCharge, colour); 126 return Set(myCharge, colour); 116 } 127 } 117 128 118 void 129 void 119 G4TrajectoryDrawByCharge::Set(const G4String& 130 G4TrajectoryDrawByCharge::Set(const G4String& charge, const G4Colour& colour) 120 { 131 { 121 Charge myCharge; 132 Charge myCharge; 122 133 123 if (!ConvertToCharge(charge, myCharge)) { 134 if (!ConvertToCharge(charge, myCharge)) { 124 G4ExceptionDescription ed; 135 G4ExceptionDescription ed; 125 ed << "Invalid charge "<<charge; 136 ed << "Invalid charge "<<charge; 126 G4Exception 137 G4Exception 127 ("G4TrajectoryDrawByCharge::Set(const G4 138 ("G4TrajectoryDrawByCharge::Set(const G4int& charge, const G4Colour& colour)", "modeling0122", JustWarning, ed); 128 } 139 } 129 140 130 return Set(myCharge, colour); 141 return Set(myCharge, colour); 131 } 142 } 132 143 133 G4bool 144 G4bool 134 G4TrajectoryDrawByCharge::ConvertToCharge(cons 145 G4TrajectoryDrawByCharge::ConvertToCharge(const G4String& string, Charge& myCharge) 135 { 146 { 136 bool result(true); 147 bool result(true); 137 148 138 G4int charge; 149 G4int charge; 139 std::istringstream is(string.c_str()); 150 std::istringstream is(string.c_str()); 140 is >> charge; 151 is >> charge; 141 152 142 switch (charge) { 153 switch (charge) { 143 case 1: 154 case 1: 144 myCharge = G4TrajectoryDrawByCharge::Posit 155 myCharge = G4TrajectoryDrawByCharge::Positive; 145 break; 156 break; 146 case 0: 157 case 0: 147 myCharge = G4TrajectoryDrawByCharge::Neutr 158 myCharge = G4TrajectoryDrawByCharge::Neutral; 148 break; 159 break; 149 case -1: 160 case -1: 150 myCharge = G4TrajectoryDrawByCharge::Negat 161 myCharge = G4TrajectoryDrawByCharge::Negative; 151 break; 162 break; 152 default: 163 default: 153 result = false; 164 result = false; 154 } 165 } 155 166 156 return result; 167 return result; 157 } 168 } 158 169