Salome HOME
Rectangle correction to have coincidence with point/line selected for the first point...
[modules/shaper.git] / src / ModuleBase / ModuleBase_ResultPrs.cpp
index f7f360422b244a5d9320c29295624c15bb5faee5..3b32e56eef836e75c07ed6542088306ae578a01b 100755 (executable)
@@ -11,6 +11,8 @@
 #include <ModelAPI_ResultConstruction.h>
 #include <GeomAPI_PlanarEdges.h>
 
+#include <Events_Error.h>
+
 #include <BRep_Builder.hxx>
 #include <Prs3d_Drawer.hxx>
 #include <Prs3d.hxx>
@@ -23,6 +25,7 @@
 #include <StdPrs_WFDeflectionShape.hxx>
 #include <StdSelect_BRepSelectionTool.hxx>
 #include <AIS_InteractiveContext.hxx>
+#include <AIS_Selection.hxx>
 #include <TColStd_ListIteratorOfListOfInteger.hxx>
 
 
@@ -71,8 +74,10 @@ void ModuleBase_ResultPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& t
                                    const Standard_Integer theMode)
 {
   std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(myResult);
-  if (!aShapePtr)
+  if (!aShapePtr) {
+    Events_Error::throwException("An empty AIS presentation: ModuleBase_ResultPrs");
     return;
+  }
 
   if (myIsSketchMode) {
     myFacesList.clear();
@@ -93,6 +98,8 @@ void ModuleBase_ResultPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& t
     ModuleBase_Tools::setDefaultDeviationCoefficient(myOriginalShape, Attributes());
     AIS_Shape::Compute(thePresentationManager, thePresentation, theMode);
   }
+  else
+    Events_Error::throwException("An empty AIS presentation: ModuleBase_ResultPrs");
 }
 
 
@@ -134,8 +141,8 @@ void ModuleBase_ResultPrs::ComputeSelection(const Handle(SelectMgr_Selection)& a
           aDeflection, myDrawer->HLRAngle(), 9, 500);
 
         for (aSelection->Init(); aSelection->More(); aSelection->Next()) {
-          Handle(SelectMgr_EntityOwner) anOwner
-            = Handle(SelectMgr_EntityOwner)::DownCast (aSelection->Sensitive()->BaseSensitive()->OwnerId());
+          Handle(SelectMgr_EntityOwner) anOwner =
+            Handle(SelectMgr_EntityOwner)::DownCast(aSelection->Sensitive()->BaseSensitive()->OwnerId());
           anOwner->Set(this);
         }
         return;
@@ -183,17 +190,25 @@ TopoDS_Shape ModuleBase_ResultPrs::getSelectionShape() const
 void ModuleBase_ResultPrs::HilightSelected(const Handle(PrsMgr_PresentationManager3d)& thePM, 
                                            const SelectMgr_SequenceOfOwner& theOwners)
 {
-  TopoDS_Shape aShape = getSelectionShape();
-  if (!aShape.IsNull()) {
-    Handle( Prs3d_Presentation ) aSelectionPrs = GetSelectPresentation( thePM );
-    aSelectionPrs->Clear();
-
-    StdPrs_WFDeflectionShape::Add(aSelectionPrs, aShape, myDrawer);
-
-    aSelectionPrs->SetDisplayPriority(9);
-    aSelectionPrs->Highlight(Aspect_TOHM_COLOR, aSelectionPrs->HighlightColor());
-    aSelectionPrs->Display();
-    thePM->Highlight(this);
+  Handle(SelectMgr_EntityOwner) anOwner;
+  Handle(ModuleBase_BRepOwner) aCompOwner;
+  for (int i = 1; i <= theOwners.Length(); i++) {
+    anOwner = theOwners.Value(i);
+    aCompOwner = Handle(ModuleBase_BRepOwner)::DownCast(anOwner);
+    if (aCompOwner.IsNull())
+      anOwner->Hilight(thePM);
+    else {
+      TopoDS_Shape aShape = aCompOwner->Shape();
+      Handle( Prs3d_Presentation ) aSelectionPrs = GetSelectPresentation( thePM );
+      aSelectionPrs->Clear();
+
+      StdPrs_WFDeflectionShape::Add(aSelectionPrs, aShape, myDrawer);
+
+      aSelectionPrs->SetDisplayPriority(9);
+      aSelectionPrs->Highlight(Aspect_TOHM_COLOR, aSelectionPrs->HighlightColor());
+      aSelectionPrs->Display();
+      thePM->Highlight(this);
+    }
   }
 }
   
@@ -201,7 +216,11 @@ void ModuleBase_ResultPrs::HilightOwnerWithColor(const Handle(PrsMgr_Presentatio
                                                  const Quantity_NameOfColor theColor, 
                                                  const Handle(SelectMgr_EntityOwner)& theOwner)
 {
-  TopoDS_Shape aShape = getSelectionShape();
+  Handle(StdSelect_BRepOwner) aOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
+  if (aOwner.IsNull())
+    return;
+
+  TopoDS_Shape aShape = aOwner->Shape();
   if (!aShape.IsNull()) {
     thePM->Color(this, theColor);