Salome HOME
Issue #1015: The validate icon must be greyed and inactive instead of red and active
[modules/shaper.git] / src / ModuleBase / ModuleBase_ResultPrs.cpp
index 4491b273a64aa0d0c2e105381161c8d810e259a1..310bb78f87cae91d1c6dd9f67bf5d880ae5bb289 100755 (executable)
@@ -7,11 +7,13 @@
 #include "ModuleBase_ResultPrs.h"
 #include "ModuleBase_Tools.h"
 
+#include <ModelAPI_Events.h>
 #include <ModelAPI_Tools.h>
 #include <ModelAPI_ResultConstruction.h>
 #include <GeomAPI_PlanarEdges.h>
 
 #include <Events_Error.h>
+#include <Events_Loop.h>
 
 #include <BRep_Builder.hxx>
 #include <Prs3d_Drawer.hxx>
 #include <AIS_Selection.hxx>
 #include <TColStd_ListIteratorOfListOfInteger.hxx>
 
-//#define DEBUG_WIRE
-
-#ifdef DEBUG_WIRE
-#include <TopTools_IndexedMapOfShape.hxx>
-#include <TopExp.hxx>
-#endif
-
 IMPLEMENT_STANDARD_HANDLE(ModuleBase_BRepOwner, StdSelect_BRepOwner);
 IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_BRepOwner, StdSelect_BRepOwner);
 
@@ -48,18 +43,9 @@ IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_ResultPrs, ViewerData_AISShape);
 
 
 ModuleBase_ResultPrs::ModuleBase_ResultPrs(ResultPtr theResult)
