Salome HOME
Porting Salome to OCCT 7.7.0
[modules/shaper.git] / src / PartSet / PartSet_Module.cpp
index 683173100f44c4d60ed3bb2501798604bda6365d..8292e70d6f6a86c708f5301bba1c18867dd2fe1f 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2021  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2022  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
 #include <SketcherPrs_Tools.h>
 
 #include <Events_Loop.h>
+#include <Events_MessageBool.h>
 #include <Config_PropManager.h>
 #include <Config_Keywords.h>
 
 
 #include <SUIT_ResourceMgr.h>
 
+#include <Basics_OCCTVersion.hxx>
+
 #define FEATURE_ITEM_COLOR "0,0,225"
 
 
@@ -187,6 +190,7 @@ PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
 
   Events_Loop* aLoop = Events_Loop::loop();
   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED));
+  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENTS_CLOSED));
   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_LICENSE_VALID));
 
@@ -286,6 +290,13 @@ PartSet_Module::~PartSet_Module()
 void PartSet_Module::createFeatures()
 {
   ModuleBase_IModule::createFeatures();
+
+  // send signal to initialization plugin about the state of the preferences: to create part or not
+  bool aCreate = ModuleBase_Preferences::resourceMgr()->booleanValue(
+    ModuleBase_Preferences::GENERAL_SECTION, "create_init_part", true);
+  Events_MessageBool aCreateMsg(Events_Loop::eventByName(EVENT_CREATE_PART_ON_START), aCreate);
+  aCreateMsg.send();
+
   myRoot = new PartSet_RootNode();
   myRoot->setWorkshop(workshop());
   ModuleBase_IModule::loadProprietaryPlugins();
@@ -1465,7 +1476,11 @@ void PartSet_Module::setTexture(const AISObjectPtr& thePrs,
 
       //aPixmap = OCCViewer_Utilities::imageToPixmap( px.toImage());
       Handle(Image_PixMap) aPixmap = new Image_PixMap();
+#if OCC_VERSION_LARGE < 0x07070000
       aPixmap->InitTrash(Image_PixMap::ImgBGRA, aWidth, aHeight);
+#else
+      aPixmap->InitTrash(Image_Format_BGRA, aWidth, aHeight);
+#endif
       std::list<unsigned char>::iterator aByteIter = aByteList.begin();
       for (int aLine = 0; aLine < aHeight; ++aLine) {
         // convert pixels from ARGB to renderer-compatible RGBA
@@ -1589,8 +1604,9 @@ void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const
   bool hasCompositeOwner = false;
   bool hasResultInHistory = false;
   bool hasFolder = false;
+  bool hasGroupsOnly = false;
   ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter,
-                                  hasCompositeOwner, hasResultInHistory, hasFolder);
+                                  hasCompositeOwner, hasResultInHistory, hasFolder, hasGroupsOnly);
 
   ModuleBase_Operation* aCurrentOp = myWorkshop->currentOperation();
   if (aSelected == 1) {
@@ -1666,7 +1682,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)) {
+  if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENTS_CLOSED)) {
+    closeDocument();
+  } else 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;