From 997fb5fcf7ceac866429f8242c32132e5e608ceb Mon Sep 17 00:00:00 2001 From: vsv Date: Mon, 3 Feb 2020 18:42:08 +0300 Subject: [PATCH] Improve loading of parts --- src/Model/Model_ResultPart.cpp | 19 ++++++++++++++- src/Model/Model_ResultPart.h | 3 +++ src/ModelAPI/ModelAPI_ResultPart.h | 3 +++ src/PartSet/PartSet_MenuMgr.cpp | 39 ++++++++++++++++++++++++++++++ src/PartSet/PartSet_MenuMgr.h | 3 +++ src/PartSet/PartSet_Module.cpp | 21 ++++++++++++++++ 6 files changed, 87 insertions(+), 1 deletion(-) diff --git a/src/Model/Model_ResultPart.cpp b/src/Model/Model_ResultPart.cpp index 7bbadba0d..f89eff7d7 100644 --- a/src/Model/Model_ResultPart.cpp +++ b/src/Model/Model_ResultPart.cpp @@ -89,7 +89,8 @@ void Model_ResultPart::activate() SessionPtr aMgr = ModelAPI_Session::get(); if (!aMgr->isOperation()) { // open transaction even document is not created to set current docs in setActiveDocument - aMgr->startOperation("Activation"); + std::string aMsg = "Activation " + data()->name(); + aMgr->startOperation(aMsg); isNewTransaction = true; } if (!aDocRef->value().get()) { // create (or open) a document if it is not yet created @@ -113,6 +114,22 @@ void Model_ResultPart::activate() } } + +void Model_ResultPart::loadPart() +{ + std::shared_ptr aDocRef = data()->document(DOC_REF()); + if (!aDocRef->value().get()) { // create (or open) a document if it is not yet created + Handle(Model_Application) anApp = Model_Application::getApplication(); + if (anApp->isLoadByDemand(data()->name(), aDocRef->docId())) { + anApp->loadDocument(data()->name(), aDocRef->docId()); // if it is just new part, load fails + } + else { + anApp->createDocument(aDocRef->docId()); + } + } +} + + std::shared_ptr Model_ResultPart::original() { if (myTrsf.get() && baseRef().get()) { // the second condition is due to #2035 diff --git a/src/Model/Model_ResultPart.h b/src/Model/Model_ResultPart.h index fff44ed1c..0f27e9c58 100644 --- a/src/Model/Model_ResultPart.h +++ b/src/Model/Model_ResultPart.h @@ -95,6 +95,9 @@ class Model_ResultPart : public ModelAPI_ResultPart /// Returns the shape selected in the selection index MODEL_EXPORT virtual std::shared_ptr selectionValue(const int theIndex); + /// Loading the part from file + MODEL_EXPORT virtual void loadPart(); + protected: /// makes a result on a temporary feature (an action) Model_ResultPart(); diff --git a/src/ModelAPI/ModelAPI_ResultPart.h b/src/ModelAPI/ModelAPI_ResultPart.h index 4a4756be5..0ceb08652 100644 --- a/src/ModelAPI/ModelAPI_ResultPart.h +++ b/src/ModelAPI/ModelAPI_ResultPart.h @@ -97,6 +97,9 @@ class ModelAPI_ResultPart : public ModelAPI_Result /// Updates the shape-result of the part (called on Part feature execution) virtual void updateShape() = 0; + + /// Loading the part from file + virtual void loadPart() = 0; }; //! Pointer on feature object diff --git a/src/PartSet/PartSet_MenuMgr.cpp b/src/PartSet/PartSet_MenuMgr.cpp index 63e88207e..f2bace900 100644 --- a/src/PartSet/PartSet_MenuMgr.cpp +++ b/src/PartSet/PartSet_MenuMgr.cpp @@ -46,6 +46,7 @@ #include #include #include +#include #include #include @@ -56,6 +57,7 @@ #include #include #include +#include #include #include @@ -104,6 +106,10 @@ void PartSet_MenuMgr::createActions() aAction = ModuleBase_Tools::createAction(QIcon(":icons/edit.png"), tr("Edit..."), aParent, this, SLOT(onEdit(bool))); myActions["EDIT_CMD"] = aAction; + + aAction = ModuleBase_Tools::createAction(QIcon(":icons/activate.png"), tr("Load all parts"), aParent, + this, SLOT(onActivateAllParts())); + myActions["ACTIVATE_ALL_PARTS_CMD"] = aAction; } @@ -504,6 +510,39 @@ void PartSet_MenuMgr::activatePart(ResultPartPtr thePart) const } } +void PartSet_MenuMgr::onActivateAllParts() +{ + SessionPtr aMgr = ModelAPI_Session::get(); + if (aMgr->isOperation()) + return; + + DocumentPtr aDoc = aMgr->moduleDocument(); + int aNbParts = aDoc->size(ModelAPI_ResultPart::group()); + bool isActivated = false; + QList aPartsToLoad; + for (int i = 0; i < aNbParts; i++) { + ObjectPtr aObj = aDoc->object(ModelAPI_ResultPart::group(), i); + ResultPartPtr aPartRes = std::dynamic_pointer_cast(aObj); + if (!aPartRes->partDoc().get()) + aPartsToLoad.append(aPartRes); + } + if (!aPartsToLoad.isEmpty()) { + QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); + aMgr->startOperation("All Parts loading"); + foreach(ResultPartPtr aPartRes, aPartsToLoad) { + aPartRes->loadPart(); + } + aMgr->finishOperation(); + + XGUI_Workshop* aWorkshop = myModule->getWorkshop(); + XGUI_ObjectsBrowser* aObjBrowser = aWorkshop->objectBrowser(); + aObjBrowser->update(); + aWorkshop->viewer()->update(); + aWorkshop->updateCommandStatus(); + QApplication::restoreOverrideCursor(); + } +} + void PartSet_MenuMgr::onActivatePartSet(bool) { if (myModule->workshop()->currentOperation()) diff --git a/src/PartSet/PartSet_MenuMgr.h b/src/PartSet/PartSet_MenuMgr.h index 1b7bec761..2bea22d23 100644 --- a/src/PartSet/PartSet_MenuMgr.h +++ b/src/PartSet/PartSet_MenuMgr.h @@ -100,6 +100,9 @@ private slots: /// A slot called on edit of feature void onEdit(bool); + /// Activates all not loaded parts + void onActivateAllParts(); + protected: /// Redefinition of virtual method /// \param theObj an object diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 1c8fbfc23..1e8d2882f 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -1313,6 +1313,27 @@ void PartSet_Module::onActiveDocPopup(const QPoint& thePnt) QMenu aMenu; aMenu.addAction(aActivatePartAction); + +#ifndef HAVE_SALOME + if (aMgr->activeDocument() == aMgr->moduleDocument()) { + DocumentPtr aDoc = aMgr->moduleDocument(); + int aNbParts = aDoc->size(ModelAPI_ResultPart::group()); + bool aHaveToActivate = false; + for (int i = 0; i < aNbParts; i++) { + ObjectPtr aObj = aDoc->object(ModelAPI_ResultPart::group(), i); + ResultPartPtr aPartRes = std::dynamic_pointer_cast(aObj); + if (!aPartRes->partDoc().get()) { + aHaveToActivate = true; + break; + } + } + if (aHaveToActivate) { + QAction* aActivateAllPartAction = myMenuMgr->action("ACTIVATE_ALL_PARTS_CMD"); + aMenu.addAction(aActivateAllPartAction); + } + } +#endif + aMenu.exec(aHeader->mapToGlobal(thePnt)); } -- 2.39.2