[834] | 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: G4XXXStoredSceneHandler.cc,v 1.9 2006/10/26 11:30:10 allison Exp $ |
---|
[944] | 28 | // GEANT4 tag $Name: $ |
---|
[834] | 29 | // |
---|
| 30 | // |
---|
| 31 | // John Allison 7th March 2006 |
---|
| 32 | // A template for a graphics driver with a store/database. |
---|
| 33 | //?? Lines beginning like this require specialisation for your driver. |
---|
| 34 | |
---|
| 35 | #include "G4XXXStoredSceneHandler.hh" |
---|
| 36 | |
---|
| 37 | #include "G4XXXStoredViewer.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 | #include "G4AttDef.hh" |
---|
| 49 | #include "G4AttValue.hh" |
---|
| 50 | #include "G4AttCheck.hh" |
---|
| 51 | |
---|
| 52 | #include <sstream> |
---|
| 53 | |
---|
| 54 | G4int G4XXXStoredSceneHandler::fSceneIdCount = 0; |
---|
| 55 | // Counter for XXX scene handlers. |
---|
| 56 | |
---|
| 57 | G4XXXStoredSceneHandler::G4XXXStoredSceneHandler(G4VGraphicsSystem& system, |
---|
| 58 | const G4String& name): |
---|
| 59 | G4VSceneHandler(system, fSceneIdCount++, name) |
---|
| 60 | {} |
---|
| 61 | |
---|
| 62 | G4XXXStoredSceneHandler::~G4XXXStoredSceneHandler() {} |
---|
| 63 | |
---|
| 64 | #ifdef G4XXXStoredDEBUG |
---|
| 65 | // Useful function... |
---|
| 66 | void G4XXXStoredSceneHandler::PrintThings() { |
---|
| 67 | G4cout << |
---|
| 68 | " with transformation " |
---|
| 69 | << (void*)fpObjectTransformation; |
---|
| 70 | if (fpModel) { |
---|
| 71 | G4cout << " from " << fpModel->GetCurrentDescription() |
---|
| 72 | << " (tag " << fpModel->GetCurrentTag() |
---|
| 73 | << ')'; |
---|
| 74 | } else { |
---|
| 75 | G4cout << "(not from a model)"; |
---|
| 76 | } |
---|
| 77 | G4PhysicalVolumeModel* pPVModel = |
---|
| 78 | dynamic_cast<G4PhysicalVolumeModel*>(fpModel); |
---|
| 79 | if (pPVModel) { |
---|
| 80 | G4cout << |
---|
| 81 | "\n current physical volume: " |
---|
| 82 | << pPVModel->GetCurrentPV()->GetName() << |
---|
| 83 | "\n current logical volume: " |
---|
| 84 | << pPVModel->GetCurrentLV()->GetName() << |
---|
| 85 | "\n current depth of geometry tree: " |
---|
| 86 | << pPVModel->GetCurrentDepth(); |
---|
| 87 | } |
---|
| 88 | G4cout << G4endl; |
---|
| 89 | } |
---|
| 90 | #endif |
---|
| 91 | |
---|
| 92 | void G4XXXStoredSceneHandler::PreAddSolid |
---|
| 93 | (const G4Transform3D& objectTransformation, |
---|
| 94 | const G4VisAttributes& visAttribs) |
---|
| 95 | { |
---|
| 96 | G4VSceneHandler::PreAddSolid(objectTransformation, visAttribs); |
---|
| 97 | |
---|
| 98 | // Get user G4Atts... |
---|
| 99 | const std::map<G4String,G4AttDef>* userAttDefs = visAttribs.GetAttDefs(); |
---|
| 100 | if (userAttDefs) { |
---|
| 101 | #ifdef G4XXXStoredDEBUG |
---|
| 102 | const std::vector<G4AttValue>* userAttValues = |
---|
| 103 | visAttribs.CreateAttValues(); |
---|
| 104 | G4cout << "\nProvided G4Atts:\n" |
---|
| 105 | << G4AttCheck(userAttValues, userAttDefs); |
---|
| 106 | // Extra checks... |
---|
| 107 | G4AttCheck attCheck(userAttValues, userAttDefs); |
---|
| 108 | if (attCheck.Check()) G4cout << "Error" << G4endl; |
---|
| 109 | else { |
---|
| 110 | std::vector<G4AttValue> standardValues; |
---|
| 111 | std::map<G4String,G4AttDef> standardDefinitions; |
---|
| 112 | attCheck.Standard(&standardValues, &standardDefinitions); |
---|
| 113 | G4cout << "\nStandard G4Atts:\n" |
---|
| 114 | << G4AttCheck(&standardValues, &standardDefinitions); |
---|
| 115 | } |
---|
| 116 | // End of extra checks. |
---|
| 117 | delete userAttValues; // (Must be deleted after use.) |
---|
| 118 | #endif |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | // Get solid's G4Atts created by G4PhysicalVolumeModel... |
---|
| 122 | G4PhysicalVolumeModel* pPVModel = |
---|
| 123 | dynamic_cast<G4PhysicalVolumeModel*>(fpModel); |
---|
| 124 | if (pPVModel) { |
---|
| 125 | const std::map<G4String,G4AttDef>* solidAttDefs = pPVModel->GetAttDefs(); |
---|
| 126 | if (solidAttDefs) { |
---|
| 127 | #ifdef G4XXXStoredDEBUG |
---|
| 128 | std::vector<G4AttValue>* solidAttValues = |
---|
| 129 | pPVModel->CreateCurrentAttValues(); |
---|
| 130 | G4cout << "\nProvided G4Atts:\n" |
---|
| 131 | << G4AttCheck(solidAttValues, solidAttDefs); |
---|
| 132 | // Extra checks... |
---|
| 133 | G4AttCheck attCheck(solidAttValues,solidAttDefs); |
---|
| 134 | if (attCheck.Check()) G4cout << "Error" << G4endl; |
---|
| 135 | else { |
---|
| 136 | std::vector<G4AttValue> standardValues; |
---|
| 137 | std::map<G4String,G4AttDef> standardDefinitions; |
---|
| 138 | attCheck.Standard(&standardValues, &standardDefinitions); |
---|
| 139 | G4cout << "\nStandard G4Atts:\n" |
---|
| 140 | << G4AttCheck(&standardValues, &standardDefinitions); |
---|
| 141 | } |
---|
| 142 | // End of extra checks. |
---|
| 143 | delete solidAttValues; // (Must be deleted after use.) |
---|
| 144 | #endif |
---|
| 145 | } |
---|
| 146 | } |
---|
| 147 | |
---|
| 148 | // Create a place for current solid... |
---|
| 149 | fCurrentItem = fStore.insert(fStore.end(), G4String("\nPreAddSolid:\n")); |
---|
| 150 | if (fReadyForTransients) { |
---|
| 151 | fTransients.push_back(fCurrentItem); |
---|
| 152 | } else { |
---|
| 153 | fPermanents.push_back(fCurrentItem); |
---|
| 154 | } |
---|
| 155 | } |
---|
| 156 | |
---|
| 157 | void G4XXXStoredSceneHandler::PostAddSolid() |
---|
| 158 | { |
---|
| 159 | *fCurrentItem += "\nEndSolid\n"; |
---|
| 160 | G4VSceneHandler::PostAddSolid(); |
---|
| 161 | } |
---|
| 162 | |
---|
| 163 | void G4XXXStoredSceneHandler::BeginPrimitives |
---|
| 164 | (const G4Transform3D& objectTransformation) |
---|
| 165 | { |
---|
| 166 | G4VSceneHandler::BeginPrimitives(objectTransformation); |
---|
| 167 | |
---|
| 168 | // If thread of control has already passed through PreAddSolid, |
---|
| 169 | // avoid opening a graphical data base component again. |
---|
| 170 | if (!fProcessingSolid) { |
---|
| 171 | // Create a place for current primitive... |
---|
| 172 | fCurrentItem = fStore.insert(fStore.end(), |
---|
| 173 | G4String("\nBeginPrimitives:\n")); |
---|
| 174 | if (fReadyForTransients) { |
---|
| 175 | fTransients.push_back(fCurrentItem); |
---|
| 176 | } else { |
---|
| 177 | fPermanents.push_back(fCurrentItem); |
---|
| 178 | } |
---|
| 179 | } |
---|
| 180 | } |
---|
| 181 | |
---|
| 182 | void G4XXXStoredSceneHandler::EndPrimitives () |
---|
| 183 | { |
---|
| 184 | if (!fProcessingSolid) { // Already done if so. |
---|
| 185 | *fCurrentItem += "\nEndPrimitives\n"; |
---|
| 186 | } |
---|
| 187 | G4VSceneHandler::EndPrimitives (); |
---|
| 188 | } |
---|
| 189 | |
---|
| 190 | // Note: This function overrides G4VSceneHandler::AddSolid(const |
---|
| 191 | // G4Box&). You may not want to do this, but this is how it's done if |
---|
| 192 | // you do. Certain other specific solids may be treated this way - |
---|
| 193 | // see G4VSceneHandler.hh. The simplest possible driver would *not* |
---|
| 194 | // implement these polymorphic functions, with the effect that the |
---|
| 195 | // default versions in G4VSceneHandler are used, which simply call |
---|
| 196 | // G4VSceneHandler::RequestPrimitives to turn the solid into a |
---|
| 197 | // G4Polyhedron usually. |
---|
| 198 | // Don't forget, solids can be transients too (e.g., representing a hit). |
---|
| 199 | void G4XXXStoredSceneHandler::AddSolid(const G4Box& box) { |
---|
| 200 | #ifdef G4XXXStoredDEBUG |
---|
| 201 | G4cout << |
---|
| 202 | "G4XXXStoredSceneHandler::AddSolid(const G4Box& box) called for " |
---|
| 203 | << box.GetName() |
---|
| 204 | << G4endl; |
---|
| 205 | #endif |
---|
| 206 | //?? Process your box... |
---|
| 207 | std::ostringstream oss; |
---|
| 208 | oss << "G4Box(" << |
---|
| 209 | G4String |
---|
| 210 | (G4BestUnit |
---|
| 211 | (G4ThreeVector |
---|
| 212 | (box.GetXHalfLength(), box.GetYHalfLength(), box.GetZHalfLength()), |
---|
| 213 | "Length")).strip() << ')'; |
---|
| 214 | *fCurrentItem += oss.str(); |
---|
| 215 | } |
---|
| 216 | |
---|
| 217 | void G4XXXStoredSceneHandler::AddPrimitive(const G4Polyline& polyline) { |
---|
| 218 | #ifdef G4XXXStoredDEBUG |
---|
| 219 | G4cout << |
---|
| 220 | "G4XXXStoredSceneHandler::AddPrimitive(const G4Polyline& polyline) called.\n" |
---|
| 221 | << polyline |
---|
| 222 | << G4endl; |
---|
| 223 | #endif |
---|
| 224 | // Get vis attributes - pick up defaults if none. |
---|
| 225 | //const G4VisAttributes* pVA = |
---|
| 226 | // fpViewer -> GetApplicableVisAttributes (polyline.GetVisAttributes ()); |
---|
| 227 | //?? Process polyline. |
---|
| 228 | std::ostringstream oss; |
---|
| 229 | oss << polyline; |
---|
| 230 | *fCurrentItem += oss.str(); |
---|
| 231 | } |
---|
| 232 | |
---|
| 233 | void G4XXXStoredSceneHandler::AddPrimitive(const G4Text& text) { |
---|
| 234 | #ifdef G4XXXStoredDEBUG |
---|
| 235 | G4cout << |
---|
| 236 | "G4XXXStoredSceneHandler::AddPrimitive(const G4Text& text) called.|n" |
---|
| 237 | << text |
---|
| 238 | << G4endl; |
---|
| 239 | #endif |
---|
| 240 | // Get text colour - special method since default text colour is |
---|
| 241 | // determined by the default text vis attributes, which may be |
---|
| 242 | // specified independent of default vis attributes of other types of |
---|
| 243 | // visible objects. |
---|
| 244 | //const G4Colour& c = GetTextColour (text); // Picks up default if none. |
---|
| 245 | //?? Process text. |
---|
| 246 | std::ostringstream oss; |
---|
| 247 | oss << text; |
---|
| 248 | *fCurrentItem += oss.str(); |
---|
| 249 | } |
---|
| 250 | |
---|
| 251 | void G4XXXStoredSceneHandler::AddPrimitive(const G4Circle& circle) { |
---|
| 252 | #ifdef G4XXXStoredDEBUG |
---|
| 253 | G4cout << |
---|
| 254 | "G4XXXStoredSceneHandler::AddPrimitive(const G4Circle& circle) called.\n" |
---|
| 255 | << circle |
---|
| 256 | << G4endl; |
---|
| 257 | MarkerSizeType sizeType; |
---|
| 258 | G4double size = GetMarkerSize (circle, sizeType); |
---|
| 259 | switch (sizeType) { |
---|
| 260 | default: |
---|
| 261 | case screen: |
---|
| 262 | // Draw in screen coordinates. |
---|
| 263 | G4cout << "screen"; |
---|
| 264 | break; |
---|
| 265 | case world: |
---|
| 266 | // Draw in world coordinates. |
---|
| 267 | G4cout << "world"; |
---|
| 268 | break; |
---|
| 269 | } |
---|
| 270 | G4cout << " size: " << size << G4endl; |
---|
| 271 | #endif |
---|
| 272 | // Get vis attributes - pick up defaults if none. |
---|
| 273 | //const G4VisAttributes* pVA = |
---|
| 274 | // fpViewer -> GetApplicableVisAttributes (circle.GetVisAttributes ()); |
---|
| 275 | //?? Process circle. |
---|
| 276 | std::ostringstream oss; |
---|
| 277 | oss << circle; |
---|
| 278 | *fCurrentItem += oss.str(); |
---|
| 279 | } |
---|
| 280 | |
---|
| 281 | void G4XXXStoredSceneHandler::AddPrimitive(const G4Square& square) { |
---|
| 282 | #ifdef G4XXXStoredDEBUG |
---|
| 283 | G4cout << |
---|
| 284 | "G4XXXStoredSceneHandler::AddPrimitive(const G4Square& square) called.\n" |
---|
| 285 | << square |
---|
| 286 | << G4endl; |
---|
| 287 | MarkerSizeType sizeType; |
---|
| 288 | G4double size = GetMarkerSize (square, sizeType); |
---|
| 289 | switch (sizeType) { |
---|
| 290 | default: |
---|
| 291 | case screen: |
---|
| 292 | // Draw in screen coordinates. |
---|
| 293 | G4cout << "screen"; |
---|
| 294 | break; |
---|
| 295 | case world: |
---|
| 296 | // Draw in world coordinates. |
---|
| 297 | G4cout << "world"; |
---|
| 298 | break; |
---|
| 299 | } |
---|
| 300 | G4cout << " size: " << size << G4endl; |
---|
| 301 | #endif |
---|
| 302 | // Get vis attributes - pick up defaults if none. |
---|
| 303 | //const G4VisAttributes* pVA = |
---|
| 304 | // fpViewer -> GetApplicableVisAttributes (square.GetVisAttributes ()); |
---|
| 305 | //?? Process square. |
---|
| 306 | std::ostringstream oss; |
---|
| 307 | oss << square; |
---|
| 308 | *fCurrentItem += oss.str(); |
---|
| 309 | } |
---|
| 310 | |
---|
| 311 | void G4XXXStoredSceneHandler::AddPrimitive(const G4Polyhedron& polyhedron) { |
---|
| 312 | #ifdef G4XXXStoredDEBUG |
---|
| 313 | G4cout << |
---|
| 314 | "G4XXXStoredSceneHandler::AddPrimitive(const G4Polyhedron&) called.\n" |
---|
| 315 | << polyhedron |
---|
| 316 | << G4endl; |
---|
| 317 | #endif |
---|
| 318 | //?? Process polyhedron. |
---|
| 319 | std::ostringstream oss; |
---|
| 320 | oss << polyhedron; |
---|
| 321 | *fCurrentItem += oss.str(); |
---|
| 322 | |
---|
| 323 | //?? Or... here are some ideas for decomposing into polygons... |
---|
| 324 | //Assume all facets are convex quadrilaterals. |
---|
| 325 | //Draw each G4Facet individually |
---|
| 326 | |
---|
| 327 | //Get colour, etc.. |
---|
| 328 | if (polyhedron.GetNoFacets() == 0) return; |
---|
| 329 | |
---|
| 330 | // Get vis attributes - pick up defaults if none. |
---|
| 331 | const G4VisAttributes* pVA = |
---|
| 332 | fpViewer -> GetApplicableVisAttributes (polyhedron.GetVisAttributes ()); |
---|
| 333 | |
---|
| 334 | // Get view parameters that the user can force through the vis |
---|
| 335 | // attributes, thereby over-riding the current view parameter. |
---|
| 336 | G4ViewParameters::DrawingStyle drawing_style = GetDrawingStyle (pVA); |
---|
| 337 | //G4bool isAuxEdgeVisible = GetAuxEdgeVisible (pVA); |
---|
| 338 | |
---|
| 339 | //Get colour, etc.. |
---|
| 340 | //const G4Colour& c = pVA -> GetColour (); |
---|
| 341 | |
---|
| 342 | // Initial action depending on drawing style. |
---|
| 343 | switch (drawing_style) { |
---|
| 344 | case (G4ViewParameters::hsr): |
---|
| 345 | { |
---|
| 346 | break; |
---|
| 347 | } |
---|
| 348 | case (G4ViewParameters::hlr): |
---|
| 349 | { |
---|
| 350 | break; |
---|
| 351 | } |
---|
| 352 | case (G4ViewParameters::wireframe): |
---|
| 353 | { |
---|
| 354 | break; |
---|
| 355 | } |
---|
| 356 | default: |
---|
| 357 | { |
---|
| 358 | break; |
---|
| 359 | } |
---|
| 360 | } |
---|
| 361 | |
---|
| 362 | // Loop through all the facets... |
---|
| 363 | |
---|
| 364 | // Look at G4OpenGLSceneHandler::AddPrimitive(const G4Polyhedron&) |
---|
| 365 | // for an example of how to get facets out of a G4Polyhedron, |
---|
| 366 | // including how to cope with triangles if that's a problem. |
---|
| 367 | } |
---|
| 368 | |
---|
| 369 | void G4XXXStoredSceneHandler::AddPrimitive(const G4NURBS&) { |
---|
| 370 | #ifdef G4XXXStoredDEBUG |
---|
| 371 | G4cout << |
---|
| 372 | "G4XXXStoredSceneHandler::AddPrimitive(const G4NURBS& nurbs) called." |
---|
| 373 | << G4endl; |
---|
| 374 | #endif |
---|
| 375 | //?? Don't bother implementing this. NURBS are not functional. |
---|
| 376 | } |
---|
| 377 | |
---|
| 378 | void G4XXXStoredSceneHandler::ClearStore () { |
---|
| 379 | |
---|
| 380 | G4VSceneHandler::ClearStore (); // Sets need kernel visit, etc. |
---|
| 381 | |
---|
| 382 | fStore.clear(); |
---|
| 383 | fPermanents.clear(); |
---|
| 384 | fTransients.clear(); |
---|
| 385 | } |
---|
| 386 | |
---|
| 387 | void G4XXXStoredSceneHandler::ClearTransientStore () { |
---|
| 388 | |
---|
| 389 | G4VSceneHandler::ClearTransientStore (); |
---|
| 390 | |
---|
| 391 | typedef std::list<G4String> Store; |
---|
| 392 | typedef std::list<G4String>::iterator StoreIterator; |
---|
| 393 | typedef std::vector<StoreIterator>::iterator StoreIteratorIterator; |
---|
| 394 | for (StoreIteratorIterator i = fTransients.begin(); |
---|
| 395 | i != fTransients.end(); ++i) { |
---|
| 396 | fStore.erase(*i); |
---|
| 397 | } |
---|
| 398 | fTransients.clear(); |
---|
| 399 | |
---|
| 400 | // Make sure screen corresponds to graphical database... |
---|
| 401 | if (fpViewer) { |
---|
| 402 | fpViewer -> SetView (); |
---|
| 403 | fpViewer -> ClearView (); |
---|
| 404 | fpViewer -> DrawView (); |
---|
| 405 | } |
---|
| 406 | } |
---|