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: G4TrajectoryDrawByCharge.cc,v 1.8 2006/06/29 21:33:06 gunter Exp $ |
---|
27 | // GEANT4 tag $Name: HEAD $ |
---|
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 |
---|
59 | G4TrajectoryDrawByCharge::Draw(const G4VTrajectory& traj, const G4int& i_mode, const G4bool& visible) const |
---|
60 | { |
---|
61 | G4Colour colour; |
---|
62 | |
---|
63 | const G4double charge = traj.GetCharge(); |
---|
64 | |
---|
65 | if(charge>0.) fMap.GetColour(Positive, colour); |
---|
66 | else if(charge<0.) fMap.GetColour(Negative, colour); |
---|
67 | else fMap.GetColour(Neutral, colour); |
---|
68 | |
---|
69 | G4VisTrajContext myContext(GetContext()); |
---|
70 | |
---|
71 | myContext.SetLineColour(colour); |
---|
72 | myContext.SetVisible(visible); |
---|
73 | |
---|
74 | if (GetVerbose()) { |
---|
75 | G4cout<<"G4TrajectoryDrawByCharge drawer named "<<Name(); |
---|
76 | G4cout<<", drawing trajectory with charge, "<<charge<<G4endl; |
---|
77 | G4cout<<", with configuration:"<<G4endl; |
---|
78 | myContext.Print(G4cout); |
---|
79 | } |
---|
80 | |
---|
81 | G4TrajectoryDrawerUtils::DrawLineAndPoints(traj, myContext, i_mode); |
---|
82 | } |
---|
83 | |
---|
84 | void |
---|
85 | G4TrajectoryDrawByCharge::Print(std::ostream& ostr) const |
---|
86 | { |
---|
87 | ostr<<"G4TrajectoryDrawByCharge model "<< Name() <<" colour scheme: "<<std::endl; |
---|
88 | fMap.Print(ostr); |
---|
89 | ostr<<"Default configuration:"<<G4endl; |
---|
90 | GetContext().Print(G4cout); |
---|
91 | } |
---|
92 | |
---|
93 | void |
---|
94 | G4TrajectoryDrawByCharge::Set(const Charge& charge, const G4String& colour) |
---|
95 | { |
---|
96 | fMap.Set(charge, colour); |
---|
97 | } |
---|
98 | |
---|
99 | void |
---|
100 | G4TrajectoryDrawByCharge::Set(const Charge& charge, const G4Colour& colour) |
---|
101 | { |
---|
102 | fMap[charge] = colour; |
---|
103 | } |
---|
104 | |
---|
105 | void |
---|
106 | G4TrajectoryDrawByCharge::Set(const G4String& charge, const G4String& colour) |
---|
107 | { |
---|
108 | Charge myCharge; |
---|
109 | |
---|
110 | if (!ConvertToCharge(charge, myCharge)) { |
---|
111 | std::ostringstream o; |
---|
112 | o << "Invalid charge "<<charge; |
---|
113 | G4Exception |
---|
114 | ("G4TrajectoryDrawByCharge::Set(const G4int& charge, const G4String& colour)", "InvalidCharge", JustWarning, o.str().c_str()); |
---|
115 | return; |
---|
116 | } |
---|
117 | |
---|
118 | return Set(myCharge, colour); |
---|
119 | } |
---|
120 | |
---|
121 | void |
---|
122 | G4TrajectoryDrawByCharge::Set(const G4String& charge, const G4Colour& colour) |
---|
123 | { |
---|
124 | Charge myCharge; |
---|
125 | |
---|
126 | if (!ConvertToCharge(charge, myCharge)) { |
---|
127 | std::ostringstream o; |
---|
128 | o << "Invalid charge "<<charge; |
---|
129 | G4Exception |
---|
130 | ("G4TrajectoryDrawByCharge::Set(const G4int& charge, const G4Colour& colour)", "InvalidCharge", JustWarning, o.str().c_str()); |
---|
131 | } |
---|
132 | |
---|
133 | return Set(myCharge, colour); |
---|
134 | } |
---|
135 | |
---|
136 | G4bool |
---|
137 | G4TrajectoryDrawByCharge::ConvertToCharge(const G4String& string, Charge& myCharge) |
---|
138 | { |
---|
139 | bool result(true); |
---|
140 | |
---|
141 | G4int charge; |
---|
142 | std::istringstream is(string.c_str()); |
---|
143 | is >> charge; |
---|
144 | |
---|
145 | switch (charge) { |
---|
146 | case 1: |
---|
147 | myCharge = G4TrajectoryDrawByCharge::Positive; |
---|
148 | break; |
---|
149 | case 0: |
---|
150 | myCharge = G4TrajectoryDrawByCharge::Neutral; |
---|
151 | break; |
---|
152 | case -1: |
---|
153 | myCharge = G4TrajectoryDrawByCharge::Negative; |
---|
154 | break; |
---|
155 | default: |
---|
156 | result = false; |
---|
157 | } |
---|
158 | |
---|
159 | return result; |
---|
160 | } |
---|