Geant4_10
G4AxesModel.cc
Go to the documentation of this file.
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 // $Id: G4AxesModel.cc 68043 2013-03-13 14:27:49Z gcosmo $
28 //
29 //
30 // John Allison 3rd April 2001
31 // Model which knows how to draw axes.
32 
33 #include "G4AxesModel.hh"
34 
35 #include "G4ModelingParameters.hh"
36 #include "G4VGraphicsScene.hh"
37 #include "G4VisAttributes.hh"
38 #include "G4Polyline.hh"
39 #include "G4Colour.hh"
40 #include "G4UnitsTable.hh"
41 #include "G4ArrowModel.hh"
42 #include "G4TextModel.hh"
43 
45 {
46  delete fZAnnotationModel;
47  delete fZLabelModel;
48  delete fZAxisModel;
49  delete fYAnnotationModel;
50  delete fYLabelModel;
51  delete fYAxisModel;
52  delete fXAnnotationModel;
53  delete fXLabelModel;
54  delete fXAxisModel;
55 }
56 
59  G4double arrowWidth,
60  const G4String& colourString,
61  const G4String& description,
62  G4bool withAnnotation):
63  fXAxisModel(0),
64  fXLabelModel(0),
65  fXAnnotationModel(0),
66  fYAxisModel(0),
67  fYLabelModel(0),
68  fYAnnotationModel(0),
69  fZAxisModel(0),
70  fZLabelModel(0),
71  fZAnnotationModel(0)
72 {
73  fType = "G4AxesModel";
74  fGlobalTag = fType;
75  fGlobalDescription = fType + ": " + description;
76  fExtent = G4VisExtent
77  (x0, x0+length, y0, y0+length, z0, z0+length);
78 
79  G4Colour colour(1,1,1,1); // Default white and opaque (unless "auto").
80  G4bool autoColour = false;
81  if (colourString == "auto") autoColour = true;
82  else {
83  if (!G4Colour::GetColour(colourString, colour)) {
85  ed << "Colour \"" << colourString
86  << "\" not found. Defaulting to white and opaque.";
88  ("G4AxesModel::G4AxesModel",
89  "modeling0012", JustWarning, ed);
90  }
91  }
92 
93  G4String annotation = G4BestUnit(length,"Length");
94 
95  G4Text* text = 0;
96  G4VisAttributes* va = 0;
97 
98  G4Colour xColour(colour);
99  if (autoColour) xColour = G4Colour::Red();
100  fXAxisModel = new G4ArrowModel
101  (x0, y0, z0, x0+length, y0, z0, arrowWidth,
102  xColour, "x-axis: " + description);
103  if (withAnnotation) {
104  text = new G4Text("x",G4Point3D(x0+1.05*length, y0, z0));
105  text->SetScreenSize(10.);
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(10.);
113  text->SetOffset(5.,5.);
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(10.);
129  text->SetLayout(G4Text::centre);
130  va = new G4VisAttributes(yColour);
131  text->SetVisAttributes(va);
132  fYLabelModel = new G4TextModel(*text);
133  delete text;
134  text = new G4Text(annotation,G4Point3D(x0, y0+0.8*length, z0));
135  text->SetScreenSize(10.);
136  text->SetOffset(5.,5.);
137  text->SetLayout(G4Text::centre);
138  va = new G4VisAttributes(yColour);
139  text->SetVisAttributes(va);
140  fYAnnotationModel = new G4TextModel(*text);
141  delete text;
142  }
143 
144  G4Colour zColour(colour);
145  if (autoColour) zColour = G4Colour::Blue();
146  fZAxisModel = new G4ArrowModel
147  (x0, y0, z0, x0, y0, z0+length, arrowWidth,
148  zColour, "z-axis: " + description);
149  if (withAnnotation) {
150  text = new G4Text("z",G4Point3D(x0, y0, z0+1.05*length));
151  text->SetScreenSize(10.);
152  text->SetLayout(G4Text::centre);
153  va = new G4VisAttributes(zColour);
154  text->SetVisAttributes(va);
155  fZLabelModel = new G4TextModel(*text);
156  delete text;
157  text = new G4Text(annotation,G4Point3D(x0, y0, z0+0.8*length));
158  text->SetScreenSize(10.);
159  text->SetOffset(5.,5.);
160  text->SetLayout(G4Text::centre);
161  va = new G4VisAttributes(zColour);
162  text->SetVisAttributes(va);
163  fZAnnotationModel = new G4TextModel(*text);
164  delete text;
165  }
166 }
167 
169 {
170  if (fXAxisModel) fXAxisModel->DescribeYourselfTo(sceneHandler);
171  if (fXLabelModel) fXLabelModel->DescribeYourselfTo(sceneHandler);
172  if (fXAnnotationModel) fXAnnotationModel->DescribeYourselfTo(sceneHandler);
173  if (fYAxisModel) fYAxisModel->DescribeYourselfTo(sceneHandler);
174  if (fYLabelModel) fYLabelModel->DescribeYourselfTo(sceneHandler);
175  if (fYAnnotationModel) fYAnnotationModel->DescribeYourselfTo(sceneHandler);
176  if (fZAxisModel) fZAxisModel->DescribeYourselfTo(sceneHandler);
177  if (fZLabelModel) fZLabelModel->DescribeYourselfTo(sceneHandler);
178  if (fZAnnotationModel) fZAnnotationModel->DescribeYourselfTo(sceneHandler);
179 }
Definition: G4Text.hh:73
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
static G4Colour Green()
Definition: G4Colour.hh:149
void SetLayout(Layout)
static G4bool GetColour(const G4String &key, G4Colour &result)
Definition: G4Colour.cc:126
HepGeom::Point3D< G4double > G4Point3D
Definition: G4Point3D.hh:35
#define G4BestUnit(a, b)
#define G4_USE_G4BESTUNIT_FOR_VERBOSE 1
virtual void DescribeYourselfTo(G4VGraphicsScene &)=0
bool G4bool
Definition: G4Types.hh:79
virtual void DescribeYourselfTo(G4VGraphicsScene &)
Definition: G4AxesModel.cc:168
static G4Colour Blue()
Definition: G4Colour.hh:150
virtual ~G4AxesModel()
Definition: G4AxesModel.cc:44
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
void SetVisAttributes(const G4VisAttributes *)
Definition: G4Visible.cc:80
void SetOffset(double dx, double dy)
static G4Colour Red()
Definition: G4Colour.hh:148
double G4double
Definition: G4Types.hh:76
G4AxesModel(G4double x0, G4double y0, G4double z0, G4double length, G4double arrowWidth=1., const G4String &colourString="auto", const G4String &description="", G4bool withAnnotation=true)
Definition: G4AxesModel.cc:58
void SetScreenSize(G4double)