Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G03ColorWriter.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 //
28 //
29 // $Id$
30 //
31 // --------------------------------------------------------------------
32 
33 #include "G03ColorWriter.hh"
34 
35 #include "G4LogicalVolume.hh"
36 #include "G4VisAttributes.hh"
37 
38 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
39 
42 {
43 }
44 
45 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
46 
48 {
49 }
50 
51 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
52 
53 void G03ColorWriter::AddExtension(xercesc::DOMElement* volumeElement,
54  const G4LogicalVolume* const vol)
55 {
56  const G4VisAttributes* vis = vol->GetVisAttributes();
57  if (vis) { ColorWrite(volumeElement, vis); }
58 }
59 
60 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
61 
62 void G03ColorWriter::ExtensionWrite(xercesc::DOMElement* element)
63 {
64  G4cout << "G4GDML: Writing GDML extension..." << G4endl;
65 
66  // Mandatory calls the -first- time an extension is created
67  //
68  extElement = NewElement("extension");
69  element->appendChild(extElement);
70 }
71 
72 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
73 
74 void G03ColorWriter::ColorWrite(xercesc::DOMElement* volumeElement,
75  const G4VisAttributes* const att)
76 {
77  G4bool book = BookAttribute(att);
78  G4Color color = att->GetColor();
79 
80  const G4String& name = GenerateName("test_color", att);
81  G4double r=color.GetRed(), g=color.GetGreen(),
82  b=color.GetBlue(), a=color.GetAlpha();
83 
84  if (book)
85  {
86  xercesc::DOMElement* colElement = NewElement("color");
87  colElement->setAttributeNode(NewAttribute("name",name));
88  colElement->setAttributeNode(NewAttribute("R",r));
89  colElement->setAttributeNode(NewAttribute("G",g));
90  colElement->setAttributeNode(NewAttribute("B",b));
91  colElement->setAttributeNode(NewAttribute("A",a));
92  extElement->appendChild(colElement);
93  }
94 
95  xercesc::DOMElement* colorrefElement = NewElement("colorref");
96  colorrefElement->setAttributeNode(NewAttribute("ref",name));
97  volumeElement->appendChild(colorrefElement);
98 
99  G4cout << "Written color attribute (R,G,B,A) is: "
100  << r << ", " << g << ", " << b << ", " << a << " !" << G4endl;
101 }
102 
103 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
104 
106 {
107  G4bool booking = true;
108  std::vector<const G4VisAttributes*>::const_iterator pos =
109  std::find(fAttribs.begin(), fAttribs.end(), ref);
110 
111  if (pos != fAttribs.end()) { booking = false; }
112  else { fAttribs.push_back(ref); }
113 
114  return booking;
115 }