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

Last change on this file since 1183 was 1136, checked in by garnier, 16 years ago

debug updates

  • Property svn:mime-type set to text/cpp
File size: 24.5 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 // 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 fGeometryMask = ParseGeometry( geomString, &x, &y, &w, &h );
559
560 // Handle special case :
561 if ((fGeometryMask & fYValue) == 0)
562 { // Using default
563 y = fWindowLocationHintY;
564 }
565 if ((fGeometryMask & fXValue) == 0)
566 { // Using default
567 x = fWindowLocationHintX;
568 }
569
570 // Check errors
571 // if there is no Width and Height
572 if ( ((fGeometryMask & fHeightValue) == 0 ) &&
573 ((fGeometryMask & fWidthValue) == 0 )) {
574 h = fWindowSizeHintY;
575 w = fWindowSizeHintX;
576 } else if ((fGeometryMask & fHeightValue) == 0 ) {
577
578 // if there is only Width. Special case to be backward compatible
579 // We set Width and Height the same to obtain a square windows.
580
581 G4cout << "Unrecognised geometry string \""
582 << geomString
583 << "\". No Height found. Using Width value instead"
584 << G4endl;
585 h = w;
586 }
587 if ( ((fGeometryMask & fXValue) == 0 ) ||
588 ((fGeometryMask & fYValue) == 0 )) {
589 //Using defaults
590 x = fWindowLocationHintX;
591 y = fWindowLocationHintY;
592 }
593 // Set the string
594 fXGeometryString = geomString;
595
596 // Set values
597 fWindowSizeHintX = w;
598 fWindowSizeHintY = h;
599 fWindowLocationHintX = x;
600 fWindowLocationHintY = y;
601
602 if ( ((fGeometryMask & fXValue)) &&
603 ((fGeometryMask & fYValue))) {
604
605 if ( (fGeometryMask & fXNegative) ) {
606 fWindowLocationHintXNegative = true;
607 } else {
608 fWindowLocationHintXNegative = false;
609 }
610 if ( (fGeometryMask & fYNegative) ) {
611 fWindowLocationHintYNegative = true;
612 } else {
613 fWindowLocationHintYNegative = false;
614 }
615 }
616}
617
618G4int G4ViewParameters::GetWindowAbsoluteLocationHintX (G4int sizeX ) const {
619 if ( fWindowLocationHintXNegative ) {
620 return sizeX + fWindowLocationHintX - fWindowSizeHintX;
621 }
622 return fWindowLocationHintX;
623}
624
625G4int G4ViewParameters::GetWindowAbsoluteLocationHintY (G4int sizeY ) const {
626 if ( fWindowLocationHintYNegative ) {
627 return sizeY + fWindowLocationHintY - fWindowSizeHintY;
628 }
629 return fWindowLocationHintY;
630}
631
632/* Keep from :
633 * 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
634 *
635 * ParseGeometry parses strings of the form
636 * "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where
637 * width, height, xoffset, and yoffset are unsigned integers.
638 * Example: "=80x24+300-49"
639 * The equal sign is optional.
640 * It returns a bitmask that indicates which of the four values
641 * were actually found in the string. For each value found,
642 * the corresponding argument is updated; for each value
643 * not found, the corresponding argument is left unchanged.
644 */
645
646int G4ViewParameters::ParseGeometry (
647 const char *string,
648 G4int *x,
649 G4int *y,
650 unsigned int *width,
651 unsigned int *height)
652{
653
654 G4int mask = fNoValue;
655 register char *strind;
656 unsigned int tempWidth = 0;
657 unsigned int tempHeight = 0;
658 G4int tempX = 0;
659 G4int tempY = 0;
660 char *nextCharacter;
661 if ( (string == NULL) || (*string == '\0')) {
662 return(mask);
663 }
664 if (*string == '=')
665 string++; /* ignore possible '=' at beg of geometry spec */
666 strind = (char *)string;
667 if (*strind != '+' && *strind != '-' && *strind != 'x') {
668 tempWidth = ReadInteger(strind, &nextCharacter);
669 if (strind == nextCharacter)
670 return (0);
671 strind = nextCharacter;
672 mask |= fWidthValue;
673 }
674 if (*strind == 'x' || *strind == 'X') {
675 strind++;
676 tempHeight = ReadInteger(strind, &nextCharacter);
677 if (strind == nextCharacter)
678 return (0);
679 strind = nextCharacter;
680 mask |= fHeightValue;
681 }
682
683 if ((*strind == '+') || (*strind == '-')) {
684 if (*strind == '-') {
685 strind++;
686 tempX = -ReadInteger(strind, &nextCharacter);
687 if (strind == nextCharacter)
688 return (0);
689 strind = nextCharacter;
690 mask |= fXNegative;
691
692 }
693 else
694 { strind++;
695 tempX = ReadInteger(strind, &nextCharacter);
696 if (strind == nextCharacter)
697 return(0);
698 strind = nextCharacter;
699 }
700 mask |= fXValue;
701 if ((*strind == '+') || (*strind == '-')) {
702 if (*strind == '-') {
703 strind++;
704 tempY = -ReadInteger(strind, &nextCharacter);
705 if (strind == nextCharacter)
706 return(0);
707 strind = nextCharacter;
708 mask |= fYNegative;
709 }
710 else
711 {
712 strind++;
713 tempY = ReadInteger(strind, &nextCharacter);
714 if (strind == nextCharacter)
715 return(0);
716 strind = nextCharacter;
717 }
718 mask |= fYValue;
719 }
720 }
721 /* If strind isn't at the end of the string the it's an invalid
722 geometry specification. */
723 if (*strind != '\0') return (0);
724 if (mask & fXValue)
725 *x = tempX;
726 if (mask & fYValue)
727 *y = tempY;
728 if (mask & fWidthValue)
729 *width = tempWidth;
730 if (mask & fHeightValue)
731 *height = tempHeight;
732 return (mask);
733}
734
735/* Keep from :
736 * 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
737 *
738 */
739G4int G4ViewParameters::ReadInteger(char *string, char **NextString)
740{
741 register G4int Result = 0;
742 G4int Sign = 1;
743
744 if (*string == '+')
745 string++;
746 else if (*string == '-')
747 {
748 string++;
749 Sign = -1;
750 }
751 for (; (*string >= '0') && (*string <= '9'); string++)
752 {
753 Result = (Result * 10) + (*string - '0');
754 }
755 *NextString = string;
756 if (Sign >= 0)
757 return (Result);
758 else
759 return (-Result);
760}
761
Note: See TracBrowser for help on using the repository browser.