From 5fc0009dcf8207a684f84f64c746ad421346a72f Mon Sep 17 00:00:00 2001 From: vsv Date: Mon, 24 Jun 2019 18:54:37 +0300 Subject: [PATCH] Provide presentation for a step --- src/ModuleBase/ModuleBase_ResultPrs.cpp | 116 +++++++++++++++--------- src/ModuleBase/ModuleBase_ResultPrs.h | 12 +++ src/XGUI/XGUI_Displayer.cpp | 98 ++++++++------------ src/XGUI/XGUI_Displayer.h | 6 +- src/XGUI/XGUI_ObjectsBrowser.cpp | 72 ++++++++++----- src/XGUI/XGUI_WorkshopListener.cpp | 13 ++- 6 files changed, 187 insertions(+), 130 deletions(-) diff --git a/src/ModuleBase/ModuleBase_ResultPrs.cpp b/src/ModuleBase/ModuleBase_ResultPrs.cpp index 281f8e36c..ff7a2b44b 100644 --- a/src/ModuleBase/ModuleBase_ResultPrs.cpp +++ b/src/ModuleBase/ModuleBase_ResultPrs.cpp @@ -70,6 +70,29 @@ ModuleBase_ResultPrs::ModuleBase_ResultPrs(ResultPtr theResult) TopoDS_Shape aShape = aShapePtr->impl(); 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(); + 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 aShapePtr = ModelAPI_Tools::shape(myResult); + std::shared_ptr aShapePtr = getOriginalShape(); bool aReadyToDisplay = aShapePtr.get(); if (aReadyToDisplay) { myOriginalShape = aShapePtr->impl(); @@ -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); + } } } diff --git a/src/ModuleBase/ModuleBase_ResultPrs.h b/src/ModuleBase/ModuleBase_ResultPrs.h index f1ad5e1a0..df01f95c0 100644 --- a/src/ModuleBase/ModuleBase_ResultPrs.h +++ b/src/ModuleBase/ModuleBase_ResultPrs.h @@ -23,6 +23,7 @@ #include "ModuleBase.h" #include +#include #include #include @@ -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; diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index e83f1f143..30f94ef70 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include @@ -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(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(); - 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(theObject); if (aResult.get() != NULL) { -#ifdef DEBUG_COMPOSILID_DISPLAY - ResultCompSolidPtr aCompsolidResult = - std::dynamic_pointer_cast(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 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(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 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) { diff --git a/src/XGUI/XGUI_Displayer.h b/src/XGUI/XGUI_Displayer.h index cf1f5edc2..df1237c43 100644 --- a/src/XGUI/XGUI_Displayer.h +++ b/src/XGUI/XGUI_Displayer.h @@ -440,10 +440,12 @@ private: const NCollection_DataMap>& 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; diff --git a/src/XGUI/XGUI_ObjectsBrowser.cpp b/src/XGUI/XGUI_ObjectsBrowser.cpp index e3dfb0935..6730df06b 100644 --- a/src/XGUI/XGUI_ObjectsBrowser.cpp +++ b/src/XGUI/XGUI_ObjectsBrowser.cpp @@ -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(aObj); XGUI_ObjectsBrowser* aObjBrowser = qobject_cast(parent()); - if (aResObj.get()) { - std::set 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(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(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(aObj); + if (aResObj.get()) { + std::set 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); } } diff --git a/src/XGUI/XGUI_WorkshopListener.cpp b/src/XGUI/XGUI_WorkshopListener.cpp index 5796ddef1..c58f65782 100644 --- a/src/XGUI/XGUI_WorkshopListener.cpp +++ b/src/XGUI/XGUI_WorkshopListener.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include @@ -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(aObj); aHide = aRes && aRes->isConcealed(); -- 2.39.2