Salome HOME
Better management of errors.
[modules/shaper.git] / src / XGUI / XGUI_Selection.cpp
index 584c9fd3690658e720c12884f0e74f0973794ee1..5af4ea4c3f4739988c0d331433bb58b6507f1b20 100644 (file)
@@ -80,15 +80,15 @@ Handle(AIS_InteractiveObject) XGUI_Selection::getIO(const ModuleBase_ViewerPrsPt
 void XGUI_Selection::getSelectedInViewer(QList<ModuleBase_ViewerPrsPtr>& thePresentations) const
 {
   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
-  if (!aContext.IsNull() && aContext->HasOpenedContext()) {
+  if (!aContext.IsNull()) {
     QList<long> aSelectedIds; // Remember of selected address in order to avoid duplicates
     for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
       ModuleBase_ViewerPrsPtr aPrs(new ModuleBase_ViewerPrs());
       Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner();
 
-      if (aSelectedIds.contains((long)anOwner.Access()))
+      if (aSelectedIds.contains((long)anOwner.get()))
         continue;
-      aSelectedIds.append((long)anOwner.Access());
+      aSelectedIds.append((long)anOwner.get());
 
       fillPresentation(aPrs, anOwner);
 
@@ -123,8 +123,8 @@ void XGUI_Selection::fillPresentation(ModuleBase_ViewerPrsPtr& thePrs,
                                       const Handle(SelectMgr_EntityOwner)& theOwner) const
 {
   thePrs->setOwner(theOwner);
-
-  Handle(AIS_InteractiveObject) anIO = 
+  Handle(SelectMgr_SelectableObject) aSelectable = theOwner->Selectable();
+  Handle(AIS_InteractiveObject) anIO =
                            Handle(AIS_InteractiveObject)::DownCast(theOwner->Selectable());
   thePrs->setInteractive(anIO);
 
@@ -140,7 +140,7 @@ void XGUI_Selection::fillPresentation(ModuleBase_ViewerPrsPtr& thePrs,
       aShape = findAxisShape(anIO);
 #endif
     if (!aShape.IsNull()) {
-      std::shared_ptr<GeomAPI_Shape> aGeomShape = 
+      std::shared_ptr<GeomAPI_Shape> aGeomShape =
         std::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape());
       aGeomShape->setImpl(new TopoDS_Shape(aShape));
       thePrs->setShape(aGeomShape);
@@ -157,7 +157,7 @@ void XGUI_Selection::fillPresentation(ModuleBase_ViewerPrsPtr& thePrs,
       gp_Lin aLine = aAxis->Component()->Lin();
       gp_Dir aDir = aLine.Direction();
       std::string aAxName;
-      if (aDir.X() == 1.) 
+      if (aDir.X() == 1.)
         aAxName = "OX";
       else if (aDir.Y() == 1.)
         aAxName = "OY";
@@ -199,7 +199,7 @@ void XGUI_Selection::fillPresentation(ModuleBase_ViewerPrsPtr& thePrs,
     }
 #endif
   }
-     
+
   XGUI_Displayer* aDisplayer = myWorkshop->displayer();
   ObjectPtr aFeature = aDisplayer->getObject(anIO);
 
@@ -234,41 +234,23 @@ QList<ModuleBase_ViewerPrsPtr> XGUI_Selection::getHighlighted() const
   for (aContext->InitDetected(); aContext->MoreDetected(); aContext->NextDetected()) {
     Handle(SelectMgr_EntityOwner) anOwner = aContext->DetectedOwner();
     if (!anOwner.IsNull()) {
-      if (aSelectedIds.contains((long)anOwner.Access()))
+      if (aSelectedIds.contains((long)anOwner.get()))
         continue;
-      aSelectedIds.append((long)anOwner.Access());
+      aSelectedIds.append((long)anOwner.get());
 
       ModuleBase_ViewerPrsPtr aPrs(new ModuleBase_ViewerPrs());
       fillPresentation(aPrs, anOwner);
       aPresentations.push_back(aPrs);
     }
-    else { // TODO: check why the entity owner is null here, case is selection point on a line
-      Handle(AIS_InteractiveObject) anIO = aContext->DetectedInteractive();
-      ModuleBase_ViewerPrsPtr aPrs(new ModuleBase_ViewerPrs());
-      aPrs->setInteractive(anIO);
-
-      ObjectPtr aResult = aDisplayer->getObject(anIO);
-      // we should not check the appearance of this feature because there can be some selected
-      // shapes for one feature
-      aPrs->setObject(aResult);
-      if (aContext->HasOpenedContext()) {
-        TopoDS_Shape aShape = aContext->DetectedShape();
-        if (!aShape.IsNull()) {
-          std::shared_ptr<GeomAPI_Shape> aGeomShape = 
-            std::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape());
-          aGeomShape->setImpl(new TopoDS_Shape(aShape));
-          aPrs->setShape(aGeomShape);
-        }
-      }
-      aPresentations.push_back(aPrs);
-    }
   }
   return aPresentations;
 }
 
 QObjectPtrList XGUI_Selection::selectedObjects() const
 {
-  return myWorkshop->objectBrowser()->selectedObjects();
+  if (myWorkshop->objectBrowser())
+    return myWorkshop->objectBrowser()->selectedObjects();
+  return QObjectPtrList();
 }
 
 void XGUI_Selection::setSelectedObjects( const QObjectPtrList& theObjects ) const
@@ -317,7 +299,7 @@ ObjectPtr XGUI_Selection::getSelectableObject(const Handle(SelectMgr_EntityOwner
 
   Handle(SelectMgr_EntityOwner) aEO = theOwner;
   if (!aEO.IsNull()) {
-    Handle(AIS_InteractiveObject) anObj = 
+    Handle(AIS_InteractiveObject) anObj =
       Handle(AIS_InteractiveObject)::DownCast(aEO->Selectable());
     anObject = myWorkshop->displayer()->getObject(anObj);
   }
@@ -377,7 +359,7 @@ TopoDS_Shape XGUI_Selection::findAxisShape(Handle(AIS_InteractiveObject) theIO)
     Handle(Prs3d_DatumAspect) DA = aAxis->Attributes()->DatumAspect();
     Handle(Geom_TrimmedCurve) aTLine = new Geom_TrimmedCurve(aLine, 0, DA->FirstAxisLength());
 
-    BRep_Builder aBuilder;      
+    BRep_Builder aBuilder;
     TopoDS_Edge aEdge;
     aBuilder.MakeEdge(aEdge, aTLine, Precision::Confusion());
     if (!aEdge.IsNull())