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[ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

  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 //
 28 // 
 29 // John Allison  23rd October 1996
 30 
 31 #include "G4VisAttributes.hh"
 32 
 33 #include "G4AttValue.hh"
 34 #include "G4AttDef.hh"
 35 
 36 G4VisAttributes::G4VisAttributes ():
 37 fVisible             (true),
 38 fDaughtersInvisible  (false),
 39 fLineStyle           (unbroken),
 40 fLineWidth           (1.),
 41 fForceDrawingStyle   (false),
 42 fForcedStyle         (wireframe),
 43 fForcedNumberOfCloudPoints (0),  // <= 0 means under control of viewer
 44 fForceAuxEdgeVisible (false),
 45 fForcedAuxEdgeVisible(false),
 46 fForcedLineSegmentsPerCircle (0),  // <=0 means not forced.
 47 fStartTime           (-fVeryLongTime),
 48 fEndTime             (fVeryLongTime),
 49 fAttValues           (nullptr),
 50 fAttDefs             (nullptr)
 51 {}
 52 
 53 G4VisAttributes::G4VisAttributes (G4bool visibility):
 54 fVisible             (visibility),
 55 fDaughtersInvisible  (false),
 56 
 57 fLineStyle           (unbroken),
 58 fLineWidth           (1.),
 59 fForceDrawingStyle   (false),
 60 fForcedStyle         (wireframe),
 61 fForcedNumberOfCloudPoints (0),  // <= 0 means under control of viewer
 62 fForceAuxEdgeVisible (false),
 63 fForcedAuxEdgeVisible(false),
 64 fForcedLineSegmentsPerCircle (0),  // <=0 means not forced.
 65 fStartTime           (-fVeryLongTime),
 66 fEndTime             (fVeryLongTime),
 67 fAttValues           (nullptr),
 68 fAttDefs             (nullptr)
 69 {}
 70 
 71 G4VisAttributes::G4VisAttributes (const G4Colour& colour):
 72 fVisible             (true),
 73 fDaughtersInvisible  (false),
 74 fColour              (colour),
 75 fLineStyle           (unbroken),
 76 fLineWidth           (1.),
 77 fForceDrawingStyle   (false),
 78 fForcedStyle         (wireframe),
 79 fForcedNumberOfCloudPoints (0),  // <= 0 means under control of viewer
 80 fForceAuxEdgeVisible (false),
 81 fForcedAuxEdgeVisible(false),
 82 fForcedLineSegmentsPerCircle (0),  // <=0 means not forced.
 83 fStartTime           (-fVeryLongTime),
 84 fEndTime             (fVeryLongTime),
 85 fAttValues           (nullptr),
 86 fAttDefs             (nullptr)
 87 {}
 88 
 89 G4VisAttributes::G4VisAttributes (G4bool visibility,
 90                                   const G4Colour& colour):
 91 fVisible             (visibility),
 92 fDaughtersInvisible  (false),
 93 fColour              (colour),
 94 fLineStyle           (unbroken),
 95 fLineWidth           (1.),
 96 fForceDrawingStyle   (false),
 97 fForcedStyle         (wireframe),
 98 fForcedNumberOfCloudPoints (0),  // <= 0 means under control of viewer
 99 fForceAuxEdgeVisible (false),
100 fForcedAuxEdgeVisible(false),
101 fForcedLineSegmentsPerCircle (0),  // <=0 means not forced.
102 fStartTime           (-fVeryLongTime),
103 fEndTime             (fVeryLongTime),
104 fAttValues           (nullptr),
105 fAttDefs             (nullptr)
106 {}
107 
108 
109 G4VisAttributes& G4VisAttributes::operator= (const G4VisAttributes& rhs)
110 {
111   if (&rhs == this) return *this;
112   fVisible              = rhs.fVisible;
113   fDaughtersInvisible   = rhs.fDaughtersInvisible;
114   fColour               = rhs.fColour;
115   fLineStyle            = rhs.fLineStyle;
116   fLineWidth            = rhs.fLineWidth;
117   fForceDrawingStyle    = rhs.fForceDrawingStyle;
118   fForcedStyle          = rhs.fForcedStyle;
119   fForcedNumberOfCloudPoints = rhs.fForcedNumberOfCloudPoints;
120   fForceAuxEdgeVisible  = rhs.fForceAuxEdgeVisible;
121   fForcedAuxEdgeVisible = rhs.fForcedAuxEdgeVisible;
122   fForcedLineSegmentsPerCircle = rhs.fForcedLineSegmentsPerCircle;
123   fStartTime           = rhs.fStartTime;
124   fEndTime             = rhs.fEndTime;
125   // AttValues are created afresh for each object (using the
126   // CreateAttValues message), but deletion is the responsibility of
127   // the creator.  So just copy pointer.
128   fAttValues           = rhs.fAttValues;
129   // AttDefs, if any, belong to the object from which they were obtained
130   // (with a GetAttDefs message), so just copy pointer.
131   fAttDefs             = rhs.fAttDefs;
132   return *this;
133 }
134 
135 const G4VisAttributes& G4VisAttributes::GetInvisible() {
136   static const G4VisAttributes invisible = G4VisAttributes(false);
137   return invisible;
138 }
139 
140 void G4VisAttributes::SetForceWireframe (G4bool force) {
141   if (force) {
142     fForceDrawingStyle = true;
143     fForcedStyle = G4VisAttributes::wireframe;
144   } else {
145     fForceDrawingStyle = false;
146   }
147 }
148 
149 void G4VisAttributes::SetForceSolid (G4bool force) {
150   if (force) {
151     fForceDrawingStyle = true;
152     fForcedStyle = G4VisAttributes::solid;
153   } else {
154     fForceDrawingStyle = false;
155   }
156 }
157 
158 void G4VisAttributes::SetForceCloud (G4bool force) {
159   if (force) {
160     fForceDrawingStyle = true;
161     fForcedStyle = G4VisAttributes::cloud;
162   } else {
163     fForceDrawingStyle = false;
164   }
165 }
166 
167 void G4VisAttributes::SetForceNumberOfCloudPoints (G4int nPoints) {
168   fForcedNumberOfCloudPoints = nPoints;
169   if (nPoints <= 0) {
170     G4cout <<
171     "G4VisAttributes::SetForceNumberOfCloudPoints: number of cloud points"
172     " set to " << fForcedNumberOfCloudPoints << '.' <<
173     "\n  This means the viewer default will be used, typically controlled by"
174     "\n  \"/vis/viewer/set/numberOfCloudPoints\""
175     << G4endl;
176   }
177 }
178 
179 void G4VisAttributes::SetForceAuxEdgeVisible (G4bool visibility) {
180   fForceAuxEdgeVisible = true;
181   fForcedAuxEdgeVisible = visibility;
182 }
183 
184 G4VisAttributes::ForcedDrawingStyle
185 G4VisAttributes::GetForcedDrawingStyle () const {
186   if (fForceDrawingStyle) return fForcedStyle;
187   return G4VisAttributes::wireframe;
188 }
189 
190 G4bool G4VisAttributes::IsForcedAuxEdgeVisible () const {
191   if (fForceAuxEdgeVisible) return fForcedAuxEdgeVisible;
192   return false;
193 }
194 
195 const std::vector<G4AttValue>* G4VisAttributes::CreateAttValues () const {
196   // Create an expendable copy on the heap...
197   return new std::vector<G4AttValue>(*fAttValues);
198 }
199 
200 void G4VisAttributes::SetForceLineSegmentsPerCircle (G4int nSegments) {
201   const G4int nSegmentsMin = fMinLineSegmentsPerCircle;
202   if (nSegments < nSegmentsMin) {
203     nSegments = nSegmentsMin;
204     G4cout <<
205       "G4VisAttributes::SetForcedLineSegmentsPerCircle: attempt to set the"
206       "\nnumber of line segments per circle < " << nSegmentsMin
207          << "; forced to " << nSegments << G4endl;
208   }
209   fForcedLineSegmentsPerCircle = nSegments;
210 }
211 
212 std::ostream& operator << (std::ostream& os, const G4VisAttributes& a)
213 {
214   os << std::defaultfloat;
215   os << "G4VisAttributes: ";
216   if (!a.fVisible) os << "in";
217   os << "visible, daughters ";
218   if (a.fDaughtersInvisible) os << "in";
219   os << "visible, colour: " << a.fColour;
220   os << "\n  linestyle: ";
221   switch (a.fLineStyle) {
222     case G4VisAttributes::unbroken:
223       os << "solid"; break;
224     case G4VisAttributes::dashed:
225       os << "dashed"; break;
226     case G4VisAttributes::dotted: os << "dotted"; break;
227     default: os << "unrecognised"; break;
228   }
229   os << ", line width: " << a.fLineWidth;
230   os << ", min line segments per circle: " << a.GetMinLineSegmentsPerCircle();
231   os << "\n  drawing style: ";
232   if (a.fForceDrawingStyle) {
233     os << "forced to ";
234     switch (a.fForcedStyle) {
235       case G4VisAttributes::wireframe:
236         os << "wireframe"; break;
237       case G4VisAttributes::solid:
238         os << "solid"; break;
239       default: os << "unrecognised"; break;
240     }
241   }
242   else {
243     os << "not forced";
244   }
245   os << ", auxiliary edge visibility: ";
246   if (a.fForceAuxEdgeVisible) {
247     os << "forced to ";
248     if (!a.fForcedAuxEdgeVisible) {
249       os << "not ";
250     }
251     os << "visible";
252   } else {
253     os << "not forced";
254   }
255   os << "\n  line segments per circle: ";
256   if (a.fForcedLineSegmentsPerCircle > 0) {
257     os << "forced to " << a.fForcedLineSegmentsPerCircle;
258   } else {
259     os << "not forced.";
260   }
261   os << "\n  time range: (" << a.fStartTime << ',' << a.fEndTime << ')';
262   os << "\n  G4AttValue pointer is ";
263   if (a.fAttValues != nullptr) {
264     os << "non-";
265   }
266   os << "zero";
267   os << ", G4AttDef pointer is ";
268   if (a.fAttDefs != nullptr) {
269     os << "non-";
270   }
271   os << "zero";
272   return os;
273 }
274 
275 G4bool G4VisAttributes::operator != (const G4VisAttributes& a) const {
276 
277   if (
278       (fVisible            != a.fVisible)            ||
279       (fDaughtersInvisible != a.fDaughtersInvisible) ||
280       (fColour             != a.fColour)             ||
281       (fLineStyle          != a.fLineStyle)          ||
282       (fLineWidth          != a.fLineWidth)          ||
283       (fForceDrawingStyle  != a.fForceDrawingStyle)  ||
284       (fForceAuxEdgeVisible!= a.fForceAuxEdgeVisible)   ||
285       (fForcedLineSegmentsPerCircle != a.fForcedLineSegmentsPerCircle) ||
286       (fStartTime          != a.fStartTime)          ||
287       (fEndTime            != a.fEndTime)            ||
288       (fAttValues          != a.fAttValues)          ||
289       (fAttDefs            != a.fAttDefs)
290       )
291     return true;
292 
293   if (fForceDrawingStyle) {
294     if (fForcedStyle != a.fForcedStyle) return true;
295   }
296 
297   if (fForceAuxEdgeVisible) {
298     if (fForcedAuxEdgeVisible != a.fForcedAuxEdgeVisible) return true;
299   }
300 
301   return false;
302 }
303 
304 G4bool G4VisAttributes::operator == (const G4VisAttributes& a) const {
305   return !(G4VisAttributes::operator != (a));
306 }
307