00001 // 00002 // ******************************************************************** 00003 // * License and Disclaimer * 00004 // * * 00005 // * The Geant4 software is copyright of the Copyright Holders of * 00006 // * the Geant4 Collaboration. It is provided under the terms and * 00007 // * conditions of the Geant4 Software License, included in the file * 00008 // * LICENSE and available at http://cern.ch/geant4/license . These * 00009 // * include a list of copyright holders. * 00010 // * * 00011 // * Neither the authors of this software system, nor their employing * 00012 // * institutes,nor the agencies providing financial support for this * 00013 // * work make any representation or warranty, express or implied, * 00014 // * regarding this software system or assume any liability for its * 00015 // * use. Please see the license in the file LICENSE and URL above * 00016 // * for the full disclaimer and the limitation of liability. * 00017 // * * 00018 // * This code implementation is the result of the scientific and * 00019 // * technical work of the GEANT4 collaboration. * 00020 // * By using, copying, modifying or distributing the software (or * 00021 // * any work based on the software) you agree to acknowledge its * 00022 // * use in resulting scientific publications, and indicate your * 00023 // * acceptance of all terms of the Geant4 Software license. * 00024 // ******************************************************************** 00025 // 00026 // 00027 // $Id$ 00028 // 00029 // 00030 // John Allison 7th March 2006 00031 // A template for a file-writing graphics driver. 00032 //?? Lines beginning like this require specialisation for your driver. 00033 00034 #include "G4XXXFileSceneHandler.hh" 00035 00036 #include "G4XXXFileViewer.hh" 00037 #include "G4PhysicalVolumeModel.hh" 00038 #include "G4LogicalVolumeModel.hh" 00039 #include "G4VPhysicalVolume.hh" 00040 #include "G4LogicalVolume.hh" 00041 #include "G4Box.hh" 00042 #include "G4Polyline.hh" 00043 #include "G4Text.hh" 00044 #include "G4Circle.hh" 00045 #include "G4Square.hh" 00046 #include "G4Polyhedron.hh" 00047 #include "G4UnitsTable.hh" 00048 00049 #include <sstream> 00050 00051 G4int G4XXXFileSceneHandler::fSceneIdCount = 0; 00052 // Counter for XXX scene handlers. 00053 00054 G4XXXFileSceneHandler::G4XXXFileSceneHandler(G4VGraphicsSystem& system, 00055 const G4String& name): 00056 G4VSceneHandler(system, fSceneIdCount++, name) 00057 {} 00058 00059 G4XXXFileSceneHandler::~G4XXXFileSceneHandler() {} 00060 00061 #ifdef G4XXXFileDEBUG 00062 // Useful function... 00063 void G4XXXFileSceneHandler::PrintThings() { 00064 G4cout << 00065 " with transformation " 00066 << (void*)fpObjectTransformation; 00067 if (fpModel) { 00068 G4cout << " from " << fpModel->GetCurrentDescription() 00069 << " (tag " << fpModel->GetCurrentTag() 00070 << ')'; 00071 } else { 00072 G4cout << "(not from a model)"; 00073 } 00074 G4PhysicalVolumeModel* pPVModel = 00075 dynamic_cast<G4PhysicalVolumeModel*>(fpModel); 00076 if (pPVModel) { 00077 G4cout << 00078 "\n current physical volume: " 00079 << pPVModel->GetCurrentPV()->GetName() << 00080 "\n current logical volume: " 00081 // There might be a problem with the LV pointer if this is a G4LogicalVolumeModel 00082 << pPVModel->GetCurrentLV()->GetName() << 00083 "\n current depth of geometry tree: " 00084 << pPVModel->GetCurrentDepth(); 00085 } 00086 G4cout << G4endl; 00087 } 00088 #endif 00089 00090 // Note: This function overrides G4VSceneHandler::AddSolid(const 00091 // G4Box&). You may not want to do this, but this is how it's done if 00092 // you do. Certain other specific solids may be treated this way - 00093 // see G4VSceneHandler.hh. The simplest possible driver would *not* 00094 // implement these polymorphic functions, with the effect that the 00095 // default versions in G4VSceneHandler are used, which simply call 00096 // G4VSceneHandler::RequestPrimitives to turn the solid into a 00097 // G4Polyhedron usually. 00098 void G4XXXFileSceneHandler::AddSolid(const G4Box& box) { 00099 #ifdef G4XXXFileDEBUG 00100 G4cout << 00101 "G4XXXFileSceneHandler::AddSolid(const G4Box& box) called for " 00102 << box.GetName() 00103 << G4endl; 00104 #endif 00105 //?? Process your box... 00106 std::ostringstream oss; 00107 oss << "G4Box(" << 00108 G4String 00109 (G4BestUnit 00110 (G4ThreeVector 00111 (box.GetXHalfLength(), box.GetYHalfLength(), box.GetZHalfLength()), 00112 "Length")).strip() << ')'; 00113 dynamic_cast<G4XXXFileViewer*>(fpViewer)-> 00114 GetFileWriter().WriteItem(oss.str()); 00115 } 00116 00117 void G4XXXFileSceneHandler::AddPrimitive(const G4Polyline& polyline) { 00118 #ifdef G4XXXFileDEBUG 00119 G4cout << 00120 "G4XXXFileSceneHandler::AddPrimitive(const G4Polyline& polyline) called.\n" 00121 << polyline 00122 << G4endl; 00123 #endif 00124 // Get vis attributes - pick up defaults if none. 00125 //const G4VisAttributes* pVA = 00126 // fpViewer -> GetApplicableVisAttributes (polyline.GetVisAttributes ()); 00127 //?? Process polyline. 00128 std::ostringstream oss; 00129 oss << polyline; 00130 dynamic_cast<G4XXXFileViewer*>(fpViewer)-> 00131 GetFileWriter().WriteItem(oss.str()); 00132 } 00133 00134 void G4XXXFileSceneHandler::AddPrimitive(const G4Text& text) { 00135 #ifdef G4XXXFileDEBUG 00136 G4cout << 00137 "G4XXXFileSceneHandler::AddPrimitive(const G4Text& text) called.\n" 00138 << text 00139 << G4endl; 00140 #endif 00141 // Get text colour - special method since default text colour is 00142 // determined by the default text vis attributes, which may be 00143 // specified independent of default vis attributes of other types of 00144 // visible objects. 00145 //const G4Colour& c = GetTextColour (text); // Picks up default if none. 00146 //?? Process text. 00147 std::ostringstream oss; 00148 oss << text; 00149 dynamic_cast<G4XXXFileViewer*>(fpViewer)-> 00150 GetFileWriter().WriteItem(oss.str()); 00151 } 00152 00153 void G4XXXFileSceneHandler::AddPrimitive(const G4Circle& circle) { 00154 #ifdef G4XXXFileDEBUG 00155 G4cout << 00156 "G4XXXFileSceneHandler::AddPrimitive(const G4Circle& circle) called.\n " 00157 << circle 00158 << G4endl; 00159 MarkerSizeType sizeType; 00160 G4double size = GetMarkerSize (circle, sizeType); 00161 switch (sizeType) { 00162 default: 00163 case screen: 00164 // Draw in screen coordinates. 00165 G4cout << "screen"; 00166 break; 00167 case world: 00168 // Draw in world coordinates. 00169 G4cout << "world"; 00170 break; 00171 } 00172 G4cout << " size: " << size << G4endl; 00173 #endif 00174 // Get vis attributes - pick up defaults if none. 00175 //const G4VisAttributes* pVA = 00176 // fpViewer -> GetApplicableVisAttributes (circle.GetVisAttributes ()); 00177 //?? Process circle. 00178 std::ostringstream oss; 00179 oss << circle; 00180 dynamic_cast<G4XXXFileViewer*>(fpViewer)-> 00181 GetFileWriter().WriteItem(oss.str()); 00182 } 00183 00184 void G4XXXFileSceneHandler::AddPrimitive(const G4Square& square) { 00185 #ifdef G4XXXFileDEBUG 00186 G4cout << 00187 "G4XXXFileSceneHandler::AddPrimitive(const G4Square& square) called.\n" 00188 << square 00189 << G4endl; 00190 MarkerSizeType sizeType; 00191 G4double size = GetMarkerSize (square, sizeType); 00192 switch (sizeType) { 00193 default: 00194 case screen: 00195 // Draw in screen coordinates. 00196 G4cout << "screen"; 00197 break; 00198 case world: 00199 // Draw in world coordinates. 00200 G4cout << "world"; 00201 break; 00202 } 00203 G4cout << " size: " << size << G4endl; 00204 #endif 00205 // Get vis attributes - pick up defaults if none. 00206 //const G4VisAttributes* pVA = 00207 // fpViewer -> GetApplicableVisAttributes (square.GetVisAttributes ()); 00208 //?? Process square. 00209 std::ostringstream oss; 00210 oss << square; 00211 dynamic_cast<G4XXXFileViewer*>(fpViewer)-> 00212 GetFileWriter().WriteItem(oss.str()); 00213 } 00214 00215 void G4XXXFileSceneHandler::AddPrimitive(const G4Polyhedron& polyhedron) { 00216 #ifdef G4XXXFileDEBUG 00217 G4cout << 00218 "G4XXXFileSceneHandler::AddPrimitive(const G4Polyhedron& polyhedron) called.\n" 00219 << polyhedron 00220 << G4endl; 00221 #endif 00222 //?? Process polyhedron. 00223 std::ostringstream oss; 00224 oss << polyhedron; 00225 dynamic_cast<G4XXXFileViewer*>(fpViewer)-> 00226 GetFileWriter().WriteItem(oss.str()); 00227 00228 //?? Or... here are some ideas for decomposing into polygons... 00229 //Assume all facets are convex quadrilaterals. 00230 //Draw each G4Facet individually 00231 00232 //Get colour, etc.. 00233 if (polyhedron.GetNoFacets() == 0) return; 00234 00235 // Get vis attributes - pick up defaults if none. 00236 const G4VisAttributes* pVA = 00237 fpViewer -> GetApplicableVisAttributes (polyhedron.GetVisAttributes ()); 00238 00239 // Get view parameters that the user can force through the vis 00240 // attributes, thereby over-riding the current view parameter. 00241 G4ViewParameters::DrawingStyle drawing_style = GetDrawingStyle (pVA); 00242 //G4bool isAuxEdgeVisible = GetAuxEdgeVisible (pVA); 00243 00244 //Get colour, etc.. 00245 //const G4Colour& c = pVA -> GetColour (); 00246 00247 // Initial action depending on drawing style. 00248 switch (drawing_style) { 00249 case (G4ViewParameters::hsr): 00250 { 00251 break; 00252 } 00253 case (G4ViewParameters::hlr): 00254 { 00255 break; 00256 } 00257 case (G4ViewParameters::wireframe): 00258 { 00259 break; 00260 } 00261 default: 00262 { 00263 break; 00264 } 00265 } 00266 00267 // Loop through all the facets... 00268 00269 // Look at G4OpenGLSceneHandler::AddPrimitive(const G4Polyhedron&) 00270 // for an example of how to get facets out of a G4Polyhedron, 00271 // including how to cope with triangles if that's a problem. 00272 } 00273 00274 void G4XXXFileSceneHandler::AddPrimitive(const G4NURBS&) { 00275 #ifdef G4XXXFileDEBUG 00276 G4cout << 00277 "G4XXXFileSceneHandler::AddPrimitive(const G4NURBS& nurbs) called." 00278 << G4endl; 00279 #endif 00280 //?? Don't bother implementing this. NURBS are not functional. 00281 }