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

Last change on this file since 899 was 897, checked in by garnier, 17 years ago

suppres des debug et modif des WinSize

  • Property svn:mime-type set to text/cpp
File size: 23.4 KB
RevLine 
[531]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//
[846]27// $Id: G4ViewParameters.cc,v 1.31 2008/04/04 13:48:53 allison Exp $
[850]28// GEANT4 tag $Name: HEAD $
[531]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 ():
[896]41 fNoValue(0x0000),
42 fXValue(0x0001),
43 fYValue(0x0002),
44 fWidthValue(0x0004),
45 fHeightValue(0x0008),
46 fAllValues(0x000F),
47 fXNegative(0x0010),
48 fYNegative(0x0020),
[531]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),
[896]81 fWindowLocationHintX(0),
82 fWindowLocationHintY(0),
83 fWindowLocationHintXNegative(true),
84 fWindowLocationHintYNegative(false),
[531]85 fAutoRefresh (false),
[593]86 fBackgroundColour (G4Colour(0.,0.,0.)), // Black
87 fPicking (false)
[531]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) {
[712]247 IncrementPan (right,up, 0);
248}
249
250void G4ViewParameters::IncrementPan (G4double right, G4double up, G4double distance) {
[531]251 G4Vector3D unitRight = (fUpVector.cross (fViewpointDirection)).unit();
252 G4Vector3D unitUp = (fViewpointDirection.cross (unitRight)).unit();
[712]253 fCurrentTargetPoint += right * unitRight + up * unitUp + distance * fViewpointDirection;
[531]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) ||
[593]292 (fBackgroundColour != v.fBackgroundColour) ||
293 (fPicking != v.fPicking)
294 )
[531]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
[593]461 os << "\n Picking requested: ";
462 if (v.fPicking) os << "true";
463 else os << "false";
464
[531]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) ||
[593]505 (fBackgroundColour != v.fBackgroundColour) ||
506 (fPicking != v.fPicking)
507 )
[531]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() &&
[846]527 ((fExplodeFactor != v.fExplodeFactor) ||
528 (fExplodeCentre != v.fExplodeCentre))) return true;
[531]529
530 return false;
531}
[896]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 ((m & fXValue) == 0) ||
544 ((m & fHeightValue) == 0 ) ||
545 ((m & fWidthValue) == 0 )) {
546 G4cout << "ERROR: Unrecognised geometry string \""
547 << geomString
548 << "\". Using default"
549 << G4endl;
550 } else {
551 // Set the string
552 fXGeometryString = geomString;
553
554 // Set values
555 fWindowSizeHintX = w;
556 fWindowSizeHintY = h;
557 fWindowLocationHintX = x;
558 fWindowLocationHintY = y;
559 if ( (m & fXNegative) ) {
560 fWindowLocationHintXNegative = true;
561 } else {
562 fWindowLocationHintXNegative = false;
563 }
564 if ( (m & fYNegative) ) {
565 fWindowLocationHintYNegative = true;
566 } else {
567 fWindowLocationHintYNegative = false;
568 }
569
570 }
571
572}
573
574G4int G4ViewParameters::GetWindowAbsoluteLocationHintX (G4int sizeX ) const {
575#ifdef G4DEBUG
576 printf("G4ViewParameters::GetWindowLocationHintX () :: %d\n",fWindowLocationHintX);
577#endif
578 if ( fWindowLocationHintXNegative ) {
579 return sizeX + fWindowLocationHintX - fWindowSizeHintX;
580 }
581 return fWindowLocationHintX;
582}
583
584G4int G4ViewParameters::GetWindowAbsoluteLocationHintY (G4int sizeY ) const {
585#ifdef G4DEBUG
586 printf("G4ViewParameters::GetWindowLocationHintY () :: %d\n",fWindowLocationHintY);
587#endif
588 if ( fWindowLocationHintYNegative ) {
589 return sizeY + fWindowLocationHintY - fWindowSizeHintY;
590 }
591 return fWindowLocationHintY;
592}
593
594/* Keep from :
595 * 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
596 *
597 * ParseGeometry parses strings of the form
598 * "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where
599 * width, height, xoffset, and yoffset are unsigned integers.
600 * Example: "=80x24+300-49"
601 * The equal sign is optional.
602 * It returns a bitmask that indicates which of the four values
603 * were actually found in the string. For each value found,
604 * the corresponding argument is updated; for each value
605 * not found, the corresponding argument is left unchanged.
606 */
607
608int G4ViewParameters::ParseGeometry (
609 const char *string,
610 G4int *x,
611 G4int *y,
612 unsigned int *width,
613 unsigned int *height)
614{
615
616 G4int mask = fNoValue;
617 register char *strind;
618 unsigned int tempWidth, tempHeight;
619 G4int tempX, tempY;
620 char *nextCharacter;
621 if ( (string == NULL) || (*string == '\0')) {
622 return(mask);
623 }
624 if (*string == '=')
625 string++; /* ignore possible '=' at beg of geometry spec */
626 strind = (char *)string;
627 if (*strind != '+' && *strind != '-' && *strind != 'x') {
628 tempWidth = ReadInteger(strind, &nextCharacter);
629 if (strind == nextCharacter)
630 return (0);
631 strind = nextCharacter;
632 mask |= fWidthValue;
633 }
634 if (*strind == 'x' || *strind == 'X') {
635 strind++;
636 tempHeight = ReadInteger(strind, &nextCharacter);
637 if (strind == nextCharacter)
638 return (0);
639 strind = nextCharacter;
640 mask |= fHeightValue;
641 }
642
643 if ((*strind == '+') || (*strind == '-')) {
644 if (*strind == '-') {
645 strind++;
646 tempX = -ReadInteger(strind, &nextCharacter);
647 if (strind == nextCharacter)
648 return (0);
649 strind = nextCharacter;
650 mask |= fXNegative;
651
652 }
653 else
654 { strind++;
655 tempX = ReadInteger(strind, &nextCharacter);
656 if (strind == nextCharacter)
657 return(0);
658 strind = nextCharacter;
659 }
660 mask |= fXValue;
661 if ((*strind == '+') || (*strind == '-')) {
662 if (*strind == '-') {
663 strind++;
664 tempY = -ReadInteger(strind, &nextCharacter);
665 if (strind == nextCharacter)
666 return(0);
667 strind = nextCharacter;
668 mask |= fYNegative;
669 }
670 else
671 {
672 strind++;
673 tempY = ReadInteger(strind, &nextCharacter);
674 if (strind == nextCharacter)
675 return(0);
676 strind = nextCharacter;
677 }
678 mask |= fYValue;
679 }
680 }
681 /* If strind isn't at the end of the string the it's an invalid
682 geometry specification. */
683 if (*strind != '\0') return (0);
684 if (mask & fXValue)
685 *x = tempX;
686 if (mask & fYValue)
687 *y = tempY;
688 if (mask & fWidthValue)
689 *width = tempWidth;
690 if (mask & fHeightValue)
691 *height = tempHeight;
692 return (mask);
693}
694
695/* Keep from :
696 * 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
697 *
698 */
699G4int G4ViewParameters::ReadInteger(char *string, char **NextString)
700{
701 register G4int Result = 0;
702 G4int Sign = 1;
703
704 if (*string == '+')
705 string++;
706 else if (*string == '-')
707 {
708 string++;
709 Sign = -1;
710 }
711 for (; (*string >= '0') && (*string <= '9'); string++)
712 {
713 Result = (Result * 10) + (*string - '0');
714 }
715 *NextString = string;
716 if (Sign >= 0)
717 return (Result);
718 else
719 return (-Result);
720}
721
Note: See TracBrowser for help on using the repository browser.