1 // Created on: 2017-06-16
2 // Created by: Natalia ERMOLAEVA
3 // Copyright (c) 2017 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <inspector/DFBrowser_Window.hxx>
18 #include <AIS_InteractiveContext.hxx>
19 #include <AIS_InteractiveObject.hxx>
20 #include <AIS_ListOfInteractive.hxx>
22 #include <inspector/DFBrowserPane_AttributePaneAPI.hxx>
24 #include <inspector/DFBrowser_AttributePaneStack.hxx>
25 #include <inspector/DFBrowser_AttributePaneType.hxx>
26 #include <inspector/DFBrowser_DumpView.hxx>
27 #include <inspector/DFBrowser_Item.hxx>
28 #include <inspector/DFBrowser_ItemApplication.hxx>
29 #include <inspector/DFBrowser_Module.hxx>
30 #include <inspector/DFBrowser_OpenApplication.hxx>
31 #include <inspector/DFBrowser_PropertyPanel.hxx>
32 #include <inspector/DFBrowser_SearchLine.hxx>
33 #include <inspector/DFBrowser_SearchView.hxx>
34 #include <inspector/DFBrowser_Thread.hxx>
35 #include <inspector/DFBrowser_ThreadItemSearch.hxx>
36 #include <inspector/DFBrowser_Tools.hxx>
37 #include <inspector/DFBrowser_TreeLevelLine.hxx>
38 #include <inspector/DFBrowser_TreeLevelView.hxx>
39 #include <inspector/DFBrowser_TreeModel.hxx>
41 #include <inspector/DFBrowserPane_AttributePaneSelector.hxx>
42 #include <inspector/DFBrowserPane_SelectionKind.hxx>
43 #include <inspector/DFBrowserPane_Tools.hxx>
45 #include <inspector/TreeModel_ContextMenu.hxx>
46 #include <inspector/TreeModel_Tools.hxx>
48 #include <inspector/ViewControl_PropertyView.hxx>
49 #include <inspector/ViewControl_TreeView.hxx>
51 #include <OSD_Directory.hxx>
52 #include <OSD_Environment.hxx>
53 #include <OSD_Protection.hxx>
54 #include <OSD_Thread.hxx>
55 #include <inspector/View_Displayer.hxx>
56 #include <inspector/View_ToolBar.hxx>
57 #include <inspector/View_Viewer.hxx>
58 #include <inspector/View_Window.hxx>
60 #include <TDF_Tool.hxx>
61 #include <inspector/ViewControl_MessageDialog.hxx>
62 #include <inspector/ViewControl_Tools.hxx>
64 #include <Standard_WarningsDisable.hxx>
65 #include <Standard_ThreadId.hxx>
67 #include <QApplication>
70 #include <QDockWidget>
71 #include <QGridLayout>
73 #include <QMainWindow>
74 #include <QItemSelectionModel>
79 #include <QMessageBox>
82 #if QT_VERSION < 0x050000
83 #include <QWindowsStyle>
85 #include <QStyleFactory>
87 #include <Standard_WarningsRestore.hxx>
89 const int DFBROWSER_DEFAULT_WIDTH = 650;
90 const int DFBROWSER_DEFAULT_HEIGHT = 350;
91 const int DFBROWSER_DEFAULT_TREE_VIEW_WIDTH = 325;
92 const int DFBROWSER_DEFAULT_TREE_VIEW_HEIGHT = 500;
93 const int DFBROWSER_DEFAULT_VIEW_WIDTH = 400;
94 const int DFBROWSER_DEFAULT_VIEW_HEIGHT = 300;
96 const int DFBROWSER_DEFAULT_POSITION_X = 200;
97 const int DFBROWSER_DEFAULT_POSITION_Y = 60;
99 const int DEFAULT_PROPERTY_PANEL_HEIGHT = 200;
100 const int DEFAULT_BROWSER_HEIGHT = 800;
102 //#define USE_DUMPJSON
104 // =======================================================================
105 // function : Constructor
107 // =======================================================================
108 DFBrowser_Window::DFBrowser_Window()
109 : myModule (0), myParent (0), myPropertyPanel (0), myExportToShapeViewDialog (0)
111 myMainWindow = new QMainWindow (0);
114 myTreeView = new ViewControl_TreeView (myMainWindow);
115 myTreeView->setContextMenuPolicy (Qt::CustomContextMenu);
116 connect (myTreeView, SIGNAL (customContextMenuRequested (const QPoint&)),
117 this, SLOT (onTreeViewContextMenuRequested (const QPoint&)));
118 new TreeModel_ContextMenu (myTreeView);
119 ((ViewControl_TreeView*)myTreeView)->SetPredefinedSize (QSize (DFBROWSER_DEFAULT_TREE_VIEW_WIDTH,
120 DFBROWSER_DEFAULT_TREE_VIEW_HEIGHT));
121 myTreeView->setHeaderHidden (true);
122 myTreeView->setSortingEnabled (Standard_False);
123 myMainWindow->setCentralWidget (myTreeView);
125 #if QT_VERSION < 0x050000
126 myTreeView->setStyle (new QWindowsStyle);
128 myTreeView->setStyle (QStyleFactory::create("Windows"));
131 myTreeLevelLine = new DFBrowser_TreeLevelLine (myMainWindow);
132 connect (myTreeLevelLine->GetSearchLine(), SIGNAL (searchActivated()), this, SLOT (onSearchActivated()));
133 connect (myTreeLevelLine, SIGNAL (indexSelected (const QModelIndex&)),
134 this, SLOT (onTreeLevelLineSelected (const QModelIndex&)));
135 connect (myTreeLevelLine, SIGNAL (updateClicked()), this, SLOT (onUpdateClicked()));
137 QDockWidget* aTreeLineDockWidget = new QDockWidget (tr ("Tree Level Line"), myMainWindow);
138 aTreeLineDockWidget->setObjectName (aTreeLineDockWidget->windowTitle());
139 aTreeLineDockWidget->setTitleBarWidget (new QWidget(myMainWindow));
140 aTreeLineDockWidget->setWidget (myTreeLevelLine->GetControl());
141 myMainWindow->addDockWidget (Qt::TopDockWidgetArea, aTreeLineDockWidget);
144 myPropertyPanel = new DFBrowser_PropertyPanel (myMainWindow);
145 DFBrowser_AttributePaneStack* anAttributePaneStack = myPropertyPanel->GetAttributesStack();
146 anAttributePaneStack->GetSearchView()->SetSearchLine (myTreeLevelLine->GetSearchLine());
148 connect (anAttributePaneStack->GetPaneSelector(),
149 SIGNAL (tableSelectionChanged (const QItemSelection&, const QItemSelection&, QItemSelectionModel*)),
150 this, SLOT (onPaneSelectionChanged (const QItemSelection&, const QItemSelection&, QItemSelectionModel*)));
152 DFBrowser_SearchView* aSearchView = anAttributePaneStack->GetSearchView();
153 connect (aSearchView, SIGNAL (pathSelected (const QStringList&, const QString&)),
154 this, SLOT (onSearchPathSelected (const QStringList&, const QString&)));
155 connect (aSearchView, SIGNAL (pathDoubleClicked (const QStringList&, const QString&)),
156 this, SLOT (onSearchPathDoubleClicked (const QStringList&, const QString&)));
158 DFBrowser_TreeLevelView* aLevelView = anAttributePaneStack->GetTreeLevelView();
159 connect (aLevelView, SIGNAL (indexSelected (const QModelIndex&)), this, SLOT (onLevelSelected (const QModelIndex&)));
160 connect (aLevelView, SIGNAL (indexDoubleClicked (const QModelIndex&)),
161 this, SLOT (onLevelDoubleClicked (const QModelIndex&)));
164 QDockWidget* aPropertyPanelWidget = new QDockWidget (tr ("PropertyPanel"), myMainWindow);
165 aPropertyPanelWidget->setObjectName (aPropertyPanelWidget->windowTitle());
166 aPropertyPanelWidget->setTitleBarWidget (new QWidget(myMainWindow));
167 aPropertyPanelWidget->setWidget (myPropertyPanel->GetControl());
168 myMainWindow->addDockWidget (Qt::RightDockWidgetArea, aPropertyPanelWidget);
172 myPropertyPanelWidget = new QDockWidget (tr ("PropertyPanel (DumpJson)"), myMainWindow);
173 myPropertyView = new ViewControl_PropertyView (myMainWindow,
174 QSize(DFBROWSER_DEFAULT_VIEW_WIDTH, DFBROWSER_DEFAULT_VIEW_HEIGHT));
175 myPropertyPanelWidget->setObjectName (myPropertyPanelWidget->windowTitle());
176 myPropertyPanelWidget->setTitleBarWidget (new QWidget(myMainWindow));
177 myPropertyPanelWidget->setWidget (myPropertyView->GetControl());
178 myMainWindow->addDockWidget (Qt::RightDockWidgetArea, myPropertyPanelWidget);
182 QWidget* aDumpWidget = new QWidget(myMainWindow);
183 QVBoxLayout* aDumpLay = new QVBoxLayout(aDumpWidget);
184 aDumpLay->setMargin(0);
185 myDumpView = new DFBrowser_DumpView(aDumpWidget);
186 aDumpLay->addWidget(myDumpView->GetControl());
187 QDockWidget* aDumpDockWidget = new QDockWidget(tr("Dump"), myMainWindow);
188 aDumpDockWidget->setObjectName(aDumpDockWidget->windowTitle());
190 aDumpDockWidget->setWidget(aDumpWidget);
191 myMainWindow->addDockWidget(Qt::RightDockWidgetArea, aDumpDockWidget);
194 myViewWindow = new View_Window (myMainWindow);
195 myViewWindow->SetPredefinedSize (DFBROWSER_DEFAULT_VIEW_WIDTH, DFBROWSER_DEFAULT_VIEW_HEIGHT);
197 QDockWidget* aViewDockWidget = new QDockWidget (tr ("View"), myMainWindow);
198 aViewDockWidget->setObjectName (aViewDockWidget->windowTitle());
199 aViewDockWidget->setTitleBarWidget (myViewWindow->ViewToolBar()->GetControl());
200 aViewDockWidget->setWidget (myViewWindow);
201 myMainWindow->addDockWidget (Qt::RightDockWidgetArea, aViewDockWidget);
203 QColor aHColor (229, 243, 255);
204 myViewWindow->Displayer()->SetAttributeColor (Quantity_Color(aHColor.red() / 255., aHColor.green() / 255.,
205 aHColor.blue() / 255., Quantity_TOC_sRGB), View_PresentationType_Additional);
207 myMainWindow->splitDockWidget (aPropertyPanelWidget, aViewDockWidget, Qt::Vertical);
210 myMainWindow->tabifyDockWidget (aDumpDockWidget, myPropertyPanelWidget);
211 myMainWindow->tabifyDockWidget (myPropertyPanelWidget, aViewDockWidget);
213 myMainWindow->tabifyDockWidget (aDumpDockWidget, aViewDockWidget);
216 myTreeView->resize (DFBROWSER_DEFAULT_TREE_VIEW_WIDTH, DFBROWSER_DEFAULT_TREE_VIEW_HEIGHT);
218 myThread = new DFBrowser_Thread (this);
221 // =======================================================================
222 // function : Destructor
224 // =======================================================================
225 DFBrowser_Window::~DFBrowser_Window()
230 // =======================================================================
231 // function : SetParent
233 // =======================================================================
234 void DFBrowser_Window::SetParent (void* theParent)
236 myParent = (QWidget*)theParent;
239 QLayout* aLayout = myParent->layout();
241 aLayout->addWidget (GetMainWindow());
243 if (!myOpenedFileName.isEmpty())
244 myParent->setObjectName(myOpenedFileName);
248 // =======================================================================
249 // function : FillActionsMenu
251 // =======================================================================
252 void DFBrowser_Window::FillActionsMenu (void* theMenu)
254 QMenu* aMenu = (QMenu*)theMenu;
255 QList<QDockWidget*> aDockwidgets = myMainWindow->findChildren<QDockWidget*>();
256 for (QList<QDockWidget*>::iterator it = aDockwidgets.begin(); it != aDockwidgets.end(); ++it)
258 QDockWidget* aDockWidget = *it;
259 if (aDockWidget->parentWidget() == myMainWindow)
260 aMenu->addAction (aDockWidget->toggleViewAction());
264 // =======================================================================
265 // function : GetPreferences
267 // =======================================================================
268 void DFBrowser_Window::GetPreferences (TInspectorAPI_PreferencesDataMap& theItem)
270 theItem.Bind ("geometry", TreeModel_Tools::ToString (myMainWindow->saveState()).toStdString().c_str());
272 QMap<QString, QString> anItems;
273 TreeModel_Tools::SaveState (myTreeView, anItems);
274 View_Window::SaveState(myViewWindow, anItems);
276 for (QMap<QString, QString>::const_iterator anItemsIt = anItems.begin(); anItemsIt != anItems.end(); anItemsIt++)
277 theItem.Bind (anItemsIt.key().toStdString().c_str(), anItemsIt.value().toStdString().c_str());
280 // =======================================================================
281 // function : SetPreferences
283 // =======================================================================
284 void DFBrowser_Window::SetPreferences (const TInspectorAPI_PreferencesDataMap& theItem)
286 if (theItem.IsEmpty())
288 TreeModel_Tools::SetDefaultHeaderSections (myTreeView);
292 for (TInspectorAPI_IteratorOfPreferencesDataMap anItemIt (theItem); anItemIt.More(); anItemIt.Next())
294 if (anItemIt.Key().IsEqual ("geometry"))
295 myMainWindow->restoreState (TreeModel_Tools::ToByteArray (anItemIt.Value().ToCString()));
296 else if (TreeModel_Tools::RestoreState (myTreeView, anItemIt.Key().ToCString(), anItemIt.Value().ToCString()))
298 else if (View_Window::RestoreState(myViewWindow, anItemIt.Key().ToCString(), anItemIt.Value().ToCString()))
303 // =======================================================================
304 // function : UpdateContent
306 // =======================================================================
307 void DFBrowser_Window::UpdateContent()
309 TCollection_AsciiString aName = "TKDFBrowser";
311 if (myParameters->FindParameters (aName))
312 Init(myParameters->Parameters (aName));
314 Init(NCollection_List<Handle(Standard_Transient)>());
316 if (myParameters->FindFileNames(aName))
318 NCollection_List<TCollection_AsciiString> aFileNames = myParameters->FileNames (aName);
319 if (aFileNames.Extent() > 0) // only one document file might be opened
320 OpenFile (aFileNames.First());
321 myParameters->SetFileNames(aName, NCollection_List<TCollection_AsciiString>());
325 // make parameter items selected if defined
326 if (myParameters->FindSelectedNames(aName))
328 const NCollection_List<TCollection_AsciiString>& aSelected = myParameters->GetSelectedNames (aName);
330 DFBrowser_TreeModel* aTreeModel = dynamic_cast<DFBrowser_TreeModel*> (myTreeView->model());
331 Handle(TDocStd_Application) anApplication = aTreeModel->GetTDocStdApplication();
333 QItemSelectionModel* aSelectionModel = myTreeView->selectionModel();
334 aSelectionModel->clear();
336 NCollection_List<TCollection_AsciiString>::Iterator aSelectedIt (aSelected);
337 if (aSelectedIt.More())
339 TCollection_AsciiString aLabelEntry = aSelectedIt.Value();
342 for (Standard_Integer aDocId = 1, aNbDoc = anApplication->NbDocuments(); aDocId <= aNbDoc; aDocId++)
344 Handle(TDocStd_Document) aDocument;
345 anApplication->GetDocument (aDocId, aDocument);
347 TDF_Tool::Label(aDocument->GetData(), aLabelEntry.ToCString(), aLabel, Standard_False);
348 if (!aLabel.IsNull())
351 if (!aLabel.IsNull())
353 QModelIndex anIndexToBeSelected = aTreeModel->FindIndex (aLabel);
355 TCollection_AsciiString anAttributeType;
357 // find attribute by attribute type on the given label
358 if (aSelectedIt.More())
360 anAttributeType = aSelectedIt.Value();
362 TreeModel_ItemBasePtr aLabelItem = TreeModel_ModelBase::GetItemByIndex (anIndexToBeSelected);
363 //DFBrowser_ItemPtr anItem = itemDynamicCast<DFBrowser_Item> (anItemBase);
364 for (int aChildId = 0, aNbChildren = aLabelItem->rowCount(); aChildId < aNbChildren; aChildId++)
366 QModelIndex anIndex = aTreeModel->index (aChildId, 0, anIndexToBeSelected);
367 TreeModel_ItemBasePtr anItemBase = TreeModel_ModelBase::GetItemByIndex (anIndex);
368 DFBrowser_ItemPtr anItem = itemDynamicCast<DFBrowser_Item> (anItemBase);
369 if (anItem->HasAttribute())
371 // processing attribute in theValue
372 DFBrowser_ItemApplicationPtr aRootAppItem = itemDynamicCast<DFBrowser_ItemApplication>(aTreeModel->RootItem (0));
373 QString anAttributeInfo = DFBrowser_Module::GetAttributeInfo (anItem->GetAttribute(), aRootAppItem->GetModule(),
374 Qt::DisplayRole, 0).toString();
375 if (anAttributeInfo == anAttributeType.ToCString())
377 anIndexToBeSelected = anIndex;
383 aSelectionModel->select (anIndexToBeSelected, QItemSelectionModel::Select);
384 myTreeView->scrollTo (anIndexToBeSelected);
388 myParameters->SetSelectedNames(aName, NCollection_List<TCollection_AsciiString>());
392 // =======================================================================
395 // =======================================================================
396 void DFBrowser_Window::Init (const NCollection_List<Handle(Standard_Transient)>& theParameters)
398 Handle(TDocStd_Application) anApplication;
401 DFBrowser_TreeModel* anOCAFViewModel = dynamic_cast<DFBrowser_TreeModel*> (myModule->GetOCAFViewModel());
403 anApplication = anOCAFViewModel->GetTDocStdApplication();
405 Handle(AIS_InteractiveContext) aContext;
407 aContext = myModule->GetExternalContext();
409 bool aSameApplication = !anApplication.IsNull(), aSameContext = !aContext.IsNull();
410 for (NCollection_List<Handle(Standard_Transient)>::Iterator aParametersIt (theParameters);
411 aParametersIt.More(); aParametersIt.Next())
413 Handle(Standard_Transient) anObject = aParametersIt.Value();
414 // check if the object is an application
415 Handle(TDocStd_Application) anIApplication = Handle(TDocStd_Application)::DownCast (anObject);
416 if (!anIApplication.IsNull())
418 aSameApplication = anApplication == anIApplication;
419 if (!aSameApplication)
420 anApplication = anIApplication;
422 // check if the object is an interactive context
423 Handle(AIS_InteractiveContext) anIContext = Handle(AIS_InteractiveContext)::DownCast (anObject);
424 if (!anIContext.IsNull())
426 aSameContext = aContext == anIContext;
428 aContext = anIContext;
431 if (aSameApplication)
433 if (!aSameContext && !aContext.IsNull())
435 myModule->SetExternalContext (aContext);
436 myViewWindow->SetContext (View_ContextType_External, aContext);
441 myModule = new DFBrowser_Module();
442 myModule->CreateViewModel (myMainWindow);
444 myPropertyPanel->GetAttributesStack()->SetModule (myModule);
446 // model should be set after the attribute pane stack is initialized by module
447 QAbstractItemModel* aModel = myModule->GetOCAFViewModel();
448 setOCAFModel (aModel);
449 myModule->SetOCAFViewSelectionModel (myTreeView->selectionModel());
450 myTreeLevelLine->GetSearchLine()->SetModule (myModule);
451 myPropertyPanel->GetAttributesStack()->GetSearchView()->InitModels();
453 connect (myModule, SIGNAL (beforeUpdateTreeModel()), this, SLOT (onBeforeUpdateTreeModel()));
455 if (!aContext.IsNull())
457 myModule->SetExternalContext (aContext);
458 myViewWindow->SetContext (View_ContextType_External, aContext);
461 myModule->SetApplication (anApplication);
462 //! expand first three levels: CUSTOM
463 QModelIndex aParentIndex = aModel->index (0, 0);
464 setExpandedLevels (myTreeView, aParentIndex, 3/*levels*/);
466 myThread->ProcessApplication();
467 myModule->SetInitialTreeViewSelection();
470 // =======================================================================
471 // function : OpenFile
473 // =======================================================================
474 void DFBrowser_Window::OpenFile (const TCollection_AsciiString& theFileName)
476 QApplication::setOverrideCursor (Qt::WaitCursor);
477 myThread->TerminateThread();
479 myTreeLevelLine->ClearHistory();
480 QItemSelectionModel* aSelectionModel = myModule->GetOCAFViewSelectionModel();
483 aSelectionModel->clearSelection();
485 aSelectionModel->select (anIndex, QItemSelectionModel::ClearAndSelect);
489 myTreeLevelLine->ClearHistory();
491 DFBrowser_TreeModel* anOCAFViewModel = dynamic_cast<DFBrowser_TreeModel*> (myModule->GetOCAFViewModel());
492 anOCAFViewModel->Reset();
494 //! close previous documents to open new document
495 Handle(TDocStd_Application) anApplication = myModule->GetTDocStdApplication();
496 if (!anApplication.IsNull())
498 for (int aDocId = 1, aNbDocuments = anApplication->NbDocuments(); aDocId <= aNbDocuments; aDocId++)
500 Handle(TDocStd_Document) aDocument;
501 anApplication->GetDocument (aDocId, aDocument);
502 if (!aDocument.IsNull())
503 anApplication->Close (aDocument);
507 //! open new document
508 bool isSTEPFileName = false;
509 anApplication = DFBrowser_OpenApplication::OpenApplication (theFileName, isSTEPFileName);
512 myParent->setObjectName (isSTEPFileName ? QString (TCollection_AsciiString (theFileName).ToCString()) : getWindowTitle());
514 myOpenedFileName = isSTEPFileName ? QString(TCollection_AsciiString(theFileName).ToCString()) : getWindowTitle();
516 if (anApplication.IsNull())
518 QApplication::restoreOverrideCursor();
519 QMessageBox::information (0, "Error", QString ("File %1 can't be opened by OCAF application")
520 .arg(TCollection_AsciiString (theFileName).ToCString()));
523 myModule->SetApplication (anApplication);
524 //! expand first three levels: CUSTOM
525 QModelIndex aParentIndex = anOCAFViewModel->index (0, 0);
526 setExpandedLevels (myTreeView, aParentIndex, 3/*levels*/);
528 myThread->ProcessApplication();
529 myModule->SetInitialTreeViewSelection();
530 QApplication::restoreOverrideCursor();
534 // =======================================================================
535 // function : getWindowTitle
537 // =======================================================================
538 QString DFBrowser_Window::getWindowTitle() const
540 DFBrowser_TreeModel* anOCAFViewModel = dynamic_cast<DFBrowser_TreeModel*> (myModule->GetOCAFViewModel());
541 if (!anOCAFViewModel)
544 Handle(TDocStd_Application) anApplication = anOCAFViewModel->GetTDocStdApplication();
545 if (anApplication.IsNull() || anApplication->NbDocuments() == 0)
548 Handle(TDocStd_Document) aDocument;
549 anApplication->GetDocument (1, aDocument);
550 if (aDocument.IsNull() || !aDocument->IsSaved())
553 return DFBrowserPane_Tools::ToString (aDocument->GetPath());
556 // =======================================================================
557 // function : setExpandedLevels
559 // =======================================================================
560 void DFBrowser_Window::setExpandedLevels (QTreeView* theTreeView, const QModelIndex& theParentIndex, const int theLevels)
565 QAbstractItemModel* aModel = theTreeView->model();
569 theTreeView->setExpanded (theParentIndex, true);
570 for (int aRowId = 0, aRows = aModel->rowCount (theParentIndex); aRowId < aRows; aRowId++)
571 setExpandedLevels (theTreeView, aModel->index (aRowId, 0, theParentIndex), theLevels - 1);
574 // =======================================================================
575 // function : setOCAFModel
577 // =======================================================================
578 void DFBrowser_Window::setOCAFModel (QAbstractItemModel* theModel)
580 myTreeView->setModel (theModel);
582 QItemSelectionModel* aSelectionModel = new QItemSelectionModel (theModel);
583 myTreeView->setSelectionModel (aSelectionModel);
585 connect (aSelectionModel, SIGNAL (selectionChanged (const QItemSelection&, const QItemSelection&)),
586 myTreeLevelLine, SLOT (OnTreeViewSelectionChanged (const QItemSelection&, const QItemSelection&)));
587 connect(aSelectionModel, SIGNAL (selectionChanged (const QItemSelection&, const QItemSelection&)),
588 myDumpView, SLOT (OnTreeViewSelectionChanged (const QItemSelection&, const QItemSelection&)));
589 connect (aSelectionModel, SIGNAL (selectionChanged (const QItemSelection&, const QItemSelection&)),
590 this, SLOT (onTreeViewSelectionChanged (const QItemSelection&, const QItemSelection&)));
593 // =======================================================================
594 // function : onBeforeUpdateTreeModel
596 // =======================================================================
597 void DFBrowser_Window::onBeforeUpdateTreeModel()
599 myTreeLevelLine->ClearHistory();
601 myThread->ProcessApplication();
604 // =======================================================================
605 // function : ClearThreadCache
607 // =======================================================================
608 void DFBrowser_Window::ClearThreadCache()
610 DFBrowser_ThreadItemSearch::ClearValues (GetTreeLevelLine()->GetSearchLine());
613 // =======================================================================
614 // function : TmpDirectory
616 // =======================================================================
617 TCollection_AsciiString DFBrowser_Window::TmpDirectory()
619 TCollection_AsciiString aTmpDir;
621 OSD_Environment anEnvironment ("TEMP");
622 aTmpDir = anEnvironment.Value();
623 if (aTmpDir.IsEmpty() )
625 anEnvironment.SetName("TMP");
626 aTmpDir = anEnvironment.Value();
627 if (aTmpDir.IsEmpty())
630 OSD_Path aTmpPath (aTmpDir);
631 OSD_Directory aTmpDirectory (aTmpPath);
632 if (!aTmpDirectory.Exists())
633 aTmpDirectory.Build(OSD_Protection());
635 OSD_Directory aTmpDirectory = OSD_Directory::BuildTemporary();
637 aTmpDirectory.Path (aTmpPath);
638 aTmpPath.SystemName(aTmpDir);
644 // =======================================================================
645 // function : onTreeViewContextMenuRequested
647 // =======================================================================
648 void DFBrowser_Window::onTreeViewContextMenuRequested (const QPoint& thePosition)
650 QMenu* aMenu = new QMenu(GetMainWindow());
651 aMenu->addAction (ViewControl_Tools::CreateAction (tr ("Expand"), SLOT (onExpand()), GetMainWindow(), this));
652 aMenu->addAction (ViewControl_Tools::CreateAction (tr ("Expand All"), SLOT (onExpandAll()), GetMainWindow(), this));
653 aMenu->addAction (ViewControl_Tools::CreateAction (tr ("Collapse All"), SLOT (onCollapseAll()), GetMainWindow(), this));
655 QPoint aPoint = myTreeView->mapToGlobal (thePosition);
656 aMenu->exec (aPoint);
659 // =======================================================================
660 // function : onExpand
662 // =======================================================================
663 void DFBrowser_Window::onExpand()
665 QApplication::setOverrideCursor (Qt::WaitCursor);
667 QItemSelectionModel* aSelectionModel = myTreeView->selectionModel();
668 QModelIndexList aSelectedIndices = aSelectionModel->selectedIndexes();
669 for (int aSelectedId = 0, aSize = aSelectedIndices.size(); aSelectedId < aSize; aSelectedId++)
672 TreeModel_Tools::SetExpanded (myTreeView, aSelectedIndices[aSelectedId], true, aLevels);
674 QApplication::restoreOverrideCursor();
677 // =======================================================================
678 // function : onExpandAll
680 // =======================================================================
681 void DFBrowser_Window::onExpandAll()
683 QApplication::setOverrideCursor (Qt::WaitCursor);
685 QItemSelectionModel* aSelectionModel = myTreeView->selectionModel();
686 QModelIndexList aSelectedIndices = aSelectionModel->selectedIndexes();
687 for (int aSelectedId = 0, aSize = aSelectedIndices.size(); aSelectedId < aSize; aSelectedId++)
690 TreeModel_Tools::SetExpanded (myTreeView, aSelectedIndices[aSelectedId], true, aLevels);
692 QApplication::restoreOverrideCursor();
695 // =======================================================================
696 // function : onCollapseAll
698 // =======================================================================
699 void DFBrowser_Window::onCollapseAll()
701 QItemSelectionModel* aSelectionModel = myTreeView->selectionModel();
702 QModelIndexList aSelectedIndices = aSelectionModel->selectedIndexes();
703 for (int aSelectedId = 0, aSize = aSelectedIndices.size(); aSelectedId < aSize; aSelectedId++) {
705 TreeModel_Tools::SetExpanded (myTreeView, aSelectedIndices[aSelectedId], false, aLevels);
709 // =======================================================================
710 // function : onTreeViewSelectionChanged
712 // =======================================================================
713 void DFBrowser_Window::onTreeViewSelectionChanged (const QItemSelection& theSelected,
714 const QItemSelection& theDeselected)
720 if (myPropertyPanelWidget->toggleViewAction()->isChecked())
721 myPropertyView->Init (ViewControl_Tools::CreateTableModelValues (myTreeView->selectionModel()));
724 // previuos selection should be cleared in the panel selectors
725 DFBrowser_AttributePaneStack* anAttributePaneStack = myPropertyPanel->GetAttributesStack();
726 anAttributePaneStack->GetPaneSelector()->ClearSelected();
728 myPropertyPanel->UpdateBySelectionChanged (theSelected, theDeselected);
729 anAttributePaneStack->GetTreeLevelView()->UpdateByTreeSelectionChanged (theSelected, theDeselected);
731 QModelIndexList aSelectedIndices = theSelected.indexes();
732 QModelIndex aSelectedIndex = TreeModel_ModelBase::SingleSelected (aSelectedIndices, 0);
734 myTreeView->scrollTo (aSelectedIndex);
735 View_Displayer* aDisplayer = myViewWindow->Displayer();
737 aDisplayer->ErasePresentations (View_PresentationType_Additional, false);
738 aDisplayer->DisplayPresentation (findPresentation (aSelectedIndex), View_PresentationType_Main);
741 // =======================================================================
742 // function : onSearchActivated
744 // =======================================================================
745 void DFBrowser_Window::onSearchActivated()
747 myPropertyPanel->GetAttributesStack()->SetPaneMode ((myTreeLevelLine->GetSearchLine()->Text().isEmpty()
748 ? DFBrowser_AttributePaneType_ItemView : DFBrowser_AttributePaneType_SearchView));
751 // =======================================================================
752 // function : onPaneSelectionChanged
754 // =======================================================================
755 void DFBrowser_Window::onPaneSelectionChanged (const QItemSelection&,
756 const QItemSelection&,
757 QItemSelectionModel* theModel)
759 DFBrowserPane_AttributePaneAPI* anAttributePane = myPropertyPanel->GetAttributesStack()->GetCurrentPane();
760 switch (anAttributePane->GetSelectionKind (theModel))
762 case DFBrowserPane_SelectionKind_ExportToShapeViewer:
764 QItemSelectionModel* aSelectionModel = theModel;
765 QModelIndexList aSelectedIndices = aSelectionModel->selectedIndexes();
766 if (aSelectedIndices.size() != 1)
769 TCollection_AsciiString aPluginName ("TKShapeView");
770 NCollection_List<Handle(Standard_Transient)> aParameters;
771 if (myParameters->FindParameters (aPluginName))
772 aParameters = myParameters->Parameters (aPluginName);
774 NCollection_List<TCollection_AsciiString> anItemNames;
775 if (myParameters->FindSelectedNames (aPluginName))
776 anItemNames = myParameters->GetSelectedNames (aPluginName);
778 int aParametersCount = aParameters.Extent();
779 anAttributePane->GetSelectionParameters (aSelectionModel, aParameters, anItemNames);
780 if (aParametersCount != aParameters.Extent()) // some TShapes are added
782 TCollection_AsciiString aPluginShortName = aPluginName.SubString (3, aPluginName.Length());
783 QString aMessage = QString ("TShape %1 is sent to %2.")
784 .arg (Standard_Dump::GetPointerInfo (aParameters.Last()).ToCString())
785 .arg (aPluginShortName.ToCString());
786 QString aQuestion = QString ("Would you like to activate %1 immediately?\n")
787 .arg (aPluginShortName.ToCString()).toStdString().c_str();
788 if (!myExportToShapeViewDialog)
789 myExportToShapeViewDialog = new ViewControl_MessageDialog (myParent, aMessage, aQuestion);
791 myExportToShapeViewDialog->SetInformation (aMessage);
792 myExportToShapeViewDialog->Start();
794 myParameters->SetSelectedNames (aPluginName, anItemNames);
795 myParameters->SetParameters (aPluginName, aParameters, myExportToShapeViewDialog->IsAccepted());
799 case DFBrowserPane_SelectionKind_ExportToBREP:
800 case DFBrowserPane_SelectionKind_LabelReferences:
801 case DFBrowserPane_SelectionKind_AttributeReferences:
805 QItemSelectionModel* aSelectionModel = myTreeView->selectionModel();
806 QModelIndexList aSelectedIndices = aSelectionModel->selectedIndexes();
807 if (aSelectedIndices.size() != 1)
810 // make the shape visualized
811 QModelIndex aSelectedIndex = aSelectedIndices.first();
812 View_Displayer* aDisplayer = myViewWindow->Displayer();
813 aDisplayer->DisplayPresentation (findPresentation (aSelectedIndex), View_PresentationType_Main);
815 // highlight and scroll to the referenced item if it exists
816 Handle(TDF_Attribute) anAttribute = myModule->FindAttribute (aSelectedIndex);
817 NCollection_List<TDF_Label> aReferences;
818 Handle(Standard_Transient) aPresentation;
819 anAttributePane->GetReferences (anAttribute, aReferences, aPresentation);
820 QModelIndexList anIndices;
821 DFBrowser_TreeModel* aTreeModel = dynamic_cast<DFBrowser_TreeModel*> (myTreeView->model());
822 if (!aReferences.IsEmpty())
823 aTreeModel->ConvertToIndices (aReferences, anIndices);
825 NCollection_List<Handle(TDF_Attribute)> anAttributeReferences;
826 anAttributePane->GetAttributeReferences (anAttribute, anAttributeReferences, aPresentation);
827 aTreeModel->ConvertToIndices (anAttributeReferences, anIndices);
829 highlightIndices (anIndices);
830 // display either the reference presentation of the panel or find a presentation if the reference
832 if (!aPresentation.IsNull())
833 aDisplayer->DisplayPresentation (aPresentation, View_PresentationType_Additional);
835 aDisplayer->ErasePresentations (View_PresentationType_Additional, false);
836 AIS_ListOfInteractive aDisplayed;
837 findPresentations (anIndices, aDisplayed);
838 for (AIS_ListIteratorOfListOfInteractive aDisplayedIt (aDisplayed); aDisplayedIt.More(); aDisplayedIt.Next())
839 aDisplayer->DisplayPresentation (aDisplayedIt.Value(), View_PresentationType_Additional, false);
841 aDisplayer->UpdateViewer();
845 // =======================================================================
846 // function : onTreeLevelLineSelected
848 // =======================================================================
849 void DFBrowser_Window::onTreeLevelLineSelected (const QModelIndex& theIndex)
851 QItemSelectionModel* aSelectionModel = myTreeView->selectionModel();
852 if (theIndex.isValid())
853 aSelectionModel->select (theIndex, QItemSelectionModel::ClearAndSelect);
855 aSelectionModel->clearSelection();
858 // =======================================================================
859 // function : onUpdateClicked
861 // =======================================================================
862 void DFBrowser_Window::onUpdateClicked()
865 myModule->UpdateTreeModel();
868 // =======================================================================
869 // function : onSearchPathSelected
871 // =======================================================================
872 void DFBrowser_Window::onSearchPathSelected (const QStringList& thePath, const QString& theValue)
874 DFBrowser_TreeModel* aDFBrowserModel = dynamic_cast<DFBrowser_TreeModel*> (myTreeView->model());
875 const QModelIndex& anIndex = aDFBrowserModel->FindIndexByPath (thePath, theValue);
877 if (anIndex.isValid())
879 QModelIndexList anIndices;
880 anIndices.append (anIndex);
881 highlightIndices (anIndices);
885 // =======================================================================
886 // function : onSearchPathDoubleClicked
888 // =======================================================================
889 void DFBrowser_Window::onSearchPathDoubleClicked (const QStringList& thePath, const QString& theValue)
891 DFBrowser_TreeModel* aDFBrowserModel = dynamic_cast<DFBrowser_TreeModel*> (myTreeView->model());
892 const QModelIndex& anIndex = aDFBrowserModel->FindIndexByPath (thePath, theValue);
894 QItemSelectionModel* aSelectionModel = myTreeView->selectionModel();
895 if (anIndex.isValid())
896 aSelectionModel->select (anIndex, QItemSelectionModel::ClearAndSelect);
898 aSelectionModel->clearSelection();
901 // =======================================================================
902 // function : onLevelSelected
904 // =======================================================================
905 void DFBrowser_Window::onLevelSelected (const QModelIndex& theIndex)
907 if (!theIndex.isValid())
910 QModelIndexList anIndices;
911 anIndices.append (theIndex);
912 highlightIndices (anIndices);
913 View_Displayer* aDisplayer = myViewWindow->Displayer();
914 aDisplayer->ErasePresentations (View_PresentationType_Additional, false);
915 aDisplayer->DisplayPresentation (findPresentation (theIndex), View_PresentationType_Main);
918 // =======================================================================
919 // function : onLevelDoubleClicked
921 // =======================================================================
922 void DFBrowser_Window::onLevelDoubleClicked (const QModelIndex& theIndex)
924 QItemSelectionModel* aSelectionModel = myTreeView->selectionModel();
925 if (theIndex.isValid())
926 aSelectionModel->select (theIndex, QItemSelectionModel::ClearAndSelect);
928 aSelectionModel->clearSelection();
931 // =======================================================================
932 // function : highlightIndices
934 // =======================================================================
935 void DFBrowser_Window::highlightIndices (const QModelIndexList& theIndices)
937 QAbstractItemModel* aModel = myTreeView->model();
941 DFBrowser_TreeModel* aTreeModel = dynamic_cast<DFBrowser_TreeModel*> (aModel);
945 aTreeModel->SetHighlighted (theIndices);
947 QModelIndex anIndexToScroll;
948 if (!theIndices.isEmpty())
949 anIndexToScroll = theIndices.last(); // scroll to last selected index
952 // scroll to tree selected item
953 QItemSelectionModel* aSelectionModel = myTreeView->selectionModel();
954 QModelIndexList aSelectedIndices = aSelectionModel->selectedIndexes();
955 if (aSelectedIndices.size() == 1)
956 anIndexToScroll = aSelectedIndices.first();
958 if (anIndexToScroll.isValid())
959 myTreeView->scrollTo (anIndexToScroll);
961 if (theIndices.isEmpty())
962 myTreeView->setFocus(); // to see the selected item in active palette color
964 aTreeModel->EmitLayoutChanged();
967 // =======================================================================
968 // function : findPresentation
970 // =======================================================================
971 Handle(AIS_InteractiveObject) DFBrowser_Window::findPresentation (const QModelIndex& theIndex)
973 Handle(AIS_InteractiveObject) aPresentation;
975 QModelIndexList anIndices;
976 anIndices.append (theIndex);
977 AIS_ListOfInteractive aDisplayed;
978 findPresentations (anIndices, aDisplayed);
979 if (!aDisplayed.IsEmpty())
980 aPresentation = aDisplayed.First();
982 return aPresentation;
985 // =======================================================================
986 // function : findPresentations
988 // =======================================================================
989 void DFBrowser_Window::findPresentations (const QModelIndexList& theIndices, AIS_ListOfInteractive& thePresentations)
991 for (int anIndexId = 0, aCount = theIndices.size(); anIndexId < aCount; anIndexId++)
993 Handle(AIS_InteractiveObject) aPresentation;
994 Handle(TDF_Attribute) anAttribute = myModule->FindAttribute (theIndices[anIndexId]);
995 if (anAttribute.IsNull())
997 DFBrowserPane_AttributePaneAPI* anAttributePane = myModule->GetAttributePane (anAttribute);
998 if (!anAttributePane)
1000 aPresentation = Handle(AIS_InteractiveObject)::DownCast (anAttributePane->GetPresentation (anAttribute));
1001 if (aPresentation.IsNull())
1004 thePresentations.Append (aPresentation);