00001 // 00002 // ******************************************************************** 00003 // * License and Disclaimer * 00004 // * * 00005 // * The Geant4 software is copyright of the Copyright Holders of * 00006 // * the Geant4 Collaboration. It is provided under the terms and * 00007 // * conditions of the Geant4 Software License, included in the file * 00008 // * LICENSE and available at http://cern.ch/geant4/license . These * 00009 // * include a list of copyright holders. * 00010 // * * 00011 // * Neither the authors of this software system, nor their employing * 00012 // * institutes,nor the agencies providing financial support for this * 00013 // * work make any representation or warranty, express or implied, * 00014 // * regarding this software system or assume any liability for its * 00015 // * use. Please see the license in the file LICENSE and URL above * 00016 // * for the full disclaimer and the limitation of liability. * 00017 // * * 00018 // * This code implementation is the result of the scientific and * 00019 // * technical work of the GEANT4 collaboration. * 00020 // * By using, copying, modifying or distributing the software (or * 00021 // * any work based on the software) you agree to acknowledge its * 00022 // * use in resulting scientific publications, and indicate your * 00023 // * acceptance of all terms of the Geant4 Software license. * 00024 // ******************************************************************** 00025 // 00026 // 00027 // $Id$ 00028 // 00029 // 00030 // John Allison 30th October 1996 00031 // Base class for all things visible, i.e., which have Vis Attributes. 00032 00033 #include "G4Visible.hh" 00034 #include "G4VisAttributes.hh" 00035 #include "G4ios.hh" 00036 00037 G4Visible::G4Visible (): 00038 fpVisAttributes (0), 00039 fAllocatedVisAttributes (false) 00040 {} 00041 00042 G4Visible::G4Visible (const G4Visible& visible){ 00043 fAllocatedVisAttributes = visible.fAllocatedVisAttributes; 00044 if (fAllocatedVisAttributes) 00045 fpVisAttributes = new G4VisAttributes(*visible.fpVisAttributes); 00046 else fpVisAttributes = visible.fpVisAttributes; 00047 } 00048 00049 G4Visible::G4Visible (const G4VisAttributes* pVA): 00050 fpVisAttributes (pVA), 00051 fAllocatedVisAttributes (false) 00052 {} 00053 00054 G4Visible::~G4Visible () { 00055 if (fAllocatedVisAttributes) delete fpVisAttributes; 00056 } 00057 00058 G4Visible& G4Visible::operator= (const G4Visible& rhs) { 00059 if (&rhs == this) return *this; 00060 fAllocatedVisAttributes = rhs.fAllocatedVisAttributes; 00061 if (fAllocatedVisAttributes) { 00062 delete fpVisAttributes; 00063 fpVisAttributes = new G4VisAttributes(*rhs.fpVisAttributes); 00064 } 00065 else fpVisAttributes = rhs.fpVisAttributes; 00066 return *this; 00067 } 00068 00069 void G4Visible::SetVisAttributes (const G4VisAttributes& VA) { 00070 // Allocate G4VisAttributes on the heap in case the user specifies a 00071 // short-lived VA for a long-lived G4Visible. Flag so that it can 00072 // be deleted in the destructor. 00073 // First delete any G4VisAttributes already on the heap... 00074 if (fAllocatedVisAttributes) delete fpVisAttributes; 00075 fpVisAttributes = new G4VisAttributes(VA); 00076 fAllocatedVisAttributes = true; 00077 } 00078 00079 00080 void G4Visible::SetVisAttributes (const G4VisAttributes* pVA) { 00081 // First delete any G4VisAttributes already on the heap... 00082 if (fAllocatedVisAttributes) delete fpVisAttributes; 00083 fpVisAttributes = pVA; 00084 fAllocatedVisAttributes = false; 00085 } 00086 00087 G4bool G4Visible::operator != (const G4Visible& right) const { 00088 if (fpVisAttributes && right.fpVisAttributes) 00089 return *fpVisAttributes != *right.fpVisAttributes; 00090 else if (!fpVisAttributes && !right.fpVisAttributes) return false; 00091 else return true; 00092 } 00093 00094 std::ostream& operator << (std::ostream& os, const G4Visible& v) { 00095 if (v.fpVisAttributes) return os << *(v.fpVisAttributes); 00096 else return os << "No Visualization Attributes"; 00097 }