+
+bool PartSet_Module::customizeObject(ObjectPtr theObject, const bool theUpdateViewer)
+{
+ bool isRedisplayed = false;
+ if (myCustomPrs->isActive())
+ isRedisplayed = myCustomPrs->redisplay(theObject, theUpdateViewer);
+
+ return isRedisplayed;
+}
+
+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&)));
+#ifdef ModuleDataModel
+ connect(aOB, SIGNAL(headerMouseDblClicked(const QModelIndex&)),
+ SLOT(onTreeViewDoubleClick(const QModelIndex&)));
+ connect(aOB->treeView(), SIGNAL(doubleClicked(const QModelIndex&)),
+ myDataModel, SLOT(onMouseDoubleClick(const QModelIndex&)));
+#endif
+ }
+}
+
+ObjectPtr PartSet_Module::findPresentedObject(const AISObjectPtr& theAIS) const
+{
+ ObjectPtr anObject;
+ ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
+ if (aOperation) {
+ /// If last line finished on vertex the lines creation sequence has to be break
+ ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
+ ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
+ // if there is an active widget, find the presented object in it
+ if (!anActiveWidget)
+ anActiveWidget = aPanel->preselectionWidget();
+
+ ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
+ (anActiveWidget);
+ if (aWidgetValidated)
+ anObject = aWidgetValidated->findPresentedObject(theAIS);
+ }
+ return anObject;
+}
+
+void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const
+{
+ QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
+ int aSelected = aObjects.size();
+ SessionPtr aMgr = ModelAPI_Session::get();
+ QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PART_CMD");
+ QAction* aActivatePartSetAction = myMenuMgr->action("ACTIVATE_PARTSET_CMD");
+ if (aSelected == 1) {
+ bool hasResult = false;
+ bool hasFeature = false;
+ bool hasParameter = false;
+ bool hasSubFeature = false;
+ ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter, hasSubFeature);
+
+ 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();
+
+ theMenu->addAction(aActivatePartAction);
+ aActivatePartAction->setEnabled((aMgr->activeDocument() != aPartDoc));
+
+ } else if (aObject->document() == aMgr->activeDocument()) {
+ if (hasParameter || hasFeature)
+ theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
+ }
+
+ ResultBodyPtr aResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aObject);
+ if( aResult.get() )
+ theMenu->addAction(myMenuMgr->action("SELECT_PARENT_CMD"));
+ } else { // If feature is 0 the it means that selected root object (document)
+ theMenu->addAction(aActivatePartSetAction);
+ aActivatePartSetAction->setEnabled((aMgr->activeDocument() != aMgr->moduleDocument()));
+ }
+ } 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
+ theMenu->addAction(aActivatePartSetAction);
+ aActivatePartSetAction->setEnabled((aMgr->activeDocument() != aMgr->moduleDocument()));
+ }
+ bool aNotDeactivate = (myWorkshop->currentOperation() == 0);
+ if (!aNotDeactivate) {
+ aActivatePartAction->setEnabled(false);
+ aActivatePartSetAction->setEnabled(false);
+ }
+}
+
+void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMessage)
+{
+ if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
+ // Do not change activation of parts if an operation active
+ static QStringList aAllowActivationList;
+ if (aAllowActivationList.isEmpty())
+ aAllowActivationList <<
+ QString(PartSetPlugin_Part::ID().c_str()) <<
+ QString(PartSetPlugin_Duplicate::ID().c_str()) <<
+ QString(PartSetPlugin_Remove::ID().c_str());
+ if (myWorkshop->currentOperation() &&
+ (!aAllowActivationList.contains(myWorkshop->currentOperation()->id())))
+ return;
+ 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();
+#ifdef ModuleDataModel
+ QModelIndex aOldIndex = myDataModel->activePartTree();
+ DocumentPtr aDoc = aMgr->moduleDocument();
+ 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;
+ }
+ }
+ }
+#else
+ if (aActivePartIndex.isValid())
+ aTreeView->setExpanded(aActivePartIndex, false);
+ XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
+ aActivePartIndex = aDataModel->documentRootIndex(aActiveDoc);
+ if (aActivePartIndex.isValid())
+ aTreeView->setExpanded(aActivePartIndex, true);
+#endif
+ aLabel->setPalette(aPalet);
+ aWorkshop->updateCommandStatus();
+
+ // Update displayed objects in order to update active color
+ XGUI_Displayer* aDisplayer = aWorkshop->displayer();
+ QObjectPtrList aObjects = aDisplayer->displayedObjects();
+ bool aHidden;
+ foreach(ObjectPtr aObj, aObjects) {
+ //TODO: replace by redisplay event.
+ aHidden = !aObj->data() || !aObj->data()->isValid() ||
+ aObj->isDisabled() || (!aObj->isDisplayed());
+ if (!aHidden)
+ aDisplayer->redisplay(aObj, false);
+ }
+ aDisplayer->updateViewer();
+ }
+}
+
+void PartSet_Module::onTreeViewDoubleClick(const QModelIndex& theIndex)
+{
+ if (myWorkshop->currentOperation()) // Do not change activation of parts if an operation active
+ return;
+ SessionPtr aMgr = ModelAPI_Session::get();
+ if (!theIndex.isValid()) {
+ aMgr->setActiveDocument(aMgr->moduleDocument());
+ return;
+ }
+ if (theIndex.column() != 0) // Use only first column
+ return;
+#ifdef ModuleDataModel
+ ObjectPtr aObj = myDataModel->object(theIndex);
+#else
+ XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
+ XGUI_Workshop* aWorkshop = aConnector->workshop();
+ XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
+ // De not use non editable Indexes
+ if ((aDataModel->flags(theIndex) & Qt::ItemIsSelectable) == 0)
+ return;
+ ObjectPtr aObj = aDataModel->object(theIndex);
+#endif
+
+ 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()) {
+ myMenuMgr->activatePartSet();
+ } else {
+ aPart->activate();
+ }
+ }
+}
+
+
+void PartSet_Module::onViewCreated(ModuleBase_IViewWindow*)
+{
+ // z layer is created for all started operations in order to visualize operation AIS presentation
+ // over the object
+ Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
+ if (aContext.IsNull())
+ return;
+
+ Handle(V3d_Viewer) aViewer = aContext->CurrentViewer();
+ if (myVisualLayerId == 0) {
+ if (myVisualLayerId == 0)
+ aViewer->AddZLayer(myVisualLayerId);
+ } else {
+ TColStd_SequenceOfInteger aZList;
+ aViewer->GetAllZLayers(aZList);
+ bool aFound = false;
+ for (int i = 1; i <= aZList.Length(); i++) {
+ if (aZList(i) == myVisualLayerId) {
+ aFound = true;
+ break;
+ }
+ }
+ if (!aFound)
+ aViewer->AddZLayer(myVisualLayerId);
+ }
+ // if there is an active operation with validated widget,
+ // the filters of this widget should be activated in the created view
+ ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
+ if (aOperation) {
+ ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
+ ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
+ if (anActiveWidget) {
+ ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
+ (anActiveWidget);
+ if (aWidgetValidated)
+ aWidgetValidated->activateFilters(true);
+ }
+ }
+}