Geant4-11
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//
28//
29// John Allison 3rd April 2001
30// Model which knows how to draw axes.
31
32#include "G4AxesModel.hh"
33
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
57(G4double x0, G4double y0, G4double z0, G4double length,
58 G4double arrowWidth, const G4String& colourString,
59 const G4String& description,
60 G4bool withAnnotation,
61 G4double textSize,
63{
65 (x0,y0,z0,length,arrowWidth,
66 colourString,description,withAnnotation,textSize,
67 transform);
68}
69
70// Alternative short constructor
72(G4double x0, G4double y0, G4double z0, G4double length,
74{
75 G4double arrowWidth = 1.;
76 const G4String& colourString = "auto";
77 const G4String& description = "";
78 G4bool withAnnotation = true;
79 G4double textSize = 10.;
81 (x0,y0,z0,length,arrowWidth,
82 colourString,description,withAnnotation,textSize,
83 transform);
84}
85
87(G4double x0, G4double y0, G4double z0, G4double length,
88 G4double arrowWidth, const G4String& colourString,
89 const G4String& description,
90 G4bool withAnnotation,
91 G4double textSize,
93{
94 fXAxisModel = nullptr;
95 fXLabelModel = nullptr;
96 fXAnnotationModel = nullptr;
97 fYAxisModel = nullptr;
98 fYLabelModel = nullptr;
99 fYAnnotationModel = nullptr;
100 fZAxisModel = nullptr;
101 fZLabelModel = nullptr;
102 fZAnnotationModel = nullptr;
103
105
106 fType = "Axes";
108 fGlobalDescription = fType + ": " + description;
110 (x0, x0+length, y0, y0+length, z0, z0+length);
111
112 G4Colour colour(1,1,1,1); // Default white and opaque (unless "auto").
113 G4bool autoColour = false;
114 if (colourString == "auto") autoColour = true;
115 else {
116 if (!G4Colour::GetColour(colourString, colour)) {
118 ed << "Colour \"" << colourString
119 << "\" not found. Defaulting to white and opaque.";
121 ("G4AxesModel::G4AxesModel",
122 "modeling0011", JustWarning, ed);
123 }
124 }
125
126 G4String annotation = G4BestUnit(length,"Length");
127
128 G4Text* text = 0;
129 G4VisAttributes* va = 0;
130 G4int lineSegmentsPerCircle = 6;
131
132 G4Colour xColour(colour);
133 if (autoColour) xColour = G4Colour::Red();
135 (x0, y0, z0, x0+length, y0, z0, arrowWidth,
136 xColour, "x-axis: " + description,
137 lineSegmentsPerCircle, fTransform);
138 if (withAnnotation) {
139 text = new G4Text("x",G4Point3D(x0+1.05*length, y0, z0));
140 text->SetScreenSize(textSize);
141 text->SetOffset(0.5*textSize,0.5*textSize);
143 va = new G4VisAttributes(xColour);
144 text->SetVisAttributes(va);
146 delete text;
147 text = new G4Text(annotation,G4Point3D(x0+0.8*length, y0, z0));
148 text->SetScreenSize(textSize);
149 text->SetOffset(-1.5*textSize,-1.5*textSize);
151 va = new G4VisAttributes(xColour);
152 text->SetVisAttributes(va);
154 delete text;
155 }
156
157 G4Colour yColour(colour);
158 if (autoColour) yColour = G4Colour::Green();
160 (x0, y0, z0, x0, y0+length, z0, arrowWidth,
161 yColour, "y-axis: " + description,
162 lineSegmentsPerCircle, fTransform);
163 if (withAnnotation) {
164 text = new G4Text("y",G4Point3D(x0, y0+1.05*length, z0));
165 text->SetScreenSize(textSize);
166 text->SetOffset(0.5*textSize,0.5*textSize);
168 va = new G4VisAttributes(yColour);
169 text->SetVisAttributes(va);
171 delete text;
172 text = new G4Text(annotation,G4Point3D(x0, y0+0.8*length, z0));
173 text->SetScreenSize(textSize);
174 text->SetOffset(-1.5*textSize,-1.5*textSize);
176 va = new G4VisAttributes(yColour);
177 text->SetVisAttributes(va);
179 delete text;
180 }
181
182 G4Colour zColour(colour);
183 if (autoColour) zColour = G4Colour::Blue();
185 (x0, y0, z0, x0, y0, z0+length, arrowWidth,
186 zColour, "z-axis: " + description,
187 lineSegmentsPerCircle, fTransform);
188 if (withAnnotation) {
189 text = new G4Text("z",G4Point3D(x0, y0, z0+1.05*length));
190 text->SetScreenSize(textSize);
191 text->SetOffset(0.5*textSize,0.5*textSize);
193 va = new G4VisAttributes(zColour);
194 text->SetVisAttributes(va);
196 delete text;
197 text = new G4Text(annotation,G4Point3D(x0, y0, z0+0.8*length));
198 text->SetScreenSize(textSize);
199 text->SetOffset(-1.5*textSize,-1.5*textSize);
201 va = new G4VisAttributes(zColour);
202 text->SetVisAttributes(va);
204 delete text;
205 }
206}
207
209{
210 if (fXAxisModel) fXAxisModel-> DescribeYourselfTo(sceneHandler);
211 if (fXLabelModel) fXLabelModel-> DescribeYourselfTo(sceneHandler);
213
214 if (fYAxisModel) fYAxisModel-> DescribeYourselfTo(sceneHandler);
215 if (fYLabelModel) fYLabelModel-> DescribeYourselfTo(sceneHandler);
217
218 if (fZAxisModel) fZAxisModel-> DescribeYourselfTo(sceneHandler);
219 if (fZLabelModel) fZLabelModel-> DescribeYourselfTo(sceneHandler);
221}
@ JustWarning
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:40
HepGeom::Point3D< G4double > G4Point3D
Definition: G4Point3D.hh:34
#define G4BestUnit(a, b)
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
virtual ~G4AxesModel()
Definition: G4AxesModel.cc:43
void Construct(G4double x0, G4double y0, G4double z0, G4double length, G4double arrowWidth, const G4String &colourString, const G4String &description, G4bool withAnnotation, G4double textSize, const G4Transform3D &transform)
Definition: G4AxesModel.cc:87
G4AxesModel(G4double x0, G4double y0, G4double z0, G4double length, G4double arrowWidth=1., const G4String &colourString="auto", const G4String &description="", G4bool withAnnotation=true, G4double textSize=10., const G4Transform3D &transform=G4Transform3D())
Definition: G4AxesModel.cc:57
G4VModel * fZAnnotationModel
Definition: G4AxesModel.hh:86
G4VModel * fZLabelModel
Definition: G4AxesModel.hh:86
G4VModel * fXLabelModel
Definition: G4AxesModel.hh:84
G4VModel * fYLabelModel
Definition: G4AxesModel.hh:85
G4VModel * fZAxisModel
Definition: G4AxesModel.hh:86
void DescribeYourselfTo(G4VGraphicsScene &) override
Definition: G4AxesModel.cc:208
G4Transform3D fTransform
Definition: G4AxesModel.hh:87
G4VModel * fYAxisModel
Definition: G4AxesModel.hh:85
G4VModel * fYAnnotationModel
Definition: G4AxesModel.hh:85
G4VModel * fXAxisModel
Definition: G4AxesModel.hh:84
G4VModel * fXAnnotationModel
Definition: G4AxesModel.hh:84
static G4bool GetColour(const G4String &key, G4Colour &result)
Definition: G4Colour.cc:161
static G4Colour Green()
Definition: G4Colour.hh:162
static G4Colour Red()
Definition: G4Colour.hh:161
static G4Colour Blue()
Definition: G4Colour.hh:163
Definition: G4Text.hh:72
void SetLayout(Layout)
void SetOffset(double dx, double dy)
@ centre
Definition: G4Text.hh:76
void SetScreenSize(G4double)
G4VisExtent fExtent
Definition: G4VModel.hh:101
G4String fGlobalDescription
Definition: G4VModel.hh:100
G4String fType
Definition: G4VModel.hh:98
virtual void DescribeYourselfTo(G4VGraphicsScene &)=0
G4String fGlobalTag
Definition: G4VModel.hh:99
void SetVisAttributes(const G4VisAttributes *)
Definition: G4Visible.cc:96
G4bool transform(G4String &input, const G4String &type)