PDA

View Full Version : Combining OpenCascade into a Qt4 QtCreator application



tandrews
28th September 2013, 12:39
Hi,

Can anyone show me how to render/paint/display an object created by opencascade?

I have a very simple functional piece of opencascade code that creates a 3D cylinder:



#include <BRepPrimAPI_MakeCylinder.hxx>
#include <gp_Ax2.hxx>
#include <gp_Pnt.hxx>
#include <TopoDS.hxx>
#include <AIS_Shape.hxx>

TopoDS_Shape MakeCylinder(const Standard_Real radius , const Standard_Real length)
{

// Create coordinates & geometry
gp_Pnt origin(0 , 0 , 0);
gp_Dir direction = gp::DZ();
gp_Ax2 axis(origin , direction);

// Create a cylinder
BRepPrimAPI_MakeCylinder cylinder(axis , radius , length);
TopoDS_Shape shape = cylinder.Shape();

return shape;
}


I have created an empty widget application using qtcreator, and that has generated main.cpp, widget.cpp, widget.h, and widget.ui:

9641



#include <QApplication>
#include "widget.h"

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();

return a.exec();
}


and



#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
}

Widget::~Widget()
{
delete ui;
}


To call my piece of opencascade code I have changed 'Widget' to this:



Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);

// I added this:
QApplication::setOverrideCursor( Qt::WaitCursor );
TopoDS_Shape aCylinder = MakeCylinder(50,400);
Handle(AIS_Shape) AISBottle = new AIS_Shape(aCylinder);
QApplication::restoreOverrideCursor();
// Now what?
}


As you can see I still need to display my image somehow? This would appear to be such a simple thing to do, but I am completely new to Qt and opencascade, so the tutorial example at the opencascade website goes totally over my head.
Please can someone help me?

I am currently using Qt Creator version 2.5.0 on Debian. The opencascade version in Debian is based on opencascade 6.5.2, and I think Qt is version 4.8.2.

Many thanks!
Thomas

eryar
10th October 2014, 16:28
Hi Thomas,

I think you can refer the Qt samples in the samples folder of OpenCASCADE.

Or you can refer to the following website:
http://www.opencascade.org/org/forum/thread_25208/?forum=5

Regards,
Xing