]> OCCT Git - occt-copy.git/commitdiff
0030737: Visualization - implementing new selection schemes in context
authornds <nds@opencascade.com>
Mon, 27 May 2019 08:35:02 +0000 (11:35 +0300)
committernds <nds@opencascade.com>
Tue, 28 May 2019 10:10:01 +0000 (13:10 +0300)
#provide selection scheme by parameter

(cherry picked from commit af73c57320c6775b87bcf5823a61eeff266ec40a)

src/AIS/AIS_InteractiveContext.cxx
src/AIS/AIS_InteractiveContext.hxx
src/AIS/AIS_InteractiveContext_1.cxx

index 5443b9b7cb29c21a49e585a2d6c29c1bd4100332..b4971d326c6615ccf5dfc1f5e65e94c35157a9f6 100644 (file)
@@ -163,13 +163,6 @@ myIsAutoActivateSelMode(Standard_True)
     aStyle->SetMethod(Aspect_TOHM_COLOR);
     aStyle->SetColor (Quantity_NOC_GRAY40);
   }
-  SetSelectionScheme (AIS_SelectionType_Select,       AIS_SelectionScheme_ClearAndAdd);
-  SetSelectionScheme (AIS_SelectionType_SelectInRect, AIS_SelectionScheme_ClearAndAdd);
-  SetSelectionScheme (AIS_SelectionType_SelectInPoly, AIS_SelectionScheme_ClearAndAdd); 
-  SetSelectionScheme (AIS_SelectionType_ShiftSelect,       AIS_SelectionScheme_Switch);
-  SetSelectionScheme (AIS_SelectionType_ShiftSelectInRect, AIS_SelectionScheme_Switch);
-  SetSelectionScheme (AIS_SelectionType_ShiftSelectInPoly, AIS_SelectionScheme_Switch);
-
   InitAttributes();
 }
 
