Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // 26 // >> 27 // $Id$ 27 // 28 // 28 // 29 // 29 // John Allison 23rd October 1996 30 // John Allison 23rd October 1996 30 31 31 #include "G4VisAttributes.hh" 32 #include "G4VisAttributes.hh" 32 33 33 #include "G4AttValue.hh" 34 #include "G4AttValue.hh" 34 #include "G4AttDef.hh" 35 #include "G4AttDef.hh" 35 36 36 G4VisAttributes::G4VisAttributes (): 37 G4VisAttributes::G4VisAttributes (): 37 fVisible (true), 38 fVisible (true), 38 fDaughtersInvisible (false), 39 fDaughtersInvisible (false), >> 40 fColour (G4Colour ()), 39 fLineStyle (unbroken), 41 fLineStyle (unbroken), 40 fLineWidth (1.), 42 fLineWidth (1.), 41 fForceDrawingStyle (false), 43 fForceDrawingStyle (false), 42 fForcedStyle (wireframe), 44 fForcedStyle (wireframe), 43 fForcedNumberOfCloudPoints (0), // <= 0 means << 44 fForceAuxEdgeVisible (false), 45 fForceAuxEdgeVisible (false), 45 fForcedAuxEdgeVisible(false), 46 fForcedAuxEdgeVisible(false), 46 fForcedLineSegmentsPerCircle (0), // <=0 mean 47 fForcedLineSegmentsPerCircle (0), // <=0 means not forced. 47 fStartTime (-fVeryLongTime), << 48 fStartTime (-DBL_MAX), 48 fEndTime (fVeryLongTime), << 49 fEndTime (DBL_MAX), 49 fAttValues (nullptr), << 50 fAttValues (0), 50 fAttDefs (nullptr) << 51 fAttDefs (0) 51 {} 52 {} 52 53 53 G4VisAttributes::G4VisAttributes (G4bool visib 54 G4VisAttributes::G4VisAttributes (G4bool visibility): 54 fVisible (visibility), 55 fVisible (visibility), 55 fDaughtersInvisible (false), 56 fDaughtersInvisible (false), 56 << 57 fColour (G4Colour ()), 57 fLineStyle (unbroken), 58 fLineStyle (unbroken), 58 fLineWidth (1.), 59 fLineWidth (1.), 59 fForceDrawingStyle (false), 60 fForceDrawingStyle (false), 60 fForcedStyle (wireframe), 61 fForcedStyle (wireframe), 61 fForcedNumberOfCloudPoints (0), // <= 0 means << 62 fForceAuxEdgeVisible (false), 62 fForceAuxEdgeVisible (false), 63 fForcedAuxEdgeVisible(false), 63 fForcedAuxEdgeVisible(false), 64 fForcedLineSegmentsPerCircle (0), // <=0 mean 64 fForcedLineSegmentsPerCircle (0), // <=0 means not forced. 65 fStartTime (-fVeryLongTime), << 65 fStartTime (-DBL_MAX), 66 fEndTime (fVeryLongTime), << 66 fEndTime (DBL_MAX), 67 fAttValues (nullptr), << 67 fAttValues (0), 68 fAttDefs (nullptr) << 68 fAttDefs (0) 69 {} 69 {} 70 70 71 G4VisAttributes::G4VisAttributes (const G4Colo 71 G4VisAttributes::G4VisAttributes (const G4Colour& colour): 72 fVisible (true), 72 fVisible (true), 73 fDaughtersInvisible (false), 73 fDaughtersInvisible (false), 74 fColour (colour), 74 fColour (colour), 75 fLineStyle (unbroken), 75 fLineStyle (unbroken), 76 fLineWidth (1.), 76 fLineWidth (1.), 77 fForceDrawingStyle (false), 77 fForceDrawingStyle (false), 78 fForcedStyle (wireframe), 78 fForcedStyle (wireframe), 79 fForcedNumberOfCloudPoints (0), // <= 0 means << 80 fForceAuxEdgeVisible (false), 79 fForceAuxEdgeVisible (false), 81 fForcedAuxEdgeVisible(false), 80 fForcedAuxEdgeVisible(false), 82 fForcedLineSegmentsPerCircle (0), // <=0 mean 81 fForcedLineSegmentsPerCircle (0), // <=0 means not forced. 83 fStartTime (-fVeryLongTime), << 82 fStartTime (-DBL_MAX), 84 fEndTime (fVeryLongTime), << 83 fEndTime (DBL_MAX), 85 fAttValues (nullptr), << 84 fAttValues (0), 86 fAttDefs (nullptr) << 85 fAttDefs (0) 87 {} 86 {} 88 87 89 G4VisAttributes::G4VisAttributes (G4bool visib 88 G4VisAttributes::G4VisAttributes (G4bool visibility, 90 const G4Colo 89 const G4Colour& colour): 91 fVisible (visibility), 90 fVisible (visibility), 92 fDaughtersInvisible (false), 91 fDaughtersInvisible (false), 93 fColour (colour), 92 fColour (colour), 94 fLineStyle (unbroken), 93 fLineStyle (unbroken), 95 fLineWidth (1.), 94 fLineWidth (1.), 96 fForceDrawingStyle (false), 95 fForceDrawingStyle (false), 97 fForcedStyle (wireframe), 96 fForcedStyle (wireframe), 98 fForcedNumberOfCloudPoints (0), // <= 0 means << 99 fForceAuxEdgeVisible (false), 97 fForceAuxEdgeVisible (false), 100 fForcedAuxEdgeVisible(false), 98 fForcedAuxEdgeVisible(false), 101 fForcedLineSegmentsPerCircle (0), // <=0 mean 99 fForcedLineSegmentsPerCircle (0), // <=0 means not forced. 102 fStartTime (-fVeryLongTime), << 100 fStartTime (-DBL_MAX), 103 fEndTime (fVeryLongTime), << 101 fEndTime (DBL_MAX), 104 fAttValues (nullptr), << 102 fAttValues (0), 105 fAttDefs (nullptr) << 103 fAttDefs (0) >> 104 {} >> 105 >> 106 G4VisAttributes::G4VisAttributes (const G4VisAttributes& va): >> 107 fVisible (va.fVisible), >> 108 fDaughtersInvisible (va.fDaughtersInvisible), >> 109 fColour (va.fColour), >> 110 fLineStyle (va.fLineStyle), >> 111 fLineWidth (va.fLineWidth), >> 112 fForceDrawingStyle (va.fForceDrawingStyle), >> 113 fForcedStyle (va.fForcedStyle), >> 114 fForceAuxEdgeVisible (va.fForceAuxEdgeVisible), >> 115 fForcedAuxEdgeVisible(va.fForcedAuxEdgeVisible), >> 116 fForcedLineSegmentsPerCircle (va.fForcedLineSegmentsPerCircle), >> 117 fStartTime (va.fStartTime), >> 118 fEndTime (va.fEndTime), >> 119 // AttValues are created afresh for each object (using the >> 120 // CreateAttValues message), but deletion is the responsibility of >> 121 // the creator. So just copy pointer. >> 122 fAttValues (va.fAttValues), >> 123 // AttDefs, if any, belong to the object from which they were obtained >> 124 // (with a GetAttDefs message), so just copy pointer. >> 125 fAttDefs (va.fAttDefs) 106 {} 126 {} 107 127 >> 128 G4VisAttributes::~G4VisAttributes() >> 129 {} 108 130 109 G4VisAttributes& G4VisAttributes::operator= (c 131 G4VisAttributes& G4VisAttributes::operator= (const G4VisAttributes& rhs) 110 { 132 { 111 if (&rhs == this) return *this; 133 if (&rhs == this) return *this; 112 fVisible = rhs.fVisible; 134 fVisible = rhs.fVisible; 113 fDaughtersInvisible = rhs.fDaughtersInvisi 135 fDaughtersInvisible = rhs.fDaughtersInvisible; 114 fColour = rhs.fColour; 136 fColour = rhs.fColour; 115 fLineStyle = rhs.fLineStyle; 137 fLineStyle = rhs.fLineStyle; 116 fLineWidth = rhs.fLineWidth; 138 fLineWidth = rhs.fLineWidth; 117 fForceDrawingStyle = rhs.fForceDrawingSty 139 fForceDrawingStyle = rhs.fForceDrawingStyle; 118 fForcedStyle = rhs.fForcedStyle; 140 fForcedStyle = rhs.fForcedStyle; 119 fForcedNumberOfCloudPoints = rhs.fForcedNumb << 120 fForceAuxEdgeVisible = rhs.fForceAuxEdgeVis 141 fForceAuxEdgeVisible = rhs.fForceAuxEdgeVisible; 121 fForcedAuxEdgeVisible = rhs.fForcedAuxEdgeVi 142 fForcedAuxEdgeVisible = rhs.fForcedAuxEdgeVisible; 122 fForcedLineSegmentsPerCircle = rhs.fForcedLi 143 fForcedLineSegmentsPerCircle = rhs.fForcedLineSegmentsPerCircle; 123 fStartTime = rhs.fStartTime; 144 fStartTime = rhs.fStartTime; 124 fEndTime = rhs.fEndTime; 145 fEndTime = rhs.fEndTime; 125 // AttValues are created afresh for each obj 146 // AttValues are created afresh for each object (using the 126 // CreateAttValues message), but deletion is 147 // CreateAttValues message), but deletion is the responsibility of 127 // the creator. So just copy pointer. 148 // the creator. So just copy pointer. 128 fAttValues = rhs.fAttValues; 149 fAttValues = rhs.fAttValues; 129 // AttDefs, if any, belong to the object fro 150 // AttDefs, if any, belong to the object from which they were obtained 130 // (with a GetAttDefs message), so just copy 151 // (with a GetAttDefs message), so just copy pointer. 131 fAttDefs = rhs.fAttDefs; 152 fAttDefs = rhs.fAttDefs; 132 return *this; 153 return *this; 133 } 154 } 134 155 >> 156 // Deprecated 14 July 2016 JA >> 157 const G4VisAttributes G4VisAttributes::Invisible = G4VisAttributes (false); >> 158 135 const G4VisAttributes& G4VisAttributes::GetInv 159 const G4VisAttributes& G4VisAttributes::GetInvisible() { 136 static const G4VisAttributes invisible = G4V 160 static const G4VisAttributes invisible = G4VisAttributes(false); 137 return invisible; 161 return invisible; 138 } 162 } 139 163 140 void G4VisAttributes::SetForceWireframe (G4boo 164 void G4VisAttributes::SetForceWireframe (G4bool force) { 141 if (force) { 165 if (force) { 142 fForceDrawingStyle = true; 166 fForceDrawingStyle = true; 143 fForcedStyle = G4VisAttributes::wireframe; 167 fForcedStyle = G4VisAttributes::wireframe; 144 } else { 168 } else { 145 fForceDrawingStyle = false; 169 fForceDrawingStyle = false; 146 } 170 } 147 } 171 } 148 172 149 void G4VisAttributes::SetForceSolid (G4bool fo 173 void G4VisAttributes::SetForceSolid (G4bool force) { 150 if (force) { 174 if (force) { 151 fForceDrawingStyle = true; 175 fForceDrawingStyle = true; 152 fForcedStyle = G4VisAttributes::solid; 176 fForcedStyle = G4VisAttributes::solid; 153 } else { 177 } else { 154 fForceDrawingStyle = false; 178 fForceDrawingStyle = false; 155 } 179 } 156 } 180 } 157 181 158 void G4VisAttributes::SetForceCloud (G4bool fo << 159 if (force) { << 160 fForceDrawingStyle = true; << 161 fForcedStyle = G4VisAttributes::cloud; << 162 } else { << 163 fForceDrawingStyle = false; << 164 } << 165 } << 166 << 167 void G4VisAttributes::SetForceNumberOfCloudPoi << 168 fForcedNumberOfCloudPoints = nPoints; << 169 if (nPoints <= 0) { << 170 G4cout << << 171 "G4VisAttributes::SetForceNumberOfCloudPoi << 172 " set to " << fForcedNumberOfCloudPoints < << 173 "\n This means the viewer default will be << 174 "\n \"/vis/viewer/set/numberOfCloudPoints << 175 << G4endl; << 176 } << 177 } << 178 << 179 void G4VisAttributes::SetForceAuxEdgeVisible ( 182 void G4VisAttributes::SetForceAuxEdgeVisible (G4bool visibility) { 180 fForceAuxEdgeVisible = true; 183 fForceAuxEdgeVisible = true; 181 fForcedAuxEdgeVisible = visibility; 184 fForcedAuxEdgeVisible = visibility; 182 } 185 } 183 186 184 G4VisAttributes::ForcedDrawingStyle 187 G4VisAttributes::ForcedDrawingStyle 185 G4VisAttributes::GetForcedDrawingStyle () cons 188 G4VisAttributes::GetForcedDrawingStyle () const { 186 if (fForceDrawingStyle) return fForcedStyle; 189 if (fForceDrawingStyle) return fForcedStyle; 187 return G4VisAttributes::wireframe; << 190 else return G4VisAttributes::wireframe; 188 } 191 } 189 192 190 G4bool G4VisAttributes::IsForcedAuxEdgeVisible 193 G4bool G4VisAttributes::IsForcedAuxEdgeVisible () const { 191 if (fForceAuxEdgeVisible) return fForcedAuxE 194 if (fForceAuxEdgeVisible) return fForcedAuxEdgeVisible; 192 return false; << 195 else return false; 193 } 196 } 194 197 195 const std::vector<G4AttValue>* G4VisAttributes 198 const std::vector<G4AttValue>* G4VisAttributes::CreateAttValues () const { 196 // Create an expendable copy on the heap... 199 // Create an expendable copy on the heap... 197 return new std::vector<G4AttValue>(*fAttValu 200 return new std::vector<G4AttValue>(*fAttValues); 198 } 201 } 199 202 200 void G4VisAttributes::SetForceLineSegmentsPerC 203 void G4VisAttributes::SetForceLineSegmentsPerCircle (G4int nSegments) { 201 const G4int nSegmentsMin = fMinLineSegmentsP 204 const G4int nSegmentsMin = fMinLineSegmentsPerCircle; 202 if (nSegments < nSegmentsMin) { << 205 if (nSegments > 0 && nSegments < nSegmentsMin) { 203 nSegments = nSegmentsMin; 206 nSegments = nSegmentsMin; 204 G4cout << 207 G4cout << 205 "G4VisAttributes::SetForcedLineSegmentsP 208 "G4VisAttributes::SetForcedLineSegmentsPerCircle: attempt to set the" 206 "\nnumber of line segments per circle < << 209 "\nnumber of line segements per circle < " << nSegmentsMin 207 << "; forced to " << nSegments << G4e 210 << "; forced to " << nSegments << G4endl; 208 } 211 } 209 fForcedLineSegmentsPerCircle = nSegments; 212 fForcedLineSegmentsPerCircle = nSegments; 210 } 213 } 211 214 212 std::ostream& operator << (std::ostream& os, c 215 std::ostream& operator << (std::ostream& os, const G4VisAttributes& a) 213 { 216 { 214 os << std::defaultfloat; << 215 os << "G4VisAttributes: "; 217 os << "G4VisAttributes: "; 216 if (!a.fVisible) os << "in"; 218 if (!a.fVisible) os << "in"; 217 os << "visible, daughters "; 219 os << "visible, daughters "; 218 if (a.fDaughtersInvisible) os << "in"; 220 if (a.fDaughtersInvisible) os << "in"; 219 os << "visible, colour: " << a.fColour; 221 os << "visible, colour: " << a.fColour; 220 os << "\n linestyle: "; 222 os << "\n linestyle: "; 221 switch (a.fLineStyle) { 223 switch (a.fLineStyle) { 222 case G4VisAttributes::unbroken: 224 case G4VisAttributes::unbroken: 223 os << "solid"; break; 225 os << "solid"; break; 224 case G4VisAttributes::dashed: 226 case G4VisAttributes::dashed: 225 os << "dashed"; break; 227 os << "dashed"; break; 226 case G4VisAttributes::dotted: os << "dotte 228 case G4VisAttributes::dotted: os << "dotted"; break; 227 default: os << "unrecognised"; break; 229 default: os << "unrecognised"; break; 228 } 230 } 229 os << ", line width: " << a.fLineWidth; 231 os << ", line width: " << a.fLineWidth; 230 os << ", min line segments per circle: " << 232 os << ", min line segments per circle: " << a.GetMinLineSegmentsPerCircle(); 231 os << "\n drawing style: "; 233 os << "\n drawing style: "; 232 if (a.fForceDrawingStyle) { 234 if (a.fForceDrawingStyle) { 233 os << "forced to "; 235 os << "forced to "; 234 switch (a.fForcedStyle) { 236 switch (a.fForcedStyle) { 235 case G4VisAttributes::wireframe: 237 case G4VisAttributes::wireframe: 236 os << "wireframe"; break; 238 os << "wireframe"; break; 237 case G4VisAttributes::solid: 239 case G4VisAttributes::solid: 238 os << "solid"; break; 240 os << "solid"; break; 239 default: os << "unrecognised"; break; 241 default: os << "unrecognised"; break; 240 } 242 } 241 } 243 } 242 else { 244 else { 243 os << "not forced"; 245 os << "not forced"; 244 } 246 } 245 os << ", auxiliary edge visibility: "; 247 os << ", auxiliary edge visibility: "; 246 if (a.fForceAuxEdgeVisible) { 248 if (a.fForceAuxEdgeVisible) { 247 os << "forced to "; 249 os << "forced to "; 248 if (!a.fForcedAuxEdgeVisible) { 250 if (!a.fForcedAuxEdgeVisible) { 249 os << "not "; 251 os << "not "; 250 } 252 } 251 os << "visible"; 253 os << "visible"; 252 } else { 254 } else { 253 os << "not forced"; 255 os << "not forced"; 254 } 256 } 255 os << "\n line segments per circle: "; 257 os << "\n line segments per circle: "; 256 if (a.fForcedLineSegmentsPerCircle > 0) { 258 if (a.fForcedLineSegmentsPerCircle > 0) { 257 os << "forced to " << a.fForcedLineSegment 259 os << "forced to " << a.fForcedLineSegmentsPerCircle; 258 } else { 260 } else { 259 os << "not forced."; 261 os << "not forced."; 260 } 262 } 261 os << "\n time range: (" << a.fStartTime << 263 os << "\n time range: (" << a.fStartTime << ',' << a.fEndTime << ')'; 262 os << "\n G4AttValue pointer is "; 264 os << "\n G4AttValue pointer is "; 263 if (a.fAttValues != nullptr) { << 265 if (a.fAttValues) { 264 os << "non-"; 266 os << "non-"; 265 } 267 } 266 os << "zero"; 268 os << "zero"; 267 os << ", G4AttDef pointer is "; 269 os << ", G4AttDef pointer is "; 268 if (a.fAttDefs != nullptr) { << 270 if (a.fAttDefs) { 269 os << "non-"; 271 os << "non-"; 270 } 272 } 271 os << "zero"; 273 os << "zero"; 272 return os; 274 return os; 273 } 275 } 274 276 275 G4bool G4VisAttributes::operator != (const G4V 277 G4bool G4VisAttributes::operator != (const G4VisAttributes& a) const { 276 278 277 if ( 279 if ( 278 (fVisible != a.fVisible) 280 (fVisible != a.fVisible) || 279 (fDaughtersInvisible != a.fDaughtersInvi 281 (fDaughtersInvisible != a.fDaughtersInvisible) || 280 (fColour != a.fColour) 282 (fColour != a.fColour) || 281 (fLineStyle != a.fLineStyle) 283 (fLineStyle != a.fLineStyle) || 282 (fLineWidth != a.fLineWidth) 284 (fLineWidth != a.fLineWidth) || 283 (fForceDrawingStyle != a.fForceDrawingS 285 (fForceDrawingStyle != a.fForceDrawingStyle) || 284 (fForceAuxEdgeVisible!= a.fForceAuxEdgeV 286 (fForceAuxEdgeVisible!= a.fForceAuxEdgeVisible) || 285 (fForcedLineSegmentsPerCircle != a.fForc 287 (fForcedLineSegmentsPerCircle != a.fForcedLineSegmentsPerCircle) || 286 (fStartTime != a.fStartTime) 288 (fStartTime != a.fStartTime) || 287 (fEndTime != a.fEndTime) 289 (fEndTime != a.fEndTime) || 288 (fAttValues != a.fAttValues) 290 (fAttValues != a.fAttValues) || 289 (fAttDefs != a.fAttDefs) 291 (fAttDefs != a.fAttDefs) 290 ) 292 ) 291 return true; 293 return true; 292 294 293 if (fForceDrawingStyle) { 295 if (fForceDrawingStyle) { 294 if (fForcedStyle != a.fForcedStyle) return 296 if (fForcedStyle != a.fForcedStyle) return true; 295 } 297 } 296 298 297 if (fForceAuxEdgeVisible) { 299 if (fForceAuxEdgeVisible) { 298 if (fForcedAuxEdgeVisible != a.fForcedAuxE 300 if (fForcedAuxEdgeVisible != a.fForcedAuxEdgeVisible) return true; 299 } 301 } 300 302 301 return false; 303 return false; 302 } 304 } 303 305 304 G4bool G4VisAttributes::operator == (const G4V 306 G4bool G4VisAttributes::operator == (const G4VisAttributes& a) const { 305 return !(G4VisAttributes::operator != (a)); 307 return !(G4VisAttributes::operator != (a)); 306 } 308 } 307 309