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: G4XXXFileSceneHandler.cc,v 1.5 2006/07/03 16:52:49 allison Exp $ |
---|
28 | // GEANT4 tag $Name: $ |
---|
29 | // |
---|
30 | // |
---|
31 | // John Allison 7th March 2006 |
---|
32 | // A template for a file-writing graphics driver. |
---|
33 | //?? Lines beginning like this require specialisation for your driver. |
---|
34 | |
---|
35 | #include "G4XXXFileSceneHandler.hh" |
---|
36 | |
---|
37 | #include "G4XXXFileViewer.hh" |
---|
38 | #include "G4PhysicalVolumeModel.hh" |
---|
39 | #include "G4VPhysicalVolume.hh" |
---|
40 | #include "G4LogicalVolume.hh" |
---|
41 | #include "G4Box.hh" |
---|
42 | #include "G4Polyline.hh" |
---|
43 | #include "G4Text.hh" |
---|
44 | #include "G4Circle.hh" |
---|
45 | #include "G4Square.hh" |
---|
46 | #include "G4Polyhedron.hh" |
---|
47 | #include "G4UnitsTable.hh" |
---|
48 | |
---|
49 | #include <sstream> |
---|
50 | |
---|
51 | G4int G4XXXFileSceneHandler::fSceneIdCount = 0; |
---|
52 | // Counter for XXX scene handlers. |
---|
53 | |
---|
54 | G4XXXFileSceneHandler::G4XXXFileSceneHandler(G4VGraphicsSystem& system, |
---|
55 | const G4String& name): |
---|
56 | G4VSceneHandler(system, fSceneIdCount++, name) |
---|
57 | {} |
---|
58 | |
---|
59 | G4XXXFileSceneHandler::~G4XXXFileSceneHandler() {} |
---|
60 | |
---|
61 | #ifdef G4XXXFileDEBUG |
---|
62 | // Useful function... |
---|
63 | void G4XXXFileSceneHandler::PrintThings() { |
---|
64 | G4cout << |
---|
65 | " with transformation " |
---|
66 | << (void*)fpObjectTransformation; |
---|
67 | if (fpModel) { |
---|
68 | G4cout << " from " << fpModel->GetCurrentDescription() |
---|
69 | << " (tag " << fpModel->GetCurrentTag() |
---|
70 | << ')'; |
---|
71 | } else { |
---|
72 | G4cout << "(not from a model)"; |
---|
73 | } |
---|
74 | G4PhysicalVolumeModel* pPVModel = |
---|
75 | dynamic_cast<G4PhysicalVolumeModel*>(fpModel); |
---|
76 | if (pPVModel) { |
---|
77 | G4cout << |
---|
78 | "\n current physical volume: " |
---|
79 | << pPVModel->GetCurrentPV()->GetName() << |
---|
80 | "\n current logical volume: " |
---|
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. |
---|
97 | void G4XXXFileSceneHandler::AddSolid(const G4Box& box) { |
---|
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(" << |
---|
107 | G4String |
---|
108 | (G4BestUnit |
---|
109 | (G4ThreeVector |
---|
110 | (box.GetXHalfLength(), box.GetYHalfLength(), box.GetZHalfLength()), |
---|
111 | "Length")).strip() << ')'; |
---|
112 | dynamic_cast<G4XXXFileViewer*>(fpViewer)-> |
---|
113 | GetFileWriter().WriteItem(oss.str()); |
---|
114 | } |
---|
115 | |
---|
116 | void G4XXXFileSceneHandler::AddPrimitive(const G4Polyline& polyline) { |
---|
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 | |
---|
133 | void G4XXXFileSceneHandler::AddPrimitive(const G4Text& text) { |
---|
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 | |
---|
152 | void G4XXXFileSceneHandler::AddPrimitive(const G4Circle& circle) { |
---|
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 | |
---|
183 | void G4XXXFileSceneHandler::AddPrimitive(const G4Square& square) { |
---|
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 | |
---|
214 | void G4XXXFileSceneHandler::AddPrimitive(const G4Polyhedron& polyhedron) { |
---|
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. |
---|
240 | G4ViewParameters::DrawingStyle drawing_style = GetDrawingStyle (pVA); |
---|
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) { |
---|
248 | case (G4ViewParameters::hsr): |
---|
249 | { |
---|
250 | break; |
---|
251 | } |
---|
252 | case (G4ViewParameters::hlr): |
---|
253 | { |
---|
254 | break; |
---|
255 | } |
---|
256 | case (G4ViewParameters::wireframe): |
---|
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 | } |
---|
272 | |
---|
273 | void G4XXXFileSceneHandler::AddPrimitive(const G4NURBS&) { |
---|
274 | #ifdef G4XXXFileDEBUG |
---|
275 | G4cout << |
---|
276 | "G4XXXFileSceneHandler::AddPrimitive(const G4NURBS& nurbs) called." |
---|
277 | << G4endl; |
---|
278 | #endif |
---|
279 | //?? Don't bother implementing this. NURBS are not functional. |
---|
280 | } |
---|