Mon, 01/23/2023 - 21:33
Forums:
Hello forum,
please see the attached document.
I loaded into a viewer two cubes, two AIS_ColoredShape (Fig. 1)
I created a composite solid, one single AIS_ColoredShape (the previous are removed from the display) (Fig. 2)
I hid one of the cubes of the composite solid, acting on the AIS_ColoredDrawer (->setHidden(true)) (Fig. 3)
I called context Redisplay onto the interactive shape, since I don't want the hidden cube is selectable
Unfortunately the hidden cube is selectable (Fig. 4)
Could you please help me?
Grazie
Giovanni
P.S. OpenCascade 7.3.0, Windows10
Attachments:
Mon, 01/23/2023 - 22:17
Could you prepare some code snippet reproducing the issue? This logic should work, if I understand description correctly.
Tue, 01/24/2023 - 12:02
void occWidget::hideSelectedBodies()
{
// check if the selected body is a main shape
for(occContext->InitSelected(); occContext->MoreSelected(); occContext->NextSelected())
{
const occHandle(AIS_ColoredShape)& curAISShape =
occHandle(AIS_ColoredShape)::DownCast(occContext->SelectedOwner()->Selectable());
occHandle(SelectMgr_EntityOwner) so = occContext->SelectedOwner();
occHandle(StdSelect_BRepOwner) bro = occHandle(StdSelect_BRepOwner)::DownCast(so);
const TopoDS_Shape& shape = bro->Shape();
if(curAISShape->Shape().ShapeType()==TopAbs_COMPSOLID && shape.ShapeType()==TopAbs_SOLID)
{
occContext->Unhilight(curAISShape,false);
curAISShape->CustomAspects(shape)->SetHidden(true);
occContext->Redisplay(curAISShape,false,true);
continue;
}
// the current selected shape is a "main" shape
occContext->Unhilight(curAISShape,false);
occContext->Erase(curAISShape,false);
}
occContext->ClearSelected(false);
occContext->UpdateCurrentViewer();
}
Tue, 01/24/2023 - 10:53
Is it done with enabled local selection for
TopoDS_Solid
?Tue, 01/24/2023 - 12:08
Selection mode is arbitrary. It is established by the buttons shown in the picture.
If a composite solid X is shown, and a face has been selected, X is hidden
If a composite solid X is shown, and one of its solids has been selected, only the selected solid is hidden
Giovanni
Tue, 01/24/2023 - 10:55
Tip: use insert code or Markdown syntax for better forgetting in the forum.
Wed, 01/25/2023 - 11:08
Hello, I would like to underline that is, obviously, possible to hide a set of faces (see picture), acting on custom aspects, and to make the hidden faces as not selectable by calling ::Redisplay.
Code (here a previous graphic selection of faces has been performed):
Redisplay is in separated for cycle only for clarity Ciao Giovanni
Wed, 01/25/2023 - 19:48
I'm unable reproducing the issue with the given code snippet neither on OCCT 7.3.0 not on the latest release. So it is better expanding sample with more elaborated reproducible scenario.
That should be done not for clarity but rather for a proper workflow. Changing objects while iterating over selection is fragile, and moreover - suboptimal in case, when more than one subshape is selected (the same object will be redisplayed multiple times). The proper way would be collecting the list of modified presentations (into
NCollection_IndexedMap<Handle(AIS_ColoredShape)>
or something like this) and redisplaying them afterwards.In these cases, compilers would handle this safely, but it is better not storing a temporary object by reference. Always check what method returns, these methods return copies of Handle() objects.
Wed, 01/25/2023 - 20:33
Thank you gkv,
also with the suggested changes, a face selection can be hidden and becomes not selectable,
while a selection of solids of a composite solid can be made hidden, but not unselectable by calling Redisplay.
Per me rimane un piccolo mistero.
Ciao
Giovanni
Wed, 01/25/2023 - 20:48
Could you share some composite solid model?
Wed, 01/25/2023 - 21:08
of course just for info I built the composite solid in attachment using something like that:
Grazie ciao Giovanni
Wed, 01/25/2023 - 21:52
OK, I see now that the problem happens specifically while picking shared Faces.
Wed, 01/25/2023 - 23:21
Thank you gkv for yout comment.
Nice to know that someone works up to 8 p.m.!
The AIS_Shape->Shape() is a composite solid.
The "problem" is that when hiding one of the two solids
by setting its custom drawer as hidden, and then calling
redisplay onto the AIS_Shape, the hidden solid can be
selected, and it is also detected when moving mouse
Buona serata e grazie
ciao
Giovanni
Thu, 01/26/2023 - 12:12
Hi Giovanni,
I think while setting the sub shape hidden it removes only presentation, To avoid selection you may need reconstruct the TopoDs_shape by removing the selected faces. In another way override ComputeSelection function and skip adding the faces which are not visible to selection structure.
It may have performance impact but this is what i found.
void MyAIS_Object::ComputeSelection(const Handle(SelectMgr_Selection)& theSelection,
const Standard_Integer theMode)
{
for (exp.Init(shape, TopAbs_FACE); exp.More(); exp.Next())
{
TopoDS_Face aFace = TopoDS::Face(exp.Current()));
// Check the AISColoredDrawer of this face is visible or not here
bool shapeVisible = true;
if(shapeVisible)
{
switch (theMode)
{
case 0: StdSelect_BRepSelectionTool::Load (theSelection, this, aFace , TopAbs_SHAPE, 0, 0); break;
case 1: StdSelect_BRepSelectionTool::Load (theSelection, this, aFace , TopAbs_VERTEX, 0, 0); break;
case 2: StdSelect_BRepSelectionTool::Load (theSelection, this, aFace , TopAbs_EDGE, 0, 0); break;
case 3: StdSelect_BRepSelectionTool::Load (theSelection, this, aFace , TopAbs_WIRE, 0, 0); break;
case 4: StdSelect_BRepSelectionTool::Load (theSelection, this, aFace , TopAbs_FACE, 0, 0); break;
}
}
}
}
Fri, 01/27/2023 - 01:10
Thank you for your hint. What actually I would like to say is that hide/show of a face of an AIS_ColoredShape works very well. Indeed, when I hide a face of a solid and then I call AIS_InteractiveContext::Redisplay on that AIS_ColoredShape, the hidden face cannot be selected (and highlighted) anymore. This because AIS_InteractiveContext::Redisplay does exactly what you're saying:
void AIS_InteractiveContext::Redisplay (const Handle(AIS_InteractiveObject)& theIObj, const Standard_Boolean theToUpdateViewer, const Standard_Boolean theAllModes) { RecomputePrsOnly (theIObj, theToUpdateViewer, theAllModes); RecomputeSelectionOnly (theIObj); }
The problem is actually that when I hide a TopoDS_Solid "child" or (or subshape of) a TopoDS_Compsolid, and I call Redisplay, the hidden solid remains selectable. Grazie e buona serata Giovanni
Fri, 01/27/2023 - 02:06
At the end a workaround