+
+
+void PartSet_Module::customizeObjectBrowser(QWidget* theObjectBrowser)
+{
+ XGUI_ObjectsBrowser* aOB = dynamic_cast<XGUI_ObjectsBrowser*>(theObjectBrowser);
+ if (aOB) {
+ QLineEdit* aLabel = aOB->activeDocLabel();
+ QPalette aPalet = aLabel->palette();
+ aPalet.setColor(QPalette::Text, QColor(0, 72, 140));
+ aLabel->setPalette(aPalet);
+ aOB->treeView()->setExpandsOnDoubleClick(false);
+ connect(aOB->treeView(), SIGNAL(doubleClicked(const QModelIndex&)),
+ SLOT(onTreeViewDoubleClick(const QModelIndex&)));
+ connect(aOB, SIGNAL(headerMouseDblClicked(const QModelIndex&)),
+ SLOT(onTreeViewDoubleClick(const QModelIndex&)));
+ connect(aOB->treeView(), SIGNAL(doubleClicked(const QModelIndex&)),
+ myDataModel, SLOT(onMouseDoubleClick(const QModelIndex&)));
+ }
+}
+
+
+void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const
+{
+ QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
+ int aSelected = aObjects.size();
+ SessionPtr aMgr = ModelAPI_Session::get();
+ if (aSelected == 1) {
+ bool hasResult = false;
+ bool hasFeature = false;
+ bool hasParameter = false;
+ ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter);
+
+ ObjectPtr aObject = aObjects.first();
+ if (aObject) {
+ ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
+ FeaturePtr aPartFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
+ bool isPart = aPart.get() ||
+ (aPartFeature.get() && (aPartFeature->getKind() == PartSetPlugin_Part::ID()));
+ if (isPart) {
+ DocumentPtr aPartDoc;
+ if (!aPart.get()) {
+ aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartFeature->firstResult());
+ }
+ if (aPart.get()) // this may be null is Part feature is disabled
+ aPartDoc = aPart->partDoc();
+ if (aMgr->activeDocument() == aPartDoc)
+ theMenu->addAction(myMenuMgr->action("DEACTIVATE_PART_CMD"));
+ else
+ theMenu->addAction(myMenuMgr->action("ACTIVATE_PART_CMD"));
+ } else if (aObject->document() == aMgr->activeDocument()) {
+ if (hasParameter || hasFeature)
+ theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
+ }
+ } else { // If feature is 0 the it means that selected root object (document)
+ if (aMgr->activeDocument() != aMgr->moduleDocument())
+ theMenu->addAction(myMenuMgr->action("ACTIVATE_PARTSET_CMD"));
+ }
+ } else if (aSelected == 0) {
+ // if there is no selection then it means that upper label is selected
+ QModelIndexList aIndexes = myWorkshop->selection()->selectedIndexes();
+ if (aIndexes.size() == 0) // it means that selection happens in top label outside of tree view
+ if (aMgr->activeDocument() != aMgr->moduleDocument())
+ theMenu->addAction(myMenuMgr->action("ACTIVATE_PARTSET_CMD"));
+ }
+}
+
+void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMessage)
+{
+ if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
+ XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
+ XGUI_Workshop* aWorkshop = aConnector->workshop();
+ XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
+ QLineEdit* aLabel = aWorkshop->objectBrowser()->activeDocLabel();
+ QPalette aPalet = aLabel->palette();
+
+ SessionPtr aMgr = ModelAPI_Session::get();
+ DocumentPtr aActiveDoc = aMgr->activeDocument();
+ DocumentPtr aDoc = aMgr->moduleDocument();
+ QModelIndex aOldIndex = myDataModel->activePartTree();
+ if (aActiveDoc == aDoc) {
+ if (aOldIndex.isValid())
+ aTreeView->setExpanded(aOldIndex, false);
+ myDataModel->deactivatePart();
+ aPalet.setColor(QPalette::Text, QColor(0, 72, 140));
+ } else {
+ std::string aGrpName = ModelAPI_ResultPart::group();
+ for (int i = 0; i < aDoc->size(aGrpName); i++) {
+ ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aDoc->object(aGrpName, i));
+ if (aPart->partDoc() == aActiveDoc) {
+ QModelIndex aIndex = myDataModel->partIndex(aPart);
+ if (myDataModel->activatePart(aIndex)) {
+ if (aOldIndex.isValid())
+ aTreeView->setExpanded(aOldIndex, false);
+ aTreeView->setExpanded(myDataModel->activePartTree(), true);
+ aPalet.setColor(QPalette::Text, Qt::black);
+ }
+ break;
+ }
+ }
+ }
+ aLabel->setPalette(aPalet);
+ aWorkshop->updateCommandStatus();
+
+ // Update displayed objects in order to update active color
+ XGUI_Displayer* aDisplayer = aWorkshop->displayer();
+ QObjectPtrList aObjects = aDisplayer->displayedObjects();
+ foreach(ObjectPtr aObj, aObjects)
+ aDisplayer->redisplay(aObj, false);
+ aDisplayer->updateViewer();
+ }
+}
+
+void PartSet_Module::onTreeViewDoubleClick(const QModelIndex& theIndex)
+{
+ SessionPtr aMgr = ModelAPI_Session::get();
+ if (!theIndex.isValid()) {
+ aMgr->setActiveDocument(aMgr->moduleDocument());
+ return;
+ }
+ if (theIndex.column() != 0) // Use only first column
+ return;
+ ObjectPtr aObj = myDataModel->object(theIndex);
+ ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
+ if (!aPart.get()) { // Probably this is Feature
+ FeaturePtr aPartFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
+ if (aPartFeature.get() && (aPartFeature->getKind() == PartSetPlugin_Part::ID())) {
+ aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartFeature->firstResult());
+ }
+ }
+ if (aPart.get()) { // if this is a part
+ if (aPart->partDoc() == aMgr->activeDocument()) {
+ aMgr->setActiveDocument(aMgr->moduleDocument());
+ } else {
+ aPart->activate();
+ }
+ }
+}