0028726: Quantity_NameOfColor should be replaced by Quantity_Color in function input...
[occt.git] / src / AIS / AIS_PointCloud.cxx
index c9c588f..a0df6dd 100644 (file)
 
 #include <AIS_PointCloud.hxx>
 
-#include <AIS_Drawer.hxx>
 #include <AIS_GraphicTool.hxx>
 #include <Graphic3d_AspectFillArea3d.hxx>
 #include <Graphic3d_AspectMarker3d.hxx>
 #include <Graphic3d_Group.hxx>
+#include <Prs3d_Drawer.hxx>
 #include <Prs3d_PointAspect.hxx>
 #include <Prs3d_Presentation.hxx>
 #include <Prs3d_Root.hxx>
 #include <PrsMgr_ModedPresentation.hxx>
 #include <PrsMgr_Presentations.hxx>
 #include <Select3D_SensitiveBox.hxx>
+#include <Select3D_SensitivePrimitiveArray.hxx>
 #include <SelectMgr_EntityOwner.hxx>
 #include <SelectMgr_Selection.hxx>
-#include <StdPrs_WFDeflectionRestrictedFace.hxx>
+#include <StdPrs_BndBox.hxx>
 
-IMPLEMENT_STANDARD_HANDLE (AIS_PointCloud, AIS_InteractiveObject)
-IMPLEMENT_STANDARD_RTTIEXT(AIS_PointCloud, AIS_InteractiveObject)
+
+IMPLEMENT_STANDARD_RTTIEXT(AIS_PointCloud,AIS_InteractiveObject)
 
 //==================================================
 // Function: AIS_PointCloud
@@ -40,6 +41,9 @@ IMPLEMENT_STANDARD_RTTIEXT(AIS_PointCloud, AIS_InteractiveObject)
 //==================================================
 AIS_PointCloud::AIS_PointCloud()
 {
+  // override default point style to Aspect_TOM_POINT
+  myDrawer->SetPointAspect (new Prs3d_PointAspect (Aspect_TOM_POINT, Quantity_NOC_YELLOW, 1.0));
+
   SetDisplayMode (AIS_PointCloud::DM_Points);
   SetHilightMode (AIS_PointCloud::DM_BndBox);
 }
@@ -136,15 +140,6 @@ void AIS_PointCloud::SetPoints (const Handle(TColgp_HArray1OfPnt)&     theCoords
   myBndBox = getBoundingBox (myPoints);
 }
 
-//=======================================================================
-//function : SetColor
-//purpose  :
-//=======================================================================
-void AIS_PointCloud::SetColor (const Quantity_NameOfColor theColor)
-{
-  SetColor (Quantity_Color (theColor));
-}
-
 //=======================================================================
 //function : SetColor
 //purpose  :
@@ -153,15 +148,21 @@ void AIS_PointCloud::SetColor (const Quantity_Color& theColor)
 {
   AIS_InteractiveObject::SetColor(theColor);
 
-  if (!myDrawer->HasPointAspect())
+  if (!myDrawer->HasOwnPointAspect())
   {
     myDrawer->SetPointAspect (new Prs3d_PointAspect (Aspect_TOM_POINT, theColor, 1.0));
-    *myDrawer->PointAspect()->Aspect() = *myDrawer->Link()->PointAspect()->Aspect();
+    if (myDrawer->HasLink())
+    {
+      *myDrawer->PointAspect()->Aspect() = *myDrawer->Link()->PointAspect()->Aspect();
+    }
   }
-  if (!myDrawer->HasShadingAspect())
+  if (!myDrawer->HasOwnShadingAspect())
   {
     myDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
-    *myDrawer->ShadingAspect()->Aspect() = *myDrawer->Link()->ShadingAspect()->Aspect();
+    if (myDrawer->HasLink())
+    {
+      *myDrawer->ShadingAspect()->Aspect() = *myDrawer->Link()->ShadingAspect()->Aspect();
+    }
   }
 
   // Override color
@@ -180,12 +181,6 @@ void AIS_PointCloud::SetColor (const Quantity_Color& theColor)
     }
 
     const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
