Subshape Selection After Setting Custom Attributes

Hello,

I am trying to implement the showing and hiding of both shapes and faces. I've got one problem, where after the user hides a shape, then decides to show a face, the face after that will not able to be selected for hiding. Hiding and showing faces and shapes each have their own mode.

I pass attributes for a semi transparent state and a solid state into the show shape method.

My best guess is the parent shape is overriding the sub shape face's newly assigned custom attributes somehow, but I'm not sure where and how to separate them. Please forgive the messy code.

void Viewer::HideShape(const Handle(AIS_ColoredShape)& aisColoredShape, const TopoDS_Shape &shape)
    {
        Handle(AIS_ColoredShape) thePrs;
        Handle(AIS_ColoredDrawer) drawer;
        if (shape.ShapeType() == TopAbs_ShapeEnum::TopAbs_FACE)
        {
            TopoDS_Face face = TopoDS::Face(shape);
            thePrs = new AIS_ColoredShape(face);
            drawer = aisColoredShape->CustomAspects(face);
        }
        else
        {
            thePrs = new AIS_ColoredShape(shape);
            drawer = aisColoredShape->CustomAspects(shape);
            for (auto it = hiddenShapes->begin(); it != hiddenShapes->end();)
            {
                if (IsFaceSubShape(shape, it->GetTopoDSShape()))
                {
                    it->GetAISColoredShape()->UnsetCustomAspects(it->GetTopoDSShape(), true);
                    //We can remove hidden subshapes, as they will be hidden by the parent shape.
                    it = hiddenShapes->erase(it);
                }
                else
                {
                    it++;
                }
            }
        }
        drawer->ClearLocalAttributes();
        drawer->SetOwnTransparency(0);
        drawer->SetTransparency(0);
        drawer->SetHidden(true);
        myAISContext()->SetLocalAttributes(thePrs, drawer, Standard_True);
        aisColoredShape->Redisplay(Standard_True);
    }

void Viewer::ShowShape(const Handle(AIS_ColoredShape)& aisColoredShape, const TopoDS_Shape &shape, const Handle(Prs3d_Drawer)& attributes, bool isClearSubShapesFromHideList)
    {
        Handle(AIS_ColoredShape) thePrs;
        Handle(AIS_ColoredDrawer) drawer;
        bool isSelectModeFace = false;
        if (shape.ShapeType() == TopAbs_ShapeEnum::TopAbs_FACE)
        {
            TopoDS_Face face = TopoDS::Face(shape);
            thePrs = new AIS_ColoredShape(face);
            drawer = aisColoredShape->CustomAspects(face);
        }
        else
        {
            thePrs = new AIS_ColoredShape(shape);
            drawer = aisColoredShape->CustomAspects(shape);

            //look through the list of previously hidden shapes and see if any faces in it are subshapes of this shape. 
            //If so, show them too and remove them from the list.
            for (auto it = hiddenShapes->begin(); it != hiddenShapes->end();)
            {
                if (IsFaceSubShape(shape, it->GetTopoDSShape()))
                {
                    it->GetAISColoredShape()->UnsetCustomAspects(it->GetTopoDSShape(), isClearSubShapesFromHideList);
                    if (isClearSubShapesFromHideList)
                    {
                        it = hiddenShapes->erase(it);
                    }
                    else
                    {
                        it++;
                    }
                }
                else
                {
                    it++;
                }
            }
        }
        drawer->SetHidden(false);
        drawer->SetOwnTransparency(attributes->Transparency());
        drawer->SetTransparency(attributes->Transparency());
        drawer->SetBasicFillAreaAspect(attributes->BasicFillAreaAspect());
        drawer->SetFaceBoundaryAspect(attributes->FaceBoundaryAspect());
        drawer->SetShadingAspect(attributes->ShadingAspect());
        myAISContext()->SetLocalAttributes(thePrs, drawer, Standard_True);
        aisColoredShape->Redisplay(Standard_True);
    }