-  : ViewerData_AISShape(TopoDS_Shape()), myResult(theResult), myIsSketchMode(false)
+  : ViewerData_AISShape(TopoDS_Shape()), myResult(theResult)
 {
   std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(theResult);
-  std::shared_ptr<GeomAPI_PlanarEdges> aWirePtr = 
-    std::dynamic_pointer_cast<GeomAPI_PlanarEdges>(aShapePtr);
-  if (aWirePtr) {
-    if (aWirePtr->hasPlane() ) {
-      // If this is a wire with plane defined thin it is a sketch-like object
-      // It must have invisible faces
-      myIsSketchMode = true;
-    }
-  }
   TopoDS_Shape aShape = aShapePtr->impl<TopoDS_Shape>();
   Set(aShape);
   Handle(Prs3d_Drawer) aDrawer = Attributes();
@@ -85,55 +71,27 @@ bool ModuleBase_ResultPrs::isValidShapeType(const TopAbs_ShapeEnum& theBaseType,
   return aValid;
 }
 
-
 void ModuleBase_ResultPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
                                    const Handle(Prs3d_Presentation)& thePresentation, 
                                    const Standard_Integer theMode)
 {
   std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(myResult);
-  if (!aShapePtr) {
-    Events_Error::throwException("An empty AIS presentation: ModuleBase_ResultPrs");
-    return;
-  }
-
-  if (myIsSketchMode) {
-    myFacesList.clear();
-    ResultConstructionPtr aConstruction = 
-      std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(myResult);
-    if (aConstruction.get()) {
-      int aFacesNum = aConstruction->facesNum();
-      for(int aFaceIndex = 0; aFaceIndex < aFacesNum; aFaceIndex++) {
-        myFacesList.push_back(aConstruction->face(aFaceIndex));
-      }
-    }
+  bool aReadyToDisplay = aShapePtr.get();
+  if (aReadyToDisplay) {
+    myOriginalShape = aShapePtr->impl<TopoDS_Shape>();
+    if (!myOriginalShape.IsNull())
+      Set(myOriginalShape);
   }
-  myOriginalShape = aShapePtr->impl<TopoDS_Shape>();
-  if (!myOriginalShape.IsNull()) {
-    Set(myOriginalShape);
+  // change deviation coefficient to provide more precise circle
+  ModuleBase_Tools::setDefaultDeviationCoefficient(Shape(), Attributes());
+  AIS_Shape::Compute(thePresentationManager, thePresentation, theMode);
 
-    // change deviation coefficient to provide more precise circle
-    ModuleBase_Tools::setDefaultDeviationCoefficient(myOriginalShape, Attributes());
-    AIS_Shape::Compute(thePresentationManager, thePresentation, theMode);
-  }
-  else
+  if (!aReadyToDisplay) {
     Events_Error::throwException("An empty AIS presentation: ModuleBase_ResultPrs");
-}
-
-#ifdef DEBUG_WIRE
-void debugInfo(const TopoDS_Shape& theShape, const TopAbs_ShapeEnum theType)
-{
-  TopTools_IndexedMapOfShape aSubShapes;
-  TopExp::MapShapes (theShape, theType, aSubShapes);
-
-  Standard_Boolean isComesFromDecomposition = !((aSubShapes.Extent() == 1) && (theShape == aSubShapes (1)));
-  int anExtent = aSubShapes.Extent();
-  for (Standard_Integer aShIndex = 1; aShIndex <= aSubShapes.Extent(); ++aShIndex)
-  {
-    const TopoDS_Shape& aSubShape = aSubShapes (aShIndex);
-    int aValue = 0;
+    static const Events_ID anEvent = Events_Loop::eventByName(EVENT_EMPTY_AIS_PRESENTATION);
+    ModelAPI_EventCreator::get()->sendUpdated(myResult, anEvent);
   }
 }
-#endif
 
 void ModuleBase_ResultPrs::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
                                             const Standard_Integer aMode)
@@ -142,37 +100,6 @@ void ModuleBase_ResultPrs::ComputeSelection(const Handle(SelectMgr_Selection)& a
     // In order to avoid using custom selection modes
     return;
 
-  if (myIsSketchMode) {
-    if (aMode == AIS_Shape::SelectionMode(TopAbs_FACE)) {
-#ifdef DEBUG_WIRE
-      const TopoDS_Shape& aShape = Shape();
-      debugInfo(aShape, TopAbs_VERTEX); // 24
-      debugInfo(aShape, TopAbs_EDGE); // 12
-      debugInfo(aShape, TopAbs_WIRE); // 0
-      debugInfo(aShape, TopAbs_FACE); // 0
-#endif
-      BRep_Builder aBuilder;
-      TopoDS_Compound aComp;
-      aBuilder.MakeCompound(aComp);
-      aBuilder.Add(aComp, myOriginalShape);
-      std::list<std::shared_ptr<GeomAPI_Shape>>::const_iterator aIt;
-      for (aIt = myFacesList.cbegin(); aIt != myFacesList.cend(); ++aIt) {
-        TopoDS_Shape aFace = (*aIt)->impl<TopoDS_Shape>();
-        aBuilder.Add(aComp, aFace);
-        // for sketch presentation in the face mode wires should be selectable also
-        // accoring to #1343 Improvement of Extrusion and Revolution operations
-        appendWiresSelection(aSelection, aFace);
-      }
-#ifdef DEBUG_WIRE
-      debugInfo(aComp, TopAbs_VERTEX); // 24
-      debugInfo(aComp, TopAbs_EDGE); // 12
-      debugInfo(aComp, TopAbs_WIRE); // 4
-      debugInfo(aComp, TopAbs_FACE); // 2
-#endif
-      Set(aComp);
-    } else
-      Set(myOriginalShape);
-  } 
   if (aMode == AIS_Shape::SelectionMode(TopAbs_COMPSOLID)) {
     // Limit selection area only by actual object (Shape)
     ResultCompSolidPtr aCompSolid = ModelAPI_Tools::compSolidOwner(myResult);
@@ -200,24 +127,6 @@ void ModuleBase_ResultPrs::ComputeSelection(const Handle(SelectMgr_Selection)& a
   AIS_Shape::ComputeSelection(aSelection, aMode);
 }
 
-
-bool ModuleBase_ResultPrs::hasCompSolidSelectionMode() const
-{
-  if (!HasInteractiveContext()) 
-    return false;
-
-  Handle(AIS_InteractiveContext) aContext = GetContext();
-  TColStd_ListOfInteger aModes;
-  aContext->ActivatedModes(this, aModes);
-
-  TColStd_ListIteratorOfListOfInteger aIt(aModes);
-  for (; aIt.More(); aIt.Next()) {
-    if (aIt.Value() == AIS_Shape::SelectionMode(TopAbs_COMPSOLID)) 
-      return true;
-  }
-  return false;
-}
-
 void ModuleBase_ResultPrs::appendWiresSelection(const Handle(SelectMgr_Selection)& theSelection,
                                                 const TopoDS_Shape& theShape)
 {
@@ -237,21 +146,6 @@ void ModuleBase_ResultPrs::appendWiresSelection(const Handle(SelectMgr_Selection
   }
 }
 
-TopoDS_Shape ModuleBase_ResultPrs::getSelectionShape() const
-{
-  if (hasCompSolidSelectionMode()) {
-    // In case of CompSolid mode use shape from Parent for highlighting
-    ResultCompSolidPtr aCompSolid = ModelAPI_Tools::compSolidOwner(myResult);
-    if (aCompSolid.get()) {
-      std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aCompSolid);
-      if (aShapePtr.get()) 
-        return aShapePtr->impl<TopoDS_Shape>();
-    }
-  } 
-  return myOriginalShape;
-}
-
-
 void ModuleBase_ResultPrs::HilightSelected(const Handle(PrsMgr_PresentationManager3d)& thePM, 
                                            const SelectMgr_SequenceOfOwner& theOwners)
 {