@@ -432,8 +425,7 @@ void AIS_InteractiveContext::Display (const Handle(AIS_InteractiveObject)& theIO
   setContextToObject (theIObj);
   if (!myObjects.IsBound (theIObj))
   {
-    Handle(AIS_GlobalStatus) aStatus = new AIS_GlobalStatus (AIS_DS_Displayed, theDispMode, theSelectionMode);
-    myObjects.Bind   (theIObj, aStatus);
+    setObjectStatus (theIObj, AIS_DS_Displayed, theDispMode, theSelectionMode);
     myMainVwr->StructureManager()->RegisterObject (theIObj);
     myMainPM->Display(theIObj, theDispMode);
     if (theSelectionMode != -1)
@@ -510,8 +502,7 @@ void AIS_InteractiveContext::Load (const Handle(AIS_InteractiveObject)& theIObj,
   {
     Standard_Integer aDispMode, aHiMod, aSelModeDef;
     GetDefModes (theIObj, aDispMode, aHiMod, aSelModeDef);
-    Handle(AIS_GlobalStatus) aStatus = new AIS_GlobalStatus (AIS_DS_Erased, aDispMode, theSelMode != -1 ? theSelMode : aSelModeDef);
-    myObjects.Bind (theIObj, aStatus);
+    setObjectStatus (theIObj, AIS_DS_Erased, aDispMode, theSelMode != -1 ? theSelMode : aSelModeDef);
     myMainVwr->StructureManager()->RegisterObject (theIObj);
   }
 
@@ -2101,7 +2092,7 @@ void AIS_InteractiveContext::ClearGlobal (const Handle(AIS_InteractiveObject)& t
   const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
   mgrSelector->Remove (anObj);
 
-  myObjects.UnBind (theIObj);
+  setObjectStatus (theIObj, AIS_DS_None, -1, -1);
   myMainVwr->StructureManager()->UnregisterObject (theIObj);
 
   for (V3d_ListOfViewIterator aDefViewIter (myMainVwr->DefinedViewIterator()); aDefViewIter.More(); aDefViewIter.Next())
@@ -2567,3 +2558,29 @@ void AIS_InteractiveContext::SetTransformPersistence (const Handle(AIS_Interacti
     anActiveViewIter.Value()->View()->InvalidateZLayerBoundingBox (aLayerId);
   }
 }
+//=======================================================================
+//function : setObjectStatus
+//purpose  :
+//=======================================================================
+void AIS_InteractiveContext::setObjectStatus (const Handle(AIS_InteractiveObject)& theIObj,
+                                              const AIS_DisplayStatus theStatus,
+                                              const Standard_Integer theDispMode,
+                                              const Standard_Integer theSelectionMode)
+{
+  if (theStatus != AIS_DS_None)
+  {
+    Handle(AIS_GlobalStatus) aStatus = new AIS_GlobalStatus (AIS_DS_Displayed, theDispMode, theSelectionMode);
+    myObjects.Bind (theIObj, aStatus);
+  }
+  else
+    myObjects.UnBind (theIObj);
+
+  for (PrsMgr_ListOfPresentableObjectsIter aPrsIter (theIObj->Children()); aPrsIter.More(); aPrsIter.Next())
+  {
+    Handle(AIS_InteractiveObject) aChild (Handle(AIS_InteractiveObject)::DownCast (aPrsIter.Value()));
+    if (aChild.IsNull())
+      continue;
+
+    setObjectStatus (aChild, theStatus, theDispMode, theSelectionMode);
+  }
+}
index 3ccaee2e3340690c001978928628f748de07c29c..626fc93bf650411ade41c18b971260fa2d4b42f5 100644 (file)
@@ -445,13 +445,23 @@ public: //! @name Selection management
     return AddSelect (theObject->GlobalSelOwner());
   }
 
-  //! Returns selection scheme used in Select
-  AIS_SelectionScheme SelectionScheme (const AIS_SelectionType theType) const
-  { return mySelectionSchemes.Find (theType); }
+  //! Selects everything found in the bounding rectangle defined by the pixel minima and maxima, XPMin, YPMin, XPMax, and YPMax in the view.
+  //! The objects detected are passed to the main viewer, which is then updated.
+  Standard_EXPORT AIS_StatusOfPick Select (const Standard_Integer  theXPMin,
+                                           const Standard_Integer  theYPMin,
+                                           const Standard_Integer  theXPMax,
+                                           const Standard_Integer  theYPMax,
+                                           const Handle(V3d_View)& theView,
+                                           const AIS_SelectionScheme theSelScheme);
+  
+  //! polyline selection; clears the previous picked list
+  Standard_EXPORT AIS_StatusOfPick Select (const TColgp_Array1OfPnt2d& thePolyline,
+                                           const Handle(V3d_View)&     theView,
+                                           const AIS_SelectionScheme   theSelScheme);
 
-  //! Returns selection scheme used in Select
-  void SetSelectionScheme (const AIS_SelectionType theType, const AIS_SelectionScheme theScheme)
-  { mySelectionSchemes.Bind (theType, theScheme); }
+  //! Stores and hilights the previous detected; Unhilights the previous picked.
+  //! @sa MoveTo().
+  Standard_EXPORT AIS_StatusOfPick Select (const AIS_SelectionScheme theSelScheme);
 
   //! Selects everything found in the bounding rectangle defined by the pixel minima and maxima, XPMin, YPMin, XPMax, and YPMax in the view.
   //! The objects detected are passed to the main viewer, which is then updated.
@@ -1359,6 +1369,14 @@ protected: //! @name internal methods
     }
   }
 
+  //! Bind/Unbind status to object and object children
+  //! \param theIObj object
+  //! \param theStatus status, if NULL, unbind object
+  Standard_EXPORT void setObjectStatus (const Handle(AIS_InteractiveObject)& theIObj,
+                                        const AIS_DisplayStatus theStatus,
+                                        const Standard_Integer theDispyMode,
+                                        const Standard_Integer theSelectionMode);
+
 protected: //! @name internal fields
 
   AIS_DataMapOfIOStatus myObjects;
@@ -1380,8 +1398,6 @@ protected: //! @name internal fields
   SelectMgr_PickingStrategy myPickingStrategy; //!< picking strategy to be applied within MoveTo()
   Standard_Boolean myAutoHilight;
   Standard_Boolean myIsAutoActivateSelMode;
-
-  NCollection_DataMap<AIS_SelectionType, AIS_SelectionScheme> mySelectionSchemes;
 };
 
 DEFINE_STANDARD_HANDLE(AIS_InteractiveContext, Standard_Transient)
