ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G03ColorReader.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G03ColorReader.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 "G03ColorReader.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  std::map<G4String, G4VisAttributes*>::iterator pos;
49  for (pos=fAttribs.begin(); pos!=fAttribs.end(); pos++)
50  { delete pos->second; }
51 }
52 
53 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
54 
55 void G03ColorReader::ExtensionRead(const xercesc::DOMElement* const extElement)
56 {
57  G4cout << "G4GDML: Reading GDML extension..." << G4endl;
58 
59  for (xercesc::DOMNode* iter = extElement->getFirstChild();
60  iter != 0; iter = iter->getNextSibling())
61  {
62  if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) { continue; }
63 
64  const xercesc::DOMElement* const child
65  = dynamic_cast<xercesc::DOMElement*>(iter);
66  const G4String tag = Transcode(child->getTagName());
67 
68  if (tag=="color") { ColorRead(child); }
69  else
70  {
71  G4String error_msg = "Unknown tag in structure: " + tag;
72  G4Exception("G03ColorReader::ExtensionRead()",
73  "ReadError", FatalException, error_msg);
74  }
75  }
76 }
77 
78 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
79 
80 void G03ColorReader::VolumeRead(const xercesc::DOMElement* const volumeElement)
81 {
82  G4VSolid* solidPtr = 0;
83  G4Material* materialPtr = 0;
84  G4VisAttributes* attrPtr = 0;
85  G4GDMLAuxListType auxList;
86 
87  XMLCh *name_attr = xercesc::XMLString::transcode("name");
88  const G4String name = Transcode(volumeElement->getAttribute(name_attr));
89  xercesc::XMLString::release(&name_attr);
90 
91  for (xercesc::DOMNode* iter = volumeElement->getFirstChild();
92  iter != 0; iter = iter->getNextSibling())
93  {
94  if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) { continue; }
95 
96  const xercesc::DOMElement* const child
97  = dynamic_cast<xercesc::DOMElement*>(iter);
98  const G4String tag = Transcode(child->getTagName());
99 
100  if (tag=="auxiliary")
101  { auxList.push_back(AuxiliaryRead(child)); } else
102  if (tag=="materialref")
103  { materialPtr = GetMaterial(GenerateName(RefRead(child),true)); } else
104  if (tag=="solidref")
105  { solidPtr = GetSolid(GenerateName(RefRead(child))); } else
106  if (tag == "colorref")
107  { attrPtr = GetVisAttribute(GenerateName(RefRead(child))); }
108  }
109 
110  pMotherLogical = new G4LogicalVolume(solidPtr,materialPtr,
111  GenerateName(name),0,0,0);
113 
114  if (!auxList.empty()) { auxMap[pMotherLogical] = auxList; }
115 
116  Volume_contentRead(volumeElement);
117 }
118 
119 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
120 
121 void G03ColorReader::ColorRead(const xercesc::DOMElement* const colorElement)
122 {
123  G4String name;
124  G4VisAttributes* color = 0;
125  G4double r=0., g=0., b=0., a=0.;
126 
127  const xercesc::DOMNamedNodeMap* const attributes
128  = colorElement->getAttributes();
129  XMLSize_t attributeCount = attributes->getLength();
130 
131  for (XMLSize_t attribute_index=0;
132  attribute_index<attributeCount; attribute_index++)
133  {
134  xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
135 
136  if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
137  { continue; }
138 
139  const xercesc::DOMAttr* const attribute
140  = dynamic_cast<xercesc::DOMAttr*>(attribute_node);
141  const G4String attName = Transcode(attribute->getName());
142  const G4String attValue = Transcode(attribute->getValue());
143 
144  if (attName=="name")
145  { name = GenerateName(attValue); } else
146  if (attName=="R")
147  { r = eval.Evaluate(attValue); } else
148  if (attName=="G")
149  { g = eval.Evaluate(attValue); } else
150  if (attName=="B")
151  { b = eval.Evaluate(attValue); } else
152  if (attName=="A")
153  { a = eval.Evaluate(attValue); }
154  }
155 
156  G4cout << "Color attribute (R,G,B,A) is: "
157  << r << ", " << g << ", " << b << ", " << a << " !" << G4endl;
158  color = new G4VisAttributes(G4Color(r,g,b,a));
159  fAttribs.insert(std::make_pair(name,color));
160 }
161 
162 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
163 
165 {
166  G4VisAttributes* col = 0;
167  std::map<G4String, G4VisAttributes*>::iterator pos = fAttribs.find(ref);
168 
169  if (pos != fAttribs.end())
170  {
171  col = pos->second;
172  }
173  else
174  {
175  G4String err_mess = "Attribute: " + ref + " NOT found !";
176  G4Exception("G03ColorReader::GetVisAttribute()",
177  "ReadError", FatalException, err_mess);
178  }
179  return col;
180 }