1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-05 18:16:23 +03:00

0029674: Improvements in Inspector tool

- preferences for dock windows geometry, tree view columns and current view projection;
- ViewControl package for common functionality between plugins;
- processing Location and Orientation for external TopoDS_Shape object
- 'F5' key to update content of each plugin
- visibility column in tree view (used now only in ShapeView)
- properties child item for context (presents tree of current Filters of context)
This commit is contained in:
nds 2018-03-23 16:08:11 +03:00 committed by bugmaster
parent 6dfdbb7ab8
commit 6822a3bef1
135 changed files with 4187 additions and 1603 deletions

View File

@ -1019,9 +1019,9 @@ OCCT_MODULES_AND_TOOLKITS (SAMPLES "SAMPLES_TOOLKITS" OCCT_SAMPLES)
if (BUILD_Inspector OR BUILD_MODULE_QtSamples)
if (BUILD_MODULE_QtSamples)
if (NOT Qt5_FOUND OR NOT WIN32)
if (NOT Qt5_FOUND OR "${Qt5Gui_EGL_INCLUDE_DIRS}" STREQUAL "" OR NOT WIN32)
list (REMOVE_ITEM qt_SAMPLES_TOOLKITS AndroidQt)
message (STATUS "Info: AndroidQt sample excluded due to Qt5 usage is disabled or OS is not Windows")
message (STATUS "Info: AndroidQt sample excluded due to OS is not Windows or Qt is configured without ANGLE")
endif()
else()
list (REMOVE_ITEM OCCT_SAMPLES qt)

View File

@ -25,7 +25,7 @@ set(CMAKE_PREFIX_PATH ${3RDPARTY_QT_DIR})
# Now we can apply standard CMake finder for Qt5. We do this mostly
# to have qt5_wrap_cpp() function available and Qt5_FOUND variable filled
find_package(Qt5 QUIET COMPONENTS Widgets Quick PATHS ${3RDPARTY_QT_DIR} NO_DEFAULT_PATH)
find_package(Qt5 QUIET COMPONENTS Widgets Quick Xml PATHS ${3RDPARTY_QT_DIR} NO_DEFAULT_PATH)
if (NOT ${Qt5_FOUND})
# Now we can apply standard CMake finder for Qt. We do this mostly
# to have qt4_wrap_cpp() function available

View File

