Salome HOME
Task "Make the size of the selection area even bigger, especially for points"
[modules/shaper.git] / src / PartSet / PartSet_ResultSketchPrs.cpp
index 04d9318eabb70215e7688025b63059ad978b19ed..d23125683ca8ae9868af9b340982a876810e5b84 100755 (executable)
 #include <ModelAPI_ResultConstruction.h>
 #include <GeomAPI_PlanarEdges.h>
 
-#include <Events_Error.h>
+#include <Events_InfoMessage.h>
 #include <Events_Loop.h>
 
 #include <SketchPlugin_SketchEntity.h>
 
+#include <SketcherPrs_Tools.h>
+
 #include <Config_PropManager.h>
 
 #include <BRep_Builder.hxx>
@@ -61,21 +63,9 @@ PartSet_ResultSketchPrs::PartSet_ResultSketchPrs(ResultPtr theResult)
   SetAutoHilight(aCompSolid.get() == NULL);
 }
 
-bool PartSet_ResultSketchPrs::isValidShapeType(const TopAbs_ShapeEnum& theBaseType,
-                                            const TopAbs_ShapeEnum& theCheckedType)
-{
-  bool aValid = theBaseType == theCheckedType;
-  if (!aValid) {
-    // currently this functionality is for all, as we have no separate wire selection mode
-    // lately it should be corrected to have the following check only for sketch presentations
-    aValid = theBaseType == TopAbs_FACE && theCheckedType == TopAbs_WIRE;
-  }
-  return aValid;
-}
-
 void PartSet_ResultSketchPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
