About this blog

Welcome to Ha Le's Work and Research Blog. This page contains information and experience that I've collected during my college's years and other work experience. The topics included are Software development (C++ mainly), Robotics Technology and other related fields.

Search This Blog

Saturday, February 20, 2010

Viewer structure in OpenCascade, integrated with Qt4


When designing a CAD software with OCC and Qt, prob the first thing you would be looking at is creating a View of OCC in a Qt Widget. This allow you to control the view by the buttons and functions provided by Qt while the contents of the display and the selecting functions are controlled by OCC Classes.


This post will explore the structure of how the integration can be realized and used effectively. The following method is based on OCC Tutorial program, with modifications to adapt the use of Qt Designer, fixing incompatibility bugs when compiled with Qt4.6.1.

Above you can find the structure of the View. I'll explain the procedure of creating an object and putting it in the context and other options below:

1. To display an object, the object has to be an AIS_InteractiveObject, most commonly an AIS_Shape. This can be created by appropriate TopoDS_ objects (typically TopoDS_Shape). These are created from basic geometry (Geom_Curve etc) by BRepBuilderAPI_ functions.
Ex:

Handle(Geom_CartesianPoint) aPoint = new Geom_CartesianPoint(-10,-20,-30);
Handle(AIS_Point) AISVertex = new AIS_Point(aPoint);
getContext()->Display(AISVertex);
You should spend time reading OCC Documentation about the above packages to have a full view of what functions they have to offer.

2. By default whey Display(AIS_InteractiveObject) is used directly, the object is displayed in Neutral Point Context (which means the base Context), where (in general) you only can select the object as whole (i.e. cannot select the edges, vertices of the object separately). To do that, follow the following procedure

  • Create a AIS_InteractiveObject
TopoDS_Shape myTestBox = MakeSimpleBox(100,200,50); Handle(AIS_Shape) AISBox=new AIS_Shape(myTestBox);
  • Create New Local Context (read AIS_InteractiveContext for detail)

getContext()->OpenLocalContext(Standard_True,Standard_True);
  • Display the object with option of allowing decomposition, update viewer, selection mode doesn't matter
getContext()->Display(AISBox,AIS_Shaded,0,Standard_True,Standard_True);
  • Activate the selection mode you want to use
getContext()->ActivateStandardMode(TopAbs_VERTEX);
getContext()->ActivateStandardMode(TopAbs_EDGE);
//getContext()->ActivateStandardMode(TopAbs_WIRE);
//getContext()->ActivateStandardMode(TopAbs_FACE);
getContext()->ActivateStandardMode(TopAbs_SOLID);
  • Note that the selection are prioritized, Vertex>Edeg>Wire>Face>Solid.
I kept the post short but happy to answer questions regarding the matter.

No comments:

Post a Comment