-
-    // Set aspects for presentation
-    aPrs->SetPrimitivesAspect (aPointAspect);
-    aPrs->SetPrimitivesAspect (anAreaAspect);
-
-    // Go through all groups to change color for all primitives
     for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
     {
       const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
@@ -220,26 +215,33 @@ void AIS_PointCloud::UnsetColor()
   }
   else
   {
-    Quantity_Color      aColor;
-    Aspect_TypeOfMarker aType  = Aspect_TOM_POINT;
-    Standard_Real       aScale = 1.0;
-    myDrawer->Link()->PointAspect()->Aspect()->Values (aColor, aType, aScale);
-    myDrawer->PointAspect()->SetColor (aColor);
+    myDrawer->PointAspect()->SetColor (myDrawer->HasLink()
+                                     ? myDrawer->Link()->PointAspect()->Aspect()->Color()
+                                     : Quantity_Color (Quantity_NOC_YELLOW));
   }
 
   if (HasMaterial()
    || IsTransparent())
   {
-    Graphic3d_MaterialAspect aMat = AIS_GraphicTool::GetMaterial (HasMaterial() ? myDrawer : myDrawer->Link());
+    Graphic3d_MaterialAspect aDefaultMat (Graphic3d_NOM_BRASS);
+    Graphic3d_MaterialAspect aMat = aDefaultMat;
+    if (HasMaterial() || myDrawer->HasLink())
+    {
+      aMat = AIS_GraphicTool::GetMaterial (HasMaterial() ? myDrawer : myDrawer->Link());
+    }
     if (HasMaterial())
     {
-      Quantity_Color aColor = myDrawer->Link()->ShadingAspect()->Color (myCurrentFacingModel);
+      Quantity_Color aColor = aDefaultMat.AmbientColor();
+      if (myDrawer->HasLink())
+      {
+        aColor = myDrawer->Link()->ShadingAspect()->Color (myCurrentFacingModel);
+      }
       aMat.SetColor (aColor);
     }
     if (IsTransparent())
     {
       Standard_Real aTransp = myDrawer->ShadingAspect()->Transparency (myCurrentFacingModel);
-      aMat.SetTransparency (aTransp);
+      aMat.SetTransparency (Standard_ShortReal(aTransp));
     }
     myDrawer->ShadingAspect()->SetMaterial (aMat, myCurrentFacingModel);
   }
@@ -262,8 +264,6 @@ void AIS_PointCloud::UnsetColor()
     }
 
     const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
-    aPrs->SetPrimitivesAspect (anAreaAsp);
-    aPrs->SetPrimitivesAspect (aMarkerAsp);
     for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
     {
       const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
@@ -283,34 +283,28 @@ void AIS_PointCloud::UnsetColor()
   }
 }
 
-//=======================================================================
-//function : SetMaterial
-//purpose  :
-//=======================================================================
-void AIS_PointCloud::SetMaterial (const Graphic3d_NameOfMaterial theMatName)
-{
-  SetMaterial (Graphic3d_MaterialAspect (theMatName));
-}
-
 //=======================================================================
 //function : SetMaterial
 //purpose  :
 //=======================================================================
 void AIS_PointCloud::SetMaterial (const Graphic3d_MaterialAspect& theMat)
 {
-  if (!myDrawer->HasShadingAspect())
+  if (!myDrawer->HasOwnShadingAspect())
   {
     myDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
-    *myDrawer->ShadingAspect()->Aspect() = *myDrawer->Link()->ShadingAspect()->Aspect();
+    if (myDrawer->HasLink())
+    {
+      *myDrawer->ShadingAspect()->Aspect() = *myDrawer->Link()->ShadingAspect()->Aspect();
+    }
   }
   hasOwnMaterial = Standard_True;
 
   myDrawer->ShadingAspect()->SetMaterial (theMat, myCurrentFacingModel);
   if (HasColor())
   {
-    myDrawer->ShadingAspect()->SetColor (myOwnColor, myCurrentFacingModel);
+    myDrawer->ShadingAspect()->SetColor (myDrawer->Color(), myCurrentFacingModel);
   }
-  myDrawer->ShadingAspect()->SetTransparency (myTransparency, myCurrentFacingModel);
+  myDrawer->ShadingAspect()->SetTransparency (myDrawer->Transparency(), myCurrentFacingModel);
 
   // modify shading presentation without re-computation
   const PrsMgr_Presentations&        aPrsList  = Presentations();
@@ -324,7 +318,6 @@ void AIS_PointCloud::SetMaterial (const Graphic3d_MaterialAspect& theMat)
     }
 
     const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
