[830] | 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: G4Visible.cc,v 1.17 2006/11/07 11:53:16 allison Exp $ |
---|
[850] | 28 | // GEANT4 tag $Name: HEAD $ |
---|
[830] | 29 | // |
---|
| 30 | // |
---|
| 31 | // John Allison 30th October 1996 |
---|
| 32 | // Base class for all things visible, i.e., which have Vis Attributes. |
---|
| 33 | |
---|
| 34 | #include "G4Visible.hh" |
---|
| 35 | #include "G4VisAttributes.hh" |
---|
| 36 | #include "G4ios.hh" |
---|
| 37 | |
---|
| 38 | G4Visible::G4Visible (): |
---|
| 39 | fpVisAttributes (0), |
---|
| 40 | fAllocatedVisAttributes (false) |
---|
| 41 | {} |
---|
| 42 | |
---|
| 43 | G4Visible::G4Visible (const G4Visible& visible){ |
---|
| 44 | fAllocatedVisAttributes = visible.fAllocatedVisAttributes; |
---|
| 45 | if (fAllocatedVisAttributes) |
---|
| 46 | fpVisAttributes = new G4VisAttributes(visible.fpVisAttributes); |
---|
| 47 | else fpVisAttributes = visible.fpVisAttributes; |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | G4Visible::G4Visible (const G4VisAttributes* pVA): |
---|
| 51 | fpVisAttributes (pVA), |
---|
| 52 | fAllocatedVisAttributes (false) |
---|
| 53 | {} |
---|
| 54 | |
---|
| 55 | G4Visible::~G4Visible () { |
---|
| 56 | if (fAllocatedVisAttributes) delete fpVisAttributes; |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | G4Visible& G4Visible::operator= (const G4Visible& rhs) { |
---|
| 60 | fAllocatedVisAttributes = rhs.fAllocatedVisAttributes; |
---|
| 61 | if (fAllocatedVisAttributes) |
---|
| 62 | fpVisAttributes = new G4VisAttributes(rhs.fpVisAttributes); |
---|
| 63 | else fpVisAttributes = rhs.fpVisAttributes; |
---|
| 64 | return *this; |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | void G4Visible::SetVisAttributes (const G4VisAttributes& VA) { |
---|
| 68 | // Allocate G4VisAttributes on the heap in case the user specifies a |
---|
| 69 | // short-lived VA for a long-lived G4Visible. Flag so that it can |
---|
| 70 | // be deleted in the destructor. |
---|
| 71 | // First delete any G4VisAttributes already on the heap... |
---|
| 72 | if (fAllocatedVisAttributes) delete fpVisAttributes; |
---|
| 73 | fpVisAttributes = new G4VisAttributes(VA); |
---|
| 74 | fAllocatedVisAttributes = true; |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | |
---|
| 78 | void G4Visible::SetVisAttributes (const G4VisAttributes* pVA) { |
---|
| 79 | // First delete any G4VisAttributes already on the heap... |
---|
| 80 | if (fAllocatedVisAttributes) delete fpVisAttributes; |
---|
| 81 | fpVisAttributes = pVA; |
---|
| 82 | fAllocatedVisAttributes = false; |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | G4bool G4Visible::operator != (const G4Visible& right) const { |
---|
| 86 | return *fpVisAttributes != *right.fpVisAttributes; |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | std::ostream& operator << (std::ostream& os, const G4Visible& v) { |
---|
| 90 | if (v.fpVisAttributes) return os << *(v.fpVisAttributes); |
---|
| 91 | else return os << "No Visualization Attributes"; |
---|
| 92 | } |
---|