Why does AIS module not have AIS_Rectangle ?

Hi, one more question not sure if it gets answered at all, but it's worth a try :

we have many AIS objects - point, circles, ellipses etc, but not rectangles why is that so ?, is there another way to construct AIS_Rectagles and display them ?


Jonathan Greig's picture

You can create an AIS_Shape. The code below is based off of the Tutorial(Qt) MakeBottle function, but stripped down quite a bit. In fact, I do not use the AIS_Point/Line/Circle for any of my shapes. I'm not sure if using a AIS_Shape versus the other classes provides any performance benefits, but so far, it seems to be a solution I like so far that can be adapted many ways. If there is a better way, or any negatives to this approach, I'm all ears, as this is a solution that has worked for me.

void MyClass::MakeRect(const gp_Pnt point1, const gp_Pnt point2)
if(point1.X() == point2.X() || point1.Y() == point2.Y())
{ return; }

//Profile : Define Support Points
gp_Pnt pt1(point1.X(),point1.Y(),point1.Z());
gp_Pnt pt2(point1.X(),point2.Y(),point1.Z());
gp_Pnt pt3(point2.X(),point2.Y(),point1.Z());
gp_Pnt pt4(point2.X(),point1.Y(),point1.Z());

//Profile : Define the Geometry
Handle(Geom_TrimmedCurve) aSegment1 = GC_MakeSegment(pt1, pt2);
Handle(Geom_TrimmedCurve) aSegment2 = GC_MakeSegment(pt2, pt3);
Handle(Geom_TrimmedCurve) aSegment3 = GC_MakeSegment(pt3, pt4);
Handle(Geom_TrimmedCurve) aSegment4 = GC_MakeSegment(pt4, pt1);

//Profile : Define the Topology
TopoDS_Edge aEdge1 = BRepBuilderAPI_MakeEdge(aSegment1);
TopoDS_Edge aEdge2 = BRepBuilderAPI_MakeEdge(aSegment2);
TopoDS_Edge aEdge3 = BRepBuilderAPI_MakeEdge(aSegment3);
TopoDS_Edge aEdge4 = BRepBuilderAPI_MakeEdge(aSegment4);

TopoDS_Wire aWire1 = BRepBuilderAPI_MakeWire(aEdge1, aEdge2 , aEdge3, aEdge4);

TopoDS_Shape aRect=aWire1;
Handle(AIS_Shape) AISRect=new AIS_Shape(aRect);
Quantity_Color color(1.0,1.0,0,Quantity_TOC_RGB);
getContext()->Display(AISRect, false);

Venugopal Gudimetla's picture

jonathan, greatly appreciate it...let me try it out and back and come back to you.

Venugopal Gudimetla's picture

Hi Jonathan, it worked perfectly, that's exactly what I wanted..again thank you very much.