Salome HOME
Provide presentation for a step
authorvsv <vsv@opencascade.com>
Mon, 24 Jun 2019 15:54:37 +0000 (18:54 +0300)
committervsv <vsv@opencascade.com>
Mon, 24 Jun 2019 15:54:37 +0000 (18:54 +0300)
src/ModuleBase/ModuleBase_ResultPrs.cpp
src/ModuleBase/ModuleBase_ResultPrs.h
src/XGUI/XGUI_Displayer.cpp
src/XGUI/XGUI_Displayer.h
src/XGUI/XGUI_ObjectsBrowser.cpp
src/XGUI/XGUI_WorkshopListener.cpp

index 281f8e36cdadde2fa654b1b06e589f4833a08002..ff7a2b44bd6b66dddcdefb00464f82ec599b2a21 100644 (file)
@@ -70,6 +70,29 @@ ModuleBase_ResultPrs::ModuleBase_ResultPrs(ResultPtr 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);
+
+  init();
+}
+
+//********************************************************************
+ModuleBase_ResultPrs::ModuleBase_ResultPrs(FieldStepPtr theStep)
+  : ViewerData_AISShape(TopoDS_Shape()), myStep(theStep), myAdditionalSelectionPriority(0),
+  myTransparency(1), myIsSubstituted(false)
+{
+  GeomShapePtr aShapePtr = theStep->field()->shape();
+  TopoDS_Shape aShape = aShapePtr->impl<TopoDS_Shape>();
+  Set(aShape);
+
+  init();
+}
+
+
+//********************************************************************
+void ModuleBase_ResultPrs::init()
+{
   // Set own free boundaries aspect in order to have free
   // and unfree boundaries with different colors
   Handle(Prs3d_Drawer) aDrawer = Attributes();
@@ -82,11 +105,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);
@@ -97,6 +116,7 @@ ModuleBase_ResultPrs::ModuleBase_ResultPrs(ResultPtr theResult)
   setEdgesDefaultColor();
 }
 
+
 //********************************************************************
 void ModuleBase_ResultPrs::setAdditionalSelectionPriority(const int thePriority)
 {
@@ -113,31 +133,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);
+    }
   }
 }
 
@@ -239,13 +261,21 @@ bool ModuleBase_ResultPrs::setHiddenSubShapeTransparency(double theTransparency)
   return true;
 }
 
+//********************************************************************
+GeomShapePtr ModuleBase_ResultPrs::getOriginalShape() const
+{
+  if (myStep.get())
+    return myStep->field()->shape();
+  return myResult->shape();
+}
+
 //********************************************************************
 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);
+  std::shared_ptr<GeomAPI_Shape> aShapePtr = getOriginalShape();
   bool aReadyToDisplay = aShapePtr.get();
   if (aReadyToDisplay) {
     myOriginalShape = aShapePtr->impl<TopoDS_Shape>();
@@ -272,8 +302,6 @@ void ModuleBase_ResultPrs::Compute(
         aReadyToDisplay = false;
     }
   }
-  // change deviation coefficient to provide more precise circle
-  //ModuleBase_Tools::setDefaultDeviationCoefficient(myResult, Attributes());
   try {
     AIS_Shape::Compute(thePresentationManager, thePresentation, theMode);
   }
@@ -282,17 +310,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);
+    }
   }
 }
 
index f1ad5e1a0c2c588b59fe1d14e3543c1b486361a9..df01f95c0a241afba04c0194dc1e6f2e6058b3ee 100644 (file)
@@ -23,6 +23,7 @@
 #include "ModuleBase.h"
 
 #include <ModelAPI_Result.h>
+#include <ModelAPI_ResultField.h>
 
 #include <BRep_Builder.hxx>
 #include <NCollection_List.hxx>
@@ -56,6 +57,10 @@ public:
   /// \param theResult a result object
   Standard_EXPORT ModuleBase_ResultPrs(ResultPtr theResult);
 
+  /// Constructor
+  /// \param theResult a result object
+  Standard_EXPORT ModuleBase_ResultPrs(FieldStepPtr theStep);
+
   //! Method which draws selected owners ( for fast presentation draw )
   Standard_EXPORT virtual void HilightSelected(const Handle(PrsMgr_PresentationManager3d)& thePM,
                                                const SelectMgr_SequenceOfOwner& theOwners);
