source: trunk/geant4/visualization/OpenInventor/src/G4OpenInventorViewer.cc @ 529

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

r658@mac-90108: laurentgarnier | 2007-06-25 12:02:16 +0200
import de visualisation

  • Property svn:mime-type set to text/cpp
File size: 22.4 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// $Id: G4OpenInventorViewer.cc,v 1.57 2006/11/01 11:06:07 allison Exp $
27// GEANT4 tag $Name: geant4-08-02-patch-01 $
28
29#ifdef G4VIS_BUILD_OI_DRIVER
30
31// this :
32#include "G4OpenInventorViewer.hh"
33
34#include <Inventor/nodes/SoSelection.h>
35#include <Inventor/nodes/SoShape.h>
36#include <Inventor/nodes/SoOrthographicCamera.h>
37#include <Inventor/nodes/SoPerspectiveCamera.h>
38#include <Inventor/actions/SoCallbackAction.h>
39#include <Inventor/actions/SoWriteAction.h>
40#include <Inventor/sensors/SoNodeSensor.h>
41
42#include "HEPVis/nodes/SoImageWriter.h"
43#include "HEPVis/actions/SoGL2PSAction.h"
44#include "HEPVis/actions/SoCounterAction.h"
45#include "HEPVis/actions/SoAlternateRepAction.h"
46
47#include "G4OpenInventor.hh"
48#include "G4OpenInventorSceneHandler.hh"
49#include "G4VInteractorManager.hh"
50#include "G4Scene.hh"
51#include "Geant4_SoPolyhedron.h"
52#include "G4AttValue.hh"
53#include "G4AttDef.hh"
54#include "G4AttCheck.hh"
55#include "G4AttHolder.hh"
56
57G4OpenInventorViewer::G4OpenInventorViewer(
58 G4OpenInventorSceneHandler& sceneHandler
59,const G4String& name)
60:G4VViewer(sceneHandler, sceneHandler.IncrementViewCount(), name)
61,fG4OpenInventorSceneHandler(sceneHandler)
62,fInteractorManager(0)
63,fSoSelection(0)
64,fSoImageWriter(0)
65,fGL2PSAction(0) //To be set be suclass.
66,fGroupCameraSensor(0)
67,fCameraSensor(0)
68{
69  fNeedKernelVisit = true;  //?? Temporary, until KernelVisitDecision fixed.
70
71  fDefaultVP.SetAutoRefresh(true);
72  fVP.SetAutoRefresh(true);
73
74  //FIXME : G.Barrand : not convinced that we have to rm culling.
75  // For viewing of all objects by default :
76  //fDefaultVP.SetCulling(false);
77  //fVP.SetCulling(false);
78
79  fInteractorManager =
80    ((G4OpenInventor*)fG4OpenInventorSceneHandler.GetGraphicsSystem())->
81    GetInteractorManager();
82
83  // Main user scene graph root sent to the viewers.
84  fSoSelection = new SoSelection;
85  fSoSelection->ref();
86  fSoSelection->addSelectionCallback(SelectionCB,this);
87  //fSoSelection->addDeselectionCallback(DeselectionCB,this);
88  fSoSelection->policy = SoSelection::SINGLE;
89
90  SoGroup* group = new SoGroup;
91  fSoSelection->addChild(group);
92
93  //  Have a camera under fSoSelection in order
94  // that the below SceneGraphSensor be notifed
95  // when the viewer changes the camera type.
96  //  But we put the camera under a SoGroup so that
97  // the SceneGraphSensor be not triggered at each change
98  // under the fG4OpenInventorSceneHandler.fRoot.
99  SoOrthographicCamera* camera = new SoOrthographicCamera;
100  camera->viewportMapping.setValue(SoCamera::ADJUST_CAMERA);
101  //camera->aspectRatio.setValue(10);
102  camera->position.setValue(0,0,10);
103  camera->orientation.setValue(SbRotation(SbVec3f(0,1,0),0));
104  camera->height.setValue(10);
105  camera->nearDistance.setValue(1);
106  camera->farDistance.setValue(100);
107  camera->focalDistance.setValue(10);
108  group->addChild(camera);
109
110 {SoInput soInput;
111   if(soInput.openFile("g4view.iv",TRUE)) {
112    SoSeparator* separator = SoDB::readAll(&soInput);
113    if(separator) fSoSelection->addChild(separator);
114  }}
115
116  fSoSelection->addChild(fG4OpenInventorSceneHandler.fRoot);
117
118  // SoImageWriter should be the last.
119  fSoImageWriter = new SoImageWriter();
120  fSoImageWriter->fileName.setValue("g4out.ps");
121  fSoSelection->addChild(fSoImageWriter);
122
123  // Sensors :
124  // To detect that the viewer had changed the camera type :
125  fGroupCameraSensor = new SoNodeSensor(GroupCameraSensorCB,this);
126  fGroupCameraSensor->setPriority(0);//Needed in order to do getTriggerNode()
127  fGroupCameraSensor->attach(group);
128
129  fCameraSensor = new SoNodeSensor(CameraSensorCB,this);
130  fCameraSensor->setPriority(0);//Needed in order to do getTriggerNode()
131}
132
133G4OpenInventorViewer::~G4OpenInventorViewer () {
134  fCameraSensor->detach();
135  delete fCameraSensor;
136  fGroupCameraSensor->detach();
137  delete fGroupCameraSensor;
138  fSoSelection->unref();
139}
140
141void G4OpenInventorViewer::KernelVisitDecision () {
142 
143  // If there's a significant difference with the last view parameters
144  // of either the scene handler or this viewer, trigger a rebuild.
145
146  if (
147      //??fG4OpenInventorSceneHandler.fPODLList.size() == 0 ||
148      // We need a test for empty scene graph, such as
149      // staticRoot.size() or something??????????  See temporary fix
150      // in contructor.  (John Allison Aug 2001)
151      CompareForKernelVisit(fLastVP)) {
152    NeedKernelVisit ();
153  }     
154  fLastVP = fVP;
155}
156 
157G4bool G4OpenInventorViewer::CompareForKernelVisit(G4ViewParameters& vp) {
158
159  if (
160      (vp.GetDrawingStyle ()    != fVP.GetDrawingStyle ())    ||
161      (vp.IsAuxEdgeVisible ()   != fVP.IsAuxEdgeVisible ())   ||
162      (vp.GetRepStyle ()        != fVP.GetRepStyle ())        ||
163      (vp.IsCulling ()          != fVP.IsCulling ())          ||
164      (vp.IsCullingInvisible () != fVP.IsCullingInvisible ()) ||
165      (vp.IsDensityCulling ()   != fVP.IsDensityCulling ())   ||
166      (vp.IsCullingCovered ()   != fVP.IsCullingCovered ())   ||
167      (vp.IsSection ()          != fVP.IsSection ())          ||
168      (vp.IsCutaway ()          != fVP.IsCutaway ())          ||
169      // This assumes use of generic clipping (sectioning, slicing,
170      // DCUT, cutaway).  If a decision is made to implement locally,
171      // this will need changing.  See G4OpenGLViewer::SetView,
172      // G4OpenGLStoredViewer.cc::CompareForKernelVisit and
173      // G4OpenGLStoredSceneHander::CreateSection/CutawayPolyhedron.
174      (vp.IsExplode ()          != fVP.IsExplode ())          ||
175      (vp.GetNoOfSides ()       != fVP.GetNoOfSides ())       ||
176      (vp.IsMarkerNotHidden ()  != fVP.IsMarkerNotHidden ())  ||
177      (vp.GetBackgroundColour ()!= fVP.GetBackgroundColour ())
178      ) {
179      return true;;
180  }
181  if (vp.IsDensityCulling () &&
182      (vp.GetVisibleDensity () != fVP.GetVisibleDensity ()))
183    return true;
184
185  if (vp.IsSection () &&
186      (vp.GetSectionPlane () != fVP.GetSectionPlane ()))
187    return true;
188
189  if (vp.IsCutaway ()) {
190    if (vp.GetCutawayPlanes ().size () !=
191        fVP.GetCutawayPlanes ().size ()) return true;
192    for (size_t i = 0; i < vp.GetCutawayPlanes().size(); ++i)
193      if (vp.GetCutawayPlanes()[i] != fVP.GetCutawayPlanes()[i])
194        return true;
195  }
196
197  if (vp.IsExplode () &&
198      (vp.GetExplodeFactor () != fVP.GetExplodeFactor ()))
199    return true;
200     
201  return false;
202}
203
204void G4OpenInventorViewer::ClearView () {
205}
206
207void G4OpenInventorViewer::SetView () {
208
209  // Get G4 camera infos :
210  const G4Point3D target
211    = fSceneHandler.GetScene()->GetStandardTargetPoint()
212    + fVP.GetCurrentTargetPoint ();
213  G4double radius = fSceneHandler.GetScene()->GetExtent().GetExtentRadius();
214  if(radius<=0.) radius = 1.;
215  const G4double cameraDistance = fVP.GetCameraDistance (radius);
216  const G4Vector3D& direction = fVP.GetViewpointDirection().unit();
217  const G4Point3D cameraPosition = target + cameraDistance * direction;
218  //const G4double pnear = fVP.GetNearDistance (cameraDistance, radius);
219  //const G4double pfar  = fVP.GetFarDistance  (cameraDistance, pnear, radius);
220  const G4Normal3D& up = fVP.GetUpVector (); 
221
222/*
223  printf("debug : target : %g %g %g\n",target.x(),
224                                       target.y(),
225                                       target.z());
226  printf("debug : dir : %g %g %g\n",direction.x(),
227                                    direction.y(),
228                                    direction.z());
229  printf("debug : pos : %g %g %g\n",cameraPosition.x(),
230                                    cameraPosition.y(),
231                                    cameraPosition.z());
232  //printf("debug : near %g far %g\n",pnear,pfar);
233*/
234
235  SoCamera* camera = GetCamera();
236  if(!camera) return;
237
238  // viewer camera setup :
239  camera->position.setValue((float)cameraPosition.x(),
240                               (float)cameraPosition.y(),
241                               (float)cameraPosition.z());
242
243  SbVec3f sbTarget((float)target.x(),
244                   (float)target.y(),
245                   (float)target.z());
246  SbVec3f sbUp((float)up.x(),
247               (float)up.y(),
248               (float)up.z());
249  sbUp.normalize();
250  // Need Coin's camera->pointAt(sbTarget,sbUp); not in the SGI API
251  // Stole Coin's code...
252  pointAt(camera,sbTarget,sbUp);
253
254  //camera->height.setValue(10);
255  //camera->nearDistance.setValue((float)pnear);
256  //camera->farDistance.setValue((float)pfar);
257  //camera->focalDistance.setValue((float)cameraDistance);
258
259  if(camera->isOfType(SoOrthographicCamera::getClassTypeId())) {
260    if (fVP.GetFieldHalfAngle() == 0.) {
261      //FIXME : ((SoOrthographicCamera*)camera)->height.setValue();
262      //FIXME : (Don't think we have to do that.)
263    } else {
264      //FIXME : Have to set a perspective camera !
265      //FIXME : viewer->setCameraType(SoPerspectiveCamera::getClassTypeId())
266      //FIXME : ((SoPerspectiveCamera*)camera)->heightAngle.setValue
267      //FIXME :   (2.*fVP.GetFieldHalfAngle());
268    }
269  } else if(camera->isOfType(SoPerspectiveCamera::getClassTypeId())) {
270    if (fVP.GetFieldHalfAngle() == 0.) {
271      //FIXME : Have to set an orthographic camera !
272      //FIXME : viewer->setCameraType(SoOrthographicCamera::getClassTypeId())
273    } else {
274      //FIXME : ((SoPerspectiveCamera*)camera)->heightAngle.setValue
275      //FIXME :   (2.*fVP.GetFieldHalfAngle());
276    }
277  }
278}
279
280//COIN_FUNCTION_EXTENSION
281void
282G4OpenInventorViewer::pointAt(SoCamera* camera,const SbVec3f & targetpoint, const SbVec3f & upvector)
283{
284  SbVec3f dir = targetpoint - camera->position.getValue();
285  if (dir.normalize() == 0.0f) return;
286  lookAt(camera,dir, upvector);
287}
288
289//COIN_FUNCTION
290// Private method that calculates a new orientation based on camera
291// direction and camera up vector. Vectors must be unit length.
292void
293G4OpenInventorViewer::lookAt(SoCamera* camera,const SbVec3f & dir, const SbVec3f & up)
294{
295  SbVec3f z = -dir;
296  SbVec3f y = up;
297  SbVec3f x = y.cross(z);
298
299  // recompute y to create a valid coordinate system
300  y = z.cross(x);
301
302  // normalize x and y to create an orthonormal coord system
303  y.normalize();
304  x.normalize();
305
306  // create a rotation matrix
307  SbMatrix rot = SbMatrix::identity();
308  rot[0][0] = x[0];
309  rot[0][1] = x[1];
310  rot[0][2] = x[2];
311
312  rot[1][0] = y[0];
313  rot[1][1] = y[1];
314  rot[1][2] = y[2];
315
316  rot[2][0] = z[0];
317  rot[2][1] = z[1];
318  rot[2][2] = z[2];
319
320  camera->orientation.setValue(SbRotation(rot));
321}
322
323void
324G4OpenInventorViewer::lookedAt(SoCamera* camera,SbVec3f & dir, SbVec3f & up)
325{
326  SbRotation rot = camera->orientation.getValue();
327  SbMatrix mrot; rot.getValue(mrot);
328
329  SbVec3f x, y, z;
330
331  // create a rotation matrix
332  x[0] = mrot[0][0];
333  x[1] = mrot[0][1];
334  x[2] = mrot[0][2];
335
336  y[0] = mrot[1][0];
337  y[1] = mrot[1][1];
338  y[2] = mrot[1][2];
339
340  z[0] = mrot[2][0];
341  z[1] = mrot[2][1];
342  z[2] = mrot[2][2];
343
344  dir = -z;
345  dir.normalize();
346  up = SbVec3f(0.f,1.f,0.f);  // Choose y-axis if possible.
347  if (std::abs(up.dot(z)) > 1.e-6) {
348    up = y;
349    up.normalize();
350  }
351}
352
353void G4OpenInventorViewer::DrawView () {
354  //G4cout << "debug Iv::DrawViewer " <<G4endl;
355  if (!fNeedKernelVisit) KernelVisitDecision();
356  ProcessView();
357  FinishView();
358}
359
360void G4OpenInventorViewer::ShowView () {
361  fInteractorManager -> SecondaryLoop ();
362}
363
364void G4OpenInventorViewer::GroupCameraSensorCB(void* aThis,SoSensor* aSensor){
365  G4OpenInventorViewer* This = (G4OpenInventorViewer*)aThis;
366
367  SoNode* node = ((SoNodeSensor*)aSensor)->getTriggerNode();
368  //printf("debug : GroupCameraSensorCB %s\n",
369  //node->getTypeId().getName().getString());
370
371  if(node->isOfType(SoCamera::getClassTypeId())) {
372    // Viewer had changed the camera type,
373    // attach the fCameraSensor to the new camera.
374    SoCamera* camera = (SoCamera*)node;
375    This->fCameraSensor->detach();
376    This->fCameraSensor->attach(camera);
377  }
378
379}
380
381void G4OpenInventorViewer::CameraSensorCB(void* aThis,SoSensor* aSensor) {
382  G4OpenInventorViewer* This = (G4OpenInventorViewer*)aThis;
383
384  //printf("debug : CameraSensorCB\n");
385
386  SoNode* node = ((SoNodeSensor*)aSensor)->getTriggerNode();
387
388  if(node->isOfType(SoCamera::getClassTypeId())) {
389    SoCamera* camera = (SoCamera*)node;
390
391    SbVec3f direction, up;
392    lookedAt(camera,direction, up);
393    This->fVP.SetViewpointDirection
394      (G4Vector3D(-direction[0],-direction[1],-direction[2]));
395    This->fVP.SetUpVector(G4Vector3D(up[0],up[1],up[2]));
396
397    SbVec3f pos = camera->position.getValue();
398    SbVec3f target = pos + direction * camera->focalDistance.getValue();
399
400    This->fVP.SetCurrentTargetPoint(G4Point3D(target[0],target[1],target[2]));
401  }
402}
403
404void G4OpenInventorViewer::SelectionCB(
405 void* aThis
406,SoPath* aPath
407)
408{
409  G4OpenInventorViewer* This = (G4OpenInventorViewer*)aThis;
410  SoNode* node = ((SoFullPath*)aPath)->getTail();
411  G4AttHolder* attHolder = dynamic_cast<G4AttHolder*>(node);
412  if(attHolder && attHolder->GetAttDefs().size()) {
413    for (size_t i = 0; i < attHolder->GetAttDefs().size(); ++i) {
414      G4cout << G4AttCheck(attHolder->GetAttValues()[i],
415                           attHolder->GetAttDefs()[i]);
416    }
417  } else {
418    G4String name((char*)node->getName().getString());
419    G4String cls((char*)node->getTypeId().getName().getString());
420    G4cout << "SoNode : " << node
421           << " SoType : " << cls
422           << " name : " << name
423           << G4endl;
424    G4cout << "No attributes attached." << G4endl;
425  }
426  /*FIXME : to explore (need different button - this is used for picking.
427  if(node->isOfType(Geant4_SoPolyhedron::getClassTypeId())) {
428    Geant4_SoPolyhedron* polyhedron = (Geant4_SoPolyhedron*)node;
429    if(polyhedron->solid.getValue()==FALSE)
430      polyhedron->solid.setValue(TRUE);
431    else
432      polyhedron->solid.setValue(FALSE);
433  }*/
434  This->fSoSelection->deselectAll();
435}
436/*
437void G4OpenInventorViewer::DeselectionCB(
438 void* aThis
439,SoPath* aPath
440)
441{
442  //G4OpenInventorViewer* This = (G4OpenInventorViewer*)aThis;
443  G4String name((char*)aPath->getTail()->getTypeId().getName().getString());
444  G4cout << "Deselect : " << name << G4endl;
445}
446*/
447
448void G4OpenInventorViewer::DrawDetector() {
449  /* Replace this... - JA
450  // DrawView does a ClearStore. Do not clear the transient store :
451  SoSeparator* tmp = fG4OpenInventorSceneHandler.fTransientRoot;
452  fG4OpenInventorSceneHandler.fTransientRoot = new SoSeparator;
453  if (!fNeedKernelVisit) KernelVisitDecision();
454  ProcessView();
455  fG4OpenInventorSceneHandler.fTransientRoot->unref();
456  fG4OpenInventorSceneHandler.fTransientRoot = tmp;
457  */
458  // ...by this... - JA
459  DrawView();
460}
461
462//////////////////////////////////////////////////////////////////////////////
463/// Menu items callbacks /////////////////////////////////////////////////////
464//////////////////////////////////////////////////////////////////////////////
465
466void G4OpenInventorViewer::Escape(){
467  G4cout << "Escape..." <<G4endl;
468  fInteractorManager->RequireExitSecondaryLoop (OIV_EXIT_CODE);
469}
470
471void G4OpenInventorViewer::WritePostScript(const G4String& aFile) {
472  if(!fGL2PSAction) return;
473  fGL2PSAction->setFileName(aFile.c_str());
474  G4cout << "Produce " << aFile << "..." << G4endl;
475  fGL2PSAction->enableFileWriting();
476  ViewerRender();
477  fGL2PSAction->disableFileWriting();
478}
479
480void G4OpenInventorViewer::WritePixmapPostScript(const G4String& aFile) {
481  fSoImageWriter->fileName.setValue(aFile.c_str());
482  //imageWriter->format.setValue(SoImageWriter::POST_SCRIPT);
483  fSoImageWriter->enable();
484  ViewerRender();
485  fSoImageWriter->disable();
486  if(fSoImageWriter->getStatus()) {
487    G4cout << G4String(fSoImageWriter->fileName.getValue().getString())
488           << " produced."
489           << G4endl;
490  } else {
491    G4cout << G4String(fSoImageWriter->fileName.getValue().getString())
492           << " not produced."
493           << G4endl;
494  }
495
496
497void G4OpenInventorViewer::WriteInventor(const G4String& aFile) {
498  G4cout << "Produce " << aFile << "..." << G4endl;
499
500  SbBool genAlternateRep = TRUE;
501  //SbBool binary = FALSE;
502  SbBool binary = TRUE;
503  SoAlternateRepAction alternateRepAction;
504  if(genAlternateRep==TRUE) {
505    alternateRepAction.setGenerate(TRUE); //Clear alternate reps.
506    alternateRepAction.apply(fSoSelection);
507  }
508
509  SoWriteAction writeAction;
510  writeAction.getOutput()->openFile(aFile.c_str());
511  writeAction.getOutput()->setBinary(binary);
512  writeAction.apply(fSoSelection);
513  writeAction.getOutput()->closeFile();
514
515  if(genAlternateRep==TRUE) {
516    alternateRepAction.setGenerate(FALSE); //Clear alternate reps.
517    alternateRepAction.apply(fSoSelection);
518  }
519
520
521
522}
523
524struct Counter {
525 int fTriangles;
526 int fLineSegments;
527 int fPoints;
528};
529
530static void CountTrianglesCB(
531 void* userData
532,SoCallbackAction*
533,const SoPrimitiveVertex*
534,const SoPrimitiveVertex*,
535const SoPrimitiveVertex*)
536{
537  Counter* counter = (Counter*)userData;
538  counter->fTriangles++;
539}
540
541static void CountLineSegmentsCB(
542 void* userData
543,SoCallbackAction*
544,const SoPrimitiveVertex*
545,const SoPrimitiveVertex*)
546{
547  Counter* counter = (Counter*)userData;
548  counter->fLineSegments++;
549}
550
551static void CountPointsCB(
552 void* userData
553,SoCallbackAction*
554,const SoPrimitiveVertex*)
555{
556  Counter* counter = (Counter*)userData;
557  counter->fPoints++;
558}
559
560void G4OpenInventorViewer::SceneGraphStatistics() {
561  Counter counter;
562  counter.fTriangles = 0;
563  counter.fLineSegments = 0;
564  counter.fPoints = 0;
565
566  SoCallbackAction callbackAction;
567  callbackAction.addTriangleCallback
568    (SoShape::getClassTypeId(),CountTrianglesCB,(void*)&counter);
569  callbackAction.addLineSegmentCallback
570    (SoShape::getClassTypeId(),CountLineSegmentsCB,(void*)&counter);
571  callbackAction.addPointCallback
572    (SoShape::getClassTypeId(),CountPointsCB,(void*)&counter);
573  callbackAction.apply(fSoSelection);
574
575  SoCounterAction counterAction;
576  counterAction.apply(fSoSelection);
577  int nodes = counterAction.getCount();
578
579  counterAction.setLookFor(SoCounterAction::TYPE);
580  counterAction.setType(SoShape::getClassTypeId());
581  counterAction.apply(fSoSelection);
582  int shapes = counterAction.getCount();
583
584  G4cout << "Number of triangles : " << counter.fTriangles << G4endl;
585  G4cout << "Number of line segments : " << counter.fLineSegments << G4endl;
586  G4cout << "Number of points : " << counter.fPoints << G4endl;
587  G4cout << "Number of nodes : " << nodes << G4endl;
588  G4cout << "Number of shapes : " << shapes << G4endl;
589}
590
591void G4OpenInventorViewer::EraseDetector() {
592  fG4OpenInventorSceneHandler.fDetectorRoot->removeAllChildren();
593}
594void G4OpenInventorViewer::EraseEvent() {
595  fG4OpenInventorSceneHandler.fTransientRoot->removeAllChildren();
596}
597
598void G4OpenInventorViewer::SetPreviewAndFull() {
599  fG4OpenInventorSceneHandler.fPreviewAndFull = true;
600
601  NeedKernelVisit();
602  DrawDetector();
603}
604
605void G4OpenInventorViewer::SetPreview() {
606  fG4OpenInventorSceneHandler.fPreviewAndFull = false;
607
608  NeedKernelVisit();
609  DrawDetector();
610}
611
612// When ViewParameter <-> SoCamera mapping ready
613// uncomment the below
614//#define USE_SET_VIEW
615
616void G4OpenInventorViewer::SetSolid() {
617  G4ViewParameters vp = GetViewParameters();
618  G4ViewParameters::DrawingStyle existingStyle = vp.GetDrawingStyle();
619  //From G4VisCommandsViewerSet : /vis/viewer/set/style solid.
620  switch (existingStyle) {
621  case G4ViewParameters::wireframe:
622    vp.SetDrawingStyle(G4ViewParameters::hsr);
623    break;
624  case G4ViewParameters::hlr:
625    vp.SetDrawingStyle(G4ViewParameters::hlhsr);
626    break;
627  case G4ViewParameters::hsr:
628    break;
629  case G4ViewParameters::hlhsr:
630    break;
631  }
632  SetViewParameters(vp);
633  DrawDetector();
634}
635void G4OpenInventorViewer::SetWireFrame() {
636  G4ViewParameters vp = GetViewParameters();
637  G4ViewParameters::DrawingStyle existingStyle = vp.GetDrawingStyle();
638  switch (existingStyle) {
639  case G4ViewParameters::wireframe:
640    break;
641  case G4ViewParameters::hlr:
642    break;
643  case G4ViewParameters::hsr:
644    vp.SetDrawingStyle(G4ViewParameters::wireframe);
645    break;
646  case G4ViewParameters::hlhsr:
647    vp.SetDrawingStyle(G4ViewParameters::hlr);
648    break;
649  }
650  SetViewParameters(vp);
651  DrawDetector();
652}
653
654
655void G4OpenInventorViewer::SetReducedWireFrame(bool aValue) {
656  G4ViewParameters vp = GetViewParameters();
657
658  // Set the wire frame kind :
659  vp.SetAuxEdgeVisible(!aValue);
660
661  // Set wire frame :
662  G4ViewParameters::DrawingStyle existingStyle = vp.GetDrawingStyle();
663  switch (existingStyle) {
664  case G4ViewParameters::wireframe:
665    break;
666  case G4ViewParameters::hlr:
667    break;
668  case G4ViewParameters::hsr:
669    vp.SetDrawingStyle(G4ViewParameters::wireframe);
670    break;
671  case G4ViewParameters::hlhsr:
672    vp.SetDrawingStyle(G4ViewParameters::hlr);
673    break;
674  }
675  SetViewParameters(vp);
676  NeedKernelVisit(); // Just in case it was alread in wire framw.
677  DrawDetector();
678}
679
680void G4OpenInventorViewer::UpdateScene() {
681  /* Replace this... - JA
682  fG4OpenInventorSceneHandler.ClearStore();
683  ClearView();
684  if (!fNeedKernelVisit) KernelVisitDecision();
685  ProcessView();
686  ShowView();
687  */
688  // ...by this - JA
689  NeedKernelVisit();
690  DrawView();
691}
692G4String G4OpenInventorViewer::Help(const G4String& aTopic) {
693  if(aTopic=="controls") {
694    return G4String("\
695Controls on an Inventor examiner viewer are :\n\
696- in picking mode (cursor is the upper left arrow)\n\
697  Ctrl + pick a volume : see daughters.\n\
698  Shift + pick a volume : see mother.\n\
699- in viewing mode (cursor is the hand)\n\
700  Left-button + pointer move : rotate.\n\
701  Ctrl+Left-button + pointer move : pan.\n\
702  Ctrl+Shift+Left-button + pointer move : scale.\n\
703  Middle-button + pointer move : pan.\n\
704  Right-button : popup menu.\n");
705  } else {
706    return "";
707  }
708}
709
710#endif
Note: See TracBrowser for help on using the repository browser.