ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4AxesModel.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4AxesModel.cc
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 //
27 //
28 //
29 // John Allison 3rd April 2001
30 // Model which knows how to draw axes.
31 
32 #include "G4AxesModel.hh"
33 
34 #include "G4ModelingParameters.hh"
35 #include "G4VGraphicsScene.hh"
36 #include "G4VisAttributes.hh"
37 #include "G4Polyline.hh"
38 #include "G4Colour.hh"
39 #include "G4UnitsTable.hh"
40 #include "G4ArrowModel.hh"
41 #include "G4TextModel.hh"
42 
44 {
45  delete fZAnnotationModel;
46  delete fZLabelModel;
47  delete fZAxisModel;
48  delete fYAnnotationModel;
49  delete fYLabelModel;
50  delete fYAxisModel;
51  delete fXAnnotationModel;
52  delete fXLabelModel;
53  delete fXAxisModel;
54 }
55 
58  G4double arrowWidth, const G4String& colourString,
59  const G4String& description,
60  G4bool withAnnotation,
61  G4double textSize):
62  fXAxisModel(0),
63  fXLabelModel(0),
64  fXAnnotationModel(0),
65  fYAxisModel(0),
66  fYLabelModel(0),
67  fYAnnotationModel(0),
68  fZAxisModel(0),
69  fZLabelModel(0),
70  fZAnnotationModel(0)
71 {
72  fType = "G4AxesModel";
73  fGlobalTag = fType;
74  fGlobalDescription = fType + ": " + description;
75  fExtent = G4VisExtent
76  (x0, x0+length, y0, y0+length, z0, z0+length);
77 
78  G4Colour colour(1,1,1,1); // Default white and opaque (unless "auto").
79  G4bool autoColour = false;
80  if (colourString == "auto") autoColour = true;
81  else {
82  if (!G4Colour::GetColour(colourString, colour)) {
84  ed << "Colour \"" << colourString
85  << "\" not found. Defaulting to white and opaque.";
87  ("G4AxesModel::G4AxesModel",
88  "modeling0011", JustWarning, ed);
89  }
90  }
91 
92  G4String annotation = G4BestUnit(length,"Length");
93 
94  G4Text* text = 0;
95  G4VisAttributes* va = 0;
96 
97  G4Colour xColour(colour);
98  if (autoColour) xColour = G4Colour::Red();
99  fXAxisModel = new G4ArrowModel
100  (x0, y0, z0, x0+length, y0, z0, arrowWidth,
101  xColour, "x-axis: " + description);
102  if (withAnnotation) {
103  text = new G4Text("x",G4Point3D(x0+1.05*length, y0, z0));
104  text->SetScreenSize(textSize);
105  text->SetOffset(0.5*textSize,0.5*textSize);
106  text->SetLayout(G4Text::centre);
107  va = new G4VisAttributes(xColour);
108  text->SetVisAttributes(va);
109  fXLabelModel = new G4TextModel(*text);
110  delete text;
111  text = new G4Text(annotation,G4Point3D(x0+0.8*length, y0, z0));
112  text->SetScreenSize(textSize);
113  text->SetOffset(-1.5*textSize,-1.5*textSize);
114  text->SetLayout(G4Text::centre);
115  va = new G4VisAttributes(xColour);
116  text->SetVisAttributes(va);
117  fXAnnotationModel = new G4TextModel(*text);
118  delete text;
119  }
120 
121  G4Colour yColour(colour);
122  if (autoColour) yColour = G4Colour::Green();
123  fYAxisModel = new G4ArrowModel
124  (x0, y0, z0, x0, y0+length, z0, arrowWidth,
125  yColour, "y-axis: " + description);
126  if (withAnnotation) {
127  text = new G4Text("y",G4Point3D(x0, y0+1.05*length, z0));
128  text->SetScreenSize(textSize);
129  text->SetOffset(0.5*textSize,0.5*textSize);
130  text->SetLayout(G4Text::centre);
131  va = new G4VisAttributes(yColour);
132  text->SetVisAttributes(va);
133  fYLabelModel = new G4TextModel(*text);
134  delete text;
135  text = new G4Text(annotation,G4Point3D(x0, y0+0.8*length, z0));
136  text->SetScreenSize(textSize);
137  text->SetOffset(-1.5*textSize,-1.5*textSize);
138  text->SetLayout(G4Text::centre);
139  va = new G4VisAttributes(yColour);
140  text->SetVisAttributes(va);
141  fYAnnotationModel = new G4TextModel(*text);
142  delete text;
143  }
144 
145  G4Colour zColour(colour);
146  if (autoColour) zColour = G4Colour::Blue();
147  fZAxisModel = new G4ArrowModel
148  (x0, y0, z0, x0, y0, z0+length, arrowWidth,
149  zColour, "z-axis: " + description);
150  if (withAnnotation) {
151  text = new G4Text("z",G4Point3D(x0, y0, z0+1.05*length));
152  text->SetScreenSize(textSize);
153  text->SetOffset(0.5*textSize,0.5*textSize);
154  text->SetLayout(G4Text::centre);
155  va = new G4VisAttributes(zColour);
156  text->SetVisAttributes(va);
157  fZLabelModel = new G4TextModel(*text);
158  delete text;
159  text = new G4Text(annotation,G4Point3D(x0, y0, z0+0.8*length));
160  text->SetScreenSize(textSize);
161  text->SetOffset(-1.5*textSize,-1.5*textSize);
162  text->SetLayout(G4Text::centre);
163  va = new G4VisAttributes(zColour);
164  text->SetVisAttributes(va);
165  fZAnnotationModel = new G4TextModel(*text);
166  delete text;
167  }
168 }
169 
171 {
172  if (fXAxisModel) fXAxisModel->DescribeYourselfTo(sceneHandler);
173  if (fXLabelModel) fXLabelModel->DescribeYourselfTo(sceneHandler);
175  if (fYAxisModel) fYAxisModel->DescribeYourselfTo(sceneHandler);
176  if (fYLabelModel) fYLabelModel->DescribeYourselfTo(sceneHandler);
178  if (fZAxisModel) fZAxisModel->DescribeYourselfTo(sceneHandler);
179  if (fZLabelModel) fZLabelModel->DescribeYourselfTo(sceneHandler);
181 }