source: trunk/source/visualization/OpenInventor/src/G4OpenInventorViewer.cc@ 849

Last change on this file since 849 was 773, checked in by garnier, 18 years ago

r782@wl-72126: garnier | 2008-04-17 11:28:38 +0200
mise à jour

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