Salome HOME
Merge remote-tracking branch 'remotes/origin/Filters_Development_2'
[modules/shaper.git] / src / ModuleBase / ModuleBase_ResultPrs.cpp
index 11ab42dc67af2d85f29e2814faea8d6f9850fd64..e2d35c87b2a8111facc8ebd31d15db737b151aee 100644 (file)
@@ -64,12 +64,16 @@ IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_ResultPrs, ViewerData_AISShape);
 //********************************************************************
 ModuleBase_ResultPrs::ModuleBase_ResultPrs(ResultPtr theResult)
   : ViewerData_AISShape(TopoDS_Shape()), myResult(theResult), myAdditionalSelectionPriority(0),
-  myTransparency(1)
+  myTransparency(1), myIsSubstituted(false)
 {
   std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(theResult);
   TopoDS_Shape aShape = aShapePtr->impl<TopoDS_Shape>();
   Set(aShape);
 
+  // Activate individual repaintng if this is a part of compsolid
+  ResultBodyPtr aResOwner = ModelAPI_Tools::bodyOwner(myResult);
+  SetAutoHilight(aResOwner.get() == NULL);
+
   // Set own free boundaries aspect in order to have free
   // and unfree boundaries with different colors
   Handle(Prs3d_Drawer) aDrawer = Attributes();
@@ -82,11 +86,7 @@ ModuleBase_ResultPrs::ModuleBase_ResultPrs(ResultPtr theResult)
   else
     aDrawer->SetPointAspect(new Prs3d_PointAspect(Aspect_TOM_PLUS, Quantity_NOC_YELLOW, 1.));
 
-  // Activate individual repaintng if this is a part of compsolid
-  ResultBodyPtr aResOwner = ModelAPI_Tools::bodyOwner(myResult);
-  SetAutoHilight(aResOwner.get() == NULL);
-
-  myHiddenSubShapesDrawer = new AIS_ColoredDrawer (myDrawer);
+  myHiddenSubShapesDrawer = new AIS_ColoredDrawer(myDrawer);
   Handle(Prs3d_ShadingAspect) aShadingAspect = new Prs3d_ShadingAspect();
   aShadingAspect->SetMaterial(Graphic3d_NOM_BRASS); //default value of context material
   myHiddenSubShapesDrawer->SetShadingAspect(aShadingAspect);
@@ -113,31 +113,33 @@ void ModuleBase_ResultPrs::SetColor (const Quantity_Color& theColor)
 
 void ModuleBase_ResultPrs::setEdgesDefaultColor()
 {
-  AttributeIntArrayPtr aColorAttr = myResult->data()->intArray(ModelAPI_Result::COLOR_ID());
-  bool aHasColor = aColorAttr.get() && aColorAttr->isInitialized();
-
-  if (!aHasColor) {
-    Handle(Prs3d_Drawer) aDrawer = Attributes();
-    Handle(Prs3d_LineAspect) anAspect; // = aDrawer->LineAspect();
-    //anAspect->SetColor(Quantity_NOC_YELLOW);
-    //aDrawer->SetLineAspect(anAspect);
-
-    // - unfree boundaries color
-    anAspect = aDrawer->UnFreeBoundaryAspect();
-    anAspect->SetColor(Quantity_NOC_YELLOW);
-    aDrawer->SetUnFreeBoundaryAspect(anAspect);
-    aDrawer->SetUnFreeBoundaryDraw(true);
-
-    // - free boundaries color
-    anAspect = aDrawer->FreeBoundaryAspect();
-    anAspect->SetColor(Quantity_NOC_GREEN);
-    aDrawer->SetFreeBoundaryAspect(anAspect);
-    aDrawer->SetFreeBoundaryDraw(true);
-
-    // - standalone edges color
-    anAspect = aDrawer->WireAspect();
-    anAspect->SetColor(Quantity_NOC_RED);
-    aDrawer->SetWireAspect(anAspect);
+  if (myResult.get()) {
+    AttributeIntArrayPtr aColorAttr = myResult->data()->intArray(ModelAPI_Result::COLOR_ID());
+    bool aHasColor = aColorAttr.get() && aColorAttr->isInitialized();
+
+    if (!aHasColor) {
+      Handle(Prs3d_Drawer) aDrawer = Attributes();
+      Handle(Prs3d_LineAspect) anAspect; // = aDrawer->LineAspect();
+      //anAspect->SetColor(Quantity_NOC_YELLOW);
+      //aDrawer->SetLineAspect(anAspect);
+
+      // - unfree boundaries color
+      anAspect = aDrawer->UnFreeBoundaryAspect();
+      anAspect->SetColor(Quantity_NOC_YELLOW);
+      aDrawer->SetUnFreeBoundaryAspect(anAspect);
+      aDrawer->SetUnFreeBoundaryDraw(true);
+
+      // - free boundaries color
+      anAspect = aDrawer->FreeBoundaryAspect();
+      anAspect->SetColor(Quantity_NOC_GREEN);
+      aDrawer->SetFreeBoundaryAspect(anAspect);
+      aDrawer->SetFreeBoundaryDraw(true);
+
+      // - standalone edges color
+      anAspect = aDrawer->WireAspect();
+      anAspect->SetColor(Quantity_NOC_RED);
+      aDrawer->SetWireAspect(anAspect);
+    }
   }
 }
 
@@ -150,30 +152,44 @@ bool ModuleBase_ResultPrs::setSubShapeHidden(const NCollection_List<TopoDS_Shape
   TopoDS_Compound aCompound;
   BRep_Builder aBBuilder;
   aBBuilder.MakeCompound (aCompound);
+
+  TopoDS_Compound aShownComp;
+  if (myIsSubstituted)
+    aShownComp = TopoDS::Compound(Shape());
+
   // restore hidden shapes if there are not the shapes in parameter container
   NCollection_List<TopoDS_Shape> aVisibleSubShapes;
-  for (NCollection_List<TopoDS_Shape>::Iterator aHiddenIt(myHiddenSubShapes); aHiddenIt.More();
-       aHiddenIt.Next()) {
-    if (!theShapes.Contains(aHiddenIt.Value()))
+  NCollection_List<TopoDS_Shape>::Iterator aHiddenIt(myHiddenSubShapes);
+  for (; aHiddenIt.More(); aHiddenIt.Next()) {
+    if (!theShapes.Contains(aHiddenIt.Value())) {
       aVisibleSubShapes.Append(aHiddenIt.Value());
-    else
-      aBBuilder.Add (aCompound, aHiddenIt.Value());
+    }
+    else {
+      aBBuilder.Add(aCompound, aHiddenIt.Value());
+      if (!aShownComp.IsNull())
+        aBBuilder.Remove(aShownComp, aHiddenIt.Value());
+    }
   }
   isModified = !aVisibleSubShapes.IsEmpty();
-  for (NCollection_List<TopoDS_Shape>::Iterator aVisibleIt(aVisibleSubShapes); aVisibleIt.More();
-       aVisibleIt.Next())
-    myHiddenSubShapes.Remove(aVisibleIt.Value());
-
+  NCollection_List<TopoDS_Shape>::Iterator aVisibleIt(aVisibleSubShapes);
+  for (; aVisibleIt.More(); aVisibleIt.Next()) {
+    if (myHiddenSubShapes.Contains(aVisibleIt.Value())) {
+      myHiddenSubShapes.Remove(aVisibleIt.Value());
+      if (!aShownComp.IsNull())
+        aBBuilder.Add(aShownComp, aVisibleIt.Value());
+    }
+  }
   // append hidden shapes into internal container if there are not these shapes
-  for (NCollection_List<TopoDS_Shape>::Iterator aShapeIt(theShapes); aShapeIt.More();
-    aShapeIt.Next())
-  {
+  NCollection_List<TopoDS_Shape>::Iterator aShapeIt(theShapes);
+  for (; aShapeIt.More(); aShapeIt.Next()) {
     if (aShapeIt.Value().ShapeType() != TopAbs_FACE) // only face shape can be hidden
       continue;
 
     if (!myHiddenSubShapes.Contains(aShapeIt.Value())) {
       myHiddenSubShapes.Append(aShapeIt.Value());
       aBBuilder.Add (aCompound, aShapeIt.Value());
+      if (!aShownComp.IsNull())
+        aBBuilder.Remove(aShownComp, aShapeIt.Value());
       isModified = true;
     }
   }
@@ -231,27 +247,33 @@ void ModuleBase_ResultPrs::Compute(
           const Handle(Prs3d_Presentation)& thePresentation,
           const Standard_Integer theMode)
 {
-  std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(myResult);
+  std::shared_ptr<GeomAPI_Shape> aShapePtr = myResult->shape();
   bool aReadyToDisplay = aShapePtr.get();
   if (aReadyToDisplay) {
     myOriginalShape = aShapePtr->impl<TopoDS_Shape>();
     if (myHiddenSubShapes.IsEmpty() || myOriginalShape.ShapeType() > TopAbs_FACE ) {
-      if (!myOriginalShape.IsNull())
+      if (!myOriginalShape.IsNull()) {
         Set(myOriginalShape);
+        myIsSubstituted = false;
+      }
     }
     else { // convert shape into SHELL
       TopoDS_Compound aCompound;
-      BRep_Builder aBuilder;
-      aBuilder.MakeCompound (aCompound);
-      collectSubShapes(aBuilder, aCompound, myOriginalShape, myHiddenSubShapes);
+      if (!myIsSubstituted) {
+        BRep_Builder aBuilder;
+        aBuilder.MakeCompound(aCompound);
+        collectSubShapes(aBuilder, aCompound, myOriginalShape, myHiddenSubShapes);
+      }
+      else {
+        aCompound = TopoDS::Compound(Shape());
+      }
       bool isEmptyShape = BOPTools_AlgoTools3D::IsEmptyShape(aCompound);
       Set(aCompound);
+      myIsSubstituted = true;
       if (isEmptyShape)
         aReadyToDisplay = false;
     }
   }
-  // change deviation coefficient to provide more precise circle
-  //ModuleBase_Tools::setDefaultDeviationCoefficient(myResult, Attributes());
   try {
     AIS_Shape::Compute(thePresentationManager, thePresentation, theMode);
   }
@@ -260,17 +282,19 @@ void ModuleBase_ResultPrs::Compute(
   }
 
   // visualize hidden sub-shapes transparent
-  if (myTransparency < 1 && !myHiddenSubShapes.IsEmpty())
-  {
-    StdPrs_ShadedShape::Add (thePresentation, myHiddenCompound, myHiddenSubShapesDrawer);
-    aReadyToDisplay = true;
-  }
+  if (myResult.get()) {
+    if (myTransparency < 1 && !myHiddenSubShapes.IsEmpty())
+    {
+      StdPrs_ShadedShape::Add(thePresentation, myHiddenCompound, myHiddenSubShapesDrawer);
+      aReadyToDisplay = true;
+    }
 
-  if (!aReadyToDisplay) {
-    Events_InfoMessage("ModuleBase_ResultPrs",
-                       "An empty AIS presentation: ModuleBase_ResultPrs").send();
-    static const Events_ID anEvent = Events_Loop::eventByName(EVENT_EMPTY_AIS_PRESENTATION);
-    ModelAPI_EventCreator::get()->sendUpdated(myResult, anEvent);
+    if (!aReadyToDisplay) {
+      Events_InfoMessage("ModuleBase_ResultPrs",
+        "An empty AIS presentation: ModuleBase_ResultPrs").send();
+      static const Events_ID anEvent = Events_Loop::eventByName(EVENT_EMPTY_AIS_PRESENTATION);
+      ModelAPI_EventCreator::get()->sendUpdated(myResult, anEvent);
+    }
   }
 }