Salome HOME
Merge remote-tracking branch 'remotes/origin/EDF_2020_Lot2'
[modules/shaper.git] / src / PartSet / PartSet_Module.cpp
index eeb18584f342dc5f8d26077e92f3bf73e85267d8..108db7563a6e55d89ff1affa57834a6112d3deb3 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2020  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -158,18 +158,15 @@ extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(ModuleBase_IWorkshop*
 //******************************************************
 PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
 : ModuleBase_IModule(theWshop),
+  myIsOperationIsLaunched(false),
   myVisualLayerId(0),
-  myRoot(0),
-  myIsOperationIsLaunched(false)
+  myRoot(0)
 {
   new PartSet_IconFactory(this);
 
   mySketchMgr = new PartSet_SketcherMgr(this);
   mySketchReentrantMgr = new PartSet_SketcherReentrantMgr(theWshop);
 
-  XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWshop);
-  XGUI_Workshop* aWorkshop = aConnector->workshop();
-
   ModuleBase_IViewer* aViewer = theWshop->viewer();
   connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)),
           this, SLOT(onKeyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
@@ -357,15 +354,7 @@ void PartSet_Module::operationCommitted(ModuleBase_Operation* theOperation)
 
   /// Restart sketcher operations automatically
   if (!mySketchReentrantMgr->operationCommitted(theOperation)) {
-
-    ModuleBase_OperationFeature* aFOperation =
-      dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
-    if (aFOperation && !aFOperation->isEditOperation()) {
-      // the selection is cleared after commit the create operation
-      // in order to do not use the same selected objects in the restarted operation
-      // for common behaviour, the selection is cleared even if the operation is not restarted
-      getWorkshop()->selector()->clearSelection();
-    }
+    getWorkshop()->selector()->clearSelection();
   }
 }
 
@@ -377,6 +366,8 @@ void PartSet_Module::operationAborted(ModuleBase_Operation* theOperation)
   /// deactivate of overconstraint listener should be performed after Sketch abort (#2176)
   if (PartSet_SketcherMgr::isSketchOperation(theOperation))
     overconstraintListener()->setActive(false);
+
+  getWorkshop()->selector()->clearSelection();
 }
 
 //******************************************************
@@ -888,7 +879,6 @@ ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& th
                                                            Config_WidgetAPI* theWidgetApi)
 {
   ModuleBase_IWorkshop* aWorkshop = workshop();
-  XGUI_Workshop* aXUIWorkshop = getWorkshop();
   ModuleBase_ModelWidget* aWgt = NULL;
   if (theType == "sketch-start-label") {
     PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent, aWorkshop,
@@ -1170,8 +1160,6 @@ void PartSet_Module::onViewTransformed(int theTrsfType)
      sketchMgr()->isNestedSketchOperation(aCurrentOperation) ||
      (aCurrentOperation->id() == "Measurement")))
   {
-
-    double aPrevLen = SketcherPrs_Tools::getArrowSize();
     SketcherPrs_Tools::setArrowSize(aLen);
     const double aCurScale = aViewer->activeView()->Camera()->Scale();
     aViewer->SetScale(aViewer->activeView(), aCurScale);
@@ -1570,6 +1558,9 @@ if (aObjIndex.isValid()) { \
 void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMessage)
 {
   if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
+    SessionPtr aMgr = ModelAPI_Session::get();
+    if (!aMgr->hasModuleDocument()) // if document is closed, do not call the document creation
+      return;
     // Do not change activation of parts if an operation active
     static QStringList aAllowActivationList;
     if (aAllowActivationList.isEmpty())
@@ -1581,32 +1572,34 @@ void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMess
       (!aAllowActivationList.contains(myWorkshop->currentOperation()->id())))
       return;
     XGUI_Workshop* aWorkshop = getWorkshop();
-    XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
-    QLabel* aLabel = aWorkshop->objectBrowser()->activeDocLabel();
-    QPalette aPalet = aLabel->palette();
+    bool needUpdate = false;
+    XGUI_DataTree* aTreeView;
+    if (aWorkshop->objectBrowser()) {
+      aTreeView = aWorkshop->objectBrowser()->treeView();
+      QLabel* aLabel = aWorkshop->objectBrowser()->activeDocLabel();
+      QPalette aPalet = aLabel->palette();
 
-    SessionPtr aMgr = ModelAPI_Session::get();
-    DocumentPtr aActiveDoc = aMgr->activeDocument();
+      DocumentPtr aActiveDoc = aMgr->activeDocument();
 
-    // Clear active part index if there is no Part documents
-    // It could be not null if document was closed and opened a new
-    // without closeDocument call
-    if (aMgr->allOpenedDocuments().size() <= 1)
-      myActivePartIndex = QModelIndex();
+      // Clear active part index if there is no Part documents
+      // It could be not null if document was closed and opened a new
+      // without closeDocument call
+      if (aMgr->allOpenedDocuments().size() <= 1)
+        myActivePartIndex = QModelIndex();
 
-    XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
-    QModelIndex aOldActive = myActivePartIndex;
-    myActivePartIndex = aDataModel->documentRootIndex(aActiveDoc, 0);
-    bool needUpdate = false;
-    if (myActivePartIndex.isValid()) {
-      needUpdate = aTreeView->isExpanded(myActivePartIndex);
-      if (!needUpdate)
-        aTreeView->setExpanded(myActivePartIndex, true);
-    }
-    if ((aOldActive != myActivePartIndex) && (aOldActive.isValid()))
-      aTreeView->setExpanded(aOldActive, false);
+      XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
+      QModelIndex aOldActive = myActivePartIndex;
+      myActivePartIndex = aDataModel->documentRootIndex(aActiveDoc, 0);
+      if (myActivePartIndex.isValid()) {
+        needUpdate = aTreeView->isExpanded(myActivePartIndex);
+        if (!needUpdate)
+          aTreeView->setExpanded(myActivePartIndex, true);
+      }
+      if ((aOldActive != myActivePartIndex) && (aOldActive.isValid()))
+        aTreeView->setExpanded(aOldActive, false);
 
-    aLabel->setPalette(aPalet);
+      aLabel->setPalette(aPalet);
+    }
     aWorkshop->updateCommandStatus();
 
     // Update displayed objects in order to update active color