@@ -147,10 +152,17 @@ private:
 
   void setEdgesDefaultColor();
 
+  void init();
+
+  GeomShapePtr getOriginalShape() const;
+
 private:
   /// Reference to result object
   ResultPtr myResult;
 
+  /// Reference to step object (initialised is only or step or result)
+  FieldStepPtr myStep;
+
   /// Original shape of the result object
   TopoDS_Shape myOriginalShape;
 
index e83f1f14328bbe221d9e655f12e29f123d3bd95c..30f94ef70929ad744c19856f8bc2b01c9a579453 100644 (file)
@@ -38,6 +38,7 @@
 #include <ModelAPI_AttributeIntArray.h>
 #include <ModelAPI_ResultBody.h>
 #include <ModelAPI_ResultConstruction.h>
+#include <ModelAPI_ResultField.h>
 
 #include <ModuleBase_BRepOwner.h>
 #include <ModuleBase_IModule.h>
@@ -97,8 +98,6 @@ const int MOUSE_SENSITIVITY_IN_PIXEL = 10;
 //#define DEBUG_FEATURE_REDISPLAY
 //#define DEBUG_SELECTION_FILTERS
 
-//#define DEBUG_COMPOSILID_DISPLAY
-
 //#define DEBUG_OCCT_SHAPE_SELECTION
 
 #define CLEAR_OUTDATED_SELECTION_BEFORE_REDISPLAY
@@ -146,20 +145,6 @@ bool XGUI_Displayer::display(ObjectPtr theObject, bool theUpdateViewer)
 {
   bool aDisplayed = false;
   if (isVisible(theObject)) {
-#ifdef DEBUG_COMPOSILID_DISPLAY
-    ResultCompSolidPtr aCompsolidResult =
-      std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObject);
-    if (aCompsolidResult.get()) {
-      for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
-        ResultPtr aSubResult = aCompsolidResult->subResult(i);
-        if (aSubResult.get())
-          redisplay(aSubResult, false);
-      }
-      if (theUpdateViewer)
-        updateViewer();
-    }
-    else
-#endif
     aDisplayed = redisplay(theObject, theUpdateViewer);
   } else {
     AISObjectPtr anAIS;
@@ -172,54 +157,24 @@ bool XGUI_Displayer::display(ObjectPtr theObject, bool theUpdateViewer)
         aScreen->setViewScale(getViewScale());
       }
       anAIS = aPrs->getAISObject(anAIS);
-      //if (anAIS.get()) {
-        // correct deviation coefficient for
-        /*Handle(AIS_InteractiveObject) anAISPrs = anAIS->impl<Handle(AIS_InteractiveObject)>();
-        if (!anAISPrs.IsNull()) {
-          Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(anAISPrs);
-          if (!aShapePrs.IsNull()) {
-            TopoDS_Shape aShape = aShapePrs->Shape();
-            if (!aShape.IsNull())
-              //ModuleBase_Tools::setDefaultDeviationCoefficient(aShape, anAISPrs->Attributes());
-          }
-        }*/
-      //}
     } else {
       ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
       if (aResult.get() != NULL) {
-#ifdef DEBUG_COMPOSILID_DISPLAY
-        ResultCompSolidPtr aCompsolidResult =
-          std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObject);
-        if (aCompsolidResult.get()) {
-          for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
-            ResultPtr aSubResult = aCompsolidResult->subResult(i);
-            if (aSubResult.get())
-              display(aSubResult, false);
-          }
-          if (theUpdateViewer)
-            updateViewer();
-        }
-        else {
-#endif
-        std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
-        if (aShapePtr.get() != NULL) {
-          anAIS = AISObjectPtr(new GeomAPI_AISObject());
-          Handle(AIS_InteractiveObject) anAISPrs =
-            myWorkshop->module()->createPresentation(aResult);
-          if (anAISPrs.IsNull())
-            anAISPrs = new ModuleBase_ResultPrs(aResult);
-          else {
-            Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(anAISPrs);
-            if (!aShapePrs.IsNull())
-              ModuleBase_Tools::setPointBallHighlighting((AIS_Shape*) aShapePrs.get());
+        anAIS = createPresentation(aResult);
+        isShading = true;
+      }
+      else {
+        FieldStepPtr aStep =
+          std::dynamic_pointer_cast<ModelAPI_ResultField::ModelAPI_FieldStep>(theObject);
+        if (aStep) {
+          GeomShapePtr aShapePtr = aStep->field()->shape();
+          if (aShapePtr.get() != NULL) {
+            Handle(AIS_InteractiveObject) anAISPrs = new ModuleBase_ResultPrs(aStep);
+            anAIS = AISObjectPtr(new GeomAPI_AISObject());
+            anAIS->setImpl(new Handle(AIS_InteractiveObject)(anAISPrs));
+            isShading = true;
           }
-          anAIS->setImpl(new Handle(AIS_InteractiveObject)(anAISPrs));
-          //anAIS->createShape(aShapePtr);
-          isShading = true;
         }
-#ifdef DEBUG_COMPOSILID_DISPLAY
-        } // close else
-#endif
       }
     }
     if (anAIS)