-    aPrs->SetPrimitivesAspect (anAreaAsp);
     for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
     {
       const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
@@ -350,12 +343,15 @@ void AIS_PointCloud::UnsetMaterial()
   if (HasColor()
    || IsTransparent())
   {
-    myDrawer->ShadingAspect()->SetMaterial (myDrawer->Link()->ShadingAspect()->Material (myCurrentFacingModel),
+    Graphic3d_MaterialAspect aDefaultMat (Graphic3d_NOM_BRASS);
+    myDrawer->ShadingAspect()->SetMaterial (myDrawer->HasLink() ?
+                                            myDrawer->Link()->ShadingAspect()->Material (myCurrentFacingModel) :
+                                            aDefaultMat,
                                             myCurrentFacingModel);
     if (HasColor())
     {
-      myDrawer->ShadingAspect()->SetColor        (myOwnColor,     myCurrentFacingModel);
-      myDrawer->ShadingAspect()->SetTransparency (myTransparency, myCurrentFacingModel);
+      myDrawer->ShadingAspect()->SetColor        (myDrawer->Color(),        myCurrentFacingModel);
+      myDrawer->ShadingAspect()->SetTransparency (myDrawer->Transparency(), myCurrentFacingModel);
     }
   }
   else
@@ -376,7 +372,6 @@ void AIS_PointCloud::UnsetMaterial()
     }
 
     const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
-    aPrs->SetPrimitivesAspect (anAreaAsp);
     for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
     {
       const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
@@ -396,7 +391,6 @@ void AIS_PointCloud::Compute (const Handle(PrsMgr_PresentationManager3d)& /*theP
                               const Handle(Prs3d_Presentation)&           thePrs,
                               const Standard_Integer                      theMode)
 {
-  thePrs->Clear();
   switch (theMode)
   {
     case AIS_PointCloud::DM_Points:
@@ -407,14 +401,9 @@ void AIS_PointCloud::Compute (const Handle(PrsMgr_PresentationManager3d)& /*theP
         return;
       }
 
-      Handle(Graphic3d_AspectMarker3d) aMarkerAspect = myDrawer->PointAspect()->Aspect();
-      if (!myDrawer->HasPointAspect())
-      {
-        aMarkerAspect->SetType (Aspect_TOM_POINT);
-      }
-
       Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (thePrs);
-      aGroup->SetGroupPrimitivesAspect (aMarkerAspect);
+      aGroup->SetGroupPrimitivesAspect (myDrawer->PointAspect()->Aspect());
+      aGroup->SetGroupPrimitivesAspect (myDrawer->ShadingAspect()->Aspect());
       aGroup->AddPrimitiveArray (aPoints);
       break;
     }
@@ -426,7 +415,7 @@ void AIS_PointCloud::Compute (const Handle(PrsMgr_PresentationManager3d)& /*theP
         return;
       }
 
-      StdPrs_WFDeflectionRestrictedFace::AddBox (thePrs, aBndBox, myDrawer);
+      StdPrs_BndBox::Add (thePrs, aBndBox, myDrawer);
       break;
     }
   }
@@ -437,15 +426,41 @@ void AIS_PointCloud::Compute (const Handle(PrsMgr_PresentationManager3d)& /*theP
 //purpose  :
 //=======================================================================
 void AIS_PointCloud::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
-                                       const Standard_Integer             /*theMode*/)
+                                       const Standard_Integer             theMode)
 {
+  Handle(SelectMgr_EntityOwner) anOwner = new SelectMgr_EntityOwner (this);
+  switch (theMode)
+  {
+    case SM_Points:
+    {
+      const Handle(Graphic3d_ArrayOfPoints) aPoints = GetPoints();
+      if (!aPoints.IsNull()
+       && !aPoints->Attributes().IsNull())
+      {
+        Handle(Select3D_SensitivePrimitiveArray) aSensitive = new Select3D_SensitivePrimitiveArray (anOwner);
+        aSensitive->SetSensitivityFactor (8);
+        aSensitive->InitPoints (aPoints->Attributes(), aPoints->Indices(), TopLoc_Location());
+        aSensitive->BVH();
+        theSelection->Add (aSensitive);
+        return;
+      }
+      break;
+    }
+    case SM_BndBox:
+    {
+      break;
+    }
+    default:
+    {
+      return;
+    }
+  }
+
   Bnd_Box aBndBox = GetBoundingBox();
   if (aBndBox.IsVoid())
   {
     return;
   }
-
-  Handle(SelectMgr_EntityOwner) anOwner  = new SelectMgr_EntityOwner (this);
   Handle(Select3D_SensitiveBox) aSensBox = new Select3D_SensitiveBox (anOwner, aBndBox);
   theSelection->Add (aSensBox);
 }