
Tue, 03/16/2021 - 11:29
Hello everyone,
I'm trying to inherit from AIS_InteractiveObject in order to create a new object (usinig OCC 7.3.0)
I've seen that, implementing properly the Compute() method I can build its presentation as desired (more or less).
Of course I will vary its aspect according to "theMode" parameter in case this is needed.
But one of my goals is also to have a possibly different representation of this interactive object when the mouse passes over it (dynamic hilight) and/or when the object is selected: of course, by changing the properties for drawer associated to selection/hilight mechanism is a way, but this doesn't change its aspect very much as, I guess, only color, thickness, material, transparency and so on will be affected. How will I, for instance, get my object to look like a box (its bounding box, for instance) instead of a sphere or a 3D wire? I thought that this can be achieved with a certain usage of Compute method, but I don't remember how...
Many thanks in advance
Gianluca
Wed, 03/17/2021 - 17:38
The simplest way is using different Display Mode for main presentation and highlighting. For that you need redefining AIS_InteractiveObject::Compute() to handle different Display Modes and choose one for highlighting - see AIS_InteractiveObject::SetDisplayMode() and AIS_InteractiveObject::SetHilightMode().
This is how AIS_Shape behaves by default, when the main presentation is AIS_Shaded (1) and highlighting is AIS_Wireframe (0).
Thu, 03/18/2021 - 13:32
Hello Kirill,
many thanks for your answer.
As a matter of fact I was able to remember this approach and managed to gete a different representation for my object.
I still have many questions about this:
public override void Compute(PrsMgr_PresentationManager thePrsMgr, Prs3d_Presentation thePrs, int theMode)
{
thePrs.Clear();
if (theMode == 3)
{
for (int i = 0; i < _centers.Count; i++)
{
gp_Pnt curCenter = _centers[i];
double curRadius = _radii[i];
BRepPrimAPI_MakeSphere sphereMk = new BRepPrimAPI_MakeSphere(curCenter, curRadius);
StdPrs_ShadedShape.Add(thePrs, sphereMk.Shape(), Attributes());
}
}
else if (theMode == 0)
{
Prs3d_Drawer dynamicHilightDrawer = new Prs3d_Drawer();
dynamicHilightDrawer.SetColor(new Quantity.Quantity_Color(Quantity.Quantity_NameOfColor.Quantity_NOC_BLUE1));
Prs3d_LineAspect lineAspect = dynamicHilightDrawer.LineAspect();
lineAspect.SetAspect(new Graphic3d_AspectLine3d(new Quantity.Quantity_Color(Quantity.Quantity_NameOfColor.Quantity_NOC_BLUE1), Aspect.Aspect_TypeOfLine.Aspect_TOL_DASH, 3));
dynamicHilightDrawer.SetLineAspect(lineAspect);
for (int i = 0; i < _centers.Count; i++)
{
// for some reasons, here the list of gp_Pnt is not consisten any longer and I get a null exception!!!
//gp_Pnt curCenter = _centers[i];
gp_Pnt curCenter = new gp_Pnt(_xList[i], _yList[i], _zList[i]);
double curRadius = _radii[i];
Bnd.Bnd_Box bb = new Bnd.Bnd_Box();
bb.SetVoid();
double x = _xList[i];
double y = _yList[i];
double z = _zList[i];
bb.Update(x - curRadius, y - curRadius, z - curRadius, x + curRadius, y + curRadius, z + curRadius);
StdPrs_BndBox.Add(thePrs, bb, dynamicHilightDrawer);
}
}
Many thanks again
Gianluca