@ -9,9 +9,9 @@ macro (FIND_QT_PACKAGE PROJECT_LIBRARIES_DEBUG PROJECT_LIBRARIES_RELEASE PROJECT
if (${Qt5_FOUND})
#message (STATUS "Qt5 cmake configuration")
set(PROJECT_INCLUDES "${Qt5Widgets_INCLUDE_DIRS}" "${Qt5Quick_INCLUDE_DIRS}")
set(PROJECT_LIBRARIES_DEBUG "${Qt5Widgets_LIBRARIES}" "${Qt5Quick_LIBRARIES}")
set(PROJECT_LIBRARIES_RELEASE "${Qt5Widgets_LIBRARIES}" "${Qt5Quick_LIBRARIES}")
set(PROJECT_INCLUDES "${Qt5Widgets_INCLUDE_DIRS}" "${Qt5Quick_INCLUDE_DIRS}" "${Qt5Xml_INCLUDE_DIRS}")
set(PROJECT_LIBRARIES_DEBUG "${Qt5Widgets_LIBRARIES}" "${Qt5Quick_LIBRARIES}" "${Qt5Xml_LIBRARIES}")
set(PROJECT_LIBRARIES_RELEASE "${Qt5Widgets_LIBRARIES}" "${Qt5Quick_LIBRARIES}" "${Qt5Xml_LIBRARIES}")
# processing *.ts files to generate *.qm
find_package(Qt5LinguistTools)
@ -24,11 +24,11 @@ macro (FIND_QT_PACKAGE PROJECT_LIBRARIES_DEBUG PROJECT_LIBRARIES_RELEASE PROJECT
#message (STATUS "Qt4 cmake configuration")
set(PROJECT_INCLUDES ${QT_INCLUDES})
if (WIN32)
set(PROJECT_LIBRARIES_DEBUG "${3RDPARTY_QT_DIR}/lib/QtCored4.lib;${3RDPARTY_QT_DIR}/lib/QtGuid4.lib")
set(PROJECT_LIBRARIES_RELEASE "${3RDPARTY_QT_DIR}/lib/QtCore4.lib;${3RDPARTY_QT_DIR}/lib/QtGui4.lib")
set(PROJECT_LIBRARIES_DEBUG "${3RDPARTY_QT_DIR}/lib/QtCored4.lib;${3RDPARTY_QT_DIR}/lib/QtGuid4.lib;${3RDPARTY_QT_DIR}/lib/QtXmld4.lib")
set(PROJECT_LIBRARIES_RELEASE "${3RDPARTY_QT_DIR}/lib/QtCore4.lib;${3RDPARTY_QT_DIR}/lib/QtGui4.lib;${3RDPARTY_QT_DIR}/lib/QtXml4.lib")
else()
set(PROJECT_LIBRARIES_DEBUG "${3RDPARTY_QT_DIR}/lib/libQtCore.so;${3RDPARTY_QT_DIR}/lib/libQtGui.so")
set(PROJECT_LIBRARIES_RELEASE "${3RDPARTY_QT_DIR}/lib/libQtCore.so;${3RDPARTY_QT_DIR}/lib/libQtGui.so")
set(PROJECT_LIBRARIES_DEBUG "${3RDPARTY_QT_DIR}/lib/libQtCore.so;${3RDPARTY_QT_DIR}/lib/libQtGui.so;${3RDPARTY_QT_DIR}/lib/libQtXml.so")
set(PROJECT_LIBRARIES_RELEASE "${3RDPARTY_QT_DIR}/lib/libQtCore.so;${3RDPARTY_QT_DIR}/lib/libQtGui.so;${3RDPARTY_QT_DIR}/lib/libQtXml.so")
endif(WIN32)
find_program(QT_LRELEASE_EXECUTABLE lrelease)
endif()

View File

@ -20,11 +20,13 @@
#include <OSD_Environment.hxx>
#include <Standard_WarningsDisable.hxx>
#include <QAction>
#include <QApplication>
#include <QDir>
#include <QMainWindow>
#include <QToolBar>
#include <Standard_WarningsRestore.hxx>
#include <set>

View File

@ -18,6 +18,7 @@
#include <inspector/TInspector_Communicator.hxx>
#include <Standard_WarningsDisable.hxx>
#include <QApplication>
#include <QCompleter>
#include <QDir>
@ -35,6 +36,7 @@
#include <QPushButton>
#include <QVBoxLayout>
#include <QWidget>
#include <Standard_WarningsRestore.hxx>
const int FONT_POINT_SIZE = 18;
const int ICON_SIZE = 40;
@ -232,8 +234,9 @@ void TInspectorEXE_OpenFileDialog::onSelectClicked()
if (aFileName.isEmpty())
return; // do nothing, left the previous value
mySelectedName->setText (aFileName);
onNameChanged (aFileName);
myFileName = aFileName;
accept();
}
// =======================================================================

View File

@ -19,12 +19,11 @@
#include <NCollection_DataMap.hxx>
#include <TCollection_AsciiString.hxx>
#ifdef _MSC_VER
#pragma warning(disable : 4127) // conditional expression is constant
#endif
#include <Standard_WarningsDisable.hxx>
#include <QDialog>
#include <QItemSelection>
#include <QStringList>
#include <Standard_WarningsRestore.hxx>
#include <map>

View File

@ -15,10 +15,12 @@
#include <TInspectorEXE_OpenFileViewModel.hxx>
#include <Standard_WarningsDisable.hxx>
#include <QApplication>
#include <QFileInfo>
#include <QIcon>
#include <QPainter>
#include <Standard_WarningsRestore.hxx>
const int ICON_SIZE = 40;
@ -36,11 +38,9 @@ void TInspectorEXE_OpenFileItemDelegate::paint (QPainter* thePainter, const QSty
// action icon for all indices before the last one
QIcon anIcon (":/icons/folder_import.png");
QSize anIconSize (ICON_SIZE, ICON_SIZE);
int aWidth = theOption.rect.width();
int aCenter = aWidth / 2.;
int aHalf = anIconSize.width() / 2.;
int aDX = (theOption.rect.width() - anIconSize.width()) / 2;
int aMargin = qApp->style()->pixelMetric (QStyle::PM_HeaderMargin);
thePainter->drawPixmap (QRect (theOption.rect.left() + (aCenter - aHalf),
thePainter->drawPixmap (QRect (theOption.rect.left() + aDX,
theOption.rect.top() + aMargin,
anIconSize.width(),
anIconSize.height()),

View File

@ -18,12 +18,11 @@
#include <Standard_Macro.hxx>
#ifdef _MSC_VER
#pragma warning(disable : 4127) // conditional expression is constant
#endif
#include <Standard_WarningsDisable.hxx>
#include <QAbstractTableModel>
#include <QStringList>
#include <QItemDelegate>
#include <Standard_WarningsRestore.hxx>
class QObject;
class QPainter;

View File

@ -70,6 +70,27 @@ Standard_CString TopAbs::ShapeOrientationToString (TopAbs_Orientation theOrienta
return TopAbs_Table_PrintOrientation[theOrientation];
}
//=======================================================================
//function : ShapeOrientationFromString
//purpose :
//=======================================================================
Standard_Boolean TopAbs::ShapeOrientationFromString (const Standard_CString theOrientationString,
TopAbs_Orientation& theOrientation)
{
TCollection_AsciiString aName (theOrientationString);
aName.UpperCase();
for (Standard_Integer anOrientationIter = 0; anOrientationIter <= TopAbs_EXTERNAL; ++anOrientationIter)
{
Standard_CString anOrientationName = TopAbs_Table_PrintOrientation[anOrientationIter];
if (aName == anOrientationName)
{
theOrientation = TopAbs_Orientation(anOrientationIter);
return Standard_True;
}
}
return Standard_False;
}
//=======================================================================
//function : TopAbs_Compose
//purpose : Compose two orientations

View File

@ -141,6 +141,22 @@ public:
//! @return string identifier from the list FORWARD, REVERSED, INTERNAL, EXTERNAL
Standard_EXPORT static Standard_CString ShapeOrientationToString (TopAbs_Orientation theOrientation);
//! Returns the shape orientation from the given string identifier (using case-insensitive comparison).
//! @param theOrientationString string identifier
//! @return shape orientation or TopAbs_FORWARD if string identifier is invalid
static TopAbs_Orientation ShapeOrientationFromString (const Standard_CString theOrientationString)
{
TopAbs_Orientation aType = TopAbs_FORWARD;
ShapeOrientationFromString (theOrientationString, aType);
return aType;
}
//! Determines the shape orientation from the given string identifier (using case-insensitive comparison).
//! @param theOrientationString string identifier
//! @param theOrientation detected shape orientation
//! @return TRUE if string identifier is known
Standard_EXPORT static Standard_Boolean ShapeOrientationFromString (const Standard_CString theOrientationString,
TopAbs_Orientation& theOrientation);
};
#endif // _TopAbs_HeaderFile

View File

@ -26,6 +26,17 @@
#include <V3d_View.hxx>
#include <V3d_Viewer.hxx>
namespace
{
static Standard_CString V3d_Table_PrintTypeOfOrientation[26] =
{
"XPOS", "YPOS", "ZPOS", "XNEG", "YNEG", "ZNEG", "XPOSYPOS", "XPOSZPOS", "XPOSZPOS", "XNEGYNEG",
"XNEGYPOS", "XNEGZNEG", "XNEGZPOS", "YNEGZNEG", "YNEGZPOS", "XPOSYNEG", "XPOSZNEG", "YPOSZNEG",
"XPOSYPOSZPOS", "XPOSYNEGZPOS", "XPOSYPOSZNEG", "XNEGYPOSZPOS", "XPOSYNEGZNEG", "XNEGYPOSZNEG",
"XNEGYNEGZPOS", "XNEGYNEGZNEG"
};
}
void V3d::ArrowOfRadius(const Handle(Graphic3d_Group)& garrow,const Standard_Real X0,const Standard_Real Y0,const Standard_Real Z0,const Standard_Real Dx,const Standard_Real Dy,const Standard_Real Dz,const Standard_Real Alpha,const Standard_Real Lng)
{
Standard_Real Xc, Yc, Zc, Xi, Yi, Zi, Xj, Yj, Zj;
@ -134,3 +145,33 @@ void V3d::SwitchViewsinWindow(const Handle(V3d_View)& aPreviousView,
aNextView->Viewer()->SetViewOn(aNextView);
}
//=======================================================================
//function : TypeOfOrientationToString
//purpose :
//=======================================================================
Standard_CString V3d::TypeOfOrientationToString (V3d_TypeOfOrientation theType)
{
return V3d_Table_PrintTypeOfOrientation[theType];
}
//=======================================================================
//function : TypeOfOrientationFromString
//purpose :
//=======================================================================
Standard_Boolean V3d::TypeOfOrientationFromString (Standard_CString theTypeString,
V3d_TypeOfOrientation& theType)
{
TCollection_AsciiString aName (theTypeString);
aName.UpperCase();
for (Standard_Integer aTypeIter = 0; aTypeIter <= V3d_XnegYnegZneg; ++aTypeIter)
{
Standard_CString aTypeName = V3d_Table_PrintTypeOfOrientation[aTypeIter];
if (aName == aTypeName)
{
theType = V3d_TypeOfOrientation (aTypeIter);
return Standard_True;
}
}
return Standard_False;
}

View File

@ -93,6 +93,28 @@ public:
Standard_EXPORT static void SwitchViewsinWindow (const Handle(V3d_View)& aPreviousView, const Handle(V3d_View)& aNextView);
//! Returns the string name for a given orientation type.
//! @param theType orientation type
//! @return string identifier from the list Xpos, Ypos, Zpos and others
Standard_EXPORT static Standard_CString TypeOfOrientationToString (V3d_TypeOfOrientation theType);
//! Returns the orientation type from the given string identifier (using case-insensitive comparison).
//! @param theTypeString string identifier
//! @return orientation type or V3d_TypeOfOrientation if string identifier is invalid
static V3d_TypeOfOrientation TypeOfOrientationFromString (Standard_CString theTypeString)
{
V3d_TypeOfOrientation aType = V3d_Xpos;
TypeOfOrientationFromString (theTypeString, aType);
return aType;
}
//! Determines the shape type from the given string identifier (using case-insensitive comparison).
//! @param theTypeString string identifier
//! @param theType detected shape type
//! @return TRUE if string identifier is known
Standard_EXPORT static Standard_Boolean TypeOfOrientationFromString (const Standard_CString theTypeString,
V3d_TypeOfOrientation& theType);
};
#endif // _V3d_HeaderFile

View File

@ -25,6 +25,8 @@
#include <inspector/DFBrowser_SearchView.hxx>
#include <inspector/DFBrowser_Window.hxx>
#include <inspector/ViewControl_Tools.hxx>
#include <TDF_Attribute.hxx>
#include <Standard_WarningsDisable.hxx>
@ -51,9 +53,9 @@ DFBrowser_AttributePaneStack::DFBrowser_AttributePaneStack (QObject* theParent)
void DFBrowser_AttributePaneStack::CreateWidget (QWidget* theParent)
{
myAttributesStack = new QStackedWidget (theParent);
DFBrowser_Window::SetWhiteBackground (myAttributesStack);
ViewControl_Tools::SetWhiteBackground (myAttributesStack);
myEmptyWidget = new QWidget (theParent);
DFBrowser_Window::SetWhiteBackground (myEmptyWidget);
ViewControl_Tools::SetWhiteBackground (myEmptyWidget);
myAttributesStack->addWidget (myEmptyWidget);
@ -87,7 +89,7 @@ void DFBrowser_AttributePaneStack::SetPaneMode (const DFBrowser_AttributePaneTyp
else
{
QItemSelectionModel* aSelectionModel = myModule->GetOCAFViewSelectionModel();
QModelIndex anIndex = DFBrowser_Window::SingleSelected (aSelectionModel->selectedIndexes(), 0);
QModelIndex anIndex = TreeModel_ModelBase::SingleSelected (aSelectionModel->selectedIndexes(), 0);
SetCurrentItem (anIndex);
}
}

View File

@ -49,6 +49,20 @@ public:
//! \param theParameters a parameters container
Standard_EXPORT virtual void SetParameters (const Handle(TInspectorAPI_PluginParameters)& theParameters) Standard_OVERRIDE;
//! Provide container for actions available in inspector on general level
//! \param theMenu if Qt implementation, it is QMenu object
Standard_EXPORT virtual void FillActionsMenu (void* theMenu) Standard_OVERRIDE { myWindow->FillActionsMenu (theMenu); }
//! Returns plugin preferences, empty implementation by default
//! \param theItem container of preference elements
virtual void GetPreferences (TInspectorAPI_PreferencesDataMap& theItem) Standard_OVERRIDE
{ myWindow->GetPreferences (theItem); }
//! Stores plugin preferences, empty implementation by default
//! \param theItem container of preference elements
virtual void SetPreferences (const TInspectorAPI_PreferencesDataMap& theItem) Standard_OVERRIDE
{ myWindow->SetPreferences (theItem); }
//! Updates content of the current window
virtual void UpdateContent() Standard_OVERRIDE { myWindow->UpdateContent(); }

View File

@ -31,8 +31,6 @@
#include <QObject>
#include <Standard_WarningsRestore.hxx>
const int INFO_LENGHT = 60;
// =======================================================================
// function : hasAttribute
// purpose :
@ -136,8 +134,8 @@ QVariant DFBrowser_Item::initValue (const int theItemRole) const
DFBrowser_ItemRole_AdditionalInfo, Column()).toString();
if (!anAdditionalInfo.isEmpty())
{
if (theItemRole == DFBrowserPane_ItemRole_DisplayExtended && anAdditionalInfo.length() > INFO_LENGHT)
anAdditionalInfo = anAdditionalInfo.mid (0, INFO_LENGHT - 3) + "...";
if (theItemRole == DFBrowserPane_ItemRole_DisplayExtended)
anAdditionalInfo = TreeModel_Tools::CutString (anAdditionalInfo);
if (!anAdditionalInfo.isEmpty())
aValue = QVariant (aValue.toString() + QString (" [%1]").arg (anAdditionalInfo));
//if (aRole == Qt::ToolTipRole)

View File

@ -21,6 +21,10 @@
#include <inspector/DFBrowser_Window.hxx>
#include <inspector/DFBrowser_TreeLevelView.hxx>
#include <inspector/TreeModel_ModelBase.hxx>
#include <inspector/ViewControl_Tools.hxx>
#include <Standard_WarningsDisable.hxx>
#include <QAbstractItemModel>
#include <QGridLayout>
@ -36,7 +40,7 @@ DFBrowser_PropertyPanel::DFBrowser_PropertyPanel (QWidget* theParent)
: QObject (theParent), myAttributesStack (0)
{
myMainWindow = new QWidget (theParent);
DFBrowser_Window::SetWhiteBackground (myMainWindow);
ViewControl_Tools::SetWhiteBackground (myMainWindow);
QGridLayout* aLayout = new QGridLayout (myMainWindow);
aLayout->setContentsMargins (0, 0, 0, 0);
@ -55,6 +59,6 @@ void DFBrowser_PropertyPanel::UpdateBySelectionChanged (const QItemSelection& th
{
GetAttributesStack()->GetSearchView()->Reset();
QModelIndex anIndex = DFBrowser_Window::SingleSelected (theSelected.indexes(), 0);
QModelIndex anIndex = TreeModel_ModelBase::SingleSelected (theSelected.indexes(), 0);
myAttributesStack->SetCurrentItem (anIndex);
}

View File

@ -20,6 +20,8 @@
#include <inspector/DFBrowserPane_Tools.hxx>
#include <inspector/DFBrowser_Module.hxx>
#include <inspector/ViewControl_Tools.hxx>
#include <TDocStd_Application.hxx>
#include <TDocStd_Document.hxx>
#include <TDF_AttributeIterator.hxx>
@ -108,7 +110,7 @@ DFBrowser_SearchLine::DFBrowser_SearchLine (QWidget* theParent)
connect (myLineControl, SIGNAL (returnPressed()), this, SLOT (onReturnPressed()));
connect (mySearchButton, SIGNAL (clicked()), this, SLOT (onSearchButtonClicked()));
DFBrowser_Window::SetWhiteBackground (this);
ViewControl_Tools::SetWhiteBackground (this);
}
// =======================================================================

View File

@ -22,6 +22,11 @@
#include <inspector/DFBrowserPane_Tools.hxx>
#include <inspector/TreeModel_ModelBase.hxx>
#include <inspector/TreeModel_Tools.hxx>
#include <inspector/ViewControl_Tools.hxx>
#include <Standard_WarningsDisable.hxx>
#include <QAbstractProxyModel>
#include <QGridLayout>
@ -46,7 +51,7 @@ DFBrowser_SearchView::DFBrowser_SearchView (QWidget* theParent)
myTableView = new QTableView (myMainWindow);
myTableView->verticalHeader()->setVisible (false);
myTableView->verticalHeader()->setDefaultSectionSize (DEFAULT_ICON_SIZE + DFBrowserPane_Tools::HeaderSectionMargin());
myTableView->verticalHeader()->setDefaultSectionSize (DEFAULT_ICON_SIZE + TreeModel_Tools::HeaderSectionMargin());
myTableView->setIconSize (QSize (DEFAULT_ICON_SIZE, DEFAULT_ICON_SIZE));
myTableView->horizontalHeader()->setVisible (false);
myTableView->horizontalHeader()->setStretchLastSection (true);
@ -56,7 +61,7 @@ DFBrowser_SearchView::DFBrowser_SearchView (QWidget* theParent)
aLayout->addWidget (myTableView);
DFBrowser_Window::SetWhiteBackground (myTableView);
ViewControl_Tools::SetWhiteBackground (myTableView);
myTableView->setGridStyle (Qt::NoPen);
}
@ -69,7 +74,7 @@ void DFBrowser_SearchView::InitModels()
QAbstractItemModel* aModel = mySearchLine->GetCompletionModel();
myTableView->setModel (aModel);
myTableView->setColumnWidth (0, 0); // to hide column
myTableView->setColumnWidth (1, DEFAULT_ICON_SIZE + DFBrowserPane_Tools::HeaderSectionMargin());
myTableView->setColumnWidth (1, DEFAULT_ICON_SIZE + TreeModel_Tools::HeaderSectionMargin());
QItemSelectionModel* aSelectionModel = new QItemSelectionModel (aModel);
myTableView->setSelectionMode (QAbstractItemView::SingleSelection);
@ -89,7 +94,7 @@ void DFBrowser_SearchView::onTableSelectionChanged (const QItemSelection&,
{
QItemSelectionModel* aSelectionModel = myTableView->selectionModel();
QModelIndexList aSelectedIndices = aSelectionModel->selectedIndexes();
QModelIndex aSelectedIndex = DFBrowser_Window::SingleSelected (aSelectedIndices, 2);
QModelIndex aSelectedIndex = TreeModel_ModelBase::SingleSelected (aSelectedIndices, 2);
if (!aSelectedIndex.isValid())
return;
QAbstractProxyModel* aTableModel = dynamic_cast<QAbstractProxyModel*> (myTableView->model());

View File

@ -15,7 +15,6 @@
#include <inspector/DFBrowser_Thread.hxx>
#include <inspector/DFBrowser_ThreadItemSearch.hxx>
#include <inspector/DFBrowser_ThreadItemUsedShapesMap.hxx>
#include <inspector/DFBrowser_TreeLevelLine.hxx>
#include <inspector/DFBrowser_SearchLine.hxx>
@ -67,21 +66,6 @@ DFBrowser_Thread::DFBrowser_Thread (DFBrowser_Window* theWindow)
{
DFBrowser_SearchLine* aSearchLine = theWindow->GetTreeLevelLine()->GetSearchLine();
myItems.append (new DFBrowser_ThreadItemSearch(aSearchLine));
myItems.append (new DFBrowser_ThreadItemUsedShapesMap());
}
// =======================================================================
// function : SetModule
// purpose :
// =======================================================================
void DFBrowser_Thread::SetModule (DFBrowser_Module* theModule)
{
for (int anItemId = 0, aSize = myItems.size(); anItemId < aSize; anItemId++)
{
DFBrowser_ThreadItemUsedShapesMap* aShapesItem = dynamic_cast<DFBrowser_ThreadItemUsedShapesMap*> (myItems[anItemId]);
if (aShapesItem)
aShapesItem->SetModule (theModule);
}
}
// =======================================================================

View File

@ -42,10 +42,6 @@ public:
//! Destructor
virtual ~DFBrowser_Thread() {}
//! Sets module to the started thread items
//! \param theModule a current module
Standard_EXPORT void SetModule (DFBrowser_Module* theModule);
//! Starts all candidate thread items
Standard_EXPORT void ProcessApplication();

View File

@ -1,223 +0,0 @@
// Created on: 2017-06-16
// Created by: Natalia ERMOLAEVA
// Copyright (c) 2017 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <inspector/DFBrowser_ThreadItemUsedShapesMap.hxx>
#include <inspector/DFBrowser_Module.hxx>
#include <inspector/DFBrowser_Tools.hxx>
#include <inspector/DFBrowser_TreeModel.hxx>
#include <inspector/DFBrowserPane_TNamingUsedShapes.hxx>
#include <inspector/DFBrowserPane_Tools.hxx>
#include <TNaming_DataMapIteratorOfDataMapOfShapePtrRefShape.hxx>
#include <TNaming_PtrRefShape.hxx>
#include <TNaming_RefShape.hxx>
#include <TNaming_UsedShapes.hxx>
#include <Standard_Type.hxx>
#include <TDocStd_Document.hxx>
// =======================================================================
// function : Run
// purpose :
// =======================================================================
void DFBrowser_ThreadItemUsedShapesMap::Run()
{
if (!myModule)
return;
DFBrowser_TreeModel* aDFBrowserModel = dynamic_cast<DFBrowser_TreeModel*> (myModule->GetOCAFViewModel());
if (!aDFBrowserModel)
return;
Handle(TDocStd_Application) anApplication = aDFBrowserModel->GetTDocStdApplication();
if (anApplication.IsNull())
return;
for (Standard_Integer aDocId = 1, aNbDocuments = anApplication->NbDocuments(); aDocId <= aNbDocuments; aDocId++)
{
Handle(TDocStd_Document) aDocument;
anApplication->GetDocument (aDocId, aDocument);
if (aDocument.IsNull())
continue;
TDF_Label aLabel = aDocument->Main().Root();
Handle(TNaming_UsedShapes) anAttribute;
if (!aLabel.FindAttribute (TNaming_UsedShapes::GetID(), anAttribute))
continue;
std::list<TCollection_AsciiString> aReferences;
findReferences (anAttribute, aReferences);
if (!aReferences.empty())
myAttributeRefs.Bind (anAttribute, aReferences);
}
}
// =======================================================================
// function : ApplyValues
// purpose :
// =======================================================================
void DFBrowser_ThreadItemUsedShapesMap::ApplyValues()
{
if (myAttributeRefs.IsEmpty())
return;
DFBrowserPane_AttributePaneAPI* aPane = myModule->GetAttributePane (STANDARD_TYPE (TNaming_UsedShapes)->Name());
if (aPane)
{
DFBrowserPane_TNamingUsedShapes* aUsedShapesPane = dynamic_cast<DFBrowserPane_TNamingUsedShapes*> (aPane);
aUsedShapesPane->SetSortedReferences (myAttributeRefs);
}
// update
DFBrowser_TreeModel* aDFBrowserModel = dynamic_cast<DFBrowser_TreeModel*> (myModule->GetOCAFViewModel());
for (NCollection_DataMap<Handle(TDF_Attribute), std::list<TCollection_AsciiString> >::Iterator aRefIt (myAttributeRefs);
aRefIt.More(); aRefIt.Next())
{
TreeModel_ItemBasePtr anItemBase = TreeModel_ModelBase::GetItemByIndex
(aDFBrowserModel->FindIndexByAttribute (aRefIt.Key()));
if (anItemBase)
{
anItemBase->Reset();
anItemBase->Init();
}
}
// clear cache
myAttributeRefs.Clear();
}
// =======================================================================
// function : ClearSortedReferences
// purpose :
// =======================================================================
void DFBrowser_ThreadItemUsedShapesMap::ClearSortedReferences (DFBrowser_Module* theModule)
{
DFBrowserPane_AttributePaneAPI* aPane = theModule->GetAttributePane (STANDARD_TYPE (TNaming_UsedShapes)->Name());
if (!aPane)
return;
DFBrowserPane_TNamingUsedShapes* aUsedShapesPane = dynamic_cast<DFBrowserPane_TNamingUsedShapes*> (aPane);
aUsedShapesPane->ClearSortedReferences();
// update tree item state
DFBrowser_TreeModel* aDFBrowserModel = dynamic_cast<DFBrowser_TreeModel*> (theModule->GetOCAFViewModel());
if (!aDFBrowserModel)
return;
Handle(TDocStd_Application) anApplication = aDFBrowserModel->GetTDocStdApplication();
if (anApplication.IsNull())
return;
for (Standard_Integer aDocId = 1, aNbDocuments = anApplication->NbDocuments(); aDocId <= aNbDocuments; aDocId++)
{
Handle(TDocStd_Document) aDocument;
anApplication->GetDocument (aDocId, aDocument);
if (aDocument.IsNull())
continue;
TDF_Label aLabel = aDocument->Main().Root();
Handle(TNaming_UsedShapes) anAttribute;
if (aLabel.FindAttribute (TNaming_UsedShapes::GetID(), anAttribute))
{
TreeModel_ItemBasePtr anItemBase = TreeModel_ModelBase::GetItemByIndex(
aDFBrowserModel->FindIndexByAttribute (anAttribute));
if (anItemBase)
anItemBase->Init();
}
}
}
// =======================================================================
// function : isLessThan
// purpose :
// =======================================================================
bool DFBrowser_ThreadItemUsedShapesMap::isLessThan (const QStringList& theLeft, const QStringList& theRight)
{
int aState = 1; //! where 0 - less, 1 - equal, 2 - larger
int aLeftSize = theLeft.size();
int aRightSize = theRight.size();
for (int anItemId = 0; anItemId < aRightSize && anItemId < aLeftSize && aState == 1; anItemId++)
{
int aRightId = theRight[anItemId].toInt();
int aLeftId = theLeft[anItemId].toInt();
if (aLeftId == aRightId)
continue;
else if (aLeftId < aRightId)
aState = 0; // less
else if (aLeftId > aRightId)
aState = 2; // less
}
if (aState == 1)
{ // equal in similar parts
if (aLeftSize < aRightSize)
aState = 0;
else if (aLeftSize > aRightSize)
aState = 2;
}
return aState == 0;
}
// =======================================================================
// function : addValue
// purpose :
// =======================================================================
void DFBrowser_ThreadItemUsedShapesMap::addValue (const TCollection_AsciiString& theEntry,
QList<QPair<TCollection_AsciiString, QStringList > >& theEntries)
{
QStringList aSplit = QString (theEntry.ToCString()).split (":");
int aLessIndex = -1;
bool isInserted = false;
// looking for nearest smaller value from the end of the list
for (int anEntryId = theEntries.size() - 1; anEntryId >= 0 && !isInserted; anEntryId--)
{
if (isLessThan(aSplit, theEntries[anEntryId].second))
aLessIndex = anEntryId;
else
{
// if less than was found and now, the entry is greater than current entry
if (aLessIndex != -1)
{
theEntries.insert (aLessIndex, qMakePair (theEntry, aSplit));
isInserted = true;
}
break;
}
}
if (!isInserted)
{
if (aLessIndex != -1) // less than all, insert at this position
theEntries.insert (aLessIndex, qMakePair (theEntry, aSplit));
else
theEntries.append (qMakePair (theEntry, aSplit));
}
}
// =======================================================================
// function : findReferences
// purpose :
// =======================================================================
void DFBrowser_ThreadItemUsedShapesMap::findReferences (Handle(TDF_Attribute) theAttribute,
std::list<TCollection_AsciiString>& theReferences)
{
Handle(TNaming_UsedShapes) anAttribute = Handle(TNaming_UsedShapes)::DownCast (theAttribute);
QList<QPair<TCollection_AsciiString, QStringList> > anEntries;
for (TNaming_DataMapIteratorOfDataMapOfShapePtrRefShape aDataIt(anAttribute->Map()); aDataIt.More(); aDataIt.Next())
addValue(DFBrowserPane_Tools::GetEntry (aDataIt.Value()->Label()), anEntries);
for (QList<QPair<TCollection_AsciiString, QStringList> >::const_iterator anEntryIt = anEntries.begin();
anEntryIt != anEntries.end(); anEntryIt++)
theReferences.push_back (anEntryIt->first);
}

View File

@ -1,81 +0,0 @@
// Created on: 2017-06-16
// Created by: Natalia ERMOLAEVA
// Copyright (c) 2017 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef DFBROWSER_ThreadItemUsedShapesMap_H
#define DFBROWSER_ThreadItemUsedShapesMap_H
#include <inspector/DFBrowser_ThreadItem.hxx>
#include <NCollection_DataMap.hxx>
#include <Standard.hxx>
#include <TCollection_AsciiString.hxx>
#include <TDF_Attribute.hxx>
#include <Standard_WarningsDisable.hxx>
#include <QStringList>
#include <QPair>
#include <Standard_WarningsRestore.hxx>
class DFBrowser_Module;
//! \class DFBrowser_ThreadItemUsedShapesMap
//! Collects and sorts map values of TNaming_UsedShape attributes. Applies values to the OCAF tree view model
class DFBrowser_ThreadItemUsedShapesMap : public DFBrowser_ThreadItem
{
public:
//! Constructor
DFBrowser_ThreadItemUsedShapesMap() : myModule (0) {}
//! Destructor
virtual ~DFBrowser_ThreadItemUsedShapesMap() {}
//! Sets the current module
void SetModule (DFBrowser_Module* theModule) { myModule = theModule; }
//! Iterates by application documents and for TNaming_UsedShape attribute collects container of sorted values.
Standard_EXPORT virtual void Run() Standard_OVERRIDE;
//! Initialize tree view model of OCAF by internal container of sorted values.
Standard_EXPORT virtual void ApplyValues() Standard_OVERRIDE;
//! Set empty cache into tree view model of OCAF. Calls Init of these item by usual values (not sorted)
Standard_EXPORT static void ClearSortedReferences (DFBrowser_Module* theModule);
private:
//! Collects sorted values of the attribute if the attribute has TNaming_UsedShape type
//! \param theAttribute a processed attribute
//! \param theReferences a output container of sorted references
void findReferences (Handle(TDF_Attribute) theAttribute, std::list<TCollection_AsciiString>& theReferences);
//! Checks whether the left path is less than the right path
//! \param theLeft path to label
//! \param theRight path to label
//! \returns true if the left path is less(not equal) than right path
static bool isLessThan (const QStringList& theLeft, const QStringList& theRight);
//! Insert entry into container of entries using sorting. It is split by ":" separator to perform soring
//! \param theEntry a label entry
//! \param theEntries a result container
void addValue (const TCollection_AsciiString& theEntry, QList<QPair<TCollection_AsciiString, QStringList > >& theEntries);
private:
DFBrowser_Module* myModule; //!< the current module
NCollection_DataMap<Handle(TDF_Attribute), std::list<TCollection_AsciiString> > myAttributeRefs; //!< sorted references
};
#endif

View File

@ -22,6 +22,9 @@
#include <inspector/DFBrowserPane_Tools.hxx>
#include <inspector/TreeModel_ModelBase.hxx>
#include <inspector/TreeModel_Tools.hxx>
#include <Standard_WarningsDisable.hxx>
#include <QAbstractItemModel>
#include <QFrame>
@ -65,7 +68,7 @@ DFBrowser_TreeLevelLine::DFBrowser_TreeLevelLine (QWidget* theParent)
myTableView->horizontalHeader()->setVisible (false);
QHeaderView* aVHeader = myTableView->verticalHeader();
aVHeader->setVisible (false);
int aDefCellSize = aVHeader->minimumSectionSize() + DFBrowserPane_Tools::HeaderSectionMargin();
int aDefCellSize = aVHeader->minimumSectionSize() + TreeModel_Tools::HeaderSectionMargin();
aVHeader->setDefaultSectionSize (aDefCellSize);
aLayout->addWidget (myTableView, 0, 2);
@ -120,7 +123,7 @@ void DFBrowser_TreeLevelLine::OnTreeViewSelectionChanged (const QItemSelection&
const QItemSelection&)
{
QModelIndexList aSelectedIndices = theSelected.indexes();
QModelIndex aSelectedIndex = DFBrowser_Window::SingleSelected (aSelectedIndices, 0);
QModelIndex aSelectedIndex = TreeModel_ModelBase::SingleSelected (aSelectedIndices, 0);
if (!mySelectionProcessingBlocked) // we're processing action click
setForwardIndex (aSelectedIndex);
@ -152,7 +155,7 @@ void DFBrowser_TreeLevelLine::onTableSelectionChanged (const QItemSelection& the
if (!aTableModel)
return;
QModelIndex aSelectedIndex = DFBrowser_Window::SingleSelected (theSelected.indexes(), 0, Qt::Vertical);
QModelIndex aSelectedIndex = TreeModel_ModelBase::SingleSelected (theSelected.indexes(), 0, Qt::Vertical);
emit indexSelected (aTableModel->GetTreeViewIndex (aSelectedIndex));
}

View File

@ -21,6 +21,7 @@
#include <inspector/DFBrowserPane_Tools.hxx>
#include <inspector/TreeModel_ModelBase.hxx>
#include <inspector/ViewControl_Tools.hxx>
#include <Standard_WarningsDisable.hxx>
#include <QItemSelectionModel>
#include <QGridLayout>
@ -62,7 +63,7 @@ DFBrowser_TreeLevelView::DFBrowser_TreeLevelView (QWidget* theParent)
connect (myTableView, SIGNAL (doubleClicked (const QModelIndex&)),
this, SLOT (onTableDoubleClicked (const QModelIndex&)));
DFBrowser_Window::SetWhiteBackground (myTableView);
ViewControl_Tools::SetWhiteBackground (myTableView);
myTableView->setGridStyle (Qt::NoPen);
}
@ -129,7 +130,7 @@ void DFBrowser_TreeLevelView::onTableSelectionChanged (const QItemSelection& the
const QItemSelection&)
{
QModelIndexList aSelectedIndices = theSelected.indexes();
QModelIndex aSelectedIndex = DFBrowser_Window::SingleSelected (aSelectedIndices, 0);
QModelIndex aSelectedIndex = TreeModel_ModelBase::SingleSelected (aSelectedIndices, 0);
DFBrowser_TreeLevelViewModel* aTableModel = dynamic_cast<DFBrowser_TreeLevelViewModel*> (myTableView->model());
if (aTableModel && aTableModel->IsInitialized())

View File

@ -32,6 +32,8 @@
#include <QAbstractItemModel>
#include <Standard_WarningsRestore.hxx>
const int COLUMN_NAME_WIDTH = 300;
// =======================================================================
// function : Constructor
// purpose :
@ -39,11 +41,21 @@
DFBrowser_TreeModel::DFBrowser_TreeModel (QObject* theParent, DFBrowser_Module* theModule)
: TreeModel_ModelBase (theParent)
{
m_pRootItem = DFBrowser_ItemApplication::CreateItem (TreeModel_ItemBasePtr());
SetHeaderItem (0, TreeModel_HeaderSection ("Name", COLUMN_NAME_WIDTH));
DFBrowser_ItemApplicationPtr aRootItem = itemDynamicCast<DFBrowser_ItemApplication> (m_pRootItem);
aRootItem->SetModule (theModule);
}
// =======================================================================
// function : createRootItem
// purpose :
// =======================================================================
void DFBrowser_TreeModel::createRootItem (const int)
{
m_pRootItem = DFBrowser_ItemApplication::CreateItem (TreeModel_ItemBasePtr());
}
// =======================================================================
// function : Init
// purpose :

View File

@ -95,11 +95,10 @@ public:
Standard_EXPORT virtual QVariant data (const QModelIndex& theIndex,
int theRole = Qt::DisplayRole) const Standard_OVERRIDE;
//! Returns count of columns in the model
//! \param theParent an index of the parent item
//! \return integer value
virtual int columnCount (const QModelIndex& theParent = QModelIndex()) const Standard_OVERRIDE
{ (void)theParent; return 1; }
protected:
//! Creates root item
//! \param theColumnId index of a column
virtual void createRootItem (const int theColumnId);
private:

View File

@ -33,20 +33,24 @@
#include <inspector/DFBrowser_PropertyPanel.hxx>
#include <inspector/DFBrowser_SearchLine.hxx>
#include <inspector/DFBrowser_SearchView.hxx>
#include <inspector/DFBrowser_Shortcut.hxx>
#include <inspector/DFBrowser_Thread.hxx>
#include <inspector/DFBrowser_ThreadItemSearch.hxx>
#include <inspector/DFBrowser_ThreadItemUsedShapesMap.hxx>
#include <inspector/DFBrowser_Tools.hxx>
#include <inspector/DFBrowser_TreeLevelLine.hxx>
#include <inspector/DFBrowser_TreeLevelView.hxx>
#include <inspector/DFBrowser_TreeModel.hxx>
#include <inspector/DFBrowser_TreeView.hxx>
#include <inspector/DFBrowserPane_AttributePaneSelector.hxx>
#include <inspector/DFBrowserPane_SelectionKind.hxx>
#include <inspector/DFBrowserPane_Tools.hxx>
#include <inspector/TreeModel_ContextMenu.hxx>
#include <inspector/TreeModel_Tools.hxx>
#include <inspector/ViewControl_TreeView.hxx>
#include <inspector/View_Tools.hxx>
#include <OSD_Directory.hxx>
#include <OSD_Environment.hxx>
#include <OSD_Protection.hxx>
@ -58,7 +62,8 @@
#include <inspector/View_Window.hxx>
#include <TDF_Tool.hxx>
#include <inspector/TreeModel_MessageDialog.hxx>
#include <inspector/ViewControl_MessageDialog.hxx>
#include <inspector/ViewControl_Tools.hxx>
#include <Standard_WarningsDisable.hxx>
#include <QAction>
@ -94,7 +99,6 @@ const int DFBROWSER_DEFAULT_VIEW_HEIGHT = 300;
const int DFBROWSER_DEFAULT_POSITION_X = 200;
const int DFBROWSER_DEFAULT_POSITION_Y = 60;
const int OCAF_BROWSER_COLUMN_WIDTH_0 = 300;
const int DEFAULT_PROPERTY_PANEL_HEIGHT = 200;
const int DEFAULT_BROWSER_HEIGHT = 800;
@ -108,21 +112,16 @@ DFBrowser_Window::DFBrowser_Window()
myMainWindow = new QMainWindow (0);
// tree view
myTreeView = new DFBrowser_TreeView (myMainWindow);
myTreeView = new ViewControl_TreeView (myMainWindow);
myTreeView->setContextMenuPolicy (Qt::CustomContextMenu);
connect (myTreeView, SIGNAL (customContextMenuRequested (const QPoint&)),
this, SLOT (onTreeViewContextMenuRequested (const QPoint&)));
((DFBrowser_TreeView*)myTreeView)->SetPredefinedSize (DFBROWSER_DEFAULT_TREE_VIEW_WIDTH,
DFBROWSER_DEFAULT_TREE_VIEW_HEIGHT);
new TreeModel_ContextMenu (myTreeView);
((ViewControl_TreeView*)myTreeView)->SetPredefinedSize (QSize (DFBROWSER_DEFAULT_TREE_VIEW_WIDTH,
DFBROWSER_DEFAULT_TREE_VIEW_HEIGHT));
myTreeView->setHeaderHidden (true);
myTreeView->setSortingEnabled (Standard_False);
QDockWidget* aTreeViewWidget = new QDockWidget (tr ("TreeView"), myMainWindow);
aTreeViewWidget->setTitleBarWidget (new QWidget(myMainWindow));
aTreeViewWidget->setFeatures (QDockWidget::NoDockWidgetFeatures);
aTreeViewWidget->setWidget (myTreeView);
myMainWindow->addDockWidget (Qt::LeftDockWidgetArea, aTreeViewWidget);
myMainWindow->setCorner (Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
myMainWindow->setCentralWidget (myTreeView);
#if QT_VERSION < 0x050000
myTreeView->setStyle (new QWindowsStyle);
@ -137,22 +136,11 @@ DFBrowser_Window::DFBrowser_Window()
connect (myTreeLevelLine, SIGNAL (updateClicked()), this, SLOT (onUpdateClicked()));
QDockWidget* aTreeLineDockWidget = new QDockWidget (tr ("Tree Level Line"), myMainWindow);
aTreeLineDockWidget->setObjectName (aTreeLineDockWidget->windowTitle());
aTreeLineDockWidget->setTitleBarWidget (new QWidget(myMainWindow));
aTreeLineDockWidget->setFeatures (QDockWidget::NoDockWidgetFeatures);
aTreeLineDockWidget->setWidget (myTreeLevelLine->GetControl());
myMainWindow->addDockWidget (Qt::TopDockWidgetArea, aTreeLineDockWidget);
// dump view window
QWidget* aDumpWidget = new QWidget (myMainWindow);
QVBoxLayout* aDumpLay = new QVBoxLayout (aDumpWidget);
aDumpLay->setMargin (0);
myDumpView = new DFBrowser_DumpView (aDumpWidget);
aDumpLay->addWidget (myDumpView->GetControl());
QDockWidget* aDumpDockWidget = new QDockWidget (tr ("Dump"), myMainWindow);
aDumpDockWidget->setWidget (aDumpWidget);
myMainWindow->addDockWidget (Qt::BottomDockWidgetArea, aDumpDockWidget);
// property panel
myPropertyPanel = new DFBrowser_PropertyPanel (myMainWindow);
DFBrowser_AttributePaneStack* anAttributePaneStack = myPropertyPanel->GetAttributesStack();
@ -173,27 +161,44 @@ DFBrowser_Window::DFBrowser_Window()
connect (aLevelView, SIGNAL (indexDoubleClicked (const QModelIndex&)),
this, SLOT (onLevelDoubleClicked (const QModelIndex&)));
myMainWindow->setCentralWidget (myPropertyPanel->GetControl());
QDockWidget* aPropertyPanelWidget = new QDockWidget (tr ("PropertyPanel"), myMainWindow);
aPropertyPanelWidget->setObjectName (aPropertyPanelWidget->windowTitle());
aPropertyPanelWidget->setTitleBarWidget (new QWidget(myMainWindow));
aPropertyPanelWidget->setWidget (myPropertyPanel->GetControl());
myMainWindow->addDockWidget (Qt::RightDockWidgetArea, aPropertyPanelWidget);
// dump view window
QWidget* aDumpWidget = new QWidget(myMainWindow);
QVBoxLayout* aDumpLay = new QVBoxLayout(aDumpWidget);
aDumpLay->setMargin(0);
myDumpView = new DFBrowser_DumpView(aDumpWidget);
aDumpLay->addWidget(myDumpView->GetControl());
QDockWidget* aDumpDockWidget = new QDockWidget(tr("Dump"), myMainWindow);
aDumpDockWidget->setObjectName(aDumpDockWidget->windowTitle());
aDumpDockWidget->setWidget(aDumpWidget);
myMainWindow->addDockWidget(Qt::RightDockWidgetArea, aDumpDockWidget);
// view
myViewWindow = new View_Window (myMainWindow);
myViewWindow->GetView()->SetPredefinedSize (DFBROWSER_DEFAULT_VIEW_WIDTH, DFBROWSER_DEFAULT_VIEW_HEIGHT);
QDockWidget* aViewDockWidget = new QDockWidget (tr ("View"), myMainWindow);
aViewDockWidget->setObjectName (aViewDockWidget->windowTitle());
aViewDockWidget->setTitleBarWidget (myViewWindow->GetViewToolBar()->GetControl());
aViewDockWidget->setWidget (myViewWindow);
myMainWindow->addDockWidget (Qt::BottomDockWidgetArea, aViewDockWidget);
myMainWindow->addDockWidget (Qt::RightDockWidgetArea, aViewDockWidget);
QColor aHColor (229, 243, 255);
myViewWindow->GetDisplayer()->SetAttributeColor (Quantity_Color(aHColor.red() / 255., aHColor.green() / 255.,
aHColor.blue() / 255., Quantity_TOC_RGB), View_PresentationType_Additional);
myMainWindow->splitDockWidget(aPropertyPanelWidget, aViewDockWidget, Qt::Vertical);
myMainWindow->tabifyDockWidget (aDumpDockWidget, aViewDockWidget);
aTreeViewWidget->resize (DFBROWSER_DEFAULT_TREE_VIEW_WIDTH, DFBROWSER_DEFAULT_TREE_VIEW_HEIGHT);
myTreeView->resize (DFBROWSER_DEFAULT_TREE_VIEW_WIDTH, DFBROWSER_DEFAULT_TREE_VIEW_HEIGHT);
myThread = new DFBrowser_Thread (this);
myShortcut = new DFBrowser_Shortcut (myMainWindow);
}
// =======================================================================
@ -220,6 +225,62 @@ void DFBrowser_Window::SetParent (void* theParent)
}
}
// =======================================================================
// function : FillActionsMenu
// purpose :
// =======================================================================
void DFBrowser_Window::FillActionsMenu (void* theMenu)
{
QMenu* aMenu = (QMenu*)theMenu;
QList<QDockWidget*> aDockwidgets = myMainWindow->findChildren<QDockWidget*>();
for (QList<QDockWidget*>::iterator it = aDockwidgets.begin(); it != aDockwidgets.end(); ++it)
{
QDockWidget* aDockWidget = *it;
if (aDockWidget->parentWidget() == myMainWindow)
aMenu->addAction (aDockWidget->toggleViewAction());
}
}
// =======================================================================
// function : GetPreferences
// purpose :
// =======================================================================
void DFBrowser_Window::GetPreferences (TInspectorAPI_PreferencesDataMap& theItem)
{
theItem.Clear();
theItem.Bind ("geometry", TreeModel_Tools::ToString (myMainWindow->saveState()).toStdString().c_str());
QMap<QString, QString> anItems;
TreeModel_Tools::SaveState (myTreeView, anItems);
View_Tools::SaveState(myViewWindow, anItems);
for (QMap<QString, QString>::const_iterator anItemsIt = anItems.begin(); anItemsIt != anItems.end(); anItemsIt++)
theItem.Bind (anItemsIt.key().toStdString().c_str(), anItemsIt.value().toStdString().c_str());
}
// =======================================================================
// function : SetPreferences
// purpose :
// =======================================================================
void DFBrowser_Window::SetPreferences (const TInspectorAPI_PreferencesDataMap& theItem)
{
if (theItem.IsEmpty())
{
TreeModel_Tools::SetDefaultHeaderSections (myTreeView);
return;
}
for (TInspectorAPI_IteratorOfPreferencesDataMap anItemIt (theItem); anItemIt.More(); anItemIt.Next())
{
if (anItemIt.Key().IsEqual ("geometry"))
myMainWindow->restoreState (TreeModel_Tools::ToByteArray (anItemIt.Value().ToCString()));
else if (TreeModel_Tools::RestoreState (myTreeView, anItemIt.Key().ToCString(), anItemIt.Value().ToCString()))
continue;
else if (View_Tools::RestoreState(myViewWindow, anItemIt.Key().ToCString(), anItemIt.Value().ToCString()))
continue;
}
}
// =======================================================================
// function : UpdateContent
// purpose :
@ -370,9 +431,6 @@ void DFBrowser_Window::Init (const NCollection_List<Handle(Standard_Transient)>&
myTreeLevelLine->GetSearchLine()->SetModule (myModule);
myPropertyPanel->GetAttributesStack()->GetSearchView()->InitModels();
myShortcut->SetModule (myModule);
myThread->SetModule (myModule);
connect (myModule, SIGNAL (beforeUpdateTreeModel()), this, SLOT (onBeforeUpdateTreeModel()));
if (!aContext.IsNull())
@ -506,7 +564,6 @@ void DFBrowser_Window::setExpandedLevels (QTreeView* theTreeView, const QModelIn
void DFBrowser_Window::setOCAFModel (QAbstractItemModel* theModel)
{
myTreeView->setModel (theModel);
myTreeView->setColumnWidth (0, OCAF_BROWSER_COLUMN_WIDTH_0);
QItemSelectionModel* aSelectionModel = new QItemSelectionModel (theModel);
myTreeView->setSelectionModel (aSelectionModel);
@ -536,21 +593,9 @@ void DFBrowser_Window::onBeforeUpdateTreeModel()
// =======================================================================
void DFBrowser_Window::ClearThreadCache()
{
DFBrowser_ThreadItemUsedShapesMap::ClearSortedReferences (myModule);
DFBrowser_ThreadItemSearch::ClearValues (GetTreeLevelLine()->GetSearchLine());
}
// =======================================================================
// function : SetWhiteBackground
// purpose :
// =======================================================================
void DFBrowser_Window::SetWhiteBackground (QWidget* theControl)
{
QPalette aPalette = theControl->palette();
aPalette.setColor (QPalette::All, QPalette::Foreground, Qt::white);
theControl->setPalette (aPalette);
}
// =======================================================================
// function : TmpDirectory
// purpose :
@ -582,25 +627,6 @@ TCollection_AsciiString DFBrowser_Window::TmpDirectory()
return aTmpDir;
}
// =======================================================================
// function : SingleSelected
// purpose :
// =======================================================================
QModelIndex DFBrowser_Window::SingleSelected (const QModelIndexList& theIndices, const int theCellId,
const Qt::Orientation theOrientation)
{
QModelIndexList aFirstColumnSelectedIndices;
for (QModelIndexList::const_iterator anIndicesIt = theIndices.begin(), aLast = theIndices.end();
anIndicesIt != aLast; anIndicesIt++)
{
QModelIndex anIndex = *anIndicesIt;
if ((theOrientation == Qt::Horizontal && anIndex.column() == theCellId) ||
(theOrientation == Qt::Vertical && anIndex.row() == theCellId))
aFirstColumnSelectedIndices.append (anIndex);
}
return aFirstColumnSelectedIndices.size() == 1 ? aFirstColumnSelectedIndices.first() : QModelIndex();
}
// =======================================================================
// function : onTreeViewContextMenuRequested
// purpose :
@ -608,25 +634,14 @@ QModelIndex DFBrowser_Window::SingleSelected (const QModelIndexList& theIndices,
void DFBrowser_Window::onTreeViewContextMenuRequested (const QPoint& thePosition)
{
QMenu* aMenu = new QMenu(GetMainWindow());
aMenu->addAction (createAction (tr ("Expand"), SLOT (onExpand())));
aMenu->addAction (createAction (tr ("Expand All"), SLOT (onExpandAll())));
aMenu->addAction (createAction (tr ("Collapse All"), SLOT (onCollapseAll())));
aMenu->addAction (ViewControl_Tools::CreateAction (tr ("Expand"), SLOT (onExpand()), GetMainWindow(), this));
aMenu->addAction (ViewControl_Tools::CreateAction (tr ("Expand All"), SLOT (onExpandAll()), GetMainWindow(), this));
aMenu->addAction (ViewControl_Tools::CreateAction (tr ("Collapse All"), SLOT (onCollapseAll()), GetMainWindow(), this));
QPoint aPoint = myTreeView->mapToGlobal (thePosition);
aMenu->exec (aPoint);
}
// =======================================================================
// function : createAction
// purpose :
// =======================================================================
QAction* DFBrowser_Window::createAction (const QString& theText, const char* theSlot)
{
QAction* anAction = new QAction (theText, GetMainWindow());
connect (anAction, SIGNAL (triggered(bool)), this, theSlot);
return anAction;
}
// =======================================================================
// function : onExpand
// purpose :
@ -694,7 +709,7 @@ void DFBrowser_Window::onTreeViewSelectionChanged (const QItemSelection& theSele
anAttributePaneStack->GetTreeLevelView()->UpdateByTreeSelectionChanged (theSelected, theDeselected);
QModelIndexList aSelectedIndices = theSelected.indexes();
QModelIndex aSelectedIndex = DFBrowser_Window::SingleSelected (aSelectedIndices, 0);
QModelIndex aSelectedIndex = TreeModel_ModelBase::SingleSelected (aSelectedIndices, 0);
myTreeView->scrollTo (aSelectedIndex);
View_Displayer* aDisplayer = myViewWindow->GetDisplayer();
@ -736,8 +751,12 @@ void DFBrowser_Window::onPaneSelectionChanged (const QItemSelection&,
if (myParameters->FindParameters (aPluginName))
aParameters = myParameters->Parameters (aPluginName);
NCollection_List<TCollection_AsciiString> anItemNames;
if (myParameters->FindSelectedNames (aPluginName))
anItemNames = myParameters->GetSelectedNames (aPluginName);
int aParametersCount = aParameters.Extent();
anAttributePane->GetSelectionParameters (aSelectionModel, aParameters);
anAttributePane->GetSelectionParameters (aSelectionModel, aParameters, anItemNames);
if (aParametersCount != aParameters.Extent()) // some TShapes are added
{
TCollection_AsciiString aPluginShortName = aPluginName.SubString (3, aPluginName.Length());
@ -747,11 +766,12 @@ void DFBrowser_Window::onPaneSelectionChanged (const QItemSelection&,
QString aQuestion = QString ("Would you like to activate %1 immediately?\n")
.arg (aPluginShortName.ToCString()).toStdString().c_str();
if (!myExportToShapeViewDialog)
myExportToShapeViewDialog = new TreeModel_MessageDialog (myParent, aMessage, aQuestion);
myExportToShapeViewDialog = new ViewControl_MessageDialog (myParent, aMessage, aQuestion);
else
myExportToShapeViewDialog->SetInformation (aMessage);
myExportToShapeViewDialog->Start();
myParameters->SetSelectedNames (aPluginName, anItemNames);
myParameters->SetParameters (aPluginName, aParameters, myExportToShapeViewDialog->IsAccepted());
}
return;

View File

@ -35,11 +35,10 @@
class DFBrowser_DumpView;
class DFBrowser_Module;
class DFBrowser_PropertyPanel;
class DFBrowser_Shortcut;
class DFBrowser_Thread;
class DFBrowser_TreeLevelLine;
class TreeModel_MessageDialog;
class ViewControl_MessageDialog;
class View_ToolBar;
class View_Window;
@ -73,6 +72,18 @@ public:
//! \param theParameters a parameters container
void SetParameters (const Handle(TInspectorAPI_PluginParameters)& theParameters) { myParameters = theParameters; }
//! Provide container for actions available in inspector on general level
//! \param theMenu if Qt implementation, it is QMenu object
Standard_EXPORT virtual void FillActionsMenu (void* theMenu);
//! Returns plugin preferences: dock widgets state, tree view columns.
//! \param theItem container of preference elements
Standard_EXPORT void GetPreferences (TInspectorAPI_PreferencesDataMap& theItem);
//! Applies plugin preferences
//! \param theItem container of preference elements
Standard_EXPORT void SetPreferences (const TInspectorAPI_PreferencesDataMap& theItem);
//! Applyes parameters to Init controls, opens files if there are in parameters, updates OCAF tree view model
Standard_EXPORT void UpdateContent();
@ -101,22 +112,10 @@ public:
//! Returns tree level line control
DFBrowser_TreeLevelLine* GetTreeLevelLine() const { return myTreeLevelLine; }
//! Change palette of the widget to have white foreground
//! \param theControl a widget to be modified
Standard_EXPORT static void SetWhiteBackground (QWidget* theControl);
//! Returns temporary directory defined by environment variables TEMP or TMP
//! \return string value
Standard_EXPORT static TCollection_AsciiString TmpDirectory();
//! Returns single selected item in the cell of given orientation. If the orientation is Horizontal,
//! in the cell id colum, one row should be selected.
//! \param theIndices a container of selected indices
//! \param theCellId column index if orientation is horizontal, row index otherwise
//! \param theOrientation an orientation to apply the cell index
//! \return model index from the list
Standard_EXPORT static QModelIndex SingleSelected (const QModelIndexList& theIndices, const int theCellId,
const Qt::Orientation theOrientation = Qt::Horizontal);
private slots:
//! Cleans history in tree level line, clears cache of thread processing, starts threads for application
@ -191,12 +190,6 @@ private:
//! \param theIndices a container of OCAF tree view model indices
void highlightIndices (const QModelIndexList& theIndices);
//! Creates an action with the given text connected to the slot
//! \param theText an action text value
//! \param theSlot a listener of triggered signal of the new action
//! \return a new action
QAction* createAction (const QString& theText, const char* theSlot);
//! Returns candidate to be the window title. It is either name of opened STEP file or the application path
//! \return string value
QString getWindowTitle() const;
@ -231,8 +224,7 @@ private:
View_Window* myViewWindow; //!< V3d view to visualize presentations/references if it can be build for a selected item
DFBrowser_DumpView* myDumpView; //!< Text editor where "Dump" method output is shown
DFBrowser_Thread* myThread; //!< Threads manipulator, starting thread items, listens finalizing
DFBrowser_Shortcut* myShortcut; //!< Short cut processor, F5 - updates OCAF view model content
TreeModel_MessageDialog* myExportToShapeViewDialog; //!< dialog about exporting TopoDS_Shape to ShapeView plugin
ViewControl_MessageDialog* myExportToShapeViewDialog; //!< dialog about exporting TopoDS_Shape to ShapeView plugin
Handle(TInspectorAPI_PluginParameters) myParameters; //!< contains application, context, files that should be opened
};

View File

@ -30,15 +30,11 @@ DFBrowser_SearchLineModel.cxx
DFBrowser_SearchLineModel.hxx
DFBrowser_SearchView.cxx
DFBrowser_SearchView.hxx
DFBrowser_Shortcut.cxx
DFBrowser_Shortcut.hxx
DFBrowser_Thread.cxx
DFBrowser_Thread.hxx
DFBrowser_ThreadItem.hxx
DFBrowser_ThreadItemSearch.cxx
DFBrowser_ThreadItemSearch.hxx
DFBrowser_ThreadItemUsedShapesMap.cxx
DFBrowser_ThreadItemUsedShapesMap.hxx
DFBrowser_Tools.cxx
DFBrowser_Tools.hxx
DFBrowser_TreeLevelLine.cxx
@ -53,7 +49,5 @@ DFBrowser_TreeLevelViewModel.cxx
DFBrowser_TreeLevelViewModel.hxx
DFBrowser_TreeModel.cxx
DFBrowser_TreeModel.hxx
DFBrowser_TreeView.cxx
DFBrowser_TreeView.hxx
DFBrowser_Window.cxx
DFBrowser_Window.hxx

View File

@ -66,9 +66,11 @@ public:
//! Returns selection parameters, that may be useful for communicate between tools
//! \param theModel one of selection models provided by this pane
//! \theParameters a container of parameters, might be extended depending on the pane state(e.g. selection)
//! \theItemNames names to be selected for each selection parameter
virtual void GetSelectionParameters (QItemSelectionModel* theModel,
NCollection_List<Handle(Standard_Transient)>& theParameters)
{ (void)theModel; (void)theParameters; }
NCollection_List<Handle(Standard_Transient)>& theParameters,
NCollection_List<TCollection_AsciiString>& theItemNames)
{ (void)theModel; (void)theParameters; (void)theItemNames; }
//! Returns presentation of the attribute to be visualized in the view
//! \param theAttribute a current attribute

View File

@ -29,7 +29,16 @@
DFBrowserPane_TDataStdTreeNodeModel::DFBrowserPane_TDataStdTreeNodeModel (QObject* theParent)
: TreeModel_ModelBase (theParent)
{
m_pRootItem = DFBrowserPane_TDataStdTreeNodeItem::CreateItem (TreeModel_ItemBasePtr(), 0, 0);
createRootItem(0);
}
// =======================================================================
// function : createRootItem
// purpose :
// =======================================================================
void DFBrowserPane_TDataStdTreeNodeModel::createRootItem (const int theColumnId)
{
m_pRootItem = DFBrowserPane_TDataStdTreeNodeItem::CreateItem (TreeModel_ItemBasePtr(), 0, theColumnId);
}
// =======================================================================

View File

@ -56,6 +56,11 @@ public:
virtual int columnCount (const QModelIndex& theParent = QModelIndex()) const Standard_OVERRIDE
{ (void)theParent; return 1; }
protected:
//! Creates root item
//! \param theColumnId index of a column
virtual void createRootItem (const int theColumnId) Standard_OVERRIDE;
private:
Handle(TDF_Attribute) myAttribute; //! the parent attribute

View File

@ -106,7 +106,7 @@ void DFBrowserPane_TDocStdOwner::GetValues (const Handle(TDF_Attribute)& theAttr
<< aSeparationStr.ToCString() << aSeparationStr.ToCString()
<< "IsSaved" << DFBrowserPane_Tools::BoolToStr (aDocument->IsSaved())
<< "IsChanged" << DFBrowserPane_Tools::BoolToStr (aDocument->IsChanged())
<< "GetSavedTime" << aDocument->GetSavedTime()
<< "GetSavedTime" << QString::number (aDocument->GetSavedTime())
<< "GetName" << (aDocument->IsSaved() ? DFBrowserPane_Tools::ToString (aDocument->GetName()) : "")
<< "GetPath" << (aDocument->IsSaved() ? DFBrowserPane_Tools::ToString (aDocument->GetPath()) : "")
<< "GetData" << aDocumentDataInfo.ToCString()

View File

@ -22,6 +22,7 @@
#include <inspector/DFBrowserPane_SelectionKind.hxx>
#include <inspector/DFBrowserPane_TableView.hxx>
#include <inspector/DFBrowserPane_Tools.hxx>
#include <inspector/TInspectorAPI_PluginParameters.hxx>
#include <AIS_InteractiveObject.hxx>
#include <AIS_Shape.hxx>
@ -367,7 +368,8 @@ int DFBrowserPane_TNamingNamedShape::GetSelectionKind (QItemSelectionModel* theM
// purpose :
// =======================================================================
void DFBrowserPane_TNamingNamedShape::GetSelectionParameters (QItemSelectionModel* theModel,
NCollection_List<Handle(Standard_Transient)>& theParameters)
NCollection_List<Handle(Standard_Transient)>& theParameters,
NCollection_List<TCollection_AsciiString>& theItemNames)
{
QTableView* aTableView = myTableView->GetTableView();
if (aTableView->selectionModel() != theModel)
@ -385,6 +387,7 @@ void DFBrowserPane_TNamingNamedShape::GetSelectionParameters (QItemSelectionMode
if (aShape.IsNull())
return;
theParameters.Append (aShape.TShape());
theItemNames.Append (TInspectorAPI_PluginParameters::ParametersToString (aShape));
}
// =======================================================================

View File

@ -75,8 +75,10 @@ public:
//! Returns selection parameters, that may be useful for communicate between tools
//! \param theModel one of selection models provided by this pane
//! \theParameters a container of parameters, might be extended depending on the pane state(e.g. selection)
//! \theItemNames names to be selected for each selection parameter
Standard_EXPORT virtual void GetSelectionParameters (QItemSelectionModel* theModel,
NCollection_List<Handle(Standard_Transient)>& theParameters) Standard_OVERRIDE;
NCollection_List<Handle(Standard_Transient)>& theParameters,
NCollection_List<TCollection_AsciiString>& theItemNames) Standard_OVERRIDE;
//! Returns container of Label references to the attribute
//! \param theAttribute a current attribute

View File

@ -16,6 +16,8 @@
#include <inspector/DFBrowserPane_TableView.hxx>
#include <inspector/DFBrowserPane_Tools.hxx>
#include <inspector/TreeModel_Tools.hxx>
#include <Standard_WarningsDisable.hxx>
#include <QAbstractTableModel>
#include <QHeaderView>
@ -70,7 +72,7 @@ void DFBrowserPane_TableView::SetModel (QAbstractTableModel* theModel)
// =======================================================================
void DFBrowserPane_TableView::SetFixedRowCount (const int theCount, QTableView* theView, const bool theScroll)
{
int aHeight = theView->verticalHeader()->defaultSectionSize() * theCount + DFBrowserPane_Tools::HeaderSectionMargin();
int aHeight = theView->verticalHeader()->defaultSectionSize()*theCount + TreeModel_Tools::HeaderSectionMargin();
if (theScroll)
aHeight += theView->horizontalScrollBar()->sizeHint().height();

View File

@ -25,9 +25,7 @@
#include <TopoDS_Shape.hxx>
#include <Standard_WarningsDisable.hxx>
#include <QApplication>
#include <QString>
#include <QStyle>
#include <QString>
#include <QVariant>
#include <Standard_WarningsRestore.hxx>
@ -45,10 +43,6 @@ public:
//! \returns value
Standard_EXPORT static int DefaultPanelColumnWidth (const int theColumnId);
//! Returns header margin, defined in style settings of application
//! \return integer value
Standard_EXPORT static int HeaderSectionMargin() { return qApp->style()->pixelMetric (QStyle::PM_HeaderMargin); }
//! Returns a string presentation of the label
//! \param theLabel a label object
//! \return the string value
@ -69,7 +63,7 @@ public:
//! Returns "true" or "false" text for the given boolean state
//! \param theValue a boolean value
//! \return string value
Standard_EXPORT static QString BoolToStr (const Standard_Boolean theValue) { return theValue ? "true" : "false"; }
Standard_EXPORT static QString BoolToStr (const bool theValue) { return theValue ? "true" : "false"; }
//! Converts a Qt string to OCCT extended string
//! \param theValue a converted string

View File

@ -164,12 +164,13 @@ int DFBrowserPaneXDE_AttributeCommonPane::GetSelectionKind (QItemSelectionModel*
// purpose :
// =======================================================================
void DFBrowserPaneXDE_AttributeCommonPane::GetSelectionParameters (QItemSelectionModel* theModel,
NCollection_List<Handle(Standard_Transient)>& theParameters)
NCollection_List<Handle(Standard_Transient)>& theParameters,
NCollection_List<TCollection_AsciiString>& theItemNames)
{
if (myStandardPane)
myStandardPane->GetSelectionParameters (theModel, theParameters);
myStandardPane->GetSelectionParameters (theModel, theParameters, theItemNames);
DFBrowserPane_AttributePane::GetSelectionParameters (theModel, theParameters);
DFBrowserPane_AttributePane::GetSelectionParameters (theModel, theParameters, theItemNames);
}
// =======================================================================

View File

@ -83,8 +83,10 @@ public:
//! Returns selection parameters, that may be useful for communicate between tools
//! \param theModel one of selection models provided by this pane
//! \theParameters a container of parameters, might be extended depending on the pane state(e.g. selection)
//! \theItemNames names to be selected for each selection parameter
Standard_EXPORT virtual void GetSelectionParameters (QItemSelectionModel* theModel,
NCollection_List<Handle(Standard_Transient)>& theParameters) Standard_OVERRIDE;
NCollection_List<Handle(Standard_Transient)>& theParameters,
NCollection_List<TCollection_AsciiString>& theItemNames) Standard_OVERRIDE;
//! Returns presentation of the attribute to be visualized in the view
//! \param theAttribute a current attribute

View File

@ -14,5 +14,7 @@ ShapeView_Tools.cxx
ShapeView_Tools.hxx
ShapeView_TreeModel.cxx
ShapeView_TreeModel.hxx
ShapeView_VisibilityState.cxx
ShapeView_VisibilityState.hxx
ShapeView_Window.cxx
ShapeView_Window.hxx

View File

@ -15,18 +15,6 @@
#include <inspector/ShapeView_Communicator.hxx>
#include <inspector/ShapeView_Window.hxx>
#include <OSD_Directory.hxx>
#include <OSD_Environment.hxx>
#include <OSD_Path.hxx>
#include <OSD_Protection.hxx>
#include <Standard_WarningsDisable.hxx>
#include <QApplication>
#include <QMainWindow>
#include <QDir>
#include <Standard_WarningsRestore.hxx>
// =======================================================================
// function : CreateCommunicator
// purpose : Creates a communicator by the library loading
@ -35,52 +23,3 @@ Standard_EXPORTEXTERNC TInspectorAPI_Communicator* CreateCommunicator()
{
return new ShapeView_Communicator();
}
// =======================================================================
// function : Constructor
// purpose :
// =======================================================================
ShapeView_Communicator::ShapeView_Communicator()
: TInspectorAPI_Communicator(), myWindow (0)
{
// main window creation
TCollection_AsciiString aTmpDir;
#ifdef _WIN32
OSD_Environment anEnvironment ("TEMP");
aTmpDir = anEnvironment.Value();
if (aTmpDir.IsEmpty() )
{
anEnvironment.SetName("TMP");
aTmpDir = anEnvironment.Value();
if (aTmpDir.IsEmpty())
aTmpDir = "C:\\";
}
if (!aTmpDir.EndsWith ("\\"))
aTmpDir += "\\";
OSD_Path aTmpPath (aTmpDir);
OSD_Directory aTmpDirectory;
#else
OSD_Directory aTmpDirectory = OSD_Directory::BuildTemporary();
OSD_Path aTmpPath;
aTmpDirectory.Path (aTmpPath);
#endif
aTmpPath.DownTrek ("ShapeView");
aTmpDirectory.SetPath (aTmpPath);
if (!aTmpDirectory.Exists())
aTmpDirectory.Build (OSD_Protection());
aTmpDirectory.Path (aTmpPath);
TCollection_AsciiString aTmpDirectoryName;
aTmpPath.SystemName(aTmpDirectoryName);
myWindow = new ShapeView_Window (0, aTmpDirectoryName);
}
ShapeView_Communicator::~ShapeView_Communicator()
{
myWindow->RemoveAllShapes(); // removes all cached shapes and files in temporary directory
OSD_Path aPath (myWindow->GetTemporaryDirectory());
OSD_Directory aTmpDirectory (aPath);
// temporary directory can be removed only if is empty
aTmpDirectory.Remove();
}

View File

@ -26,10 +26,10 @@ class ShapeView_Communicator : public TInspectorAPI_Communicator
public:
//! Constructor
Standard_EXPORT ShapeView_Communicator();
ShapeView_Communicator() : TInspectorAPI_Communicator(), myWindow (new ShapeView_Window (0)) {}
//! Destructor
Standard_EXPORT virtual ~ShapeView_Communicator() Standard_OVERRIDE;
virtual ~ShapeView_Communicator() Standard_OVERRIDE { myWindow->RemoveAllShapes(); }
//! Provides the container with a parent where this container should be inserted.
//! If Qt implementation, it should be QWidget with QLayout set inside
@ -41,6 +41,20 @@ public:
virtual void SetParameters (const Handle(TInspectorAPI_PluginParameters)& theParameters) Standard_OVERRIDE
{ myWindow->SetParameters (theParameters); }
//! Provide container for actions available in inspector on general level
//! \param theMenu if Qt implementation, it is QMenu object
Standard_EXPORT virtual void FillActionsMenu(void* theMenu) Standard_OVERRIDE { myWindow->FillActionsMenu (theMenu); }
//! Returns plugin preferences, empty implementation by default
//! \param theItem container of preference elements
virtual void GetPreferences (TInspectorAPI_PreferencesDataMap& theItem) Standard_OVERRIDE
{ myWindow->GetPreferences (theItem); }
//! Stores plugin preferences, empty implementation by default
//! \param theItem container of preference elements
virtual void SetPreferences (const TInspectorAPI_PreferencesDataMap& theItem) Standard_OVERRIDE
{ myWindow->SetPreferences (theItem); }
//! Calls update of the plugin's content
virtual void UpdateContent() Standard_OVERRIDE { myWindow->UpdateContent(); }

View File

@ -96,21 +96,6 @@ QString ToName (const GeomAbs_Shape& theType)
return QString();
}
// =======================================================================
// function : ToFlags
// purpose :
// =======================================================================
void ToFlags (const TopoDS_Shape& theShape, QVariant& theValue, QVariant& theInfo)
{
QStringList aValues;
aValues << ToString (theShape.Checked()) << ToString (theShape.Closed())
<< ToString (theShape.Infinite()) << ToString (theShape.Locked())
<< ToString (theShape.Modified()) << ToString (theShape.Orientable());
theValue = aValues.join ("/");
theInfo = "Checked/Closed/Infinite/Locked/Modified/Orientable";
}
// =======================================================================
// function : ToOtherInfo
// purpose :
@ -171,14 +156,6 @@ void ToOtherInfo (const TopoDS_Shape& theShape, QVariant& theValue, QVariant& th
theInfo = QString ("%1:\n%2").arg (anInfo.join (" / ")).arg (aValues.join ("\n"));
break;
}
case TopAbs_VERTEX:
{
TopoDS_Vertex aVertex = TopoDS::Vertex (theShape);
gp_Pnt aPoint = BRep_Tool::Pnt (aVertex);
theValue = ToString (aPoint);
theInfo = "(X, Y, Z) of gp_Pnt";
break;
}
case TopAbs_SHAPE:
default:
break;
@ -235,25 +212,59 @@ QVariant ShapeView_ItemShape::initValue(const int theRole) const
if (theRole != Qt::DisplayRole && theRole != Qt::ToolTipRole)
return QVariant();
bool isDisplayRole = theRole == Qt::DisplayRole;
switch (Column())
{
case 0: return isDisplayRole ? ToName (aShape.ShapeType()) : "ShapeType";
case 1: return isDisplayRole ? (rowCount() > 0 ? QVariant (rowCount()) : QVariant())
: QVariant ("Number of sub shapes");
case 2: return isDisplayRole ? TShapePointer().ToCString() : "TShape pointer";
case 3: return isDisplayRole ? ToName(aShape.Orientation()) : "Orientation";
case 4: return isDisplayRole ? locationInfo(aShape.Location()) : "Location";
case 5:
case 6:
case 7:
case 0: return ToName (aShape.ShapeType());
case 2: return rowCount() > 0 ? QVariant (rowCount()) : QVariant();
case 3: return TShapePointer().ToCString();
case 4: return ToName(aShape.Orientation());
case 5: return locationInfo(aShape.Location());
case 6: return ToString (aShape.Checked());
case 7: return ToString (aShape.Closed());
case 8: return ToString (aShape.Infinite());
case 9: return ToString (aShape.Locked());
case 10: return ToString (aShape.Modified());
case 11: return ToString (aShape.Orientable());
case 12:
{
QVariant aDataInfo, aTooTipInfo;
if (Column() == 5)
ToFlags(aShape, aDataInfo, aTooTipInfo);
else if (Column() == 6)
ToOtherInfo(aShape, aDataInfo, aTooTipInfo);
return isDisplayRole ? aDataInfo : aTooTipInfo;
if (aShape.ShapeType() != TopAbs_VERTEX)
return QVariant();
TopoDS_Vertex aVertex = TopoDS::Vertex (aShape);
gp_Pnt aPoint = BRep_Tool::Pnt (aVertex);
return ToString (aPoint);
}
case 13:
case 14:
case 15:
case 16:
case 17:
case 18:
case 19:
{
if (aShape.ShapeType() != TopAbs_EDGE)
return QVariant();
TopoDS_Edge anEdge = TopoDS::Edge(aShape);
double aFirst, aLast;
Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFirst, aLast);
GeomAdaptor_Curve aAdaptor(aCurve, aFirst, aLast);
gp_Pnt aFirstPnt = aAdaptor.Value(aFirst);
gp_Pnt aLastPnt = aAdaptor.Value(aLast);
BRepAdaptor_Curve aBRepAdaptor = BRepAdaptor_Curve(anEdge);
Adaptor3d_Curve* anAdaptor3d = &aBRepAdaptor;
switch (Column())
{
case 13: return QString::number (GCPnts_AbscissaPoint::Length(*anAdaptor3d));
case 14: return aCurve->DynamicType()->Name();
case 15: return ToString (aFirstPnt);
case 16: return ToString (aLastPnt);
case 17: return ToName (aCurve->Continuity());
case 18: return ToString (aCurve->IsClosed());
case 19: return aCurve->IsPeriodic() ? QString::number (aCurve->Period()) : ToString (aCurve->IsPeriodic());
}
}
default: break;
}

View File

@ -31,12 +31,3 @@ TopoDS_Shape ShapeView_Tools::ReadShape (const TCollection_AsciiString& theFileN
BRepTools::Read (aShape, theFileName.ToCString(), aBuilder);
return aShape;
}
// =======================================================================
// function : CreatePresentation
// purpose :
// =======================================================================
Handle(Standard_Transient) ShapeView_Tools::CreatePresentation (const TopoDS_Shape& theShape)
{
return new AIS_Shape (theShape);
}

View File

@ -32,11 +32,6 @@ public:
//! \param theFileName a file name
//! \return shape or NULL
Standard_EXPORT static TopoDS_Shape ReadShape (const TCollection_AsciiString& theFileName);
//! Creates AIS_Shape for the shape
//! \param theShape a shape
//! \return presentation
Standard_EXPORT static Handle(Standard_Transient) CreatePresentation (const TopoDS_Shape& theShape);
};
#endif

View File

@ -19,6 +19,14 @@
#include <inspector/ShapeView_ItemRoot.hxx>
#include <inspector/ShapeView_ItemShape.hxx>
const int COLUMN_NAME_WIDTH = 190;
const int COLUMN_SIZE_WIDTH = 30;
const int COLUMN_POINTER_WIDTH = 70;
const int COLUMN_SHAPE_TYPE_WIDTH = 75;
const int COLUMN_ORIENTATION_WIDTH = 70;
const int COLUMN_LOCATION_WIDTH = 120;
// =======================================================================
// function : Constructor
// purpose :
@ -26,9 +34,39 @@
ShapeView_TreeModel::ShapeView_TreeModel (QObject* theParent)
: TreeModel_ModelBase (theParent)
{
for (int aColumnId = 0, aNbColumns = columnCount(); aColumnId < aNbColumns; aColumnId++)
myRootItems.insert(aColumnId, ShapeView_ItemRoot::CreateItem(TreeModel_ItemBasePtr(), 0, aColumnId));
SetHeaderItem (0, TreeModel_HeaderSection ("Name", COLUMN_NAME_WIDTH));
// column 1 is reserved for visiblity state
SetHeaderItem (2, TreeModel_HeaderSection ("Size", COLUMN_SIZE_WIDTH));
SetHeaderItem (3, TreeModel_HeaderSection ("Pointer", COLUMN_POINTER_WIDTH));
SetHeaderItem (4, TreeModel_HeaderSection ("Orientation", COLUMN_ORIENTATION_WIDTH));
SetHeaderItem (5, TreeModel_HeaderSection ("Location", COLUMN_LOCATION_WIDTH));
SetHeaderItem (6, TreeModel_HeaderSection ("Checked", -1, true));
SetHeaderItem (7, TreeModel_HeaderSection ("Closed", -1, true));
SetHeaderItem (8, TreeModel_HeaderSection ("Infinite", -1, true));
SetHeaderItem (9, TreeModel_HeaderSection ("Locked", -1, true));
SetHeaderItem (10, TreeModel_HeaderSection ("Modified", -1, true));
SetHeaderItem (11, TreeModel_HeaderSection ("Orientable", -1, true));
SetHeaderItem (12, TreeModel_HeaderSection ("VERTEX: (X, Y, Z)", -1, true));
SetHeaderItem (13, TreeModel_HeaderSection ("EDGE: Length", -1, true));
SetHeaderItem (14, TreeModel_HeaderSection ("DynamicType", -1, true));
SetHeaderItem (15, TreeModel_HeaderSection ("First", -1, true));
SetHeaderItem (16, TreeModel_HeaderSection ("Last", -1, true));
SetHeaderItem (17, TreeModel_HeaderSection ("Continuity", -1, true));
SetHeaderItem (18, TreeModel_HeaderSection ("IsClosed", -1, true));
SetHeaderItem (19, TreeModel_HeaderSection ("IsPeriodic", -1, true));
}
// =======================================================================
// function : createRootItem
// purpose :
// =======================================================================
void ShapeView_TreeModel::createRootItem (const int theColumnId)
{
myRootItems.insert (theColumnId, ShapeView_ItemRoot::CreateItem (TreeModel_ItemBasePtr(), 0, theColumnId));
if (theColumnId == 0)
m_pRootItem = myRootItems[0];
}
@ -63,31 +101,6 @@ void ShapeView_TreeModel::RemoveAllShapes()
EmitLayoutChanged();
}
// =======================================================================
// function : headerData
// purpose :
// =======================================================================
QVariant ShapeView_TreeModel::headerData (int theSection, Qt::Orientation theOrientation, int theRole) const
{
if (theOrientation != Qt::Horizontal || theRole != Qt::DisplayRole)
return QVariant();
{
switch (theSection)
{
case 0: return "Name";
case 1: return "Size";
case 2: return "Pointer";
case 3: return "Orientation";
case 4: return "Location";
case 5: return "Flags"; // Checked/Closed/Infinite/Locked/Modified/Orientable
case 7: return "Other";
//Auto Triangulation
default: break;
}
}
return QVariant();
}
// =======================================================================
// function : FindIndex
// purpose :
@ -105,21 +118,3 @@ QModelIndex ShapeView_TreeModel::FindIndex (const TopoDS_Shape& theShape) const
}
return QModelIndex();
}
// =======================================================================
// function : SingleSelected
// purpose :
// =======================================================================
QModelIndex ShapeView_TreeModel::SingleSelected (const QModelIndexList& theIndices, const int theCellId,
const Qt::Orientation theOrientation)
{
QModelIndexList aFirstColumnSelectedIndices;
for (QModelIndexList::const_iterator anIndicesIt = theIndices.begin(); anIndicesIt != theIndices.end(); anIndicesIt++)
{
QModelIndex anIndex = *anIndicesIt;
if ((theOrientation == Qt::Horizontal && anIndex.column() == theCellId) ||
(theOrientation == Qt::Vertical && anIndex.row() == theCellId))
aFirstColumnSelectedIndices.append (anIndex);
}
return aFirstColumnSelectedIndices.size() == 1 ? aFirstColumnSelectedIndices.first() : QModelIndex();
}

View File

@ -53,32 +53,15 @@ public:
virtual TreeModel_ItemBasePtr RootItem(const int theColumn) const Standard_OVERRIDE
{ return myRootItems[theColumn]; }
//! Returns count of columns in the model.
//! \param theParent an index of the parent item
//! \return integer value
virtual int columnCount (const QModelIndex& theParent = QModelIndex()) const Standard_OVERRIDE
{ (void)theParent; return 7; }
//! Returns the header data for the given role and section in the header with the specified orientation.
//! \param theSection the header section. For horizontal headers - column number, for vertical headers - row number.
//! \param theOrientation a header orientation
//! \param theRole a data role
//! \return the header data
Standard_EXPORT virtual QVariant headerData (int theSection, Qt::Orientation theOrientation,
int theRole = Qt::DisplayRole ) const Standard_OVERRIDE;
//! Returns model index of the shape.
//! \param theShape a shape object
//! \return the model index
QModelIndex FindIndex (const TopoDS_Shape& theShape) const;
//! Returns single selected item in the cell of given orientation. If the orientation is Horizontal,
//! in the cell id colum, one row should be selected.
//! \param theIndices a container of selected indices
//! \param theCellId column index if orientation is horizontal, row index otherwise
//! \param theOrientation an orientation to apply the cell index
//! \return model index from the list
Standard_EXPORT static QModelIndex SingleSelected (const QModelIndexList& theIndices, const int theCellId,
const Qt::Orientation theOrientation = Qt::Horizontal);
protected:
//! Creates root item
//! \param theColumnId index of a column
virtual void createRootItem (const int theColumnId) Standard_OVERRIDE;
private:
QMap<int, TreeModel_ItemBasePtr> myRootItems; //!< container of root items, for each column own root item

View File

@ -0,0 +1,52 @@
// Created on: 2017-06-16
// Created by: Natalia ERMOLAEVA
// Copyright (c) 2017 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <inspector/ShapeView_VisibilityState.hxx>
#include <inspector/ShapeView_ItemShape.hxx>
// =======================================================================
// function : SetVisible
// purpose :
// =======================================================================
bool ShapeView_VisibilityState::SetVisible (const QModelIndex& theIndex, const bool theState, const bool toEmitDataChanged)
{
TopoDS_Shape aShape = GetShape (theIndex);
if (aShape.IsNull())
return false;
myDisplayer->SetVisible (aShape, theState, myPresentationType);
if (toEmitDataChanged)
getModel()->EmitDataChanged (theIndex, theIndex);
return true;
}
// =======================================================================
// function : GetShape
// purpose :
// =======================================================================
TopoDS_Shape ShapeView_VisibilityState::GetShape (const QModelIndex& theIndex) const
{
TreeModel_ItemBasePtr anItemBase = TreeModel_ModelBase::GetItemByIndex (theIndex);
if (!anItemBase)
return TopoDS_Shape();
ShapeView_ItemShapePtr aShapeItem = itemDynamicCast<ShapeView_ItemShape>(anItemBase);
if (!aShapeItem)
return TopoDS_Shape();
return aShapeItem->GetItemShape();
}

View File

@ -0,0 +1,76 @@
// Created on: 2017-06-16
// Created by: Natalia ERMOLAEVA
// Copyright (c) 2017 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef ShapeView_VisibilityState_H
#define ShapeView_VisibilityState_H
#include <inspector/TreeModel_VisibilityState.hxx>
#include <inspector/View_Displayer.hxx>
#include <Standard.hxx>
#include <Standard_Macro.hxx>
#include <TopoDS_Shape.hxx>
class TreeModel_ModelBase;
//! \class ShapeView_VisibilityState
//! \brief Class provides connection between model and visualization control
class ShapeView_VisibilityState : public TreeModel_VisibilityState
{
public:
//! Constructor
ShapeView_VisibilityState (TreeModel_ModelBase* theModel) : TreeModel_VisibilityState (theModel),
myPresentationType (View_PresentationType_Main) {}
//! Destructor
~ShapeView_VisibilityState() {}
//! Sets current displayer
//! \theDisplayer class that provides connection to visualized objects
void SetDisplayer (View_Displayer* theDisplayer) { myDisplayer = theDisplayer; }
//! Sets presentation type for displayer
//! \param theType type value
void SetPresentationType (const View_PresentationType theType) { myPresentationType = theType; }
//! Returns true if visibility of the item can be changed
//! \param theIndex tree model index
//! \return boolean value
virtual bool CanBeVisible (const QModelIndex& theIndex) const Standard_OVERRIDE { return !GetShape (theIndex).IsNull(); }
//! Sets visibility state
//! \theIndex tree model index
//! \param theState visibility state
//! \param toEmitDataChanged boolean flag whether emit of the model should be done immediatelly
//! \return true if state is changed
Standard_EXPORT virtual bool SetVisible (const QModelIndex& theIndex, const bool theState, const bool toEmitDataChanged) Standard_OVERRIDE;
//! Returns visibility state value
virtual bool IsVisible (const QModelIndex& theIndex) const Standard_OVERRIDE
{ return myDisplayer->IsVisible (GetShape (theIndex), myPresentationType); }
protected:
//! Gets shape of the view model by the parameter index if it has a shape
//! \param theIndex tree model index
//! \return shape instance
TopoDS_Shape GetShape (const QModelIndex& theIndex) const;
private:
View_Displayer* myDisplayer; //! view displayer
View_PresentationType myPresentationType; //! presentation type
};
#endif

View File

@ -17,16 +17,23 @@
#include <inspector/ShapeView_ItemRoot.hxx>
#include <inspector/ShapeView_ItemShape.hxx>
#include <inspector/ShapeView_TreeModel.hxx>
#include <inspector/ShapeView_VisibilityState.hxx>
#include <inspector/TreeModel_Tools.hxx>
#include <inspector/TreeModel_ContextMenu.hxx>
#include <inspector/ViewControl_Tools.hxx>
#include <inspector/ViewControl_TreeView.hxx>
#include <inspector/View_Displayer.hxx>
#include <inspector/View_PresentationType.hxx>
#include <inspector/View_Tools.hxx>
#include <inspector/View_ToolBar.hxx>
#include <inspector/View_Widget.hxx>
#include <inspector/View_Window.hxx>
#include <inspector/View_Viewer.hxx>
#include <inspector/ShapeView_Window.hxx>
#include <inspector/ShapeView_ItemRoot.hxx>
#include <inspector/ShapeView_ItemShape.hxx>
#include <inspector/ShapeView_TreeModel.hxx>
#include <inspector/ShapeView_OpenFileDialog.hxx>
#include <inspector/ShapeView_Tools.hxx>
@ -54,13 +61,6 @@
#include <QVBoxLayout>
#include <Standard_WarningsRestore.hxx>
const int FIRST_COLUMN_WIDTH = 190;
const int SIZE_COLUMN_WIDTH = 30;
const int POINTER_COLUMN_WIDTH = 70;
const int ORIENTATION_COLUMN_WIDTH = 70;
const int LOCATION_COLUMN_WIDTH = 120;
const int FLAGS_COLUMN_WIDTH = 70;
const int DEFAULT_TEXT_VIEW_WIDTH = 800;
const int DEFAULT_TEXT_VIEW_HEIGHT = 700;
const int DEFAULT_TEXT_VIEW_POSITION_X = 430;
@ -75,95 +75,44 @@ const int DEFAULT_SHAPE_VIEW_POSITION_Y = 60;
const int SHAPEVIEW_DEFAULT_TREE_VIEW_WIDTH = 600;
const int SHAPEVIEW_DEFAULT_TREE_VIEW_HEIGHT = 500;
const int SHAPEVIEW_DEFAULT_VIEW_WIDTH = 200;//400;
const int SHAPEVIEW_DEFAULT_VIEW_WIDTH = 300;
const int SHAPEVIEW_DEFAULT_VIEW_HEIGHT = 1000;
//! \class ShapeView_TreeView
//! Extended tree view control with possibility to set predefined size.
class ShapeView_TreeView : public QTreeView
{
public:
//! Constructor
ShapeView_TreeView (QWidget* theParent) : QTreeView (theParent), myDefaultWidth (-1), myDefaultHeight (-1) {}
//! Destructor
virtual ~ShapeView_TreeView() {}
//! Sets default size of control, that is used by the first control show
//! \param theDefaultWidth the width value
//! \param theDefaultHeight the height value
void SetPredefinedSize (int theDefaultWidth, int theDefaultHeight);
//! Returns predefined size if both values are positive, otherwise parent size hint
virtual QSize sizeHint() const Standard_OVERRIDE;
private:
int myDefaultWidth; //!< default width, -1 if it should not be used
int myDefaultHeight; //!< default height, -1 if it should not be used
};
// =======================================================================
// function : SetPredefinedSize
// purpose :
// =======================================================================
void ShapeView_TreeView::SetPredefinedSize (int theDefaultWidth, int theDefaultHeight)
{
myDefaultWidth = theDefaultWidth;
myDefaultHeight = theDefaultHeight;
}
// =======================================================================
// function : sizeHint
// purpose :
// =======================================================================
QSize ShapeView_TreeView::sizeHint() const
{
if (myDefaultWidth > 0 && myDefaultHeight > 0)
return QSize (myDefaultWidth, myDefaultHeight);
return QTreeView::sizeHint();
}
// =======================================================================
// function : Constructor
// purpose :
// =======================================================================
ShapeView_Window::ShapeView_Window (QWidget* theParent, const TCollection_AsciiString& theTemporaryDirectory)
: QObject (theParent), myTemporaryDirectory (theTemporaryDirectory), myNextPosition (0)
ShapeView_Window::ShapeView_Window (QWidget* theParent)
: QObject (theParent), myNextPosition (0)
{
myMainWindow = new QMainWindow (theParent);
myTreeView = new ShapeView_TreeView (myMainWindow);
((ShapeView_TreeView*)myTreeView)->SetPredefinedSize (SHAPEVIEW_DEFAULT_TREE_VIEW_WIDTH,
SHAPEVIEW_DEFAULT_TREE_VIEW_HEIGHT);
myTreeView = new ViewControl_TreeView (myMainWindow);
((ViewControl_TreeView*)myTreeView)->SetPredefinedSize (QSize (SHAPEVIEW_DEFAULT_TREE_VIEW_WIDTH,
SHAPEVIEW_DEFAULT_TREE_VIEW_HEIGHT));
myTreeView->setContextMenuPolicy (Qt::CustomContextMenu);
connect (myTreeView, SIGNAL (customContextMenuRequested (const QPoint&)),
this, SLOT (onTreeViewContextMenuRequested (const QPoint&)));
new TreeModel_ContextMenu (myTreeView);
ShapeView_TreeModel* aModel = new ShapeView_TreeModel (myTreeView);
myTreeView->setModel (aModel);
QItemSelectionModel* aSelectionModel = new QItemSelectionModel (aModel);
myTreeView->setSelectionMode (QAbstractItemView::ExtendedSelection);
myTreeView->setSelectionModel (aSelectionModel);
connect (aSelectionModel, SIGNAL (selectionChanged (const QItemSelection&, const QItemSelection&)),
this, SLOT (onTreeViewSelectionChanged (const QItemSelection&, const QItemSelection&)));
ShapeView_VisibilityState* aVisibilityState = new ShapeView_VisibilityState (aModel);
aModel->SetVisibilityState (aVisibilityState);
TreeModel_Tools::UseVisibilityColumn (myTreeView);
QModelIndex aParentIndex = myTreeView->model()->index (0, 0);
myTreeView->setExpanded (aParentIndex, true);
myTreeView->setColumnWidth (0, FIRST_COLUMN_WIDTH);
myTreeView->setColumnWidth (1, SIZE_COLUMN_WIDTH);
myTreeView->setColumnWidth (2, POINTER_COLUMN_WIDTH);
myTreeView->setColumnWidth (3, ORIENTATION_COLUMN_WIDTH);
myTreeView->setColumnWidth (4, LOCATION_COLUMN_WIDTH);
myTreeView->setColumnWidth (5, FLAGS_COLUMN_WIDTH);
myMainWindow->setCentralWidget (myTreeView);
// view
myViewWindow = new View_Window (myMainWindow);
myViewWindow = new View_Window (myMainWindow, false);
connect (myViewWindow, SIGNAL(eraseAllPerformed()), this, SLOT(onEraseAllPerformed()));
aVisibilityState->SetDisplayer (myViewWindow->GetDisplayer());
aVisibilityState->SetPresentationType (View_PresentationType_Main);
myViewWindow->GetView()->SetPredefinedSize (SHAPEVIEW_DEFAULT_VIEW_WIDTH, SHAPEVIEW_DEFAULT_VIEW_HEIGHT);
QDockWidget* aViewDockWidget = new QDockWidget (tr ("View"), myMainWindow);
aViewDockWidget->setObjectName (aViewDockWidget->windowTitle());
aViewDockWidget->setWidget (myViewWindow);
aViewDockWidget->setTitleBarWidget (myViewWindow->GetViewToolBar()->GetControl());
myMainWindow->addDockWidget (Qt::RightDockWidgetArea, aViewDockWidget);
@ -196,6 +145,61 @@ void ShapeView_Window::SetParent (void* theParent)
}
}
// =======================================================================
// function : FillActionsMenu
// purpose :
// =======================================================================
void ShapeView_Window::FillActionsMenu (void* theMenu)
{
QMenu* aMenu = (QMenu*)theMenu;
QList<QDockWidget*> aDockwidgets = myMainWindow->findChildren<QDockWidget*>();
for (QList<QDockWidget*>::iterator it = aDockwidgets.begin(); it != aDockwidgets.end(); ++it)
{
QDockWidget* aDockWidget = *it;
if (aDockWidget->parentWidget() == myMainWindow)
aMenu->addAction (aDockWidget->toggleViewAction());
}
}
// =======================================================================
// function : GetPreferences
// purpose :
// =======================================================================
void ShapeView_Window::GetPreferences (TInspectorAPI_PreferencesDataMap& theItem)
{
theItem.Clear();
theItem.Bind ("geometry", TreeModel_Tools::ToString (myMainWindow->saveState()).toStdString().c_str());
QMap<QString, QString> anItems;
TreeModel_Tools::SaveState (myTreeView, anItems);
View_Tools::SaveState(myViewWindow, anItems);
for (QMap<QString, QString>::const_iterator anItemsIt = anItems.begin(); anItemsIt != anItems.end(); anItemsIt++)
theItem.Bind (anItemsIt.key().toStdString().c_str(), anItemsIt.value().toStdString().c_str());
}
// =======================================================================
// function : SetPreferences
// purpose :
// =======================================================================
void ShapeView_Window::SetPreferences (const TInspectorAPI_PreferencesDataMap& theItem)
{
if (theItem.IsEmpty())
{
TreeModel_Tools::SetDefaultHeaderSections (myTreeView);
return;
}
for (TInspectorAPI_IteratorOfPreferencesDataMap anItemIt (theItem); anItemIt.More(); anItemIt.Next())
{
if (anItemIt.Key().IsEqual ("geometry"))
myMainWindow->restoreState (TreeModel_Tools::ToByteArray (anItemIt.Value().ToCString()));
else if (TreeModel_Tools::RestoreState (myTreeView, anItemIt.Key().ToCString(), anItemIt.Value().ToCString()))
continue;
else if (View_Tools::RestoreState(myViewWindow, anItemIt.Key().ToCString(), anItemIt.Value().ToCString()))
continue;
}
}
// =======================================================================
// function : UpdateContent
// purpose :
@ -255,15 +259,28 @@ void ShapeView_Window::Init (NCollection_List<Handle(Standard_Transient)>& thePa
{
Handle(AIS_InteractiveContext) aContext;
NCollection_List<Handle(Standard_Transient)> aParameters;
for (NCollection_List<Handle(Standard_Transient)>::Iterator aParamsIt (theParameters);
aParamsIt.More(); aParamsIt.Next())
TCollection_AsciiString aPluginName ("TKShapeView");
NCollection_List<TCollection_AsciiString> aSelectedParameters;
if (myParameters->FindSelectedNames (aPluginName)) // selected names have TShape parameters
aSelectedParameters = myParameters->GetSelectedNames (aPluginName);
NCollection_List<TCollection_AsciiString>::Iterator aParamsIt (aSelectedParameters);
for (NCollection_List<Handle(Standard_Transient)>::Iterator anObjectsIt (theParameters);
anObjectsIt.More(); anObjectsIt.Next())
{
Handle(Standard_Transient) anObject = aParamsIt.Value();
Handle(Standard_Transient) anObject = anObjectsIt.Value();
Handle(TopoDS_TShape) aShapePointer = Handle(TopoDS_TShape)::DownCast (anObject);
if (!aShapePointer.IsNull())
{
TopoDS_Shape aShape;
aShape.TShape (aShapePointer);
if (aParamsIt.More())
{
// each Transient object has own location/orientation description
TInspectorAPI_PluginParameters::ParametersToShape (aParamsIt.Value(), aShape);
aParamsIt.Next();
}
addShape (aShape);
}
else
@ -277,6 +294,7 @@ void ShapeView_Window::Init (NCollection_List<Handle(Standard_Transient)>& thePa
myViewWindow->SetContext (View_ContextType_External, aContext);
theParameters = aParameters;
myParameters->SetSelectedNames (aPluginName, NCollection_List<TCollection_AsciiString>());
}
// =======================================================================
@ -322,7 +340,7 @@ void ShapeView_Window::onTreeViewContextMenuRequested (const QPoint& thePosition
if (!aModel)
return;
QModelIndex anIndex = ShapeView_TreeModel::SingleSelected (aModel->selectedIndexes(), 0);
QModelIndex anIndex = TreeModel_ModelBase::SingleSelected (aModel->selectedIndexes(), 0);
TreeModel_ItemBasePtr anItemBase = TreeModel_ModelBase::GetItemByIndex (anIndex);
if (!anItemBase)
return;
@ -330,19 +348,34 @@ void ShapeView_Window::onTreeViewContextMenuRequested (const QPoint& thePosition
QMenu* aMenu = new QMenu(myMainWindow);
ShapeView_ItemRootPtr aRootItem = itemDynamicCast<ShapeView_ItemRoot> (anItemBase);
if (aRootItem) {
aMenu->addAction (createAction("Load BREP file", SLOT (onLoadFile())));
aMenu->addAction (createAction ("Remove all shape items", SLOT (onClearView())));
aMenu->addAction (ViewControl_Tools::CreateAction ("Load BREP file", SLOT (onLoadFile()), myMainWindow, this));
aMenu->addAction (ViewControl_Tools::CreateAction ("Remove all shape items", SLOT (onClearView()), myMainWindow, this));
}
else {
if (!myTemporaryDirectory.IsEmpty())
aMenu->addAction (createAction ("BREP view", SLOT (onBREPView())));
aMenu->addAction (createAction ("Close All BREP views", SLOT (onCloseAllBREPViews())));
aMenu->addAction (createAction ("BREP directory", SLOT (onBREPDirectory())));
if (!GetTemporaryDirectory().IsEmpty())
aMenu->addAction (ViewControl_Tools::CreateAction ("BREP view", SLOT (onBREPView()), myMainWindow, this));
aMenu->addAction (ViewControl_Tools::CreateAction ("Close All BREP views", SLOT (onCloseAllBREPViews()), myMainWindow, this));
aMenu->addAction (ViewControl_Tools::CreateAction ("BREP directory", SLOT (onBREPDirectory()), myMainWindow, this));
}
QPoint aPoint = myTreeView->mapToGlobal (thePosition);
aMenu->exec (aPoint);
}
// =======================================================================
// function : onEraseAllPerformed
// purpose :
// =======================================================================
void ShapeView_Window::onEraseAllPerformed()
{
ShapeView_TreeModel* aTreeModel = dynamic_cast<ShapeView_TreeModel*> (myTreeView->model());
// TODO: provide update for only visibility state for better performance TopoDS_Shape myCustomShape;
aTreeModel->Reset();
aTreeModel->EmitLayoutChanged();
}
// =======================================================================
// function : onBREPDirectory
// purpose :
@ -352,7 +385,7 @@ void ShapeView_Window::onBREPDirectory()
QString aFilter (tr ("BREP file (*.brep*)"));
QString aSelectedFilter;
QString aFileName = QFileDialog::getOpenFileName (0, tr ("Export shape to BREP file"),
myTemporaryDirectory.ToCString(), aSelectedFilter);
GetTemporaryDirectory().ToCString(), aSelectedFilter);
if (!aFileName.isEmpty())
viewFile (aFileName);
}
@ -377,7 +410,7 @@ void ShapeView_Window::onLoadFile()
// =======================================================================
void ShapeView_Window::onBREPView()
{
if (myTemporaryDirectory.IsEmpty())
if (GetTemporaryDirectory().IsEmpty())
return;
QItemSelectionModel* aModel = myTreeView->selectionModel();
@ -401,7 +434,7 @@ void ShapeView_Window::onBREPView()
QDir aDir;
if (aFileName.isEmpty() || !aDir.exists (aFileName))
{
TCollection_AsciiString aFileNameIndiced = myTemporaryDirectory + TCollection_AsciiString ("\\") +
TCollection_AsciiString aFileNameIndiced = GetTemporaryDirectory() + TCollection_AsciiString ("\\") +
getNextTmpName (anItem->TShapePointer());
const TopoDS_Shape& aShape = anItem->GetItemShape();
BRepTools::Write (aShape, aFileNameIndiced.ToCString());
@ -440,32 +473,6 @@ void ShapeView_Window::onEditorDestroyed(QObject* theObject)
}
}
// =======================================================================
// function : displaySelectedShapes
// purpose :
// =======================================================================
void ShapeView_Window::displaySelectedShapes (const QModelIndexList& theSelected)
{
for (QModelIndexList::const_iterator aSelIt = theSelected.begin(); aSelIt != theSelected.end(); aSelIt++)
{
QModelIndex anIndex = *aSelIt;
if (anIndex.column() != 0)
continue;
TreeModel_ItemBasePtr anItemBase = TreeModel_ModelBase::GetItemByIndex (anIndex);
if (!anItemBase)
continue;
ShapeView_ItemShapePtr aShapeItem = itemDynamicCast<ShapeView_ItemShape>(anItemBase);
if (!aShapeItem)
continue;
TopoDS_Shape aShape = aShapeItem->GetItemShape();
myViewWindow->GetDisplayer()->DisplayPresentation (ShapeView_Tools::CreatePresentation(aShape),
View_PresentationType_Main, true);
}
myViewWindow->GetDisplayer()->UpdateViewer();
}
// =======================================================================
// function : viewFile
// purpose :
@ -506,7 +513,7 @@ void ShapeView_Window::viewFile (const QString& theFileName)
// =======================================================================
void ShapeView_Window::removeBREPFiles()
{
QDir aDir (myTemporaryDirectory.ToCString());
QDir aDir (GetTemporaryDirectory().ToCString());
QStringList anEntries = aDir.entryList();
QString aPrefix(viewBREPPrefix().ToCString());
@ -517,17 +524,6 @@ void ShapeView_Window::removeBREPFiles()
}
}
// =======================================================================
// function : createAction
// purpose :
// =======================================================================
QAction* ShapeView_Window::createAction (const QString& theText, const char* theSlot)
{
QAction* anAction = new QAction (theText, myMainWindow);
connect (anAction, SIGNAL (triggered(bool)), this, theSlot);
return anAction;
}
// =======================================================================
// function : getNextTmpName
// purpose :

View File

@ -31,7 +31,6 @@
#include <QTreeView>
#include <Standard_WarningsRestore.hxx>
class View_Displayer;
class View_Window;
class QAction;
@ -46,7 +45,7 @@ class ShapeView_Window : public QObject
public:
//! Constructor
Standard_EXPORT ShapeView_Window (QWidget* theParent, const TCollection_AsciiString& theTemporaryDirectory);
Standard_EXPORT ShapeView_Window (QWidget* theParent);
//! Destructor
Standard_EXPORT virtual ~ShapeView_Window();
@ -60,6 +59,18 @@ public:
//! \param theParameters a parameters container
void SetParameters (const Handle(TInspectorAPI_PluginParameters)& theParameters) { myParameters = theParameters; }
//! Provide container for actions available in inspector on general level
//! \param theMenu if Qt implementation, it is QMenu object
Standard_EXPORT virtual void FillActionsMenu (void* theMenu);
//! Returns plugin preferences: dock widgets state, tree view columns.
//! \param theItem container of preference elements
Standard_EXPORT void GetPreferences (TInspectorAPI_PreferencesDataMap& theItem);
//! Applies plugin preferences
//! \param theItem container of preference elements
Standard_EXPORT void SetPreferences (const TInspectorAPI_PreferencesDataMap& theItem);
//! Applyes parameters to Init controls, opens files if there are in parameters, updates OCAF tree view model
Standard_EXPORT void UpdateContent();
@ -70,7 +81,7 @@ public:
QTreeView* GetTreeView() const { return myTreeView; }
//! Returns path to temporary directory
TCollection_AsciiString GetTemporaryDirectory() const { return myTemporaryDirectory; }
TCollection_AsciiString GetTemporaryDirectory() const { return myParameters->GetTemporaryDirectory(); }
//! Removes all shapes in tree view model, remove all stored BREP files
Standard_EXPORT void RemoveAllShapes();
@ -93,16 +104,13 @@ private:
protected slots:
//! Displays shapes obtained by selected indices
//! \param theSelected a container of selected indices in tree view
//! \param theDeselected a container of deselected indices in tree view
void onTreeViewSelectionChanged (const QItemSelection& theSelected, const QItemSelection& theDeselected)
{ (void)theDeselected; displaySelectedShapes(theSelected.indexes()); }
//! Shows context menu for tree view selected item. It contains expand/collapse actions.
//! \param thePosition a clicked point
void onTreeViewContextMenuRequested (const QPoint& thePosition);
//! Updates visibility states by erase all in context
void onEraseAllPerformed();
//! Exports shape to BREP file and view result file
void onBREPDirectory();
@ -148,17 +156,13 @@ protected:
//! \return string value
TCollection_AsciiString getNextTmpName (const TCollection_AsciiString& thePointerInfo);
//! Finds shapes for selected items in tree view and display presentations for the shapes
//! \param theSelected a list of selected indices in tree view
void displaySelectedShapes (const QModelIndexList& theSelected);
private:
QMainWindow* myMainWindow; //!< main control, parent for all ShapeView controls
View_Window* myViewWindow; //!< OCC 3d view to visualize presentations
QTreeView* myTreeView; //!< tree view visualized shapes
TCollection_AsciiString myTemporaryDirectory; //!< path to the temporary directory
int myNextPosition; //!< delta of moving control of view BREP file
QList<QWidget*> myBREPViews; //!< list of view BREP file controls

View File

@ -3,5 +3,9 @@ TInspector_Communicator.cxx
TInspector_Communicator.hxx
TInspector_PluginParameters.cxx
TInspector_PluginParameters.hxx
TInspector_Preferences.cxx
TInspector_Preferences.hxx
TInspector_Shortcut.cxx
TInspector_Shortcut.hxx
TInspector_Window.cxx
TInspector_Window.hxx

View File

@ -1,5 +1,6 @@
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file>icons/item_algo_folder.png</file>
<file>icons/plugin_actions.png</file>
</qresource>
</RCC>

View File

@ -37,9 +37,10 @@ TInspector_Communicator::TInspector_Communicator()
static int argc = 1;
static char* argv[] = { (char*)"", 0 };
#if QT_VERSION > 0x050000
TCollection_AsciiString aPlugindsDirName = OSD_Environment ("QTDIR").Value();
if (!aPlugindsDirName.IsEmpty())
QApplication::addLibraryPath (QString (aPlugindsDirName.ToCString()) + "/plugins");
OSD_Environment anEnvironment ("QTDIR");
TCollection_AsciiString aPlugindsDirName = anEnvironment.Value();
aPlugindsDirName += "/plugins";
QApplication::addLibraryPath (aPlugindsDirName.ToCString());
#endif
new QApplication (argc, argv);
}
@ -58,3 +59,12 @@ void TInspector_Communicator::SetVisible (const bool theVisible)
QApplication::processEvents();
#endif
}
// =======================================================================
// function : Move
// purpose :
// =======================================================================
void TInspector_Communicator::Move (const int theXPosition, const int theYPosition)
{
myWindow->GetMainWindow()->move (theXPosition, theYPosition);
}

View File

@ -86,10 +86,27 @@ public:
Standard_EXPORT void SetSelected (const NCollection_List<Handle(Standard_Transient)>& theObjects)
{ myWindow->SetSelected (theObjects); }
//! Sets path to a directory for temporary plugin files
//! \param thePath a path
void SetTemporaryDirectory (const TCollection_AsciiString& thePath) { myWindow->SetTemporaryDirectory (thePath); }
//! Returns path to a directory for temporary plugin files
//! \return path
TCollection_AsciiString GetTemporaryDirectory() const { return myWindow->GetTemporaryDirectory(); }
//! Change window visibility
//! \param theVisible boolean state
Standard_EXPORT virtual void SetVisible (const bool theVisible);
//! Change window position
//! \param theX X pixel position of top left corner of the window
//! \param theY Y pixel position
Standard_EXPORT virtual void Move (const int theXPosition, const int theYPosition);
//! Puts in the stream information about communicator
//! \param theStream stream for output
void Dump (Standard_OStream& theStream) const { return myWindow->Dump (theStream); }
private:
TInspector_Window* myWindow; //!< current window

View File

@ -15,6 +15,17 @@
#include <inspector/TInspector_PluginParameters.hxx>
#include <inspector/TInspector_Preferences.hxx>
// =======================================================================
// function : Constructor
// purpose :
// =======================================================================
TInspector_PluginParameters::TInspector_PluginParameters (TInspector_Window* theWindow)
: myWindow (theWindow), myPreferences (new TInspector_Preferences())
{
myPreferences->SetDirectory (GetTemporaryDirectory());
}
// =======================================================================
// function : SetParameters
@ -32,3 +43,15 @@ void TInspector_PluginParameters::SetParameters (const TCollection_AsciiString&
SetSelected (thePluginName, theParameters);
myWindow->ActivateTool (thePluginName);
}
// =======================================================================
// function : SetTemporaryDirectory
// purpose :
// =======================================================================
void TInspector_PluginParameters::SetTemporaryDirectory (const TCollection_AsciiString& thePath)
{
if (thePath.IsEqual (myPreferences->GetDirectory()))
return;
myPreferences->SetDirectory (thePath);
}

View File

@ -20,8 +20,11 @@
#include <Standard_Macro.hxx>
#include <inspector/TInspectorAPI_PluginParameters.hxx>
#include <inspector/TInspector_Preferences.hxx>
#include <inspector/TInspector_Window.hxx>
class TInspector_ReportCallBack;
//! \class TInspector_PluginParameters.
//! \brief This is plugin parameters extended by a possibility to activate module during setting new parameters
class TInspector_PluginParameters : public TInspectorAPI_PluginParameters
@ -29,7 +32,7 @@ class TInspector_PluginParameters : public TInspectorAPI_PluginParameters
public:
//! Constructor
Standard_EXPORT TInspector_PluginParameters (TInspector_Window* theWindow) : myWindow (theWindow) {}
Standard_EXPORT TInspector_PluginParameters (TInspector_Window* theWindow);
//! Destructor
virtual ~TInspector_PluginParameters() Standard_OVERRIDE {}
@ -42,9 +45,34 @@ public:
const NCollection_List<Handle(Standard_Transient)>& theParameters,
const Standard_Boolean& theToActivatePlugin = Standard_False) Standard_OVERRIDE;
//! Sets path to a directory for temporary plugin files. Sets the directory into preferences loader
//! \param thePath a path
virtual void SetTemporaryDirectory (const TCollection_AsciiString& thePath) Standard_OVERRIDE;
//! Returns plugin preferences
//! \param thePluginName a plugin name
virtual void GetPreferences (const TCollection_AsciiString& thePluginName,
TInspectorAPI_PreferencesDataMap& theItem) Standard_OVERRIDE
{ myPreferences->GetPreferences (thePluginName, theItem); }
//! Stores plugin preferences
//! \param thePluginName a plugin name
//! \theItem container of plugin preferences values in form: <name, value>
virtual void SetPreferences (const TCollection_AsciiString& thePluginName,
const TInspectorAPI_PreferencesDataMap& theItem) Standard_OVERRIDE
{ myPreferences->SetPreferences (thePluginName, theItem); }
//! Store plugin preferences into a preferences file
void StorePreferences() { myPreferences->StorePreferences(); }
//! Remove plugin preferences file
void RemovePreferences() { myPreferences->RemovePreferences(); }
private:
TInspector_Window* myWindow; //!< the current window
Handle(TInspector_ReportCallBack) myReportCallBack; //!< inspector report callback for automatic view update
TInspector_Preferences* myPreferences; //!< the preferences loader
};
#endif

View File

@ -0,0 +1,159 @@
// Created on: 2017-06-16
// Created by: Natalia ERMOLAEVA
// Copyright (c) 2017 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <inspector/TInspector_Preferences.hxx>
#include <Standard_WarningsDisable.hxx>
#include <QDir>
#include <QDomDocument>
#include <QDomElement>
#include <QDomNode>
#include <QFile>
#include <QTextStream>
#include <Standard_WarningsRestore.hxx>
// =======================================================================
// function : GetPreferences
// purpose :
// =======================================================================
void TInspector_Preferences::GetPreferences (const TCollection_AsciiString& thePluginName,
TInspectorAPI_PreferencesDataMap& theItem)
{
theItem.Clear();
if (!myIsLoadedPreferences)
{
loadPreferences();
myIsLoadedPreferences = Standard_True;
}
myLoadedPreferences.Find (thePluginName, theItem);
}
// =======================================================================
// function : StorePreferences
// purpose :
// =======================================================================
void TInspector_Preferences::StorePreferences()
{
if (myLoadedPreferences.IsEmpty())
return;
QString aFileName = QString (GetDirectory().ToCString()) + QDir::separator() + PreferencesFileName();
QFile aFile(aFileName);
if (!aFile.open (QFile::WriteOnly))
return;
QDomDocument aDomDocument (documentKey());
QDomComment aComment = aDomDocument.createComment("\nThis file is automatically created by TInspector application.\nChanges made in this file can be lost.\n");
aDomDocument.appendChild (aComment);
QDomElement aRootElement = aDomDocument.createElement (documentKey());
aDomDocument.appendChild (aRootElement);
for (NCollection_DataMap<TCollection_AsciiString, TInspectorAPI_PreferencesDataMap>::Iterator aPrefsIt (myLoadedPreferences);
aPrefsIt.More(); aPrefsIt.Next())
{
QDomElement aPluginElement = aDomDocument.createElement (pluginKey());
aPluginElement.setAttribute (nameKey(), aPrefsIt.Key().ToCString());
aRootElement.appendChild (aPluginElement);
const TInspectorAPI_PreferencesDataMap& aPluginMap = aPrefsIt.Value();
for (TInspectorAPI_IteratorOfPreferencesDataMap aPluginPrefsIt (aPluginMap); aPluginPrefsIt.More(); aPluginPrefsIt.Next())
{
QDomElement aParameterElement = aDomDocument.createElement (parameterKey());
aParameterElement.setAttribute (nameKey(), aPluginPrefsIt.Key().ToCString());
aParameterElement.setAttribute (valueKey(), aPluginPrefsIt.Value().ToCString());
aPluginElement.appendChild (aParameterElement);
}
}
QTextStream aTextStream (&aFile);
QStringList aDocumentStr = aDomDocument.toString().split ("\n");
for (QStringList::ConstIterator aContentIt = aDocumentStr.begin(); aContentIt != aDocumentStr.end(); ++aContentIt)
aTextStream << *aContentIt << endl;
aFile.close();
}
// =======================================================================
// function : RemovePreferences
// purpose :
// =======================================================================
void TInspector_Preferences::RemovePreferences()
{
QString aFileName = QString (GetDirectory().ToCString()) + QDir::separator() + PreferencesFileName();
QDir aDir (GetDirectory().ToCString());
if (aDir.exists (aFileName))
aDir.remove (aFileName);
reset();
}
// =======================================================================
// function : loadPreferences
// purpose :
// =======================================================================
void TInspector_Preferences::loadPreferences()
{
QString aFileName = QString (GetDirectory().ToCString()) + QDir::separator() + PreferencesFileName();
QFile aFile (aFileName);
if (!aFile.open (QFile::ReadOnly))
return;
QDomDocument aDomDocument;
bool aResult = aDomDocument.setContent (&aFile);
aFile.close();
if (!aResult)
return;
QDomElement aRootElement = aDomDocument.documentElement();
if (aRootElement.isNull() || aRootElement.tagName() != documentKey())
return;
QDomNode aPluginNode = aRootElement.firstChild();
while (!aPluginNode.isNull())
{
if (aPluginNode.isElement())
{
QDomElement aPluginElement = aPluginNode.toElement();
if (aPluginElement.tagName() == pluginKey() && aPluginElement.hasAttribute (nameKey()))
{
TInspectorAPI_PreferencesDataMap anItem;
readPluginItem (aPluginElement, anItem);
myLoadedPreferences.Bind (aPluginElement.attribute (nameKey()).toStdString().c_str(), anItem);
}
}
aPluginNode = aPluginNode.nextSibling();
}
}
// =======================================================================
// function : readPluginItem
// purpose :
// =======================================================================
void TInspector_Preferences::readPluginItem (const QDomElement thePluginElement, TInspectorAPI_PreferencesDataMap& theItem)
{
QDomNode aParameterNode = thePluginElement.firstChild();
while (!aParameterNode.isNull())
{
if (aParameterNode.isElement())
{
QDomElement aParameterElement = aParameterNode.toElement();
if (aParameterElement.tagName() == parameterKey() &&
aParameterElement.hasAttribute (nameKey()) && aParameterElement.hasAttribute (valueKey()))
{
theItem.Bind (aParameterElement.attribute (nameKey()).toStdString().c_str(),
aParameterElement.attribute (valueKey()).toStdString().c_str());
}
}
aParameterNode = aParameterNode.nextSibling();
}
}

View File

@ -0,0 +1,100 @@
// Created on: 2017-06-16
// Created by: Natalia ERMOLAEVA
// Copyright (c) 2017 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef TInspector_Preferences_H
#define TInspector_Preferences_H
#include <TCollection_AsciiString.hxx>
#include <inspector/TInspectorAPI_PreferencesDataMap.hxx>
#include <Standard_WarningsDisable.hxx>
#include <QDomElement>
#include <Standard_WarningsRestore.hxx>
//! The class to read/write custom plugin preferences in XML format.
//! The preferences file is intended to know about:
//! - dock window placement
//! - tree view columns: visibility, width
class TInspector_Preferences
{
public:
//! Constructs the communicator.
TInspector_Preferences() {}
//! Destructor
virtual ~TInspector_Preferences() {}
static Standard_CString PreferencesFileName() { return ".tinspector.xml"; }
//! Sets path to a preferences file
//! \param thePath a path
void SetDirectory (const TCollection_AsciiString& thePath) { reset(); myDirectory = thePath; }
//! Returns path to a preferences file
//! \return path
TCollection_AsciiString GetDirectory() const { return myDirectory; }
//! Returns plugin preferences
//! \param thePluginName a plugin name
Standard_EXPORT void GetPreferences (const TCollection_AsciiString& thePluginName,
TInspectorAPI_PreferencesDataMap& theItem);
//! Stores plugin preferences
//! \param thePluginName a plugin name
//! \theItem container of plugin preferences values in form: <name, value>
void SetPreferences (const TCollection_AsciiString& thePluginName, const TInspectorAPI_PreferencesDataMap& theItem)
{ myLoadedPreferences.Bind(thePluginName, theItem); }
//! Store plugin preferences into a preferences file
Standard_EXPORT void StorePreferences();
//! Remove plugin preferences file
Standard_EXPORT void RemovePreferences();
private:
//! Loads the directory preference file with filling internal container
void loadPreferences();
//! clears all internal containers with information of already loaded file
void reset() { myLoadedPreferences.Clear(); myIsLoadedPreferences = Standard_False; }
//! Reads plugin preferences and fill container
void readPluginItem(const QDomElement thePluginElement, TInspectorAPI_PreferencesDataMap& theItem);
//! Returns text of attribute document
static Standard_CString documentKey() { return "document"; }
//! Returns text of attribute plugin
static Standard_CString pluginKey() { return "plugin"; }
//! Returns text of attribute parameter
static Standard_CString parameterKey() { return "parameter"; }
//! Returns text of attribute name
static Standard_CString nameKey() { return "name"; }
//! Returns text of attribute value
static Standard_CString valueKey() { return "value"; }
private:
//! directory of preferences file
TCollection_AsciiString myDirectory;
//! container of already loaded preferences : cache
NCollection_DataMap<TCollection_AsciiString, TInspectorAPI_PreferencesDataMap> myLoadedPreferences;
//! state whether the preferences of the current directory is loaded
Standard_Boolean myIsLoadedPreferences;
};
#endif

View File

@ -13,9 +13,9 @@
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <inspector/DFBrowser_Shortcut.hxx>
#include <inspector/TInspector_Shortcut.hxx>
#include <inspector/DFBrowser_Module.hxx>
#include <inspector/TInspector_Window.hxx>
#include <Standard_WarningsDisable.hxx>
#include <QApplication>
@ -26,8 +26,8 @@
// function : Constructor
// purpose :
// =======================================================================
DFBrowser_Shortcut::DFBrowser_Shortcut (QObject* theParent)
: QObject (theParent), myModule (0)
TInspector_Shortcut::TInspector_Shortcut (QObject* theParent, TInspector_Window* theWindow)
: QObject (theParent), myWindow (theWindow)
{
qApp->installEventFilter (this);
}
@ -36,9 +36,9 @@ DFBrowser_Shortcut::DFBrowser_Shortcut (QObject* theParent)
// function : eventFilter
// purpose :
// =======================================================================
bool DFBrowser_Shortcut::eventFilter (QObject* theObject, QEvent* theEvent)
bool TInspector_Shortcut::eventFilter (QObject* theObject, QEvent* theEvent)
{
if (!myModule || theEvent->type() != QEvent::KeyRelease)
if (!myWindow || theEvent->type() != QEvent::KeyRelease)
return QObject::eventFilter (theObject, theEvent);
QKeyEvent* aKeyEvent = dynamic_cast<QKeyEvent*> (theEvent);
@ -46,7 +46,7 @@ bool DFBrowser_Shortcut::eventFilter (QObject* theObject, QEvent* theEvent)
{
case Qt::Key_F5:
{
myModule->UpdateTreeModel();
myWindow->UpdateContent();
return true;
}
default: break;

View File

@ -13,8 +13,8 @@
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef DFBrowser_Shortcut_H
#define DFBrowser_Shortcut_H
#ifndef TInspector_Shortcut_H
#define TInspector_Shortcut_H
#include <Standard.hxx>
#include <Standard_Macro.hxx>
@ -23,31 +23,27 @@
#include <QObject>
#include <Standard_WarningsRestore.hxx>
class DFBrowser_Module;
class TInspector_Window;
class QEvent;
//! \class DFBrowser_Shortcut
//! \class TInspector_Shortcut
//! Listens application KeyRelease event. Processes key event:
//! - <Key_F5>: updates tree view model
class DFBrowser_Shortcut : public QObject
//! - <Key_F5>: updates content (tree view model) of the active plugin
class TInspector_Shortcut : public QObject
{
public:
//! Constructor
Standard_EXPORT DFBrowser_Shortcut (QObject* theParent);
Standard_EXPORT TInspector_Shortcut (QObject* theParent, TInspector_Window* theWindow);
//! Destructor
virtual ~DFBrowser_Shortcut() {}
//! Sets the current module
//! \param theModule a module
void SetModule (DFBrowser_Module* theModule) { myModule = theModule; }
virtual ~TInspector_Shortcut() {}
//! Processes key release event to update view model, otherwise do usual QObject functionality
Standard_EXPORT virtual bool eventFilter (QObject *theObject, QEvent* theEvent) Standard_OVERRIDE;
private:
DFBrowser_Module* myModule; //!< the current module
TInspector_Window* myWindow; //!< the current window
};

View File

@ -13,19 +13,30 @@
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <inspector/TInspector_Window.hxx>
#include <inspector/TInspector_Window.hxx>
#include <inspector/TInspectorAPI_Communicator.hxx>
#include <inspector/TInspector_PluginParameters.hxx>
#include <inspector/TInspector_Shortcut.hxx>
#include <inspector/TreeModel_Tools.hxx>
#include <inspector/ViewControl_Tools.hxx>
#include <OSD_Directory.hxx>
#include <OSD_Environment.hxx>
#include <OSD_Path.hxx>
#include <OSD_Protection.hxx>
#include <Standard_WarningsDisable.hxx>
#include <QApplication>
#include <QButtonGroup>
#include <QDockWidget>
#include <QLabel>
#include <QMainWindow>
#include <QMenu>
#include <QPushButton>
#include <QStackedWidget>
#include <QToolButton>
#include <QVBoxLayout>
#include <Standard_WarningsRestore.hxx>
@ -56,13 +67,32 @@ TInspector_Window::TInspector_Window()
myEmptyWidget = new QWidget (aCentralWidget);
myToolsStack->addWidget (myEmptyWidget);
QWidget* aTopWidget = new QWidget (aCentralWidget);
QHBoxLayout* aTopWidgetLayout = new QHBoxLayout (aTopWidget);
aTopWidgetLayout->setContentsMargins (0, 0, 0, 0);
aTopWidgetLayout->setSpacing (0);
myButtonWidget = new QWidget (aCentralWidget);
myButtonLay = new QHBoxLayout (myButtonWidget);
myButtonLay->setContentsMargins (0, 0, 0, 0);
myButtonLay->setSpacing (0);
myButtonLay->insertStretch (0, 1);
aCentralLayout->addWidget (myButtonWidget);
myButtonGroup = new QButtonGroup (aCentralWidget);
myButtonGroup->setExclusive (true);
myActionsWidget = new QToolButton(aCentralWidget);
myActionsWidget->setPopupMode(QToolButton::InstantPopup);
myActionsWidget->setIcon (QIcon (":/icons/plugin_actions.png"));
myActionsWidget->setIconSize (QSize (20, 20));
QMenu* anActionsMenu = new QMenu(myActionsWidget);
myActionsWidget->setMenu(anActionsMenu);
connect (anActionsMenu, SIGNAL (aboutToShow()), this, SLOT (onShowActionsMenu()));
aTopWidgetLayout->addWidget(myButtonWidget, 1);
aTopWidgetLayout->addWidget(myActionsWidget);
aCentralLayout->addWidget (aTopWidget);
aCentralLayout->addWidget (myToolsStack);
myMainWindow->resize (TINSPECTOR_DEFAULT_WIDTH, TINSPECTOR_DEFAULT_HEIGHT);
@ -70,6 +100,13 @@ TInspector_Window::TInspector_Window()
myMainWindow->setDockOptions (QMainWindow::VerticalTabs);
myParameters = new TInspector_PluginParameters (this);
myDefaultDirectory = defaultTemporaryDirectory();
myParameters->SetTemporaryDirectory (myDefaultDirectory);
applyPreferences();
myShortcut = new TInspector_Shortcut (myMainWindow, this);
}
// =======================================================================
@ -80,7 +117,7 @@ void TInspector_Window::RegisterPlugin (const TCollection_AsciiString& thePlugin
{
TInspector_ToolInfo anInfo;
int aToolId;
if (FindPlugin (thePluginName, anInfo, aToolId))
if (findPlugin (thePluginName, anInfo, aToolId))
return;
myToolNames.append (TInspector_ToolInfo (thePluginName));
@ -137,7 +174,7 @@ void TInspector_Window::Init (const TCollection_AsciiString& thePluginName,
TInspector_ToolInfo anInfo;
int aToolId;
if (!FindPlugin (thePluginName, anInfo, aToolId))
if (!findPlugin (thePluginName, anInfo, aToolId))
return;
if (anInfo.myButton)
@ -148,8 +185,10 @@ void TInspector_Window::Init (const TCollection_AsciiString& thePluginName,
aButtonName = aButtonName.mid(2);
QPushButton* aButton = new QPushButton(aButtonName, myButtonWidget);
aButton->setCheckable (true);
connect (aButton, SIGNAL (clicked (bool)), this, SLOT (onButtonClicked()));
myButtonLay->insertWidget (myButtonLay->count()-1, aButton);
myButtonGroup->addButton (aButton);
anInfo.myButton = aButton;
myToolNames[aToolId] = anInfo;
}
@ -173,6 +212,7 @@ void TInspector_Window::ActivateTool (const TCollection_AsciiString& thePluginNa
return;
TInspector_ToolInfo anInfo = myToolNames[aToolIndex];
bool isPluginLoaded = false;
if (!anInfo.myWidget)
{
if (!LoadPlugin (thePluginName, anInfo))
@ -180,6 +220,7 @@ void TInspector_Window::ActivateTool (const TCollection_AsciiString& thePluginNa
anInfo.myButton->setEnabled (false);
return;
}
isPluginLoaded = true;
myToolsStack->addWidget (anInfo.myWidget);
myToolNames[aToolIndex] = anInfo;
}
@ -190,6 +231,13 @@ void TInspector_Window::ActivateTool (const TCollection_AsciiString& thePluginNa
myOpenButton->setObjectName (thePluginName.ToCString());
anInfo.myCommunicator->UpdateContent();
if (isPluginLoaded)
{
// apply preferences
TInspectorAPI_PreferencesDataMap aPreferences;
myParameters->GetPreferences (thePluginName, aPreferences);
anInfo.myCommunicator->SetPreferences (aPreferences);
}
onCommuncatorNameChanged();
}
@ -200,7 +248,7 @@ void TInspector_Window::ActivateTool (const TCollection_AsciiString& thePluginNa
void TInspector_Window::SetSelected (const NCollection_List<TCollection_AsciiString>& theItemNames)
{
TInspector_ToolInfo anInfo;
if (!ActiveToolInfo (anInfo))
if (!activeToolInfo (anInfo))
return;
myParameters->SetSelectedNames (anInfo.myName, theItemNames);
@ -219,7 +267,7 @@ void TInspector_Window::SetSelected (const NCollection_List<TCollection_AsciiStr
void TInspector_Window::SetSelected (const NCollection_List<Handle(Standard_Transient)>& theObjects)
{
TInspector_ToolInfo anInfo;
if (!ActiveToolInfo (anInfo))
if (!activeToolInfo (anInfo))
return;
myParameters->SetSelected (anInfo.myName, theObjects);
@ -239,7 +287,7 @@ void TInspector_Window::SetOpenButton (QPushButton* theButton)
{
myOpenButton = theButton;
TInspector_ToolInfo anInfo;
if (ActiveToolInfo (anInfo))
if (activeToolInfo (anInfo))
myOpenButton->setObjectName (anInfo.myName.ToCString());
myButtonLay->insertWidget (0, theButton);
}
@ -262,7 +310,7 @@ void TInspector_Window::OpenFile (const TCollection_AsciiString& thePluginName,
myParameters->AddFileName (thePluginName, theFileName);
TInspector_ToolInfo anInfo;
if (!ActiveToolInfo (anInfo) || anInfo.myName != thePluginName)
if (!activeToolInfo (anInfo) || anInfo.myName != thePluginName)
return;
TInspectorAPI_Communicator* aCommunicator = anInfo.myCommunicator;
@ -277,9 +325,7 @@ void TInspector_Window::OpenFile (const TCollection_AsciiString& thePluginName,
void TInspector_Window::UpdateContent()
{
TInspector_ToolInfo anInfo;
if (!ActiveToolInfo (anInfo) || !anInfo.myCommunicator)
return;
if (activeToolInfo (anInfo) && anInfo.myCommunicator)
anInfo.myCommunicator->UpdateContent();
}
@ -314,6 +360,90 @@ bool TInspector_Window::LoadPlugin (const TCollection_AsciiString& thePluginName
return aLoaded;
}
// =======================================================================
// function : GetPreferences
// purpose :
// =======================================================================
void TInspector_Window::GetPreferences (TInspectorAPI_PreferencesDataMap& theItem)
{
theItem.Clear();
theItem.Bind ("geometry", TreeModel_Tools::ToString (myMainWindow->saveGeometry()).toStdString().c_str());
}
// =======================================================================
// function : SetPreferences
// purpose :
// =======================================================================
void TInspector_Window::SetPreferences (const TInspectorAPI_PreferencesDataMap& theItem)
{
for (TInspectorAPI_IteratorOfPreferencesDataMap anItemIt (theItem); anItemIt.More(); anItemIt.Next())
{
if (anItemIt.Key().IsEqual ("geometry"))
myMainWindow->restoreGeometry (TreeModel_Tools::ToByteArray (anItemIt.Value().ToCString()));
}
}
// =======================================================================
// function : Dump
// purpose :
// =======================================================================
void TInspector_Window::Dump (Standard_OStream& theStream) const
{
TInspector_ToolInfo anInfo;
activeToolInfo(anInfo);
theStream << "Active Plugin: " << anInfo.myName << "\n";
theStream << "Temporary Directory: " << GetTemporaryDirectory() << "\n";
}
// =======================================================================
// function : OnStorePreferences
// purpose :
// =======================================================================
void TInspector_Window::OnStorePreferences()
{
Handle(TInspector_PluginParameters) aParameters = Handle(TInspector_PluginParameters)::DownCast (myParameters);
TInspectorAPI_PreferencesDataMap aPreferences;
GetPreferences (aPreferences);
aParameters->SetPreferences ("Desktop", aPreferences);
TInspector_ToolInfo anInfo;
for (int aToolId = 0, aSize = myToolNames.size(); aToolId < aSize; aToolId++)
{
anInfo = myToolNames[aToolId];
if (!anInfo.myCommunicator)
continue;
anInfo.myCommunicator->GetPreferences (aPreferences);
myParameters->SetPreferences (anInfo.myName, aPreferences);
}
// store preferences parameters into a file
aParameters->StorePreferences();
}
// =======================================================================
// function : OnRemovePreferences
// purpose :
// =======================================================================
void TInspector_Window::OnRemovePreferences()
{
Handle(TInspector_PluginParameters) aParameters = Handle(TInspector_PluginParameters)::DownCast (myParameters);
// remove preferences file
aParameters->RemovePreferences();
// restore plugins default state
TInspector_ToolInfo anInfo;
for (int aToolId = 0, aSize = myToolNames.size(); aToolId < aSize; aToolId++)
{
anInfo = myToolNames[aToolId];
if (!anInfo.myCommunicator)
continue;
anInfo.myCommunicator->SetPreferences (TInspectorAPI_PreferencesDataMap());
}
}
// =======================================================================
// function : onButtonClicked
// purpose :
@ -321,7 +451,38 @@ bool TInspector_Window::LoadPlugin (const TCollection_AsciiString& thePluginName
void TInspector_Window::onButtonClicked()
{
QPushButton* aButton = (QPushButton*)sender();
ActivateTool (TCollection_AsciiString ("TK") + aButton->text().toStdString().c_str());
TCollection_AsciiString aPluginName = aButton->text().toStdString().c_str();
TInspector_ToolInfo anInfo;
int aToolId;
if (!findPlugin (aPluginName, anInfo, aToolId))
aPluginName = TCollection_AsciiString ("TK") + aPluginName;
ActivateTool (aPluginName);
}
// =======================================================================
// function : onShowActionsMenu
// purpose :
// =======================================================================
void TInspector_Window::onShowActionsMenu()
{
myActionsWidget->menu()->clear();
TInspector_ToolInfo anInfo;
activeToolInfo(anInfo);
QMenu* aMenu = myActionsWidget->menu();
anInfo.myCommunicator->FillActionsMenu(aMenu);
aMenu->addSeparator();
aMenu->addAction (ViewControl_Tools::CreateAction (tr ("Store Preferences"),
SLOT (OnStorePreferences()), myMainWindow, this));
QAction* anAction = ViewControl_Tools::CreateAction (tr ("Remove Preferences"),
SLOT (OnRemovePreferences()), myMainWindow, this);
anAction->setToolTip ("Default state will be restored after restarting the application");
aMenu->addAction (anAction);
}
// =======================================================================
@ -332,17 +493,17 @@ void TInspector_Window::onCommuncatorNameChanged()
{
#if QT_VERSION >= 0x050000
TInspector_ToolInfo anInfo;
if (!ActiveToolInfo (anInfo))
if (!activeToolInfo (anInfo))
return;
myMainWindow->setWindowTitle (anInfo.myWidget->objectName());
#endif
}
// =======================================================================
// function : ActiveToolInfo
// function : activeToolInfo
// purpose :
// =======================================================================
bool TInspector_Window::ActiveToolInfo (TInspector_Window::TInspector_ToolInfo& theToolInfo) const
bool TInspector_Window::activeToolInfo (TInspector_Window::TInspector_ToolInfo& theToolInfo) const
{
QWidget* anActiveWidget = myToolsStack->currentWidget();
if (anActiveWidget == myEmptyWidget)
@ -360,10 +521,10 @@ bool TInspector_Window::ActiveToolInfo (TInspector_Window::TInspector_ToolInfo&
}
// =======================================================================
// function : FindPlugin
// function : findPlugin
// purpose :
// =======================================================================
bool TInspector_Window::FindPlugin (const TCollection_AsciiString& thePluginName, TInspector_ToolInfo& theToolInfo,
bool TInspector_Window::findPlugin (const TCollection_AsciiString& thePluginName, TInspector_ToolInfo& theToolInfo,
int& theToolId)
{
for (int aToolId = 0, aSize = myToolNames.size(); aToolId < aSize; aToolId++)
@ -379,3 +540,52 @@ bool TInspector_Window::FindPlugin (const TCollection_AsciiString& thePluginName
return false;
}
// =======================================================================
// function : applyPreferences
// purpose :
// =======================================================================
void TInspector_Window::applyPreferences()
{
TInspectorAPI_PreferencesDataMap aPreferences;
myParameters->GetPreferences ("Desktop", aPreferences);
SetPreferences (aPreferences);
}
// =======================================================================
// function : defaultTemporaryDirectory
// purpose :
// =======================================================================
TCollection_AsciiString TInspector_Window::defaultTemporaryDirectory() const
{
// main window creation
TCollection_AsciiString aTmpDir;
#ifdef _WIN32
OSD_Environment anEnvironment ("TEMP");
aTmpDir = anEnvironment.Value();
if (aTmpDir.IsEmpty() )
{
anEnvironment.SetName ("TMP");
aTmpDir = anEnvironment.Value();
if (aTmpDir.IsEmpty())
aTmpDir = "C:\\";
}
if (!aTmpDir.EndsWith ("\\"))
aTmpDir += "\\";
OSD_Path aTmpPath (aTmpDir);
OSD_Directory aTmpDirectory;
#else
OSD_Directory aTmpDirectory = OSD_Directory::BuildTemporary();
OSD_Path aTmpPath;
aTmpDirectory.Path (aTmpPath);
#endif
aTmpPath.DownTrek ("TInspector");
aTmpDirectory.SetPath (aTmpPath);
if (!aTmpDirectory.Exists())
aTmpDirectory.Build (OSD_Protection());
aTmpDirectory.Path (aTmpPath);
TCollection_AsciiString aTmpDirectoryName;
aTmpPath.SystemName (aTmpDirectoryName);
return aTmpDir;
}

View File

@ -29,11 +29,14 @@
#include <Standard_WarningsRestore.hxx>
class TInspectorAPI_Communicator;
class TInspector_Shortcut;
class QButtonGroup;
class QMainWindow;
class QHBoxLayout;
class QPushButton;
class QStackedWidget;
class QToolButton;
//! \class Inspector_Window
//! Control that contains:
@ -117,11 +120,42 @@ public:
//! \param theInfo an output parameter for plugin info
Standard_EXPORT bool LoadPlugin (const TCollection_AsciiString& thePluginName, TInspector_ToolInfo& theInfo);
//! Sets path to a directory for temporary plugin files. If parameter is empty, using default directory
//! \param thePath a path
void SetTemporaryDirectory (const TCollection_AsciiString& thePath)
{ myParameters->SetTemporaryDirectory (thePath.IsEmpty() ? myDefaultDirectory : thePath); }
//! Returns path to a directory for temporary plugin files
//! \return path
TCollection_AsciiString GetTemporaryDirectory() const { return myParameters->GetTemporaryDirectory(); }
//! Returns plugin preferences: dock widgets state, tree view columns.
//! \param theItem container of preference elements
Standard_EXPORT void GetPreferences (TInspectorAPI_PreferencesDataMap& theItem);
//! Applies plugin preferences
//! \param theItem container of preference elements
Standard_EXPORT void SetPreferences (const TInspectorAPI_PreferencesDataMap& theItem);
//! Puts in the stream information about communicator
//! \param theStream stream for output
Standard_EXPORT void Dump (Standard_OStream& theStream) const;
public slots:
//! Stores preferences (current state) of all plugins into a preferences file
Standard_EXPORT void OnStorePreferences();
//! Remove preferences file
Standard_EXPORT void OnRemovePreferences();
protected slots:
//! Activates plugin correspnded to the clicked button
void onButtonClicked();
//! Updates available actions by the active plugin
void onShowActionsMenu();
//! Updates the TInspector window title giving object name of plugin widget (available only in Qt5)
void onCommuncatorNameChanged();
@ -129,16 +163,23 @@ protected:
//! Activates plugin by the plugin info
//! \param theToolInfo an information about plugin
bool ActiveToolInfo (TInspector_ToolInfo& theToolInfo) const;
bool activeToolInfo (TInspector_ToolInfo& theToolInfo) const;
//! Returns true if there is plugin registered by the given name
//! \param thePluginName a name of the plugin
//! \param theToolInfo an output parameter for plugin information
//! \param theToolId an index in internal map
//! \return true if the plugin is found
bool FindPlugin (const TCollection_AsciiString& thePluginName, TInspector_ToolInfo& theToolInfo,
bool findPlugin (const TCollection_AsciiString& thePluginName, TInspector_ToolInfo& theToolInfo,
int& theToolId);
//! Applies desktop preferences to window
void applyPreferences();
//! Generate default temp directory by 'TEMP' or 'TMP' environment variables
//! \return generated path
TCollection_AsciiString defaultTemporaryDirectory() const;
private:
QWidget* myEmptyWidget; //!< widget that is active in tools stack while no one plugin is loaded
@ -147,8 +188,12 @@ private:
QWidget* myButtonWidget; //!< container of plugin buttons
QPushButton* myOpenButton; //!< button to open file for the active plugin
QHBoxLayout* myButtonLay; //!< layout of plugin buttons
QButtonGroup* myButtonGroup; //!< exclusive toggled button
QToolButton* myActionsWidget; //!< tool button for plugin actions
QList<TInspector_ToolInfo> myToolNames; //!< container of plugin names
Handle(TInspectorAPI_PluginParameters) myParameters; //!< plugins parameters container
TInspector_Shortcut* myShortcut; //!< listener of key events
TCollection_AsciiString myDefaultDirectory; //!< default directory
};
#endif

Binary file not shown.

After

Width:  |  Height:  |  Size: 204 B

View File

@ -2,3 +2,4 @@ TInspectorAPI_Communicator.cxx
TInspectorAPI_Communicator.hxx
TInspectorAPI_PluginParameters.cxx
TInspectorAPI_PluginParameters.hxx
TInspectorAPI_PreferencesDataMap.hxx

View File

@ -50,6 +50,16 @@ public:
//! \param theParent a parent class
Standard_EXPORT virtual void SetParent (void* theParent) = 0;
//! Provide container for actions available in inspector on general level
//! \param theMenu if Qt implementation, it is QMenu object
Standard_EXPORT virtual void FillActionsMenu (void* theMenu) { (void)theMenu; }
//! Returns plugin preferences, empty implementation by default
virtual void GetPreferences (TInspectorAPI_PreferencesDataMap&) {}
//! Applies plugin preferences, empty implementation by default
virtual void SetPreferences (const TInspectorAPI_PreferencesDataMap&) {}
//! Calls update of the plugin's content
Standard_EXPORT virtual void UpdateContent() = 0;

View File

@ -22,14 +22,6 @@ IMPLEMENT_STANDARD_RTTIEXT (TInspectorAPI_PluginParameters, Standard_Transient)
IMPLEMENT_STANDARD_RTTIEXT (TInspectorAPI_PluginParameters, Standard_Transient)
#endif
// =======================================================================
// function : Constructor
// purpose :
// =======================================================================
TInspectorAPI_PluginParameters::TInspectorAPI_PluginParameters()
{
}
// =======================================================================
// function : SetParameters
// purpose :
@ -163,3 +155,131 @@ Standard_Boolean TInspectorAPI_PluginParameters::GetSelectedObjects (const TColl
{
return mySelectedObjects.Find (thePluginName, theObjects);
}
// =======================================================================
// function : toString
// purpose :
// =======================================================================
TCollection_AsciiString toString (const TopLoc_Location& theLocation)
{
TCollection_AsciiString anInfo;
gp_Trsf aTrsf = theLocation.Transformation();
for (int aRowId = 1; aRowId <= 3; aRowId++)
{
if (!anInfo.IsEmpty())
anInfo += " ";
for (int aColumnId = 1; aColumnId <= 4; aColumnId++)
{
if (aColumnId > 1)
anInfo += ",";
anInfo += TCollection_AsciiString (aTrsf.Value (aRowId, aColumnId));
}
}
return anInfo;
}
// =======================================================================
// function : ParametersToString
// purpose :
// =======================================================================
TCollection_AsciiString TInspectorAPI_PluginParameters::ParametersToString (const TopoDS_Shape& theShape)
{
const TopLoc_Location& aLocation = theShape.Location();
TCollection_AsciiString aLocationStr = toString (aLocation);
TopAbs_Orientation anOrientation = theShape.Orientation();
Standard_SStream aSStream;
TopAbs::Print (anOrientation, aSStream);
return TCollection_AsciiString (aSStream.str().c_str()) + ":" + aLocationStr;
}
// =======================================================================
// function : fromString
// purpose :
// =======================================================================
TopLoc_Location fromString (const TCollection_AsciiString& theValue)
{
NCollection_Mat4<Standard_Real> aValues;
TCollection_AsciiString aCurrentString = theValue;
Standard_Integer aPosition = aCurrentString.Search (" ");
if (aPosition < 0)
return TopLoc_Location();
TCollection_AsciiString aTailString = aCurrentString.Split (aPosition);
Standard_Integer aRow = 0;
while (!aCurrentString.IsEmpty())
{
TCollection_AsciiString aValueString = aCurrentString;
aPosition = aValueString.Search (",");
if (aPosition < 0 )
break;
aCurrentString = aValueString.Split (aPosition);
Standard_Integer aColumn = 0;
while (!aValueString.IsEmpty())
{
aPosition = aCurrentString.Search (" ");
if (aPosition > 0)
aValueString.Split (aValueString.Length() - 1);
aValues.SetValue (aRow, aColumn, aValueString.RealValue());
aColumn++;
if (aCurrentString.IsEmpty())
break;
aValueString = aCurrentString;
aPosition = aValueString.Search (",");
if (aPosition < 0 )
{
aValueString = aCurrentString;
aCurrentString = TCollection_AsciiString();
}
else
aCurrentString = aValueString.Split (aPosition);
}
if (aTailString.IsEmpty())
break;
aCurrentString = aTailString;
aPosition = aCurrentString.Search (" ");
if (aPosition < 0 )
{
aCurrentString = aTailString;
aTailString = TCollection_AsciiString();
}
else
aTailString = aCurrentString.Split (aPosition);
aRow++;
}
//if (aValues.Rows() != 3 || aValues.Cols() != 4)
// return TopLoc_Location();
gp_Trsf aTrsf;
aTrsf.SetValues (aValues.GetValue (0, 0), aValues.GetValue (0, 1), aValues.GetValue (0, 2), aValues.GetValue (0, 3),
aValues.GetValue (1, 0), aValues.GetValue (1, 1), aValues.GetValue (1, 2), aValues.GetValue (1, 3),
aValues.GetValue (2, 0), aValues.GetValue (2, 1), aValues.GetValue (2, 2), aValues.GetValue (2, 3));
return TopLoc_Location (aTrsf);
}
// =======================================================================
// function : ParametersToShape
// purpose :
// =======================================================================
void TInspectorAPI_PluginParameters::ParametersToShape (const TCollection_AsciiString& theValue,
TopoDS_Shape& theShape)
{
int aSeparatorPos = theValue.Search (":");
TCollection_AsciiString anOrientationStr = theValue;
TCollection_AsciiString aLocationStr = anOrientationStr.Split (aSeparatorPos);
// orientation
if (anOrientationStr.Length() < 2)
return;
anOrientationStr.Split (anOrientationStr.Length() - 1);
TopAbs_Orientation anOrientation;
if (!TopAbs::ShapeOrientationFromString (anOrientationStr.ToCString(), anOrientation))
return;
// location
TopLoc_Location aLocation = fromString (aLocationStr);
theShape.Location (aLocation);
theShape.Orientation (anOrientation);
}

View File

@ -21,7 +21,9 @@
#include <Standard_Version.hxx>
#include <Standard_Transient.hxx>
#include <TCollection_AsciiString.hxx>
#include <TCollection_AsciiString.hxx>
#include <TopoDS_Shape.hxx>
#include <inspector/TInspectorAPI_PreferencesDataMap.hxx>
class TInspectorAPI_PluginParameters;
DEFINE_STANDARD_HANDLE (TInspectorAPI_PluginParameters, Standard_Transient)
@ -36,7 +38,7 @@ class TInspectorAPI_PluginParameters : public Standard_Transient
public:
//! Constructs the container.
Standard_EXPORT TInspectorAPI_PluginParameters();
Standard_EXPORT TInspectorAPI_PluginParameters() {}
//! Destructor
Standard_EXPORT virtual ~TInspectorAPI_PluginParameters() Standard_OVERRIDE {}
@ -81,8 +83,7 @@ public:
//! Returns parameters set for the given plugin
//! \param thePluginName a plugin name
//! \return container of objects
Standard_EXPORT const NCollection_List<Handle(Standard_Transient)>& Parameters (
const TCollection_AsciiString& thePluginName);
Standard_EXPORT const NCollection_List<Handle(Standard_Transient)>& Parameters (const TCollection_AsciiString& thePluginName);
//! Returns true if there are file names set for the given plugin
//! \param thePluginName a plugin name
@ -92,8 +93,7 @@ public:
//! Returns file names set for the given plugin
//! \param thePluginName a plugin name
//! \return container of names
Standard_EXPORT const NCollection_List<TCollection_AsciiString>& FileNames(
const TCollection_AsciiString& thePluginName);
Standard_EXPORT const NCollection_List<TCollection_AsciiString>& FileNames (const TCollection_AsciiString& thePluginName);
//! Returns true if there are file names set for the given plugin
//! \param thePluginName a plugin name
@ -112,6 +112,36 @@ public:
Standard_EXPORT Standard_Boolean GetSelectedObjects (const TCollection_AsciiString& thePluginName,
NCollection_List<Handle(Standard_Transient)>& theObjects);
//! Sets path to a directory for temporary plugin files
//! \param thePath a path
virtual void SetTemporaryDirectory (const TCollection_AsciiString& thePath) { myTemporaryDirectory = thePath; }
//! Returns path to a directory for temporary plugin files
//! \return path
TCollection_AsciiString GetTemporaryDirectory() const { return myTemporaryDirectory; }
//! Returns plugin preferences
//! \param thePluginName a plugin name
Standard_EXPORT virtual void GetPreferences (const TCollection_AsciiString& thePluginName,
TInspectorAPI_PreferencesDataMap& theItem) = 0;
//! Stores plugin preferences
//! \param thePluginName a plugin name
//! \theItem container of plugin preferences values in form: <name, value>
Standard_EXPORT virtual void SetPreferences (const TCollection_AsciiString& thePluginName,
const TInspectorAPI_PreferencesDataMap& theItem) = 0;
//! Converts a Shape parameters excepting TShape into a string value
//! \param theShape processed shape
//! \return string instance
Standard_EXPORT static TCollection_AsciiString ParametersToString (const TopoDS_Shape& theShape);
//! Converts a Shape parameters exceptin TShape into a string value
//! \param theValue parameters string value (without TShape information)
//! \param theShape processed shape
Standard_EXPORT static void ParametersToShape (const TCollection_AsciiString& theValue, TopoDS_Shape& theShape);
#if OCC_VERSION_HEX <= 0x060901
DEFINE_STANDARD_RTTI (TInspectorAPI_PluginParameters)
#else
@ -126,6 +156,8 @@ private:
NCollection_DataMap<TCollection_AsciiString, NCollection_List<TCollection_AsciiString> > mySelectedItemNames;
//! container of select objects
NCollection_DataMap<TCollection_AsciiString, NCollection_List<Handle(Standard_Transient)> > mySelectedObjects;
//! temporary directory for saving plugin preferences
TCollection_AsciiString myTemporaryDirectory;
};
#endif

View File

@ -0,0 +1,25 @@
// Created on: 2017-06-16
// Created by: Natalia ERMOLAEVA
// Copyright (c) 2017 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef TInspectorAPI_PreferencesDataMap_H
#define TInspectorAPI_PreferencesDataMap_H
#include <NCollection_DataMap.hxx>
#include <TCollection_AsciiString.hxx>
typedef NCollection_DataMap<TCollection_AsciiString, TCollection_AsciiString> TInspectorAPI_PreferencesDataMap;
typedef NCollection_DataMap<TCollection_AsciiString, TCollection_AsciiString>::Iterator TInspectorAPI_IteratorOfPreferencesDataMap;
#endif

View File

@ -1,3 +1,4 @@
TKTInspectorAPI
TKernel
TKTInspectorAPI
TKTreeModel
CSF_QT

View File

@ -1,2 +1,4 @@
TKG3d
TKernel
TKLCAF
TKMath

View File

@ -1 +1,2 @@
TreeModel
ViewControl

View File

@ -13,7 +13,6 @@
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <inspector/ToolsDraw.hxx>
#include <inspector/ToolsDraw.hxx>
#include <AIS_InteractiveContext.hxx>
@ -26,11 +25,13 @@
#include <NCollection_DataMap.hxx>
#include <Standard_Stream.hxx>
#include <TDocStd_Application.hxx>
#include <inspector/TInspector_Communicator.hxx>
#include <TopoDS_Shape.hxx>
#include <ViewerTest.hxx>
#include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
#include <inspector/TInspectorAPI_PluginParameters.hxx>
#include <inspector/TInspector_Communicator.hxx>
#if ! defined(_WIN32)
extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
#else
@ -84,7 +85,7 @@ void getArgumentPlugins (Standard_Integer theArgsNb, const char** theArgs, Stand
// function : tinspector
// purpose :
// =======================================================================
static int tinspector (Draw_Interpretor&/* di*/, Standard_Integer theArgsNb, const char** theArgs)
static int tinspector (Draw_Interpretor& di, Standard_Integer theArgsNb, const char** theArgs)
{
if (theArgsNb < 1)
{
@ -99,7 +100,10 @@ static int tinspector (Draw_Interpretor&/* di*/, Standard_Integer theArgsNb, con
TCollection_AsciiString aPluginNameToActivate;
Standard_Boolean aNeedToUpdateContent = Standard_False,
aNeedToHideInspector = Standard_False,
aNeedToShowInspector = Standard_False;
aNeedToShowInspector = Standard_False,
aNeedToPrintState = Standard_False,
aNeedDirectory = Standard_False;
TCollection_AsciiString aTemporaryDirectory;
NCollection_List<Handle(Standard_Transient)> aDefaultParameters;
TCollection_AsciiString aDefaultOpenFileParameter;
@ -146,8 +150,12 @@ static int tinspector (Draw_Interpretor&/* di*/, Standard_Integer theArgsNb, con
}
NCollection_List<TCollection_AsciiString> anArgPlugins;
getArgumentPlugins (theArgsNb, theArgs, anIt, anArgPlugins);
if (anArgPlugins.IsEmpty())
{
aDefaultParameters.Append (aShape.TShape());
anItemNamesToSelect.Append (TInspectorAPI_PluginParameters::ParametersToString (aShape));
}
else
{
for (NCollection_List<TCollection_AsciiString>::Iterator anArgIt (anArgPlugins);
@ -156,6 +164,7 @@ static int tinspector (Draw_Interpretor&/* di*/, Standard_Integer theArgsNb, con
NCollection_List<Handle(Standard_Transient)> aPluginParameters;
aParameters.Find (anArgIt.Value(), aPluginParameters);
aPluginParameters.Append (aShape.TShape());
anItemNamesToSelect.Append (TInspectorAPI_PluginParameters::ParametersToString (aShape));
aParameters.Bind (anArgIt.Value(), aPluginParameters);
}
}
@ -186,6 +195,22 @@ static int tinspector (Draw_Interpretor&/* di*/, Standard_Integer theArgsNb, con
}
}
}
else if (aParam.IsEqual ("-directory")) // [-directory path]"
{
anIt++;
if (anIt == theArgsNb)
{
cout << "Empty argument of '" << aParam << "'.\n";
return 1;
}
aNeedDirectory = true;
aParam = theArgs[anIt];
aTemporaryDirectory = aParam.IsEqual ("default") ? "" : aParam;
}
else if (aParam.IsEqual ("-state")) // [-state]
{
aNeedToPrintState = Standard_True;
}
else if (aParam.IsEqual ("-update")) // [-update]
{
aNeedToUpdateContent = Standard_True;
@ -203,6 +228,7 @@ static int tinspector (Draw_Interpretor&/* di*/, Standard_Integer theArgsNb, con
if (!aShape.IsNull())
{
anObjectsToSelect.Append (aShape.TShape());
anItemNamesToSelect.Append (TInspectorAPI_PluginParameters::ParametersToString (aShape));
}
// search prsentations with given name
if (GetMapOfAIS().IsBound2 (theArgs[anIt]))
@ -313,6 +339,9 @@ static int tinspector (Draw_Interpretor&/* di*/, Standard_Integer theArgsNb, con
if (!anItemNamesToSelect.IsEmpty())
MyCommunicator->SetSelected (anItemNamesToSelect);
if (aNeedDirectory)
MyCommunicator->SetTemporaryDirectory (aTemporaryDirectory);
if (aNeedToUpdateContent)
MyCommunicator->UpdateContent();
@ -322,6 +351,13 @@ static int tinspector (Draw_Interpretor&/* di*/, Standard_Integer theArgsNb, con
if (aNeedToHideInspector)
MyCommunicator->SetVisible (false);
if (aNeedToPrintState)
{
Standard_SStream aSStream;
MyCommunicator->Dump (aSStream);
di << aSStream << "\n";
}
return 0;
}
@ -342,6 +378,8 @@ void ToolsDraw::Commands(Draw_Interpretor& theCommands)
"\n\t\t: [-update]"
"\n\t\t: [-select {object | name1 ... [nameN]}]"
"\n\t\t: [-show {0|1} = 1]"
"\n\t\t: [-directory path|<default>]"
"\n\t\t: [-state]"
"\n\t\t: Starts tool of inspection."
"\n\t\t: Options:"
"\n\t\t: -plugins enters plugins that should be added in the inspector."
@ -360,8 +398,11 @@ void ToolsDraw::Commands(Draw_Interpretor& theCommands)
"\n\t\t: ShapeView: 'object' is an instance of TopoDS_Shape TShape,"
"\n\t\t: DFBrowser: 'name' is an entry of TDF_Label and name2(optionaly) for TDF_Attribute type name,"
"\n\t\t: VInspector: 'object' is an instance of AIS_InteractiveObject;"
"\n\t\t: -show sets Inspector view visible or hidden. The first call of this command will show it.",
"\n\t\t: -show sets Inspector view visible or hidden. The first call of this command will show it."
"\n\t\t: -directory sets Inspector temporary directory. Preferences file is stored there."
"\n\t\t: -state print some current information about inspector, like name of active plugin, temporary director.",
__FILE__, tinspector, group);
}
// =======================================================================

View File

@ -1,7 +1,15 @@
TreeModel.hxx
TreeModel.qrc
TreeModel_ColumnType.hxx
TreeModel_ContextMenu.cxx
TreeModel_ContextMenu.hxx
TreeModel_HeaderSection.hxx
TreeModel_ItemBase.cxx
TreeModel_ItemBase.hxx
TreeModel_ItemRole.hxx
TreeModel_MessageDialog.cxx
TreeModel_MessageDialog.hxx
TreeModel_ModelBase.cxx
TreeModel_ModelBase.hxx
TreeModel_Tools.cxx
TreeModel_Tools.hxx
TreeModel_VisibilityState.cxx
TreeModel_VisibilityState.hxx

View File

@ -0,0 +1,33 @@
// Created on: 2017-06-16
// Created by: Natalia ERMOLAEVA
// Copyright (c) 2017 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef TREEMODEL_H
#define TREEMODEL_H
#ifdef __TreeModel_DLL
#ifdef _WIN32
#define TREEMODEL_EXPORT __declspec(dllexport)
#else
#define TREEMODEL_EXPORT
#endif
#else
#ifdef _WIN32
#define TREEMODEL_EXPORT __declspec(dllimport)
#else
#define TREEMODEL_EXPORT
#endif
#endif
#endif

View File

@ -0,0 +1,6 @@
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file>icons/item_invisible.png</file>
<file>icons/item_visible.png</file>
</qresource>
</RCC>

View File

@ -0,0 +1,30 @@
// Created on: 2017-06-16
// Created by: Natalia ERMOLAEVA
// Copyright (c) 2017 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef TreeModel_ColumnType_H
#define TreeModel_ColumnType_H
#include <Standard_WarningsDisable.hxx>
#include <Qt>
#include <Standard_WarningsRestore.hxx>
//! Sets custom item role of Tree view wmodel
enum TreeModel_ColumnType
{
TreeModel_ColumnType_Name = 0, //! name column
TreeModel_ColumnType_Visibility //! visibility state column
};
#endif

View File

@ -0,0 +1,82 @@
// Created on: 2017-06-16
// Created by: Natalia ERMOLAEVA
// Copyright (c) 2017 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <inspector/TreeModel_ContextMenu.hxx>
#include <inspector/TreeModel_ModelBase.hxx>
#include <inspector/TreeModel_Tools.hxx>
#include <inspector/ViewControl_Tools.hxx>
#include <Standard_WarningsDisable.hxx>
#include <QHeaderView>
#include <QMenu>
#include <QTreeView>
#include <Standard_WarningsRestore.hxx>
// =======================================================================
// function : Constructor
// purpose :
// =======================================================================
TreeModel_ContextMenu::TreeModel_ContextMenu (QTreeView* theTreeView)
: QObject (theTreeView), myTreeView (theTreeView)
{
myTreeView->header()->setContextMenuPolicy (Qt::CustomContextMenu);
#if QT_VERSION >= 0x050000
myTreeView->header()->setSectionsClickable (true);
#endif
myTreeView->header()->setHighlightSections (true);
connect (myTreeView->header(), SIGNAL (customContextMenuRequested (const QPoint&)),
this, SLOT (onTreeViewHeaderContextMenuRequested (const QPoint&)));
}
// =======================================================================
// function : onTreeViewHeaderContextMenuRequested
// purpose :
// =======================================================================
void TreeModel_ContextMenu::onTreeViewHeaderContextMenuRequested (const QPoint& thePosition)
{
TreeModel_ModelBase* aModel = dynamic_cast<TreeModel_ModelBase*> (myTreeView->model());
if (!aModel)
return;
QMenu* aMenu = new QMenu (myTreeView);
int aNbSections = aModel->columnCount();
for (int aColumnId = 0; aColumnId < aNbSections; aColumnId++)
{
QAction* anAction = ViewControl_Tools::CreateAction (aModel->GetHeaderItem (aColumnId).GetName(),
SLOT (onColumnVisibilityChanged()), myTreeView, this);
anAction->setCheckable (true);
anAction->setChecked (!myTreeView->isColumnHidden (aColumnId));
anAction->setData (aColumnId);
aMenu->addAction (anAction);
}
if (aMenu->actions().isEmpty())
return;
QPoint aPoint = myTreeView->mapToGlobal (thePosition);
aMenu->exec (aPoint);
}
// =======================================================================
// function : onColumnVisibilityChanged
// purpose :
// =======================================================================
void TreeModel_ContextMenu::onColumnVisibilityChanged()
{
QAction* aClickedAction = (QAction*)sender();
myTreeView->setColumnHidden(aClickedAction->data().toInt(), !aClickedAction->isChecked());
}

View File

@ -0,0 +1,53 @@
// Created on: 2017-06-16
// Created by: Natalia ERMOLAEVA
// Copyright (c) 2017 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef TreeModel_ContextMenu_H
#define TreeModel_ContextMenu_H
#include <Standard.hxx>
#include <Standard_Macro.hxx>
#include <Standard_WarningsDisable.hxx>
#include <QObject>
#include <QPoint>
#include <Standard_WarningsRestore.hxx>
class QTreeView;
//! \class TreeModel_ContextMenu
//! \brief Creates actions to show/hide tree view columns
class TreeModel_ContextMenu : public QObject
{
Q_OBJECT
public:
//! Constructor
Standard_EXPORT TreeModel_ContextMenu (QTreeView* theTreeView);
//! Destructor
~TreeModel_ContextMenu() {}
protected slots:
//! Shows context menu for tree view header. It contains actions to change columns visibility.
//! \param thePosition a clicked point
void onTreeViewHeaderContextMenuRequested (const QPoint& thePosition);
//! Changes clicked column visiblity
void onColumnVisibilityChanged();
private:
QTreeView* myTreeView;
};
#endif

View File

@ -0,0 +1,78 @@
// Created on: 2017-06-16
// Created by: Natalia ERMOLAEVA
// Copyright (c) 2017 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef TreeModel_HeaderSection_H
#define TreeModel_HeaderSection_H
#include <Standard.hxx>
#include <Standard_Macro.hxx>
#include <inspector/TreeModel_Tools.hxx>
#include <Standard_WarningsDisable.hxx>
#include <QString>
#include <Standard_WarningsRestore.hxx>
//! \class TreeModel_HeaderSection
//! \brief Container of tree view header sections, like width, visibility, text value
class TreeModel_HeaderSection
{
public:
//! Constructor
TreeModel_HeaderSection() : myName(), myWidth (-1), myIsHidden (false), myIsItalic (false) {}
//! Constructor
TreeModel_HeaderSection (const QString& theName, const int theWidth = -1, const bool theIsHidden = false,
const bool theIsItalic = false)
: myName (theName), myWidth (theWidth), myIsHidden (theIsHidden), myIsItalic (theIsItalic) {}
//! Destructor
~TreeModel_HeaderSection() {}
//! Sets text value
//! \theName text value
void SetName (const QString& theName) { myName = theName; }
//! Returns text value
QString GetName() const { return myName; }
//! Sets section width
//! \param theValue width value
void SetWidth (const int theWidth) { myWidth = theWidth; }
//! Returns section width
int GetWidth (const bool isComputeDefault = true) const
{ return (myWidth ==-1 && isComputeDefault) ? TreeModel_Tools::GetTextWidth (GetName(), 0) : myWidth; }
//! Sets section width
void SetIsHidden (bool isHidden) { myIsHidden = isHidden; }
//! Returns if the section is visiblt
bool IsHidden() const { return myIsHidden; }
//! Sets section width
void SetIsItalic (bool isItalic) { myIsItalic = isItalic; }
//! Returns if the section is visiblt
bool IsItalic() const { return myIsItalic; }
private:
QString myName; //! text value
int myWidth; //! section width
bool myIsHidden; //! visibility
bool myIsItalic; //! italic
};
#endif

View File

@ -14,6 +14,7 @@
// commercial license or contractual agreement.
#include <inspector/TreeModel_ItemBase.hxx>
#include <inspector/TreeModel_ItemRole.hxx>
#include <Standard_WarningsDisable.hxx>
@ -45,8 +46,19 @@ void TreeModel_ItemBase::Reset()
anItem->Reset();
}
m_bInitialized = false;
mycachedValues.clear();
myCachedValues.clear();
}
// =======================================================================
// function : Reset
// purpose :
// =======================================================================
void TreeModel_ItemBase::Reset (int theRole)
{
if (!myCachedValues.contains (theRole))
return;
myCachedValues.remove (theRole);
}
// =======================================================================
@ -84,11 +96,11 @@ const TreeModel_ItemBasePtr TreeModel_ItemBase::currentItem()
// =======================================================================
QVariant TreeModel_ItemBase::cachedValue (const int theItemRole) const
{
if (mycachedValues.contains (theItemRole))
return mycachedValues[theItemRole];
if (myCachedValues.contains (theItemRole))
return myCachedValues[theItemRole];
const_cast<TreeModel_ItemBase*>(this)->mycachedValues.insert (theItemRole,
const_cast<TreeModel_ItemBase*>(this)->myCachedValues.insert (theItemRole,
theItemRole == TreeModel_ItemRole_RowCountRole ? QVariant (initRowCount()) : initValue (theItemRole));
return mycachedValues.contains (theItemRole) ? mycachedValues[theItemRole] : QVariant();
return myCachedValues.contains (theItemRole) ? myCachedValues[theItemRole] : QVariant();
}

View File

@ -87,6 +87,10 @@ public:
//! If the item has internal values, there should be reseted here.
Standard_EXPORT virtual void Reset();
//! Resets the item cached value for the parameter role.
//! \param theRole an item role
Standard_EXPORT virtual void Reset(int theRole);
//! Gets the parent of the item, or TreeModel_ItemBasePtr() if it has no parent.
//! \return pointer to the item
TreeModel_ItemBasePtr Parent() const { return m_pParent; };
@ -108,6 +112,11 @@ public:
//! \return the child item or TreeModel_ItemBasePtr() if it does not exist
Standard_EXPORT TreeModel_ItemBasePtr Child (int theRow, int theColumn, const bool isToCreate = true);
//! Sets a custom value for the role in an internal cache
//! \param theValue a value
//! \param theRole a value role
void SetCustomData(const QVariant theValue, int theRole) { myCachedValues.insert (theRole, theValue); }
//! Returns the data stored under the given role for the current item
//! \param theIndex the item model index
//! \param theRole the item model role
@ -154,7 +163,7 @@ private:
typedef QHash< QPair<int, int>, TreeModel_ItemBasePtr > PositionToItemHash;
PositionToItemHash m_ChildItems; //!< the hash of item children
QMap<int, QVariant> mycachedValues; //!< cached values, should be cleared by reset
QMap<int, QVariant> myCachedValues; //!< cached values, should be cleared by reset
TreeModel_ItemBasePtr m_pParent; //!< the parent item
int m_iRow; //!< the item row position in the parent item
int m_iColumn; //!< the item column position in the parent item

View File

@ -16,13 +16,20 @@
#include <inspector/TreeModel_ModelBase.hxx>
#include <inspector/TreeModel_ItemBase.hxx>
#include <inspector/TreeModel_Tools.hxx>
#include <inspector/TreeModel_VisibilityState.hxx>
#include <Standard_WarningsDisable.hxx>
#include <QIcon>
#include <Standard_WarningsRestore.hxx>
// =======================================================================
// function : Constructor
// purpose :
// =======================================================================
TreeModel_ModelBase::TreeModel_ModelBase (QObject* theParent)
: QAbstractItemModel (theParent), m_pRootItem (0)
: QAbstractItemModel (theParent), m_pRootItem (0), m_pUseVisibilityColumn (false),
myVisibilityState (0)
{
}
@ -43,7 +50,11 @@ TreeModel_ItemBasePtr TreeModel_ModelBase::GetItemByIndex (const QModelIndex& th
void TreeModel_ModelBase::Reset()
{
for (int aColId = 0, aNbColumns = columnCount(); aColId < aNbColumns; aColId++)
RootItem (aColId)->Reset();
{
TreeModel_ItemBasePtr aRootItem = RootItem (aColId);
if (aRootItem)
aRootItem->Reset();
}
}
// =======================================================================
@ -78,6 +89,27 @@ QVariant TreeModel_ModelBase::data (const QModelIndex& theIndex, int theRole) co
if (!theIndex.isValid())
return QVariant ("undefined");
if (IsUseVisibilityColumn() && theIndex.column() == TreeModel_ColumnType_Visibility)
{
if (theRole != Qt::DecorationRole)
return QVariant();
TreeModel_ItemBasePtr anItem = GetItemByIndex (theIndex);
if (!anItem->data (theIndex, theRole).isNull()) // value is already in cache
return anItem->data (theIndex, theRole);
if (!anItem->IsInitialized())
anItem->Init();
if (!myVisibilityState || !myVisibilityState->CanBeVisible (theIndex))
return QVariant();
QVariant aValue = QIcon (myVisibilityState->IsVisible (theIndex) ? ":/icons/item_visible.png"
: ":/icons/item_invisible.png");
anItem->SetCustomData (aValue, theRole);
return aValue;
}
TreeModel_ItemBasePtr anItem = GetItemByIndex (theIndex);
return anItem->data (theIndex, theRole);
}
@ -111,6 +143,21 @@ Qt::ItemFlags TreeModel_ModelBase::flags (const QModelIndex& theIndex) const
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
}
// =======================================================================
// function : headerData
// purpose :
// =======================================================================
QVariant TreeModel_ModelBase::headerData (int theSection, Qt::Orientation theOrientation, int theRole) const
{
if (theOrientation != Qt::Horizontal || theRole != Qt::DisplayRole)
return QVariant();
if (IsUseVisibilityColumn() && theSection == TreeModel_ColumnType_Visibility)
return QVariant();
return GetHeaderItem (theSection).GetName();
}
// =======================================================================
// function : rowCount
// purpose :
@ -131,7 +178,7 @@ int TreeModel_ModelBase::rowCount (const QModelIndex& theParent) const
}
// =======================================================================
// function : emitLayoutChanged
// function : EmitLayoutChanged
// purpose :
// =======================================================================
void TreeModel_ModelBase::EmitLayoutChanged()
@ -139,6 +186,44 @@ void TreeModel_ModelBase::EmitLayoutChanged()
emit layoutChanged();
}
// =======================================================================
// function : EmitLayoutChanged
// purpose :
// =======================================================================
void TreeModel_ModelBase::EmitDataChanged (const QModelIndex& theTopLeft, const QModelIndex& theBottomRight,
const QVector<int>& theRoles,
const bool isResetItem)
{
TreeModel_ItemBasePtr anItemBase = TreeModel_ModelBase::GetItemByIndex (theTopLeft);
if (anItemBase && isResetItem)
anItemBase->Reset();
#if QT_VERSION < 0x050000
(void)theRoles;
emit dataChanged (theTopLeft, theBottomRight);
#else
emit dataChanged (theTopLeft, theBottomRight, theRoles);
#endif
}
// =======================================================================
// function : SingleSelected
// purpose :
// =======================================================================
QModelIndex TreeModel_ModelBase::SingleSelected (const QModelIndexList& theIndices, const int theCellId,
const Qt::Orientation theOrientation)
{
QModelIndexList aFirstColumnSelectedIndices;
for (QModelIndexList::const_iterator anIndicesIt = theIndices.begin(); anIndicesIt != theIndices.end(); anIndicesIt++)
{
QModelIndex anIndex = *anIndicesIt;
if ((theOrientation == Qt::Horizontal && anIndex.column() == theCellId) ||
(theOrientation == Qt::Vertical && anIndex.row() == theCellId))
aFirstColumnSelectedIndices.append (anIndex);
}
return aFirstColumnSelectedIndices.size() == 1 ? aFirstColumnSelectedIndices.first() : QModelIndex();
}
// =======================================================================
// function : getIndexValue
// purpose :

View File

@ -18,14 +18,19 @@
#include <Standard.hxx>
#include <inspector/TreeModel_ItemBase.hxx>
#include <inspector/TreeModel_HeaderSection.hxx>
#include <Standard_WarningsDisable.hxx>
#include <QAbstractItemModel>
#include <QExplicitlySharedDataPointer>
#include <QMap>
#include <QModelIndex>
#include <QVariant>
#include <QVector>
#include <Standard_WarningsRestore.hxx>
class TreeModel_VisibilityState;
//! \class TreeModel_ModelBase
//! \brief Implementation of the tree item based model of QAbstractItemModel.
//! The TreeModel_ModelBase class defines the abstract model realization throught the base item architecture.
@ -59,6 +64,26 @@ public:
//! Emits the layoutChanged signal from outside of this class
Standard_EXPORT void EmitLayoutChanged();
//! Emits the dataChanged signal from outside of this class
Standard_EXPORT void EmitDataChanged (const QModelIndex& theTopLeft, const QModelIndex& theBottomRight,
const QVector<int>& theRoles = QVector<int>(), const bool isResetItem = true);
//! Sets state whether visibility column (0) is used in the model
//! \param theState state
void SetUseVisibilityColumn (const bool theState) { m_pUseVisibilityColumn = theState; }
//! Returns state whether visibility column (0) is used in the model
//! \param theState state
bool IsUseVisibilityColumn() const { return m_pUseVisibilityColumn; }
//!< Fills visibility state checker
//!< \param theController the checker interface
void SetVisibilityState (TreeModel_VisibilityState* theController) { myVisibilityState = theController; }
//!< Returns visibility state checker
//!< \return the checker interface
TreeModel_VisibilityState* GetVisibilityState () const { return myVisibilityState; }
//! Returns the index of the item in the model specified by the given row, column and parent index.
//! Saves an internal pointer at the createIndex. This pointer is a shared pointer to the class,
//! that realizes a base item interface. If the parent is invalid, a root item is used, otherwise a new item
@ -92,8 +117,7 @@ public:
//! \param theRole a data role
//! \return the header data
Standard_EXPORT virtual QVariant headerData (int theSection, Qt::Orientation theOrientation,
int theRole = Qt::DisplayRole) const Standard_OVERRIDE
{ (void)theSection, (void)theOrientation; (void)theRole; return QVariant(); }
int theRole = Qt::DisplayRole) const Standard_OVERRIDE;
//! Returns the number of rows under the given parent. When the parent is valid it means that rowCount is returning
//! the number of children of parent.
@ -101,13 +125,40 @@ public:
//! \return the number of rows
Standard_EXPORT virtual int rowCount (const QModelIndex& theParent = QModelIndex()) const Standard_OVERRIDE;
//! Returns the number of columns for the children of the given parent.
//! \param theParent a parent model index
//! \return the number of columns
//! Returns whether the column is hidden by default
//! \param theColumnId a column index
//! \return header section values container
TreeModel_HeaderSection GetHeaderItem (const int theColumnId) const { return myHeaderValues[theColumnId]; }
//! Set header properties item.
//! \param theColumnId a column index
//! \param theSection a section value
void SetHeaderItem (const int theColumnId, const TreeModel_HeaderSection& theSection)
{ myHeaderValues[theColumnId] = theSection; createRootItem (theColumnId); }
//! Returns count of columns in the model
//! \param theParent an index of the parent item
//! \return integer value
virtual int columnCount (const QModelIndex& theParent = QModelIndex()) const Standard_OVERRIDE
{ (void)theParent; return 1; }
{ (void)theParent; return myHeaderValues.size(); }
//! Returns default value of the visibility column
//! \return integer value
static int ColumnVisibilityWidth() { return 20; }
//! Returns single selected item in the cell of given orientation. If the orientation is Horizontal,
//! in the cell id colum, one row should be selected.
//! \param theIndices a container of selected indices
//! \param theCellId column index if orientation is horizontal, row index otherwise
//! \param theOrientation an orientation to apply the cell index
//! \return model index from the list
Standard_EXPORT static QModelIndex SingleSelected (const QModelIndexList& theIndices, const int theCellId,
const Qt::Orientation theOrientation = Qt::Horizontal);
protected:
//! Creates root item
//! \param theColumnId index of a column
virtual void createRootItem (const int theColumnId) = 0;
//! Converts the item shared pointer to void* type
//! \param theItem
@ -117,7 +168,11 @@ protected:
protected:
TreeModel_ItemBasePtr m_pRootItem; //!< the model root item. It should be created in the
QMap<int, TreeModel_HeaderSection> myHeaderValues; //!< header values
//!< model subclass. The model is fulfilled by this item content
bool m_pUseVisibilityColumn; //!< the state whether column=0 is reserved for Visibility state
TreeModel_VisibilityState* myVisibilityState; //!< the interface of item visibility
};
#endif

View File

@ -0,0 +1,213 @@
// Created on: 2017-06-16
// Created by: Natalia ERMOLAEVA
// Copyright (c) 2017 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <inspector/TreeModel_Tools.hxx>
#include <inspector/TreeModel_ModelBase.hxx>
#include <inspector/TreeModel_ColumnType.hxx>
#include <inspector/TreeModel_VisibilityState.hxx>
#include <Standard_WarningsDisable.hxx>
#include <QAction>
#include <QApplication>
#include <QFont>
#include <QFontMetrics>
#include <QHeaderView>
#include <QObject>
#include <QRegExp>
#include <QStringList>
#include <QStyle>
#include <QTreeView>
#include <Standard_WarningsRestore.hxx>
const int INFO_LENGHT = 60;
// =======================================================================
// function : ToString
// purpose :
// =======================================================================
QString TreeModel_Tools::ToString (const QByteArray& theValue)
{
char aBuffer[8];
QStringList aBytesList;
for (int aByteId = 0; aByteId < theValue.size(); aByteId++)
{
::sprintf (aBuffer, "#%02X", (unsigned char)theValue.at (aByteId));
aBytesList.append (QString (aBuffer));
}
return QString ("@ByteArray[%1]").arg (aBytesList.join (" "));
}
// =======================================================================
// function : ToByteArray
// purpose :
// =======================================================================
QByteArray TreeModel_Tools::ToByteArray (const QString& theValue)
{
QByteArray aStateArray;
if (!theValue.startsWith ("@ByteArray[") || !theValue.endsWith (']'))
return aStateArray;
QString aValue = theValue.mid (11, theValue.size() - 12);
QStringList lst = aValue.split (QRegExp ("[\\s|,]"), QString::SkipEmptyParts);
for (QStringList::ConstIterator aByteId = lst.begin(); aByteId != lst.end(); ++aByteId)
{
int aBase = 10;
QString aString = *aByteId;
if (aString.startsWith ("#"))
{
aBase = 16;
aString = aString.mid (1);
}
bool isOk = false;
int aNum = aString.toInt (&isOk, aBase);
if (!isOk || aNum < 0 || aNum > 255)
continue;
aStateArray.append ((char)aNum);
}
return aStateArray;
}
// =======================================================================
// function : SaveState
// purpose :
// =======================================================================
void TreeModel_Tools::SaveState (QTreeView* theTreeView, QMap<QString, QString>& theItems,
const QString& thePrefix)
{
QStringList aColumnWidths, aHiddenColumns;
for (int aColumnId = 0; aColumnId < theTreeView->model()->columnCount(); aColumnId++)
{
if (theTreeView->isColumnHidden (aColumnId))
{
aHiddenColumns.append (QString::number (aColumnId));
aColumnWidths.append (QString());
}
else
aColumnWidths.append (QString::number (theTreeView->columnWidth (aColumnId)));
}
theItems[thePrefix + "columns_width"] = aColumnWidths.join (",");
theItems[thePrefix + "columns_hidden"] = aHiddenColumns.join (",");
}
// =======================================================================
// function : RestoreState
// purpose :
// =======================================================================
bool TreeModel_Tools::RestoreState (QTreeView* theTreeView, const QString& theKey, const QString& theValue,
const QString& thePrefix)
{
if (theKey == thePrefix + "columns_width")
{
QStringList aValues = theValue.split (",");
for (int aColumnId = 0; aColumnId < theTreeView->model()->columnCount() && aColumnId < aValues.size(); aColumnId++)
{
bool isOk;
int aWidth = aValues.at (aColumnId).toInt (&isOk);
if (isOk && !theTreeView->isColumnHidden (aColumnId)) // do not resize hidden columnsa
theTreeView->setColumnWidth (aColumnId, aWidth);
}
}
else if (theKey == thePrefix + "columns_hidden")
{
int aColumnSize = theTreeView->model()->columnCount();
QStringList aValues = theValue.split (",", QString::SkipEmptyParts);
QList<int> aColumnIds;
for (int aValueId = 0; aValueId < aValues.size(); aValueId++)
{
if (aValueId < aColumnSize)
aColumnIds.append (aValues.at (aValueId).toInt());
}
for (int aColumnId = 0; aColumnId < aColumnSize; aColumnId++)
{
theTreeView->setColumnHidden (aColumnId, aColumnIds.contains(aColumnId) == true);
}
}
else
return false;
return true;
}
// =======================================================================
// function : SetDefaultHeaderSections
// purpose :
// =======================================================================
void TreeModel_Tools::SetDefaultHeaderSections(QTreeView* theTreeView)
{
TreeModel_ModelBase* aTreeModel = dynamic_cast<TreeModel_ModelBase*> (theTreeView->model());
for (int aColumnId = 0, aNbColumns = aTreeModel->columnCount(); aColumnId < aNbColumns; aColumnId++)
{
TreeModel_HeaderSection aSection = aTreeModel->GetHeaderItem (aColumnId);
theTreeView->setColumnWidth (aColumnId, aSection.GetWidth());
theTreeView->setColumnHidden (aColumnId, aSection.IsHidden());
}
}
// =======================================================================
// function : UseVisibilityColumn
// purpose :
// =======================================================================
void TreeModel_Tools::UseVisibilityColumn (QTreeView* theTreeView, const bool theActive)
{
QHeaderView* aHeader = theTreeView->header();
#if QT_VERSION < 0x050000
aHeader->setResizeMode (TreeModel_ColumnType_Visibility, QHeaderView::Fixed);
#else
aHeader->setSectionResizeMode (TreeModel_ColumnType_Visibility, QHeaderView::Fixed);
#endif
aHeader->moveSection (TreeModel_ColumnType_Name, TreeModel_ColumnType_Visibility);
TreeModel_ModelBase* aModel = dynamic_cast<TreeModel_ModelBase*> (theTreeView->model());
aModel->SetHeaderItem (TreeModel_ColumnType_Visibility,
TreeModel_HeaderSection ("Visibility", TreeModel_ModelBase::ColumnVisibilityWidth()));
TreeModel_VisibilityState* aVisibilityState = aModel->GetVisibilityState ();
aModel->SetUseVisibilityColumn (true);
if (theActive && aVisibilityState)
QObject::connect (theTreeView, SIGNAL (clicked (const QModelIndex&)),
aVisibilityState, SLOT (OnClicked(const QModelIndex&)));
}
// =======================================================================
// function : GetTextWidth
// purpose :
// =======================================================================
int TreeModel_Tools::GetTextWidth (const QString& theText, QObject*)
{
// TODO: find margins like QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin, 0, (QWidget*)theParent);
int aTextMargin = 10;
QFontMetrics aFontMetrics (QApplication::font());
QRect aBoundingRect = aFontMetrics.boundingRect (theText);
return qMax (aBoundingRect.width(), aFontMetrics.width (theText)) + aTextMargin * 2;
}
// =======================================================================
// function : CutString
// purpose :
// =======================================================================
QString TreeModel_Tools::CutString (const QString& theText, const int theWidth, const QString& theTail)
{
if (theText.isEmpty())
return theText;
int aLength = theWidth < 0 ? INFO_LENGHT : theWidth - 3;
int anIndex = theText.indexOf ('\n');
if (anIndex > 0 && anIndex < aLength)
aLength = anIndex;
return aLength < theText.length() ? theText.mid (0, aLength) + theTail : theText;
}

View File

@ -0,0 +1,95 @@
// Created on: 2017-06-16
// Created by: Natalia ERMOLAEVA
// Copyright (c) 2017 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef TreeModel_Tools_H
#define TreeModel_Tools_H
#include <Standard.hxx>
#include <Standard_Macro.hxx>
#include <Standard_WarningsDisable.hxx>
#include <QApplication>
#include <QByteArray>
#include <QMap>
#include <QString>
#include <QStyle>
#include <Standard_WarningsRestore.hxx>
class QAction;
class QObject;
class QTreeView;
//! \class TreeModel_Tools
//! \brief The tool that gives auxiliary methods for qt elements manipulation
class TreeModel_Tools
{
public:
//! Converts a Qt string to byte array, string has mask: @ByteArray[...]
//! \param theValue a converted string
//! \return the extended filled array
Standard_EXPORT static QString ToString (const QByteArray& theValue);
//! Converts a Qt byte array to Qt string. It has mask: @ByteArray[...]
//! \param theValue a converted string
//! \return the extended filled array
Standard_EXPORT static QByteArray ToByteArray (const QString& theValue);
//! Returns header margin, defined in style settings of application
//! \return integer value
Standard_EXPORT static int HeaderSectionMargin() { return qApp->style()->pixelMetric (QStyle::PM_HeaderMargin); }
//! Save state of three view in a container in form: key, value. It saves:
//! - visibiblity of columns,
//! - columns width
//! \param theTreeView a view instance
//! \param theItems [out] properties
//! \param thePrefix peference item prefix
Standard_EXPORT static void SaveState (QTreeView* theTreeView, QMap<QString, QString>& theItems,
const QString& thePrefix = QString());
//! Restore state of three view by a container
//! \param theTreeView a view instance
//! \param theKey property key
//! \param theValue property value
//! \param thePrefix peference item prefix
//! \return boolean value whether the property is applyed to the tree view
Standard_EXPORT static bool RestoreState (QTreeView* theTreeView, const QString& theKey, const QString& theValue,
const QString& thePrefix = QString());
//! Fills tree view by default sections parameters obtained in view's tree model
//! \param theTreeView tree view instance
Standard_EXPORT static void SetDefaultHeaderSections (QTreeView* theTreeView);
//! Sets using visibility column in the tree view:
//! - sets the state in the TreeModel
//! - set section width, not resizable
//! \param theTreeView a view instance
//! \param theActive boolean value if the column should be connected/visible and other
Standard_EXPORT static void UseVisibilityColumn (QTreeView* theTreeView, const bool theActive = true);
//! Returns the text width
//! \param theText source text
//! \param theParent parent widget with its own style
//! \return calculated width value
Standard_EXPORT static int GetTextWidth (const QString& theText, QObject* theParent);
//! Returns string cut by width and '\n'
//! \param theText processing string
//! \param theWidth width value, if -1, default value is used
//! \param theTail symbols added to the end of the cut string
Standard_EXPORT static QString CutString (const QString& theText, const int theWidth = -1, const QString& theTail = "...");
};
#endif

View File

@ -13,25 +13,20 @@
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <inspector/DFBrowser_TreeView.hxx>
#include <inspector/TreeModel_VisibilityState.hxx>
// =======================================================================
// function : SetPredefinedSize
// function : OnClicked
// purpose :
// =======================================================================
void DFBrowser_TreeView::SetPredefinedSize (int theDefaultWidth, int theDefaultHeight)
void TreeModel_VisibilityState::OnClicked (const QModelIndex& theIndex)
{
myDefaultWidth = theDefaultWidth;
myDefaultHeight = theDefaultHeight;
}
if (theIndex.column() != TreeModel_ColumnType_Visibility)
return;
// =======================================================================
// function : sizeHint
// purpose :
// =======================================================================
QSize DFBrowser_TreeView::sizeHint() const
{
if (myDefaultWidth > 0 && myDefaultHeight > 0)
return QSize (myDefaultWidth, myDefaultHeight);
return QTreeView::sizeHint();
if (!CanBeVisible (theIndex))
return;
SetVisible (theIndex, !IsVisible (theIndex), true);
emit itemClicked (theIndex);
}

View File

@ -0,0 +1,81 @@
// Created on: 2017-06-16
// Created by: Natalia ERMOLAEVA
// Copyright (c) 2017 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef TreeModel_VisibilityState_H
#define TreeModel_VisibilityState_H
#include <inspector/TreeModel.hxx>
#include <inspector/TreeModel_ModelBase.hxx>
#include <inspector/TreeModel_ColumnType.hxx>
#include <Standard.hxx>
#include <Standard_Macro.hxx>
#include <Standard_WarningsDisable.hxx>
#include <QObject>
#include <QString>
#include <Standard_WarningsRestore.hxx>
//! \class TreeModel_VisibilityState
//! \brief Interface that provides connection between model and visualization control to:
//! - know whether the model item is visible
//! - change visibility of the model item
class TREEMODEL_EXPORT TreeModel_VisibilityState : public QObject
{
Q_OBJECT
public:
//! Constructor
TreeModel_VisibilityState (TreeModel_ModelBase* theModel) : myModel (theModel) {}
//! Destructor
~TreeModel_VisibilityState() {}
//! Returns true if visibility of the item can be changed
//! \param theIndex tree model index
//! \return boolean value
virtual bool CanBeVisible (const QModelIndex& theIndex) const = 0;
//! Sets visibility state
//! \param theIndex tree model index
//! \param theState visibility state
//! \param toEmitDataChanged boolean flag whether emit of the model should be done immediatelly
//! \return true if state is changed
virtual bool SetVisible (const QModelIndex& theIndex, const bool theState, const bool toEmitDataChanged = true) = 0;
//! Returns visibility state value
//! \param theIndex tree model index
//! \return boolean value
virtual bool IsVisible (const QModelIndex& theIndex) const = 0;
public slots:
//! Processes the mouse clicked on the index.
//! It changes the item visibility if model allows to change it.
//! \theIndex tree model index
void OnClicked (const QModelIndex& theIndex);
signals:
//! Signal after OnClicked is performed
//! \theIndex tree model index
void itemClicked (const QModelIndex& theIndex);
protected:
//! tree view model
TreeModel_ModelBase* getModel() const { return myModel; }
private:
TreeModel_ModelBase* myModel; //! tree view model
};
#endif

Binary file not shown.

After

Width:  |  Height:  |  Size: 446 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 478 B

View File

@ -8,6 +8,8 @@ VInspector_ItemBase.cxx
VInspector_ItemBase.hxx
VInspector_ItemContext.cxx
VInspector_ItemContext.hxx
VInspector_ItemFolderObject.cxx
VInspector_ItemFolderObject.hxx
VInspector_ItemEntityOwner.cxx
VInspector_ItemEntityOwner.hxx
VInspector_ItemHistoryElement.cxx
@ -21,6 +23,8 @@ VInspector_ItemPresentableObject.cxx
VInspector_ItemPresentableObject.hxx
VInspector_ItemSelection.cxx
VInspector_ItemSelection.hxx
VInspector_ItemSelectMgrFilter.cxx
VInspector_ItemSelectMgrFilter.hxx
VInspector_ItemSensitiveEntity.cxx
VInspector_ItemSensitiveEntity.hxx
VInspector_SelectionType.hxx

View File

@ -1,5 +1,7 @@
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file>icons/treeview_and.png</file>
<file>icons/treeview_or.png</file>
<file>icons/treeview_update.png</file>
</qresource>
</RCC>

View File

@ -44,6 +44,20 @@ public:
virtual void SetParameters (const Handle(TInspectorAPI_PluginParameters)& theParameters) Standard_OVERRIDE
{ myWindow->SetParameters (theParameters); }
//! Provide container for actions available in inspector on general level
//! \param theMenu if Qt implementation, it is QMenu object
Standard_EXPORT virtual void FillActionsMenu(void* theMenu) Standard_OVERRIDE { myWindow->FillActionsMenu (theMenu); }
//! Returns plugin preferences, empty implementation by default
//! \param theItem container of preference elements
virtual void GetPreferences (TInspectorAPI_PreferencesDataMap& theItem) Standard_OVERRIDE
{ myWindow->GetPreferences (theItem); }
//! Stores plugin preferences, empty implementation by default
//! \param theItem container of preference elements
virtual void SetPreferences (const TInspectorAPI_PreferencesDataMap& theItem) Standard_OVERRIDE
{ myWindow->SetPreferences (theItem); }
//! Calls update of the plugin's content
virtual void UpdateContent() Standard_OVERRIDE { myWindow->UpdateContent(); }

View File

@ -21,15 +21,15 @@
// function : GetContext
// purpose :
// =======================================================================
const Handle(AIS_InteractiveContext)& VInspector_ItemBase::GetContext() const
Handle(AIS_InteractiveContext) VInspector_ItemBase::GetContext() const
{
if (!myContext.IsNull())
return myContext;
Handle(AIS_InteractiveContext) aContext;
if (const VInspector_ItemContext* aThisContextItem = dynamic_cast<const VInspector_ItemContext*> (this))
if (dynamic_cast<const VInspector_ItemContext*> (this))
{
aContext = aThisContextItem->GetContext();
return Handle(AIS_InteractiveContext)(); // context has not be set yet
}
else
{

View File

@ -41,12 +41,12 @@ public:
//! Returns the current contex. It iterates up by list of parents to found context item and return context
//! \return a context
Standard_EXPORT const Handle(AIS_InteractiveContext)& GetContext() const;
Standard_EXPORT Handle(AIS_InteractiveContext) GetContext() const;
protected:
//! Initialize the current item. It creates a backup of the specific item information
virtual void initItem() const {};// = 0;
virtual void initItem() const {}
protected:

View File

@ -17,9 +17,14 @@
#include <AIS_ListOfInteractive.hxx>
#include <SelectMgr_EntityOwner.hxx>
#include <inspector/VInspector_ItemFolderObject.hxx>
#include <inspector/VInspector_ItemPresentableObject.hxx>
#include <inspector/VInspector_Tools.hxx>
#include <Standard_WarningsDisable.hxx>
#include <QStringList>
#include <Standard_WarningsRestore.hxx>
//#define DEBUG_FREE_OWNERS
// =======================================================================
@ -31,20 +36,22 @@ int VInspector_ItemContext::initRowCount() const
if (Column() != 0)
return 0;
int aNbProperties = 1; // item to visualize Filters/Drawer information of context
int aNbPresentations = 0;
if (!GetContext().IsNull())
{
Handle(AIS_InteractiveContext) aContext = GetContext();
if (aContext.IsNull())
return 0;
AIS_ListOfInteractive aListOfIO;
GetContext()->DisplayedObjects (aListOfIO);
GetContext()->ErasedObjects(aListOfIO);
aContext->DisplayedObjects (aListOfIO);
aContext->ErasedObjects(aListOfIO);
aNbPresentations = aListOfIO.Extent();
}
// owners without Presentation
#ifdef DEBUG_FREE_OWNERS
int aRows = 0;
// only local context is processed: TODO for global context
Handle(AIS_InteractiveContext) aContext = GetContext();
if (!aContext.IsNull()) {
NCollection_List<Handle(SelectBasics_EntityOwner)> anActiveOwners;
aContext->MainSelector()->ActiveOwners(anActiveOwners);
@ -59,25 +66,18 @@ int VInspector_ItemContext::initRowCount() const
if (anAISObj.IsNull())
aRows++;
}
}
// owners in Global Context
if (!aContext.IsNull())
{
NCollection_List<Handle(SelectBasics_EntityOwner)> anActiveOwners;
aContext->MainSelector()->ActiveOwners(anActiveOwners);
}
if (aRows > 0)
aNbPresentations += aRows;
#endif
#ifdef DEBUG_FREE_OWNERS
NCollection_List<Handle(SelectBasics_EntityOwner)> anEmptySelectableOwners;
NCollection_List<Handle(SelectBasics_EntityOwner)> anOwners =
VInspector_Tools::ActiveOwners (GetContext(), anEmptySelectableOwners);
VInspector_Tools::ActiveOwners (aContext, anEmptySelectableOwners);
if (anEmptySelectableOwners.Size() > 0)
aNbPresentations += 1;
#endif
return aNbPresentations;
return aNbProperties + aNbPresentations;
}
// =======================================================================
@ -89,42 +89,20 @@ QVariant VInspector_ItemContext::initValue (const int theItemRole) const
if (theItemRole != Qt::DisplayRole && theItemRole != Qt::EditRole && theItemRole != Qt::ToolTipRole)
return QVariant();
if (GetContext().IsNull())
return Column() == 0 ? "Empty context" : "";
switch (Column())
{
case 0: return GetContext()->DynamicType()->Name();
case 1: return rowCount();
case 4:
{
if (theItemRole == Qt::ToolTipRole)
return "Selected Owners";
else
{
Handle(AIS_InteractiveObject) anEmptyIO;
int aSelectedCount = VInspector_Tools::SelectedOwners (GetContext(), anEmptyIO, false);
return aSelectedCount > 0 ? QString::number (aSelectedCount) : "";
}
}
case 7:
{
if (theItemRole == Qt::ToolTipRole)
return QString ("All Owners/Active Owners");
else
{
NCollection_List<Handle(SelectBasics_EntityOwner)> anEmptySelectableOwners;
NCollection_List<Handle(SelectBasics_EntityOwner)> anOwners =
VInspector_Tools::ActiveOwners (GetContext(), anEmptySelectableOwners);
int anActiveOwners = anOwners.Size();
anOwners = VInspector_Tools::ContextOwners (GetContext());
return QString ("%1 / %2").arg (anOwners.Size()).arg (anActiveOwners);
}
}
case 8:
{
if (theItemRole == Qt::ToolTipRole)
return QString ("DeviationCoefficient");
else
return GetContext()->DeviationCoefficient();
}
case 6: return GetContext()->DeviationCoefficient();
default:
break;
}
@ -137,5 +115,8 @@ QVariant VInspector_ItemContext::initValue (const int theItemRole) const
// =======================================================================
TreeModel_ItemBasePtr VInspector_ItemContext::createChild (int theRow, int theColumn)
{
if (theRow == 0)
return VInspector_ItemFolderObject::CreateItem (currentItem(), theRow, theColumn);
else
return VInspector_ItemPresentableObject::CreateItem (currentItem(), theRow, theColumn);
}

View File

@ -24,6 +24,9 @@ typedef QExplicitlySharedDataPointer<VInspector_ItemContext> VInspector_ItemCont
//! \class VInspector_ItemContext
//! Parent item, that corresponds to AIS_InteractiveContext
//! Children of the item are:
//! - "Property" item to show context attributes such as selection filters and drawer properties
//! - presentation items to show all interactive elements displayed/erased in the context
class VInspector_ItemContext : public VInspector_ItemBase
{
public:

View File

@ -47,58 +47,34 @@ QVariant VInspector_ItemEntityOwner::initValue(int theItemRole) const
switch (Column())
{
case 0: return anOwner->DynamicType()->Name();
case 2: return theItemRole == Qt::ToolTipRole ? "Owner pointer"
: VInspector_Tools::GetPointerInfo (anOwner, true).ToCString();
case 2: return VInspector_Tools::GetPointerInfo (anOwner, true).ToCString();
case 3:
{
if (theItemRole == Qt::ToolTipRole)
return "Owner Shape type";
else
{
Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast (anOwner);
if (!BROwnr.IsNull())
{
if (BROwnr.IsNull())
return QVariant();
const TopoDS_Shape& aShape = BROwnr->Shape();
if (!aShape.IsNull())
if (aShape.IsNull())
return QVariant();
return VInspector_Tools::GetShapeTypeInfo (aShape.ShapeType()).ToCString();
}
}
break;
}
case 5:
{
if (theItemRole == Qt::ToolTipRole)
return "TShape pointer";
else
case 17:
case 18:
case 19:
{
Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast (anOwner);
if (!BROwnr.IsNull())
{
if (BROwnr.IsNull())
return QVariant();
const TopoDS_Shape& aShape = BROwnr->Shape();
if (!aShape.IsNull())
return VInspector_Tools::GetPointerInfo (aShape.TShape(), true).ToCString();
}
}
break;
}
case 8:
{
if (theItemRole == Qt::ToolTipRole)
return "Shape Location : Shape Orientation";
else
{
Handle(StdSelect_BRepOwner) aBROwnr = Handle(StdSelect_BRepOwner)::DownCast (anOwner);
if (!aBROwnr.IsNull())
{
const TopoDS_Shape& aShape = aBROwnr->Shape();
if (!aShape.IsNull())
return QString ("%1 : %2")
.arg (VInspector_Tools::LocationToName(aShape.Location()).ToCString())
.arg (VInspector_Tools::OrientationToName(aShape.Orientation()).ToCString());
return VInspector_Tools::GetShapeTypeInfo (aShape.ShapeType()).ToCString();
}
}
break;
if (aShape.IsNull())
return QVariant();
return Column() == 17 ? VInspector_Tools::GetPointerInfo (aShape.TShape(), true).ToCString()
: Column() == 18 ? VInspector_Tools::OrientationToName (aShape.Orientation()).ToCString()
: /*19*/ VInspector_Tools::LocationToName (aShape.Location()).ToCString();
}
default: break;
}
@ -148,12 +124,21 @@ void VInspector_ItemEntityOwner::Init()
int aRowId = Row();
int aCurrentIndex = 0;
#if OCC_VERSION_HEX < 0x070201
for (anIO->Init(); anIO->More() && anOwner.IsNull(); anIO->Next())
{
const Handle(SelectMgr_Selection)& aSelection = anIO->CurrentSelection();
for (aSelection->Init(); aSelection->More() && anOwner.IsNull(); aSelection->Next())
{
Handle(SelectMgr_SensitiveEntity) anEntity = aSelection->Sensitive();
#else
for (SelectMgr_SequenceOfSelection::Iterator aSelIter (anIO->Selections()); aSelIter.More() && anOwner.IsNull(); aSelIter.Next())
{
const Handle(SelectMgr_Selection)& aSelection = aSelIter.Value();
for (NCollection_Vector<Handle(SelectMgr_SensitiveEntity)>::Iterator aSelEntIter (aSelection->Entities()); aSelEntIter.More() && anOwner.IsNull(); aSelEntIter.Next())
{
Handle(SelectMgr_SensitiveEntity) anEntity = aSelEntIter.Value();
#endif
const Handle(SelectBasics_SensitiveEntity)& aBase = anEntity->BaseSensitive();
if (!aBase.IsNull())
{

View File

@ -0,0 +1,93 @@
// Created on: 2017-06-16
// Created by: Natalia ERMOLAEVA
// Copyright (c) 2017 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <inspector/VInspector_ItemFolderObject.hxx>
#include <inspector/VInspector_ItemContext.hxx>
#include <inspector/VInspector_ItemSelectMgrFilter.hxx>
// =======================================================================
// function : initValue
// purpose :
// =======================================================================
QVariant VInspector_ItemFolderObject::initValue (int theItemRole) const
{
if (Column() == 0 && (theItemRole == Qt::DisplayRole || theItemRole == Qt::ToolTipRole))
{
if (parentItemIsContext()) return "Properties";
else if (Row() == 0) return "Filters";
else return QVariant();
}
return QVariant();
}
// =======================================================================
// function : initRowCount
// purpose :
// =======================================================================
int VInspector_ItemFolderObject::initRowCount() const
{
return parentItemIsContext() ? 1 : (GetContext().IsNull() ? 0 : GetContext()->Filters().Extent());
}
// =======================================================================
// function : createChild
// purpose :
// =======================================================================
TreeModel_ItemBasePtr VInspector_ItemFolderObject::createChild (int theRow, int theColumn)
{
if (parentItemIsContext())
return VInspector_ItemFolderObject::CreateItem (currentItem(), theRow, theColumn);
else
return VInspector_ItemSelectMgrFilter::CreateItem (currentItem(), theRow, theColumn);
}
// =======================================================================
// function : Init
// purpose :
// =======================================================================
void VInspector_ItemFolderObject::Init()
{
TreeModel_ItemBase::Init(); // to use getIO() without circling initialization
}
// =======================================================================
// function : Reset
// purpose :
// =======================================================================
void VInspector_ItemFolderObject::Reset()
{
VInspector_ItemBase::Reset();
}
// =======================================================================
// function : initItem
// purpose :
// =======================================================================
void VInspector_ItemFolderObject::initItem() const
{
if (IsInitialized())
return;
const_cast<VInspector_ItemFolderObject*> (this)->Init();
}
// =======================================================================
// function : parentItemIsContext
// purpose :
// =======================================================================
bool VInspector_ItemFolderObject::parentItemIsContext() const
{
return itemDynamicCast<VInspector_ItemContext> (Parent());
}

View File

@ -0,0 +1,86 @@
// Created on: 2017-06-16
// Created by: Natalia ERMOLAEVA
// Copyright (c) 2017 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef VInspector_ItemFolderObject_H
#define VInspector_ItemFolderObject_H
#include <Standard.hxx>
#include <inspector/VInspector_ItemBase.hxx>
#include <AIS_InteractiveObject.hxx>
#include <NCollection_List.hxx>
#include <TCollection_AsciiString.hxx>
class QItemSelectionModel;
class VInspector_ItemFolderObject;
typedef QExplicitlySharedDataPointer<VInspector_ItemFolderObject> VInspector_ItemFolderObjectPtr;
//! \class VInspector_ItemFolderObject
//! Item presents additional level of information in the tree model.
//! Parent is item context, children are either folder item or Selection filter item.
class VInspector_ItemFolderObject : public VInspector_ItemBase
{
public:
//! Creates an item wrapped by a shared pointer
static VInspector_ItemFolderObjectPtr CreateItem (TreeModel_ItemBasePtr theParent,
const int theRow, const int theColumn)
{ return VInspector_ItemFolderObjectPtr (new VInspector_ItemFolderObject (theParent, theRow, theColumn)); }
//! Destructor
virtual ~VInspector_ItemFolderObject() Standard_OVERRIDE {};
//! Inits the item, fills internal containers
Standard_EXPORT virtual void Init() Standard_OVERRIDE;
//! Resets cached values
Standard_EXPORT virtual void Reset() Standard_OVERRIDE;
protected:
//! Initialize the current item. It is empty because Reset() is also empty.
virtual void initItem() const Standard_OVERRIDE;
//! Returns number of item selected
//! \return rows count
virtual int initRowCount() const Standard_OVERRIDE;
//! Returns item information for the given role. Fills internal container if it was not filled yet
//! \param theItemRole a value role
//! \return the value
virtual QVariant initValue (const int theItemRole) const Standard_OVERRIDE;
//! Creates a child item in the given position.
//! \param theRow the child row position
//! \param theColumn the child column position
//! \return the created item
virtual TreeModel_ItemBasePtr createChild (int theRow, int theColumn) Standard_OVERRIDE;
private:
//! Returns whether the parent item is context item
//! \returns bolean value
bool parentItemIsContext() const;
private:
//! Constructor
//! param theParent a parent item
VInspector_ItemFolderObject (TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn)
: VInspector_ItemBase (theParent, theRow, theColumn) {}
};
#endif

Some files were not shown because too many files have changed in this diff Show More