Xw_Window trouble

Hi, my name is Juergen Riegel and try to make a QT Viewer Widget for OpenCasCade. I have some experience with CasCade on NT and tried the same scheme to bind a Xw_Window to a existing Xwindow of a QT Widget. But it didn't work so far. Here's what I did;

In the Application:

// Graphic Device from default ($DISPLAY)

myDevice = new Graphic3d_GraphicDevice("");

// Create a Viewer for this document

TCollection_ExtendedString a3DName("Visu3D");

myViewer = new V3d_Viewer(myDevice, a3DName.ToExtString());

myViewer->SetDefaultLights();

myViewer->SetLightOn();

// Create Interactive Context! myAISContext =new AIS_InteractiveContext(myViewer); // TRIHEDRON

Handle(AIS_Trihedron) aTrihedron;

Handle(Geom_Axis2Placement) aTrihedronAxis=new Geom_Axis2Placement(gp::XOY());

aTrihedron=new AIS_Trihedron(aTrihedronAxis);

myAISContext->Display(aTrihedron);

In the View Widget:

myView = theView;

cout VisualDepth() SetWindow(aWindow);

}catch(Standard_Failure){

cout IsMapped()) aWindow->Map();

myView->Update();

And in myView->SetWindow(aWindow) it get stacked in a Xlib __select() call and never come back!

This behavior is not described in the documentation. Anyone an Idea ?!?!

Francois Lauzon's picture

Hi Juergen. I think I could help you with that. We have been using Qt with Cascade for some time now, on both Unix and NT and it works fine. You will have to create a widget that derive from the QGLWidget (this widget support opengl rendering and deal with all the colormap stuff on unix). The header file for Unix could look like this (sorry for the layout, it is well formatted when I enter it but not when I preview it):

#include #include #include #include

#include

/** This class define a window with 3D opengl support.

*/ class Qt_Window3D : public QGLWidget { Q_OBJECT public:

/** Build a widget. */ Qt_Window3D(QWidget* parent=0, const char* name=0,WFlags f=0) :

QGLWidget(QGLFormat(DoubleBuffer|DepthBuffer|AlphaChannel|DirectRendering),

parent,name,0,f) { // get the rigth graphic device myDevice=new Graphic3d_GraphicDevice("");

// create a x-window myWindow=new Xw_Window(myDevice,winId()); }

/** Access the graphic device on X11. */ const Handle(Graphic3d_GraphicDevice)& GraphicDevice() const { return myDevice; }

/** Access the window on X11. */ const Handle(Xw_Window)& Window() const { return myWindow; }

/** Set the 3d view to associate with the opengl window. */ void SetView(const Handle(V3d_View)& aView) { // set the window for that view myView=aView; myView->SetWindow(myWindow); }

/** Access the 3d view. */ const Handle(V3d_View)& View() const { return myView; }

protected:

/** Update the view when paint event occur. */ virtual void paintEvent ( QPaintEvent * ) { if (!myView.IsNull()) myView->Redraw(); }

/** Update the view when resize event occur. */ virtual void resizeEvent ( QResizeEvent * ) { if (!myView.IsNull()) myView->MustBeResized(); }

private: // device on X11 workstation Handle(Graphic3d_GraphicDevice) myDevice;

// cascade window on X11 Handle(Xw_Window) myWindow;

Handle(V3d_View) myView; };

#endif

and you could create the widget like this:

// create an opengl window Qt_Window3D *aWindow=new Qt_Window3D();

// create a viewer TCollection_ExtendedString Name("Test_Viewer"); TCollection_AsciiString Domain("DBMReflex"); Handle(V3d_Viewer) aViewer=new V3d_Viewer(aWindow->GraphicDevice(),Name.ToExtString(),Domain.ToCString(),1000.0,V3d_XposYnegZpos,Quantity_NOC_BLACK,
V3d_ZBUFFER,V3d_GOURAUD,V3d_WAIT,Standard_True,Standard_True,V3d_TEX_ALL);

// create an ortographic view Handle(V3d_OrthographicView) aView=new V3d_OrthographicView(aViewer);

aWindow->SetView(aView);

and it should work ok. I didn't test this code like that, because we have something a little more complex, but the basic idea is there. You shouldn't have to modify any of the cascade class or Qt class to make it work.

Good luck. Francois.