Salome HOME
Issue #849 (#775) Crash in second study during sketch operation
authornds <nds@opencascade.com>
Thu, 27 Aug 2015 13:35:39 +0000 (16:35 +0300)
committernds <nds@opencascade.com>
Thu, 27 Aug 2015 13:35:39 +0000 (16:35 +0300)
Handle of operation presentation should be nullified when study is closed.

src/ModuleBase/ModuleBase_IModule.h
src/ModuleBase/ModuleBase_OperationFeature.h
src/PartSet/PartSet_CustomPrs.cpp
src/PartSet/PartSet_CustomPrs.h
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_Module.h
src/PartSet/PartSet_WidgetSketchLabel.cpp
src/XGUI/XGUI_Displayer.cpp
src/XGUI/XGUI_Displayer.h
src/XGUI/XGUI_Workshop.cpp

index ae8e4645f877febdc27d074d7573c9e303a6d379..cf3177f98314750692ff97dfc670a57a56eb4fe7 100644 (file)
@@ -146,6 +146,8 @@ class MODULEBASE_EXPORT ModuleBase_IModule : public QObject
   /// Returns data model object for representation of data tree in Object browser\r
   virtual ModuleBase_IDocumentDataModel* dataModel() const = 0;\r
 \r
+  virtual void closeDocument() = 0;\r
+\r
   /// Returns a list of modes, where the AIS objects should be activated\r
   /// \param theModes a list of modes\r
   virtual void activeSelectionModes(QIntList& theModes) {}\r
index c2eeb0087459168239810d314131e1a948605d75..0d2afdd9ba8e7dcdd5116f9aa5f559c3191ad970 100755 (executable)
@@ -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.
index 008640c20275c9e0de40b651ea83e36aaa0f4af3..1457e0307cd5a2cad622ddac5c3b07b4405762bc 100755 (executable)
 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<int> 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<PartSet_Module*>(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_InteractiveObject)>();
-  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<Handle(AIS_InteractiveObject)>();
   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<int> 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<XGUI_ModuleConnector*>(myWorkshop);
+  return aConnector->workshop();
+}
index b5fec271cb19ba45364cbca0665e01cebf07cff7..1c749413817d516dfefabd1e82798315cb95ce68 100755 (executable)
@@ -20,6 +20,7 @@
 #include <GeomAPI_Shape.h>
 
 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();
index 23741dfbdc94ab6996f10fa8ddfdbb555ba5cf8d..6a1e233216cbe9d83b0a6d60fac8f9f03e80e4ed 100755 (executable)
@@ -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<ModuleBase_OperationFeature*>(theOperation);
index d2f9c163b48239808792d3debfd1f1057a8dc407..449964b4dae131cd36ba9a9e5d5d27238c54de2b 100644 (file)
@@ -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<Events_Message>& theMessage);
index 73fd01d6cb8743a0ead06e0601b5538ea222fdf6..e7f7e0d1c564ee074d1d91a4d3b4b3abf130eb74 100644 (file)
@@ -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;
 }
 
index b20a2f24620ffcca612e6567d58c203c886cd431..f91e8fa082e307d497e471feb7524cef706fb24f 100644 (file)
@@ -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<Handle(AIS_InteractiveObject)>();
       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<Handle(AIS_InteractiveObject)>();
   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<Handle(AIS_InteractiveObject)>();
-  if (!anAISIO.IsNull()) {
+  if (!anAISIO.IsNull() && aContext->IsDisplayed(anAISIO)) {
     aContext->Remove(anAISIO, theUpdateViewer);
   }
 }
index c64bccb21593a156ecba0369dd7d5dcca38a0502..beefc2f4801fe41434465a5b262b46199155b5f2 100644 (file)
@@ -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
index facd2e4286158d34e5188b90cf52cc7e5b396f46..02c06f646b2f216b41ef5a0a7d3834bd60ffc1c8 100644 (file)
@@ -1523,6 +1523,8 @@ void XGUI_Workshop::closeDocument()
   myDisplayer->eraseAll();
   objectBrowser()->clearContent();
 
+  module()->closeDocument();
+
   SessionPtr aMgr = ModelAPI_Session::get();
   aMgr->closeAll();
 }