00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "G4TrajectoryDrawByCharge.hh"
00030 #include "G4TrajectoryDrawerUtils.hh"
00031 #include "G4VisTrajContext.hh"
00032 #include "G4VTrajectory.hh"
00033 #include <sstream>
00034
00035 G4TrajectoryDrawByCharge::G4TrajectoryDrawByCharge(const G4String& name, G4VisTrajContext* context)
00036 :G4VTrajectoryModel(name, context)
00037 {
00038
00039 fMap[Positive] = G4Colour::Blue();
00040 fMap[Negative] = G4Colour::Red();
00041 fMap[Neutral] = G4Colour::Green();
00042 }
00043
00044 G4TrajectoryDrawByCharge::G4TrajectoryDrawByCharge(const G4String& name,
00045 const G4Colour& positive,
00046 const G4Colour& negative,
00047 const G4Colour& neutral)
00048 :G4VTrajectoryModel(name)
00049 {
00050 fMap[Positive] = positive;
00051 fMap[Negative] = negative;
00052 fMap[Neutral] = neutral;
00053 }
00054
00055 G4TrajectoryDrawByCharge::~G4TrajectoryDrawByCharge() {}
00056
00057 void
00058 G4TrajectoryDrawByCharge::Draw(const G4VTrajectory& object,
00059 const G4int&,
00060 const G4bool& visible) const
00061 {
00062 Draw(object, visible);
00063 }
00064
00065 void
00066 G4TrajectoryDrawByCharge::Draw(const G4VTrajectory& traj, const G4bool& visible) const
00067 {
00068 G4Colour colour;
00069
00070 const G4double charge = traj.GetCharge();
00071
00072 if(charge>0.) fMap.GetColour(Positive, colour);
00073 else if(charge<0.) fMap.GetColour(Negative, colour);
00074 else fMap.GetColour(Neutral, colour);
00075
00076 G4VisTrajContext myContext(GetContext());
00077
00078 myContext.SetLineColour(colour);
00079 myContext.SetVisible(visible);
00080
00081 if (GetVerbose()) {
00082 G4cout<<"G4TrajectoryDrawByCharge drawer named "<<Name();
00083 G4cout<<", drawing trajectory with charge, "<<charge<<G4endl;
00084 G4cout<<", with configuration:"<<G4endl;
00085 myContext.Print(G4cout);
00086 }
00087
00088 G4TrajectoryDrawerUtils::DrawLineAndPoints(traj, myContext);
00089 }
00090
00091 void
00092 G4TrajectoryDrawByCharge::Print(std::ostream& ostr) const
00093 {
00094 ostr<<"G4TrajectoryDrawByCharge model "<< Name() <<" colour scheme: "<<std::endl;
00095 fMap.Print(ostr);
00096 ostr<<"Default configuration:"<<G4endl;
00097 GetContext().Print(G4cout);
00098 }
00099
00100 void
00101 G4TrajectoryDrawByCharge::Set(const Charge& charge, const G4String& colour)
00102 {
00103 fMap.Set(charge, colour);
00104 }
00105
00106 void
00107 G4TrajectoryDrawByCharge::Set(const Charge& charge, const G4Colour& colour)
00108 {
00109 fMap[charge] = colour;
00110 }
00111
00112 void
00113 G4TrajectoryDrawByCharge::Set(const G4String& charge, const G4String& colour)
00114 {
00115 Charge myCharge;
00116
00117 if (!ConvertToCharge(charge, myCharge)) {
00118 G4ExceptionDescription ed;
00119 ed << "Invalid charge "<<charge;
00120 G4Exception
00121 ("G4TrajectoryDrawByCharge::Set(const G4int& charge, const G4String& colour)", "modeling0121", JustWarning, ed);
00122 return;
00123 }
00124
00125 return Set(myCharge, colour);
00126 }
00127
00128 void
00129 G4TrajectoryDrawByCharge::Set(const G4String& charge, const G4Colour& colour)
00130 {
00131 Charge myCharge;
00132
00133 if (!ConvertToCharge(charge, myCharge)) {
00134 G4ExceptionDescription ed;
00135 ed << "Invalid charge "<<charge;
00136 G4Exception
00137 ("G4TrajectoryDrawByCharge::Set(const G4int& charge, const G4Colour& colour)", "modeling0122", JustWarning, ed);
00138 }
00139
00140 return Set(myCharge, colour);
00141 }
00142
00143 G4bool
00144 G4TrajectoryDrawByCharge::ConvertToCharge(const G4String& string, Charge& myCharge)
00145 {
00146 bool result(true);
00147
00148 G4int charge;
00149 std::istringstream is(string.c_str());
00150 is >> charge;
00151
00152 switch (charge) {
00153 case 1:
00154 myCharge = G4TrajectoryDrawByCharge::Positive;
00155 break;
00156 case 0:
00157 myCharge = G4TrajectoryDrawByCharge::Neutral;
00158 break;
00159 case -1:
00160 myCharge = G4TrajectoryDrawByCharge::Negative;
00161 break;
00162 default:
00163 result = false;
00164 }
00165
00166 return result;
00167 }