[834] | 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 | // |
---|
[1258] | 26 | // $Id: G4TrajectoryDrawByCharge.cc,v 1.9 2010/05/11 11:31:31 allison Exp $ |
---|
[954] | 27 | // GEANT4 tag $Name: $ |
---|
[834] | 28 | // |
---|
| 29 | // Jane Tinslay, John Allison, Joseph Perl November 2005 |
---|
| 30 | #include "G4TrajectoryDrawByCharge.hh" |
---|
| 31 | #include "G4TrajectoryDrawerUtils.hh" |
---|
| 32 | #include "G4VisTrajContext.hh" |
---|
| 33 | #include "G4VTrajectory.hh" |
---|
| 34 | #include <sstream> |
---|
| 35 | |
---|
| 36 | G4TrajectoryDrawByCharge::G4TrajectoryDrawByCharge(const G4String& name, G4VisTrajContext* context) |
---|
| 37 | :G4VTrajectoryModel(name, context) |
---|
| 38 | { |
---|
| 39 | // Default configuration |
---|
| 40 | fMap[Positive] = G4Colour::Blue(); |
---|
| 41 | fMap[Negative] = G4Colour::Red(); |
---|
| 42 | fMap[Neutral] = G4Colour::Green(); |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | G4TrajectoryDrawByCharge::G4TrajectoryDrawByCharge(const G4String& name, |
---|
| 46 | const G4Colour& positive, |
---|
| 47 | const G4Colour& negative, |
---|
| 48 | const G4Colour& neutral) |
---|
| 49 | :G4VTrajectoryModel(name) |
---|
| 50 | { |
---|
| 51 | fMap[Positive] = positive; |
---|
| 52 | fMap[Negative] = negative; |
---|
| 53 | fMap[Neutral] = neutral; |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | G4TrajectoryDrawByCharge::~G4TrajectoryDrawByCharge() {} |
---|
| 57 | |
---|
| 58 | void |
---|
[1258] | 59 | G4TrajectoryDrawByCharge::Draw(const G4VTrajectory& object, |
---|
| 60 | const G4int& i_mode, |
---|
| 61 | const G4bool& visible) const |
---|
[834] | 62 | { |
---|
[1258] | 63 | Draw(object, visible); |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | void |
---|
| 67 | G4TrajectoryDrawByCharge::Draw(const G4VTrajectory& traj, const G4bool& visible) const |
---|
| 68 | { |
---|
[834] | 69 | G4Colour colour; |
---|
| 70 | |
---|
| 71 | const G4double charge = traj.GetCharge(); |
---|
| 72 | |
---|
| 73 | if(charge>0.) fMap.GetColour(Positive, colour); |
---|
| 74 | else if(charge<0.) fMap.GetColour(Negative, colour); |
---|
| 75 | else fMap.GetColour(Neutral, colour); |
---|
| 76 | |
---|
| 77 | G4VisTrajContext myContext(GetContext()); |
---|
| 78 | |
---|
| 79 | myContext.SetLineColour(colour); |
---|
| 80 | myContext.SetVisible(visible); |
---|
| 81 | |
---|
| 82 | if (GetVerbose()) { |
---|
| 83 | G4cout<<"G4TrajectoryDrawByCharge drawer named "<<Name(); |
---|
| 84 | G4cout<<", drawing trajectory with charge, "<<charge<<G4endl; |
---|
| 85 | G4cout<<", with configuration:"<<G4endl; |
---|
| 86 | myContext.Print(G4cout); |
---|
| 87 | } |
---|
| 88 | |
---|
[1258] | 89 | G4TrajectoryDrawerUtils::DrawLineAndPoints(traj, myContext); |
---|
[834] | 90 | } |
---|
| 91 | |
---|
| 92 | void |
---|
| 93 | G4TrajectoryDrawByCharge::Print(std::ostream& ostr) const |
---|
| 94 | { |
---|
| 95 | ostr<<"G4TrajectoryDrawByCharge model "<< Name() <<" colour scheme: "<<std::endl; |
---|
| 96 | fMap.Print(ostr); |
---|
| 97 | ostr<<"Default configuration:"<<G4endl; |
---|
| 98 | GetContext().Print(G4cout); |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | void |
---|
| 102 | G4TrajectoryDrawByCharge::Set(const Charge& charge, const G4String& colour) |
---|
| 103 | { |
---|
| 104 | fMap.Set(charge, colour); |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | void |
---|
| 108 | G4TrajectoryDrawByCharge::Set(const Charge& charge, const G4Colour& colour) |
---|
| 109 | { |
---|
| 110 | fMap[charge] = colour; |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | void |
---|
| 114 | G4TrajectoryDrawByCharge::Set(const G4String& charge, const G4String& colour) |
---|
| 115 | { |
---|
| 116 | Charge myCharge; |
---|
| 117 | |
---|
| 118 | if (!ConvertToCharge(charge, myCharge)) { |
---|
| 119 | std::ostringstream o; |
---|
| 120 | o << "Invalid charge "<<charge; |
---|
| 121 | G4Exception |
---|
| 122 | ("G4TrajectoryDrawByCharge::Set(const G4int& charge, const G4String& colour)", "InvalidCharge", JustWarning, o.str().c_str()); |
---|
| 123 | return; |
---|
| 124 | } |
---|
| 125 | |
---|
| 126 | return Set(myCharge, colour); |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | void |
---|
| 130 | G4TrajectoryDrawByCharge::Set(const G4String& charge, const G4Colour& colour) |
---|
| 131 | { |
---|
| 132 | Charge myCharge; |
---|
| 133 | |
---|
| 134 | if (!ConvertToCharge(charge, myCharge)) { |
---|
| 135 | std::ostringstream o; |
---|
| 136 | o << "Invalid charge "<<charge; |
---|
| 137 | G4Exception |
---|
| 138 | ("G4TrajectoryDrawByCharge::Set(const G4int& charge, const G4Colour& colour)", "InvalidCharge", JustWarning, o.str().c_str()); |
---|
| 139 | } |
---|
| 140 | |
---|
| 141 | return Set(myCharge, colour); |
---|
| 142 | } |
---|
| 143 | |
---|
| 144 | G4bool |
---|
| 145 | G4TrajectoryDrawByCharge::ConvertToCharge(const G4String& string, Charge& myCharge) |
---|
| 146 | { |
---|
| 147 | bool result(true); |
---|
| 148 | |
---|
| 149 | G4int charge; |
---|
| 150 | std::istringstream is(string.c_str()); |
---|
| 151 | is >> charge; |
---|
| 152 | |
---|
| 153 | switch (charge) { |
---|
| 154 | case 1: |
---|
| 155 | myCharge = G4TrajectoryDrawByCharge::Positive; |
---|
| 156 | break; |
---|
| 157 | case 0: |
---|
| 158 | myCharge = G4TrajectoryDrawByCharge::Neutral; |
---|
| 159 | break; |
---|
| 160 | case -1: |
---|
| 161 | myCharge = G4TrajectoryDrawByCharge::Negative; |
---|
| 162 | break; |
---|
| 163 | default: |
---|
| 164 | result = false; |
---|
| 165 | } |
---|
| 166 | |
---|
| 167 | return result; |
---|
| 168 | } |
---|