Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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$
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 
47 (G4double x0, G4double y0, G4double z0, G4double length,
48  G4double arrowWidth,
49  const G4String& colourString,
50  const G4String& description,
51  G4bool withAnnotation):
52  fXAxisModel(0),
53  fXLabelModel(0),
54  fXAnnotationModel(0),
55  fYAxisModel(0),
56  fYLabelModel(0),
57  fYAnnotationModel(0),
58  fZAxisModel(0),
59  fZLabelModel(0),
60  fZAnnotationModel(0)
61 {
62  fType = "G4AxesModel";
63  fGlobalTag = fType;
64  fGlobalDescription = fType + ": " + description;
65  fExtent = G4VisExtent
66  (x0, x0+length, y0, y0+length, z0, z0+length);
67 
68  G4Colour colour(1,1,1,1); // Default white and opaque (unless "auto").
69  G4bool autoColour = false;
70  if (colourString == "auto") autoColour = true;
71  else {
72  if (!G4Colour::GetColour(colourString, colour)) {
74  ed << "Colour \"" << colourString
75  << "\" not found. Defaulting to white and opaque.";
77  ("G4AxesModel::G4AxesModel",
78  "modeling0012", JustWarning, ed);
79  }
80  }
81 
82  G4String annotation = G4BestUnit(length,"Length");
83 
84  G4Text* text = 0;
85  G4VisAttributes* va = 0;
86 
87  G4Colour xColour(colour);
88  if (autoColour) xColour = G4Colour::Red();
89  fXAxisModel = new G4ArrowModel
90  (x0, y0, z0, x0+length, y0, z0, arrowWidth,
91  xColour, "x-axis: " + description);
92  if (withAnnotation) {
93  text = new G4Text("x",G4Point3D(x0+1.05*length, y0, z0));
94  text->SetScreenSize(10.);
96  va = new G4VisAttributes(xColour);
97  text->SetVisAttributes(va);
98  fXLabelModel = new G4TextModel(*text);
99  text = new G4Text(annotation,G4Point3D(x0+0.8*length, y0, z0));
100  text->SetScreenSize(10.);
101  text->SetOffset(5.,5.);
102  text->SetLayout(G4Text::centre);
103  va = new G4VisAttributes(xColour);
104  text->SetVisAttributes(va);
105  fXAnnotationModel = new G4TextModel(*text);
106  }
107 
108  G4Colour yColour(colour);
109  if (autoColour) yColour = G4Colour::Green();
110  fYAxisModel = new G4ArrowModel
111  (x0, y0, z0, x0, y0+length, z0, arrowWidth,
112  yColour, "y-axis: " + description);
113  if (withAnnotation) {
114  text = new G4Text("y",G4Point3D(x0, y0+1.05*length, z0));
115  text->SetScreenSize(10.);
116  text->SetLayout(G4Text::centre);
117  va = new G4VisAttributes(yColour);
118  text->SetVisAttributes(va);
119  fYLabelModel = new G4TextModel(*text);
120  text = new G4Text(annotation,G4Point3D(x0, y0+0.8*length, z0));
121  text->SetScreenSize(10.);
122  text->SetOffset(5.,5.);
123  text->SetLayout(G4Text::centre);
124  va = new G4VisAttributes(yColour);
125  text->SetVisAttributes(va);
126  fYAnnotationModel = new G4TextModel(*text);
127  }
128 
129  G4Colour zColour(colour);
130  if (autoColour) zColour = G4Colour::Blue();
131  fZAxisModel = new G4ArrowModel
132  (x0, y0, z0, x0, y0, z0+length, arrowWidth,
133  zColour, "z-axis: " + description);
134  if (withAnnotation) {
135  text = new G4Text("z",G4Point3D(x0, y0, z0+1.05*length));
136  text->SetScreenSize(10.);
137  text->SetLayout(G4Text::centre);
138  va = new G4VisAttributes(zColour);
139  text->SetVisAttributes(va);
140  fZLabelModel = new G4TextModel(*text);
141  text = new G4Text(annotation,G4Point3D(x0, y0, z0+0.8*length));
142  text->SetScreenSize(10.);
143  text->SetOffset(5.,5.);
144  text->SetLayout(G4Text::centre);
145  va = new G4VisAttributes(zColour);
146  text->SetVisAttributes(va);
147  fZAnnotationModel = new G4TextModel(*text);
148  }
149 }
150 
152 {
153  if (fXAxisModel) fXAxisModel->DescribeYourselfTo(sceneHandler);
154  if (fXLabelModel) fXLabelModel->DescribeYourselfTo(sceneHandler);
155  if (fXAnnotationModel) fXAnnotationModel->DescribeYourselfTo(sceneHandler);
156  if (fYAxisModel) fYAxisModel->DescribeYourselfTo(sceneHandler);
157  if (fYLabelModel) fYLabelModel->DescribeYourselfTo(sceneHandler);
158  if (fYAnnotationModel) fYAnnotationModel->DescribeYourselfTo(sceneHandler);
159  if (fZAxisModel) fZAxisModel->DescribeYourselfTo(sceneHandler);
160  if (fZLabelModel) fZLabelModel->DescribeYourselfTo(sceneHandler);
161  if (fZAnnotationModel) fZAnnotationModel->DescribeYourselfTo(sceneHandler);
162 }