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

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

tag geant4.9.4 beta 1 + modifs locales

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