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
}
}
+
+void Model_ResultPart::loadPart()
+{
+ std::shared_ptr<ModelAPI_AttributeDocRef> 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<ModelAPI_ResultPart> Model_ResultPart::original()
{
if (myTrsf.get() && baseRef().get()) { // the second condition is due to #2035
/// Returns the shape selected in the selection index
MODEL_EXPORT virtual std::shared_ptr<GeomAPI_Shape> 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();
/// 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
#include <XGUI_DataModel.h>
#include <XGUI_OperationMgr.h>
#include <XGUI_ObjectsBrowser.h>
+#include <XGUI_ViewerProxy.h>
#include <Events_Loop.h>
#include <ModelAPI_Events.h>
#include <QAction>
#include <QMenu>
#include <QEvent>
+#include <QApplication>
#include <TopoDS.hxx>
#include <BRep_Tool.hxx>
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;
}
}
}
+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<ResultPartPtr> aPartsToLoad;
+ for (int i = 0; i < aNbParts; i++) {
+ ObjectPtr aObj = aDoc->object(ModelAPI_ResultPart::group(), i);
+ ResultPartPtr aPartRes = std::dynamic_pointer_cast<ModelAPI_ResultPart>(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())
/// 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
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<ModelAPI_ResultPart>(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));
}