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

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

change debug definition, and tag for files

  • Property svn:mime-type set to text/cpp
File size: 23.9 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.34 2009/01/19 16:26:40 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& geomStringArg) {
535
536
537  G4int x,y = 0;
538  unsigned int w,h = 0;
539  G4String geomString = geomStringArg;
540  // Parse windowSizeHintString for backwards compatibility...
541  const G4String delimiters("xX+-");
542  G4String::size_type i = geomString.find_first_of(delimiters);
543  if (i == G4String::npos) {  // Does not contain "xX+-".  Assume single number
544    std::istringstream iss(geomString);
545    G4int size;
546    iss >> size;
547    if (!iss) {
548      size = 600;
549      G4cout << "Unrecognised windowSizeHint string: \""
550             << geomString
551             << "\".  Asuuming " << size << G4endl;
552    }
553    std::ostringstream oss;
554    oss << size << 'x' << size;
555    geomString = oss.str();
556  }
557 
558  G4int m = ParseGeometry( geomString, &x, &y, &w, &h );
559
560  // Handle special case :
561  if ((m & fYValue) == 0)
562    {  // Using default
563      y =  fWindowLocationHintY;     
564    }
565  if ((m & fXValue) == 0)
566    {  // Using default
567      x =  fWindowLocationHintX;     
568    }
569
570  // Check errors
571  if ( ((m & fHeightValue) == 0 ) ||
572       ((m & fWidthValue)  == 0 )) {
573    G4cout << "ERROR: Unrecognised geometry string \""
574           << geomString
575           << "\".  Using default"
576           << G4endl;
577  } else {
578    // Set the string
579    fXGeometryString = geomString;
580
581    // Set values
582    fWindowSizeHintX = w;
583    fWindowSizeHintY = h;
584    fWindowLocationHintX = x;
585    fWindowLocationHintY = y;
586    if ( (m & fXNegative) ) {
587      fWindowLocationHintXNegative = true;
588    } else {
589      fWindowLocationHintXNegative = false;
590    }
591    if ( (m & fYNegative) ) {
592      fWindowLocationHintYNegative = true;
593    } else {
594      fWindowLocationHintYNegative = false;
595    }
596  }
597
598}
599
600G4int G4ViewParameters::GetWindowAbsoluteLocationHintX (G4int sizeX ) const {
601  if ( fWindowLocationHintXNegative ) {
602    return  sizeX  + fWindowLocationHintX - fWindowSizeHintX;
603  }
604  return fWindowLocationHintX;
605}
606
607G4int G4ViewParameters::GetWindowAbsoluteLocationHintY (G4int sizeY ) const {
608  if (  fWindowLocationHintYNegative ) {
609    return  sizeY  + fWindowLocationHintY - fWindowSizeHintY;
610  }
611  return fWindowLocationHintY;
612}
613
614/* Keep from :
615 * 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
616 *
617 *    ParseGeometry parses strings of the form
618 *   "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where
619 *   width, height, xoffset, and yoffset are unsigned integers.
620 *   Example:  "=80x24+300-49"
621 *   The equal sign is optional.
622 *   It returns a bitmask that indicates which of the four values
623 *   were actually found in the string. For each value found,
624 *   the corresponding argument is updated;  for each value
625 *   not found, the corresponding argument is left unchanged.
626 */
627
628int G4ViewParameters::ParseGeometry (
629 const char *string,
630 G4int *x,
631 G4int *y,
632 unsigned int *width,
633 unsigned int *height)
634{
635
636  G4int mask = fNoValue;
637  register char *strind;
638  unsigned int tempWidth  = 0;
639  unsigned int tempHeight = 0;
640  G4int tempX = 0;
641  G4int tempY = 0;
642  char *nextCharacter;
643  if ( (string == NULL) || (*string == '\0')) {
644    return(mask);
645  }
646  if (*string == '=')
647    string++;  /* ignore possible '=' at beg of geometry spec */
648  strind = (char *)string;
649  if (*strind != '+' && *strind != '-' && *strind != 'x') {
650    tempWidth = ReadInteger(strind, &nextCharacter);
651    if (strind == nextCharacter)
652      return (0);
653    strind = nextCharacter;
654    mask |= fWidthValue;
655  }
656  if (*strind == 'x' || *strind == 'X') {
657    strind++;
658    tempHeight = ReadInteger(strind, &nextCharacter);
659    if (strind == nextCharacter)
660      return (0);
661    strind = nextCharacter;
662    mask |= fHeightValue;
663  }
664
665  if ((*strind == '+') || (*strind == '-')) {
666    if (*strind == '-') {
667      strind++;
668      tempX = -ReadInteger(strind, &nextCharacter);
669      if (strind == nextCharacter)
670        return (0);
671      strind = nextCharacter;
672      mask |= fXNegative;
673
674    }
675    else
676      { strind++;
677        tempX = ReadInteger(strind, &nextCharacter);
678        if (strind == nextCharacter)
679          return(0);
680        strind = nextCharacter;
681      }
682    mask |= fXValue;
683    if ((*strind == '+') || (*strind == '-')) {
684      if (*strind == '-') {
685        strind++;
686        tempY = -ReadInteger(strind, &nextCharacter);
687        if (strind == nextCharacter)
688          return(0);
689        strind = nextCharacter;
690        mask |= fYNegative;
691      }
692      else
693        {
694          strind++;
695          tempY = ReadInteger(strind, &nextCharacter);
696          if (strind == nextCharacter)
697            return(0);
698          strind = nextCharacter;
699        }
700      mask |= fYValue;
701    }
702  }
703  /* If strind isn't at the end of the string the it's an invalid
704     geometry specification. */
705  if (*strind != '\0') return (0);
706  if (mask & fXValue)
707    *x = tempX;
708  if (mask & fYValue)
709    *y = tempY;
710  if (mask & fWidthValue)
711    *width = tempWidth;
712  if (mask & fHeightValue)
713    *height = tempHeight;
714  return (mask);
715}
716
717/* Keep from :
718 * 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
719 *
720 */
721G4int G4ViewParameters::ReadInteger(char *string, char **NextString)
722{
723    register G4int Result = 0;
724    G4int Sign = 1;
725
726    if (*string == '+')
727        string++;
728    else if (*string == '-')
729    {
730        string++;
731        Sign = -1;
732    }
733    for (; (*string >= '0') && (*string <= '9'); string++)
734    {
735        Result = (Result * 10) + (*string - '0');
736    }
737    *NextString = string;
738    if (Sign >= 0)
739        return (Result);
740    else
741        return (-Result);
742}
743   
Note: See TracBrowser for help on using the repository browser.