About the down-conversion of AIS_InteractiveObject to AIS_Shape

sjwa

CAD practitioner
I tried to use the following code to get the AIS_Shape out
But the judgment method confuses me, the return result is not a AIS_Shape
Is there any good solution for this situation?
thank you

//------------------------------------------
Handle(AIS_Shape) anAIS_Shape = Handle(AIS_Shape)::DownCast(gfxObject);
if (anAIS_Shape.IsNull()) {
std::cout << "anAIS_Shape is null" << std::endl;
}
if (gfxObject->IsKind(STANDARD_TYPE(AIS_Shape)))
{
std::cout << "gfxObject is shape" << std::endl;
Handle(AIS_Shape) anAIS_Shape = Handle(AIS_Shape)::DownCast(gfxObject);
}
else
{
std::cout << "gfxObject not shape" << std::endl;
}
//------------------------------------------

1661160290657.png
 

JSlyadne

Administrator
Staff member
I tried to use the following code to get the AIS_Shape out
But the judgment method confuses me, the return result is not a AIS_Shape
Is there any good solution for this situation?
thank you

//------------------------------------------
Handle(AIS_Shape) anAIS_Shape = Handle(AIS_Shape)::DownCast(gfxObject);
if (anAIS_Shape.IsNull()) {
std::cout << "anAIS_Shape is null" << std::endl;
}
if (gfxObject->IsKind(STANDARD_TYPE(AIS_Shape)))
{
std::cout << "gfxObject is shape" << std::endl;
Handle(AIS_Shape) anAIS_Shape = Handle(AIS_Shape)::DownCast(gfxObject);
}
else
{
std::cout << "gfxObject not shape" << std::endl;
}
//------------------------------------------

View attachment 365
Let's look at how gfxObject was constructed?!
 

sjwa

CAD practitioner
Let's look at how gfxObject was constructed?!
void GraphicsScene::toggleOwnerSelection(const GraphicsOwnerPtr& gfxOwner)
{
std::cout << "GraphicsScene::toggleOwnerSelection" << std::endl;
auto gfxObject = GraphicsObjectPtr::DownCast(
gfxOwner ? gfxOwner->Selectable() : Handle_SelectMgr_SelectableObject());
if (GraphicsUtils::AisObject_isVisible(gfxObject))
d->m_aisContext->AddOrRemoveSelected(gfxOwner, false);
//------------------------------------------
if (gfxObject->IsKind(STANDARD_TYPE(AIS_Shape)))
{
std::cout << "gfxObject is shape" << std::endl;
Handle(AIS_Shape) anAIS_Shape = Handle(AIS_Shape)::DownCast(gfxObject);
}
else
{
std::cout << "gfxObject not shape" << std::endl;
}
//------------------------------------------
}


The premise of the above procedure is:
using GraphicsOwnerPtr = Handle(SelectMgr_EntityOwner);
using GraphicsObjectPtr = Handle(AIS_InteractiveObject);


Below is a screenshot of my run:
1661162328459.png

1661162298217.png
why?
 

JSlyadne

Administrator
Staff member
void GraphicsScene::toggleOwnerSelection(const GraphicsOwnerPtr& gfxOwner)
{
std::cout << "GraphicsScene::toggleOwnerSelection" << std::endl;
auto gfxObject = GraphicsObjectPtr::DownCast(
gfxOwner ? gfxOwner->Selectable() : Handle_SelectMgr_SelectableObject());
if (GraphicsUtils::AisObject_isVisible(gfxObject))
d->m_aisContext->AddOrRemoveSelected(gfxOwner, false);
//------------------------------------------
if (gfxObject->IsKind(STANDARD_TYPE(AIS_Shape)))
{
std::cout << "gfxObject is shape" << std::endl;
Handle(AIS_Shape) anAIS_Shape = Handle(AIS_Shape)::DownCast(gfxObject);
}
else
{
std::cout << "gfxObject not shape" << std::endl;
}
//------------------------------------------
}


The premise of the above procedure is:
using GraphicsOwnerPtr = Handle(SelectMgr_EntityOwner);
using GraphicsObjectPtr = Handle(AIS_InteractiveObject);


Below is a screenshot of my run:
View attachment 367

View attachment 366
why?
I suppose a presentable object you're trying to convert to AIS_Shape wasn't initialized as AIS_Shape before, and, consequently, you get what you get - failure of convertion. So, let's try to find a piece of code where this gfxOwner is initialized.
 

sjwa

CAD practitioner
I suppose a presentable object you're trying to convert to AIS_Shape wasn't initialized as AIS_Shape before, and, consequently, you get what you get - failure of convertion. So, let's try to find a piece of code where this gfxOwner is initialized.
JSlyadne, thanks for your reply
I think the piece of code you said is more cumbersome and requires a lot of associated classes,
So JSlyadne, can you tell me how to initialize AIS_InteractiveObject to AIS_Shape? Or how to implement it according to your idea?
thanks
 

JSlyadne

Administrator
Staff member
JSlyadne, thanks for your reply
I think the piece of code you said is more cumbersome and requires a lot of associated classes,
So JSlyadne, can you tell me how to initialize AIS_InteractiveObject to AIS_Shape? Or how to implement it according to your idea?
thanks
TopoDS_Shape shape = ...;
Handle(AIS_Shape) prs = new AIS_Shape(shape );
 
Top