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

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

geant4 tag 9.4

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