source: trunk/source/visualization/management/src/G4ViewParameters.cc @ 909

Last change on this file since 909 was 909, checked in by garnier, 15 years ago

en test

  • Property svn:mime-type set to text/cpp
File size: 24.1 KB
Line 
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: G4ViewParameters.cc,v 1.32 2009/01/13 09:55:15 lgarnier Exp $
28// GEANT4 tag $Name:  $
29//
30//
31// John Allison  19th July 1996
32// View parameters and options.
33
34#include "G4ViewParameters.hh"
35
36#include "G4VisManager.hh"
37#include "G4UnitsTable.hh"
38#include "G4ios.hh"
39
40G4ViewParameters::G4ViewParameters ():
41  fNoValue(0x0000),
42  fXValue(0x0001),
43  fYValue(0x0002),
44  fWidthValue(0x0004),
45  fHeightValue(0x0008),
46  fAllValues(0x000F),
47  fXNegative(0x0010),
48  fYNegative(0x0020),
49  fDrawingStyle (wireframe),
50  fAuxEdgeVisible (false),
51  fRepStyle (polyhedron),
52  fCulling (true),
53  fCullInvisible (true),
54  fDensityCulling (false),
55  fVisibleDensity (0.01 * g / cm3),
56  fCullCovered (false),
57  fSection (false),
58  fSectionPlane (),
59  fCutawayMode (cutawayUnion),
60  fCutawayPlanes (),
61  fExplodeFactor (1.),
62  fNoOfSides (24),
63  fViewpointDirection (G4Vector3D (0., 0., 1.)),  // On z-axis.
64  fUpVector (G4Vector3D (0., 1., 0.)),            // y-axis up.
65  fFieldHalfAngle (0.),                           // Orthogonal projection.
66  fZoomFactor (1.),
67  fScaleFactor (G4Vector3D (1., 1., 1.)),
68  fCurrentTargetPoint (),
69  fDolly (0.),
70  fLightsMoveWithCamera (false),
71  fRelativeLightpointDirection (G4Vector3D (1., 1., 1.)),
72  fActualLightpointDirection (G4Vector3D (1., 1., 1.)),
73  fDefaultVisAttributes (),
74  fDefaultTextVisAttributes (G4Colour (0., 0., 1.)),
75  fDefaultMarker (),
76  fGlobalMarkerScale (1.),
77  fGlobalLineWidthScale (1.),
78  fMarkerNotHidden (true),
79  fWindowSizeHintX (600),
80  fWindowSizeHintY (600),
81  fWindowLocationHintX(0),
82  fWindowLocationHintY(0),
83  fWindowLocationHintXNegative(true),
84  fWindowLocationHintYNegative(false),
85  fAutoRefresh (false),
86  fBackgroundColour (G4Colour(0.,0.,0.)),         // Black
87  fPicking (false)
88{
89  fDefaultMarker.SetScreenSize (5.);
90  // Markers are 5 pixels "overall" size, i.e., diameter.
91}
92
93G4ViewParameters::~G4ViewParameters () {}
94
95void G4ViewParameters::MultiplyScaleFactor
96(const G4Vector3D& scaleFactorMultiplier) {
97  fScaleFactor.setX(fScaleFactor.x() * scaleFactorMultiplier.x());
98  fScaleFactor.setY(fScaleFactor.y() * scaleFactorMultiplier.y());
99  fScaleFactor.setZ(fScaleFactor.z() * scaleFactorMultiplier.z());
100}
101
102G4Vector3D& G4ViewParameters::GetActualLightpointDirection () {
103  SetViewAndLights (fViewpointDirection);
104  return fActualLightpointDirection;
105}
106
107// Useful quantities - begin snippet.
108// Here Follow functions to evaluate the above algorithms as a
109// function of the radius of the Bounding Sphere of the object being
110// viewed.  Call them in the order given - for efficiency, later
111// functions depend on the results of earlier ones (Store the
112// results of earlier functions in your own temporary variables -
113// see, for example, G4OpenGLView::SetView ().)
114
115G4double G4ViewParameters::GetCameraDistance (G4double radius) const {
116  G4double cameraDistance;
117  if (fFieldHalfAngle == 0.) {
118    cameraDistance = radius;
119  }
120  else {
121    cameraDistance = radius / std::sin (fFieldHalfAngle) - fDolly;
122  }
123  return cameraDistance;
124}
125
126G4double G4ViewParameters::GetNearDistance (G4double cameraDistance,
127                                            G4double radius) const {
128  const G4double small = 1.e-6 * radius;
129  G4double nearDistance = cameraDistance - radius;
130  if (nearDistance < small) nearDistance = small;
131  return nearDistance;
132}
133
134G4double G4ViewParameters::GetFarDistance (G4double cameraDistance,
135                                           G4double nearDistance,
136                                           G4double radius) const {
137  G4double farDistance = cameraDistance + radius;
138  if (farDistance < nearDistance) farDistance = nearDistance;
139  return farDistance;
140}
141
142G4double G4ViewParameters::GetFrontHalfHeight (G4double nearDistance,
143                                               G4double radius) const {
144  G4double frontHalfHeight;
145  if (fFieldHalfAngle == 0.) {
146    frontHalfHeight = radius / fZoomFactor;
147  }
148  else {
149    frontHalfHeight = nearDistance * std::tan (fFieldHalfAngle) / fZoomFactor;
150  }
151  return frontHalfHeight;
152}
153// Useful quantities - end snippet.
154
155void G4ViewParameters::AddCutawayPlane (const G4Plane3D& cutawayPlane) {
156  if (fCutawayPlanes.size () < 3 ) {
157    fCutawayPlanes.push_back (cutawayPlane);
158  }
159  else {
160    G4cout <<
161      "ERROR: G4ViewParameters::AddCutawayPlane:"
162      "\n  A maximum of 3 cutaway planes supported." << G4endl;
163  }
164}
165
166void G4ViewParameters::ChangeCutawayPlane
167(size_t index, const G4Plane3D& cutawayPlane) {
168  if (index >= fCutawayPlanes.size()) {
169    G4cout <<
170      "ERROR: G4ViewParameters::ChangeCutawayPlane:"
171      "\n  Plane " << index << " does not exist." << G4endl;
172  } else {
173    fCutawayPlanes[index] = cutawayPlane;
174  }
175}
176
177void G4ViewParameters::SetVisibleDensity (G4double visibleDensity) {
178  const G4double reasonableMaximum = 10.0 * g / cm3;
179  if (visibleDensity < 0) {
180    G4cout << "G4ViewParameters::SetVisibleDensity: attempt to set negative "
181      "density - ignored." << G4endl;
182  }
183  else {
184    if (visibleDensity > reasonableMaximum) {
185      G4cout << "G4ViewParameters::SetVisibleDensity: density > "
186             << G4BestUnit (reasonableMaximum, "Volumic Mass")
187             << " - did you mean this?"
188             << G4endl;
189    }
190    fVisibleDensity = visibleDensity;
191  }
192}
193
194G4int G4ViewParameters::SetNoOfSides (G4int nSides) {
195  const G4int  nSidesMin = 12;
196  if (nSides < nSidesMin) {
197    nSides = nSidesMin;
198    G4cout << "G4ViewParameters::SetNoOfSides: attempt to set the"
199      "\nnumber of sides per circle < " << nSidesMin
200         << "; forced to " << nSides << G4endl;
201  }
202  fNoOfSides = nSides;
203  return fNoOfSides;
204}
205
206void G4ViewParameters::SetViewAndLights
207(const G4Vector3D& viewpointDirection) {
208
209  fViewpointDirection = viewpointDirection;
210
211  // If the requested viewpoint direction is parallel to the up
212  // vector, the orientation of the view is undefined...
213  if (fViewpointDirection.unit() * fUpVector.unit() > .9999) {
214    G4cout <<
215      "WARNING: Viewpoint direction is very close to the up vector direction."
216      "\n  Consider setting the up vector to obtain definable behaviour."
217           << G4endl;
218  }
219
220  // Move the lights too if requested...
221  if (fLightsMoveWithCamera) {
222    G4Vector3D zprime = fViewpointDirection.unit ();
223    G4Vector3D xprime = (fUpVector.cross (zprime)).unit ();
224    G4Vector3D yprime = zprime.cross (xprime);
225    fActualLightpointDirection =
226      fRelativeLightpointDirection.x () * xprime +
227      fRelativeLightpointDirection.y () * yprime +
228      fRelativeLightpointDirection.x () * zprime;     
229  } else {
230    fActualLightpointDirection = fRelativeLightpointDirection;
231  }
232}
233
234void G4ViewParameters::SetLightpointDirection
235(const G4Vector3D& lightpointDirection) {
236  fRelativeLightpointDirection = lightpointDirection;
237  SetViewAndLights (fViewpointDirection);
238}
239
240void G4ViewParameters::SetPan (G4double right, G4double up) {
241  G4Vector3D unitRight = (fUpVector.cross (fViewpointDirection)).unit();
242  G4Vector3D unitUp    = (fViewpointDirection.cross (unitRight)).unit();
243  fCurrentTargetPoint  = right * unitRight + up * unitUp;
244}
245
246void G4ViewParameters::IncrementPan (G4double right, G4double up) {
247  IncrementPan (right,up, 0);
248}
249
250void G4ViewParameters::IncrementPan (G4double right, G4double up, G4double distance) {
251  G4Vector3D unitRight = (fUpVector.cross (fViewpointDirection)).unit();
252  G4Vector3D unitUp    = (fViewpointDirection.cross (unitRight)).unit();
253  fCurrentTargetPoint += right * unitRight + up * unitUp + distance * fViewpointDirection;
254}
255
256void G4ViewParameters::PrintDifferences (const G4ViewParameters& v) const {
257
258  // Put performance-sensitive parameters first.
259  if (
260      // This first to optimise spin, etc.
261      (fViewpointDirection   != v.fViewpointDirection)   ||
262
263      // No particular order from here on.
264      (fDrawingStyle         != v.fDrawingStyle)         ||
265      (fAuxEdgeVisible       != v.fAuxEdgeVisible)       ||
266      (fRepStyle             != v.fRepStyle)             ||
267      (fCulling              != v.fCulling)              ||
268      (fCullInvisible        != v.fCullInvisible)        ||
269      (fDensityCulling       != v.fDensityCulling)       ||
270      (fVisibleDensity       != v.fVisibleDensity)       ||
271      (fCullCovered          != v.fCullCovered)          ||
272      (fSection              != v.fSection)              ||
273      (fNoOfSides            != v.fNoOfSides)            ||
274      (fUpVector             != v.fUpVector)             ||
275      (fFieldHalfAngle       != v.fFieldHalfAngle)       ||
276      (fZoomFactor           != v.fZoomFactor)           ||
277      (fScaleFactor          != v.fScaleFactor)          ||
278      (fCurrentTargetPoint   != v.fCurrentTargetPoint)   ||
279      (fDolly                != v.fDolly)                ||
280      (fRelativeLightpointDirection != v.fRelativeLightpointDirection)  ||
281      (fLightsMoveWithCamera != v.fLightsMoveWithCamera) ||
282      (fDefaultVisAttributes != v.fDefaultVisAttributes) ||
283      (fDefaultTextVisAttributes != v.fDefaultTextVisAttributes) ||
284      (fDefaultMarker        != v.fDefaultMarker)        ||
285      (fGlobalMarkerScale    != v.fGlobalMarkerScale)    ||
286      (fGlobalLineWidthScale != v.fGlobalLineWidthScale) ||
287      (fMarkerNotHidden      != v.fMarkerNotHidden)      ||
288      (fWindowSizeHintX      != v.fWindowSizeHintX)      ||
289      (fWindowSizeHintY      != v.fWindowSizeHintY)      ||
290      (fXGeometryString      != v.fXGeometryString)      ||
291      (fAutoRefresh          != v.fAutoRefresh)          ||
292      (fBackgroundColour     != v.fBackgroundColour)     ||
293      (fPicking              != v.fPicking)
294      )
295    G4cout << "Difference in 1st batch." << G4endl;
296
297  if (fSection) {
298    if (!(fSectionPlane == v.fSectionPlane))
299      G4cout << "Difference in section planes batch." << G4endl;
300  }
301
302  if (IsCutaway()) {
303    if (fCutawayPlanes.size () != v.fCutawayPlanes.size ()) {
304      G4cout << "Difference in no of cutaway planes." << G4endl;
305    }
306    else {
307      for (size_t i = 0; i < fCutawayPlanes.size (); i++) {
308        if (!(fCutawayPlanes[i] == v.fCutawayPlanes[i]))
309          G4cout << "Difference in cutaway plane no. " << i << G4endl;
310      }
311    }
312  }
313
314  if (IsExplode()) {
315    if (fExplodeFactor != v.fExplodeFactor)
316      G4cout << "Difference in explode factor." << G4endl;
317    if (fExplodeCentre != v.fExplodeCentre)
318      G4cout << "Difference in explode centre." << G4endl;
319  }
320}
321
322std::ostream& operator << (std::ostream& os,
323                             const G4ViewParameters::DrawingStyle& style) {
324  switch (style) {
325  case G4ViewParameters::wireframe:
326    os << "wireframe"; break;
327  case G4ViewParameters::hlr:
328    os << "hlr - hidden lines removed"; break;
329  case G4ViewParameters::hsr:
330    os << "hsr - hidden surfaces removed"; break;
331  case G4ViewParameters::hlhsr:
332    os << "hlhsr - hidden line, hidden surface removed"; break;
333  default: os << "unrecognised"; break;
334  }
335  return os;
336}
337
338std::ostream& operator << (std::ostream& os, const G4ViewParameters& v) {
339  os << "View parameters and options:";
340
341  os << "\n  Drawing style: " << v.fDrawingStyle;
342
343  os << "\n  Auxiliary edges: ";
344  if (!v.fAuxEdgeVisible) os << "in";
345  os << "visible";
346
347  os << "\n  Representation style: ";
348  switch (v.fRepStyle) {
349  case G4ViewParameters::polyhedron:
350    os << "polyhedron"; break;
351  case G4ViewParameters::nurbs:
352    os << "nurbs"; break;
353  default: os << "unrecognised"; break;
354  }
355
356  os << "\n  Culling: ";
357  if (v.fCulling) os << "on";
358  else            os << "off";
359
360  os << "\n  Culling invisible objects: ";
361  if (v.fCullInvisible) os << "on";
362  else                  os << "off";
363
364  os << "\n  Density culling: ";
365  if (v.fDensityCulling) {
366    os << "on - invisible if density less than "
367       << v.fVisibleDensity / (1. * g / cm3) << " g cm^-3";
368  }
369  else os << "off";
370
371  os << "\n  Culling daughters covered by opaque mothers: ";
372  if (v.fCullCovered) os << "on";
373  else                os << "off";
374
375  os << "\n  Section flag: ";
376  if (v.fSection) os << "true, section/cut plane: " << v.fSectionPlane;
377  else            os << "false";
378
379  if (v.IsCutaway()) {
380    os << "\n  Cutaway planes: ";
381    for (size_t i = 0; i < v.fCutawayPlanes.size (); i++) {
382      os << ' ' << v.fCutawayPlanes[i];
383    }
384  }
385  else {
386    os << "\n  No cutaway planes";
387  }
388
389  os << "\n  Explode factor: " << v.fExplodeFactor
390     << " about centre: " << v.fExplodeCentre;
391
392  os << "\n  No. of sides used in circle polygon approximation: "
393     << v.fNoOfSides;
394
395  os << "\n  Viewpoint direction:  " << v.fViewpointDirection;
396
397  os << "\n  Up vector:            " << v.fUpVector;
398
399  os << "\n  Field half angle:     " << v.fFieldHalfAngle;
400
401  os << "\n  Zoom factor:          " << v.fZoomFactor;
402
403  os << "\n  Scale factor:         " << v.fScaleFactor;
404
405  os << "\n  Current target point: " << v.fCurrentTargetPoint;
406
407  os << "\n  Dolly distance:       " << v.fDolly;
408
409  os << "\n  Light ";
410  if (v.fLightsMoveWithCamera) os << "moves";
411  else                         os << "does not move";
412  os << " with camera";
413
414  os << "\n  Relative lightpoint direction: "
415     << v.fRelativeLightpointDirection;
416
417  os << "\n  Actual lightpoint direction: "
418     << v.fActualLightpointDirection;
419
420  os << "\n  Derived parameters for standard view of object of unit radius:";
421  G4ViewParameters tempVP = v;
422  tempVP.fDolly = 0.;
423  tempVP.fZoomFactor = 1.;
424  const G4double radius = 1.;
425  const G4double cameraDistance = tempVP.GetCameraDistance (radius);
426  const G4double nearDistance =
427    tempVP.GetNearDistance (cameraDistance, radius);
428  const G4double farDistance =
429    tempVP.GetFarDistance  (cameraDistance, nearDistance, radius);
430  const G4double right  = tempVP.GetFrontHalfHeight (nearDistance, radius);
431  os << "\n    Camera distance:   " << cameraDistance;
432  os << "\n    Near distance:     " << nearDistance;
433  os << "\n    Far distance:      " << farDistance;
434  os << "\n    Front half height: " << right;
435
436  os << "\n  Default VisAttributes:\n  " << v.fDefaultVisAttributes;
437
438  os << "\n  Default TextVisAttributes:\n  " << v.fDefaultTextVisAttributes;
439
440  os << "\n  Default marker: " << v.fDefaultMarker;
441
442  os << "\n  Global marker scale: " << v.fGlobalMarkerScale;
443
444  os << "\n  Global lineWidth scale: " << v.fGlobalLineWidthScale;
445
446  os << "\n  Marker ";
447  if (v.fMarkerNotHidden) os << "not ";
448  os << "hidden by surfaces.";
449
450  os << "\n  Window size hint: "
451     << v.fWindowSizeHintX << 'x'<< v.fWindowSizeHintX;
452
453  os << "\n  X geometry string: " << v.fXGeometryString;
454
455  os << "\n  Auto refresh: ";
456  if (v.fAutoRefresh) os << "true";
457  else os << "false";
458
459  os << "\n  Background colour: " << v.fBackgroundColour;
460
461  os << "\n  Picking requested: ";
462  if (v.fPicking) os << "true";
463  else os << "false";
464
465  return os;
466}
467
468G4bool G4ViewParameters::operator != (const G4ViewParameters& v) const {
469
470  // Put performance-sensitive parameters first.
471  if (
472      // This first to optimise spin, etc.
473      (fViewpointDirection   != v.fViewpointDirection)   ||
474
475      // No particular order from here on.
476      (fDrawingStyle         != v.fDrawingStyle)         ||
477      (fAuxEdgeVisible       != v.fAuxEdgeVisible)       ||
478      (fRepStyle             != v.fRepStyle)             ||
479      (fCulling              != v.fCulling)              ||
480      (fCullInvisible        != v.fCullInvisible)        ||
481      (fDensityCulling       != v.fDensityCulling)       ||
482      (fCullCovered          != v.fCullCovered)          ||
483      (fSection              != v.fSection)              ||
484      (IsCutaway()           != v.IsCutaway())           ||
485      (IsExplode()           != v.IsExplode())           ||
486      (fNoOfSides            != v.fNoOfSides)            ||
487      (fUpVector             != v.fUpVector)             ||
488      (fFieldHalfAngle       != v.fFieldHalfAngle)       ||
489      (fZoomFactor           != v.fZoomFactor)           ||
490      (fScaleFactor          != v.fScaleFactor)          ||
491      (fCurrentTargetPoint   != v.fCurrentTargetPoint)   ||
492      (fDolly                != v.fDolly)                ||
493      (fRelativeLightpointDirection != v.fRelativeLightpointDirection)  ||
494      (fLightsMoveWithCamera != v.fLightsMoveWithCamera) ||
495      (fDefaultVisAttributes != v.fDefaultVisAttributes) ||
496      (fDefaultTextVisAttributes != v.fDefaultTextVisAttributes) ||
497      (fDefaultMarker        != v.fDefaultMarker)        ||
498      (fGlobalMarkerScale    != v.fGlobalMarkerScale)    ||
499      (fGlobalLineWidthScale != v.fGlobalLineWidthScale) ||
500      (fMarkerNotHidden      != v.fMarkerNotHidden)      ||
501      (fWindowSizeHintX      != v.fWindowSizeHintX)      ||
502      (fWindowSizeHintY      != v.fWindowSizeHintY)      ||
503      (fXGeometryString      != v.fXGeometryString)      ||
504      (fAutoRefresh          != v.fAutoRefresh)          ||
505      (fBackgroundColour     != v.fBackgroundColour)     ||
506      (fPicking              != v.fPicking)
507      )
508    return true;
509
510  if (fDensityCulling &&
511      (fVisibleDensity != v.fVisibleDensity)) return true;
512
513  if (fSection &&
514      (!(fSectionPlane == v.fSectionPlane))) return true;
515
516  if (IsCutaway()) {
517    if (fCutawayPlanes.size () != v.fCutawayPlanes.size ())
518      return true;
519    else {
520      for (size_t i = 0; i < fCutawayPlanes.size (); i++) {
521        if (!(fCutawayPlanes[i] == v.fCutawayPlanes[i])) return true;
522      }
523    }
524  }
525
526  if (IsExplode() &&
527      ((fExplodeFactor != v.fExplodeFactor) ||
528       (fExplodeCentre != v.fExplodeCentre))) return true;
529
530  return false;
531}
532
533
534void G4ViewParameters::SetXGeometryString (const G4String& geomString) {
535
536
537  G4int x,y = 0;
538  unsigned int w,h = 0;
539  G4int m = ParseGeometry( geomString, &x, &y, &w, &h );
540
541  // Check errors
542  if ( ((m & fYValue) == 0))
543#ifdef G4DEBUG
544    printf("G4ViewParameters::SetXGeometryString YValue\n");
545#endif
546
547  if ( ((m & fXValue) == 0))
548#ifdef G4DEBUG
549    printf("G4ViewParameters::SetXGeometryString XValue\n");
550#endif
551  if ( ((m & fHeightValue) == 0 ))
552#ifdef G4DEBUG
553    printf("G4ViewParameters::SetXGeometryString fHeightValue\n");
554#endif
555  if ( ((m & fWidthValue)  == 0 ))
556#ifdef G4DEBUG
557    printf("G4ViewParameters::SetXGeometryString fWidthValue\n");
558#endif
559
560  if ( ((m & fYValue) == 0) ||
561       ((m & fXValue) == 0) ||
562       ((m & fHeightValue) == 0 ) ||
563       ((m & fWidthValue)  == 0 )) {
564    G4cout << "ERROR: Unrecognised geometry string \""
565           << geomString
566           << "\".  Using default"
567           << G4endl;
568  } else {
569    // Set the string
570    fXGeometryString = geomString;
571
572    // Set values
573    fWindowSizeHintX = w;
574    fWindowSizeHintY = h;
575    fWindowLocationHintX = x;
576    fWindowLocationHintY = y;
577    if ( (m & fXNegative) ) {
578      fWindowLocationHintXNegative = true;
579    } else {
580      fWindowLocationHintXNegative = false;
581    }
582    if ( (m & fYNegative) ) {
583      fWindowLocationHintYNegative = true;
584    } else {
585      fWindowLocationHintYNegative = false;
586    }
587
588  }
589
590}
591
592G4int G4ViewParameters::GetWindowAbsoluteLocationHintX (G4int sizeX ) const {
593#ifdef G4DEBUG
594  printf("G4ViewParameters::GetWindowLocationHintX () :: %d\n",fWindowLocationHintX);
595#endif
596  if ( fWindowLocationHintXNegative ) {
597    return  sizeX  + fWindowLocationHintX - fWindowSizeHintX;
598  }
599  return fWindowLocationHintX;
600}
601
602G4int G4ViewParameters::GetWindowAbsoluteLocationHintY (G4int sizeY ) const {
603#ifdef G4DEBUG
604  printf("G4ViewParameters::GetWindowLocationHintY () :: %d\n",fWindowLocationHintY);
605#endif
606  if (  fWindowLocationHintYNegative ) {
607    return  sizeY  + fWindowLocationHintY - fWindowSizeHintY;
608  }
609  return fWindowLocationHintY;
610}
611
612/* Keep from :
613 * ftp://ftp.trolltech.com/qt/source/qt-embedded-free-3.0.6.tar.gz/qt-embedded-free-3.0.6/src/kernel/qapplication_qws.cpp
614 *
615 *    ParseGeometry parses strings of the form
616 *   "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where
617 *   width, height, xoffset, and yoffset are unsigned integers.
618 *   Example:  "=80x24+300-49"
619 *   The equal sign is optional.
620 *   It returns a bitmask that indicates which of the four values
621 *   were actually found in the string. For each value found,
622 *   the corresponding argument is updated;  for each value
623 *   not found, the corresponding argument is left unchanged.
624 */
625
626int G4ViewParameters::ParseGeometry (
627 const char *string,
628 G4int *x,
629 G4int *y,
630 unsigned int *width,
631 unsigned int *height)
632{
633
634  G4int mask = fNoValue;
635  register char *strind;
636  unsigned int tempWidth  = 0;
637  unsigned int tempHeight = 0;
638  G4int tempX = 0;
639  G4int tempY = 0;
640  char *nextCharacter;
641  if ( (string == NULL) || (*string == '\0')) {
642    return(mask);
643  }
644  if (*string == '=')
645    string++;  /* ignore possible '=' at beg of geometry spec */
646  strind = (char *)string;
647  if (*strind != '+' && *strind != '-' && *strind != 'x') {
648#ifdef G4DEBUG
649  printf("G4ViewParameters::ParseGeometry !+-x\n");
650#endif
651    tempWidth = ReadInteger(strind, &nextCharacter);
652    if (strind == nextCharacter)
653      return (0);
654    strind = nextCharacter;
655    mask |= fWidthValue;
656  }
657  if (*strind == 'x' || *strind == 'X') {
658#ifdef G4DEBUG
659  printf("G4ViewParameters::ParseGeometry = xX\n");
660#endif
661    strind++;
662    tempHeight = ReadInteger(strind, &nextCharacter);
663    if (strind == nextCharacter)
664      return (0);
665    strind = nextCharacter;
666    mask |= fHeightValue;
667  }
668
669  if ((*strind == '+') || (*strind == '-')) {
670#ifdef G4DEBUG
671  printf("G4ViewParameters::ParseGeometry = +-\n");
672#endif
673    if (*strind == '-') {
674      strind++;
675      tempX = -ReadInteger(strind, &nextCharacter);
676      if (strind == nextCharacter)
677        return (0);
678      strind = nextCharacter;
679      mask |= fXNegative;
680
681    }
682    else
683      { strind++;
684        tempX = ReadInteger(strind, &nextCharacter);
685        if (strind == nextCharacter)
686          return(0);
687        strind = nextCharacter;
688      }
689    mask |= fXValue;
690    if ((*strind == '+') || (*strind == '-')) {
691      if (*strind == '-') {
692        strind++;
693        tempY = -ReadInteger(strind, &nextCharacter);
694        if (strind == nextCharacter)
695          return(0);
696        strind = nextCharacter;
697        mask |= fYNegative;
698      }
699      else
700        {
701          strind++;
702          tempY = ReadInteger(strind, &nextCharacter);
703          if (strind == nextCharacter)
704            return(0);
705          strind = nextCharacter;
706        }
707      mask |= fYValue;
708    }
709  }
710  /* If strind isn't at the end of the string the it's an invalid
711     geometry specification. */
712  if (*strind != '\0') return (0);
713  if (mask & fXValue)
714    *x = tempX;
715  if (mask & fYValue)
716    *y = tempY;
717  if (mask & fWidthValue)
718    *width = tempWidth;
719  if (mask & fHeightValue)
720    *height = tempHeight;
721  return (mask);
722}
723
724/* Keep from :
725 * ftp://ftp.trolltech.com/qt/source/qt-embedded-free-3.0.6.tar.gz/qt-embedded-free-3.0.6/src/kernel/qapplication_qws.cpp
726 *
727 */
728G4int G4ViewParameters::ReadInteger(char *string, char **NextString)
729{
730    register G4int Result = 0;
731    G4int Sign = 1;
732
733    if (*string == '+')
734        string++;
735    else if (*string == '-')
736    {
737        string++;
738        Sign = -1;
739    }
740    for (; (*string >= '0') && (*string <= '9'); string++)
741    {
742        Result = (Result * 10) + (*string - '0');
743    }
744    *NextString = string;
745    if (Sign >= 0)
746        return (Result);
747    else
748        return (-Result);
749}
750   
Note: See TracBrowser for help on using the repository browser.