@@ -228,6 +183,31 @@ bool XGUI_Displayer::display(ObjectPtr theObject, bool theUpdateViewer)
   return aDisplayed;
 }
 
+
+//**************************************************************
+AISObjectPtr XGUI_Displayer::createPresentation(const ResultPtr& theResult) const
+{
+  AISObjectPtr anAIS;
+  if (theResult.get() != NULL) {
+    std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(theResult);
+    if (aShapePtr.get() != NULL) {
+      anAIS = AISObjectPtr(new GeomAPI_AISObject());
+      Handle(AIS_InteractiveObject) anAISPrs =
+        myWorkshop->module()->createPresentation(theResult);
+      if (anAISPrs.IsNull())
+        anAISPrs = new ModuleBase_ResultPrs(theResult);
+      else {
+        Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(anAISPrs);
+        if (!aShapePrs.IsNull())
+          ModuleBase_Tools::setPointBallHighlighting((AIS_Shape*)aShapePrs.get());
+      }
+      anAIS->setImpl(new Handle(AIS_InteractiveObject)(anAISPrs));
+    }
+  }
+  return anAIS;
+}
+
+
 //**************************************************************
 bool canBeShaded(Handle(AIS_InteractiveObject) theAIS, ModuleBase_IModule* theModule)
 {
index cf1f5edc2dedf66f6caf8dd8a6d98ba06b5f5b96..df1237c43087d75b2510b67e3a3b8a8e758a0e49 100644 (file)
@@ -440,10 +440,12 @@ private:
     const NCollection_DataMap<TopoDS_Shape,
       NCollection_Map<Handle(AIS_InteractiveObject)>>& theShapesToBeSelected);
 
-protected:
+private:
   XGUI_SelectionActivate* selectionActivate() const;
 
-protected:
+  AISObjectPtr createPresentation(const ResultPtr& theResult) const;
+
+private:
   XGUI_Workshop* myWorkshop; ///< Reference to workshop
 #ifdef TINSPECTOR
   Handle(VInspectorAPI_CallBack) myVCallBack;
