2 #include <TestViewer.h>
3 #include <OCCViewer_ViewManager.h>
4 #include <OCCViewer_ViewModel.h>
5 #include <OCCViewer_ViewWindow.h>
6 #include <AIS_InteractiveContext.hxx>
7 #include <AIS_Shape.hxx>
8 #include <TopoDS_Iterator.hxx>
11 OCCViewer_ViewManager* TestViewer::myViewManager = 0;
12 OCCViewer_ViewWindow* TestViewer::myViewWindow = 0;
14 OCCViewer_ViewManager* TestViewer::viewManager()
19 myViewManager = new OCCViewer_ViewManager( 0, 0 );
20 OCCViewer_Viewer* aViewer = new OCCViewer_Viewer( true );
22 aViewer->setTrihedronSize( 100, true );
23 aViewer->setInteractionStyle( 0 );
24 aViewer->setZoomingStyle( 1 );
26 myViewManager->setViewModel( aViewer );
27 myViewWindow = dynamic_cast<OCCViewer_ViewWindow*>( myViewManager->createViewWindow() );
32 OCCViewer_Viewer* TestViewer::viewer()
34 return dynamic_cast<OCCViewer_Viewer*>( viewManager()->getViewModel() );
37 OCCViewer_ViewWindow* TestViewer::viewWindow()
39 viewManager(); //to create the view if it was not created earlier
43 Handle(AIS_InteractiveContext) context()
45 return TestViewer::viewer()->getAISContext();
48 void TestViewer::show( const TopoDS_Shape& theShape, const QColor& theColor, int theMode )
50 QColor aColor = theColor;
51 if( !aColor.isValid() )
54 int aHue = rand()%255;
55 aColor = QColor::fromHsl( aHue, 255, 128 );
58 double r = aColor.red() / 255.0;
59 double g = aColor.green() / 255.0;
60 double b = aColor.blue() / 255.0;
62 Handle(AIS_Shape) aShape = new AIS_Shape( theShape );
63 aShape->SetMaterial( Graphic3d_NOM_PLASTIC );
64 aShape->SetColor( Quantity_Color( r, g, b, Quantity_TOC_RGB ) );
65 context()->Display( aShape, theMode, 0, Standard_False );
68 void TestViewer::show( const TopoDS_Shape& theShape, int theMode, bool isFitAll )
70 context()->EraseAll();
72 if( theShape.ShapeType()==TopAbs_COMPOUND )
74 TopoDS_Iterator anIt( theShape );
75 for( ; anIt.More(); anIt.Next() )
76 show( anIt.Value(), QColor(), theMode );
79 show( theShape, QColor(), theMode );
81 viewWindow()->onTopView();
82 viewWindow()->onFitAll();
85 void TestViewer::dump( const TopoDS_Shape& theShape, int theMode, const QString& theName )
87 show( theShape, theMode, true );
88 QImage anImage = viewWindow()->dumpView();
90 QString aPath = QDir::tempPath() + "/" + theName + ".png";
91 anImage.save( aPath );