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

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

en test de gl2ps. Problemes de libraries

  • 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: HEAD $
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"#include "G4AttDef.hh"
53#include "G4AttCheck.hh"
54#include "G4AttHolder.hh"
55
56G4OpenInventorViewer::G4OpenInventorViewer(
57 G4OpenInventorSceneHandler& sceneHandler
58,const G4String& name)
59:G4VViewer(sceneHandler, sceneHandler.IncrementViewCount(), name)
60,fG4OpenInventorSceneHandler(sceneHandler)
61,fInteractorManager(0)
62,fSoSelection(0)
63,fSoImageWriter(0)
64,fGL2PSAction(0) //To be set be suclass.
65,fGroupCameraSensor(0)
66,fCameraSensor(0)
67{
68 fNeedKernelVisit = true; //?? Temporary, until KernelVisitDecision fixed.
69
70 fVP.SetAutoRefresh(true);
71 fDefaultVP.SetAutoRefresh(true);
72 fVP.SetPicking(true);
73 fDefaultVP.SetPicking(true);
74
75 //FIXME : G.Barrand : not convinced that we have to rm culling.
76 // For viewing of all objects by default :
77 //fDefaultVP.SetCulling(false);
78 //fVP.SetCulling(false);
79
80 fInteractorManager =
81 ((G4OpenInventor*)fG4OpenInventorSceneHandler.GetGraphicsSystem())->
82 GetInteractorManager();
83
84 // Main user scene graph root sent to the viewers.
85 fSoSelection = new SoSelection;
86 fSoSelection->ref();
87 fSoSelection->addSelectionCallback(SelectionCB,this);
88 //fSoSelection->addDeselectionCallback(DeselectionCB,this);
89 fSoSelection->policy = SoSelection::SINGLE;
90
91 SoGroup* group = new SoGroup;
92 fSoSelection->addChild(group);
93
94 // Have a camera under fSoSelection in order
95 // that the below SceneGraphSensor be notifed
96 // when the viewer changes the camera type.
97 // But we put the camera under a SoGroup so that
98 // the SceneGraphSensor be not triggered at each change
99 // under the fG4OpenInventorSceneHandler.fRoot.
100 SoOrthographicCamera* camera = new SoOrthographicCamera;
101 camera->viewportMapping.setValue(SoCamera::ADJUST_CAMERA);
102 //camera->aspectRatio.setValue(10);
103 camera->position.setValue(0,0,10);
104 camera->orientation.setValue(SbRotation(SbVec3f(0,1,0),0));
105 camera->height.setValue(10);
106 camera->nearDistance.setValue(1);
107 camera->farDistance.setValue(100);
108 camera->focalDistance.setValue(10);
109 group->addChild(camera);
110
111 {SoInput soInput;
112 if(soInput.openFile("g4view.iv",TRUE)) {
113 SoSeparator* separator = SoDB::readAll(&soInput);
114 if(separator) fSoSelection->addChild(separator);
115 }}
116
117 fSoSelection->addChild(fG4OpenInventorSceneHandler.fRoot);
118
119 // SoImageWriter should be the last.
120 fSoImageWriter = new SoImageWriter();
121 fSoImageWriter->fileName.setValue("g4out.ps");
122 fSoSelection->addChild(fSoImageWriter);
123
124 // Sensors :
125 // To detect that the viewer had changed the camera type :
126 fGroupCameraSensor = new SoNodeSensor(GroupCameraSensorCB,this);
127 fGroupCameraSensor->setPriority(0);//Needed in order to do getTriggerNode()
128 fGroupCameraSensor->attach(group);
129
130 fCameraSensor = new SoNodeSensor(CameraSensorCB,this);
131 fCameraSensor->setPriority(0);//Needed in order to do getTriggerNode()
132}
133
134G4OpenInventorViewer::~G4OpenInventorViewer () {
135 fCameraSensor->detach();
136 delete fCameraSensor;
137 fGroupCameraSensor->detach();
138 delete fGroupCameraSensor;
139 fSoSelection->unref();
140}
141
142void G4OpenInventorViewer::KernelVisitDecision () {
143
144 // If there's a significant difference with the last view parameters
145 // of either the scene handler or this viewer, trigger a rebuild.
146
147 if (
148 //??fG4OpenInventorSceneHandler.fPODLList.size() == 0 ||
149 // We need a test for empty scene graph, such as
150 // staticRoot.size() or something?????????? See temporary fix
151 // in contructor. (John Allison Aug 2001)
152 CompareForKernelVisit(fLastVP)) {
153 NeedKernelVisit ();
154 }
155 fLastVP = fVP;
156}
157
158G4bool G4OpenInventorViewer::CompareForKernelVisit(G4ViewParameters& vp) {
159
160 if (
161 (vp.GetDrawingStyle () != fVP.GetDrawingStyle ()) ||
162 (vp.IsAuxEdgeVisible () != fVP.IsAuxEdgeVisible ()) ||
163 (vp.GetRepStyle () != fVP.GetRepStyle ()) ||
164 (vp.IsCulling () != fVP.IsCulling ()) ||
165 (vp.IsCullingInvisible () != fVP.IsCullingInvisible ()) ||
166 (vp.IsDensityCulling () != fVP.IsDensityCulling ()) ||
167 (vp.IsCullingCovered () != fVP.IsCullingCovered ()) ||
168 (vp.IsSection () != fVP.IsSection ()) ||
169 (vp.IsCutaway () != fVP.IsCutaway ()) ||
170 // This assumes use of generic clipping (sectioning, slicing,
171 // DCUT, cutaway). If a decision is made to implement locally,
172 // this will need changing. See G4OpenGLViewer::SetView,
173 // G4OpenGLStoredViewer.cc::CompareForKernelVisit and
174 // G4OpenGLStoredSceneHander::CreateSection/CutawayPolyhedron.
175 (vp.IsExplode () != fVP.IsExplode ()) ||
176 (vp.GetNoOfSides () != fVP.GetNoOfSides ()) ||
177 (vp.IsMarkerNotHidden () != fVP.IsMarkerNotHidden ()) ||
178 (vp.GetBackgroundColour ()!= fVP.GetBackgroundColour ())||
179 (vp.IsPicking () != fVP.IsPicking ()) ||
180 // Scaling for Open Inventor is done by the scene handler so it
181 // needs a kernel visit. (In this respect, it differs from the
182 // OpenGL drivers, where it's done in SetView.)
183 (vp.GetScaleFactor () != fVP.GetScaleFactor ())
184 )
185 return true;
186
187 if (vp.IsDensityCulling () &&
188 (vp.GetVisibleDensity () != fVP.GetVisibleDensity ()))
189 return true;
190
191 if (vp.IsSection () &&
192 (vp.GetSectionPlane () != fVP.GetSectionPlane ()))
193 return true;
194
195 if (vp.IsCutaway ()) {
196 if (vp.GetCutawayPlanes ().size () !=
197 fVP.GetCutawayPlanes ().size ()) return true;
198 for (size_t i = 0; i < vp.GetCutawayPlanes().size(); ++i)
199 if (vp.GetCutawayPlanes()[i] != fVP.GetCutawayPlanes()[i])
200 return true;
201 }
202
203 if (vp.IsExplode () &&
204 (vp.GetExplodeFactor () != fVP.GetExplodeFactor ()))
205 return true;
206
207 return false;
208}
209
210void G4OpenInventorViewer::ClearView () {
211}
212
213void G4OpenInventorViewer::SetView () {
214
215 // Get G4 camera infos :
216 const G4Point3D target
217 = fSceneHandler.GetScene()->GetStandardTargetPoint()
218 + fVP.GetCurrentTargetPoint ();
219 G4double radius = fSceneHandler.GetScene()->GetExtent().GetExtentRadius();
220 if(radius<=0.) radius = 1.;
221 const G4double cameraDistance = fVP.GetCameraDistance (radius);
222 const G4Vector3D& direction = fVP.GetViewpointDirection().unit();
223 const G4Point3D cameraPosition = target + cameraDistance * direction;
224 //const G4double pnear = fVP.GetNearDistance (cameraDistance, radius);
225 //const G4double pfar = fVP.GetFarDistance (cameraDistance, pnear, radius);
226 const G4Normal3D& up = fVP.GetUpVector ();
227
228/*
229 printf("debug : target : %g %g %g\n",target.x(),
230 target.y(),
231 target.z());
232 printf("debug : dir : %g %g %g\n",direction.x(),
233 direction.y(),
234 direction.z());
235 printf("debug : pos : %g %g %g\n",cameraPosition.x(),
236 cameraPosition.y(),
237 cameraPosition.z());
238 //printf("debug : near %g far %g\n",pnear,pfar);
239*/
240
241 SoCamera* camera = GetCamera();
242 if(!camera) return;
243
244 // viewer camera setup :
245 camera->position.setValue((float)cameraPosition.x(),
246 (float)cameraPosition.y(),
247 (float)cameraPosition.z());
248
249 SbVec3f sbTarget((float)target.x(),
250 (float)target.y(),
251 (float)target.z());
252 SbVec3f sbUp((float)up.x(),
253 (float)up.y(),
254 (float)up.z());
255 sbUp.normalize();
256 // Need Coin's camera->pointAt(sbTarget,sbUp); not in the SGI API
257 // Stole Coin's code...
258 pointAt(camera,sbTarget,sbUp);
259
260 //camera->height.setValue(10);
261 //camera->nearDistance.setValue((float)pnear);
262 //camera->farDistance.setValue((float)pfar);
263 //camera->focalDistance.setValue((float)cameraDistance);
264
265 if(camera->isOfType(SoOrthographicCamera::getClassTypeId())) {
266 if (fVP.GetFieldHalfAngle() == 0.) {
267 //FIXME : ((SoOrthographicCamera*)camera)->height.setValue();
268 //FIXME : (Don't think we have to do that.)
269 } else {
270 //FIXME : Have to set a perspective camera !
271 //FIXME : viewer->setCameraType(SoPerspectiveCamera::getClassTypeId())
272 //FIXME : ((SoPerspectiveCamera*)camera)->heightAngle.setValue
273 //FIXME : (2.*fVP.GetFieldHalfAngle());
274 }
275 } else if(camera->isOfType(SoPerspectiveCamera::getClassTypeId())) {
276 if (fVP.GetFieldHalfAngle() == 0.) {
277 //FIXME : Have to set an orthographic camera !
278 //FIXME : viewer->setCameraType(SoOrthographicCamera::getClassTypeId())
279 } else {
280 //FIXME : ((SoPerspectiveCamera*)camera)->heightAngle.setValue
281 //FIXME : (2.*fVP.GetFieldHalfAngle());
282 }
283 }
284}
285
286//COIN_FUNCTION_EXTENSION
287void
288G4OpenInventorViewer::pointAt(SoCamera* camera,const SbVec3f & targetpoint, const SbVec3f & upvector)
289{
290 SbVec3f dir = targetpoint - camera->position.getValue();
291 if (dir.normalize() == 0.0f) return;
292 lookAt(camera,dir, upvector);
293}
294
295//COIN_FUNCTION
296// Private method that calculates a new orientation based on camera
297// direction and camera up vector. Vectors must be unit length.
298void
299G4OpenInventorViewer::lookAt(SoCamera* camera,const SbVec3f & dir, const SbVec3f & up)
300{
301 SbVec3f z = -dir;
302 SbVec3f y = up;
303 SbVec3f x = y.cross(z);
304
305 // recompute y to create a valid coordinate system
306 y = z.cross(x);
307
308 // normalize x and y to create an orthonormal coord system
309 y.normalize();
310 x.normalize();
311
312 // create a rotation matrix
313 SbMatrix rot = SbMatrix::identity();
314 rot[0][0] = x[0];
315 rot[0][1] = x[1];
316 rot[0][2] = x[2];
317
318 rot[1][0] = y[0];
319 rot[1][1] = y[1];
320 rot[1][2] = y[2];
321
322 rot[2][0] = z[0];
323 rot[2][1] = z[1];
324 rot[2][2] = z[2];
325
326 camera->orientation.setValue(SbRotation(rot));
327}
328
329void
330G4OpenInventorViewer::lookedAt(SoCamera* camera,SbVec3f & dir, SbVec3f & up)
331{
332 SbRotation rot = camera->orientation.getValue();
333 SbMatrix mrot; rot.getValue(mrot);
334
335 SbVec3f x, y, z;
336
337 // create a rotation matrix
338 x[0] = mrot[0][0];
339 x[1] = mrot[0][1];
340 x[2] = mrot[0][2];
341
342 y[0] = mrot[1][0];
343 y[1] = mrot[1][1];
344 y[2] = mrot[1][2];
345
346 z[0] = mrot[2][0];
347 z[1] = mrot[2][1];
348 z[2] = mrot[2][2];
349
350 dir = -z;
351 dir.normalize();
352 up = SbVec3f(0.f,1.f,0.f); // Choose y-axis if possible.
353 if (std::abs(up.dot(z)) > 1.e-6) {
354 up = y;
355 up.normalize();
356 }
357}
358
359void G4OpenInventorViewer::DrawView () {
360 //G4cout << "debug Iv::DrawViewer " <<G4endl;
361 if (!fNeedKernelVisit) KernelVisitDecision();
362 ProcessView();
363 FinishView();
364}
365
366void G4OpenInventorViewer::ShowView () {
367 fInteractorManager -> SecondaryLoop ();
368}
369
370void G4OpenInventorViewer::GroupCameraSensorCB(void* aThis,SoSensor* aSensor){
371 G4OpenInventorViewer* This = (G4OpenInventorViewer*)aThis;
372
373 SoNode* node = ((SoNodeSensor*)aSensor)->getTriggerNode();
374 //printf("debug : GroupCameraSensorCB %s\n",
375 //node->getTypeId().getName().getString());
376
377 if(node->isOfType(SoCamera::getClassTypeId())) {
378 // Viewer had changed the camera type,
379 // attach the fCameraSensor to the new camera.
380 SoCamera* camera = (SoCamera*)node;
381 This->fCameraSensor->detach();
382 This->fCameraSensor->attach(camera);
383 }
384
385}
386
387void G4OpenInventorViewer::CameraSensorCB(void* aThis,SoSensor* aSensor) {
388 G4OpenInventorViewer* This = (G4OpenInventorViewer*)aThis;
389
390 //printf("debug : CameraSensorCB\n");
391
392 SoNode* node = ((SoNodeSensor*)aSensor)->getTriggerNode();
393
394 if(node->isOfType(SoCamera::getClassTypeId())) {
395 SoCamera* camera = (SoCamera*)node;
396
397 SbVec3f direction, up;
398 lookedAt(camera,direction, up);
399 This->fVP.SetViewpointDirection
400 (G4Vector3D(-direction[0],-direction[1],-direction[2]));
401 This->fVP.SetUpVector(G4Vector3D(up[0],up[1],up[2]));
402
403 SbVec3f pos = camera->position.getValue();
404 SbVec3f target = pos + direction * camera->focalDistance.getValue();
405
406 This->fVP.SetCurrentTargetPoint(G4Point3D(target[0],target[1],target[2]));
407 }
408}
409
410void G4OpenInventorViewer::SelectionCB(
411 void* aThis
412,SoPath* aPath
413)
414{
415 G4OpenInventorViewer* This = (G4OpenInventorViewer*)aThis;
416 SoNode* node = ((SoFullPath*)aPath)->getTail();
417 G4AttHolder* attHolder = dynamic_cast<G4AttHolder*>(node);
418 if(attHolder && attHolder->GetAttDefs().size()) {
419 for (size_t i = 0; i < attHolder->GetAttDefs().size(); ++i) {
420 G4cout << G4AttCheck(attHolder->GetAttValues()[i],
421 attHolder->GetAttDefs()[i]);
422 }
423 } else {
424 G4String name((char*)node->getName().getString());
425 G4String cls((char*)node->getTypeId().getName().getString());
426 G4cout << "SoNode : " << node
427 << " SoType : " << cls
428 << " name : " << name
429 << G4endl;
430 G4cout << "No attributes attached." << G4endl;
431 }
432 /*FIXME : to explore (need different button - this is used for picking.
433 if(node->isOfType(Geant4_SoPolyhedron::getClassTypeId())) {
434 Geant4_SoPolyhedron* polyhedron = (Geant4_SoPolyhedron*)node;
435 if(polyhedron->solid.getValue()==FALSE)
436 polyhedron->solid.setValue(TRUE);
437 else
438 polyhedron->solid.setValue(FALSE);
439 }*/
440 This->fSoSelection->deselectAll();
441}
442/*
443void G4OpenInventorViewer::DeselectionCB(
444 void* aThis
445,SoPath* aPath
446)
447{
448 //G4OpenInventorViewer* This = (G4OpenInventorViewer*)aThis;
449 G4String name((char*)aPath->getTail()->getTypeId().getName().getString());
450 G4cout << "Deselect : " << name << G4endl;
451}
452*/
453
454void G4OpenInventorViewer::DrawDetector() {
455 /* Replace this... - JA
456 // DrawView does a ClearStore. Do not clear the transient store :
457 SoSeparator* tmp = fG4OpenInventorSceneHandler.fTransientRoot;
458 fG4OpenInventorSceneHandler.fTransientRoot = new SoSeparator;
459 if (!fNeedKernelVisit) KernelVisitDecision();
460 ProcessView();
461 fG4OpenInventorSceneHandler.fTransientRoot->unref();
462 fG4OpenInventorSceneHandler.fTransientRoot = tmp;
463 */
464 // ...by this... - JA
465 DrawView();
466}
467
468//////////////////////////////////////////////////////////////////////////////
469/// Menu items callbacks /////////////////////////////////////////////////////
470//////////////////////////////////////////////////////////////////////////////
471
472void G4OpenInventorViewer::Escape(){
473 G4cout << "Escape..." <<G4endl;
474 fInteractorManager->RequireExitSecondaryLoop (OIV_EXIT_CODE);
475}
476
477void G4OpenInventorViewer::WritePostScript(const G4String& aFile) {
478 if(!fGL2PSAction) return;
479 fGL2PSAction->setFileName(aFile.c_str());
480 G4cout << "Produce " << aFile << "..." << G4endl;
481 if (fGL2PSAction->enableFileWriting()) {
482 ViewerRender();
483 fGL2PSAction->disableFileWriting();
484 }
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.