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