index 55eb128dd256a92a00f405d57ddc556114c53c6d..e02c852ee3c9fb0413a63488f357c7f0e55e4005 100644 (file)
@@ -411,7 +411,7 @@ AIS_StatusOfPick AIS_InteractiveContext::Select (const Standard_Integer  theXPMi
                                                  const Standard_Integer  theXPMax,
                                                  const Standard_Integer  theYPMax,
                                                  const Handle(V3d_View)& theView,
-                                                 const Standard_Boolean  toUpdateViewer)
+                                                 const AIS_SelectionScheme theSelScheme)
 {
   if (theView->Viewer() != myMainVwr)
   {
@@ -434,11 +434,11 @@ AIS_StatusOfPick AIS_InteractiveContext::Select (const Standard_Integer  theXPMi
   {
     aPickedOwners.Append (myMainSel->Picked (aPickIter));
   }
-  mySelection->SelectOwners (aPickedOwners, SelectionScheme (AIS_SelectionType_SelectInRect), myFilters);
+  mySelection->SelectOwners (aPickedOwners, theSelScheme, myFilters);
 
   if (myAutoHilight)
   {
-    HilightSelected (toUpdateViewer);
+    HilightSelected (Standard_False);
   }
 
   Standard_Integer aSelNum = NbSelected();
@@ -455,7 +455,7 @@ AIS_StatusOfPick AIS_InteractiveContext::Select (const Standard_Integer  theXPMi
 //=======================================================================
 AIS_StatusOfPick AIS_InteractiveContext::Select (const TColgp_Array1OfPnt2d& thePolyline,
                                                  const Handle(V3d_View)&     theView,
-                                                 const Standard_Boolean      toUpdateViewer)
+                                                 const AIS_SelectionScheme   theSelScheme)
 {
   if (theView->Viewer() != myMainVwr)
   {
@@ -478,11 +478,11 @@ AIS_StatusOfPick AIS_InteractiveContext::Select (const TColgp_Array1OfPnt2d& the
   {
     aPickedOwners.Append (myMainSel->Picked (aPickIter));
   }
-  mySelection->SelectOwners (aPickedOwners, SelectionScheme (AIS_SelectionType_SelectInPoly), myFilters);
+  mySelection->SelectOwners (aPickedOwners, theSelScheme, myFilters);
 
   if (myAutoHilight)
   {
-    HilightSelected (toUpdateViewer);
+    HilightSelected (Standard_False);
   }
 
   Standard_Integer aSelNum = NbSelected();
@@ -497,7 +497,7 @@ AIS_StatusOfPick AIS_InteractiveContext::Select (const TColgp_Array1OfPnt2d& the
 //function : Select
 //purpose  : 
 //=======================================================================
-AIS_StatusOfPick AIS_InteractiveContext::Select (const Standard_Boolean toUpdateViewer)
+AIS_StatusOfPick AIS_InteractiveContext::Select (const AIS_SelectionScheme theSelScheme)
 {
   // special case: single selection of detected owner - is it necessary ?
   /*if (myWasLastMain && !myLastinMain.IsNull() && !myAutoHilight &&
@@ -517,16 +517,11 @@ AIS_StatusOfPick AIS_InteractiveContext::Select (const Standard_Boolean toUpdate
 
   AIS_NListOfEntityOwner aPickedOwners;
   aPickedOwners.Append (myLastinMain);
-  mySelection->SelectOwners (aPickedOwners, SelectionScheme (AIS_SelectionType_Select), myFilters);
+  mySelection->SelectOwners (aPickedOwners, theSelScheme, myFilters);
 
   if (myAutoHilight)
   {
-    HilightSelected (toUpdateViewer);
-  }
-
-  if(toUpdateViewer)
-  {
-    UpdateCurrentViewer();
+    HilightSelected (Standard_False);
   }
 
   Standard_Integer aSelNum = NbSelected();
@@ -537,35 +532,46 @@ AIS_StatusOfPick AIS_InteractiveContext::Select (const Standard_Boolean toUpdate
 }
 
 //=======================================================================
-//function : ShiftSelect
+//function : Select
 //purpose  : 
 //=======================================================================
-AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const Standard_Boolean toUpdateViewer)
+AIS_StatusOfPick AIS_InteractiveContext::Select (const Standard_Integer  theXPMin,
+                                                 const Standard_Integer  theYPMin,
+                                                 const Standard_Integer  theXPMax,
+                                                 const Standard_Integer  theYPMax,
+                                                 const Handle(V3d_View)& theView,
+                                                 const Standard_Boolean)
 {
-  AIS_NListOfEntityOwner aPrevSelected = mySelection->Objects();
-  if (myAutoHilight)
-  {
-    clearDynamicHighlight();
-    UnhilightSelected (Standard_False);
-  }
-
-  AIS_NListOfEntityOwner aPickedOwners;
-  aPickedOwners.Append (myLastinMain);
-  mySelection->SelectOwners (aPickedOwners, SelectionScheme (AIS_SelectionType_ShiftSelect), myFilters);
-
-  if (myAutoHilight)
-  {
-    HilightSelected (toUpdateViewer);
-  }
+  return Select (theXPMin, theYPMin, theXPMax, theYPMax, theView, AIS_SelectionScheme_ClearAndAdd);
+}
 
-  if (toUpdateViewer)
-    UpdateCurrentViewer();
+//=======================================================================
+//function : Select
+//purpose  : Selection by polyline
+//=======================================================================
+AIS_StatusOfPick AIS_InteractiveContext::Select (const TColgp_Array1OfPnt2d& thePolyline,
+                                                 const Handle(V3d_View)&     theView,
+                                                 const Standard_Boolean)
+{
+  return Select (thePolyline, theView, AIS_SelectionScheme_ClearAndAdd);
+}
 
-  Standard_Integer aSelNum = NbSelected();
+//=======================================================================
+//function : Select
+//purpose  : 
+//=======================================================================
+AIS_StatusOfPick AIS_InteractiveContext::Select (const Standard_Boolean)
+{
+  return Select (AIS_SelectionScheme_ClearAndAdd);
+}
 
-  return (aSelNum == 0) ? AIS_SOP_NothingSelected
-                        : (aSelNum == 1) ? AIS_SOP_OneSelected
-                        : AIS_SOP_SeveralSelected;
+//=======================================================================
+//function : ShiftSelect
+//purpose  : 
+//=======================================================================
+AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const Standard_Boolean)
+{
+  return Select (AIS_SelectionScheme_Switch);
 }
 
 //=======================================================================
@@ -577,40 +583,9 @@ AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const Standard_Integer the
                                                       const Standard_Integer theXPMax,
                                                       const Standard_Integer theYPMax,
                                                       const Handle(V3d_View)& theView,
-                                                      const Standard_Boolean toUpdateViewer)
+                                                      const Standard_Boolean)
 {
-  if (theView->Viewer() != myMainVwr)
-  {
-    throw Standard_ProgramError ("AIS_InteractiveContext::ShiftSelect() - invalid argument");
-  }
-
-  AIS_NListOfEntityOwner aPrevSelected = mySelection->Objects();
-  if (myAutoHilight)
-  {
-    clearDynamicHighlight();
-    UnhilightSelected (Standard_False);
-  }
-  myWasLastMain = Standard_True;
-  myMainSel->Pick (theXPMin, theYPMin, theXPMax, theYPMax, theView);
-
-  AIS_NListOfEntityOwner aPickedOwners;
-  for (Standard_Integer aPickIter = 1; aPickIter <= myMainSel->NbPicked(); ++aPickIter)
-  {
-    aPickedOwners.Append (myMainSel->Picked (aPickIter));
-  }
-  mySelection->SelectOwners (aPickedOwners, SelectionScheme (AIS_SelectionType_ShiftSelectInRect), myFilters);
-
-  if (myAutoHilight)
-  {
-    HilightSelected (toUpdateViewer);
-  }
-
-  Standard_Integer aSelNum = NbSelected();
-
-  return (aSelNum == 0) ? AIS_SOP_NothingSelected
-                        : (aSelNum == 1) ? AIS_SOP_OneSelected
-                                         : AIS_SOP_SeveralSelected;
-
+  return Select (theXPMin, theYPMin, theXPMax, theYPMax, theView, AIS_SelectionScheme_Switch);
 }
 
 //=======================================================================
@@ -619,39 +594,9 @@ AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const Standard_Integer the
 //=======================================================================
 AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const TColgp_Array1OfPnt2d& thePolyline,
                                                       const Handle(V3d_View)& theView,
-                                                      const Standard_Boolean toUpdateViewer)
+                                                      const Standard_Boolean)
 {
-  if (theView->Viewer() != myMainVwr)
-  {
-    throw Standard_ProgramError ("AIS_InteractiveContext::ShiftSelect() - invalid argument");
-  }
-
-  AIS_NListOfEntityOwner aPrevSelected = mySelection->Objects();
-  if (myAutoHilight)
-  {
-    clearDynamicHighlight();
-    UnhilightSelected (Standard_False);
-  }
-  myWasLastMain = Standard_True;
-  myMainSel->Pick (thePolyline, theView);
-
-  AIS_NListOfEntityOwner aPickedOwners;
-  for (Standard_Integer aPickIter = 1; aPickIter <= myMainSel->NbPicked(); ++aPickIter)
-  {
-    aPickedOwners.Append (myMainSel->Picked (aPickIter));
-  }
-  mySelection->SelectOwners (aPickedOwners, SelectionScheme (AIS_SelectionType_ShiftSelectInPoly), myFilters);
-
-  if (myAutoHilight)
-  {
-    HilightSelected (toUpdateViewer);
-  }
-
-  Standard_Integer aSelNum = NbSelected();
-
-  return (aSelNum == 0) ? AIS_SOP_NothingSelected
-                        : (aSelNum == 1) ? AIS_SOP_OneSelected
-                                         : AIS_SOP_SeveralSelected;
+  return Select (thePolyline, theView, AIS_SelectionScheme_Switch);
 }
 
 //=======================================================================