how to bridge selected face and the properties

Hi all,

I need your suggestion. I have a question related to bridging or accessing properties (Edge or Vertex) after selecting face.

void GetSelectedFaces()

{

   const Handle(AIS_InteractiveContext)& ctx = ...; //my AIS

   ctx->InitSelected();

  while (ctx->MoreSelected() )

  {

     TopoDS_Shape sh = ctx->SelectedShape();

     ctx->NextSelected();

  }

}

How do I access selected face's properties (such as: Edge or Vertex)?

I have tried to downcast, but still not working.

Handle (TopoDS_Face) face = Handle (TopoDS_Face)::DownCast(sh.TShape());

 

Thanks.

 

Daniel Neander's picture

Try this

...

void AssemblyWidget::test23()

{
    context->InitSelected();
    if (context->MoreSelected()) {
        const TopoDS_Shape& aSelShape = context->SelectedShape();
        if (aSelShape.ShapeType() == TopAbs_FACE) {
            // Get list of edges
            TopTools_IndexedMapOfShape edgeMap;
            TopExp::MapShapes(aSelShape,TopAbs_EDGE, edgeMap);
            Standard_Integer edgeCount = edgeMap.Extent();
            qDebug() <<  "Number of edges: " + QString::number(edgeCount);

            // Loop through each edge
            for(int i = 1; i <= edgeMap.Extent(); i++) {
                const TopoDS_Edge& edge = TopoDS::Edge(edgeMap(i));
                TopoDS_Vertex vert1, vert2;
                TopExp::Vertices(edge, vert1, vert2);
                gp_Pnt point1 = BRep_Tool::Pnt(vert1);
                gp_Pnt point2 = BRep_Tool::Pnt(vert2);
                qDebug() << "Edge " + QString::number(i)
                            + " Start = " + QString::number(point1.X()) + ", " + QString::number(point1.Y()) + ", " + QString::number(point1.Z())
                            + " End = " + QString::number(point2.X()) + ", " + QString::number(point2.Y()) + ", " + QString::number(point2.Z());
            }
        }
    }
}

...

rivai 99's picture

Thanks for your suggestion.

I have still couple questions. In this case, I selected a cylindrical face (see attachment). Then I want to access cylindrical face's properties (e.g. EDGE), it means straight edge - circular edge/arc - straight edge - circular edge/arc.

How can I directly access those edges? or do I have to do EdgeFilter for accessing circular edge/arc?

THanks.

Attachments: 
Daniel Neander's picture

For more elaborate information on your edge, you want the Geom_Curve

                ...
                Standard_Real f,l;
                Handle(Geom_Curve) curve = BRep_Tool::Curve (edge,f,l);
                if (curve->IsKind(STANDARD_TYPE(Geom_Circle))) { // Geom_Line, Geom_TrimmedCurve and so on
                    gp_Circ circle = Handle(Geom_Circle)::DownCast(curve)->Circ();
                    gp_Pnt center = circle.Location ();
                    qDebug() << "Radius: " + QString::number(circle.Radius());
                    qDebug() << "Centre: " + QString::number(center.X()) + ", " + QString::number(center.Y()) + ", " + QString::number(center.Z());
                }
                ...

Hope that helps ;)