Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
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 // $Id: G03ColorWriter.cc 68025 2013-03-13 13:43:46Z gcosmo $
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 }
const XML_Char * name
Definition: expat.h:151
const G4Color & GetColor() const
std::vector< ExP01TrackerHit * > a
Definition: ExP01Classes.hh:33
static const G4double pos
G4String GenerateName(const G4String &, const void *const)
Definition: G4GDMLWrite.cc:124
#define G4endl
Definition: G4ios.hh:61
void AddExtension(xercesc::DOMElement *volumeElement, const G4LogicalVolume *const vol)
xercesc::DOMElement * NewElement(const G4String &)
Definition: G4GDMLWrite.cc:161
xercesc::DOMElement * extElement
Definition: G4GDMLWrite.hh:134
static constexpr double g
Definition: G4SIunits.hh:183
double G4double
Definition: G4Types.hh:76
bool G4bool
Definition: G4Types.hh:79
Definition of the G03ColorWriter class.
void ColorWrite(xercesc::DOMElement *volumeElement, const G4VisAttributes *const att)
const G4VisAttributes * GetVisAttributes() const
G4double GetRed() const
Definition: G4Colour.hh:151
std::vector< const G4VisAttributes * > fAttribs
void ExtensionWrite(xercesc::DOMElement *element)
G4double GetAlpha() const
Definition: G4Colour.hh:154
G4GLOB_DLL std::ostream G4cout
xercesc::DOMAttr * NewAttribute(const G4String &, const G4String &)
Definition: G4GDMLWrite.cc:137
G4double GetBlue() const
Definition: G4Colour.hh:153
G4double GetGreen() const
Definition: G4Colour.hh:152
G4bool BookAttribute(const G4VisAttributes *const att)