From: nds Date: Thu, 27 Aug 2015 13:35:39 +0000 (+0300) Subject: Issue #849 (#775) Crash in second study during sketch operation X-Git-Tag: V_1.4.0_beta4~226 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=5ebfd3be8bf1d28be01c4edd749e73852591dd21;p=modules%2Fshaper.git Issue #849 (#775) Crash in second study during sketch operation Handle of operation presentation should be nullified when study is closed. --- diff --git a/src/ModuleBase/ModuleBase_IModule.h b/src/ModuleBase/ModuleBase_IModule.h index ae8e4645f..cf3177f98 100644 --- a/src/ModuleBase/ModuleBase_IModule.h +++ b/src/ModuleBase/ModuleBase_IModule.h @@ -146,6 +146,8 @@ class MODULEBASE_EXPORT ModuleBase_IModule : public QObject /// Returns data model object for representation of data tree in Object browser virtual ModuleBase_IDocumentDataModel* dataModel() const = 0; + virtual void closeDocument() = 0; + /// Returns a list of modes, where the AIS objects should be activated /// \param theModes a list of modes virtual void activeSelectionModes(QIntList& theModes) {} diff --git a/src/ModuleBase/ModuleBase_OperationFeature.h b/src/ModuleBase/ModuleBase_OperationFeature.h index c2eeb0087..0d2afdd9b 100755 --- a/src/ModuleBase/ModuleBase_OperationFeature.h +++ b/src/ModuleBase/ModuleBase_OperationFeature.h @@ -144,7 +144,7 @@ signals: /// If the operation works with feature which is sub-feature of another one /// then this variable has to be initialised by parent feature /// before operation feature creating - CompositeFeaturePtr myParentFeature; + CompositeFeaturePtr myParentFeature; /// Last current feature before editing operation. It is cashed when Edit operation is started /// in order to restore the document current feature on commit/abort this operation. diff --git a/src/PartSet/PartSet_CustomPrs.cpp b/src/PartSet/PartSet_CustomPrs.cpp index 008640c20..1457e0307 100755 --- a/src/PartSet/PartSet_CustomPrs.cpp +++ b/src/PartSet/PartSet_CustomPrs.cpp @@ -28,18 +28,10 @@ PartSet_CustomPrs::PartSet_CustomPrs(ModuleBase_IWorkshop* theWorkshop) : myWorkshop(theWorkshop) { - myOperationPrs = AISObjectPtr(new GeomAPI_AISObject()); - myOperationPrs->setImpl(new Handle(AIS_InteractiveObject)(new PartSet_OperationPrs(theWorkshop))); - - std::vector aColor = Config_PropManager::color("Visualization", "operation_parameter_color", - OPERATION_PARAMETER_COLOR); - myOperationPrs->setColor(aColor[0], aColor[1], aColor[2]); - - myOperationPrs->setPointMarker(5, 2.); - myOperationPrs->setWidth(1); + initPrs(); } -bool PartSet_CustomPrs::isActive() const +bool PartSet_CustomPrs::isActive() { Handle(PartSet_OperationPrs) anOperationPrs = getPresentation(); Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); @@ -74,7 +66,9 @@ void PartSet_CustomPrs::displayPresentation() Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); if (!aContext->IsDisplayed(anOperationPrs)) { PartSet_Module* aModule = dynamic_cast(myWorkshop->module()); - aContext->Display(anOperationPrs); + + XGUI_Workshop* aWorkshop = workshop(); + aWorkshop->displayer()->displayAIS(myOperationPrs, false/*load object in selection*/, true); aContext->SetZLayer(anOperationPrs, aModule->getVisualLayerId()); } else @@ -83,14 +77,14 @@ void PartSet_CustomPrs::displayPresentation() void PartSet_CustomPrs::erasePresentation() { - Handle(AIS_InteractiveObject) anOperationPrs = myOperationPrs->impl(); - Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); - if (aContext->IsDisplayed(anOperationPrs)) - aContext->Remove(anOperationPrs); + XGUI_Workshop* aWorkshop = workshop(); + aWorkshop->displayer()->eraseAIS(myOperationPrs, true); } -Handle(PartSet_OperationPrs) PartSet_CustomPrs::getPresentation() const +Handle(PartSet_OperationPrs) PartSet_CustomPrs::getPresentation() { + if (!myOperationPrs.get()) + initPrs(); Handle(AIS_InteractiveObject) anAISIO = myOperationPrs->impl(); return Handle(PartSet_OperationPrs)::DownCast(anAISIO); } @@ -110,3 +104,31 @@ void PartSet_CustomPrs::customize(const ObjectPtr& theObject) anOperationPrs->Redisplay(); } } + +void PartSet_CustomPrs::clearPrs() +{ + Handle(PartSet_OperationPrs) anOperationPrs = getPresentation(); + if (!anOperationPrs.IsNull()) + anOperationPrs.Nullify(); + + myOperationPrs = 0; +} + +void PartSet_CustomPrs::initPrs() +{ + myOperationPrs = AISObjectPtr(new GeomAPI_AISObject()); + myOperationPrs->setImpl(new Handle(AIS_InteractiveObject)(new PartSet_OperationPrs(myWorkshop))); + + std::vector aColor = Config_PropManager::color("Visualization", "operation_parameter_color", + OPERATION_PARAMETER_COLOR); + myOperationPrs->setColor(aColor[0], aColor[1], aColor[2]); + + myOperationPrs->setPointMarker(5, 2.); + myOperationPrs->setWidth(1); +} + +XGUI_Workshop* PartSet_CustomPrs::workshop() const +{ + XGUI_ModuleConnector* aConnector = dynamic_cast(myWorkshop); + return aConnector->workshop(); +} diff --git a/src/PartSet/PartSet_CustomPrs.h b/src/PartSet/PartSet_CustomPrs.h index b5fec271c..1c7494138 100755 --- a/src/PartSet/PartSet_CustomPrs.h +++ b/src/PartSet/PartSet_CustomPrs.h @@ -20,6 +20,7 @@ #include class ModuleBase_IWorkshop; +class XGUI_Workshop; /** * Interface of a class which can provide specific customization of @@ -32,7 +33,7 @@ public: PARTSET_EXPORT virtual ~PartSet_CustomPrs() {}; /// Returns true if the presentation is active - bool isActive() const; + bool isActive(); /// Initializes the presentation by the parameter object void activate(const FeaturePtr& theObject); @@ -42,9 +43,16 @@ public: /// Modifies the given presentation in the custom way. void customize(const ObjectPtr& theObject); + void clearPrs(); + + void initPrs(); + private: /// Returns the AIS presentation - Handle(PartSet_OperationPrs) getPresentation() const; + Handle(PartSet_OperationPrs) getPresentation(); + + //! Returns workshop + XGUI_Workshop* workshop() const; /// Displays the internal presentation in the viewer of workshop void displayPresentation(); diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 23741dfbd..6a1e23321 100755 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -405,6 +405,11 @@ bool PartSet_Module::isMouseOverWindow() return mySketchMgr->isMouseOverWindow(); } +void PartSet_Module::closeDocument() +{ + myCustomPrs->clearPrs(); +} + void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation) { ModuleBase_OperationFeature* aFOperation = dynamic_cast(theOperation); diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index d2f9c163b..449964b4d 100644 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -145,6 +145,8 @@ public: /// Returns data model object for representation of data tree in Object browser virtual ModuleBase_IDocumentDataModel* dataModel() const { return myDataModel; } + virtual void closeDocument(); + /// Event Listener method /// \param theMessage an event message virtual void processEvent(const std::shared_ptr& theMessage); diff --git a/src/PartSet/PartSet_WidgetSketchLabel.cpp b/src/PartSet/PartSet_WidgetSketchLabel.cpp index 73fd01d6c..e7f7e0d1c 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.cpp +++ b/src/PartSet/PartSet_WidgetSketchLabel.cpp @@ -365,9 +365,9 @@ void PartSet_WidgetSketchLabel::showPreviewPlanes() myXYPlane = createPreviewPlane(anOrigin, aXYDir, aB); } XGUI_Displayer* aDisp = workshop()->displayer(); - aDisp->displayAIS(myYZPlane, false); - aDisp->displayAIS(myXZPlane, false); - aDisp->displayAIS(myXYPlane, false); + aDisp->displayAIS(myYZPlane, true, false); + aDisp->displayAIS(myXZPlane, true, false); + aDisp->displayAIS(myXYPlane, true, false); myPreviewDisplayed = true; } diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index b20a2f246..f91e8fa08 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -576,15 +576,18 @@ void XGUI_Displayer::closeLocalContexts(const bool theUpdateViewer) //aContext->ClearSelected(); aContext->CloseAllContexts(false); + // From the moment when the AIS_DS_Displayed flag is used in the Display of AIS object, + // this code is obsolete. It is temporaty commented and should be removed after + // the test campaign. // Redisplay all object if they were displayed in localContext - Handle(AIS_InteractiveObject) aAISIO; + /*Handle(AIS_InteractiveObject) aAISIO; foreach (AISObjectPtr aAIS, myResult2AISObjectMap) { aAISIO = aAIS->impl(); if (aContext->DisplayStatus(aAISIO) != AIS_DS_Displayed) { aContext->Display(aAISIO, false); aContext->SetDisplayMode(aAISIO, Shading, false); } - } + }*/ // Append the filters from the local selection in the global selection context SelectMgr_ListIteratorOfListOfFilter aIt(aFilters); @@ -709,20 +712,25 @@ Handle(SelectMgr_AndFilter) XGUI_Displayer::GetFilter() return myAndFilter; } -void XGUI_Displayer::displayAIS(AISObjectPtr theAIS, bool theUpdateViewer) +void XGUI_Displayer::displayAIS(AISObjectPtr theAIS, const bool toActivateInSelectionModes, + bool theUpdateViewer) { Handle(AIS_InteractiveContext) aContext = AISContext(); if (aContext.IsNull()) return; Handle(AIS_InteractiveObject) anAISIO = theAIS->impl(); if (!anAISIO.IsNull()) { - aContext->Display(anAISIO, theUpdateViewer); - if (aContext->HasOpenedContext()) { - if (myActiveSelectionModes.size() == 0) - activateAIS(anAISIO, 0, theUpdateViewer); - else { - foreach(int aMode, myActiveSelectionModes) { - activateAIS(anAISIO, aMode, theUpdateViewer); + aContext->Display(anAISIO, 0/*wireframe*/, 0, theUpdateViewer, true, AIS_DS_Displayed); + aContext->Deactivate(anAISIO); + aContext->Load(anAISIO); + if (toActivateInSelectionModes) { + if (aContext->HasOpenedContext()) { + if (myActiveSelectionModes.size() == 0) + activateAIS(anAISIO, 0, theUpdateViewer); + else { + foreach(int aMode, myActiveSelectionModes) { + activateAIS(anAISIO, aMode, theUpdateViewer); + } } } } @@ -735,7 +743,7 @@ void XGUI_Displayer::eraseAIS(AISObjectPtr theAIS, const bool theUpdateViewer) if (aContext.IsNull()) return; Handle(AIS_InteractiveObject) anAISIO = theAIS->impl(); - if (!anAISIO.IsNull()) { + if (!anAISIO.IsNull() && aContext->IsDisplayed(anAISIO)) { aContext->Remove(anAISIO, theUpdateViewer); } } diff --git a/src/XGUI/XGUI_Displayer.h b/src/XGUI/XGUI_Displayer.h index c64bccb21..beefc2f48 100644 --- a/src/XGUI/XGUI_Displayer.h +++ b/src/XGUI/XGUI_Displayer.h @@ -67,10 +67,15 @@ class XGUI_EXPORT XGUI_Displayer: public QObject /// Returns true if the Feature succesfully displayed void display(ObjectPtr theObject, bool theUpdateViewer = true); - /// Display the given AIS object. To hide this object use corresponde erase method + /// Display the given AIS object. This object is not added to the displayer internal map of objects + /// So, it can not be obtained from displayer. This is just a wrap method of OCC display in order + /// to perform the display with correct flags. /// \param theAIS AIOS object to display + /// \param toActivateInSelectionModes boolean value whether the presentation should be + /// activated in the current selection modes /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly - void displayAIS(AISObjectPtr theAIS, bool theUpdateViewer = true); + void displayAIS(AISObjectPtr theAIS, const bool toActivateInSelectionModes, + bool theUpdateViewer = true); /** Redisplay the shape if it was displayed * \param theObject an object instance diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index facd2e428..02c06f646 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -1523,6 +1523,8 @@ void XGUI_Workshop::closeDocument() myDisplayer->eraseAll(); objectBrowser()->clearContent(); + module()->closeDocument(); + SessionPtr aMgr = ModelAPI_Session::get(); aMgr->closeAll(); }