How to get the selected Face in the viewer

Hi everyone,

I try to get the face selected in an opencascade viewer but i don't know how to do this. When I load a step I add the shape in the context and I activate the face selection like this :

m_aisContext->Activate(m_aisObject, AIS_Shape::SelectionMode(TopAbs_FACE));

This woks, only the face are selectable in the viewer. But finally, when I pick the face I don't kown how to get the information of this face.

The action to pick the face works because the the face is highlight in the viewer but when I check the context the selected face is empty, idem for the owner. Someone know the solution ?

Regards,

Manon

Attachments: 
Benjamin Bihler's picture

Are you using code similar to that one?

if (0 != interactiveContext->NbSelected())
    {
        for (interactiveContext->InitSelected(); interactiveContext->MoreSelected();
                interactiveContext->NextSelected())
        {
            const Handle(AIS_InteractiveObject) object =
                    interactiveContext->SelectedInteractive();
            
            ...
        }
    }

This works here.

Benjamin

Manon Jubert's picture

Thanks for your answer,

Finally I have solved my problem, with interactiveContext->MainSelector()->OnePicked() I get the SelectMgr_EntityOwner under the mouse and it exactly what I need !

Manon

anilkumardudhani_137654's picture

Hi,

could you please share the code.

thanks 

Anilkumar

Manon Jubert's picture

Hi Anil,

I use Qt for the interface, so in the eventFilter function of your widget you need to get your contest and check which face is under you mouse at the moment. I paste my event function :

bool QtController::eventFilter(QEvent* event)

{

   switch (event->type()) {

      case QEvent::MouseButtonPress: {

         auto mouseEvent = static_cast<const QMouseEvent*>(event);

         if (mouseEvent->button() == Qt::LeftButton) {

            // get your context

            const Handle_AIS_InteractiveContext& ctx = m_document->aisInteractiveContext();

            if (ctx->HasDetected() && ctx->MainSelector()->NbPicked() > 0) {

               auto x = ctx->MainSelector()->OnePicked();

              // get the list of entity owner (list which contains all the entity in your context, complete the list at each new object add in the context)

             // example to construct the list of entity owner :  

             // Handle_AIS_InteractiveObject aisObject = new AIS_Shape(myshape);

             // aisContext->Display(aisObject, true);

             // opencascade::handle<SelectMgr_IndexedMapOfOwner> mapEntityOwner;

             // aisContext->EntityOwners( mapEntityOwner, aisObject, AIS_Shape::SelectionMode(TopAbs_FACE));

             // vecGpxEntityOwner.reserve(mapEntityOwner->Extent());

             // for (auto it = mapEntityOwner->cbegin(); it != mapEntityOwner->cend(); ++it)

            //    vecGpxEntityOwner.push_back(std::move(*it));

               std::vector<Handle_SelectMgr_EntityOwner> vecGpxEntityOwner = m_document->vecGpxEntityOwner;

               int cpt = 0;

               for (const Handle_SelectMgr_EntityOwner& owner : vecGpxEntityOwner)

              {

                 if (owner == x)

                {

                   qDebug() << "face picked :: " << cpt;

                  _m_currentFacePicked = cpt;

               }

               cpt++;

            }

         }

         else {

            _m_currentFacePicked = -1;

         }

      return true;

      }

      default: return false;

   } // end switch

   return false;

}

Manon