Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4XXXFileSceneHandler.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 7th March 2006
30// A template for a file-writing graphics driver.
31//?? Lines beginning like this require specialisation for your driver.
32
34
35#include "G4XXXFileViewer.hh"
38#include "G4VPhysicalVolume.hh"
39#include "G4LogicalVolume.hh"
40#include "G4Box.hh"
41#include "G4Polyline.hh"
42#include "G4Text.hh"
43#include "G4Circle.hh"
44#include "G4Square.hh"
45#include "G4Polyhedron.hh"
46#include "G4UnitsTable.hh"
47
48#include <sstream>
49
51// Counter for XXX scene handlers.
52
54 const G4String& name):
55 G4VSceneHandler(system, fSceneIdCount++, name)
56{}
57
59
60#ifdef G4XXXFileDEBUG
61// Useful function...
62void G4XXXFileSceneHandler::PrintThings() {
63 G4cout <<
64 " with transformation "
65 << (void*)fpObjectTransformation;
66 if (fpModel) {
67 G4cout << " from " << fpModel->GetCurrentDescription()
68 << " (tag " << fpModel->GetCurrentTag()
69 << ')';
70 } else {
71 G4cout << "(not from a model)";
72 }
73 G4PhysicalVolumeModel* pPVModel =
74 dynamic_cast<G4PhysicalVolumeModel*>(fpModel);
75 if (pPVModel) {
76 G4cout <<
77 "\n current physical volume: "
78 << pPVModel->GetCurrentPV()->GetName() <<
79 "\n current logical volume: "
80// There might be a problem with the LV pointer if this is a G4LogicalVolumeModel
81 << pPVModel->GetCurrentLV()->GetName() <<
82 "\n current depth of geometry tree: "
83 << pPVModel->GetCurrentDepth();
84 }
85 G4cout << G4endl;
86}
87#endif
88
89// Note: This function overrides G4VSceneHandler::AddSolid(const
90// G4Box&). You may not want to do this, but this is how it's done if
91// you do. Certain other specific solids may be treated this way -
92// see G4VSceneHandler.hh. The simplest possible driver would *not*
93// implement these polymorphic functions, with the effect that the
94// default versions in G4VSceneHandler are used, which simply call
95// G4VSceneHandler::RequestPrimitives to turn the solid into a
96// G4Polyhedron usually.
98#ifdef G4XXXFileDEBUG
99 G4cout <<
100 "G4XXXFileSceneHandler::AddSolid(const G4Box& box) called for "
101 << box.GetName()
102 << G4endl;
103#endif
104 //?? Process your box...
105 std::ostringstream oss;
106 oss << "G4Box(" <<
110 (box.GetXHalfLength(), box.GetYHalfLength(), box.GetZHalfLength()),
111 "Length")).strip() << ')';
112 dynamic_cast<G4XXXFileViewer*>(fpViewer)->
113 GetFileWriter().WriteItem(oss.str());
114}
115
117#ifdef G4XXXFileDEBUG
118 G4cout <<
119 "G4XXXFileSceneHandler::AddPrimitive(const G4Polyline& polyline) called.\n"
120 << polyline
121 << G4endl;
122#endif
123 // Get vis attributes - pick up defaults if none.
124 //const G4VisAttributes* pVA =
125 // fpViewer -> GetApplicableVisAttributes (polyline.GetVisAttributes ());
126 //?? Process polyline.
127 std::ostringstream oss;
128 oss << polyline;
129 dynamic_cast<G4XXXFileViewer*>(fpViewer)->
130 GetFileWriter().WriteItem(oss.str());
131}
132
134#ifdef G4XXXFileDEBUG
135 G4cout <<
136 "G4XXXFileSceneHandler::AddPrimitive(const G4Text& text) called.\n"
137 << text
138 << G4endl;
139#endif
140 // Get text colour - special method since default text colour is
141 // determined by the default text vis attributes, which may be
142 // specified independent of default vis attributes of other types of
143 // visible objects.
144 //const G4Colour& c = GetTextColour (text); // Picks up default if none.
145 //?? Process text.
146 std::ostringstream oss;
147 oss << text;
148 dynamic_cast<G4XXXFileViewer*>(fpViewer)->
149 GetFileWriter().WriteItem(oss.str());
150}
151
153#ifdef G4XXXFileDEBUG
154 G4cout <<
155 "G4XXXFileSceneHandler::AddPrimitive(const G4Circle& circle) called.\n "
156 << circle
157 << G4endl;
158 MarkerSizeType sizeType;
159 G4double size = GetMarkerSize (circle, sizeType);
160 switch (sizeType) {
161 default:
162 case screen:
163 // Draw in screen coordinates.
164 G4cout << "screen";
165 break;
166 case world:
167 // Draw in world coordinates.
168 G4cout << "world";
169 break;
170 }
171 G4cout << " size: " << size << G4endl;
172#endif
173 // Get vis attributes - pick up defaults if none.
174 //const G4VisAttributes* pVA =
175 // fpViewer -> GetApplicableVisAttributes (circle.GetVisAttributes ());
176 //?? Process circle.
177 std::ostringstream oss;
178 oss << circle;
179 dynamic_cast<G4XXXFileViewer*>(fpViewer)->
180 GetFileWriter().WriteItem(oss.str());
181}
182
184#ifdef G4XXXFileDEBUG
185 G4cout <<
186 "G4XXXFileSceneHandler::AddPrimitive(const G4Square& square) called.\n"
187 << square
188 << G4endl;
189 MarkerSizeType sizeType;
190 G4double size = GetMarkerSize (square, sizeType);
191 switch (sizeType) {
192 default:
193 case screen:
194 // Draw in screen coordinates.
195 G4cout << "screen";
196 break;
197 case world:
198 // Draw in world coordinates.
199 G4cout << "world";
200 break;
201 }
202 G4cout << " size: " << size << G4endl;
203#endif
204 // Get vis attributes - pick up defaults if none.
205 //const G4VisAttributes* pVA =
206 // fpViewer -> GetApplicableVisAttributes (square.GetVisAttributes ());
207 //?? Process square.
208 std::ostringstream oss;
209 oss << square;
210 dynamic_cast<G4XXXFileViewer*>(fpViewer)->
211 GetFileWriter().WriteItem(oss.str());
212}
213
215#ifdef G4XXXFileDEBUG
216 G4cout <<
217"G4XXXFileSceneHandler::AddPrimitive(const G4Polyhedron& polyhedron) called.\n"
218 << polyhedron
219 << G4endl;
220#endif
221 //?? Process polyhedron.
222 std::ostringstream oss;
223 oss << polyhedron;
224 dynamic_cast<G4XXXFileViewer*>(fpViewer)->
225 GetFileWriter().WriteItem(oss.str());
226
227 //?? Or... here are some ideas for decomposing into polygons...
228 //Assume all facets are convex quadrilaterals.
229 //Draw each G4Facet individually
230
231 //Get colour, etc..
232 if (polyhedron.GetNoFacets() == 0) return;
233
234 // Get vis attributes - pick up defaults if none.
235 const G4VisAttributes* pVA =
236 fpViewer -> GetApplicableVisAttributes (polyhedron.GetVisAttributes ());
237
238 // Get view parameters that the user can force through the vis
239 // attributes, thereby over-riding the current view parameter.
241 //G4bool isAuxEdgeVisible = GetAuxEdgeVisible (pVA);
242
243 //Get colour, etc..
244 //const G4Colour& c = pVA -> GetColour ();
245
246 // Initial action depending on drawing style.
247 switch (drawing_style) {
249 {
250 break;
251 }
253 {
254 break;
255 }
257 {
258 break;
259 }
260 default:
261 {
262 break;
263 }
264 }
265
266 // Loop through all the facets...
267
268 // Look at G4OpenGLSceneHandler::AddPrimitive(const G4Polyhedron&)
269 // for an example of how to get facets out of a G4Polyhedron,
270 // including how to cope with triangles if that's a problem.
271}
double G4double
Definition: G4Types.hh:83
int G4int
Definition: G4Types.hh:85
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
Definition: G4Box.hh:56
G4double GetYHalfLength() const
G4double GetZHalfLength() const
G4double GetXHalfLength() const
const G4String & GetName() const
G4VPhysicalVolume * GetCurrentPV() const
G4LogicalVolume * GetCurrentLV() const
G4String strip(G4int strip_Type=trailing, char c=' ')
Definition: G4Text.hh:72
virtual G4String GetCurrentDescription() const
Definition: G4VModel.cc:53
virtual G4String GetCurrentTag() const
Definition: G4VModel.cc:48
const G4String & GetName() const
G4double GetMarkerSize(const G4VMarker &, MarkerSizeType &)
G4VViewer * fpViewer
G4ViewParameters::DrawingStyle GetDrawingStyle(const G4VisAttributes *)
G4String GetName() const
const G4VisAttributes * GetVisAttributes() const
void AddPrimitive(const G4Polyline &)
G4XXXFileSceneHandler(G4VGraphicsSystem &system, const G4String &name)
void AddSolid(const G4Box &)
G4int GetNoFacets() const