index e3dfb0935340a7b421e246d423425bd58f461229..6730df06b979fd515d9ca1798b90a0bff1686f80 100644 (file)
@@ -231,51 +231,75 @@ void XGUI_DataTree::processHistoryChange(const QModelIndex& theIndex)
 
 void XGUI_DataTree::processEyeClick(const QModelIndex& theIndex)
 {
+  static Events_Loop* aLoop = Events_Loop::loop();
+  static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
+  static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
+
   XGUI_DataModel* aModel = dataModel();
   ObjectPtr aObj = aModel->object(theIndex);
   if (aObj.get()) {
-    ResultPtr aResObj = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
     XGUI_ObjectsBrowser* aObjBrowser = qobject_cast<XGUI_ObjectsBrowser*>(parent());
-    if (aResObj.get()) {
-      std::set<ObjectPtr> anObjects;
-      anObjects.insert(aResObj);
-
-      bool hasHiddenState = aModel->hasHiddenState(theIndex);
-      if (aObjBrowser && hasHiddenState && !aObjBrowser->workshop()->prepareForDisplay(anObjects))
-        return;
-      if (hasHiddenState) { // #issue 2335(hide all faces then show solid problem)
-        if (aResObj->isDisplayed())
-          aResObj->setDisplayed(false);
-        aResObj->setDisplayed(true);
+    ResultFieldPtr aField = std::dynamic_pointer_cast<ModelAPI_ResultField>(aObj);
+    if (aField.get()) {
+      bool toDisplay = !aField->isDisplayed();
+      aField->setDisplayed(toDisplay);
+      if (toDisplay) {
+        for (int i = 0; i < aField->stepsSize(); i++) {
+          aField->step(i)->setDisplayed(false);
+          // TODO: Sending events has to be removed when step will be defined as Object
+          aECreator->sendUpdated(aField->step(i), EVENT_DISP);
+        }
       }
-      else
-        aResObj->setDisplayed(!aResObj->isDisplayed());
       Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
-      update(theIndex);
     }
     else {
       FieldStepPtr aStep =
         std::dynamic_pointer_cast<ModelAPI_ResultField::ModelAPI_FieldStep>(aObj);
       if (aStep.get()) {
         // Only one step from a field can be visible at once
-        int aId = aStep->id();
-        ModelAPI_ResultField* aField = aStep->field();
-        aField->setDisplayed(false);
-        for (int i = 0; i < aField->stepsSize(); i++) {
-          aField->step(i)->setDisplayed(i == aId);
-          static Events_Loop* aLoop = Events_Loop::loop();
-          static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
-          static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
-          aECreator->sendUpdated(aField->step(i), EVENT_DISP);
+        bool toDisplay = !aStep->isDisplayed();
+        if (toDisplay) {
+          int aId = aStep->id();
+          ModelAPI_ResultField* aField = aStep->field();
+          aField->setDisplayed(false);
+          for (int i = 0; i < aField->stepsSize(); i++) {
+            aField->step(i)->setDisplayed(i == aId);
+            // TODO: Sending events has to be removed when step will be defined as Object
+            aECreator->sendUpdated(aField->step(i), EVENT_DISP);
+          }
+        }
+        else {
+          aStep->setDisplayed(false);
+          aECreator->sendUpdated(aStep, EVENT_DISP);
         }
         Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
       }
+      else {
+        ResultPtr aResObj = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
+        if (aResObj.get()) {
+          std::set<ObjectPtr> anObjects;
+          anObjects.insert(aResObj);
+
+          bool hasHiddenState = aModel->hasHiddenState(theIndex);
+          if (aObjBrowser && hasHiddenState && !aObjBrowser->workshop()->prepareForDisplay(anObjects))
+            return;
+          if (hasHiddenState) { // #issue 2335(hide all faces then show solid problem)
+            if (aResObj->isDisplayed())
+              aResObj->setDisplayed(false);
+            aResObj->setDisplayed(true);
+          }
+          else
+            aResObj->setDisplayed(!aResObj->isDisplayed());
+          Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
+        }
+      }
     }
     // Update list of selected objects because this event happens after
     // selection event in object browser
     if (aObjBrowser) {
       aObjBrowser->onSelectionChanged();
     }
+    update(theIndex);
   }
 }
 
index 5796ddef17d4d8b1262bf596482766279863fe48..c58f65782a2602b0f377fa6a1b14d3d07314d72c 100644 (file)
@@ -38,6 +38,7 @@
 #include <ModelAPI_Feature.h>
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Tools.h>
+#include <ModelAPI_ResultField.h>
 
 #include <ModuleBase_Events.h>
 #include <ModuleBase_IModule.h>
@@ -270,8 +271,16 @@ void XGUI_WorkshopListener::
     ObjectPtr aObj = (*aIt);
 
     // Hide the object if it is invalid or concealed one
-    bool aHide = !aObj->data() || !aObj->data()->isValid() ||
-      aObj->isDisabled() || (!aObj->isDisplayed());
+    //bool aHide = !aObj->data() || !aObj->data()->isValid() ||
+    //  aObj->isDisabled() || (!aObj->isDisplayed());
+    // TODO: Remove the Hide code as soon as a fields step will become as object
+    bool aHide = false;
+    if (aObj->groupName() == ModelAPI_ResultField::ModelAPI_FieldStep::group())
+      aHide = !aObj->isDisplayed();
+    else
+      aHide = !aObj->data() || !aObj->data()->isValid() ||
+        aObj->isDisabled() || (!aObj->isDisplayed());
+
     if (!aHide) { // check that this is not hidden result
       ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
       aHide = aRes && aRes->isConcealed();