-                                   const Handle(Prs3d_Presentation)& thePresentation, 
-                                   const Standard_Integer theMode)
+                                      const Handle(Prs3d_Presentation)& thePresentation, 
+                                      const Standard_Integer theMode)
 {
   thePresentation->Clear();
 
@@ -84,21 +74,21 @@ void PartSet_ResultSketchPrs::Compute(const Handle(PrsMgr_PresentationManager3d)
   NCollection_List<TopoDS_Shape> aFaceList;
   fillShapes(aResultShape, anAuxiliaryCompound, mySketchFaceList);
 
-  bool isEmptyPresentation = aResultShape.IsNull() && anAuxiliaryCompound.IsNull();
+  bool aReadyToDisplay = !aResultShape.IsNull() || !anAuxiliaryCompound.IsNull();
 
-  if (!aResultShape.IsNull()) {
-    myOriginalShape = aResultShape;
-    if (!myOriginalShape.IsNull())
-      Set(myOriginalShape);
-  }
-
-  if (!anAuxiliaryCompound.IsNull())
+  if (aReadyToDisplay) {
+    if (!aResultShape.IsNull()) {
+      myOriginalShape = aResultShape;
+      if (!myOriginalShape.IsNull())
+        Set(myOriginalShape);
+    }
     myAuxiliaryCompound = anAuxiliaryCompound;
+  }
 
   setAuxiliaryPresentationStyle(false);
 
-    // change deviation coefficient to provide more precise circle
-  ModuleBase_Tools::setDefaultDeviationCoefficient(Shape(), Attributes());
+  // change deviation coefficient to provide more precise circle
+  ModuleBase_Tools::setDefaultDeviationCoefficient(myResult, Attributes());
   AIS_Shape::Compute(thePresentationManager, thePresentation, theMode);
 
   if (!myAuxiliaryCompound.IsNull()) {
@@ -108,8 +98,8 @@ void PartSet_ResultSketchPrs::Compute(const Handle(PrsMgr_PresentationManager3d)
     StdPrs_WFDeflectionShape::Add(thePresentation, myAuxiliaryCompound, aDrawer);
   }
 
-  if (isEmptyPresentation) {
-    Events_Error::throwException("An empty AIS presentation: PartSet_ResultSketchPrs");
+  if (!aReadyToDisplay) {
+    Events_InfoMessage("PartSet_ResultSketchPrs", "An empty AIS presentation: PartSet_ResultSketchPrs").send();
     static const Events_ID anEvent = Events_Loop::eventByName(EVENT_EMPTY_AIS_PRESENTATION);
     ModelAPI_EventCreator::get()->sendUpdated(myResult, anEvent);
   }
@@ -132,13 +122,21 @@ void debugInfo(const TopoDS_Shape& theShape, const TopAbs_ShapeEnum theType)
 #endif
 
 void PartSet_ResultSketchPrs::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
-                                            const Standard_Integer aMode)
+                                            const Standard_Integer theMode)
 {
-  if (aMode > 8)
+  int aMode = theMode;
+
+  if (aMode > 8 &&
+      aMode != SketcherPrs_Tools::Sel_Sketch_Face &&
+      aMode != SketcherPrs_Tools::Sel_Sketch_Wire)
     // In order to avoid using custom selection modes
     return;
 
-  if (aMode == AIS_Shape::SelectionMode(TopAbs_FACE)) {
+  bool aShapeIsChanged = false;
+  if (aMode == SketcherPrs_Tools::Sel_Sketch_Face ||
+      aMode == SketcherPrs_Tools::Sel_Sketch_Wire) {
+    aMode = (aMode == SketcherPrs_Tools::Sel_Sketch_Face) ? AIS_Shape::SelectionMode(TopAbs_FACE)
+                                                          : AIS_Shape::SelectionMode(TopAbs_WIRE);
 #ifdef DEBUG_WIRE
     const TopoDS_Shape& aShape = Shape();
     debugInfo(aShape, TopAbs_VERTEX); // 24
@@ -154,9 +152,6 @@ void PartSet_ResultSketchPrs::ComputeSelection(const Handle(SelectMgr_Selection)
     for(NCollection_List<TopoDS_Shape>::Iterator anIt(mySketchFaceList); anIt.More(); anIt.Next()) {
       const TopoDS_Shape& aFace = anIt.Value();
       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
-      appendShapeSelection(aSelection, aFace, TopAbs_WIRE);
     }
 #ifdef DEBUG_WIRE
     debugInfo(aComp, TopAbs_VERTEX); // 24
@@ -165,18 +160,23 @@ void PartSet_ResultSketchPrs::ComputeSelection(const Handle(SelectMgr_Selection)
     debugInfo(aComp, TopAbs_FACE); // 2
 #endif
     Set(aComp);
-  } else
+    aShapeIsChanged = true;
+  }
+  else
     Set(myOriginalShape);
 
   // append auxiliary compound to selection of edges/vertices
   if (aMode == AIS_Shape::SelectionMode(TopAbs_EDGE) ||
       aMode == AIS_Shape::SelectionMode(TopAbs_VERTEX)) {
 
-        bool isVertex = aMode == AIS_Shape::SelectionMode(TopAbs_VERTEX);
+    bool isVertex = aMode == AIS_Shape::SelectionMode(TopAbs_VERTEX);
     appendShapeSelection(aSelection, myAuxiliaryCompound, isVertex ? TopAbs_VERTEX : TopAbs_EDGE);
   }
 
   AIS_Shape::ComputeSelection(aSelection, aMode);
+
+  if (aShapeIsChanged)
+    Set(myOriginalShape);
 }
 
 void PartSet_ResultSketchPrs::appendShapeSelection(const Handle(SelectMgr_Selection)& theSelection,
@@ -210,9 +210,9 @@ void PartSet_ResultSketchPrs::setAuxiliaryPresentationStyle(const bool isAuxilia
     aLineStyle = SketchPlugin_SketchEntity::SKETCH_LINE_STYLE();
   }
   else {
-    aColor = Config_PropManager::color("Visualization", "sketch_auxiliary_color",
-                                         SKETCH_AUXILIARY_COLOR);
-    aWidth = SketchPlugin_SketchEntity::SKETCH_LINE_WIDTH_AUXILIARY();
+    aColor = Config_PropManager::color("Visualization", "result_construction_color",
+                                        ModelAPI_ResultConstruction::DEFAULT_COLOR());
+    aWidth = PartSet_Tools::getAISDefaultWidth();// default width value
     aLineStyle = SketchPlugin_SketchEntity::SKETCH_LINE_STYLE_AUXILIARY();
   }