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

Last change on this file since 939 was 931, checked in by garnier, 17 years ago

test pour GL_POINTS au lieu de glBitmap

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